1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <BOPTools_AlgoTools.ixx>
18 #include <gp_Pnt2d.hxx>
20 #include <Adaptor3d_HCurve.hxx>
21 #include <Adaptor3d_CurveOnSurface.hxx>
22 #include <Adaptor3d_HCurveOnSurface.hxx>
24 #include <Geom_Curve.hxx>
25 #include <Geom_Surface.hxx>
26 #include <Geom_Plane.hxx>
27 #include <Geom_TrimmedCurve.hxx>
28 #include <Geom_RectangularTrimmedSurface.hxx>
30 #include <GeomAdaptor_Surface.hxx>
31 #include <GeomAdaptor_Curve.hxx>
32 #include <GeomAdaptor_HCurve.hxx>
33 #include <GeomAdaptor_HSurface.hxx>
35 #include <Geom2d_Curve.hxx>
36 #include <Geom2dInt_GInter.hxx>
37 #include <Geom2dAdaptor_Curve.hxx>
38 #include <Geom2dAdaptor_HCurve.hxx>
39 #include <Geom2dAdaptor.hxx>
41 #include <GeomProjLib.hxx>
43 #include <ProjLib_ProjectedCurve.hxx>
44 #include <Extrema_LocateExtPC.hxx>
46 #include <IntRes2d_Domain.hxx>
47 #include <IntRes2d_IntersectionPoint.hxx>
49 #include <TopLoc_Location.hxx>
52 #include <TopoDS_Edge.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <TopoDS_Face.hxx>
55 #include <TopoDS_Iterator.hxx>
56 #include <TopoDS_Wire.hxx>
58 #include <BRep_TVertex.hxx>
59 #include <BRep_TEdge.hxx>
60 #include <BRep_TFace.hxx>
61 #include <BRep_Tool.hxx>
62 #include <BRep_GCurve.hxx>
63 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
64 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
65 #include <BRep_CurveRepresentation.hxx>
66 #include <BRep_PointRepresentation.hxx>
67 #include <BRep_Builder.hxx>
69 #include <BRepAdaptor_Surface.hxx>
71 #include <BRepTools_WireExplorer.hxx>
74 #include <TopExp_Explorer.hxx>
75 #include <TopTools_IndexedMapOfShape.hxx>
76 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
77 #include <TopTools_ListOfShape.hxx>
78 #include <TopTools_ListIteratorOfListOfShape.hxx>
80 #include <IntTools_Tools.hxx>
82 #include <BOPCol_NCVector.hxx>
83 #include <BOPCol_Parallel.hxx>
84 #include <BRepLib_CheckCurveOnSurface.hxx>
87 void CheckEdge (const TopoDS_Edge& E,
88 const Standard_Real aMaxTol);
90 void CorrectEdgeTolerance (const TopoDS_Edge& myShape,
92 const Standard_Real aMaxTol);
94 Standard_Boolean Validate(const Adaptor3d_Curve& CRef,
95 const Adaptor3d_Curve& Other,
96 const Standard_Real Tol,
97 const Standard_Boolean SameParameter,
98 Standard_Real& aNewTolerance);
101 void CorrectVertexTolerance(const TopoDS_Edge& aE);
104 void CorrectWires(const TopoDS_Face& aF);
109 void UpdateEdges(const TopoDS_Face& aF);
112 Standard_Real IntersectCurves2d(const gp_Pnt& aPV,
113 const TopoDS_Face& aF,
114 const Handle(Geom_Surface)& aS,
115 const TopoDS_Edge& aE1,
116 const TopoDS_Edge& aE2);
120 //=======================================================================
121 //class : BOPTools_CPC
123 //=======================================================================
133 void SetEdge(const TopoDS_Edge& aE) {
137 const TopoDS_Edge& Edge()const {
141 void SetMaxTol(const Standard_Real aMaxTol) {
145 Standard_Real MaxTol()const {
150 CheckEdge(myEdge, myMaxTol);
154 Standard_Real myMaxTol;
158 //=======================================================================
159 typedef BOPCol_NCVector<BOPTools_CPC> BOPTools_VectorOfCPC;
161 typedef BOPCol_Functor
163 BOPTools_VectorOfCPC> BOPTools_CPCFunctor;
166 <BOPTools_CPCFunctor,
167 BOPTools_VectorOfCPC> BOPTools_CPCCnt;
169 //=======================================================================
170 //class : BOPTools_CWT
172 //=======================================================================
181 void SetFace(const TopoDS_Face& aF) {
186 CorrectWires(myFace);
192 //=======================================================================
193 typedef BOPCol_NCVector<BOPTools_CWT> BOPTools_VectorOfCWT;
195 typedef BOPCol_Functor
197 BOPTools_VectorOfCWT> BOPTools_CWTFunctor;
200 <BOPTools_CWTFunctor,
201 BOPTools_VectorOfCWT> BOPTools_CWTCnt;
203 //=======================================================================
204 //class : BOPTools_CDT
206 //=======================================================================
216 void SetEdge(const TopoDS_Edge& aE) {
220 void SetFace(const TopoDS_Face& aF) {
224 void SetMaxTol(const Standard_Real aMaxTol) {
229 CorrectEdgeTolerance (myEdge, myFace, myMaxTol);
233 Standard_Real myMaxTol;
237 //=======================================================================
238 typedef BOPCol_NCVector<BOPTools_CDT> BOPTools_VectorOfCDT;
240 typedef BOPCol_Functor
242 BOPTools_VectorOfCDT> BOPTools_CDTFunctor;
245 <BOPTools_CDTFunctor,
246 BOPTools_VectorOfCDT> BOPTools_CDTCnt;
248 //=======================================================================
249 //class : BOPTools_CVT
251 //=======================================================================
260 void SetEdge(const TopoDS_Edge& aE) {
265 CorrectVertexTolerance(myEdge);
272 //=======================================================================
273 typedef BOPCol_NCVector<BOPTools_CVT> BOPTools_VectorOfCVT;
275 typedef BOPCol_Functor
277 BOPTools_VectorOfCVT> BOPTools_CVTFunctor;
280 <BOPTools_CVTFunctor,
281 BOPTools_VectorOfCVT> BOPTools_CVTCnt;
283 //=======================================================================
284 //class : BOPTools_CET
286 //=======================================================================
295 void SetFace(const TopoDS_Face& aF) {
306 //=======================================================================
307 typedef BOPCol_NCVector<BOPTools_CET> BOPTools_VectorOfCET;
309 typedef BOPCol_Functor
311 BOPTools_VectorOfCET> BOPTools_CETFunctor;
314 <BOPTools_CETFunctor,
315 BOPTools_VectorOfCET> BOPTools_CETCnt;
318 //=======================================================================
320 //=======================================================================
321 // Function : CorrectTolerances
323 //=======================================================================
324 void BOPTools_AlgoTools::CorrectTolerances
325 (const TopoDS_Shape& aShape,
326 const Standard_Real aMaxTol,
327 const Standard_Boolean bRunParallel)
329 BOPTools_AlgoTools::CorrectPointOnCurve(aShape, aMaxTol, bRunParallel);
330 BOPTools_AlgoTools::CorrectCurveOnSurface(aShape, aMaxTol, bRunParallel);
333 //=======================================================================
334 // Function : CorrectPointOnCurve
336 //=======================================================================
337 void BOPTools_AlgoTools::CorrectPointOnCurve
338 (const TopoDS_Shape& aS,
339 const Standard_Real aMaxTol,
340 const Standard_Boolean bRunParallel)
342 TopExp_Explorer aExp;
343 BOPTools_VectorOfCPC aVCPC;
345 aExp.Init(aS, TopAbs_EDGE);
346 for(; aExp.More(); aExp.Next()) {
347 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aExp.Current());
348 BOPTools_CPC& aCPC=aVCPC.Append1();
350 aCPC.SetMaxTol(aMaxTol);
353 //======================================================
354 BOPTools_CPCCnt::Perform(bRunParallel, aVCPC);
355 //======================================================
357 //=======================================================================
358 // Function : CorrectCurveOnSurface
360 //=======================================================================
361 void BOPTools_AlgoTools::CorrectCurveOnSurface
362 (const TopoDS_Shape& aS,
363 const Standard_Real aMaxTol,
364 const Standard_Boolean bRunParallel)
366 TopExp_Explorer aExpF, aExpE;
367 BOPTools_VectorOfCWT aVCWT;
368 BOPTools_VectorOfCDT aVCDT;
370 aExpF.Init(aS, TopAbs_FACE);
371 for (; aExpF.More(); aExpF.Next()) {
372 const TopoDS_Face& aF=*((TopoDS_Face*)&aExpF.Current());
374 BOPTools_CWT& aCWT=aVCWT.Append1();
377 aExpE.Init(aF, TopAbs_EDGE);
378 for (; aExpE.More(); aExpE.Next()) {
379 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aExpE.Current());
381 BOPTools_CDT& aCDT=aVCDT.Append1();
384 aCDT.SetMaxTol(aMaxTol);
388 //======================================================
389 BOPTools_CWTCnt::Perform(bRunParallel, aVCWT);
390 //======================================================
391 BOPTools_CDTCnt::Perform(bRunParallel, aVCDT);
392 //======================================================
394 //=======================================================================
395 // Function : CorrectShapeTolerances
397 //=======================================================================
398 void BOPTools_AlgoTools::CorrectShapeTolerances
399 (const TopoDS_Shape& aShape,
400 const Standard_Boolean bRunParallel)
402 TopExp_Explorer aExp;
403 BOPTools_VectorOfCVT aVCVT;
404 BOPTools_VectorOfCET aVCET;
406 aExp.Init(aShape, TopAbs_EDGE);
407 for (; aExp.More(); aExp.Next()) {
408 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aExp.Current();
409 BOPTools_CVT& aCVT=aVCVT.Append1();
413 //======================================================
414 BOPTools_CVTCnt::Perform(bRunParallel, aVCVT);
415 //======================================================
417 aExp.Init(aShape, TopAbs_FACE);
418 for (; aExp.More(); aExp.Next()) {
419 const TopoDS_Face& aF = *(TopoDS_Face*)&aExp.Current();
420 BOPTools_CET& aCET=aVCET.Append1();
424 //======================================================
425 BOPTools_CETCnt::Perform(bRunParallel, aVCET);
426 //======================================================
429 //=======================================================================
430 // Function : CheckEdge
431 // purpose : Correct tolerances for Vertices on Edge
432 //=======================================================================
433 void CheckEdge (const TopoDS_Edge& Ed,
434 const Standard_Real aMaxTol)
436 Standard_Real aTolE, aTol, aD2, aNewTolerance, dd;
441 TopoDS_Iterator aItS;
443 TopAbs_Orientation aOrV;
444 BRep_ListIteratorOfListOfPointRepresentation aItPR;
445 BRep_ListIteratorOfListOfCurveRepresentation aItCR;
448 aE.Orientation(TopAbs_FORWARD);
449 aTolE=BRep_Tool::Tolerance(aE);
451 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&aE.TShape());
454 for (; aItS.More(); aItS.Next()) {
455 aV= TopoDS::Vertex(aItS.Value());
457 Handle(BRep_TVertex)& TV=*((Handle(BRep_TVertex)*)&aV.TShape());
458 const gp_Pnt& aPV = TV->Pnt();
460 aTol=BRep_Tool::Tolerance(aV);
461 aTol=Max(aTol, aTolE);
465 const TopLoc_Location& Eloc = aE.Location();
467 aItCR.Initialize(TE->Curves());
468 while (aItCR.More()) {
469 const Handle(BRep_CurveRepresentation)& aCR = aItCR.Value();
470 const TopLoc_Location& loc = aCR->Location();
471 L = (Eloc * loc).Predivided(aV.Location());
473 if (aCR->IsCurve3D()) {
474 const Handle(Geom_Curve)& aC = aCR->Curve3D();
476 aItPR.Initialize(TV->Points());
477 while (aItPR.More()) {
478 const Handle(BRep_PointRepresentation)& aPR=aItPR.Value();
479 if (aPR->IsPointOnCurve(aC, L)) {
480 aPC = aC->Value(aPR->Parameter());
481 aPC.Transform(L.Transformation());
482 aD2=aPV.SquareDistance(aPC);
484 aNewTolerance=sqrt(aD2)+dd;
485 if (aNewTolerance<aMaxTol)
486 TV->UpdateTolerance(aNewTolerance);
492 aOrV=aV.Orientation();
493 if (aOrV==TopAbs_FORWARD || aOrV==TopAbs_REVERSED) {
494 const Handle(BRep_GCurve)& aGC=*((Handle(BRep_GCurve)*)&aCR);
496 if (aOrV==TopAbs_FORWARD) {
497 aPC=aC->Value(aGC->First());
500 aPC=aC->Value(aGC->Last());
502 aPC.Transform(L.Transformation());
504 aD2=aPV.SquareDistance(aPC);
506 aNewTolerance=sqrt(aD2)+dd;
507 if (aNewTolerance<aMaxTol)
508 TV->UpdateTolerance(aNewTolerance);
514 }// while (itcr.More()) {
515 } // for (; aVExp.More(); aVExp.Next()) {
517 //=======================================================================
518 // Function : CorrectWires
520 //=======================================================================
521 void CorrectWires(const TopoDS_Face& aFx)
523 Standard_Boolean bIsPeriodic;
524 Standard_Integer i, aNbV;
525 Standard_Real aTol, aTol2, aD2, aD2max, aT1, aT2, aT;
529 TopoDS_Vertex aV11, aV12, aV21, aV22;;
530 TopTools_IndexedDataMapOfShapeListOfShape aMVE;
531 TopTools_ListIteratorOfListOfShape aIt, aIt1;
534 aF.Orientation(TopAbs_FORWARD);
535 const Handle(Geom_Surface)& aS=BRep_Tool::Surface(aFx);
536 GeomAdaptor_Surface aGAS (aS);
538 bIsPeriodic=(aGAS.IsUPeriodic() || aGAS.IsVPeriodic());
540 TopExp::MapShapesAndAncestors(aF,
545 for (i=1; i<=aNbV; ++i) {
546 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMVE.FindKey(i));
547 aPV=BRep_Tool::Pnt(aV);
548 aTol=BRep_Tool::Tolerance(aV);
552 const TopTools_ListOfShape& aLE=aMVE.FindFromIndex(i);
554 for (; aIt.More(); aIt.Next()) {
555 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aIt.Value());
556 const Handle(Geom2d_Curve)& aC2D=
557 BRep_Tool::CurveOnSurface(aE, aF, aT1, aT2);
558 aT=BRep_Tool::Parameter(aV, aE);
561 aS->D0(aP2D.X(), aP2D.Y(), aP);
562 aD2=aPV.SquareDistance(aP);
566 //check self interference
575 TopExp::Vertices(aE, aV11, aV12);
579 for (; aIt1.More(); aIt1.Next()) {
580 const TopoDS_Edge& aE1=*(TopoDS_Edge*)(&aIt1.Value());
582 //do not perform check for edges that have two common vertices
583 TopExp::Vertices(aE1, aV21, aV22);
584 if ((aV11.IsSame(aV21) && aV12.IsSame(aV22)) ||
585 (aV12.IsSame(aV21) && aV11.IsSame(aV22))) {
589 aD2=IntersectCurves2d(aPV, aF, aS, aE, aE1);
593 }// for (; aIt1.More(); aIt1.Next()) {
594 }// for (; aIt.More(); aIt.Next()) {
599 aBB.UpdateVertex(aV, aTol);
601 }// for (i=1; i<=aNbV; ++i) {
603 //=======================================================================
604 // Function : IntersectCurves2d
605 // purpose : Intersect 2d curves of edges
606 //=======================================================================
607 Standard_Real IntersectCurves2d(const gp_Pnt& aPV,
608 const TopoDS_Face& aF,
609 const Handle(Geom_Surface)& aS,
610 const TopoDS_Edge& aE1,
611 const TopoDS_Edge& aE2)
613 Standard_Real aDist, aD, aT11, aT12, aT21, aT22, aTol2d;
614 Standard_Integer j, aNbPnt;
615 Geom2dInt_GInter aInter;
620 aTol2d = Precision::Confusion();
622 const Handle(Geom2d_Curve)& aC2D1=
623 BRep_Tool::CurveOnSurface(aE1, aF, aT11, aT12);
624 const Handle(Geom2d_Curve)& aC2D2=
625 BRep_Tool::CurveOnSurface(aE2, aF, aT21, aT22);
627 Geom2dAdaptor_Curve aGAC1(aC2D1), aGAC2(aC2D2);
628 IntRes2d_Domain aDom1(aC2D1->Value(aT11), aT11, aTol2d,
629 aC2D1->Value(aT12), aT12, aTol2d);
630 IntRes2d_Domain aDom2(aC2D2->Value(aT21), aT21, aTol2d,
631 aC2D2->Value(aT22), aT22, aTol2d);
633 aInter.Perform(aGAC1, aDom1, aGAC2, aDom2, aTol2d, aTol2d);
634 if (aInter.IsDone()) {
635 if (aInter.NbSegments()) {
638 aNbPnt = aInter.NbPoints();
640 aDist = Precision::Infinite();
641 for (j = 1; j <= aNbPnt; ++j) {
642 aP2D = aInter.Point(j).Value();
643 aS->D0(aP2D.X(), aP2D.Y(), aP);
644 aD=aPV.SquareDistance(aP);
653 //=======================================================================
654 // Function : CorrectEdgeTolerance
655 // purpose : Correct tolerances for Edge
656 //=======================================================================
657 void CorrectEdgeTolerance (const TopoDS_Edge& myShape,
658 const TopoDS_Face& S,
659 const Standard_Real aMaxTol)
662 // 1. Minimum of conditions to Perform
663 Handle (BRep_CurveRepresentation) myCref;
664 Handle (Adaptor3d_HCurve) myHCurve;
668 Handle(BRep_TEdge)& TEx = *((Handle(BRep_TEdge)*)&myShape.TShape());
669 BRep_ListIteratorOfListOfCurveRepresentation itcrx(TEx->Curves());
670 Standard_Boolean Degenerated, SameParameterx, SameRangex;
672 Standard_Integer unique = 0;
674 Degenerated = TEx->Degenerated();
675 SameParameterx = TEx->SameParameter();
676 SameRangex = TEx->SameRange();
678 if (!SameRangex && SameParameterx) {
682 Handle(Geom_Curve) C3d;
683 while (itcrx.More()) {
684 const Handle(BRep_CurveRepresentation)& cr = itcrx.Value();
685 if (cr->IsCurve3D()) {
687 if (myCref.IsNull() && !cr->Curve3D().IsNull()) {
695 return;//...No3DCurve
698 return;//...Multiple3DCurve;
701 if (myCref.IsNull() && !Degenerated) {
702 itcrx.Initialize(TEx->Curves());
703 while (itcrx.More()) {
704 const Handle(BRep_CurveRepresentation)& cr = itcrx.Value();
705 if (cr->IsCurveOnSurface()) {
713 else if (!myCref.IsNull() && Degenerated){
714 return ;//...InvalidDegeneratedFlag;
717 if (!myCref.IsNull()) {
718 const Handle(BRep_GCurve)& GCref =
719 *((Handle(BRep_GCurve)*)&myCref);
720 Standard_Real First,Last;
721 GCref->Range(First,Last);
724 return ;//InvalidRange;
728 if (myCref->IsCurve3D()) {
729 Handle(Geom_Curve) C3dx = Handle(Geom_Curve)::DownCast
730 (myCref->Curve3D()->Transformed
731 (myCref->Location().Transformation()));
732 GeomAdaptor_Curve GAC3d(C3dx, First, Last);
733 myHCurve = new GeomAdaptor_HCurve(GAC3d);
735 else { // curve on surface
736 Handle(Geom_Surface) Sref = myCref->Surface();
737 Sref = Handle(Geom_Surface)::
738 DownCast(Sref->Transformed(myCref->Location().Transformation()));
739 const Handle(Geom2d_Curve)& PCref = myCref->PCurve();
740 Handle(GeomAdaptor_HSurface) GAHSref =
741 new GeomAdaptor_HSurface(Sref);
742 Handle(Geom2dAdaptor_HCurve) GHPCref =
743 new Geom2dAdaptor_HCurve(PCref, First, Last);
744 Adaptor3d_CurveOnSurface ACSref(GHPCref,GAHSref);
745 myHCurve = new Adaptor3d_HCurveOnSurface(ACSref);
750 //===============================================
751 // 2. Tolerances in InContext
755 Standard_Boolean ok=Standard_True;;
757 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&myShape.TShape());
758 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Edge(myShape));
759 Standard_Real aNewTol=Tol;
761 Standard_Boolean SameParameter = TE->SameParameter();
762 Standard_Boolean SameRange = TE->SameRange();
763 Standard_Real First = myHCurve->FirstParameter();
764 Standard_Real Last = myHCurve->LastParameter();
765 Standard_Real Delta =1.e-12;
767 Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &S.TShape());
768 const TopLoc_Location& Floc = S.Location();
769 const TopLoc_Location& TFloc = TF->Location();
770 const Handle(Geom_Surface)& Su = TF->Surface();
771 TopLoc_Location L = (Floc * TFloc).Predivided(myShape.Location());
772 Standard_Boolean pcurvefound = Standard_False;
774 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
775 while (itcr.More()) {
776 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
777 if (cr != myCref && cr->IsCurveOnSurface(Su,L)) {
778 pcurvefound = Standard_True;
779 const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
782 if (SameRange && (f != First || l != Last)) {
783 return ;//BRepCheck_InvalidSameRangeFlag;
786 Handle(Geom_Surface) Sb = cr->Surface();
787 Sb = Handle(Geom_Surface)::
788 DownCast (Su->Transformed(L.Transformation()));
789 Handle(Geom2d_Curve) PC = cr->PCurve();
790 Handle(GeomAdaptor_HSurface) GAHS =
791 new GeomAdaptor_HSurface(Sb);
792 Handle(Geom2dAdaptor_HCurve) GHPC =
793 new Geom2dAdaptor_HCurve(PC,f,l);
794 Adaptor3d_CurveOnSurface ACS(GHPC,GAHS);
795 ok = Validate(myHCurve->Curve(), ACS,
796 Tol, SameParameter, aNewTol);
798 if (aNewTol<aMaxTol) {
799 TE->UpdateTolerance(aNewTol+Delta);
801 CorrectVertexTolerance(myShape);
805 if (cr->IsCurveOnClosedSurface()) {
806 //checkclosed = Standard_True;
807 GHPC->ChangeCurve2d().Load(cr->PCurve2(),f,l); // same bounds
808 ACS.Load(GAHS); // sans doute inutile
809 ACS.Load(GHPC); // meme remarque...
810 ok = Validate(myHCurve->Curve(),ACS,Tol,SameParameter, aNewTol);
812 if (aNewTol<aMaxTol) {
813 TE->UpdateTolerance(aNewTol+Delta);
814 CorrectVertexTolerance(myShape);
823 Handle(Geom_Plane) P;
824 Handle(Standard_Type) styp = Su->DynamicType();
825 if (styp == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
826 P = Handle(Geom_Plane)::
827 DownCast(Handle(Geom_RectangularTrimmedSurface)::
828 DownCast(Su)->BasisSurface());
831 P = Handle(Geom_Plane)::DownCast(Su);
833 if (P.IsNull()) { // not a plane
837 else {// on fait la projection a la volee, comme BRep_Tool
838 P = Handle(Geom_Plane)::
839 DownCast(P->Transformed(L.Transformation()));
840 //on projette Cref sur ce plan
841 Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(P);
843 // Dub - Normalement myHCurve est une GeomAdaptor_HCurve
844 GeomAdaptor_Curve& Gac =
845 Handle(GeomAdaptor_HCurve)::DownCast(myHCurve)->ChangeCurve();
846 Handle(Geom_Curve) C3dx = Gac.Curve();
847 Handle(Geom_Curve) ProjOnPlane =
848 GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3dx,First,Last),
850 P->Position().Direction(),
853 Handle(GeomAdaptor_HCurve) aHCurve =
854 new GeomAdaptor_HCurve(ProjOnPlane);
856 ProjLib_ProjectedCurve proj(GAHS,aHCurve);
857 Handle(Geom2d_Curve) PC = Geom2dAdaptor::MakeCurve(proj);
858 Handle(Geom2dAdaptor_HCurve) GHPC =
859 new Geom2dAdaptor_HCurve(PC,
860 myHCurve->FirstParameter(),
861 myHCurve->LastParameter());
863 Adaptor3d_CurveOnSurface ACS(GHPC,GAHS);
865 Standard_Boolean okx = Validate(myHCurve->Curve(),ACS,
866 Tol,Standard_True, aNewTol);
868 if (aNewTol<aMaxTol) {
869 TE->UpdateTolerance(aNewTol+Delta);
870 CorrectVertexTolerance(myShape);
874 }//end of if (!pcurvefound) {
875 } // end of 2. Tolerances in InContext
877 //=======================================================================
878 //function : CorrectVertexTolerance
880 //=======================================================================
881 void CorrectVertexTolerance(const TopoDS_Edge& aE)
883 Standard_Real aTolE, aTolV;
886 aTolE=BRep_Tool::Tolerance(aE);
888 for(; aIt.More(); aIt.Next()) {
889 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aIt.Value());
890 aTolV=BRep_Tool::Tolerance(aV);
892 Handle(BRep_TVertex)& aTV= *((Handle(BRep_TVertex)*)&aV.TShape());
893 aTV->UpdateTolerance(aTolE);
897 //=======================================================================
898 //function : Validate
900 //=======================================================================
901 Standard_Boolean Validate(const Adaptor3d_Curve& CRef,
902 const Adaptor3d_Curve& Other,
903 const Standard_Real Tol,
904 const Standard_Boolean SameParameter,
905 Standard_Real& aNewTolerance)
907 Standard_Real First, Last, MaxDistance, aD, Tol2;
909 First = CRef.FirstParameter();
910 Last = CRef.LastParameter();
914 Standard_Integer NCONTROL=23;
915 Standard_Integer i, aNC1=NCONTROL-1;
917 Standard_Boolean aFlag=Standard_False;
918 Standard_Boolean proj = (!SameParameter ||
919 First != Other.FirstParameter() ||
920 Last != Other.LastParameter());
924 for (i = 0; i < NCONTROL; i++) {
925 Standard_Real prm = ((aNC1-i)*First + i*Last)/aNC1;
926 gp_Pnt pref = CRef.Value(prm);
927 gp_Pnt pother = Other.Value(prm);
929 aD=pref.SquareDistance(pother);
932 if (aD>MaxDistance) {
940 aNewTolerance=sqrt(MaxDistance);
948 Extrema_LocateExtPC refd,otherd;
949 Standard_Real OFirst, OLast;
950 OFirst = Other.FirstParameter();
951 OLast = Other.LastParameter();
953 gp_Pnt pd = CRef.Value(First);
954 gp_Pnt pdo = Other.Value(OFirst);
956 aD = pd.SquareDistance(pdo);
958 if (aD>MaxDistance) {
964 pd = CRef.Value(Last);
965 pdo = Other.Value(OLast);
966 aD = pd.SquareDistance(pdo);
967 if (aD > Tol2 && aD > MaxDistance) {
972 refd.Initialize(CRef, First, Last, CRef.Resolution(Tol));
973 otherd.Initialize(Other, OFirst, OLast, Other.Resolution(Tol));
975 for (i = 2; i< aNC1; i++) {
976 Standard_Real rprm = ((aNC1-i)*First + i*Last)/aNC1;
977 gp_Pnt pref = CRef.Value(rprm);
979 Standard_Real oprm = ((aNC1-i)*OFirst + i*OLast)/aNC1;
980 gp_Pnt pother = Other.Value(oprm);
982 refd.Perform(pother,rprm);
983 if (!refd.IsDone() || refd.SquareDistance() > Tol2) {
985 aD=refd.SquareDistance();
986 if (aD > Tol2 && aD>MaxDistance) {
993 otherd.Perform(pref,oprm);
994 if (!otherd.IsDone() || otherd.SquareDistance() > Tol2) {
996 if (otherd.IsDone()) {
997 aD=otherd.SquareDistance();
998 if (aD > Tol2 && aD>MaxDistance) {
1007 aD=sqrt (MaxDistance);
1011 //=======================================================================
1012 // Function : UpdateEdges
1014 //=======================================================================
1015 void UpdateEdges(const TopoDS_Face& aF)
1017 Standard_Real aTolF, aTolE, aTolV;
1018 TopoDS_Iterator aItF, aItW, aItE;
1021 aTolE=aTolF= BRep_Tool::Tolerance(aF);
1022 aItF.Initialize(aF);
1023 for (; aItF.More(); aItF.Next()) {
1024 const TopoDS_Shape& aS = aItF.Value();
1025 if (aS.ShapeType()==TopAbs_WIRE) {
1026 aItW.Initialize(aS);
1027 for (; aItW.More(); aItW.Next()) {
1028 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aItW.Value());
1029 aTolE = BRep_Tool::Tolerance(aE);
1030 if (aTolE < aTolF) {
1031 aBB.UpdateEdge(aE, aTolF);
1034 //UpdateVertices(aE);
1038 const TopoDS_Vertex& aV=*(TopoDS_Vertex*)&aItF.Value();
1039 aTolV = BRep_Tool::Tolerance(aV);
1040 if (aTolV < aTolE) {
1041 aBB.UpdateVertex(aV, aTolF);
1046 //=======================================================================
1047 // Function : ComputeTolerance
1049 //=======================================================================
1050 Standard_Boolean BOPTools_AlgoTools::ComputeTolerance
1051 (const TopoDS_Face& theFace,
1052 const TopoDS_Edge& theEdge,
1053 Standard_Real& theMaxDist,
1054 Standard_Real& theMaxPar)
1056 BRepLib_CheckCurveOnSurface aCS;
1058 aCS.Init(theEdge, theFace);
1060 if (!aCS.IsDone()) {
1061 return Standard_False;
1064 theMaxDist = aCS.MaxDistance();
1065 theMaxPar = aCS.MaxParameter();
1067 return Standard_True;