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.
19 #include <BOPCol_IndexedMapOfShape.hxx>
20 #include <BOPCol_MapOfShape.hxx>
21 #include <BOPTools.hxx>
22 #include <BOPTools_AlgoTools.hxx>
23 #include <BOPTools_AlgoTools2D.hxx>
24 #include <BOPTools_AlgoTools3D.hxx>
25 #include <BOPTools_CoupleOfShape.hxx>
26 #include <BOPTools_ListOfCoupleOfShape.hxx>
27 #include <BRep_Builder.hxx>
28 #include <BRep_Tool.hxx>
29 #include <BRepAdaptor_Curve2d.hxx>
30 #include <BRepAdaptor_Surface.hxx>
31 #include <BRepClass3d_SolidClassifier.hxx>
32 #include <BRepLib.hxx>
33 #include <Geom2d_Curve.hxx>
34 #include <Geom2dInt_Geom2dCurveTool.hxx>
35 #include <Geom_Curve.hxx>
36 #include <Geom_Plane.hxx>
37 #include <Geom_Surface.hxx>
38 #include <Geom_TrimmedCurve.hxx>
39 #include <GeomAPI_ProjectPointOnSurf.hxx>
40 #include <gp_Cone.hxx>
41 #include <gp_Cylinder.hxx>
44 #include <gp_Pnt2d.hxx>
45 #include <gp_Sphere.hxx>
46 #include <gp_Torus.hxx>
48 #include <IntTools_Context.hxx>
49 #include <IntTools_Curve.hxx>
50 #include <IntTools_Range.hxx>
51 #include <IntTools_ShrunkRange.hxx>
52 #include <IntTools_Tools.hxx>
53 #include <Precision.hxx>
54 #include <TopAbs_Orientation.hxx>
56 #include <TopExp_Explorer.hxx>
57 #include <TopoDS_Compound.hxx>
58 #include <TopoDS_CompSolid.hxx>
59 #include <TopoDS_Edge.hxx>
60 #include <TopoDS_Face.hxx>
61 #include <TopoDS_Shape.hxx>
62 #include <TopoDS_Shell.hxx>
63 #include <TopoDS_Solid.hxx>
64 #include <TopoDS_Vertex.hxx>
65 #include <TopoDS_Wire.hxx>
66 #include <NCollection_Array1.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,
112 //=======================================================================
113 // function: MakeConnexityBlocks
115 //=======================================================================
116 void BOPTools_AlgoTools::MakeConnexityBlocks
117 (const TopoDS_Shape& theS,
118 const TopAbs_ShapeEnum theType1,
119 const TopAbs_ShapeEnum theType2,
120 BOPCol_ListOfShape& theLCB)
122 Standard_Integer aNbF, aNbAdd, aNbAdd1, i;
126 TopExp_Explorer aExp;
127 BOPCol_MapOfShape aMP;
128 BOPCol_IndexedMapOfShape aMCB, aMAdd, aMAdd1;
129 BOPCol_IndexedDataMapOfShapeListOfShape aMEF;
130 BOPCol_ListIteratorOfListOfShape aItLF;
133 BOPTools::MapShapesAndAncestors(theS, theType1, theType2, aMEF);
136 aIt.Initialize(theS);
137 for (; aIt.More(); aIt.Next()) {
138 const TopoDS_Shape& aF1=aIt.Value();
139 if (aMP.Contains(aF1)) {
150 aNbAdd = aMAdd.Extent();
151 for (i=1; i<=aNbAdd; ++i) {
152 const TopoDS_Shape& aF=aMAdd(i);
154 aExp.Init(aF, theType1);
155 for (; aExp.More(); aExp.Next()) {
156 const TopoDS_Shape& aE=aExp.Current();
158 const BOPCol_ListOfShape& aLF=aMEF.FindFromKey(aE);
159 aItLF.Initialize(aLF);
160 for (; aItLF.More(); aItLF.Next()) {
161 const TopoDS_Shape& aFx=aItLF.Value();
162 if (aFx.IsSame(aF)) {
165 if (aMCB.Contains(aFx)) {
170 }//for (; aExp.More(); aExp.Next()){
172 }// for (i=1; i<=aNbAdd; ++i) {
174 aNbAdd1=aMAdd1.Extent();
176 break;// ->make new CB from aMCB
180 for (i=1; i<=aNbAdd1; ++i) {
181 const TopoDS_Shape& aFAdd = aMAdd1(i);
188 aBB.MakeCompound(aC);
190 for (i=1; i<=aNbF; ++i) {
191 const TopoDS_Shape& aF=aMCB(i);
197 }// for (; aIt.More(); aIt.Next())
199 //=======================================================================
200 // function: OrientFacesOnShell
202 //=======================================================================
203 void BOPTools_AlgoTools::OrientFacesOnShell (TopoDS_Shape& aShell)
205 Standard_Boolean bIsProcessed1, bIsProcessed2;
206 Standard_Integer i, aNbE, aNbF, j;
207 TopAbs_Orientation anOrE1, anOrE2;
208 TopoDS_Face aF1x, aF2x;
209 TopoDS_Shape aShellNew;
210 BOPCol_IndexedDataMapOfShapeListOfShape aEFMap;
211 BOPCol_IndexedMapOfShape aProcessedFaces;
214 BOPTools_AlgoTools::MakeContainer(TopAbs_SHELL, aShellNew);
216 BOPTools::MapShapesAndAncestors(aShell,
217 TopAbs_EDGE, TopAbs_FACE,
219 aNbE=aEFMap.Extent();
221 // One seam edge in aEFMap contains 2 equivalent faces.
222 for (i=1; i<=aNbE; ++i) {
223 BOPCol_ListOfShape& aLF=aEFMap.ChangeFromIndex(i);
226 BOPCol_ListOfShape aLFTmp;
227 BOPCol_IndexedMapOfShape aFM;
229 BOPCol_ListIteratorOfListOfShape anIt(aLF);
230 for (; anIt.More(); anIt.Next()) {
231 const TopoDS_Shape& aF=anIt.Value();
232 if (!aFM.Contains(aF)) {
243 for (i=1; i<=aNbE; ++i) {
244 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aEFMap.FindKey(i)));
245 if (BRep_Tool::Degenerated(aE)) {
249 const BOPCol_ListOfShape& aLF=aEFMap.FindFromIndex(i);
255 TopoDS_Face& aF1=(*(TopoDS_Face*)(&aLF.First()));
256 TopoDS_Face& aF2=(*(TopoDS_Face*)(&aLF.Last()));
258 bIsProcessed1=aProcessedFaces.Contains(aF1);
259 bIsProcessed2=aProcessedFaces.Contains(aF2);
260 if (bIsProcessed1 && bIsProcessed2) {
264 if (!bIsProcessed1 && !bIsProcessed2) {
265 aProcessedFaces.Add(aF1);
266 aBB.Add(aShellNew, aF1);
267 bIsProcessed1=!bIsProcessed1;
272 j=aProcessedFaces.FindIndex(aF1);
273 aF1x=(*(TopoDS_Face*)(&aProcessedFaces.FindKey(j)));
278 j=aProcessedFaces.FindIndex(aF2);
279 aF2x=(*(TopoDS_Face*)(&aProcessedFaces.FindKey(j)));
282 anOrE1=Orientation(aE, aF1x);
283 anOrE2=Orientation(aE, aF2x);
285 if (bIsProcessed1 && !bIsProcessed2) {
286 if (anOrE1==anOrE2) {
287 if (!BRep_Tool::IsClosed(aE, aF1) &&
288 !BRep_Tool::IsClosed(aE, aF2)) {
292 aProcessedFaces.Add(aF2);
293 aBB.Add(aShellNew, aF2);
295 else if (!bIsProcessed1 && bIsProcessed2) {
296 if (anOrE1==anOrE2) {
297 if (!BRep_Tool::IsClosed(aE, aF1) &&
298 !BRep_Tool::IsClosed(aE, aF2)) {
302 aProcessedFaces.Add(aF1);
303 aBB.Add(aShellNew, aF1);
308 for (i=1; i<=aNbE; ++i) {
309 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aEFMap.FindKey(i)));
310 if (BRep_Tool::Degenerated(aE)) {
314 const BOPCol_ListOfShape& aLF=aEFMap.FindFromIndex(i);
317 BOPCol_ListIteratorOfListOfShape anIt(aLF);
318 for(; anIt.More(); anIt.Next()) {
319 const TopoDS_Face& aF=(*(TopoDS_Face*)(&anIt.Value()));
320 if (!aProcessedFaces.Contains(aF)) {
321 aProcessedFaces.Add(aF);
322 aBB.Add(aShellNew, aF);
329 //=======================================================================
330 //function : Orientation
332 //=======================================================================
333 TopAbs_Orientation Orientation(const TopoDS_Edge& anE,
334 const TopoDS_Face& aF)
336 TopAbs_Orientation anOr=TopAbs_INTERNAL;
338 TopExp_Explorer anExp;
339 anExp.Init(aF, TopAbs_EDGE);
340 for (; anExp.More(); anExp.Next()) {
341 const TopoDS_Edge& anEF1=(*(TopoDS_Edge*)(&anExp.Current()));
342 if (anEF1.IsSame(anE)) {
343 anOr=anEF1.Orientation();
349 //=======================================================================
350 // function: MakeConnexityBlock.
352 //=======================================================================
353 void BOPTools_AlgoTools::MakeConnexityBlock
354 (BOPCol_ListOfShape& theLFIn,
355 BOPCol_IndexedMapOfShape& theMEAvoid,
356 BOPCol_ListOfShape& theLCB,
357 const Handle(NCollection_BaseAllocator)& theAllocator)
359 Standard_Integer aNbF, aNbAdd1, aNbAdd, i;
360 TopExp_Explorer aExp;
361 BOPCol_ListIteratorOfListOfShape aIt;
363 BOPCol_IndexedMapOfShape aMCB(100, theAllocator);
364 BOPCol_IndexedMapOfShape aMAdd(100, theAllocator);
365 BOPCol_IndexedMapOfShape aMAdd1(100, theAllocator);
366 BOPCol_IndexedDataMapOfShapeListOfShape aMEF(100, theAllocator);
369 aNbF=theLFIn.Extent();
370 aIt.Initialize(theLFIn);
371 for (; aIt.More(); aIt.Next()) {
372 const TopoDS_Shape& aF=aIt.Value();
373 BOPTools::MapShapesAndAncestors(aF, TopAbs_EDGE, TopAbs_FACE, aMEF);
377 const TopoDS_Shape& aF1=theLFIn.First();
382 aNbAdd = aMAdd.Extent();
383 for (i=1; i<=aNbAdd; ++i) {
384 const TopoDS_Shape& aF=aMAdd(i);
387 aExp.Init(aF, TopAbs_EDGE);
388 for (; aExp.More(); aExp.Next()) {
389 const TopoDS_Shape& aE=aExp.Current();
390 if (theMEAvoid.Contains(aE)){
394 const BOPCol_ListOfShape& aLF=aMEF.FindFromKey(aE);
396 for (; aIt.More(); aIt.Next()) {
397 const TopoDS_Shape& aFx=aIt.Value();
398 if (aFx.IsSame(aF)) {
401 if (aMCB.Contains(aFx)) {
406 }//for (; aExp.More(); aExp.Next()){
408 }// for (i=1; i<=aNbAdd; ++i) {
410 aNbAdd1=aMAdd1.Extent();
416 for (i=1; i<=aNbAdd1; ++i) {
417 const TopoDS_Shape& aFAdd=aMAdd1(i);
425 for (i=1; i<=aNbF; ++i) {
426 const TopoDS_Shape& aF=aMCB(i);
430 //=======================================================================
431 // function: ComputeStateByOnePoint
433 //=======================================================================
434 TopAbs_State BOPTools_AlgoTools::ComputeStateByOnePoint
435 (const TopoDS_Shape& theS,
436 const TopoDS_Solid& theRef,
437 const Standard_Real theTol,
438 Handle(IntTools_Context)& theContext)
441 TopAbs_ShapeEnum aType;
443 aState=TopAbs_UNKNOWN;
444 aType=theS.ShapeType();
445 if (aType==TopAbs_VERTEX) {
446 const TopoDS_Vertex& aV=(*(TopoDS_Vertex*)(&theS));
447 aState=BOPTools_AlgoTools::ComputeState(aV, theRef, theTol, theContext);
449 else if (aType==TopAbs_EDGE) {
450 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&theS));
451 aState=BOPTools_AlgoTools::ComputeState(aE, theRef, theTol, theContext);
456 //=======================================================================
457 // function: ComputeState
459 //=======================================================================
460 TopAbs_State BOPTools_AlgoTools::ComputeState
461 (const TopoDS_Face& theF,
462 const TopoDS_Solid& theRef,
463 const Standard_Real theTol,
464 BOPCol_IndexedMapOfShape& theBounds,
465 Handle(IntTools_Context)& theContext)
468 TopExp_Explorer aExp;
473 aState=TopAbs_UNKNOWN;
475 aExp.Init(theF, TopAbs_EDGE);
476 for (; aExp.More(); aExp.Next()) {
477 const TopoDS_Edge& aSE=(*(TopoDS_Edge*)(&aExp.Current()));
478 if (BRep_Tool::Degenerated(aSE)) {
482 if (!theBounds.Contains(aSE)) {
483 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aSE));
484 aState=BOPTools_AlgoTools::ComputeState(aE, theRef, theTol,
489 aE1=(*(TopoDS_Edge*)(&aSE));
492 // !!<- process edges that are all on theRef
494 BOPTools_AlgoTools3D::PointNearEdge(aE1, theF,
495 aP2D, aP3D, theContext);
496 aState=BOPTools_AlgoTools::ComputeState(aP3D, theRef, theTol,
502 //=======================================================================
503 // function: ComputeState
505 //=======================================================================
506 TopAbs_State BOPTools_AlgoTools::ComputeState
507 (const TopoDS_Vertex& theV,
508 const TopoDS_Solid& theRef,
509 const Standard_Real theTol,
510 Handle(IntTools_Context)& theContext)
515 aP3D=BRep_Tool::Pnt(theV);
516 aState=BOPTools_AlgoTools::ComputeState(aP3D, theRef, theTol,
520 //=======================================================================
521 // function: ComputeState
523 //=======================================================================
524 TopAbs_State BOPTools_AlgoTools::ComputeState
525 (const TopoDS_Edge& theE,
526 const TopoDS_Solid& theRef,
527 const Standard_Real theTol,
528 Handle(IntTools_Context)& theContext)
530 Standard_Real aT1, aT2, aT = 0.;
532 Handle(Geom_Curve) aC3D;
535 aC3D = BRep_Tool::Curve(theE, aT1, aT2);
538 //it means that we are in degenerated edge
539 const TopoDS_Vertex& aV = TopExp::FirstVertex(theE);
541 return TopAbs_UNKNOWN;
543 aP3D=BRep_Tool::Pnt(aV);
546 Standard_Boolean bF2Inf, bL2Inf;
547 Standard_Real dT=10.;
549 bF2Inf = Precision::IsNegativeInfinite(aT1);
550 bL2Inf = Precision::IsPositiveInfinite(aT2);
552 if (bF2Inf && !bL2Inf) {
555 else if (!bF2Inf && bL2Inf) {
558 else if (bF2Inf && bL2Inf) {
562 aT=IntTools_Tools::IntermediatePoint(aT1, aT2);
567 aState=BOPTools_AlgoTools::ComputeState(aP3D, theRef, theTol,
572 //=======================================================================
573 // function: ComputeState
575 //=======================================================================
576 TopAbs_State BOPTools_AlgoTools::ComputeState
578 const TopoDS_Solid& theRef,
579 const Standard_Real theTol,
580 Handle(IntTools_Context)& theContext)
584 BRepClass3d_SolidClassifier& aSC=theContext->SolidClassifier(theRef);
585 aSC.Perform(theP, theTol);
591 //=======================================================================
592 //function : IsInternalFace
594 //=======================================================================
595 Standard_Boolean BOPTools_AlgoTools::IsInternalFace
596 (const TopoDS_Face& theFace,
597 const TopoDS_Solid& theSolid,
598 BOPCol_IndexedDataMapOfShapeListOfShape& theMEF,
599 const Standard_Real theTol,
600 Handle(IntTools_Context)& theContext)
602 Standard_Boolean bDegenerated;
603 Standard_Integer aNbF, iRet, iFound;
604 TopAbs_Orientation aOr;
606 TopExp_Explorer aExp;
607 BOPCol_ListIteratorOfListOfShape aItF;
609 // For all invoked functions: [::IsInternalFace(...)]
610 // the returned value iRet means:
611 // iRet=0; - state is not IN
612 // iRet=1; - state is IN
613 // iRet=2; - state can not be found by the method of angles
615 // For this function the returned value iRet means:
616 // iRet=0; - state is not IN
617 // iRet=1; - state is IN
620 // 1 Try to find an edge from theFace in theMEF
622 aExp.Init(theFace, TopAbs_EDGE);
623 for(; aExp.More(); aExp.Next()) {
624 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current()));
625 if (!theMEF.Contains(aE)) {
631 aOr=aE.Orientation();
632 if (aOr==TopAbs_INTERNAL) {
635 bDegenerated=BRep_Tool::Degenerated(aE);
640 BOPCol_ListOfShape& aLF=theMEF.ChangeFromKey(aE);
643 return iRet != 0; // it can not be so
647 // aE is internal edge on aLF.First()
648 const TopoDS_Face& aF1=(*(TopoDS_Face*)(&aLF.First()));
649 BOPTools_AlgoTools::GetEdgeOnFace(aE, aF1, aE1);
650 if (aE1.Orientation()!=TopAbs_INTERNAL) {
655 iRet=BOPTools_AlgoTools::IsInternalFace(theFace, aE, aF1, aF1,
661 const TopoDS_Face& aF1=(*(TopoDS_Face*)(&aLF.First()));
662 const TopoDS_Face& aF2=(*(TopoDS_Face*)(&aLF.Last()));
664 if (aF2.IsSame(aF1) && BRep_Tool::IsClosed(aE, aF1)) {
665 // treat as it was for 1 face
666 iRet=BOPTools_AlgoTools::IsInternalFace(theFace, aE, aF1, aF2,
673 return Standard_False; // it can not be so
675 else { // aNbF=2,4,6,8,...
676 iRet=BOPTools_AlgoTools::IsInternalFace(theFace, aE, aLF,
680 }//for(; aExp.More(); aExp.Next()) {
683 // the face has no shared edges with the solid
691 //========================================
692 // 2. Classify face using classifier
695 BOPCol_IndexedMapOfShape aBounds;
697 BOPTools::MapShapes(theSolid, TopAbs_EDGE, aBounds);
699 aState=BOPTools_AlgoTools::ComputeState(theFace, theSolid,
700 theTol, aBounds, theContext);
701 return aState == TopAbs_IN;
703 //=======================================================================
704 //function : IsInternalFace
706 //=======================================================================
707 Standard_Integer BOPTools_AlgoTools::IsInternalFace
708 (const TopoDS_Face& theFace,
709 const TopoDS_Edge& theEdge,
710 BOPCol_ListOfShape& theLF,
711 Handle(IntTools_Context)& theContext)
713 Standard_Integer aNbF, iRet;
719 const TopoDS_Face& aF1=(*(TopoDS_Face*)(&theLF.First()));
720 const TopoDS_Face& aF2=(*(TopoDS_Face*)(&theLF.Last()));
721 iRet=BOPTools_AlgoTools::IsInternalFace(theFace, theEdge, aF1, aF2,
727 BOPTools_ListOfCoupleOfShape aLCFF;
728 BOPTools_ListIteratorOfListOfCoupleOfShape aIt;
730 FindFacePairs(theEdge, theLF, aLCFF, theContext);
732 aIt.Initialize(aLCFF);
733 for (; aIt.More(); aIt.Next()) {
734 BOPTools_CoupleOfShape& aCSFF=aIt.ChangeValue();
736 const TopoDS_Face& aF1=(*(TopoDS_Face*)(&aCSFF.Shape1()));
737 const TopoDS_Face& aF2=(*(TopoDS_Face*)(&aCSFF.Shape2()));
738 iRet=BOPTools_AlgoTools::IsInternalFace(theFace, theEdge, aF1, aF2,
747 //=======================================================================
748 //function : IsInternalFace
750 //=======================================================================
751 Standard_Integer BOPTools_AlgoTools::IsInternalFace
752 (const TopoDS_Face& theFace,
753 const TopoDS_Edge& theEdge,
754 const TopoDS_Face& theFace1,
755 const TopoDS_Face& theFace2,
756 Handle(IntTools_Context)& theContext)
758 Standard_Boolean bRet;
759 Standard_Integer iRet;
760 TopoDS_Edge aE1, aE2;
762 BOPTools_ListOfCoupleOfShape theLCSOff;
763 BOPTools_CoupleOfShape aCS1, aCS2;
765 BOPTools_AlgoTools::GetEdgeOnFace(theEdge, theFace1, aE1);
766 if (aE1.Orientation()==TopAbs_INTERNAL) {
768 aE1.Orientation(TopAbs_FORWARD);
769 aE2.Orientation(TopAbs_REVERSED);
771 else if (theFace1==theFace2) {
773 aE1.Orientation(TopAbs_FORWARD);
774 aE2.Orientation(TopAbs_REVERSED);
777 BOPTools_AlgoTools::GetEdgeOnFace(theEdge, theFace2, aE2);
780 aCS1.SetShape1(theEdge);
781 aCS1.SetShape2(theFace);
782 theLCSOff.Append(aCS1);
785 aCS2.SetShape2(theFace2);
786 theLCSOff.Append(aCS2);
788 bRet=GetFaceOff(aE1, theFace1, theLCSOff, aFOff, theContext);
790 iRet=0; // theFace is not internal
791 if (theFace.IsEqual(aFOff)) {
792 // theFace is internal
795 // theFace seems to be internal
801 //=======================================================================
802 //function : GetFaceOff
804 //=======================================================================
805 Standard_Boolean BOPTools_AlgoTools::GetFaceOff
806 (const TopoDS_Edge& theE1,
807 const TopoDS_Face& theF1,
808 BOPTools_ListOfCoupleOfShape& theLCSOff,
809 TopoDS_Face& theFOff,
810 Handle(IntTools_Context)& theContext)
812 Standard_Boolean bRet;
813 Standard_Real aT, aT1, aT2, aAngle, aTwoPI, aAngleMin, aDt3D;
814 Standard_Real aUmin, aUsup, aVmin, aVsup, aPA;
815 gp_Pnt aPn1, aPn2, aPx;
816 gp_Dir aDN1, aDN2, aDBF, aDBF2, aDTF;
818 TopAbs_Orientation aOr;
819 Handle(Geom_Curve)aC3D;
820 Handle(Geom_Plane) aPL;
821 BOPTools_ListIteratorOfListOfCoupleOfShape aIt;
822 GeomAPI_ProjectPointOnSurf aProjPL;
824 aPA=Precision::Angular();
827 aC3D =BRep_Tool::Curve(theE1, aT1, aT2);
828 aT=BOPTools_AlgoTools2D::IntermediatePoint(aT1, aT2);
831 BOPTools_AlgoTools2D::EdgeTangent(theE1, aT, aVTgt);
832 gp_Dir aDTgt(aVTgt), aDTgt2;
833 aOr = theE1.Orientation();
835 aPL = new Geom_Plane(aPx, aDTgt);
836 aPL->Bounds(aUmin, aUsup, aVmin, aVsup);
837 aProjPL.Init(aPL, aUmin, aUsup, aVmin, aVsup);
839 aDt3D = MinStep3D(theE1, theF1, theLCSOff, aPx);
840 GetFaceDir(theE1, theF1, aPx, aT, aDTgt, aDN1, aDBF, theContext,
846 aIt.Initialize(theLCSOff);
847 for (; aIt.More(); aIt.Next()) {
848 const BOPTools_CoupleOfShape& aCS=aIt.Value();
849 const TopoDS_Edge& aE2=(*(TopoDS_Edge*)(&aCS.Shape1()));
850 const TopoDS_Face& aF2=(*(TopoDS_Face*)(&aCS.Shape2()));
852 aDTgt2 = (aE2.Orientation()==aOr) ? aDTgt : aDTgt.Reversed();
853 GetFaceDir(aE2, aF2, aPx, aT, aDTgt2, aDN2, aDBF2, theContext,
856 aAngle=AngleWithRef(aDBF, aDBF2, aDTF);
859 aAngle=aTwoPI+aAngle;
866 else if (aF2.IsSame(theF1)) {
871 if (fabs(aAngle-aAngleMin)<aPA) {
872 // the minimal angle can not be found
876 if (aAngle<aAngleMin){
880 else if (aAngle==aAngleMin) {
881 // the minimal angle can not be found
887 //=======================================================================
888 //function : GetEdgeOff
890 //=======================================================================
891 Standard_Boolean BOPTools_AlgoTools::GetEdgeOff(const TopoDS_Edge& theE1,
892 const TopoDS_Face& theF2,
895 Standard_Boolean bFound;
896 TopAbs_Orientation aOr1, aOr1C, aOr2;
897 TopExp_Explorer anExp;
899 bFound=Standard_False;
900 aOr1=theE1.Orientation();
901 aOr1C=TopAbs::Reverse(aOr1);
903 anExp.Init(theF2, TopAbs_EDGE);
904 for (; anExp.More(); anExp.Next()) {
905 const TopoDS_Edge& aEF2=(*(TopoDS_Edge*)(&anExp.Current()));
906 if (aEF2.IsSame(theE1)) {
907 aOr2=aEF2.Orientation();
918 //=======================================================================
919 //function : AreFacesSameDomain
921 //=======================================================================
922 Standard_Boolean BOPTools_AlgoTools::AreFacesSameDomain
923 (const TopoDS_Face& theF1,
924 const TopoDS_Face& theF2,
925 Handle(IntTools_Context)& theContext)
927 Standard_Boolean bFlag;
928 Standard_Integer iErr;
929 Standard_Real aTolF1, aTolF2, aTol;
932 TopoDS_Face aF1, aF2;
934 TopExp_Explorer aExp;
936 bFlag=Standard_False;
939 aF1.Orientation(TopAbs_FORWARD);
941 aF2.Orientation(TopAbs_FORWARD);
943 aTolF1=BRep_Tool::Tolerance(aF1);
945 aExp.Init(aF1, TopAbs_EDGE);
946 for (; aExp.More(); aExp.Next()) {
947 aE1=(*(TopoDS_Edge*)(&aExp.Current()));
948 if (!BRep_Tool::Degenerated(aE1)) {
949 Standard_Real aTolE = BRep_Tool::Tolerance(aE1);
950 aTolF1 = (aTolE > aTolF1) ? aTolE : aTolF1;
954 aTolF2=BRep_Tool::Tolerance(aF2);
955 aTol = aTolF1 + aTolF2 + Precision::Confusion();
957 iErr = BOPTools_AlgoTools3D::PointInFace(aF1, aP, aP2D,
960 bFlag=theContext->IsValidPointForFace(aP, aF2, aTol);
966 //=======================================================================
967 //function : CheckSameGeom
969 //=======================================================================
970 Standard_Boolean BOPTools_AlgoTools::CheckSameGeom
971 (const TopoDS_Face& theF1,
972 const TopoDS_Face& theF2,
973 Handle(IntTools_Context)& theContext)
975 Standard_Boolean bRet;
976 Standard_Real aTolF1, aTolF2, aTol;
979 TopExp_Explorer aExp;
982 aExp.Init(theF1, TopAbs_EDGE);
983 for (; aExp.More(); aExp.Next()) {
984 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current()));
985 if (!BRep_Tool::Degenerated(aE)) {
986 aTolF1=BRep_Tool::Tolerance(theF1);
987 aTolF2=BRep_Tool::Tolerance(theF2);
989 BOPTools_AlgoTools3D::PointNearEdge(aE, theF1, aP2D, aP, theContext);
990 bRet=theContext->IsValidPointForFace(aP, theF2, aTol);
996 //=======================================================================
999 //=======================================================================
1000 Standard_Integer BOPTools_AlgoTools::Sense (const TopoDS_Face& theF1,
1001 const TopoDS_Face& theF2)
1003 Standard_Integer iSense=0;
1004 gp_Dir aDNF1, aDNF2;
1005 TopoDS_Edge aE1, aE2;
1006 TopExp_Explorer aExp;
1008 aExp.Init(theF1, TopAbs_EDGE);
1009 for (; aExp.More(); aExp.Next()) {
1010 aE1=(*(TopoDS_Edge*)(&aExp.Current()));
1011 if (!BRep_Tool::Degenerated(aE1)) {
1012 if (!BRep_Tool::IsClosed(aE1, theF1)) {
1018 aExp.Init(theF2, TopAbs_EDGE);
1019 for (; aExp.More(); aExp.Next()) {
1020 aE2=(*(TopoDS_Edge*)(&aExp.Current()));
1021 if (!BRep_Tool::Degenerated(aE2)) {
1022 if (!BRep_Tool::IsClosed(aE2, theF2)) {
1023 if (aE2.IsSame(aE1)) {
1035 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge(aE1, theF1, aDNF1);
1036 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge(aE2, theF2, aDNF2);
1038 iSense=BOPTools_AlgoTools3D::SenseFlag(aDNF1, aDNF2);
1042 //=======================================================================
1043 // function: IsSplitToReverse
1045 //=======================================================================
1046 Standard_Boolean BOPTools_AlgoTools::IsSplitToReverse
1047 (const TopoDS_Shape& theSp,
1048 const TopoDS_Shape& theSr,
1049 Handle(IntTools_Context)& theContext)
1051 Standard_Boolean bRet;
1052 TopAbs_ShapeEnum aType;
1054 bRet=Standard_False;
1056 aType=theSp.ShapeType();
1059 const TopoDS_Edge& aESp=(*(TopoDS_Edge*)(&theSp));
1060 const TopoDS_Edge& aESr=(*(TopoDS_Edge*)(&theSr));
1061 bRet=BOPTools_AlgoTools::IsSplitToReverse(aESp, aESr, theContext);
1066 const TopoDS_Face& aFSp=(*(TopoDS_Face*)(&theSp));
1067 const TopoDS_Face& aFSr=(*(TopoDS_Face*)(&theSr));
1068 bRet=BOPTools_AlgoTools::IsSplitToReverse(aFSp, aFSr, theContext);
1077 //=======================================================================
1078 //function :IsSplitToReverse
1080 //=======================================================================
1081 Standard_Boolean BOPTools_AlgoTools::IsSplitToReverse
1082 (const TopoDS_Face& theFSp,
1083 const TopoDS_Face& theFSr,
1084 Handle(IntTools_Context)& theContext)
1086 Standard_Boolean bRet, bFound, bInFace;
1087 Standard_Real aT1, aT2, aT, aU, aV, aScPr;
1088 gp_Pnt aPFSp, aPFSr;
1091 Handle(Geom_Surface) aSr, aSp;
1092 TopAbs_Orientation aOrSr, aOrSp;
1093 TopExp_Explorer anExp;
1096 bRet=Standard_False;
1098 aSr=BRep_Tool::Surface(theFSr);
1099 aSp=BRep_Tool::Surface(theFSp);
1101 aOrSr=theFSr.Orientation();
1102 aOrSp=theFSp.Orientation();
1103 bRet=(aOrSr!=aOrSp);
1107 bFound=Standard_False;
1108 anExp.Init(theFSp, TopAbs_EDGE);
1109 for (; anExp.More(); anExp.Next()) {
1110 aESp=(*(TopoDS_Edge*)(&anExp.Current()));
1111 if (!BRep_Tool::Degenerated(aESp)) {
1112 if (!BRep_Tool::IsClosed(aESp, theFSp)) {
1119 Standard_Boolean bFlag;
1120 Standard_Integer iErr;
1123 iErr=BOPTools_AlgoTools3D::PointInFace(theFSp, aPFSp, aP2DFSp,
1129 aP2DFSp.Coord(aU, aV);
1130 bFlag=BOPTools_AlgoTools3D::GetNormalToSurface(aSp, aU, aV, aDNFSp);
1135 if (theFSp.Orientation()==TopAbs_REVERSED){
1140 BRep_Tool::Range(aESp, aT1, aT2);
1141 aT=BOPTools_AlgoTools2D::IntermediatePoint(aT1, aT2);
1142 BOPTools_AlgoTools3D::GetApproxNormalToFaceOnEdge(aESp, theFSp, aT,
1147 // Parts of theContext->ComputeVS(..)
1148 GeomAPI_ProjectPointOnSurf& aProjector=theContext->ProjPS(theFSr);
1149 aProjector.Perform(aPFSp);
1150 if (!aProjector.IsDone()) {
1154 aProjector.LowerDistanceParameters(aU, aV);
1155 gp_Pnt2d aP2D(aU, aV);
1156 bInFace=theContext->IsPointInOnFace (theFSr, aP2D);
1161 aSr->D1(aU, aV, aPFSr, aD1U, aD1V);
1164 gp_Dir aDNFSr=aDD1U^aDD1V;
1165 if (theFSr.Orientation()==TopAbs_REVERSED){
1169 aScPr=aDNFSp*aDNFSr;
1174 //=======================================================================
1175 //function :IsSplitToReverse
1177 //=======================================================================
1178 Standard_Boolean BOPTools_AlgoTools::IsSplitToReverse
1179 (const TopoDS_Edge& aEF1,
1180 const TopoDS_Edge& aEF2,
1181 Handle(IntTools_Context)& theContext)
1183 Standard_Boolean bRet, bIsDegenerated;
1185 bRet=Standard_False;
1186 bIsDegenerated=(BRep_Tool::Degenerated(aEF1) ||
1187 BRep_Tool::Degenerated(aEF2));
1188 if (bIsDegenerated) {
1193 TopAbs_Orientation aOrE, aOrSp;
1194 Handle(Geom_Curve)aC1, aC2;
1196 aC2=BRep_Tool::Curve(aEF2, a, b);
1197 aC1=BRep_Tool::Curve(aEF1, a, b);
1200 aOrE=aEF2.Orientation();
1201 aOrSp=aEF1.Orientation();
1206 Standard_Real aT1, aT2, aScPr;
1210 aT1=BOPTools_AlgoTools2D::IntermediatePoint(a, b);
1212 BOPTools_AlgoTools2D::EdgeTangent(aEF1, aT1, aV1);
1215 theContext->ProjectPointOnEdge(aP, aEF2, aT2);
1217 BOPTools_AlgoTools2D::EdgeTangent(aEF2, aT2, aV2);
1226 //=======================================================================
1229 //=======================================================================
1230 Standard_Boolean BOPTools_AlgoTools::IsHole(const TopoDS_Shape& aW,
1231 const TopoDS_Shape& aFace)
1233 Standard_Boolean bIsHole;
1234 Standard_Integer i, aNbS;
1235 Standard_Real aT1, aT2, aS;
1236 Standard_Real aU1, aU, dU;
1237 Standard_Real aX1, aY1, aX0, aY0;
1238 TopAbs_Orientation aOr;
1240 gp_Pnt2d aP2D0, aP2D1;
1241 Handle(Geom2d_Curve) aC2D;
1242 TopoDS_Face aF, aFF;
1243 TopoDS_Iterator aItW;
1245 bIsHole=Standard_False;
1247 aF=(*(TopoDS_Face *)(&aFace));
1249 aFF.Orientation(TopAbs_FORWARD);
1252 aItW.Initialize(aW);
1253 for (; aItW.More(); aItW.Next()) {
1254 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aItW.Value()));
1255 aOr=aE.Orientation();
1256 if (!(aOr==TopAbs_FORWARD ||
1257 aOr==TopAbs_REVERSED)) {
1261 aC2D=BRep_Tool::CurveOnSurface(aE, aFF, aT1, aT2);
1262 if (aC2D.IsNull()) {
1266 BRepAdaptor_Curve2d aBAC2D(aE, aFF);
1267 aNbS=Geom2dInt_Geom2dCurveTool::NbSamples(aBAC2D);
1272 dU=(aT2-aT1)/(Standard_Real)(aNbS-1);
1275 if (aOr==TopAbs_REVERSED) {
1281 aBAC2D.D0(aU, aP2D0);
1282 for(i=2; i<=aNbS; i++) {
1284 aBAC2D.D0(aU, aP2D1);
1285 aP2D0.Coord(aX0, aY0);
1286 aP2D1.Coord(aX1, aY1);
1288 aS=aS+(aY0+aY1)*(aX1-aX0);
1292 }//for (; aItW.More(); aItW.Next()) {
1297 //=======================================================================
1298 // function: MakeContainer
1300 //=======================================================================
1301 void BOPTools_AlgoTools::MakeContainer(const TopAbs_ShapeEnum theType,
1307 case TopAbs_COMPOUND:{
1309 aBB.MakeCompound(aC);
1314 case TopAbs_COMPSOLID:{
1315 TopoDS_CompSolid aCS;
1316 aBB.MakeCompSolid(aCS);
1322 TopoDS_Solid aSolid;
1323 aBB.MakeSolid(aSolid);
1330 TopoDS_Shell aShell;
1331 aBB.MakeShell(aShell);
1338 aBB.MakeWire(aWire);
1347 //=======================================================================
1348 // function: MakePCurve
1350 //=======================================================================
1351 void BOPTools_AlgoTools::MakePCurve(const TopoDS_Edge& aE,
1352 const TopoDS_Face& aF1,
1353 const TopoDS_Face& aF2,
1354 const IntTools_Curve& aIC,
1355 const Standard_Boolean bPC1,
1356 const Standard_Boolean bPC2)
1360 Standard_Real aTolE, aT1, aT2, aOutFirst, aOutLast, aOutTol;
1361 Handle(Geom2d_Curve) aC2D, aC2DA, aC2Dx1;
1364 Standard_Boolean bPC;
1366 aTolE=BRep_Tool::Tolerance(aE);
1368 const Handle(Geom_Curve)& aC3DE=BRep_Tool::Curve(aE, aT1, aT2);
1369 Handle(Geom_TrimmedCurve)aC3DETrim=
1370 new Geom_TrimmedCurve(aC3DE, aT1, aT2);
1372 for (i=0; i<2; ++i) {
1373 bPC = !i ? bPC1 : bPC2;
1380 aC2Dx1=aIC.FirstCurve2d();
1384 aC2Dx1=aIC.SecondCurve2d();
1387 aFFWD.Orientation(TopAbs_FORWARD);
1390 if (aC2D.IsNull()) {
1391 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aE, aFFWD);
1392 BOPTools_AlgoTools2D::CurveOnSurface(aE, aFFWD, aC2D,
1393 aOutFirst, aOutLast,
1397 if (aC3DE->IsPeriodic()) {
1398 BOPTools_AlgoTools2D::AdjustPCurveOnFace(aFFWD, aT1, aT2, aC2D,
1402 BOPTools_AlgoTools2D::AdjustPCurveOnFace(aFFWD, aC3DETrim, aC2D,
1406 aBB.UpdateEdge(aE, aC2DA, aFFWD, aTolE);
1407 //BRepLib::SameParameter(aE);
1409 BRepLib::SameParameter(aE);
1411 //=======================================================================
1412 // function: MakeEdge
1414 //=======================================================================
1415 void BOPTools_AlgoTools::MakeEdge(const IntTools_Curve& theIC,
1416 const TopoDS_Vertex& theV1,
1417 const Standard_Real theT1,
1418 const TopoDS_Vertex& theV2,
1419 const Standard_Real theT2,
1420 const Standard_Real theTolR3D,
1423 Standard_Real aTolV;
1426 BOPTools_AlgoTools::MakeSectEdge (theIC, theV1, theT1, theV2, theT2,
1429 aBB.UpdateEdge(theE, theTolR3D);
1431 aTolV=BRep_Tool::Tolerance(theV1);
1432 if (aTolV<theTolR3D) {
1433 aBB.UpdateVertex(theV1, theTolR3D);
1436 aTolV=BRep_Tool::Tolerance(theV2);
1437 if (aTolV<theTolR3D) {
1438 aBB.UpdateVertex(theV2, theTolR3D);
1441 //=======================================================================
1442 // function: ComputeVV
1444 //=======================================================================
1445 Standard_Integer BOPTools_AlgoTools::ComputeVV(const TopoDS_Vertex& aV1,
1447 const Standard_Real aTolP2)
1449 Standard_Real aTolV1, aTolSum, aTolSum2, aD2;
1452 aTolV1=BRep_Tool::Tolerance(aV1);
1454 aTolSum = aTolV1 + aTolP2 + Precision::Confusion();
1455 aTolSum2=aTolSum*aTolSum;
1457 aP1=BRep_Tool::Pnt(aV1);
1459 aD2=aP1.SquareDistance(aP2);
1465 //=======================================================================
1466 // function: ComputeVV
1468 //=======================================================================
1469 Standard_Integer BOPTools_AlgoTools::ComputeVV(const TopoDS_Vertex& aV1,
1470 const TopoDS_Vertex& aV2)
1472 Standard_Real aTolV1, aTolV2, aTolSum, aTolSum2, aD2;
1475 aTolV1=BRep_Tool::Tolerance(aV1);
1476 aTolV2=BRep_Tool::Tolerance(aV2);
1477 aTolSum = aTolV1 + aTolV2 + Precision::Confusion();
1478 aTolSum2=aTolSum*aTolSum;
1480 aP1=BRep_Tool::Pnt(aV1);
1481 aP2=BRep_Tool::Pnt(aV2);
1483 aD2=aP1.SquareDistance(aP2);
1489 //=======================================================================
1490 // function: MakeVertex
1492 //=======================================================================
1493 void BOPTools_AlgoTools::MakeVertex(const BOPCol_ListOfShape& aLV,
1494 TopoDS_Vertex& aVnew)
1496 Standard_Integer aNb = aLV.Extent();
1498 aVnew=*((TopoDS_Vertex*)(&aLV.First()));
1501 Standard_Real aNTol;
1503 BRepLib::BoundingVertex(aLV, aNC, aNTol);
1505 aBB.MakeVertex(aVnew, aNC, aNTol);
1508 //=======================================================================
1509 //function : GetEdgeOnFace
1511 //=======================================================================
1512 Standard_Boolean BOPTools_AlgoTools::GetEdgeOnFace
1513 (const TopoDS_Edge& theE1,
1514 const TopoDS_Face& theF2,
1517 Standard_Boolean bFound;
1518 TopoDS_Iterator aItF, aItW;
1520 bFound=Standard_False;
1522 aItF.Initialize(theF2);
1523 for (; aItF.More(); aItF.Next()) {
1524 const TopoDS_Shape& aW=aItF.Value();
1525 aItW.Initialize(aW);
1526 for (; aItW.More(); aItW.Next()) {
1527 const TopoDS_Shape& aE=aItW.Value();
1528 if (aE.IsSame(theE1)) {
1529 theE2=(*(TopoDS_Edge*)(&aE));
1537 //=======================================================================
1538 //function : FindFacePairs
1540 //=======================================================================
1541 Standard_Boolean FindFacePairs (const TopoDS_Edge& theE,
1542 const BOPCol_ListOfShape& thLF,
1543 BOPTools_ListOfCoupleOfShape& theLCFF,
1544 Handle(IntTools_Context)& theContext)
1546 Standard_Boolean bFound;
1547 Standard_Integer i, aNbCEF;
1548 TopAbs_Orientation aOr, aOrC = TopAbs_FORWARD;
1549 BOPCol_MapOfShape aMFP;
1550 TopoDS_Face aF1, aF2;
1551 TopoDS_Edge aEL, aE1;
1552 BOPCol_ListIteratorOfListOfShape aItLF;
1553 BOPTools_CoupleOfShape aCEF, aCFF;
1554 BOPTools_ListOfCoupleOfShape aLCEF, aLCEFx;
1555 BOPTools_ListIteratorOfListOfCoupleOfShape aIt;
1557 bFound=Standard_True;
1560 aItLF.Initialize(thLF);
1561 for (; aItLF.More(); aItLF.Next()) {
1562 const TopoDS_Face& aFL=(*(TopoDS_Face*)(&aItLF.Value()));
1564 bFound=BOPTools_AlgoTools::GetEdgeOnFace(theE, aFL, aEL);
1566 return bFound; // it can not be so
1569 aCEF.SetShape1(aEL);
1570 aCEF.SetShape2(aFL);
1574 aNbCEF=aLCEF.Extent();
1579 aIt.Initialize(aLCEF);
1580 for (i=0; aIt.More(); aIt.Next(), ++i) {
1581 const BOPTools_CoupleOfShape& aCSx=aIt.Value();
1582 const TopoDS_Shape& aEx=aCSx.Shape1();
1583 const TopoDS_Shape& aFx=aCSx.Shape2();
1585 aOr=aEx.Orientation();
1588 aOrC=TopAbs::Reverse(aOr);
1589 aE1=(*(TopoDS_Edge*)(&aEx));
1590 aF1=(*(TopoDS_Face*)(&aFx));
1596 aLCEFx.Append(aCSx);
1602 BOPTools_AlgoTools::GetFaceOff(aE1, aF1, aLCEFx, aF2, theContext);
1604 aCFF.SetShape1(aF1);
1605 aCFF.SetShape2(aF2);
1606 theLCFF.Append(aCFF);
1615 aIt.Initialize(aLCEFx);
1616 for (; aIt.More(); aIt.Next()) {
1617 const BOPTools_CoupleOfShape& aCSx=aIt.Value();
1618 const TopoDS_Shape& aFx=aCSx.Shape2();
1619 if (!aMFP.Contains(aFx)) {
1624 aNbCEF=aLCEF.Extent();
1629 //=======================================================================
1630 //function : AngleWithRef
1632 //=======================================================================
1633 Standard_Real AngleWithRef(const gp_Dir& theD1,
1634 const gp_Dir& theD2,
1635 const gp_Dir& theDRef)
1637 Standard_Real aCosinus, aSinus, aBeta, aHalfPI, aScPr;
1642 const gp_XYZ& aXYZ1=theD1.XYZ();
1643 const gp_XYZ& aXYZ2=theD2.XYZ();
1644 aXYZ=aXYZ1.Crossed(aXYZ2);
1645 aSinus=aXYZ.Modulus();
1646 aCosinus=theD1*theD2;
1650 aBeta=aHalfPI*(1.-aCosinus);
1653 aBeta=2.*M_PI-aHalfPI*(3.+aCosinus);
1656 aScPr=aXYZ.Dot(theDRef.XYZ());
1662 //=======================================================================
1663 // function: IsBlockInOnFace
1665 //=======================================================================
1666 Standard_Boolean BOPTools_AlgoTools::IsBlockInOnFace
1667 (const IntTools_Range& aShrR,
1668 const TopoDS_Face& aF,
1669 const TopoDS_Edge& aE1,
1670 Handle(IntTools_Context)& aContext)
1672 Standard_Boolean bFlag;
1673 Standard_Real f1, l1, ULD, VLD;
1677 aShrR.Range(f1, l1);
1678 Standard_Real dt=0.0075, k;//dt=0.001, k;
1684 BOPTools_AlgoTools::PointOnEdge(aE1, f1, aP11);
1686 GeomAPI_ProjectPointOnSurf& aProjector=aContext->ProjPS(aF);
1687 aProjector.Perform(aP11);
1689 bFlag=aProjector.IsDone();
1694 aProjector.LowerDistanceParameters(ULD, VLD);
1695 aP2D.SetCoord(ULD, VLD);
1697 bFlag=aContext->IsPointInOnFace (aF, aP2D);
1704 BOPTools_AlgoTools::PointOnEdge(aE1, l1, aP12);
1706 aProjector.Perform(aP12);
1708 bFlag=aProjector.IsDone();
1713 aProjector.LowerDistanceParameters(ULD, VLD);
1714 aP2D.SetCoord(ULD, VLD);
1716 bFlag=aContext->IsPointInOnFace (aF, aP2D);
1722 // Treatment intemediate
1723 Standard_Real m1, aTolF, aTolE, aTol, aDist;
1724 m1=IntTools_Tools::IntermediatePoint(f1, l1);
1725 BOPTools_AlgoTools::PointOnEdge(aE1, m1, aP12);
1727 aProjector.Perform(aP12);
1729 bFlag=aProjector.IsDone();
1734 aTolE=BRep_Tool::Tolerance(aE1);
1735 aTolF=BRep_Tool::Tolerance(aF);
1737 aDist=aProjector.LowerDistance();
1739 return Standard_False;
1742 aProjector.LowerDistanceParameters(ULD, VLD);
1743 aP2D.SetCoord(ULD, VLD);
1745 bFlag=aContext->IsPointInOnFace (aF, aP2D);
1753 //=======================================================================
1754 //function : IsMicroEdge
1756 //=======================================================================
1757 Standard_Boolean BOPTools_AlgoTools::IsMicroEdge
1758 (const TopoDS_Edge& aE,
1759 const Handle(IntTools_Context)& aCtx,
1760 const Standard_Boolean bCheckSplittable)
1762 Standard_Boolean bRet;
1763 Standard_Real aT1, aT2, aTmp;
1764 Handle(Geom_Curve) aC3D;
1765 TopoDS_Vertex aV1, aV2;
1767 bRet=(BRep_Tool::Degenerated(aE) ||
1768 !BRep_Tool::IsGeometric(aE));
1773 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
1774 TopExp::Vertices(aE, aV1, aV2);
1775 aT1=BRep_Tool::Parameter(aV1, aE);
1776 aT2=BRep_Tool::Parameter(aV2, aE);
1783 IntTools_ShrunkRange aSR;
1784 aSR.SetContext(aCtx);
1785 aSR.SetData(aE, aT1, aT2, aV1, aV2);
1787 bRet = !aSR.IsDone();
1788 if (!bRet && bCheckSplittable) {
1789 bRet = !aSR.IsSplittable();
1795 //=======================================================================
1796 //function : GetFaceDir
1797 //purpose : Get binormal direction for the face in the point aP
1798 //=======================================================================
1799 void GetFaceDir(const TopoDS_Edge& aE,
1800 const TopoDS_Face& aF,
1802 const Standard_Real aT,
1803 const gp_Dir& aDTgt,
1806 Handle(IntTools_Context)& theContext,
1807 GeomAPI_ProjectPointOnSurf& aProjPL,
1808 const Standard_Real aDt)
1810 Standard_Real aTolE;
1813 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge(aE, aF, aT, aDN);
1814 if (aF.Orientation()==TopAbs_REVERSED){
1818 aTolE=BRep_Tool::Tolerance(aE);
1821 if (!FindPointInFace(aF, aP, aDB, aPx, theContext, aProjPL, aDt, aTolE)) {
1822 BOPTools_AlgoTools3D::GetApproxNormalToFaceOnEdge(aE, aF, aT, aPx,
1824 aProjPL.Perform(aPx);
1825 aPx = aProjPL.NearestPoint();
1826 gp_Vec aVec(aP, aPx);
1827 aDB.SetXYZ(aVec.XYZ());
1830 //=======================================================================
1831 //function : FindPointInFace
1832 //purpose : Find a point in the face in direction of <aDB>
1833 //=======================================================================
1834 Standard_Boolean FindPointInFace(const TopoDS_Face& aF,
1838 Handle(IntTools_Context)& theContext,
1839 GeomAPI_ProjectPointOnSurf& aProjPL,
1840 const Standard_Real aDt,
1841 const Standard_Real aTolE)
1843 Standard_Integer aNbItMax;
1844 Standard_Real aDist, aDTol, aPM, anEps;
1845 Standard_Boolean bRet;
1848 aDTol = Precision::Angular();
1849 aPM = aP.XYZ().Modulus();
1851 aDTol = 5.e-16 * aPM;
1853 bRet = Standard_False;
1855 anEps = Precision::SquareConfusion();
1857 GeomAPI_ProjectPointOnSurf& aProj=theContext->ProjPS(aF);
1861 if (!aProj.IsDone()) {
1864 aPS=aProj.NearestPoint();
1865 aProjPL.Perform(aPS);
1866 aPS=aProjPL.NearestPoint();
1868 aPS.SetXYZ(aPS.XYZ()+2.*aTolE*aDB.XYZ());
1870 if (!aProj.IsDone()) {
1873 aPS=aProj.NearestPoint();
1874 aProjPL.Perform(aPS);
1875 aPS=aProjPL.NearestPoint();
1878 aP1.SetXYZ(aPS.XYZ()+aDt*aDB.XYZ());
1881 if (!aProj.IsDone()) {
1884 aPOut = aProj.NearestPoint();
1885 aDist = aProj.LowerDistance();
1887 aProjPL.Perform(aPOut);
1888 aPOut = aProjPL.NearestPoint();
1890 gp_Vec aV(aPS, aPOut);
1891 if (aV.SquareMagnitude() < anEps) {
1894 aDB.SetXYZ(aV.XYZ());
1895 } while (aDist > aDTol && --aNbItMax);
1897 bRet = aDist < aDTol;
1900 //=======================================================================
1901 //function : MinStep3D
1903 //=======================================================================
1904 Standard_Real MinStep3D(const TopoDS_Edge& theE1,
1905 const TopoDS_Face& theF1,
1906 const BOPTools_ListOfCoupleOfShape& theLCS,
1909 Standard_Real aDt, aTolE, aTolF, aDtMax, aDtMin, aR;
1910 BOPTools_CoupleOfShape aCS1;
1911 BOPTools_ListOfCoupleOfShape aLCS;
1912 BOPTools_ListIteratorOfListOfCoupleOfShape aIt;
1913 BRepAdaptor_Surface aBAS;
1916 aCS1.SetShape1(theE1);
1917 aCS1.SetShape2(theF1);
1920 aTolE = BRep_Tool::Tolerance(theE1);
1924 aIt.Initialize(aLCS);
1925 for (; aIt.More(); aIt.Next()) {
1926 const BOPTools_CoupleOfShape& aCS = aIt.Value();
1927 const TopoDS_Face& aF = (*(TopoDS_Face*)(&aCS.Shape2()));
1929 aTolF = BRep_Tool::Tolerance(aF);
1930 aDt = 2*(aTolE + aTolF);
1933 aBAS.Initialize(aF, Standard_False);
1934 GeomAbs_SurfaceType aSType = aBAS.GetType();
1936 case GeomAbs_Cylinder: {
1937 aR = aBAS.Cylinder().Radius();
1940 case GeomAbs_Cone: {
1941 gp_Lin aL(aBAS.Cone().Axis());
1942 aR = aL.Distance(aP);
1945 case GeomAbs_Sphere: {
1946 aDtMin = Max(aDtMin, 5.e-4);
1947 aR = aBAS.Sphere().Radius();
1950 case GeomAbs_Torus: {
1951 aR = aBAS.Torus().MajorRadius();
1955 aDtMin = Max(aDtMin, 5.e-4);
1960 Standard_Real d = 10*Precision::PConfusion();
1961 aDtMin = Max(aDtMin, sqrt(d*d + 2*d*aR));
1969 if (aDtMax < aDtMin) {
1975 //=======================================================================
1976 //function : IsOpenShell
1978 //=======================================================================
1979 Standard_Boolean BOPTools_AlgoTools::IsOpenShell(const TopoDS_Shell& aSh)
1981 Standard_Boolean bRet;
1982 Standard_Integer i, aNbE, aNbF;
1983 TopAbs_Orientation aOrF;
1984 BOPCol_IndexedDataMapOfShapeListOfShape aMEF;
1985 BOPCol_ListIteratorOfListOfShape aItLS;
1987 bRet=Standard_False;
1989 BOPTools::MapShapesAndAncestors(aSh, TopAbs_EDGE, TopAbs_FACE, aMEF);
1992 for (i=1; i<=aNbE; ++i) {
1993 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aMEF.FindKey(i));
1994 if (BRep_Tool::Degenerated(aE)) {
1999 const BOPCol_ListOfShape& aLF=aMEF(i);
2000 aItLS.Initialize(aLF);
2001 for (; aItLS.More(); aItLS.Next()) {
2002 const TopoDS_Shape& aF=aItLS.Value();
2003 aOrF=aF.Orientation();
2004 if (aOrF==TopAbs_INTERNAL || aOrF==TopAbs_EXTERNAL) {
2018 //=======================================================================
2019 //function : IsInvertedSolid
2021 //=======================================================================
2022 Standard_Boolean BOPTools_AlgoTools::IsInvertedSolid
2023 (const TopoDS_Solid& aSolid)
2025 Standard_Real aTolS;
2026 TopAbs_State aState;
2027 BRepClass3d_SolidClassifier aSC(aSolid);
2030 aSC.PerformInfinitePoint(aTolS);
2032 return (aState==TopAbs_IN);