1 // Created on: 2001-04-09
2 // Created by: Peter KURNEV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <BOP_WireSplitter.ixx>
23 #include <gp_Pnt2d.hxx>
24 #include <gp_Vec2d.hxx>
26 #include <Geom_Curve.hxx>
27 #include <Geom2d_Curve.hxx>
30 #include <TopoDS_Vertex.hxx>
31 #include <TopoDS_Edge.hxx>
32 #include <TopoDS_Face.hxx>
33 #include <TopAbs_Orientation.hxx>
35 #include <BRep_Tool.hxx>
38 #include <TopExp_Explorer.hxx>
40 #include <TColgp_SequenceOfPnt2d.hxx>
42 #include <TopTools_SequenceOfShape.hxx>
43 #include <TopTools_ListOfShape.hxx>
44 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
46 #include <TopTools_IndexedMapOfShape.hxx>
48 #include <BOPTColStd_ListOfListOfShape.hxx>
49 #include <BOPTColStd_ListIteratorOfListOfListOfShape.hxx>
51 #include <BOPTools_Tools2D.hxx>
53 #include <BOP_EdgeInfo.hxx>
54 #include <BOP_ListOfEdgeInfo.hxx>
55 #include <BOP_ListIteratorOfListOfEdgeInfo.hxx>
56 #include <BOP_IndexedDataMapOfVertexListEdgeInfo.hxx>
59 #include <BRepAdaptor_Surface.hxx>
60 #include <GeomAdaptor_Surface.hxx>
61 #include <BRepAdaptor_Curve2d.hxx>
62 #include <TColStd_SequenceOfReal.hxx>
63 #include <Precision.hxx>
66 void Path (const GeomAdaptor_Surface& aGAS,
67 const TopoDS_Face& myFace,
68 const TopoDS_Vertex& aVa,
69 const TopoDS_Edge& aEOuta,
70 BOP_EdgeInfo& anEdgeInfo,
71 TopTools_SequenceOfShape& aLS,
72 TopTools_SequenceOfShape& aVertVa,
73 TColgp_SequenceOfPnt2d& aCoordVa,
74 BOPTColStd_ListOfListOfShape& myShapes,
75 BOP_IndexedDataMapOfVertexListEdgeInfo& mySmartMap);
79 Standard_Real Angle (const gp_Dir2d& aDir2D);
83 void GetNextVertex(const TopoDS_Vertex& aV,
84 const TopoDS_Edge& aE,
87 Standard_Real ClockWiseAngle(const Standard_Real aAngleIn,
88 const Standard_Real aAngleOut);
91 Standard_Real AngleIn(const TopoDS_Edge& aEIn,
92 const BOP_ListOfEdgeInfo& aLEInfo);
95 Standard_Real Angle2D (const TopoDS_Vertex& aV,
96 const TopoDS_Edge& anEdge,
97 const TopoDS_Face& myFace,
98 const GeomAdaptor_Surface& aGAS,
99 const Standard_Boolean aFlag);
101 gp_Pnt2d Coord2d (const TopoDS_Vertex& aV1,
102 const TopoDS_Edge& aE1,
103 const TopoDS_Face& aF);
105 gp_Pnt2d Coord2dVf (const TopoDS_Edge& aE,
106 const TopoDS_Face& aF);
108 Standard_Real Tolerance2D (const TopoDS_Vertex& aV,
109 const GeomAdaptor_Surface& aGAS);
112 Standard_Real UTolerance2D (const TopoDS_Vertex& aV,
113 const GeomAdaptor_Surface& aGAS);
115 Standard_Real VTolerance2D (const TopoDS_Vertex& aV,
116 const GeomAdaptor_Surface& aGAS);
119 Standard_Boolean RecomputeAngles(const BOP_ListOfEdgeInfo& aLEInfo,
120 const TopoDS_Face& theFace,
121 const gp_Pnt2d& thePb,
122 const TopoDS_Vertex& theVb,
123 const GeomAdaptor_Surface& theGAS,
124 const TopoDS_Edge& theEOuta,
125 const Standard_Boolean& bHasClosed,
126 const Standard_Real& theTol2D,
127 TColStd_SequenceOfReal& theRecomputedAngles);
130 Standard_Integer NbWaysOut(const BOP_ListOfEdgeInfo& );
133 //=======================================================================
134 // function: DoWithFace
136 //=======================================================================
137 void BOP_WireSplitter::DoWithFace()
141 TopExp_Explorer anExpEdges (myFace, TopAbs_EDGE);
142 for (; anExpEdges.More(); anExpEdges.Next()) {
143 const TopoDS_Edge& anEdge = TopoDS::Edge(anExpEdges.Current());
145 if (anEdge.Orientation()==TopAbs_INTERNAL){
149 myEdges.Append(anEdge);
153 //=======================================================================
154 // function: DoWithListOfEdges
156 //=======================================================================
157 void BOP_WireSplitter::DoWithListOfEdges(const TopTools_ListOfShape& aLE)
161 TopTools_ListIteratorOfListOfShape anItList;
163 anItList.Initialize(aLE);
164 for (; anItList.More(); anItList.Next()) {
165 const TopoDS_Edge& anEdge = TopoDS::Edge(anItList.Value());
167 if (anEdge.Orientation()==TopAbs_INTERNAL){
171 myEdges.Append(anEdge);
175 //=======================================================================
178 //=======================================================================
179 void BOP_WireSplitter::Do()
181 myIsDone=Standard_False;
182 myNothingToDo=Standard_True;
184 Standard_Integer index, i, aNb, aCntIn, aCntOut;
185 Standard_Boolean anIsIn;
186 Standard_Real anAngle;
188 BOP_ListOfEdgeInfo emptyInfo;
189 TopTools_ListIteratorOfListOfShape anItList;
191 // 1.Filling mySmartMap
194 anItList.Initialize(myEdges);
195 for (; anItList.More(); anItList.Next()) {
196 const TopoDS_Edge& anEdge = TopoDS::Edge(anItList.Value());
198 if (!BOPTools_Tools2D::HasCurveOnSurface (anEdge, myFace)) {
202 TopExp_Explorer anExpVerts (anEdge, TopAbs_VERTEX);
203 for (; anExpVerts.More(); anExpVerts.Next()) {
204 const TopoDS_Shape& aVertex= anExpVerts.Current();
206 index = mySmartMap.FindIndex(aVertex);
208 index=mySmartMap.Add(aVertex, emptyInfo);
211 BOP_ListOfEdgeInfo& aListOfEInfo=mySmartMap(index);
214 aEInfo.SetEdge(anEdge);
216 TopAbs_Orientation anOr=aVertex.Orientation();
218 if (anOr==TopAbs_FORWARD) {
219 aEInfo.SetInFlag(Standard_False);
222 else if (anOr==TopAbs_REVERSED) {
223 aEInfo.SetInFlag(Standard_True);
226 aListOfEInfo.Append(aEInfo);
230 aNb=mySmartMap.Extent();
233 myNothingToDo=Standard_True;
235 for (i=1; i<=aNb; i++) {
238 const BOP_ListOfEdgeInfo& aLEInfo= mySmartMap(i);
239 BOP_ListIteratorOfListOfEdgeInfo anIt(aLEInfo);
240 for (; anIt.More(); anIt.Next()) {
241 const BOP_EdgeInfo& anEdgeInfo=anIt.Value();
242 anIsIn=anEdgeInfo.IsIn();
250 if (aCntIn!=1 || aCntOut!=1) {
251 myNothingToDo=Standard_False;
256 // Each vertex has one edge In and one - Out. Good. But it is not enought
257 // to consider that nothing to do with this. We must check edges on TShape
258 // coinsidence. If there are such edges there is something to do with.
261 Standard_Integer aNbE, aNbMapEE;
262 TopTools_IndexedDataMapOfShapeListOfShape aMapEE;
263 aNbE=myEdges.Extent();
265 anItList.Initialize(myEdges);
266 for (; anItList.More(); anItList.Next()) {
267 const TopoDS_Shape& aE = anItList.Value();
269 if (!aMapEE.Contains(aE)) {
270 TopTools_ListOfShape aLEx;
272 aMapEE.Add(aE, aLEx);
275 TopTools_ListOfShape& aLEx=aMapEE.ChangeFromKey(aE);
280 Standard_Boolean bFlag;
282 aNbMapEE=aMapEE.Extent();
283 for (i=1; i<=aNbMapEE; i++) {
284 const TopTools_ListOfShape& aLEx=aMapEE(i);
291 const TopoDS_Shape& aE1=aLEx.First();
292 const TopoDS_Shape& aE2=aLEx.Last();
293 if (aE1.IsSame(aE2)) {
294 bFlag=Standard_False;
299 bFlag=Standard_False;
303 myNothingToDo=myNothingToDo && bFlag;
308 myIsDone=Standard_True;
312 // 3. Angles in mySmartMap
313 BRepAdaptor_Surface aBAS(myFace);
314 const GeomAdaptor_Surface& aGAS=aBAS.Surface();
315 for (i=1; i<=aNb; i++) {
316 const TopoDS_Vertex& aV=TopoDS::Vertex (mySmartMap.FindKey(i));
317 const BOP_ListOfEdgeInfo& aLEInfo= mySmartMap(i);
319 BOP_ListIteratorOfListOfEdgeInfo anIt(aLEInfo);
320 for (; anIt.More(); anIt.Next()) {
321 BOP_EdgeInfo& anEdgeInfo=anIt.Value();
322 const TopoDS_Edge& aE=anEdgeInfo.Edge();
324 TopoDS_Vertex aVV=aV;
326 anIsIn=anEdgeInfo.IsIn();
329 aVV.Orientation(TopAbs_REVERSED);
330 anAngle=Angle2D (aVV, aE, myFace, aGAS, Standard_True);
335 aVV.Orientation(TopAbs_FORWARD);
336 anAngle=Angle2D (aVV, aE, myFace, aGAS, Standard_False);
338 anEdgeInfo.SetAngle(anAngle);
345 Standard_Boolean anIsOut, anIsNotPassed;
347 TopTools_SequenceOfShape aLS, aVertVa;
348 TColgp_SequenceOfPnt2d aCoordVa;
350 BOP_ListIteratorOfListOfEdgeInfo anIt;
352 for (i=1; i<=aNb; i++) {
353 const TopoDS_Vertex aVa=TopoDS::Vertex (mySmartMap.FindKey(i));
354 const BOP_ListOfEdgeInfo& aLEInfo=mySmartMap(i);
356 anIt.Initialize(aLEInfo);
357 for (; anIt.More(); anIt.Next()) {
358 BOP_EdgeInfo& anEdgeInfo=anIt.Value();
359 const TopoDS_Edge& aEOuta=anEdgeInfo.Edge();
361 anIsOut=!anEdgeInfo.IsIn();
362 anIsNotPassed=!anEdgeInfo.Passed();
364 if (anIsOut && anIsNotPassed) {
370 Path(aGAS, myFace, aVa, aEOuta, anEdgeInfo, aLS,
371 aVertVa, aCoordVa, myShapes, mySmartMap);
377 Standard_Integer aNbV, aNbE;
378 TopoDS_Vertex aV1, aV2;
379 BOPTColStd_ListOfListOfShape aShapes;
380 BOPTColStd_ListIteratorOfListOfListOfShape anItW(myShapes);
382 for (; anItW.More(); anItW.Next()) {
383 TopTools_IndexedMapOfShape aMV, aME;
384 const TopTools_ListOfShape& aLE=anItW.Value();
385 TopTools_ListIteratorOfListOfShape anItE(aLE);
386 for (; anItE.More(); anItE.Next()) {
387 const TopoDS_Edge& aE=TopoDS::Edge(anItE.Value());
389 TopExp::Vertices(aE, aV1, aV2);
401 anItW.Initialize(aShapes);
402 for (; anItW.More(); anItW.Next()) {
403 const TopTools_ListOfShape& aLE=anItW.Value();
404 myShapes.Append(aLE);
408 myIsDone=Standard_True;
410 //=======================================================================
413 //=======================================================================
414 void Path (const GeomAdaptor_Surface& aGAS,
415 const TopoDS_Face& myFace,
416 const TopoDS_Vertex& aVa,
417 const TopoDS_Edge& aEOuta,
418 BOP_EdgeInfo& anEdgeInfo,
419 TopTools_SequenceOfShape& aLS,
420 TopTools_SequenceOfShape& aVertVa,
421 TColgp_SequenceOfPnt2d& aCoordVa,
422 BOPTColStd_ListOfListOfShape& myShapes,
423 BOP_IndexedDataMapOfVertexListEdgeInfo& mySmartMap)
426 Standard_Integer i,j, aNb, aNbj;
427 Standard_Real aD, aTol=1.e-7, anAngleIn, anAngleOut, anAngle, aMinAngle;
428 Standard_Real aTol2D, aTolVb, aTolVPrev;
429 Standard_Boolean anIsSameV2d, anIsSameV, anIsFound, anIsOut, anIsNotPassed;
430 BOP_ListIteratorOfListOfEdgeInfo anIt;
437 // Do not escape through edge from which you enter
440 const TopoDS_Shape& anEPrev=aLS(aNb);
442 if (anEPrev.IsSame(aEOuta)) {
448 anEdgeInfo.SetPassed(Standard_True);
452 TopoDS_Vertex pVa=aVa;
453 pVa.Orientation(TopAbs_FORWARD);
454 gp_Pnt2d aPa=Coord2d(pVa, aEOuta, myFace);
455 aCoordVa.Append(aPa);
457 GetNextVertex (pVa, aEOuta, aVb);
459 gp_Pnt2d aPb=Coord2d(aVb, aEOuta, myFace);
461 const BOP_ListOfEdgeInfo& aLEInfoVb=mySmartMap.FindFromKey(aVb);
463 TopoDS_Vertex aV1, aV2;
464 TopExp::Vertices(aEOuta, aV1, aV2);
465 Standard_Boolean bHasClosedEdge = aV1.IsNull() || aV2.IsNull() || aV1.IsSame(aV2);
466 Standard_Boolean bHasDegenerated = BRep_Tool::Degenerated(aEOuta);
467 Standard_Boolean bHasSeam = BRep_Tool::IsClosed(aEOuta, myFace);
468 anIt.Initialize(aLEInfoVb);
470 for (; anIt.More(); anIt.Next()) {
471 BOP_EdgeInfo& anEI=anIt.Value();
472 const TopoDS_Edge& aE=anEI.Edge();
473 bHasDegenerated = bHasDegenerated || BRep_Tool::Degenerated(aE);
474 bHasSeam = bHasSeam || BRep_Tool::IsClosed(aE, myFace);
477 TopExp::Vertices(aE, aV1, aV2);
478 bHasClosedEdge = bHasClosedEdge || aV1.IsNull() || aV2.IsNull() || aV1.IsSame(aV2);
484 TopTools_ListOfShape aBuf;
485 for (i=aNb; i>0; i--) {
486 const TopoDS_Shape& aVPrev=aVertVa(i);
487 const gp_Pnt2d& aPaPrev=aCoordVa(i);
488 const TopoDS_Shape& aEPrev=aLS(i);
492 anIsSameV=aVPrev.IsSame(aVb);
493 anIsSameV2d = Standard_False;
496 anIsSameV2d = Standard_True;
498 if(bHasDegenerated || bHasSeam || bHasClosedEdge) {
499 aTolVb =BRep_Tool::Tolerance(TopoDS::Vertex(aVb));
500 aTolVPrev=BRep_Tool::Tolerance(TopoDS::Vertex(aVPrev));
501 aTol=aTolVb+aTolVPrev;
503 aTol=2.*Tolerance2D(aVb, aGAS);
504 aD=aPaPrev.Distance(aPb);
505 anIsSameV2d = (aD < aTol);
508 Standard_Real udist = fabs(aPaPrev.X() - aPb.X());
509 Standard_Real vdist = fabs(aPaPrev.Y() - aPb.Y());
510 Standard_Real aTolU = 2. * UTolerance2D(aVb, aGAS);
511 Standard_Real aTolV = 2. * VTolerance2D(aVb, aGAS);
513 if((udist > aTolU) ||
515 anIsSameV2d = Standard_False;
522 if (anIsSameV && anIsSameV2d) {
523 myShapes.Append(aBuf);
525 TopTools_SequenceOfShape aLSt, aVertVat;
526 TColgp_SequenceOfPnt2d aCoordVat;
538 aVb=TopoDS::Vertex(aVertVa(i));
540 for (j=1; j<=aNbj; j++) {
542 aVertVat.Append(aVertVa(j));
543 aCoordVat.Append(aCoordVa(j));
559 aTol2D=2.*Tolerance2D(aVb, aGAS);
561 // anAngleIn in Vb from edge aEOuta
562 const BOP_ListOfEdgeInfo& aLEInfo=mySmartMap.FindFromKey(aVb);
564 anAngleIn=AngleIn(aEOuta, aLEInfo);
567 BOP_EdgeInfo *pEdgeInfo=NULL;
570 anIsFound=Standard_False;
572 TColStd_SequenceOfReal aRecomputedAngles;
574 Standard_Boolean bRecomputeAngle =
575 RecomputeAngles(aLEInfo, myFace, aPb, aVb, aGAS, aEOuta,
576 (bHasDegenerated || bHasSeam || bHasClosedEdge),
577 aTol2D, aRecomputedAngles);
579 Standard_Integer aCurIndexE = 0;
581 anIt.Initialize(aLEInfo);
582 for (; anIt.More(); anIt.Next()) {
583 BOP_EdgeInfo& anEI=anIt.Value();
584 const TopoDS_Edge& aE=anEI.Edge();
585 anIsOut=!anEI.IsIn();
586 anIsNotPassed=!anEI.Passed();
588 if (anIsOut && anIsNotPassed) {
591 // Is there one way to go out of the vertex
592 // we have to use it only.
593 Standard_Integer iCnt;
594 iCnt=NbWaysOut (aLEInfo);
597 // no way to go . (Error)
602 // the one and only way to go out .
604 anIsFound=Standard_True;
608 // Look for minimal angle and make the choice.
611 aP2Dx=Coord2dVf(aE, myFace);
613 aD=aP2Dx.Distance(aPb);
619 anAngleOut=anEI.Angle();
621 if(bRecomputeAngle) {
622 if(aCurIndexE <= aRecomputedAngles.Length()) {
623 anAngleOut = aRecomputedAngles.Value(aCurIndexE);
627 anAngle=ClockWiseAngle(anAngleIn, anAngleOut);
628 if (anAngle < aMinAngle) {
631 anIsFound=Standard_True;
634 } // for (; anIt.More(); anIt.Next())
637 // no way to go . (Error)
641 aEOutb=pEdgeInfo->Edge();
642 Path (aGAS, myFace, aVb, aEOutb, *pEdgeInfo, aLS,
643 aVertVa, aCoordVa, myShapes, mySmartMap);
645 //=======================================================================
646 // function: Coord2dVf
648 //=======================================================================
649 gp_Pnt2d Coord2dVf (const TopoDS_Edge& aE,
650 const TopoDS_Face& aF)
652 TopExp_Explorer anExp(aE, TopAbs_VERTEX);
653 for (; anExp.More(); anExp.Next()) {
654 const TopoDS_Vertex& aVx=TopoDS::Vertex(anExp.Current());
655 if (aVx.Orientation()==TopAbs_FORWARD)
656 return Coord2d(aVx, aE, aF);
658 const Standard_Real aCoord=99.;
659 const gp_Pnt2d aP2D1(aCoord, aCoord);
662 //=======================================================================
663 // function: Tolerance2D
665 //=======================================================================
666 Standard_Real Tolerance2D (const TopoDS_Vertex& aV,
667 const GeomAdaptor_Surface& aGAS)
669 const GeomAbs_SurfaceType aType=aGAS.GetType();
670 const Standard_Real aTolV3D=BRep_Tool::Tolerance(aV);
671 const Standard_Real aUr=aGAS.UResolution(aTolV3D);
672 const Standard_Real aVr=aGAS.VResolution(aTolV3D);
674 Standard_Real aTol2D=(aVr>aUr) ? aVr : aUr;
676 if (aType==GeomAbs_BSplineSurface || aType==GeomAbs_Sphere) {
677 if (aTol2D < aTolV3D)
680 //modified by NIZNHY-PKV Wed Jul 5 16:44:59 2006f
681 else if (aType==GeomAbs_BSplineSurface) {
684 //modified by NIZNHY-PKV Wed Jul 5 16:45:02 2006t
689 //=======================================================================
692 //=======================================================================
693 gp_Pnt2d Coord2d (const TopoDS_Vertex& aV1,
694 const TopoDS_Edge& aE1,
695 const TopoDS_Face& aF)
697 const Standard_Real t=BRep_Tool::Parameter (aV1, aE1, aF);
699 Standard_Real aFirst, aLast, aToler;
700 Handle(Geom2d_Curve) aC2D;
701 BOPTools_Tools2D::CurveOnSurface
702 (aE1, aF, aC2D, aFirst, aLast, aToler, Standard_True);
709 //=======================================================================
712 //=======================================================================
713 Standard_Real AngleIn(const TopoDS_Edge& aEIn,
714 const BOP_ListOfEdgeInfo& aLEInfo)
716 BOP_ListIteratorOfListOfEdgeInfo anIt(aLEInfo);
717 for (; anIt.More(); anIt.Next()) {
718 const BOP_EdgeInfo& anEdgeInfo=anIt.Value();
719 const TopoDS_Edge& aE=anEdgeInfo.Edge();
720 const Standard_Boolean anIsIn=anEdgeInfo.IsIn();
722 if (anIsIn && aE==aEIn)
723 return anEdgeInfo.Angle();
727 //=======================================================================
728 // function: ClockWiseAngle
730 //=======================================================================
731 Standard_Real ClockWiseAngle(const Standard_Real aAngleIn,
732 const Standard_Real aAngleOut)
734 const Standard_Real aTwoPi = M_PI + M_PI;
735 Standard_Real dA, A1, A2, AIn, AOut ;
743 if (AOut >= aTwoPi) {
760 //else if (dA <= 1.e-15) {
761 else if (dA <= 1.e-14) {
766 //=======================================================================
767 // function: GetNextVertex
769 //=======================================================================
770 void GetNextVertex(const TopoDS_Vertex& aV,
771 const TopoDS_Edge& aE,
774 TopExp_Explorer anExp(aE, TopAbs_VERTEX);
775 for (; anExp.More(); anExp.Next()) {
776 const TopoDS_Vertex& aVx=TopoDS::Vertex(anExp.Current());
777 if (!aVx.IsEqual(aV)) {
784 //=======================================================================
787 //=======================================================================
788 Standard_Real Angle2D (const TopoDS_Vertex& aV,
789 const TopoDS_Edge& anEdge,
790 const TopoDS_Face& myFace,
791 const GeomAdaptor_Surface& aGAS,
792 const Standard_Boolean aFlag)
794 const Standard_Real aTV=BRep_Tool::Parameter (aV, anEdge, myFace);
795 if (Precision::IsInfinite(aTV))
798 Handle(Geom2d_Curve) aC2D;
799 Standard_Real aFirst, aLast, aToler;
800 BOPTools_Tools2D::CurveOnSurface (anEdge, myFace, aC2D, aFirst, aLast, aToler, Standard_True);
805 Standard_Real dt=Tolerance2D(aV, aGAS);
806 const Standard_Real dtmax=(aLast - aFirst) * 0.25;
808 // to save direction of the curve as much as it possible
809 // in the case of big tolerances
812 const Standard_Real aTV1 = (fabs (aTV-aFirst) < fabs(aTV - aLast))? aTV + dt : aTV - dt;
816 aC2D->D0 (aTV1, aPV1);
817 const gp_XY aV2D( aFlag? (aPV.XY()-aPV1.XY()) : (aPV1.XY()-aPV.XY()) );
819 //See http://www.opencascade.org/org/forum/thread_17712/
820 if (aV2D.SquareModulus() <= gp::Resolution()*gp::Resolution())
823 const gp_Dir2d aDir2D(aV2D);
825 return Angle(aDir2D);
827 //=======================================================================
830 //=======================================================================
831 Standard_Real Angle (const gp_Dir2d& aDir2D)
833 const Standard_Real anAngle = gp_Dir2d(1.,0.).Angle(aDir2D);
834 return ((anAngle < 0.)? anAngle + M_PI + M_PI : anAngle);
837 //=======================================================================
838 // function: NbWaysOut
840 //=======================================================================
841 Standard_Integer NbWaysOut(const BOP_ListOfEdgeInfo& aLEInfo)
843 Standard_Integer iCnt=0;
845 BOP_ListIteratorOfListOfEdgeInfo anIt(aLEInfo);
846 for (; anIt.More(); anIt.Next()) {
847 const BOP_EdgeInfo& anEI=anIt.Value();
849 //const TopoDS_Edge& aE=anEI.Edge();
850 const Standard_Boolean bIsOut=!anEI.IsIn();
851 const Standard_Boolean bIsNotPassed=!anEI.Passed();
852 if (bIsOut && bIsNotPassed)
858 //=======================================================================
859 //function : UTolerance2D
861 //=======================================================================
862 Standard_Real UTolerance2D (const TopoDS_Vertex& aV,
863 const GeomAdaptor_Surface& aGAS)
865 const Standard_Real aTolV3D = BRep_Tool::Tolerance(aV);
866 const Standard_Real anUr = aGAS.UResolution(aTolV3D);
871 //=======================================================================
872 //function : VTolerance2D
874 //=======================================================================
875 Standard_Real VTolerance2D (const TopoDS_Vertex& aV,
876 const GeomAdaptor_Surface& aGAS)
878 const Standard_Real aTolV3D = BRep_Tool::Tolerance(aV);
879 const Standard_Real anVr = aGAS.VResolution(aTolV3D);
883 //=======================================================================
884 // function: RecomputeAngles
886 //=======================================================================
887 Standard_Boolean RecomputeAngles(const BOP_ListOfEdgeInfo& aLEInfo,
888 const TopoDS_Face& theFace,
889 const gp_Pnt2d& thePb,
890 const TopoDS_Vertex& theVb,
891 const GeomAdaptor_Surface& theGAS,
892 const TopoDS_Edge& theEOuta,
893 const Standard_Boolean& bHasClosed,
894 const Standard_Real& theTol2D,
895 TColStd_SequenceOfReal& theRecomputedAngles)
897 Standard_Boolean bRecomputeAngle = Standard_False;
898 BOP_ListIteratorOfListOfEdgeInfo anIt;
899 anIt.Initialize(aLEInfo);
901 for (; anIt.More(); anIt.Next()) {
902 BOP_EdgeInfo& anEI=anIt.Value();
903 const TopoDS_Edge& aE=anEI.Edge();
904 Standard_Boolean anIsOut=!anEI.IsIn();
905 Standard_Boolean anIsNotPassed=!anEI.Passed();
907 if (anIsOut && anIsNotPassed) {
908 theRecomputedAngles.Append(anEI.Angle());
909 Standard_Integer acurindex = theRecomputedAngles.Length();
911 Standard_Boolean bRecomputeAngleLocal = Standard_False;
912 TopExp_Explorer anExp1(aE, TopAbs_VERTEX);
914 for(; anExp1.More(); anExp1.Next()) {
915 TopExp_Explorer anExp2(theEOuta, TopAbs_VERTEX);
916 Standard_Boolean existsInEdge = Standard_False;
918 for(; anExp2.More(); anExp2.Next()) {
919 if(anExp1.Current().IsSame(anExp2.Current())) {
920 existsInEdge = Standard_True;
926 bRecomputeAngleLocal = Standard_False;
929 bRecomputeAngleLocal = Standard_True;
931 bRecomputeAngle = bRecomputeAngle || bRecomputeAngleLocal;
933 if(!bRecomputeAngle) {
934 BOP_ListIteratorOfListOfEdgeInfo anIt2(aLEInfo);
936 for(; anIt2.More(); anIt2.Next()) {
937 BOP_EdgeInfo& anEI2=anIt2.Value();
938 const TopoDS_Edge& aE2=anEI2.Edge();
942 Standard_Boolean anIsOut2=!anEI2.IsIn();
943 Standard_Boolean anIsNotPassed2=!anEI2.Passed();
945 if (anIsOut2 && anIsNotPassed2) {
946 anExp1.Init(aE, TopAbs_VERTEX);
948 for(; anExp1.More(); anExp1.Next()) {
949 TopExp_Explorer anExp2(aE2, TopAbs_VERTEX);
950 Standard_Boolean existsInEdge = Standard_False;
952 for(; anExp2.More(); anExp2.Next()) {
953 if(anExp1.Current().IsSame(anExp2.Current())) {
954 existsInEdge = Standard_True;
960 bRecomputeAngleLocal = Standard_False;
963 bRecomputeAngleLocal = Standard_True;
965 bRecomputeAngle = bRecomputeAngle || bRecomputeAngleLocal;
970 bRecomputeAngle = bRecomputeAngle || bRecomputeAngleLocal;
972 if(bRecomputeAngle) {
975 aP2Dx=Coord2dVf(aE, theFace);
976 Standard_Real aD = aP2Dx.Distance(thePb);
979 TopExp_Explorer anExp(aE, TopAbs_VERTEX);
981 for (; anExp.More(); anExp.Next()) {
982 const TopoDS_Vertex& aVx=TopoDS::Vertex(anExp.Current());
983 if (aVx.Orientation()==TopAbs_FORWARD) {
987 Standard_Boolean bIgnore = Standard_False;
989 if(bHasClosed || aVf.IsNull() || !aVf.IsSame(theVb)) {
990 bIgnore = (aD > theTol2D);
993 if(!bIgnore && (theTol2D > M_PI)) {
994 Standard_Real udist = fabs(aP2Dx.X() - thePb.X());
995 Standard_Real vdist = fabs(aP2Dx.Y() - thePb.Y());
996 Standard_Real aTolU = 2. * UTolerance2D(theVb, theGAS);
997 Standard_Real aTolV = 2. * VTolerance2D(theVb, theGAS);
999 if((udist > aTolU) ||
1001 bIgnore = Standard_True;
1005 if((aD > Precision::Confusion()) && !bIgnore) {
1006 Standard_Real f1, l1;
1007 Handle(Geom2d_Curve) ac1 = BRep_Tool::CurveOnSurface(aE, theFace, f1, l1);
1009 Standard_Real aTV1 = BRep_Tool::Parameter (aVf, aE, theFace);
1010 Standard_Real aTV12 = 0.;
1011 Standard_Real dt1 = (l1 - f1) * 0.5;
1013 if (fabs (aTV1-f1) < fabs(aTV1 - l1)) {
1020 gp_Pnt2d aPointNew = ac1->Value(aTV12);
1021 gp_Vec2d aV2DOut(thePb, aPointNew);
1023 gp_Dir2d aDir2D(aV2DOut);
1024 Standard_Real anAngleOut = Angle(aDir2D);
1025 theRecomputedAngles.ChangeValue(acurindex) = anAngleOut;
1030 return bRecomputeAngle;