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 <BOPAlgo_WireEdgeSet.hxx>
16 #include <BOPAlgo_WireSplitter.hxx>
17 #include <BOPTools_AlgoTools2D.hxx>
18 #include <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepAdaptor_Surface.hxx>
21 #include <Geom2d_Curve.hxx>
22 #include <Geom2d_Line.hxx>
23 #include <Geom2dAdaptor_Curve.hxx>
24 #include <Geom2dInt_GInter.hxx>
25 #include <Geom_Plane.hxx>
26 #include <Geom_RectangularTrimmedSurface.hxx>
27 #include <Geom_Surface.hxx>
28 #include <GeomAdaptor_Surface.hxx>
29 #include <gp_Dir2d.hxx>
30 #include <gp_Pnt2d.hxx>
31 #include <gp_Vec2d.hxx>
32 #include <IntRes2d_Domain.hxx>
33 #include <IntRes2d_IntersectionPoint.hxx>
34 #include <Precision.hxx>
36 #include <TopExp_Explorer.hxx>
37 #include <TopLoc_Location.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Face.hxx>
41 #include <TopoDS_Iterator.hxx>
42 #include <TopoDS_Vertex.hxx>
43 #include <TopoDS_Wire.hxx>
44 #include <TopTools_ShapeMapHasher.hxx>
45 #include <Geom2dLProp_CLProps2d.hxx>
46 #include <TColgp_SequenceOfPnt2d.hxx>
47 #include <TColStd_SequenceOfReal.hxx>
48 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
49 #include <TopTools_ListOfShape.hxx>
50 #include <TopTools_MapOfShape.hxx>
51 #include <TopTools_SequenceOfShape.hxx>
53 typedef NCollection_DataMap \
54 <TopoDS_Shape, Standard_Boolean, TopTools_ShapeMapHasher> \
55 MyDataMapOfShapeBoolean;
59 Standard_Real Angle (const gp_Dir2d& aDir2D);
62 Standard_Real Angle2D (const TopoDS_Vertex& aV,
63 const TopoDS_Edge& anEdge,
64 const TopoDS_Face& myFace,
65 const GeomAdaptor_Surface& aGAS,
66 const Standard_Boolean aFlag,
67 const Handle(IntTools_Context)& theContext);
70 void GetNextVertex(const TopoDS_Vertex& aV,
71 const TopoDS_Edge& aE,
75 Standard_Real AngleIn(const TopoDS_Edge& aEIn,
76 const BOPAlgo_ListOfEdgeInfo& aLEInfo);
79 Standard_Integer NbWaysOut(const BOPAlgo_ListOfEdgeInfo& aLEInfo);
82 gp_Pnt2d Coord2dVf (const TopoDS_Edge& aE,
83 const TopoDS_Face& aF);
86 gp_Pnt2d Coord2d (const TopoDS_Vertex& aV1,
87 const TopoDS_Edge& aE1,
88 const TopoDS_Face& aF);
91 Standard_Real ClockWiseAngle(const Standard_Real aAngleIn,
92 const Standard_Real aAngleOut);
95 void Path (const GeomAdaptor_Surface& aGAS,
96 const TopoDS_Face& myFace,
97 const TopoDS_Vertex& aVa,
98 const TopoDS_Edge& aEOuta,
99 BOPAlgo_EdgeInfo& anEdgeInfo,
100 TopTools_SequenceOfShape& aLS,
101 TopTools_SequenceOfShape& aVertVa,
102 TColgp_SequenceOfPnt2d& aCoordVa,
103 BOPTools_ConnexityBlock& aCB,
104 BOPAlgo_IndexedDataMapOfShapeListOfEdgeInfo& mySmartMap,
105 MyDataMapOfShapeBoolean aVertMap);
108 Standard_Real Angle (const gp_Dir2d& aDir2D);
111 Standard_Real Tolerance2D (const TopoDS_Vertex& aV,
112 const GeomAdaptor_Surface& aGAS);
117 Standard_Real UTolerance2D (const TopoDS_Vertex& aV,
118 const GeomAdaptor_Surface& aGAS);
120 Standard_Real VTolerance2D (const TopoDS_Vertex& aV,
121 const GeomAdaptor_Surface& aGAS);
124 void RefineAngles(const TopoDS_Face& myFace,
125 const TopTools_ListOfShape&,
126 BOPAlgo_IndexedDataMapOfShapeListOfEdgeInfo&,
127 const Handle(IntTools_Context)&);
131 void RefineAngles(const TopoDS_Vertex& ,
133 const TopTools_MapOfShape& ,
134 BOPAlgo_ListOfEdgeInfo&,
135 const Handle(IntTools_Context)&);
138 Standard_Boolean RefineAngle2D(const TopoDS_Vertex& ,
141 const Standard_Real ,
142 const Standard_Real ,
145 const Handle(IntTools_Context)& );
147 //=======================================================================
148 //function : SplitBlock
150 //=======================================================================
151 void BOPAlgo_WireSplitter::SplitBlock(const TopoDS_Face& myFace,
152 BOPTools_ConnexityBlock& aCB,
153 const Handle(IntTools_Context)& theContext)
155 Standard_Boolean bNothingToDo, bIsClosed, bIsIN;
156 Standard_Integer aIx, aNb, i, aCntIn, aCntOut;
157 Standard_Real aAngle;
158 TopAbs_Orientation aOr;
159 TopoDS_Iterator aItS;
162 TopTools_ListIteratorOfListOfShape aIt;
163 BOPAlgo_ListIteratorOfListOfEdgeInfo aItLEI;
165 BOPAlgo_IndexedDataMapOfShapeListOfEdgeInfo mySmartMap(100);
166 MyDataMapOfShapeBoolean aVertMap;
168 const TopTools_ListOfShape& myEdges=aCB.Shapes();
170 // 1.Filling mySmartMap
171 aIt.Initialize(myEdges);
172 for(; aIt.More(); aIt.Next()) {
173 const TopoDS_Edge& aE=(*(TopoDS_Edge *)&aIt.Value());
174 if (!BOPTools_AlgoTools2D::HasCurveOnSurface (aE, myFace)) {
178 bIsClosed = BRep_Tool::Degenerated(aE) ||
179 BRep_Tool::IsClosed(aE, myFace);
182 for(i = 0; aItS.More(); aItS.Next(), ++i) {
183 const TopoDS_Shape& aV = aItS.Value();
184 aIx = mySmartMap.FindIndex(aV);
186 BOPAlgo_ListOfEdgeInfo aLEIx;
187 aIx = mySmartMap.Add(aV, aLEIx);
190 BOPAlgo_ListOfEdgeInfo& aLEI = mySmartMap(aIx);
191 BOPAlgo_EdgeInfo aEI;
194 aOr = aV.Orientation();
195 bIsIN = (aOr == TopAbs_REVERSED);
196 aEI.SetInFlag(bIsIN);
202 bIsClosed = bIsClosed || aV1.IsSame(aV);
205 if (aVertMap.IsBound(aV)) {
207 aVertMap.ChangeFind(aV) = bIsClosed;
210 aVertMap.Bind(aV, bIsClosed);
215 aNb=mySmartMap.Extent();
217 bNothingToDo=Standard_True;
218 for (i=1; i<=aNb; i++) {
221 const BOPAlgo_ListOfEdgeInfo& aLEInfo= mySmartMap(i);
222 BOPAlgo_ListIteratorOfListOfEdgeInfo anIt(aLEInfo);
223 for (; anIt.More(); anIt.Next()) {
224 const BOPAlgo_EdgeInfo& aEI=anIt.Value();
232 if (aCntIn!=1 || aCntOut!=1) {
233 bNothingToDo=Standard_False;
238 // Each vertex has one edge In and one - Out. Good. But it is not enought
239 // to consider that nothing to do with this. We must check edges on TShape
240 // coinsidence. If there are such edges there is something to do with.
242 Standard_Integer aNbE, aNbMapEE;
243 Standard_Boolean bFlag;
245 TopTools_IndexedDataMapOfShapeListOfShape aMapEE(100);
246 aNbE=myEdges.Extent();
248 aIt.Initialize(myEdges);
249 for (; aIt.More(); aIt.Next()) {
250 const TopoDS_Shape& aE = aIt.Value();
251 if (!aMapEE.Contains(aE)) {
252 TopTools_ListOfShape aLEx;
254 aMapEE.Add(aE, aLEx);
257 TopTools_ListOfShape& aLEx=aMapEE.ChangeFromKey(aE);
263 aNbMapEE=aMapEE.Extent();
264 for (i=1; i<=aNbMapEE; ++i) {
265 const TopTools_ListOfShape& aLEx=aMapEE(i);
267 if (aNbE==1) {// usual case
271 const TopoDS_Shape& aE1=aLEx.First();
272 const TopoDS_Shape& aE2=aLEx.Last();
273 if (aE1.IsSame(aE2)) {
274 bFlag=Standard_False;
279 bFlag=Standard_False;
283 bNothingToDo=bNothingToDo && bFlag;
284 } // if (bNothingToDo) {
288 TopTools_ListOfShape& aLECB=aCB.ChangeShapes();
289 BOPAlgo_WireSplitter::MakeWire(aLECB, aW);
290 TopTools_ListOfShape& aLoops=aCB.ChangeLoops();
296 // 3. Angles in mySmartMap
297 const BRepAdaptor_Surface& aBAS = theContext->SurfaceAdaptor(myFace);
298 const GeomAdaptor_Surface& aGAS=aBAS.Surface();
300 for (i=1; i<=aNb; i++) {
301 const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&mySmartMap.FindKey(i)));
302 const BOPAlgo_ListOfEdgeInfo& aLEI= mySmartMap(i);
303 aItLEI.Initialize(aLEI);
304 for (; aItLEI.More(); aItLEI.Next()) {
305 BOPAlgo_EdgeInfo& aEI=aItLEI.ChangeValue();
306 const TopoDS_Edge& aE=aEI.Edge();
310 aOr = bIsIN ? TopAbs_REVERSED : TopAbs_FORWARD;
311 aVV.Orientation(aOr);
312 aAngle = Angle2D(aVV, aE, myFace, aGAS, bIsIN, theContext);
313 aEI.SetAngle(aAngle);
315 }// for (i=1; i<=aNb; i++) {
317 //Theme: The treatment p-curves convergent in node.
318 //The refining the angles of p-curves taking into account
319 //bounding curves if exist.
320 RefineAngles(myFace, myEdges, mySmartMap, theContext);
324 Standard_Boolean bIsOut, bIsNotPassed;
325 TopTools_SequenceOfShape aLS, aVertVa;
326 TColgp_SequenceOfPnt2d aCoordVa;
328 for (i=1; i<=aNb; ++i) {
329 const TopoDS_Vertex& aVa=(*(TopoDS_Vertex *)(&mySmartMap.FindKey(i)));
330 const BOPAlgo_ListOfEdgeInfo& aLEI=mySmartMap(i);
331 aItLEI.Initialize(aLEI);
332 for (; aItLEI.More(); aItLEI.Next()) {
333 BOPAlgo_EdgeInfo& aEI=aItLEI.ChangeValue();
334 const TopoDS_Edge& aEOuta=aEI.Edge();
337 bIsNotPassed=!aEI.Passed();
338 if (bIsOut && bIsNotPassed) {
344 Path(aGAS, myFace, aVa, aEOuta, aEI, aLS,
345 aVertVa, aCoordVa, aCB, mySmartMap, aVertMap);
348 }// for (i=1; i<=aNb; ++i) {
350 //=======================================================================
353 //=======================================================================
354 void Path (const GeomAdaptor_Surface& aGAS,
355 const TopoDS_Face& myFace,
356 const TopoDS_Vertex& aVFirst,
357 const TopoDS_Edge& aEFirst,
358 BOPAlgo_EdgeInfo& aEIFirst,
359 TopTools_SequenceOfShape& aLS,
360 TopTools_SequenceOfShape& aVertVa,
361 TColgp_SequenceOfPnt2d& aCoordVa,
362 BOPTools_ConnexityBlock& aCB,
363 BOPAlgo_IndexedDataMapOfShapeListOfEdgeInfo& mySmartMap,
364 MyDataMapOfShapeBoolean aVertMap)
366 Standard_Integer i, j, aNb, aNbj;
367 Standard_Real anAngleIn, anAngleOut, anAngle, aMinAngle;
368 Standard_Real aTol2D, aTol2D2, aD2, aTwoPI;
369 Standard_Boolean anIsSameV2d, anIsSameV, anIsFound, anIsOut, anIsNotPassed;
370 Standard_Boolean bIsClosed;
371 TopoDS_Vertex aVa, aVb;
373 BOPAlgo_ListIteratorOfListOfEdgeInfo anIt;
374 Standard_Real eps = Epsilon(1.);
378 BOPAlgo_EdgeInfo* anEdgeInfo = &aEIFirst;
380 aTwoPI = M_PI + M_PI;
385 // Do not escape through edge from which you enter
388 const TopoDS_Shape& anEPrev=aLS(aNb);
389 if (anEPrev.IsSame(aEOuta)) {
394 anEdgeInfo->SetPassed(Standard_True);
398 TopoDS_Vertex pVa=aVa;
399 pVa.Orientation(TopAbs_FORWARD);
400 gp_Pnt2d aPa=Coord2d(pVa, aEOuta, myFace);
401 aCoordVa.Append(aPa);
403 GetNextVertex (pVa, aEOuta, aVb);
405 gp_Pnt2d aPb=Coord2d(aVb, aEOuta, myFace);
407 const BOPAlgo_ListOfEdgeInfo& aLEInfo=mySmartMap.FindFromKey(aVb);
409 aTol2D = 2.*Tolerance2D(aVb, aGAS);
410 aTol2D2 = aTol2D * aTol2D;
412 bIsClosed = aVertMap.Find(aVb);
414 TopTools_ListOfShape aBuf;
415 Standard_Boolean bHasEdge = Standard_False;
418 for (i = aNb; i>0; --i) {
419 const TopoDS_Shape& aVPrev=aVertVa(i);
420 const gp_Pnt2d& aPaPrev=aCoordVa(i);
421 const TopoDS_Edge& aEPrev = TopoDS::Edge(aLS(i));
425 bHasEdge = !BRep_Tool::Degenerated(aEPrev);
426 // do not create wire from degenerated edges only
432 anIsSameV = aVPrev.IsSame(aVb);
433 anIsSameV2d = anIsSameV;
436 aD2 = aPaPrev.SquareDistance(aPb);
437 anIsSameV2d = aD2 < aTol2D2;
439 Standard_Real udist = fabs(aPaPrev.X() - aPb.X());
440 Standard_Real vdist = fabs(aPaPrev.Y() - aPb.Y());
441 Standard_Real aTolU = 2.*UTolerance2D(aVb, aGAS);
442 Standard_Real aTolV = 2.*VTolerance2D(aVb, aGAS);
444 if((udist > aTolU) || (vdist > aTolV)) {
445 anIsSameV2d = Standard_False;
451 if (anIsSameV && anIsSameV2d) {
452 Standard_Integer iPriz;
454 if (aBuf.Extent()==2) {
455 if(aBuf.First().IsSame(aBuf.Last())) {
461 BOPAlgo_WireSplitter::MakeWire(aBuf, aW);
462 aCB.ChangeLoops().Append(aW);
475 TopTools_SequenceOfShape aLSt, aVertVat;
476 TColgp_SequenceOfPnt2d aCoordVat;
478 aVb=(*(TopoDS_Vertex *)(&aVertVa(i)));
480 for (j=1; j<=aNbj; ++j) {
482 aVertVat.Append(aVertVa(j));
483 aCoordVat.Append(aCoordVa(j));
500 BOPAlgo_EdgeInfo *pEdgeInfo=NULL;
502 anAngleIn = AngleIn(aEOuta, aLEInfo);
504 anIsFound = Standard_False;
505 Standard_Integer iCnt = NbWaysOut(aLEInfo);
506 Standard_Integer aCurIndexE = 0;
507 anIt.Initialize(aLEInfo);
508 for (; anIt.More(); anIt.Next()) {
509 BOPAlgo_EdgeInfo& anEI=anIt.ChangeValue();
510 const TopoDS_Edge& aE=anEI.Edge();
511 anIsOut=!anEI.IsIn();
512 anIsNotPassed=!anEI.Passed();
514 if (anIsOut && anIsNotPassed) {
517 // Is there one way to go out of the vertex
518 // we have to use it only.
521 // no way to go . (Error)
526 // the one and only way to go out .
528 anIsFound=Standard_True;
532 if (aE.IsSame(aEOuta)) {
539 aP2Dx = Coord2dVf(aE, myFace);
541 aD2 = aP2Dx.SquareDistance(aPb);
547 // Look for minimal angle and make the choice.
548 anAngleOut=anEI.Angle();
549 anAngle=ClockWiseAngle(anAngleIn, anAngleOut);
551 if (anAngle < aMinAngle - eps) {
554 anIsFound=Standard_True;
557 } // for (; anIt.More(); anIt.Next())
560 // no way to go . (Error)
565 aEOuta = pEdgeInfo->Edge();
566 anEdgeInfo = pEdgeInfo;
569 //=======================================================================
570 // function: ClockWiseAngle
572 //=======================================================================
573 Standard_Real ClockWiseAngle(const Standard_Real aAngleIn,
574 const Standard_Real aAngleOut)
576 Standard_Real aTwoPi=M_PI+M_PI;
577 Standard_Real dA, A1, A2, AIn, AOut ;
585 if (AOut >= aTwoPi) {
602 //else if (dA <= 1.e-15) {
603 else if (dA <= 1.e-14) {
608 //=======================================================================
611 //=======================================================================
612 gp_Pnt2d Coord2d (const TopoDS_Vertex& aV1,
613 const TopoDS_Edge& aE1,
614 const TopoDS_Face& aF)
616 Standard_Real aT, aFirst, aLast;
617 Handle(Geom2d_Curve) aC2D;
620 aT=BRep_Tool::Parameter (aV1, aE1, aF);
621 aC2D=BRep_Tool::CurveOnSurface(aE1, aF, aFirst, aLast);
622 aC2D->D0 (aT, aP2D1);
626 //=======================================================================
627 // function: Coord2dVf
629 //=======================================================================
630 gp_Pnt2d Coord2dVf (const TopoDS_Edge& aE,
631 const TopoDS_Face& aF)
633 Standard_Real aCoord=99.;
634 gp_Pnt2d aP2D1(aCoord, aCoord);
638 for (; aIt.More(); aIt.Next()) {
639 const TopoDS_Shape& aVx=aIt.Value();
640 if (aVx.Orientation()==TopAbs_FORWARD) {
642 const TopoDS_Vertex& aVxx=(*(TopoDS_Vertex *)(&aVx));// TopoDS::Vertex(aVx);
643 aP2D1=Coord2d(aVxx, aE, aF);
650 //=======================================================================
651 // function: NbWaysOut
653 //=======================================================================
654 Standard_Integer NbWaysOut(const BOPAlgo_ListOfEdgeInfo& aLEInfo)
656 Standard_Boolean bIsOut, bIsNotPassed;
657 Standard_Integer iCnt=0;
658 BOPAlgo_ListIteratorOfListOfEdgeInfo anIt;
660 anIt.Initialize(aLEInfo);
661 for (; anIt.More(); anIt.Next()) {
662 const BOPAlgo_EdgeInfo& anEI=anIt.Value();
665 bIsNotPassed=!anEI.Passed();
666 if (bIsOut && bIsNotPassed) {
673 //=======================================================================
676 //=======================================================================
677 Standard_Real AngleIn(const TopoDS_Edge& aEIn,
678 const BOPAlgo_ListOfEdgeInfo& aLEInfo)
680 Standard_Real anAngleIn;
681 Standard_Boolean anIsIn;
682 BOPAlgo_ListIteratorOfListOfEdgeInfo anIt;
684 anIt.Initialize(aLEInfo);
685 for (; anIt.More(); anIt.Next()) {
686 const BOPAlgo_EdgeInfo& anEdgeInfo=anIt.Value();
687 const TopoDS_Edge& aE=anEdgeInfo.Edge();
688 anIsIn=anEdgeInfo.IsIn();
690 if (anIsIn && aE==aEIn) {
691 anAngleIn=anEdgeInfo.Angle();
698 //=======================================================================
699 // function: GetNextVertex
701 //=======================================================================
702 void GetNextVertex(const TopoDS_Vertex& aV,
703 const TopoDS_Edge& aE,
709 for (; aIt.More(); aIt.Next()) {
710 const TopoDS_Shape& aVx=aIt.Value();
711 if (!aVx.IsEqual(aV)) {
712 aV1=(*(TopoDS_Vertex *)(&aVx));
718 //=======================================================================
721 //=======================================================================
722 Standard_Real Angle2D (const TopoDS_Vertex& aV,
723 const TopoDS_Edge& anEdge,
724 const TopoDS_Face& myFace,
725 const GeomAdaptor_Surface& aGAS,
726 const Standard_Boolean bIsIN,
727 const Handle(IntTools_Context)& theContext)
729 Standard_Real aFirst, aLast, aToler, dt, aTV, aTV1, anAngle, aTX;
732 Handle(Geom2d_Curve) aC2D;
734 aTV=BRep_Tool::Parameter (aV, anEdge, myFace);
735 if (Precision::IsInfinite(aTV)) {
739 BOPTools_AlgoTools2D::CurveOnSurface (anEdge, myFace, aC2D,
740 aFirst, aLast, aToler, theContext);
741 Standard_Real tol2d =2.*Tolerance2D(aV, aGAS);
743 GeomAbs_CurveType aType;
744 Geom2dAdaptor_Curve aGAC2D(aC2D);
746 dt = Max(aGAC2D.Resolution(tol2d), Precision::PConfusion());
748 aType=aGAC2D.GetType();
749 if (aType != GeomAbs_Line )
751 Geom2dLProp_CLProps2d LProp(aC2D, aTV, 2, Precision::PConfusion());
752 if(LProp.IsTangentDefined())
754 Standard_Real R = LProp.Curvature();
755 if(R > Precision::PConfusion())
758 Standard_Real cosphi = R / (R + tol2d);
759 dt = Max(dt, ACos(cosphi)); //to avoid small dt for big R.
763 //for case chl/927/r9
764 aTX=0.05*(aLast - aFirst);//aTX=0.25*(aLast - aFirst);
769 // to save direction of the curve as much as it possible
770 // in the case of big tolerances
774 if (fabs (aTV-aFirst) < fabs(aTV - aLast)) {
781 aGAC2D.D0 (aTV1, aPV1);
782 aGAC2D.D0 (aTV, aPV);
784 aV2D = bIsIN ? gp_Vec2d(aPV1, aPV) : gp_Vec2d(aPV, aPV1);
786 gp_Dir2d aDir2D(aV2D);
787 anAngle=Angle(aDir2D);
791 //=======================================================================
794 //=======================================================================
795 Standard_Real Angle (const gp_Dir2d& aDir2D)
797 gp_Dir2d aRefDir(1., 0.);
798 Standard_Real anAngle;
800 anAngle = aRefDir.Angle(aDir2D);
802 anAngle += M_PI + M_PI;
805 //=======================================================================
806 // function: Tolerance2D
808 //=======================================================================
809 Standard_Real Tolerance2D (const TopoDS_Vertex& aV,
810 const GeomAdaptor_Surface& aGAS)
812 Standard_Real aTol2D, anUr, aVr, aTolV3D;
813 GeomAbs_SurfaceType aType;
815 aType=aGAS.GetType();
816 aTolV3D=BRep_Tool::Tolerance(aV);
818 anUr=aGAS.UResolution(aTolV3D);
819 aVr =aGAS.VResolution(aTolV3D);
820 aTol2D=(aVr>anUr) ? aVr : anUr;
822 if (aTol2D < aTolV3D) {
825 if (aType==GeomAbs_BSplineSurface) {
832 //=======================================================================
833 //function : UTolerance2D
835 //=======================================================================
836 Standard_Real UTolerance2D (const TopoDS_Vertex& aV,
837 const GeomAdaptor_Surface& aGAS)
839 const Standard_Real aTolV3D = BRep_Tool::Tolerance(aV);
840 const Standard_Real anUr = aGAS.UResolution(aTolV3D);
845 //=======================================================================
846 //function : VTolerance2D
848 //=======================================================================
849 Standard_Real VTolerance2D (const TopoDS_Vertex& aV,
850 const GeomAdaptor_Surface& aGAS)
852 const Standard_Real aTolV3D = BRep_Tool::Tolerance(aV);
853 const Standard_Real anVr = aGAS.VResolution(aTolV3D);
858 //=======================================================================
859 //function : RefineAngles
861 //=======================================================================
862 void RefineAngles(const TopoDS_Face& myFace,
863 const TopTools_ListOfShape& myEdges,
864 BOPAlgo_IndexedDataMapOfShapeListOfEdgeInfo& mySmartMap,
865 const Handle(IntTools_Context)& theContext)
867 Standard_Integer aNb, i;
868 NCollection_IndexedDataMap<TopoDS_Shape,
870 TopTools_ShapeMapHasher> aMSI;
871 TopTools_MapOfShape aMBE;
872 TopTools_ListIteratorOfListOfShape aIt;
875 aIt.Initialize(myEdges);
876 for(; aIt.More(); aIt.Next()) {
877 const TopoDS_Shape& aE=aIt.Value();
878 if(aMSI.Contains(aE)) {
879 Standard_Integer& iCnt = aMSI.ChangeFromKey(aE);
883 Standard_Integer iCnt = 1;
889 for (i = 1; i <= aNb; ++i) {
890 Standard_Integer iCnt = aMSI(i);
892 const TopoDS_Shape& aE = aMSI.FindKey(i);
899 aNb = mySmartMap.Extent();
900 for (i = 1; i <= aNb; ++i) {
901 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&mySmartMap.FindKey(i));
902 BOPAlgo_ListOfEdgeInfo& aLEI=mySmartMap(i);
904 RefineAngles(aV, myFace, aMBE, aLEI, theContext);
907 //=======================================================================
908 typedef NCollection_DataMap \
909 <TopoDS_Shape, Standard_Real, TopTools_ShapeMapHasher> \
910 TopTools_DataMapOfShapeReal;
911 typedef TopTools_DataMapOfShapeReal::Iterator \
912 TopTools_DataMapIteratorOfDataMapOfShapeReal;
914 //=======================================================================
915 //function : RefineAngles
917 //=======================================================================
918 void RefineAngles(const TopoDS_Vertex& aV,
919 const TopoDS_Face& myFace,
920 const TopTools_MapOfShape& aMBE,
921 BOPAlgo_ListOfEdgeInfo& aLEI,
922 const Handle(IntTools_Context)& theContext)
924 Standard_Boolean bIsIn, bIsBoundary, bRefined;
925 Standard_Integer iCntBnd, iCntInt;
926 Standard_Real aA, aA1, aA2;
927 TopTools_DataMapOfShapeReal aDMSR;
928 BOPAlgo_ListIteratorOfListOfEdgeInfo aItLEI;
930 aA1=0.; // angle of outgoing edge
931 aA2=0.; // angle of incoming edge
934 aItLEI.Initialize(aLEI);
935 for (; aItLEI.More(); aItLEI.Next()) {
936 BOPAlgo_EdgeInfo& aEI=aItLEI.ChangeValue();
937 const TopoDS_Edge& aE=aEI.Edge();
941 if (aMBE.Contains(aE)) {
959 Standard_Real aDelta = ClockWiseAngle(aA2, aA1);
960 aItLEI.Initialize(aLEI);
961 for (; aItLEI.More(); aItLEI.Next()) {
962 BOPAlgo_EdgeInfo& aEI=aItLEI.ChangeValue();
963 const TopoDS_Edge& aE=aEI.Edge();
965 bIsBoundary=aMBE.Contains(aE);
967 if (bIsBoundary || bIsIn) {
972 Standard_Real aDA = ClockWiseAngle(aA2, aA);
974 continue; // already inside
977 bRefined=RefineAngle2D(aV, aE, myFace, aA1, aA2, aDelta, aA, theContext);
981 else if (iCntInt == 2) {
982 aA = (aA <= aA1) ? (aA1 + Precision::Angular()) :
983 (aA2 - Precision::Angular());
988 if (aDMSR.IsEmpty()) {
993 aItLEI.Initialize(aLEI);
994 for (; aItLEI.More(); aItLEI.Next()) {
995 BOPAlgo_EdgeInfo& aEI=aItLEI.ChangeValue();
996 const TopoDS_Edge& aE=aEI.Edge();
999 if (!aDMSR.IsBound(aE)) {
1011 //=======================================================================
1012 //function : RefineAngle2D
1014 //=======================================================================
1015 Standard_Boolean RefineAngle2D(const TopoDS_Vertex& aV,
1016 const TopoDS_Edge& aE,
1017 const TopoDS_Face& myFace,
1018 const Standard_Real aA1,
1019 const Standard_Real aA2,
1020 const Standard_Real aDelta,
1022 const Handle(IntTools_Context)& theContext)
1024 Standard_Boolean bRet;
1025 Standard_Integer i, j, aNbP;
1026 Standard_Real aTV, aTol, aT1, aT2, dT, aAngle, aT, aTOp;
1027 Standard_Real aTolInt, aAi, aXi, aYi, aT1j, aT2j, aT1max, aT2max, aCf;
1028 gp_Pnt2d aPV, aP, aP1, aP2;
1029 Handle(Geom2d_Curve) aC2D;
1030 Handle(Geom2d_Line) aLi;
1031 Geom2dAdaptor_Curve aGAC1, aGAC2;
1032 Geom2dInt_GInter aGInter;
1033 IntRes2d_Domain aDomain1, aDomain2;
1039 BOPTools_AlgoTools2D::CurveOnSurface(aE, myFace, aC2D, aT1, aT2, aTol, theContext);
1040 aGAC1.Load(aC2D, aT1, aT2);
1042 aTV=BRep_Tool::Parameter (aV, aE, myFace);
1045 aTOp = (fabs(aTV-aT1) < fabs(aTV-aT2)) ? aT2 : aT1;
1047 const Standard_Real MaxDT = 0.3 * (aT2 - aT1);
1050 aDomain1.SetValues(aP1, aT1, aTolInt, aP2, aT2, aTolInt);
1052 for (i=0; i<2; ++i) {
1053 aAi=(!i) ? aA1 : (aA2 + M_PI);
1056 gp_Dir2d aDiri(aXi, aYi);
1057 aLi=new Geom2d_Line(aPV, aDiri);
1061 aGInter.Perform(aGAC1, aDomain1, aGAC2, aDomain2, aTolInt, aTolInt);
1062 if (!aGInter.IsDone()) {
1066 aNbP = aGInter.NbPoints();
1069 for (j = 1; j <= aNbP; ++j) {
1070 const IntRes2d_IntersectionPoint& aIPj = aGInter.Point(j);
1071 aT1j = aIPj.ParamOnFirst();
1072 aT2j = aIPj.ParamOnSecond();
1074 if (aT2j > aT2max && Abs(aT1j - aTV) < MaxDT) {
1082 if (Abs(dT) < aTolInt) {
1086 aT = aT1max + aCf*dT;
1088 gp_Vec2d aV2D(aPV, aP);
1089 gp_Dir2d aDir2D(aV2D);
1091 aAngle = Angle(aDir2D);
1092 Standard_Real aDA = ClockWiseAngle(aA2, aAngle);
1098 }// for (i=0; i<2; ++i) {