1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 // This file is part of Open CASCADE Technology software library.
9 // This library is free software; you can redistribute it and/or modify it under
10 // the terms of the GNU Lesser General Public License version 2.1 as published
11 // by the Free Software Foundation, with special exception defined in the file
12 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 // distribution for complete text of the license and disclaimer of any warranty.
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
18 #include <BOPTools_AlgoTools.ixx>
20 #include <Precision.hxx>
24 #include <gp_Pnt2d.hxx>
25 #include <gp_Cylinder.hxx>
26 #include <gp_Cone.hxx>
27 #include <gp_Sphere.hxx>
28 #include <gp_Torus.hxx>
31 #include <Geom2d_Curve.hxx>
32 #include <Geom_Surface.hxx>
33 #include <Geom_Plane.hxx>
34 #include <Geom_TrimmedCurve.hxx>
35 #include <Geom_Curve.hxx>
36 #include <GeomAPI_ProjectPointOnSurf.hxx>
37 #include <Geom2dInt_Geom2dCurveTool.hxx>
39 #include <TopAbs_Orientation.hxx>
41 #include <TopoDS_Compound.hxx>
42 #include <TopoDS_CompSolid.hxx>
43 #include <TopoDS_Solid.hxx>
44 #include <TopoDS_Shell.hxx>
45 #include <TopoDS_Wire.hxx>
47 #include <BRep_Builder.hxx>
48 #include <BRep_Tool.hxx>
49 #include <BRepLib.hxx>
50 #include <BRepAdaptor_Curve2d.hxx>
51 #include <BRepAdaptor_Surface.hxx>
52 #include <BRepClass3d_SolidClassifier.hxx>
54 #include <TopExp_Explorer.hxx>
56 #include <IntTools_Tools.hxx>
58 #include <BOPTools.hxx>
59 #include <BOPTools_CoupleOfShape.hxx>
60 #include <BOPTools_ListOfCoupleOfShape.hxx>
61 #include <BOPTools_AlgoTools2D.hxx>
62 #include <BOPTools_AlgoTools3D.hxx>
64 #include <BOPCol_IndexedMapOfShape.hxx>
65 #include <BOPCol_MapOfShape.hxx>
67 #include <IntTools_ShrunkRange.hxx>
71 Standard_Real AngleWithRef(const gp_Dir& theD1,
73 const gp_Dir& theDRef);
76 Standard_Boolean FindFacePairs (const TopoDS_Edge& theE,
77 const BOPCol_ListOfShape& thLF,
78 BOPTools_ListOfCoupleOfShape& theLCFF,
79 Handle(IntTools_Context)& theContext);
81 TopAbs_Orientation Orientation(const TopoDS_Edge& anE,
82 const TopoDS_Face& aF);
85 void GetFaceDir(const TopoDS_Edge& aE,
86 const TopoDS_Face& aF,
88 const Standard_Real aT,
92 Handle(IntTools_Context)& theContext,
93 GeomAPI_ProjectPointOnSurf& aProjPL,
94 const Standard_Real aDt);
96 Standard_Boolean FindPointInFace(const TopoDS_Face& aF,
100 Handle(IntTools_Context)& theContext,
101 GeomAPI_ProjectPointOnSurf& aProjPL,
102 const Standard_Real aDt,
103 const Standard_Real aTolE);
105 Standard_Real MinStep3D(const TopoDS_Edge& theE1,
106 const TopoDS_Face& theF1,
107 const BOPTools_ListOfCoupleOfShape& theLCS,
110 //=======================================================================
111 // function: MakeConnexityBlocks
113 //=======================================================================
114 void BOPTools_AlgoTools::MakeConnexityBlocks
115 (const TopoDS_Shape& theS,
116 const TopAbs_ShapeEnum theType1,
117 const TopAbs_ShapeEnum theType2,
118 BOPCol_ListOfShape& theLCB)
120 Standard_Integer aNbF, aNbAdd, aNbAdd1, i;
124 TopExp_Explorer aExp;
125 BOPCol_MapOfShape aMP;
126 BOPCol_IndexedMapOfShape aMCB, aMAdd, aMAdd1;
127 BOPCol_IndexedDataMapOfShapeListOfShape aMEF;
128 BOPCol_ListIteratorOfListOfShape aItLF;
131 BOPTools::MapShapesAndAncestors(theS, theType1, theType2, aMEF);
134 aIt.Initialize(theS);
135 for (; aIt.More(); aIt.Next()) {
136 const TopoDS_Shape& aF1=aIt.Value();
137 if (aMP.Contains(aF1)) {
148 aNbAdd = aMAdd.Extent();
149 for (i=1; i<=aNbAdd; ++i) {
150 const TopoDS_Shape& aF=aMAdd(i);
152 aExp.Init(aF, theType1);
153 for (; aExp.More(); aExp.Next()) {
154 const TopoDS_Shape& aE=aExp.Current();
156 const BOPCol_ListOfShape& aLF=aMEF.FindFromKey(aE);
157 aItLF.Initialize(aLF);
158 for (; aItLF.More(); aItLF.Next()) {
159 const TopoDS_Shape& aFx=aItLF.Value();
160 if (aFx.IsSame(aF)) {
163 if (aMCB.Contains(aFx)) {
168 }//for (; aExp.More(); aExp.Next()){
170 }// for (i=1; i<=aNbAdd; ++i) {
172 aNbAdd1=aMAdd1.Extent();
174 break;// ->make new CB from aMCB
178 for (i=1; i<=aNbAdd1; ++i) {
179 const TopoDS_Shape& aFAdd = aMAdd1(i);
186 aBB.MakeCompound(aC);
188 for (i=1; i<=aNbF; ++i) {
189 const TopoDS_Shape& aF=aMCB(i);
195 }// for (; aIt.More(); aIt.Next())
197 //=======================================================================
198 // function: OrientFacesOnShell
200 //=======================================================================
201 void BOPTools_AlgoTools::OrientFacesOnShell (TopoDS_Shape& aShell)
203 Standard_Boolean bIsProcessed1, bIsProcessed2;
204 Standard_Integer i, aNbE, aNbF, j;
205 TopAbs_Orientation anOrE1, anOrE2;
206 TopoDS_Face aF1x, aF2x;
207 TopoDS_Shape aShellNew;
208 BOPCol_IndexedDataMapOfShapeListOfShape aEFMap;
209 BOPCol_IndexedMapOfShape aProcessedFaces;
212 BOPTools_AlgoTools::MakeContainer(TopAbs_SHELL, aShellNew);
214 BOPTools::MapShapesAndAncestors(aShell,
215 TopAbs_EDGE, TopAbs_FACE,
217 aNbE=aEFMap.Extent();
219 // One seam edge in aEFMap contains 2 equivalent faces.
220 for (i=1; i<=aNbE; ++i) {
221 BOPCol_ListOfShape& aLF=aEFMap.ChangeFromIndex(i);
224 BOPCol_ListOfShape aLFTmp;
225 BOPCol_IndexedMapOfShape aFM;
227 BOPCol_ListIteratorOfListOfShape anIt(aLF);
228 for (; anIt.More(); anIt.Next()) {
229 const TopoDS_Shape& aF=anIt.Value();
230 if (!aFM.Contains(aF)) {
241 for (i=1; i<=aNbE; ++i) {
242 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aEFMap.FindKey(i)));
243 if (BRep_Tool::Degenerated(aE)) {
247 const BOPCol_ListOfShape& aLF=aEFMap.FindFromIndex(i);
253 TopoDS_Face& aF1=(*(TopoDS_Face*)(&aLF.First()));
254 TopoDS_Face& aF2=(*(TopoDS_Face*)(&aLF.Last()));
256 bIsProcessed1=aProcessedFaces.Contains(aF1);
257 bIsProcessed2=aProcessedFaces.Contains(aF2);
258 if (bIsProcessed1 && bIsProcessed2) {
262 if (!bIsProcessed1 && !bIsProcessed2) {
263 aProcessedFaces.Add(aF1);
264 aBB.Add(aShellNew, aF1);
265 bIsProcessed1=!bIsProcessed1;
270 j=aProcessedFaces.FindIndex(aF1);
271 aF1x=(*(TopoDS_Face*)(&aProcessedFaces.FindKey(j)));
276 j=aProcessedFaces.FindIndex(aF2);
277 aF2x=(*(TopoDS_Face*)(&aProcessedFaces.FindKey(j)));
280 anOrE1=Orientation(aE, aF1x);
281 anOrE2=Orientation(aE, aF2x);
283 if (bIsProcessed1 && !bIsProcessed2) {
284 if (anOrE1==anOrE2) {
285 if (!BRep_Tool::IsClosed(aE, aF1) &&
286 !BRep_Tool::IsClosed(aE, aF2)) {
290 aProcessedFaces.Add(aF2);
291 aBB.Add(aShellNew, aF2);
293 else if (!bIsProcessed1 && bIsProcessed2) {
294 if (anOrE1==anOrE2) {
295 if (!BRep_Tool::IsClosed(aE, aF1) &&
296 !BRep_Tool::IsClosed(aE, aF2)) {
300 aProcessedFaces.Add(aF1);
301 aBB.Add(aShellNew, aF1);
306 for (i=1; i<=aNbE; ++i) {
307 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aEFMap.FindKey(i)));
308 if (BRep_Tool::Degenerated(aE)) {
312 const BOPCol_ListOfShape& aLF=aEFMap.FindFromIndex(i);
315 BOPCol_ListIteratorOfListOfShape anIt(aLF);
316 for(; anIt.More(); anIt.Next()) {
317 const TopoDS_Face& aF=(*(TopoDS_Face*)(&anIt.Value()));
318 if (!aProcessedFaces.Contains(aF)) {
319 aProcessedFaces.Add(aF);
320 aBB.Add(aShellNew, aF);
327 //=======================================================================
328 //function : Orientation
330 //=======================================================================
331 TopAbs_Orientation Orientation(const TopoDS_Edge& anE,
332 const TopoDS_Face& aF)
334 TopAbs_Orientation anOr=TopAbs_INTERNAL;
336 TopExp_Explorer anExp;
337 anExp.Init(aF, TopAbs_EDGE);
338 for (; anExp.More(); anExp.Next()) {
339 const TopoDS_Edge& anEF1=(*(TopoDS_Edge*)(&anExp.Current()));
340 if (anEF1.IsSame(anE)) {
341 anOr=anEF1.Orientation();
347 //=======================================================================
348 // function: MakeConnexityBlock.
350 //=======================================================================
351 void BOPTools_AlgoTools::MakeConnexityBlock
352 (BOPCol_ListOfShape& theLFIn,
353 BOPCol_IndexedMapOfShape& theMEAvoid,
354 BOPCol_ListOfShape& theLCB,
355 const Handle(NCollection_BaseAllocator)& theAllocator)
357 Standard_Integer aNbF, aNbAdd1, aNbAdd, i;
358 TopExp_Explorer aExp;
359 BOPCol_ListIteratorOfListOfShape aIt;
361 BOPCol_IndexedMapOfShape aMCB(100, theAllocator);
362 BOPCol_IndexedMapOfShape aMAdd(100, theAllocator);
363 BOPCol_IndexedMapOfShape aMAdd1(100, theAllocator);
364 BOPCol_IndexedDataMapOfShapeListOfShape aMEF(100, theAllocator);
367 aNbF=theLFIn.Extent();
368 aIt.Initialize(theLFIn);
369 for (; aIt.More(); aIt.Next()) {
370 const TopoDS_Shape& aF=aIt.Value();
371 BOPTools::MapShapesAndAncestors(aF, TopAbs_EDGE, TopAbs_FACE, aMEF);
375 const TopoDS_Shape& aF1=theLFIn.First();
380 aNbAdd = aMAdd.Extent();
381 for (i=1; i<=aNbAdd; ++i) {
382 const TopoDS_Shape& aF=aMAdd(i);
385 aExp.Init(aF, TopAbs_EDGE);
386 for (; aExp.More(); aExp.Next()) {
387 const TopoDS_Shape& aE=aExp.Current();
388 if (theMEAvoid.Contains(aE)){
392 const BOPCol_ListOfShape& aLF=aMEF.FindFromKey(aE);
394 for (; aIt.More(); aIt.Next()) {
395 const TopoDS_Shape& aFx=aIt.Value();
396 if (aFx.IsSame(aF)) {
399 if (aMCB.Contains(aFx)) {
404 }//for (; aExp.More(); aExp.Next()){
406 }// for (i=1; i<=aNbAdd; ++i) {
408 aNbAdd1=aMAdd1.Extent();
414 for (i=1; i<=aNbAdd1; ++i) {
415 const TopoDS_Shape& aFAdd=aMAdd1(i);
423 for (i=1; i<=aNbF; ++i) {
424 const TopoDS_Shape& aF=aMCB(i);
428 //=======================================================================
429 // function: ComputeStateByOnePoint
431 //=======================================================================
432 TopAbs_State BOPTools_AlgoTools::ComputeStateByOnePoint
433 (const TopoDS_Shape& theS,
434 const TopoDS_Solid& theRef,
435 const Standard_Real theTol,
436 Handle(IntTools_Context)& theContext)
439 TopAbs_ShapeEnum aType;
441 aState=TopAbs_UNKNOWN;
442 aType=theS.ShapeType();
443 if (aType==TopAbs_VERTEX) {
444 const TopoDS_Vertex& aV=(*(TopoDS_Vertex*)(&theS));
445 aState=BOPTools_AlgoTools::ComputeState(aV, theRef, theTol, theContext);
447 else if (aType==TopAbs_EDGE) {
448 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&theS));
449 aState=BOPTools_AlgoTools::ComputeState(aE, theRef, theTol, theContext);
454 //=======================================================================
455 // function: ComputeState
457 //=======================================================================
458 TopAbs_State BOPTools_AlgoTools::ComputeState
459 (const TopoDS_Face& theF,
460 const TopoDS_Solid& theRef,
461 const Standard_Real theTol,
462 BOPCol_IndexedMapOfShape& theBounds,
463 Handle(IntTools_Context)& theContext)
466 TopExp_Explorer aExp;
471 aState=TopAbs_UNKNOWN;
473 aExp.Init(theF, TopAbs_EDGE);
474 for (; aExp.More(); aExp.Next()) {
475 const TopoDS_Edge& aSE=(*(TopoDS_Edge*)(&aExp.Current()));
476 if (BRep_Tool::Degenerated(aSE)) {
480 if (!theBounds.Contains(aSE)) {
481 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aSE));
482 aState=BOPTools_AlgoTools::ComputeState(aE, theRef, theTol,
487 aE1=(*(TopoDS_Edge*)(&aSE));
490 // !!<- process edges that are all on theRef
492 BOPTools_AlgoTools3D::PointNearEdge(aE1, theF,
493 aP2D, aP3D, theContext);
494 aState=BOPTools_AlgoTools::ComputeState(aP3D, theRef, theTol,
500 //=======================================================================
501 // function: ComputeState
503 //=======================================================================
504 TopAbs_State BOPTools_AlgoTools::ComputeState
505 (const TopoDS_Vertex& theV,
506 const TopoDS_Solid& theRef,
507 const Standard_Real theTol,
508 Handle(IntTools_Context)& theContext)
513 aP3D=BRep_Tool::Pnt(theV);
514 aState=BOPTools_AlgoTools::ComputeState(aP3D, theRef, theTol,
518 //=======================================================================
519 // function: ComputeState
521 //=======================================================================
522 TopAbs_State BOPTools_AlgoTools::ComputeState
523 (const TopoDS_Edge& theE,
524 const TopoDS_Solid& theRef,
525 const Standard_Real theTol,
526 Handle(IntTools_Context)& theContext)
528 Standard_Real aT1, aT2, aT = 0.;
530 Handle(Geom_Curve) aC3D;
533 aC3D = BRep_Tool::Curve(theE, aT1, aT2);
536 //it means that we are in degenerated edge
537 const TopoDS_Vertex& aV = TopExp::FirstVertex(theE);
539 return TopAbs_UNKNOWN;
541 aP3D=BRep_Tool::Pnt(aV);
544 Standard_Boolean bF2Inf, bL2Inf;
545 Standard_Real dT=10.;
547 bF2Inf = Precision::IsNegativeInfinite(aT1);
548 bL2Inf = Precision::IsPositiveInfinite(aT2);
550 if (bF2Inf && !bL2Inf) {
553 else if (!bF2Inf && bL2Inf) {
556 else if (bF2Inf && bL2Inf) {
560 aT=IntTools_Tools::IntermediatePoint(aT1, aT2);
565 aState=BOPTools_AlgoTools::ComputeState(aP3D, theRef, theTol,
570 //=======================================================================
571 // function: ComputeState
573 //=======================================================================
574 TopAbs_State BOPTools_AlgoTools::ComputeState
576 const TopoDS_Solid& theRef,
577 const Standard_Real theTol,
578 Handle(IntTools_Context)& theContext)
582 BRepClass3d_SolidClassifier& aSC=theContext->SolidClassifier(theRef);
583 aSC.Perform(theP, theTol);
589 //=======================================================================
590 //function : IsInternalFace
592 //=======================================================================
593 Standard_Integer BOPTools_AlgoTools::IsInternalFace
594 (const TopoDS_Face& theFace,
595 const TopoDS_Solid& theSolid,
596 BOPCol_IndexedDataMapOfShapeListOfShape& theMEF,
597 const Standard_Real theTol,
598 Handle(IntTools_Context)& theContext)
600 Standard_Boolean bDegenerated;
601 Standard_Integer aNbF, iRet, iFound;
602 TopAbs_Orientation aOr;
604 TopExp_Explorer aExp;
605 BOPCol_ListIteratorOfListOfShape aItF;
607 // For all invoked functions: [::IsInternalFace(...)]
608 // the returned value iRet means:
609 // iRet=0; - state is not IN
610 // iRet=1; - state is IN
611 // iRet=2; - state can not be found by the method of angles
613 // For this function the returned value iRet means:
614 // iRet=0; - state is not IN
615 // iRet=1; - state is IN
618 // 1 Try to find an edge from theFace in theMEF
620 aExp.Init(theFace, TopAbs_EDGE);
621 for(; aExp.More(); aExp.Next()) {
622 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current()));
623 if (!theMEF.Contains(aE)) {
629 aOr=aE.Orientation();
630 if (aOr==TopAbs_INTERNAL) {
633 bDegenerated=BRep_Tool::Degenerated(aE);
638 BOPCol_ListOfShape& aLF=theMEF.ChangeFromKey(aE);
641 return iRet; // it can not be so
645 // aE is internal edge on aLF.First()
646 const TopoDS_Face& aF1=(*(TopoDS_Face*)(&aLF.First()));
647 BOPTools_AlgoTools::GetEdgeOnFace(aE, aF1, aE1);
648 if (aE1.Orientation()!=TopAbs_INTERNAL) {
653 iRet=BOPTools_AlgoTools::IsInternalFace(theFace, aE, aF1, aF1,
659 const TopoDS_Face& aF1=(*(TopoDS_Face*)(&aLF.First()));
660 const TopoDS_Face& aF2=(*(TopoDS_Face*)(&aLF.Last()));
662 if (aF2.IsSame(aF1) && BRep_Tool::IsClosed(aE, aF1)) {
663 // treat as it was for 1 face
664 iRet=BOPTools_AlgoTools::IsInternalFace(theFace, aE, aF1, aF2,
672 return iRet; // it can not be so
674 else { // aNbF=2,4,6,8,...
675 iRet=BOPTools_AlgoTools::IsInternalFace(theFace, aE, aLF,
679 }//for(; aExp.More(); aExp.Next()) {
682 // the face has no shared edges with the solid
690 //========================================
691 // 2. Classify face using classifier
694 BOPCol_IndexedMapOfShape aBounds;
696 BOPTools::MapShapes(theSolid, TopAbs_EDGE, aBounds);
698 aState=BOPTools_AlgoTools::ComputeState(theFace, theSolid,
699 theTol, aBounds, theContext);
701 iRet=(aState==TopAbs_IN)? 1 : 0;
705 //=======================================================================
706 //function : IsInternalFace
708 //=======================================================================
709 Standard_Integer BOPTools_AlgoTools::IsInternalFace
710 (const TopoDS_Face& theFace,
711 const TopoDS_Edge& theEdge,
712 BOPCol_ListOfShape& theLF,
713 Handle(IntTools_Context)& theContext)
715 Standard_Integer aNbF, iRet;
721 const TopoDS_Face& aF1=(*(TopoDS_Face*)(&theLF.First()));
722 const TopoDS_Face& aF2=(*(TopoDS_Face*)(&theLF.Last()));
723 iRet=BOPTools_AlgoTools::IsInternalFace(theFace, theEdge, aF1, aF2,
729 BOPTools_ListOfCoupleOfShape aLCFF;
730 BOPTools_ListIteratorOfListOfCoupleOfShape aIt;
732 FindFacePairs(theEdge, theLF, aLCFF, theContext);
734 aIt.Initialize(aLCFF);
735 for (; aIt.More(); aIt.Next()) {
736 BOPTools_CoupleOfShape& aCSFF=aIt.ChangeValue();
738 const TopoDS_Face& aF1=(*(TopoDS_Face*)(&aCSFF.Shape1()));
739 const TopoDS_Face& aF2=(*(TopoDS_Face*)(&aCSFF.Shape2()));
740 iRet=BOPTools_AlgoTools::IsInternalFace(theFace, theEdge, aF1, aF2,
749 //=======================================================================
750 //function : IsInternalFace
752 //=======================================================================
753 Standard_Integer BOPTools_AlgoTools::IsInternalFace
754 (const TopoDS_Face& theFace,
755 const TopoDS_Edge& theEdge,
756 const TopoDS_Face& theFace1,
757 const TopoDS_Face& theFace2,
758 Handle(IntTools_Context)& theContext)
760 Standard_Boolean bRet;
761 Standard_Integer iRet;
762 TopoDS_Edge aE1, aE2;
764 BOPTools_ListOfCoupleOfShape theLCSOff;
765 BOPTools_CoupleOfShape aCS1, aCS2;
767 BOPTools_AlgoTools::GetEdgeOnFace(theEdge, theFace1, aE1);
768 if (aE1.Orientation()==TopAbs_INTERNAL) {
770 aE1.Orientation(TopAbs_FORWARD);
771 aE2.Orientation(TopAbs_REVERSED);
773 else if (theFace1==theFace2) {
775 aE1.Orientation(TopAbs_FORWARD);
776 aE2.Orientation(TopAbs_REVERSED);
779 BOPTools_AlgoTools::GetEdgeOnFace(theEdge, theFace2, aE2);
782 aCS1.SetShape1(theEdge);
783 aCS1.SetShape2(theFace);
784 theLCSOff.Append(aCS1);
787 aCS2.SetShape2(theFace2);
788 theLCSOff.Append(aCS2);
790 bRet=GetFaceOff(aE1, theFace1, theLCSOff, aFOff, theContext);
792 iRet=0; // theFace is not internal
793 if (theFace.IsEqual(aFOff)) {
794 // theFace is internal
797 // theFace seems to be internal
803 //=======================================================================
804 //function : GetFaceOff
806 //=======================================================================
807 Standard_Boolean BOPTools_AlgoTools::GetFaceOff
808 (const TopoDS_Edge& theE1,
809 const TopoDS_Face& theF1,
810 BOPTools_ListOfCoupleOfShape& theLCSOff,
811 TopoDS_Face& theFOff,
812 Handle(IntTools_Context)& theContext)
814 Standard_Boolean bRet;
815 Standard_Real aT, aT1, aT2, aAngle, aTwoPI, aAngleMin, aDt3D;
816 Standard_Real aUmin, aUsup, aVmin, aVsup;
817 gp_Pnt aPn1, aPn2, aPx;
818 gp_Dir aDN1, aDN2, aDBF, aDBF2, aDTF;
820 TopAbs_Orientation aOr;
821 Handle(Geom_Curve)aC3D;
822 Handle(Geom_Plane) aPL;
823 BOPTools_ListIteratorOfListOfCoupleOfShape aIt;
824 GeomAPI_ProjectPointOnSurf aProjPL;
828 aC3D =BRep_Tool::Curve(theE1, aT1, aT2);
829 aT=BOPTools_AlgoTools2D::IntermediatePoint(aT1, aT2);
832 BOPTools_AlgoTools2D::EdgeTangent(theE1, aT, aVTgt);
833 gp_Dir aDTgt(aVTgt), aDTgt2;
834 aOr = theE1.Orientation();
836 aPL = new Geom_Plane(aPx, aDTgt);
837 aPL->Bounds(aUmin, aUsup, aVmin, aVsup);
838 aProjPL.Init(aPL, aUmin, aUsup, aVmin, aVsup);
840 aDt3D = MinStep3D(theE1, theF1, theLCSOff, aPx);
841 GetFaceDir(theE1, theF1, aPx, aT, aDTgt, aDN1, aDBF, theContext,
847 aIt.Initialize(theLCSOff);
848 for (; aIt.More(); aIt.Next()) {
849 const BOPTools_CoupleOfShape& aCS=aIt.Value();
850 const TopoDS_Edge& aE2=(*(TopoDS_Edge*)(&aCS.Shape1()));
851 const TopoDS_Face& aF2=(*(TopoDS_Face*)(&aCS.Shape2()));
853 aDTgt2 = (aE2.Orientation()==aOr) ? aDTgt : aDTgt.Reversed();
854 GetFaceDir(aE2, aF2, aPx, aT, aDTgt2, aDN2, aDBF2, theContext,
857 aAngle=AngleWithRef(aDBF, aDBF2, aDTF);
860 aAngle=aTwoPI+aAngle;
863 if (aAngle<Precision::Angular()) {
867 else if (aF2.IsSame(theF1)) {
872 if (aAngle<aAngleMin){
876 else if (aAngle==aAngleMin) {
877 // the minimal angle can not be found
883 //=======================================================================
884 //function : GetEdgeOff
886 //=======================================================================
887 Standard_Boolean BOPTools_AlgoTools::GetEdgeOff(const TopoDS_Edge& theE1,
888 const TopoDS_Face& theF2,
891 Standard_Boolean bFound;
892 TopAbs_Orientation aOr1, aOr1C, aOr2;
893 TopExp_Explorer anExp;
895 bFound=Standard_False;
896 aOr1=theE1.Orientation();
897 aOr1C=TopAbs::Reverse(aOr1);
899 anExp.Init(theF2, TopAbs_EDGE);
900 for (; anExp.More(); anExp.Next()) {
901 const TopoDS_Edge& aEF2=(*(TopoDS_Edge*)(&anExp.Current()));
902 if (aEF2.IsSame(theE1)) {
903 aOr2=aEF2.Orientation();
914 //=======================================================================
915 //function : AreFacesSameDomain
917 //=======================================================================
918 Standard_Boolean BOPTools_AlgoTools::AreFacesSameDomain
919 (const TopoDS_Face& theF1,
920 const TopoDS_Face& theF2,
921 Handle(IntTools_Context)& theContext)
923 Standard_Boolean bFlag;
924 Standard_Integer iErr;
925 Standard_Real aTolF1, aTolF2, aTol;
928 TopoDS_Face aF1, aF2;
930 TopExp_Explorer aExp;
932 bFlag=Standard_False;
935 aF1.Orientation(TopAbs_FORWARD);
937 aF2.Orientation(TopAbs_FORWARD);
939 aTolF1=BRep_Tool::Tolerance(aF1);
941 aExp.Init(aF1, TopAbs_EDGE);
942 for (; aExp.More(); aExp.Next()) {
943 aE1=(*(TopoDS_Edge*)(&aExp.Current()));
944 if (!BRep_Tool::Degenerated(aE1)) {
945 Standard_Real aTolE = BRep_Tool::Tolerance(aE1);
946 aTolF1 = (aTolE > aTolF1) ? aTolE : aTolF1;
950 aTolF2=BRep_Tool::Tolerance(aF2);
953 iErr = BOPTools_AlgoTools3D::PointInFace(aF1, aP, aP2D,
956 bFlag=theContext->IsValidPointForFace(aP, aF2, aTol);
962 //=======================================================================
963 //function : CheckSameGeom
965 //=======================================================================
966 Standard_Boolean BOPTools_AlgoTools::CheckSameGeom
967 (const TopoDS_Face& theF1,
968 const TopoDS_Face& theF2,
969 Handle(IntTools_Context)& theContext)
971 Standard_Boolean bRet;
972 Standard_Real aTolF1, aTolF2, aTol;
975 TopExp_Explorer aExp;
978 aExp.Init(theF1, TopAbs_EDGE);
979 for (; aExp.More(); aExp.Next()) {
980 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current()));
981 if (!BRep_Tool::Degenerated(aE)) {
982 aTolF1=BRep_Tool::Tolerance(theF1);
983 aTolF2=BRep_Tool::Tolerance(theF2);
985 BOPTools_AlgoTools3D::PointNearEdge(aE, theF1, aP2D, aP, theContext);
986 bRet=theContext->IsValidPointForFace(aP, theF2, aTol);
992 //=======================================================================
995 //=======================================================================
996 Standard_Integer BOPTools_AlgoTools::Sense (const TopoDS_Face& theF1,
997 const TopoDS_Face& theF2)
999 Standard_Integer iSense=0;
1000 gp_Dir aDNF1, aDNF2;
1001 TopoDS_Edge aE1, aE2;
1002 TopExp_Explorer aExp;
1004 aExp.Init(theF1, TopAbs_EDGE);
1005 for (; aExp.More(); aExp.Next()) {
1006 aE1=(*(TopoDS_Edge*)(&aExp.Current()));
1007 if (!BRep_Tool::Degenerated(aE1)) {
1008 if (!BRep_Tool::IsClosed(aE1, theF1)) {
1014 aExp.Init(theF2, TopAbs_EDGE);
1015 for (; aExp.More(); aExp.Next()) {
1016 aE2=(*(TopoDS_Edge*)(&aExp.Current()));
1017 if (!BRep_Tool::Degenerated(aE2)) {
1018 if (!BRep_Tool::IsClosed(aE2, theF2)) {
1019 if (aE2.IsSame(aE1)) {
1031 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge(aE1, theF1, aDNF1);
1032 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge(aE2, theF2, aDNF2);
1034 iSense=BOPTools_AlgoTools3D::SenseFlag(aDNF1, aDNF2);
1038 //=======================================================================
1039 // function: IsSplitToReverse
1041 //=======================================================================
1042 Standard_Boolean BOPTools_AlgoTools::IsSplitToReverse
1043 (const TopoDS_Shape& theSp,
1044 const TopoDS_Shape& theSr,
1045 Handle(IntTools_Context)& theContext)
1047 Standard_Boolean bRet;
1048 TopAbs_ShapeEnum aType;
1050 bRet=Standard_False;
1052 aType=theSp.ShapeType();
1055 const TopoDS_Edge& aESp=(*(TopoDS_Edge*)(&theSp));
1056 const TopoDS_Edge& aESr=(*(TopoDS_Edge*)(&theSr));
1057 bRet=BOPTools_AlgoTools::IsSplitToReverse(aESp, aESr, theContext);
1062 const TopoDS_Face& aFSp=(*(TopoDS_Face*)(&theSp));
1063 const TopoDS_Face& aFSr=(*(TopoDS_Face*)(&theSr));
1064 bRet=BOPTools_AlgoTools::IsSplitToReverse(aFSp, aFSr, theContext);
1073 //=======================================================================
1074 //function :IsSplitToReverse
1076 //=======================================================================
1077 Standard_Boolean BOPTools_AlgoTools::IsSplitToReverse
1078 (const TopoDS_Face& theFSp,
1079 const TopoDS_Face& theFSr,
1080 Handle(IntTools_Context)& theContext)
1082 Standard_Boolean bRet, bFound, bInFace;
1083 Standard_Real aT1, aT2, aT, aU, aV, aScPr;
1084 gp_Pnt aPFSp, aPFSr;
1087 Handle(Geom_Surface) aSr, aSp;
1088 TopAbs_Orientation aOrSr, aOrSp;
1089 TopExp_Explorer anExp;
1092 bRet=Standard_False;
1094 aSr=BRep_Tool::Surface(theFSr);
1095 aSp=BRep_Tool::Surface(theFSp);
1097 aOrSr=theFSr.Orientation();
1098 aOrSp=theFSp.Orientation();
1099 bRet=(aOrSr!=aOrSp);
1103 bFound=Standard_False;
1104 anExp.Init(theFSp, TopAbs_EDGE);
1105 for (; anExp.More(); anExp.Next()) {
1106 aESp=(*(TopoDS_Edge*)(&anExp.Current()));
1107 if (!BRep_Tool::Degenerated(aESp)) {
1108 if (!BRep_Tool::IsClosed(aESp, theFSp)) {
1115 Standard_Boolean bFlag;
1116 Standard_Integer iErr;
1119 iErr=BOPTools_AlgoTools3D::PointInFace(theFSp, aPFSp, aP2DFSp,
1125 aP2DFSp.Coord(aU, aV);
1126 bFlag=BOPTools_AlgoTools3D::GetNormalToSurface(aSp, aU, aV, aDNFSp);
1131 if (theFSp.Orientation()==TopAbs_REVERSED){
1136 BRep_Tool::Range(aESp, aT1, aT2);
1137 aT=BOPTools_AlgoTools2D::IntermediatePoint(aT1, aT2);
1138 BOPTools_AlgoTools3D::GetApproxNormalToFaceOnEdge(aESp, theFSp, aT,
1143 // Parts of theContext->ComputeVS(..)
1144 GeomAPI_ProjectPointOnSurf& aProjector=theContext->ProjPS(theFSr);
1145 aProjector.Perform(aPFSp);
1146 if (!aProjector.IsDone()) {
1150 aProjector.LowerDistanceParameters(aU, aV);
1151 gp_Pnt2d aP2D(aU, aV);
1152 bInFace=theContext->IsPointInFace (theFSr, aP2D);
1157 aSr->D1(aU, aV, aPFSr, aD1U, aD1V);
1160 gp_Dir aDNFSr=aDD1U^aDD1V;
1161 if (theFSr.Orientation()==TopAbs_REVERSED){
1165 aScPr=aDNFSp*aDNFSr;
1170 //=======================================================================
1171 //function :IsSplitToReverse
1173 //=======================================================================
1174 Standard_Boolean BOPTools_AlgoTools::IsSplitToReverse
1175 (const TopoDS_Edge& aEF1,
1176 const TopoDS_Edge& aEF2,
1177 Handle(IntTools_Context)& theContext)
1179 Standard_Boolean bRet, bIsDegenerated;
1181 bRet=Standard_False;
1182 bIsDegenerated=(BRep_Tool::Degenerated(aEF1) ||
1183 BRep_Tool::Degenerated(aEF2));
1184 if (bIsDegenerated) {
1189 TopAbs_Orientation aOrE, aOrSp;
1190 Handle(Geom_Curve)aC1, aC2;
1192 aC2=BRep_Tool::Curve(aEF2, a, b);
1193 aC1=BRep_Tool::Curve(aEF1, a, b);
1196 aOrE=aEF2.Orientation();
1197 aOrSp=aEF1.Orientation();
1202 Standard_Real aT1, aT2, aScPr;
1206 aT1=BOPTools_AlgoTools2D::IntermediatePoint(a, b);
1208 BOPTools_AlgoTools2D::EdgeTangent(aEF1, aT1, aV1);
1211 theContext->ProjectPointOnEdge(aP, aEF2, aT2);
1213 BOPTools_AlgoTools2D::EdgeTangent(aEF2, aT2, aV2);
1222 //=======================================================================
1225 //=======================================================================
1226 Standard_Boolean BOPTools_AlgoTools::IsHole(const TopoDS_Shape& aW,
1227 const TopoDS_Shape& aFace)
1229 Standard_Boolean bIsHole;
1230 Standard_Integer i, aNbS;
1231 Standard_Real aT1, aT2, aS;
1232 Standard_Real aU1, aU, dU;
1233 Standard_Real aX1, aY1, aX0, aY0;
1234 TopAbs_Orientation aOr;
1236 gp_Pnt2d aP2D0, aP2D1;
1237 Handle(Geom2d_Curve) aC2D;
1238 TopoDS_Face aF, aFF;
1239 TopoDS_Iterator aItW;
1241 bIsHole=Standard_False;
1243 aF=(*(TopoDS_Face *)(&aFace));
1245 aFF.Orientation(TopAbs_FORWARD);
1248 aItW.Initialize(aW);
1249 for (; aItW.More(); aItW.Next()) {
1250 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aItW.Value()));
1251 aOr=aE.Orientation();
1252 if (!(aOr==TopAbs_FORWARD ||
1253 aOr==TopAbs_REVERSED)) {
1257 aC2D=BRep_Tool::CurveOnSurface(aE, aFF, aT1, aT2);
1258 if (aC2D.IsNull()) {
1262 BRepAdaptor_Curve2d aBAC2D(aE, aFF);
1263 aNbS=Geom2dInt_Geom2dCurveTool::NbSamples(aBAC2D);
1268 dU=(aT2-aT1)/(Standard_Real)(aNbS-1);
1271 if (aOr==TopAbs_REVERSED) {
1277 aC2D->D0(aU, aP2D0);
1278 for(i=2; i<=aNbS; i++) {
1280 aC2D->D0(aU, aP2D1);
1281 aP2D0.Coord(aX0, aY0);
1282 aP2D1.Coord(aX1, aY1);
1284 aS=aS+(aY0+aY1)*(aX1-aX0);
1288 }//for (; aItW.More(); aItW.Next()) {
1293 //=======================================================================
1294 // function: MakeContainer
1296 //=======================================================================
1297 void BOPTools_AlgoTools::MakeContainer(const TopAbs_ShapeEnum theType,
1303 case TopAbs_COMPOUND:{
1305 aBB.MakeCompound(aC);
1310 case TopAbs_COMPSOLID:{
1311 TopoDS_CompSolid aCS;
1312 aBB.MakeCompSolid(aCS);
1318 TopoDS_Solid aSolid;
1319 aBB.MakeSolid(aSolid);
1326 TopoDS_Shell aShell;
1327 aBB.MakeShell(aShell);
1334 aBB.MakeWire(aWire);
1343 //=======================================================================
1344 // function: MakePCurve
1346 //=======================================================================
1347 void BOPTools_AlgoTools::MakePCurve(const TopoDS_Edge& aE,
1348 const TopoDS_Face& aF1,
1349 const TopoDS_Face& aF2,
1350 const IntTools_Curve& aIC,
1351 const Standard_Boolean bPC1,
1352 const Standard_Boolean bPC2)
1356 Standard_Real aTolE, aT1, aT2, aOutFirst, aOutLast, aOutTol;
1357 Handle(Geom2d_Curve) aC2D, aC2DA, aC2Dx1;
1360 Standard_Boolean bPC;
1362 aTolE=BRep_Tool::Tolerance(aE);
1364 const Handle(Geom_Curve)& aC3DE=BRep_Tool::Curve(aE, aT1, aT2);
1365 Handle(Geom_TrimmedCurve)aC3DETrim=
1366 new Geom_TrimmedCurve(aC3DE, aT1, aT2);
1368 for (i=0; i<2; ++i) {
1369 bPC = !i ? bPC1 : bPC2;
1376 aC2Dx1=aIC.FirstCurve2d();
1380 aC2Dx1=aIC.SecondCurve2d();
1383 aFFWD.Orientation(TopAbs_FORWARD);
1386 if (aC2D.IsNull()) {
1387 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aE, aFFWD);
1388 BOPTools_AlgoTools2D::CurveOnSurface(aE, aFFWD, aC2D,
1389 aOutFirst, aOutLast,
1393 if (aC3DE->IsPeriodic()) {
1394 BOPTools_AlgoTools2D::AdjustPCurveOnFace(aFFWD, aT1, aT2, aC2D,
1398 BOPTools_AlgoTools2D::AdjustPCurveOnFace(aFFWD, aC3DETrim, aC2D,
1402 aBB.UpdateEdge(aE, aC2DA, aFFWD, aTolE);
1403 //BRepLib::SameParameter(aE);
1405 BRepLib::SameParameter(aE);
1407 //=======================================================================
1408 // function: MakeEdge
1410 //=======================================================================
1411 void BOPTools_AlgoTools::MakeEdge(const IntTools_Curve& theIC,
1412 const TopoDS_Vertex& theV1,
1413 const Standard_Real theT1,
1414 const TopoDS_Vertex& theV2,
1415 const Standard_Real theT2,
1416 const Standard_Real theTolR3D,
1419 Standard_Real aTolV;
1422 BOPTools_AlgoTools::MakeSectEdge (theIC, theV1, theT1, theV2, theT2,
1425 aBB.UpdateEdge(theE, theTolR3D);
1427 aTolV=BRep_Tool::Tolerance(theV1);
1428 if (aTolV<theTolR3D) {
1429 aBB.UpdateVertex(theV1, theTolR3D);
1432 aTolV=BRep_Tool::Tolerance(theV2);
1433 if (aTolV<theTolR3D) {
1434 aBB.UpdateVertex(theV2, theTolR3D);
1437 //=======================================================================
1438 // function: ComputeVV
1440 //=======================================================================
1441 Standard_Integer BOPTools_AlgoTools::ComputeVV(const TopoDS_Vertex& aV1,
1443 const Standard_Real aTolP2)
1445 Standard_Real aTolV1, aTolSum, aTolSum2, aD2;
1448 aTolV1=BRep_Tool::Tolerance(aV1);
1450 aTolSum=aTolV1+aTolP2;
1451 aTolSum2=aTolSum*aTolSum;
1453 aP1=BRep_Tool::Pnt(aV1);
1455 aD2=aP1.SquareDistance(aP2);
1461 //=======================================================================
1462 // function: ComputeVV
1464 //=======================================================================
1465 Standard_Integer BOPTools_AlgoTools::ComputeVV(const TopoDS_Vertex& aV1,
1466 const TopoDS_Vertex& aV2)
1468 Standard_Real aTolV1, aTolV2, aTolSum, aTolSum2, aD2;
1471 aTolV1=BRep_Tool::Tolerance(aV1);
1472 aTolV2=BRep_Tool::Tolerance(aV2);
1473 aTolSum=aTolV1+aTolV2;
1474 aTolSum2=aTolSum*aTolSum;
1476 aP1=BRep_Tool::Pnt(aV1);
1477 aP2=BRep_Tool::Pnt(aV2);
1479 aD2=aP1.SquareDistance(aP2);
1485 //=======================================================================
1486 // function: MakeVertex
1488 //=======================================================================
1489 void BOPTools_AlgoTools::MakeVertex(BOPCol_ListOfShape& aLV,
1490 TopoDS_Vertex& aVnew)
1492 Standard_Integer aNb;
1493 Standard_Real aTi, aDi, aDmax;
1495 gp_XYZ aXYZ(0.,0.,0.), aXYZi;
1496 BOPCol_ListIteratorOfListOfShape aIt;
1500 aIt.Initialize(aLV);
1501 for (; aIt.More(); aIt.Next()) {
1502 TopoDS_Vertex& aVi=*((TopoDS_Vertex*)(&aIt.Value()));
1503 aPi=BRep_Tool::Pnt(aVi);
1508 aXYZ.Divide((Standard_Real)aNb);
1512 aIt.Initialize(aLV);
1513 for (; aIt.More(); aIt.Next()) {
1514 TopoDS_Vertex& aVi=*((TopoDS_Vertex*)(&aIt.Value()));
1515 aPi=BRep_Tool::Pnt(aVi);
1516 aTi=BRep_Tool::Tolerance(aVi);
1517 aDi=aP.SquareDistance(aPi);
1526 aBB.MakeVertex (aVnew, aP, aDmax);
1529 //=======================================================================
1530 //function : GetEdgeOnFace
1532 //=======================================================================
1533 Standard_Boolean BOPTools_AlgoTools::GetEdgeOnFace
1534 (const TopoDS_Edge& theE1,
1535 const TopoDS_Face& theF2,
1538 Standard_Boolean bFound;
1539 TopoDS_Iterator aItF, aItW;
1541 bFound=Standard_False;
1543 aItF.Initialize(theF2);
1544 for (; aItF.More(); aItF.Next()) {
1545 const TopoDS_Shape& aW=aItF.Value();
1546 aItW.Initialize(aW);
1547 for (; aItW.More(); aItW.Next()) {
1548 const TopoDS_Shape& aE=aItW.Value();
1549 if (aE.IsSame(theE1)) {
1550 theE2=(*(TopoDS_Edge*)(&aE));
1558 //=======================================================================
1559 //function : FindFacePairs
1561 //=======================================================================
1562 Standard_Boolean FindFacePairs (const TopoDS_Edge& theE,
1563 const BOPCol_ListOfShape& thLF,
1564 BOPTools_ListOfCoupleOfShape& theLCFF,
1565 Handle(IntTools_Context)& theContext)
1567 Standard_Boolean bFound;
1568 Standard_Integer i, aNbCEF;
1569 TopAbs_Orientation aOr, aOrC = TopAbs_FORWARD;
1570 BOPCol_MapOfShape aMFP;
1571 TopoDS_Face aF1, aF2;
1572 TopoDS_Edge aEL, aE1;
1573 BOPCol_ListIteratorOfListOfShape aItLF;
1574 BOPTools_CoupleOfShape aCEF, aCFF;
1575 BOPTools_ListOfCoupleOfShape aLCEF, aLCEFx;
1576 BOPTools_ListIteratorOfListOfCoupleOfShape aIt;
1578 bFound=Standard_True;
1581 aItLF.Initialize(thLF);
1582 for (; aItLF.More(); aItLF.Next()) {
1583 const TopoDS_Face& aFL=(*(TopoDS_Face*)(&aItLF.Value()));
1585 bFound=BOPTools_AlgoTools::GetEdgeOnFace(theE, aFL, aEL);
1587 return bFound; // it can not be so
1590 aCEF.SetShape1(aEL);
1591 aCEF.SetShape2(aFL);
1595 aNbCEF=aLCEF.Extent();
1600 aIt.Initialize(aLCEF);
1601 for (i=0; aIt.More(); aIt.Next(), ++i) {
1602 const BOPTools_CoupleOfShape& aCSx=aIt.Value();
1603 const TopoDS_Shape& aEx=aCSx.Shape1();
1604 const TopoDS_Shape& aFx=aCSx.Shape2();
1606 aOr=aEx.Orientation();
1609 aOrC=TopAbs::Reverse(aOr);
1610 aE1=(*(TopoDS_Edge*)(&aEx));
1611 aF1=(*(TopoDS_Face*)(&aFx));
1617 aLCEFx.Append(aCSx);
1623 BOPTools_AlgoTools::GetFaceOff(aE1, aF1, aLCEFx, aF2, theContext);
1625 aCFF.SetShape1(aF1);
1626 aCFF.SetShape2(aF2);
1627 theLCFF.Append(aCFF);
1636 aIt.Initialize(aLCEFx);
1637 for (; aIt.More(); aIt.Next()) {
1638 const BOPTools_CoupleOfShape& aCSx=aIt.Value();
1639 const TopoDS_Shape& aFx=aCSx.Shape2();
1640 if (!aMFP.Contains(aFx)) {
1645 aNbCEF=aLCEF.Extent();
1650 //=======================================================================
1651 //function : AngleWithRef
1653 //=======================================================================
1654 Standard_Real AngleWithRef(const gp_Dir& theD1,
1655 const gp_Dir& theD2,
1656 const gp_Dir& theDRef)
1658 Standard_Real aCosinus, aSinus, aBeta, aHalfPI, aScPr;
1663 const gp_XYZ& aXYZ1=theD1.XYZ();
1664 const gp_XYZ& aXYZ2=theD2.XYZ();
1665 aXYZ=aXYZ1.Crossed(aXYZ2);
1666 aSinus=aXYZ.Modulus();
1667 aCosinus=theD1*theD2;
1671 aBeta=aHalfPI*(1.-aCosinus);
1674 aBeta=2.*M_PI-aHalfPI*(3.+aCosinus);
1677 aScPr=aXYZ.Dot(theDRef.XYZ());
1683 //=======================================================================
1684 // function: IsBlockInOnFace
1686 //=======================================================================
1687 Standard_Boolean BOPTools_AlgoTools::IsBlockInOnFace
1688 (const IntTools_Range& aShrR,
1689 const TopoDS_Face& aF,
1690 const TopoDS_Edge& aE1,
1691 Handle(IntTools_Context)& aContext)
1693 Standard_Boolean bFlag;
1694 Standard_Real f1, l1, ULD, VLD;
1698 aShrR.Range(f1, l1);
1699 Standard_Real dt=0.0075, k;//dt=0.001, k;
1705 BOPTools_AlgoTools::PointOnEdge(aE1, f1, aP11);
1707 GeomAPI_ProjectPointOnSurf& aProjector=aContext->ProjPS(aF);
1708 aProjector.Perform(aP11);
1710 bFlag=aProjector.IsDone();
1715 aProjector.LowerDistanceParameters(ULD, VLD);
1716 aP2D.SetCoord(ULD, VLD);
1718 bFlag=aContext->IsPointInOnFace (aF, aP2D);
1725 BOPTools_AlgoTools::PointOnEdge(aE1, l1, aP12);
1727 aProjector.Perform(aP12);
1729 bFlag=aProjector.IsDone();
1734 aProjector.LowerDistanceParameters(ULD, VLD);
1735 aP2D.SetCoord(ULD, VLD);
1737 bFlag=aContext->IsPointInOnFace (aF, aP2D);
1743 // Treatment intemediate
1744 Standard_Real m1, aTolF, aTolE, aTol, aDist;
1745 m1=IntTools_Tools::IntermediatePoint(f1, l1);
1746 BOPTools_AlgoTools::PointOnEdge(aE1, m1, aP12);
1748 aProjector.Perform(aP12);
1750 bFlag=aProjector.IsDone();
1755 aTolE=BRep_Tool::Tolerance(aE1);
1756 aTolF=BRep_Tool::Tolerance(aF);
1758 aDist=aProjector.LowerDistance();
1760 return Standard_False;
1763 aProjector.LowerDistanceParameters(ULD, VLD);
1764 aP2D.SetCoord(ULD, VLD);
1766 bFlag=aContext->IsPointInOnFace (aF, aP2D);
1774 //=======================================================================
1775 //function : IsMicroEdge
1777 //=======================================================================
1778 Standard_Boolean BOPTools_AlgoTools::IsMicroEdge
1779 (const TopoDS_Edge& aE,
1780 const Handle(IntTools_Context)& aCtx)
1782 Standard_Boolean bRet;
1783 Standard_Integer iErr;
1784 Standard_Real aT1, aT2, aTmp;
1785 Handle(Geom_Curve) aC3D;
1786 TopoDS_Vertex aV1, aV2;
1788 bRet=(BRep_Tool::Degenerated(aE) ||
1789 !BRep_Tool::IsGeometric(aE));
1794 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
1795 TopExp::Vertices(aE, aV1, aV2);
1796 aT1=BRep_Tool::Parameter(aV1, aE);
1797 aT2=BRep_Tool::Parameter(aV2, aE);
1804 IntTools_ShrunkRange aSR;
1805 aSR.SetContext(aCtx);
1806 aSR.SetData(aE, aT1, aT2, aV1, aV2);
1808 iErr=aSR.ErrorStatus();
1814 //=======================================================================
1815 //function : GetFaceDir
1816 //purpose : Get binormal direction for the face in the point aP
1817 //=======================================================================
1818 void GetFaceDir(const TopoDS_Edge& aE,
1819 const TopoDS_Face& aF,
1821 const Standard_Real aT,
1822 const gp_Dir& aDTgt,
1825 Handle(IntTools_Context)& theContext,
1826 GeomAPI_ProjectPointOnSurf& aProjPL,
1827 const Standard_Real aDt)
1829 Standard_Real aTolE;
1832 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge(aE, aF, aT, aDN);
1833 if (aF.Orientation()==TopAbs_REVERSED){
1837 aTolE=BRep_Tool::Tolerance(aE);
1840 if (!FindPointInFace(aF, aP, aDB, aPx, theContext, aProjPL, aDt, aTolE)) {
1841 BOPTools_AlgoTools3D::GetApproxNormalToFaceOnEdge(aE, aF, aT, aPx,
1843 aProjPL.Perform(aPx);
1844 aPx = aProjPL.NearestPoint();
1845 gp_Vec aVec(aP, aPx);
1846 aDB.SetXYZ(aVec.XYZ());
1849 //=======================================================================
1850 //function : FindPointInFace
1851 //purpose : Find a point in the face in direction of <aDB>
1852 //=======================================================================
1853 Standard_Boolean FindPointInFace(const TopoDS_Face& aF,
1857 Handle(IntTools_Context)& theContext,
1858 GeomAPI_ProjectPointOnSurf& aProjPL,
1859 const Standard_Real aDt,
1860 const Standard_Real aTolE)
1862 Standard_Integer aNbItMax;
1863 Standard_Real aDist, aDTol, aPM, anEps;
1864 Standard_Boolean bRet;
1867 aDTol = Precision::Angular();
1868 aPM = aP.XYZ().Modulus();
1870 aDTol = 5.e-16 * aPM;
1872 bRet = Standard_False;
1874 anEps = Precision::SquareConfusion();
1876 GeomAPI_ProjectPointOnSurf& aProj=theContext->ProjPS(aF);
1880 if (!aProj.IsDone()) {
1883 aPS=aProj.NearestPoint();
1884 aProjPL.Perform(aPS);
1885 aPS=aProjPL.NearestPoint();
1887 aPS.SetXYZ(aPS.XYZ()+2.*aTolE*aDB.XYZ());
1889 if (!aProj.IsDone()) {
1892 aPS=aProj.NearestPoint();
1893 aProjPL.Perform(aPS);
1894 aPS=aProjPL.NearestPoint();
1897 aP1.SetXYZ(aPS.XYZ()+aDt*aDB.XYZ());
1900 if (!aProj.IsDone()) {
1903 aPOut = aProj.NearestPoint();
1904 aDist = aProj.LowerDistance();
1906 aProjPL.Perform(aPOut);
1907 aPOut = aProjPL.NearestPoint();
1909 gp_Vec aV(aPS, aPOut);
1910 if (aV.SquareMagnitude() < anEps) {
1913 aDB.SetXYZ(aV.XYZ());
1914 } while (aDist > aDTol && --aNbItMax);
1916 bRet = aDist < aDTol;
1919 //=======================================================================
1920 //function : MinStep3D
1922 //=======================================================================
1923 Standard_Real MinStep3D(const TopoDS_Edge& theE1,
1924 const TopoDS_Face& theF1,
1925 const BOPTools_ListOfCoupleOfShape& theLCS,
1928 Standard_Real aDt, aTolE, aTolF, aDtMax, aDtMin, aR;
1929 BOPTools_CoupleOfShape aCS1;
1930 BOPTools_ListOfCoupleOfShape aLCS;
1931 BOPTools_ListIteratorOfListOfCoupleOfShape aIt;
1932 BRepAdaptor_Surface aBAS;
1935 aCS1.SetShape1(theE1);
1936 aCS1.SetShape2(theF1);
1939 aTolE = BRep_Tool::Tolerance(theE1);
1943 aIt.Initialize(aLCS);
1944 for (; aIt.More(); aIt.Next()) {
1945 const BOPTools_CoupleOfShape& aCS = aIt.Value();
1946 const TopoDS_Face& aF = (*(TopoDS_Face*)(&aCS.Shape2()));
1948 aTolF = BRep_Tool::Tolerance(aF);
1949 aDt = 2*(aTolE + aTolF);
1952 aBAS.Initialize(aF, Standard_False);
1953 GeomAbs_SurfaceType aSType = aBAS.GetType();
1955 case GeomAbs_Cylinder: {
1956 aR = aBAS.Cylinder().Radius();
1959 case GeomAbs_Cone: {
1960 gp_Lin aL(aBAS.Cone().Axis());
1961 aR = aL.Distance(aP);
1964 case GeomAbs_Sphere: {
1965 aDtMin = Max(aDtMin, 5.e-4);
1966 aR = aBAS.Sphere().Radius();
1969 case GeomAbs_Torus: {
1970 aR = aBAS.Torus().MajorRadius();
1974 aDtMin = Max(aDtMin, 5.e-4);
1979 Standard_Real d = 10*Precision::PConfusion();
1980 aDtMin = Max(aDtMin, sqrt(d*d + 2*d*aR));
1988 if (aDtMax < aDtMin) {
1994 //=======================================================================
1995 //function : IsOpenShell
1997 //=======================================================================
1998 Standard_Boolean BOPTools_AlgoTools::IsOpenShell(const TopoDS_Shell& aSh)
2000 Standard_Boolean bRet;
2001 Standard_Integer i, aNbE, aNbF;
2002 TopAbs_Orientation aOrF;
2003 BOPCol_IndexedDataMapOfShapeListOfShape aMEF;
2004 BOPCol_ListIteratorOfListOfShape aItLS;
2006 bRet=Standard_False;
2008 BOPTools::MapShapesAndAncestors(aSh, TopAbs_EDGE, TopAbs_FACE, aMEF);
2011 for (i=1; i<=aNbE; ++i) {
2012 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aMEF.FindKey(i));
2013 if (BRep_Tool::Degenerated(aE)) {
2018 const BOPCol_ListOfShape& aLF=aMEF(i);
2019 aItLS.Initialize(aLF);
2020 for (; aItLS.More(); aItLS.Next()) {
2021 const TopoDS_Shape& aF=aItLS.Value();
2022 aOrF=aF.Orientation();
2023 if (aOrF==TopAbs_INTERNAL || aOrF==TopAbs_EXTERNAL) {
2037 //=======================================================================
2038 //function : IsInvertedSolid
2040 //=======================================================================
2041 Standard_Boolean BOPTools_AlgoTools::IsInvertedSolid
2042 (const TopoDS_Solid& aSolid)
2044 Standard_Real aTolS;
2045 TopAbs_State aState;
2046 BRepClass3d_SolidClassifier aSC(aSolid);
2049 aSC.PerformInfinitePoint(aTolS);
2051 return (aState==TopAbs_IN);