1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 #include <BOPAlgo_WireSplitter.ixx>
21 #include <Precision.hxx>
23 #include <gp_Pnt2d.hxx>
24 #include <gp_Vec2d.hxx>
25 #include <gp_Dir2d.hxx>
26 #include <Geom2d_Curve.hxx>
27 #include <GeomAdaptor_Surface.hxx>
29 #include <TopoDS_Edge.hxx>
30 #include <TopoDS_Vertex.hxx>
31 #include <TopoDS_Wire.hxx>
32 #include <TopoDS_Iterator.hxx>
33 #include <BRep_Tool.hxx>
34 #include <BRepAdaptor_Surface.hxx>
36 #include <BOPCol_ListOfShape.hxx>
37 #include <BOPCol_SequenceOfShape.hxx>
38 #include <BOPCol_SequenceOfPnt2d.hxx>
39 #include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx>
41 #include <Geom_Surface.hxx>
42 #include <Geom_Plane.hxx>
43 #include <Geom_RectangularTrimmedSurface.hxx>
44 #include <Geom_RectangularTrimmedSurface.hxx>
45 #include <BOPTools_AlgoTools2D.hxx>
46 #include <TopLoc_Location.hxx>
47 #include <BRep_Builder.hxx>
48 #include <BOPCol_SequenceOfReal.hxx>
50 #include <TopExp_Explorer.hxx>
54 Standard_Real Angle (const gp_Dir2d& aDir2D);
57 Standard_Real Angle2D (const TopoDS_Vertex& aV,
58 const TopoDS_Edge& anEdge,
59 const TopoDS_Face& myFace,
60 const GeomAdaptor_Surface& aGAS,
61 const Standard_Boolean aFlag);
64 void GetNextVertex(const TopoDS_Vertex& aV,
65 const TopoDS_Edge& aE,
69 Standard_Real AngleIn(const TopoDS_Edge& aEIn,
70 const BOPAlgo_ListOfEdgeInfo& aLEInfo);
73 Standard_Integer NbWaysOut(const BOPAlgo_ListOfEdgeInfo& aLEInfo);
76 gp_Pnt2d Coord2dVf (const TopoDS_Edge& aE,
77 const TopoDS_Face& aF);
80 gp_Pnt2d Coord2d (const TopoDS_Vertex& aV1,
81 const TopoDS_Edge& aE1,
82 const TopoDS_Face& aF);
86 Standard_Real ClockWiseAngle(const Standard_Real aAngleIn,
87 const Standard_Real aAngleOut);
90 void Path (const GeomAdaptor_Surface& aGAS,
91 const TopoDS_Face& myFace,
92 const TopoDS_Vertex& aVa,
93 const TopoDS_Edge& aEOuta,
94 BOPAlgo_EdgeInfo& anEdgeInfo,
95 BOPCol_SequenceOfShape& aLS,
96 BOPCol_SequenceOfShape& aVertVa,
97 BOPCol_SequenceOfPnt2d& aCoordVa,
98 BOPTools_ConnexityBlock& aCB,
99 BOPAlgo_IndexedDataMapOfShapeListOfEdgeInfo& mySmartMap);
102 Standard_Real Angle2D (const TopoDS_Vertex& aV,
103 const TopoDS_Edge& anEdge,
104 const TopoDS_Face& myFace,
105 const GeomAdaptor_Surface& aGAS,
106 const Standard_Boolean aFlag);
108 Standard_Real Angle (const gp_Dir2d& aDir2D);
111 Standard_Real Tolerance2D (const TopoDS_Vertex& aV,
112 const GeomAdaptor_Surface& aGAS);
115 void BuildPCurveForPlane (const BOPCol_ListOfShape myEdges,
116 const TopoDS_Face& myFace);
119 Standard_Real UTolerance2D (const TopoDS_Vertex& aV,
120 const GeomAdaptor_Surface& aGAS);
122 Standard_Real VTolerance2D (const TopoDS_Vertex& aV,
123 const GeomAdaptor_Surface& aGAS);
126 Standard_Boolean RecomputeAngles(const BOPAlgo_ListOfEdgeInfo& aLEInfo,
127 const TopoDS_Face& theFace,
128 const gp_Pnt2d& thePb,
129 const TopoDS_Vertex& theVb,
130 const GeomAdaptor_Surface& theGAS,
131 const TopoDS_Edge& theEOuta,
132 const Standard_Boolean& bHasClosed,
133 const Standard_Real& theTol2D,
134 BOPCol_SequenceOfReal& theRecomputedAngles);
136 //=======================================================================
137 //function : SplitBlock
139 //=======================================================================
140 void BOPAlgo_WireSplitter::SplitBlock(BOPTools_ConnexityBlock& aCB)
142 Standard_Boolean bNothingToDo;
143 Standard_Integer aIx, aNb, i, aCntIn, aCntOut;
144 Standard_Real aAngle;
145 TopAbs_Orientation aOr;
146 TopoDS_Iterator aItS;
148 BOPCol_ListIteratorOfListOfShape aIt;
149 BOPAlgo_ListIteratorOfListOfEdgeInfo aItLEI;
151 BOPAlgo_IndexedDataMapOfShapeListOfEdgeInfo mySmartMap(100, myAllocator);
153 const TopoDS_Face& myFace=myWES->Face();
154 const BOPCol_ListOfShape& myEdges=aCB.Shapes();
156 // 1.Filling mySmartMap
157 BuildPCurveForPlane(myEdges, myFace);
158 aIt.Initialize(myEdges);
159 for(; aIt.More(); aIt.Next()) {
160 const TopoDS_Edge& aE=(*(TopoDS_Edge *)&aIt.Value());
161 if (!BOPTools_AlgoTools2D::HasCurveOnSurface (aE, myFace)) {
166 for(; aItS.More(); aItS.Next()) {
167 const TopoDS_Shape& aV=aItS.Value();
168 aIx=mySmartMap.FindIndex(aV);
170 BOPAlgo_ListOfEdgeInfo aLEIx(myAllocator);
171 aIx=mySmartMap.Add(aV, aLEIx);
174 BOPAlgo_ListOfEdgeInfo& aLEI=mySmartMap(aIx);
176 BOPAlgo_EdgeInfo aEI;
179 aOr=aV.Orientation();
180 if (aOr==TopAbs_FORWARD) {
181 aEI.SetInFlag(Standard_False);
183 else if (aOr==TopAbs_REVERSED) {
184 aEI.SetInFlag(Standard_True);
190 aNb=mySmartMap.Extent();
192 bNothingToDo=Standard_True;
193 for (i=1; i<=aNb; i++) {
196 const BOPAlgo_ListOfEdgeInfo& aLEInfo= mySmartMap(i);
197 BOPAlgo_ListIteratorOfListOfEdgeInfo anIt(aLEInfo);
198 for (; anIt.More(); anIt.Next()) {
199 const BOPAlgo_EdgeInfo& aEI=anIt.Value();
207 if (aCntIn!=1 || aCntOut!=1) {
208 bNothingToDo=Standard_False;
213 // Each vertex has one edge In and one - Out. Good. But it is not enought
214 // to consider that nothing to do with this. We must check edges on TShape
215 // coinsidence. If there are such edges there is something to do with.
217 Standard_Integer aNbE, aNbMapEE;
218 Standard_Boolean bFlag;
220 BOPCol_IndexedDataMapOfShapeListOfShape aMapEE(100, myAllocator);
221 aNbE=myEdges.Extent();
223 aIt.Initialize(myEdges);
224 for (; aIt.More(); aIt.Next()) {
225 const TopoDS_Shape& aE = aIt.Value();
226 if (!aMapEE.Contains(aE)) {
227 BOPCol_ListOfShape aLEx(myAllocator);
229 aMapEE.Add(aE, aLEx);
232 BOPCol_ListOfShape& aLEx=aMapEE.ChangeFromKey(aE);
238 aNbMapEE=aMapEE.Extent();
239 for (i=1; i<=aNbMapEE; ++i) {
240 const BOPCol_ListOfShape& aLEx=aMapEE(i);
242 if (aNbE==1) {// usual case
246 const TopoDS_Shape& aE1=aLEx.First();
247 const TopoDS_Shape& aE2=aLEx.Last();
248 if (aE1.IsSame(aE2)) {
249 bFlag=Standard_False;
254 bFlag=Standard_False;
258 bNothingToDo=bNothingToDo && bFlag;
259 } // if (bNothingToDo) {
263 BOPCol_ListOfShape& aLECB=aCB.ChangeShapes();
264 BOPAlgo_WireSplitter::MakeWire(aLECB, aW);
265 BOPCol_ListOfShape& aLoops=aCB.ChangeLoops();
272 // 3. Angles in mySmartMap
273 BRepAdaptor_Surface aBAS(myFace);
274 const GeomAdaptor_Surface& aGAS=aBAS.Surface();
276 for (i=1; i<=aNb; i++) {
277 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&mySmartMap.FindKey(i)));
278 const BOPAlgo_ListOfEdgeInfo& aLEI= mySmartMap(i);
280 aItLEI.Initialize(aLEI);
281 for (; aItLEI.More(); aItLEI.Next()) {
282 BOPAlgo_EdgeInfo& aEI=aItLEI.ChangeValue();
283 const TopoDS_Edge& aE=aEI.Edge();
287 aVV.Orientation(TopAbs_REVERSED);
288 aAngle=Angle2D (aVV, aE, myFace, aGAS, Standard_True);
291 aVV.Orientation(TopAbs_FORWARD);
292 aAngle=Angle2D (aVV, aE, myFace, aGAS, Standard_False);
294 aEI.SetAngle(aAngle);
296 }// for (i=1; i<=aNb; i++) {
300 Standard_Boolean bIsOut, bIsNotPassed;
301 BOPCol_SequenceOfShape aLS, aVertVa;
302 BOPCol_SequenceOfPnt2d aCoordVa;
304 for (i=1; i<=aNb; ++i) {
305 const TopoDS_Vertex& aVa=(*(TopoDS_Vertex *)(&mySmartMap.FindKey(i)));
306 const BOPAlgo_ListOfEdgeInfo& aLEI=mySmartMap(i);
307 aItLEI.Initialize(aLEI);
308 for (; aItLEI.More(); aItLEI.Next()) {
309 BOPAlgo_EdgeInfo& aEI=aItLEI.ChangeValue();
310 const TopoDS_Edge& aEOuta=aEI.Edge();
313 bIsNotPassed=!aEI.Passed();
314 if (bIsOut && bIsNotPassed) {
320 Path(aGAS, myFace, aVa, aEOuta, aEI, aLS,
321 aVertVa, aCoordVa, aCB, mySmartMap);
324 }// for (i=1; i<=aNb; ++i) {
326 //=======================================================================
329 //=======================================================================
330 void Path (const GeomAdaptor_Surface& aGAS,
331 const TopoDS_Face& myFace,
332 const TopoDS_Vertex& aVa,
333 const TopoDS_Edge& aEOuta,
334 BOPAlgo_EdgeInfo& anEdgeInfo,
335 BOPCol_SequenceOfShape& aLS,
336 BOPCol_SequenceOfShape& aVertVa,
337 BOPCol_SequenceOfPnt2d& aCoordVa,
338 BOPTools_ConnexityBlock& aCB,
339 BOPAlgo_IndexedDataMapOfShapeListOfEdgeInfo& mySmartMap)
342 Standard_Integer i, j, aNb, aNbj;
343 Standard_Real aTol, anAngleIn, anAngleOut, anAngle, aMinAngle;
344 Standard_Real aTol2D, aTol2D2;
345 Standard_Real aTol2, aD2, aTwoPI;
346 Standard_Boolean anIsSameV2d, anIsSameV, anIsFound, anIsOut, anIsNotPassed;
349 BOPAlgo_ListIteratorOfListOfEdgeInfo anIt;
351 aTwoPI = M_PI + M_PI;
356 // Do not escape through edge from which you enter
359 const TopoDS_Shape& anEPrev=aLS(aNb);
360 if (anEPrev.IsSame(aEOuta)) {
365 anEdgeInfo.SetPassed(Standard_True);
369 TopoDS_Vertex pVa=aVa;
370 pVa.Orientation(TopAbs_FORWARD);
371 gp_Pnt2d aPa=Coord2d(pVa, aEOuta, myFace);
372 aCoordVa.Append(aPa);
374 GetNextVertex (pVa, aEOuta, aVb);
376 gp_Pnt2d aPb=Coord2d(aVb, aEOuta, myFace);
378 const BOPAlgo_ListOfEdgeInfo& aLEInfoVb=mySmartMap.FindFromKey(aVb);
380 aTol=2.*Tolerance2D(aVb, aGAS);
383 TopoDS_Vertex aV1, aV2;
384 TopExp::Vertices(aEOuta, aV1, aV2);
385 Standard_Boolean bIsClosedEdge = aV1.IsNull() || aV2.IsNull() || aV1.IsSame(aV2);
386 Standard_Boolean bIsDegenerated = BRep_Tool::Degenerated(aEOuta);
387 Standard_Boolean bIsSeam = BRep_Tool::IsClosed(aEOuta, myFace);
389 anIt.Initialize(aLEInfoVb);
390 for (; anIt.More(); anIt.Next()) {
391 const BOPAlgo_EdgeInfo& anEI = anIt.Value();
392 const TopoDS_Edge& aE = anEI.Edge();
393 bIsDegenerated = bIsDegenerated || BRep_Tool::Degenerated(aE);
394 bIsSeam = bIsSeam || BRep_Tool::IsClosed(aE, myFace);
397 TopExp::Vertices(aE, aV1, aV2);
398 bIsClosedEdge = bIsClosedEdge || aV1.IsNull() || aV2.IsNull() || aV1.IsSame(aV2);
404 BOPCol_ListOfShape aBuf;
406 for (i=aNb; i>0; --i) {
407 const TopoDS_Shape& aVPrev=aVertVa(i);
408 const gp_Pnt2d& aPaPrev=aCoordVa(i);
409 const TopoDS_Shape& aEPrev=aLS(i);
413 anIsSameV=aVPrev.IsSame(aVb);
414 anIsSameV2d=Standard_False;
417 anIsSameV2d = Standard_True;
419 aD2=aPaPrev.SquareDistance(aPb);
420 anIsSameV2d =aD2<aTol2;
422 (bIsDegenerated || bIsSeam || bIsClosedEdge)) {
423 Standard_Real udist = fabs(aPaPrev.X() - aPb.X());
424 Standard_Real vdist = fabs(aPaPrev.Y() - aPb.Y());
425 Standard_Real aTolU = 2. * UTolerance2D(aVb, aGAS);
426 Standard_Real aTolV = 2. * VTolerance2D(aVb, aGAS);
428 if((udist > aTolU) ||
430 anIsSameV2d = Standard_False;
435 if (anIsSameV && anIsSameV2d) {
436 Standard_Integer iPriz;
438 if (aBuf.Extent()==2) {
439 if(aBuf.First().IsSame(aBuf.Last())) {
445 BOPAlgo_WireSplitter::MakeWire(aBuf, aW);
446 aCB.ChangeLoops().Append(aW);
459 BOPCol_SequenceOfShape aLSt, aVertVat;
460 BOPCol_SequenceOfPnt2d aCoordVat;
462 aVb=(*(TopoDS_Vertex *)(&aVertVa(i)));
464 for (j=1; j<=aNbj; ++j) {
466 aVertVat.Append(aVertVa(j));
467 aCoordVat.Append(aCoordVa(j));
483 aTol2D=2.*Tolerance2D(aVb, aGAS);
484 aTol2D2=1000.*aTol2D*aTol2D;//100.*aTol2D*aTol2D;
486 // anAngleIn in Vb from edge aEOuta
487 const BOPAlgo_ListOfEdgeInfo& aLEInfo=mySmartMap.FindFromKey(aVb);
489 anAngleIn=AngleIn(aEOuta, aLEInfo);
490 BOPCol_SequenceOfReal aRecomputedAngles;
492 Standard_Boolean bRecomputeAngle =
493 RecomputeAngles(aLEInfo, myFace, aPb, aVb, aGAS, aEOuta,
494 (bIsDegenerated || bIsSeam || bIsClosedEdge),
495 aTol2D, aRecomputedAngles);
499 BOPAlgo_EdgeInfo *pEdgeInfo=NULL;
502 anIsFound=Standard_False;
503 Standard_Integer aCurIndexE = 0;
504 anIt.Initialize(aLEInfo);
505 for (; anIt.More(); anIt.Next()) {
506 BOPAlgo_EdgeInfo& anEI=anIt.ChangeValue();
507 const TopoDS_Edge& aE=anEI.Edge();
508 anIsOut=!anEI.IsIn();
509 anIsNotPassed=!anEI.Passed();
511 if (anIsOut && anIsNotPassed) {
514 // Is there one way to go out of the vertex
515 // we have to use it only.
516 Standard_Integer iCnt;
517 iCnt=NbWaysOut (aLEInfo);
520 // no way to go . (Error)
525 // the one and only way to go out .
527 anIsFound=Standard_True;
531 if (aE.IsSame(aEOuta)) {
534 // Look for minimal angle and make the choice.
537 aP2Dx=Coord2dVf(aE, myFace);
539 aD2=aP2Dx.SquareDistance(aPb);
545 anAngleOut=anEI.Angle();
547 if(bRecomputeAngle) {
548 if(aCurIndexE <= aRecomputedAngles.Length()) {
549 anAngleOut = aRecomputedAngles.Value(aCurIndexE);
552 anAngle=ClockWiseAngle(anAngleIn, anAngleOut);
554 if (anAngle < aMinAngle) {
557 anIsFound=Standard_True;
560 } // for (; anIt.More(); anIt.Next())
563 // no way to go . (Error)
567 aEOutb=pEdgeInfo->Edge();
569 Path (aGAS, myFace, aVb, aEOutb, *pEdgeInfo, aLS,
570 aVertVa, aCoordVa, aCB, mySmartMap);
572 //=======================================================================
573 // function: ClockWiseAngle
575 //=======================================================================
576 Standard_Real ClockWiseAngle(const Standard_Real aAngleIn,
577 const Standard_Real aAngleOut)
579 Standard_Real aTwoPi=M_PI+M_PI;
580 Standard_Real dA, A1, A2, AIn, AOut ;
588 if (AOut >= aTwoPi) {
605 //else if (dA <= 1.e-15) {
606 else if (dA <= 1.e-14) {
611 //=======================================================================
614 //=======================================================================
615 gp_Pnt2d Coord2d (const TopoDS_Vertex& aV1,
616 const TopoDS_Edge& aE1,
617 const TopoDS_Face& aF)
619 Standard_Real aT, aFirst, aLast;
620 Handle(Geom2d_Curve) aC2D;
623 aT=BRep_Tool::Parameter (aV1, aE1, aF);
624 aC2D=BRep_Tool::CurveOnSurface(aE1, aF, aFirst, aLast);
625 aC2D->D0 (aT, aP2D1);
629 //=======================================================================
630 // function: Coord2dVf
632 //=======================================================================
633 gp_Pnt2d Coord2dVf (const TopoDS_Edge& aE,
634 const TopoDS_Face& aF)
636 Standard_Real aCoord=99.;
637 gp_Pnt2d aP2D1(aCoord, aCoord);
641 for (; aIt.More(); aIt.Next()) {
642 const TopoDS_Shape& aVx=aIt.Value();
643 if (aVx.Orientation()==TopAbs_FORWARD) {
645 const TopoDS_Vertex& aVxx=(*(TopoDS_Vertex *)(&aVx));// TopoDS::Vertex(aVx);
646 aP2D1=Coord2d(aVxx, aE, aF);
653 //=======================================================================
654 // function: NbWaysOut
656 //=======================================================================
657 Standard_Integer NbWaysOut(const BOPAlgo_ListOfEdgeInfo& aLEInfo)
659 Standard_Boolean bIsOut, bIsNotPassed;
660 Standard_Integer iCnt=0;
661 BOPAlgo_ListIteratorOfListOfEdgeInfo anIt;
663 anIt.Initialize(aLEInfo);
664 for (; anIt.More(); anIt.Next()) {
665 const BOPAlgo_EdgeInfo& anEI=anIt.Value();
668 bIsNotPassed=!anEI.Passed();
669 if (bIsOut && bIsNotPassed) {
676 //=======================================================================
679 //=======================================================================
680 Standard_Real AngleIn(const TopoDS_Edge& aEIn,
681 const BOPAlgo_ListOfEdgeInfo& aLEInfo)
683 Standard_Real anAngleIn;
684 Standard_Boolean anIsIn;
685 BOPAlgo_ListIteratorOfListOfEdgeInfo anIt;
687 anIt.Initialize(aLEInfo);
688 for (; anIt.More(); anIt.Next()) {
689 const BOPAlgo_EdgeInfo& anEdgeInfo=anIt.Value();
690 const TopoDS_Edge& aE=anEdgeInfo.Edge();
691 anIsIn=anEdgeInfo.IsIn();
693 if (anIsIn && aE==aEIn) {
694 anAngleIn=anEdgeInfo.Angle();
701 //=======================================================================
702 // function: GetNextVertex
704 //=======================================================================
705 void GetNextVertex(const TopoDS_Vertex& aV,
706 const TopoDS_Edge& aE,
712 for (; aIt.More(); aIt.Next()) {
713 const TopoDS_Shape& aVx=aIt.Value();
714 if (!aVx.IsEqual(aV)) {
715 aV1=(*(TopoDS_Vertex *)(&aVx));
721 //=======================================================================
724 //=======================================================================
725 Standard_Real Angle2D (const TopoDS_Vertex& aV,
726 const TopoDS_Edge& anEdge,
727 const TopoDS_Face& myFace,
728 const GeomAdaptor_Surface& aGAS,
729 const Standard_Boolean aFlag)
731 Standard_Real aFirst, aLast, aToler, dt, aTV, aTV1, anAngle, aTX;
734 Handle(Geom2d_Curve) aC2D;
736 aTV=BRep_Tool::Parameter (aV, anEdge, myFace);
737 if (Precision::IsInfinite(aTV)) {
741 BOPTools_AlgoTools2D::CurveOnSurface (anEdge, myFace, aC2D,
742 aFirst, aLast, aToler);
743 dt=2.*Tolerance2D(aV, aGAS);
745 //for case chl/927/r9
746 aTX=0.05*(aLast - aFirst);//aTX=0.25*(aLast - aFirst);
751 // to save direction of the curve as much as it possible
752 // in the case of big tolerances
756 if (fabs (aTV-aFirst) < fabs(aTV - aLast)) {
763 aC2D->D0 (aTV1, aPV1);
767 gp_Vec2d aV2DIn(aPV1, aPV);
771 gp_Vec2d aV2DOut(aPV, aPV1);
775 gp_Dir2d aDir2D(aV2D);
776 anAngle=Angle(aDir2D);
780 //=======================================================================
783 //=======================================================================
784 Standard_Real Angle (const gp_Dir2d& aDir2D)
786 gp_Dir2d aRefDir(1., 0.);
787 Standard_Real anAngle;
789 anAngle = aRefDir.Angle(aDir2D);
791 anAngle += M_PI + M_PI;
794 //=======================================================================
795 // function: Tolerance2D
797 //=======================================================================
798 Standard_Real Tolerance2D (const TopoDS_Vertex& aV,
799 const GeomAdaptor_Surface& aGAS)
801 Standard_Real aTol2D, anUr, aVr, aTolV3D;
802 GeomAbs_SurfaceType aType;
804 aType=aGAS.GetType();
805 aTolV3D=BRep_Tool::Tolerance(aV);
807 anUr=aGAS.UResolution(aTolV3D);
808 aVr =aGAS.VResolution(aTolV3D);
809 aTol2D=(aVr>anUr) ? aVr : anUr;
811 if (aTol2D < aTolV3D) {
814 if (aType==GeomAbs_BSplineSurface) {
820 //=======================================================================
821 // function: BuildPCurvesForPlane
823 //=======================================================================
824 void BuildPCurveForPlane (const BOPCol_ListOfShape myEdges,
825 const TopoDS_Face& myFace)
827 TopLoc_Location aLoc;
828 Handle(Geom2d_Curve) aC2D;
829 Handle(Geom_Plane) aGP;
830 Handle(Geom_RectangularTrimmedSurface) aGRTS;
832 const Handle(Geom_Surface)& aS = BRep_Tool::Surface(myFace, aLoc);
833 aGRTS=Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
835 aGP=Handle(Geom_Plane)::DownCast(aGRTS->BasisSurface());
838 aGP=Handle(Geom_Plane)::DownCast(aS);
846 BOPCol_ListIteratorOfListOfShape aIt;
849 aIt.Initialize(myEdges);
850 for(; aIt.More(); aIt.Next()) {
851 const TopoDS_Edge& aE=(*(TopoDS_Edge *)&aIt.Value());
852 BOPTools_AlgoTools2D::CurveOnSurface(aE, myFace, aC2D, aTolE);
853 aBB.UpdateEdge(aE, aC2D, myFace, aTolE);
856 //=======================================================================
857 //function : UTolerance2D
859 //=======================================================================
860 Standard_Real UTolerance2D (const TopoDS_Vertex& aV,
861 const GeomAdaptor_Surface& aGAS)
863 const Standard_Real aTolV3D = BRep_Tool::Tolerance(aV);
864 const Standard_Real anUr = aGAS.UResolution(aTolV3D);
869 //=======================================================================
870 //function : VTolerance2D
872 //=======================================================================
873 Standard_Real VTolerance2D (const TopoDS_Vertex& aV,
874 const GeomAdaptor_Surface& aGAS)
876 const Standard_Real aTolV3D = BRep_Tool::Tolerance(aV);
877 const Standard_Real anVr = aGAS.VResolution(aTolV3D);
882 //=======================================================================
883 // function: RecomputeAngles
885 //=======================================================================
886 Standard_Boolean RecomputeAngles(const BOPAlgo_ListOfEdgeInfo& aLEInfo,
887 const TopoDS_Face& theFace,
888 const gp_Pnt2d& thePb,
889 const TopoDS_Vertex& theVb,
890 const GeomAdaptor_Surface& theGAS,
891 const TopoDS_Edge& theEOuta,
892 const Standard_Boolean& bIsClosed,
893 const Standard_Real& theTol2D,
894 BOPCol_SequenceOfReal& theRecomputedAngles)
896 Standard_Boolean bRecomputeAngle = Standard_False;
897 BOPAlgo_ListIteratorOfListOfEdgeInfo anIt;
898 anIt.Initialize(aLEInfo);
900 for (; anIt.More(); anIt.Next()) {
901 const BOPAlgo_EdgeInfo& anEI=anIt.Value();
902 const TopoDS_Edge& aE=anEI.Edge();
903 Standard_Boolean anIsOut=!anEI.IsIn();
904 Standard_Boolean anIsNotPassed=!anEI.Passed();
906 if (anIsOut && anIsNotPassed) {
907 theRecomputedAngles.Append(anEI.Angle());
908 Standard_Integer acurindex = theRecomputedAngles.Length();
910 Standard_Boolean bRecomputeAngleLocal = Standard_False;
911 TopExp_Explorer anExp1(aE, TopAbs_VERTEX);
913 for(; anExp1.More(); anExp1.Next()) {
914 TopExp_Explorer anExp2(theEOuta, TopAbs_VERTEX);
915 Standard_Boolean existsInEdge = Standard_False;
917 for(; anExp2.More(); anExp2.Next()) {
918 if(anExp1.Current().IsSame(anExp2.Current())) {
919 existsInEdge = Standard_True;
925 bRecomputeAngleLocal = Standard_False;
928 bRecomputeAngleLocal = Standard_True;
930 bRecomputeAngle = bRecomputeAngle || bRecomputeAngleLocal;
932 if(!bRecomputeAngle) {
933 BOPAlgo_ListIteratorOfListOfEdgeInfo anIt2(aLEInfo);
935 for(; anIt2.More(); anIt2.Next()) {
936 const BOPAlgo_EdgeInfo& anEI2=anIt2.Value();
937 const TopoDS_Edge& aE2=anEI2.Edge();
941 Standard_Boolean anIsOut2=!anEI2.IsIn();
942 Standard_Boolean anIsNotPassed2=!anEI2.Passed();
944 if (anIsOut2 && anIsNotPassed2) {
945 anExp1.Init(aE, TopAbs_VERTEX);
947 for(; anExp1.More(); anExp1.Next()) {
948 TopExp_Explorer anExp2(aE2, TopAbs_VERTEX);
949 Standard_Boolean existsInEdge = Standard_False;
951 for(; anExp2.More(); anExp2.Next()) {
952 if(anExp1.Current().IsSame(anExp2.Current())) {
953 existsInEdge = Standard_True;
959 bRecomputeAngleLocal = Standard_False;
962 bRecomputeAngleLocal = Standard_True;
964 bRecomputeAngle = bRecomputeAngle || bRecomputeAngleLocal;
969 bRecomputeAngle = bRecomputeAngle || bRecomputeAngleLocal;
971 if(bRecomputeAngle) {
974 aP2Dx=Coord2dVf(aE, theFace);
975 Standard_Real aD = aP2Dx.Distance(thePb);
978 TopExp_Explorer anExp(aE, TopAbs_VERTEX);
980 for (; anExp.More(); anExp.Next()) {
981 const TopoDS_Vertex& aVx=*(TopoDS_Vertex*)(&anExp.Current());
982 if (aVx.Orientation()==TopAbs_FORWARD) {
986 Standard_Boolean bIgnore = Standard_False;
988 if(bIsClosed || aVf.IsNull() || !aVf.IsSame(theVb)) {
989 bIgnore = (aD > theTol2D);
992 if(!bIgnore && (theTol2D > M_PI)) {
993 Standard_Real udist = fabs(aP2Dx.X() - thePb.X());
994 Standard_Real vdist = fabs(aP2Dx.Y() - thePb.Y());
995 Standard_Real aTolU = 2. * UTolerance2D(theVb, theGAS);
996 Standard_Real aTolV = 2. * VTolerance2D(theVb, theGAS);
998 if((udist > aTolU) ||
1000 bIgnore = Standard_True;
1004 if((aD > Precision::Confusion()) && !bIgnore) {
1005 Standard_Real f1, l1;
1006 Handle(Geom2d_Curve) ac1 = BRep_Tool::CurveOnSurface(aE, theFace, f1, l1);
1008 Standard_Real aTV1 = BRep_Tool::Parameter (aVf, aE, theFace);
1009 Standard_Real aTV12 = 0.;
1010 Standard_Real dt1 = (l1 - f1) * 0.5;
1012 if (fabs (aTV1-f1) < fabs(aTV1 - l1)) {
1019 gp_Pnt2d aPointNew = ac1->Value(aTV12);
1020 gp_Vec2d aV2DOut(thePb, aPointNew);
1022 gp_Dir2d aDir2D(aV2DOut);
1023 Standard_Real anAngleOut = Angle(aDir2D);
1024 theRecomputedAngles.ChangeValue(acurindex) = anAngleOut;
1029 return bRecomputeAngle;