1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: GEOMAlgo_Tools3D.cxx
24 // Author: Peter KURNEV
26 #include <GEOMAlgo_Tools3D.ixx>
28 #include <Precision.hxx>
33 #include <gp_Pnt2d.hxx>
37 #include <Geom_Curve.hxx>
38 #include <Geom_Surface.hxx>
39 #include <Geom2d_Curve.hxx>
40 #include <GeomAPI_ProjectPointOnSurf.hxx>
42 #include <TopAbs_ShapeEnum.hxx>
43 #include <TopAbs_State.hxx>
45 #include <TopLoc_Location.hxx>
48 #include <TopoDS_Edge.hxx>
49 #include <TopoDS_CompSolid.hxx>
50 #include <TopoDS_Wire.hxx>
51 #include <TopoDS_Compound.hxx>
52 #include <TopoDS_Face.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <TopoDS_Solid.hxx>
55 #include <TopoDS_Shell.hxx>
56 #include <TopoDS_Iterator.hxx>
59 #include <TopExp_Explorer.hxx>
61 #include <BRep_Builder.hxx>
62 #include <BRep_Tool.hxx>
64 #include <TopTools_ListOfShape.hxx>
65 #include <TopTools_IndexedMapOfShape.hxx>
66 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
67 #include <TopTools_IndexedMapOfShape.hxx>
68 #include <TopTools_ListIteratorOfListOfShape.hxx>
69 #include <TopTools_MapOfShape.hxx>
71 #include <BRepClass3d_SolidClassifier.hxx>
73 #include <IntTools_Context.hxx>
74 #include <IntTools_Tools.hxx>
76 #include <BOPTools_Tools3D.hxx>
77 #include <BOPTools_Tools2D.hxx>
78 #include <BOPTools_Tools.hxx>
80 #include <NMTTools_ListOfCoupleOfShape.hxx>
81 #include <NMTTools_ListIteratorOfListOfCoupleOfShape.hxx>
82 #include <NMTTools_CoupleOfShape.hxx>
83 #include <TopTools_DataMapOfShapeListOfShape.hxx>
84 #include <TopTools_DataMapOfShapeListOfShape.hxx>
85 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
86 #include <TopTools_MapOfShape.hxx>
87 #include <TopTools_MapIteratorOfMapOfShape.hxx>
91 Standard_Boolean FindFacePairs (const TopoDS_Edge& ,
92 const TopTools_ListOfShape& ,
93 NMTTools_ListOfCoupleOfShape& );
97 Standard_Real AngleWithRef(const gp_Dir& ,
101 //=======================================================================
102 //function : IsInternalFace
104 //=======================================================================
105 Standard_Boolean GEOMAlgo_Tools3D::IsInternalFace(const TopoDS_Face& theFace,
106 const TopoDS_Solid& theSolid,
107 const TopTools_IndexedDataMapOfShapeListOfShape& theMEF,
108 const Standard_Real theTol,
109 IntTools_Context& theContext)
111 Standard_Boolean bRet;
112 Standard_Integer aNbF;
114 TopExp_Explorer aExp;
115 TopTools_ListIteratorOfListOfShape aItF;
119 // 1 Try to find an edge from theFace in theMEF
120 aExp.Init(theFace, TopAbs_EDGE);
121 for(; aExp.More(); aExp.Next()) {
122 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
123 if (!theMEF.Contains(aE)) {
127 const TopTools_ListOfShape& aLF=theMEF.FindFromKey(aE);
130 return bRet; // it can not be so
133 // aE is internal edge on aLF.First()
134 const TopoDS_Face& aF1=TopoDS::Face(aLF.First());
135 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, aE, aF1, aF1);
139 const TopoDS_Face& aF1=TopoDS::Face(aLF.First());
140 const TopoDS_Face& aF2=TopoDS::Face(aLF.Last());
142 if (aF2.IsSame(aF1) && BRep_Tool::IsClosed(aE, aF1)) {
143 // treat as it was for 1 face
144 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, aE, aF1, aF2);
149 return bRet; // it can not be so
151 else { // aNbF=2,4,6,8,...
152 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, aE, aLF);
155 }//for(; aExp.More(); aExp.Next()) {
157 //========================================
158 // 2. Classify face using classifier
161 TopTools_IndexedMapOfShape aBounds;
163 aState=GEOMAlgo_Tools3D::ComputeState(theFace, theSolid, theTol, aBounds, theContext);
164 bRet=(aState==TopAbs_IN);
168 //=======================================================================
169 //function : IsInternalFace
171 //=======================================================================
172 Standard_Boolean GEOMAlgo_Tools3D::IsInternalFace(const TopoDS_Face& theFace,
173 const TopoDS_Edge& theEdge,
174 const TopTools_ListOfShape& theLF)
176 Standard_Boolean bRet;
177 Standard_Boolean aNbF;
183 const TopoDS_Face& aF1=TopoDS::Face(theLF.First());
184 const TopoDS_Face& aF2=TopoDS::Face(theLF.Last());
185 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, theEdge, aF1, aF2);
190 NMTTools_ListOfCoupleOfShape aLCFF;
191 NMTTools_ListIteratorOfListOfCoupleOfShape aIt;
193 FindFacePairs(theEdge, theLF, aLCFF);
195 aIt.Initialize(aLCFF);
196 for (; aIt.More(); aIt.Next()) {
197 const NMTTools_CoupleOfShape& aCSFF=aIt.Value();
199 const TopoDS_Face& aF1=TopoDS::Face(aCSFF.Shape1());
200 const TopoDS_Face& aF2=TopoDS::Face(aCSFF.Shape2());
201 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, theEdge, aF1, aF2);
209 //=======================================================================
210 //function : IsInternalFace
212 //=======================================================================
213 Standard_Boolean GEOMAlgo_Tools3D::IsInternalFace(const TopoDS_Face& theFace,
214 const TopoDS_Edge& theEdge,
215 const TopoDS_Face& theFace1,
216 const TopoDS_Face& theFace2)
218 Standard_Boolean bRet;
219 Standard_Real aT1, aT2, aT, aDt2D, aDt2Dx;//aD1, aD2,
220 gp_Pnt aPx, aPF, aPF1, aPF2;
221 gp_Pnt2d aP2D, aPF2D;
223 TopoDS_Edge aE1, aE2;
224 Handle(Geom_Curve)aC3D;
226 aC3D =BRep_Tool::Curve(theEdge, aT1, aT2);
227 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
231 aDt2D=BOPTools_Tools3D::MinStepIn2d();
233 BOPTools_Tools3D::PointNearEdge (theEdge, theFace, aT, aDt2Dx, aPF2D, aPF);
236 GEOMAlgo_Tools3D::GetEdgeOnFace(theEdge, theFace1, aE1);
237 if (aE1.Orientation()==TopAbs_INTERNAL) {
239 aE1.Orientation(TopAbs_FORWARD);
240 aE2.Orientation(TopAbs_REVERSED);
242 else if (theFace1==theFace2) {
244 aE1.Orientation(TopAbs_FORWARD);
245 aE2.Orientation(TopAbs_REVERSED);
248 GEOMAlgo_Tools3D::GetEdgeOnFace(theEdge, theFace2, aE2);
254 //modified by NIZNHY-PKV Mon Nov 13 12:12:53 2006f
256 BOPTools_Tools3D::GetApproxNormalToFaceOnEdge (aE1, theFace1, aT, aPF1, aDNF1);
257 BOPTools_Tools3D::GetApproxNormalToFaceOnEdge (aE2, theFace2, aT, aPF2, aDNF2);
260 Standard_Real aA12, aA1x, aTwoPI;
263 gp_Vec aVBF (aPx, aPF );
264 gp_Vec aVBF1(aPx, aPF1);
265 gp_Vec aVBF2(aPx, aPF2);
273 //aA12=aDBF1.AngleWithRef(aDBF2, aDTF1);
274 aA12=AngleWithRef(aDBF1, aDBF2, aDTF1);
278 //aA1x=aDBF1.AngleWithRef(aDBF , aDTF1);
279 aA1x=AngleWithRef(aDBF1, aDBF , aDTF1);
285 bRet=!bRet; //TopAbs_IN;
291 Standard_Real aD1, aD2;
293 //BOPTools_Tools3D::GetApproxNormalToFaceOnEdge (aE1, theFace1, aT, aPF1, aDNF1);
294 gp_Pln aPlnF1(aPx, aDNF1);
296 aD1=BOPTools_Tools3D::SignDistance(aPF, aPlnF1);
298 //BOPTools_Tools3D::GetApproxNormalToFaceOnEdge (aE2, theFace2, aT, aPF2, aDNF2);
299 gp_Pln aPlnF2(aPx, aDNF2);
301 aD2=BOPTools_Tools3D::SignDistance(aPF, aPlnF2);
303 bRet=!bRet; //TopAbs_IN;
308 //modified by NIZNHY-PKV Mon Nov 13 12:12:55 2006t
313 //=======================================================================
314 //function : GetFaceOff
316 //=======================================================================
317 void GEOMAlgo_Tools3D::GetFaceOff(const TopoDS_Edge& theE1,
318 const TopoDS_Face& theF1,
319 const NMTTools_ListOfCoupleOfShape& theLCSOff,
320 TopoDS_Face& theFOff)
322 Standard_Real aT, aT1, aT2, aAngle, aTwoPI, aAngleMin;
326 NMTTools_ListIteratorOfListOfCoupleOfShape aIt;
330 BRep_Tool::Range(theE1, aT1, aT2);
331 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
333 BOPTools_Tools2D::EdgeTangent(theE1, aT, aVTgt);
334 gp_Dir aDTtgt(aVTgt);
337 BOPTools_Tools3D::GetApproxNormalToFaceOnEdge(theE1, theF1, aT, aPn1, aDN1);
339 aIt.Initialize(theLCSOff);
340 for (; aIt.More(); aIt.Next()) {
341 const NMTTools_CoupleOfShape& aCS=aIt.Value();
342 const TopoDS_Edge& aE2=TopoDS::Edge(aCS.Shape1());
343 const TopoDS_Face& aF2=TopoDS::Face(aCS.Shape2());
348 else if (aF2.IsSame(theF1)) {
352 BOPTools_Tools3D::GetApproxNormalToFaceOnEdge (aE2, aF2, aT, aPn2, aDN2);
356 //aAngle=aDN1.AngleWithRef(aDN2, aDTtgt);
357 aAngle=AngleWithRef(aDN1, aDN2, aDTtgt);
360 aAngle=aTwoPI+aAngle;
364 if (aAngle<aAngleMin){
370 //=======================================================================
371 //function : GetEdgeOnFace
373 //=======================================================================
374 Standard_Boolean GEOMAlgo_Tools3D::GetEdgeOnFace(const TopoDS_Edge& theE1,
375 const TopoDS_Face& theF2,
378 Standard_Boolean bFound;
379 TopoDS_Iterator aItF, aItW;
381 bFound=Standard_False;
383 aItF.Initialize(theF2);
384 for (; aItF.More(); aItF.Next()) {
385 const TopoDS_Shape& aW=aItF.Value();
387 for (; aItW.More(); aItW.Next()) {
388 const TopoDS_Shape& aE=aItW.Value();
389 if (aE.IsSame(theE1)) {
390 theE2=TopoDS::Edge(aE);
398 //=======================================================================
399 //function : GetEdgeOff
401 //=======================================================================
402 Standard_Boolean GEOMAlgo_Tools3D::GetEdgeOff(const TopoDS_Edge& theE1,
403 const TopoDS_Face& theF2,
407 Standard_Boolean bFound;
408 TopAbs_Orientation aOr1, aOr1C, aOr2;
409 TopExp_Explorer anExp;
411 bFound=Standard_False;
412 aOr1=theE1.Orientation();
413 aOr1C=TopAbs::Reverse(aOr1);
415 anExp.Init(theF2, TopAbs_EDGE);
416 for (; anExp.More(); anExp.Next()) {
417 const TopoDS_Edge& aEF2=TopoDS::Edge(anExp.Current());
418 if (aEF2.IsSame(theE1)) {
419 aOr2=aEF2.Orientation();
429 //=======================================================================
430 // function: ComputeState
432 //=======================================================================
433 TopAbs_State GEOMAlgo_Tools3D::ComputeState(const TopoDS_Face& theF,
434 const TopoDS_Solid& theRef,
435 const Standard_Real theTol,
436 const TopTools_IndexedMapOfShape& theBounds,
437 IntTools_Context& theCtx)
440 TopExp_Explorer aExp;
445 aState=TopAbs_UNKNOWN;
447 aExp.Init(theF, TopAbs_EDGE);
448 for (; aExp.More(); aExp.Next()) {
449 const TopoDS_Edge& aSE=TopoDS::Edge(aExp.Current());
450 if (BRep_Tool::Degenerated(aSE)) {
454 if (!theBounds.Contains(aSE)) {
455 const TopoDS_Edge& aE=TopoDS::Edge(aSE);
456 aState= GEOMAlgo_Tools3D::ComputeState(aE, theRef, theTol, theCtx);
460 aE1=TopoDS::Edge(aSE);
463 // !!<- process edges that are all on theRef
465 BOPTools_Tools3D::PointNearEdge(aE1, theF, aP2D, aP3D);
466 aState=GEOMAlgo_Tools3D::ComputeState(aP3D, theRef, theTol, theCtx);
471 //=======================================================================
472 // function: ComputeStateByOnePoint
474 //=======================================================================
475 TopAbs_State GEOMAlgo_Tools3D::ComputeStateByOnePoint(const TopoDS_Shape& theS,
476 const TopoDS_Solid& theRef,
477 const Standard_Real theTol,
478 IntTools_Context& theCtx)
481 TopAbs_ShapeEnum aType;
483 aState=TopAbs_UNKNOWN;
484 aType=theS.ShapeType();
485 if (aType==TopAbs_VERTEX) {
486 const TopoDS_Vertex& aV=TopoDS::Vertex(theS);
487 aState=GEOMAlgo_Tools3D::ComputeState(aV, theRef, theTol, theCtx);
489 else if (aType==TopAbs_EDGE) {
490 const TopoDS_Edge& aE=TopoDS::Edge(theS);
491 aState=GEOMAlgo_Tools3D::ComputeState(aE, theRef, theTol, theCtx);
495 //=======================================================================
496 // function: ComputeState
498 //=======================================================================
499 TopAbs_State GEOMAlgo_Tools3D::ComputeState(const TopoDS_Vertex& theV,
500 const TopoDS_Solid& theRef,
501 const Standard_Real theTol,
502 IntTools_Context& theCtx)
507 aP3D=BRep_Tool::Pnt(theV);
508 aState=GEOMAlgo_Tools3D::ComputeState(aP3D, theRef, theTol, theCtx);
511 //=======================================================================
512 // function: ComputeState
514 //=======================================================================
515 TopAbs_State GEOMAlgo_Tools3D::ComputeState(const TopoDS_Edge& theE,
516 const TopoDS_Solid& theRef,
517 const Standard_Real theTol,
518 IntTools_Context& theCtx)
520 Standard_Real aT1, aT2, aT = 0.;
522 Handle(Geom_Curve) aC3D;
525 aC3D = BRep_Tool::Curve(theE, aT1, aT2);
528 //it means that we are in degenerated edge
529 const TopoDS_Vertex& aV = TopExp::FirstVertex(theE);
531 return TopAbs_UNKNOWN;
533 aP3D=BRep_Tool::Pnt(aV);
536 Standard_Boolean bF2Inf, bL2Inf;
537 Standard_Real dT=10.;
539 bF2Inf = Precision::IsNegativeInfinite(aT1);
540 bL2Inf = Precision::IsPositiveInfinite(aT2);
542 if (bF2Inf && !bL2Inf) {
545 else if (!bF2Inf && bL2Inf) {
548 else if (bF2Inf && bL2Inf) {
552 aT=IntTools_Tools::IntermediatePoint(aT1, aT2);
557 aState=GEOMAlgo_Tools3D::ComputeState(aP3D, theRef, theTol, theCtx);
561 //=======================================================================
562 // function: ComputeState
564 //=======================================================================
565 TopAbs_State GEOMAlgo_Tools3D::ComputeState(const gp_Pnt& theP,
566 const TopoDS_Solid& theRef,
567 const Standard_Real theTol,
568 IntTools_Context& theCtx)
572 BRepClass3d_SolidClassifier& aSC=theCtx.SolidClassifier(theRef);
573 aSC.Perform(theP, theTol);
579 //=======================================================================
580 // function: IsSplitToReverse
582 //=======================================================================
583 Standard_Boolean GEOMAlgo_Tools3D::IsSplitToReverse(const TopoDS_Shape& theSp,
584 const TopoDS_Shape& theSr,
585 IntTools_Context& theCtx)
587 Standard_Boolean bRet;
588 TopAbs_ShapeEnum aType;
592 aType=theSp.ShapeType();
595 const TopoDS_Edge& aESp=TopoDS::Edge(theSp);
596 const TopoDS_Edge& aESr=TopoDS::Edge(theSr);
597 bRet=GEOMAlgo_Tools3D::IsSplitToReverse(aESp, aESr, theCtx);
602 const TopoDS_Face& aFSp=TopoDS::Face(theSp);
603 const TopoDS_Face& aFSr=TopoDS::Face(theSr);
604 bRet=GEOMAlgo_Tools3D::IsSplitToReverse(aFSp, aFSr, theCtx);
613 //=======================================================================
614 //function :IsSplitToReverse
616 //=======================================================================
617 Standard_Boolean GEOMAlgo_Tools3D::IsSplitToReverse(const TopoDS_Face& theFSp,
618 const TopoDS_Face& theFSr,
619 IntTools_Context& theContext)
621 Standard_Boolean bRet, bFound, bInFace;
622 Standard_Real aT1, aT2, aT, aU, aV, aScPr;
626 Handle(Geom_Surface) aSr, aSp;
627 TopAbs_Orientation aOrSr, aOrSp;
628 TopExp_Explorer anExp;
633 aSr=BRep_Tool::Surface(theFSr);
634 aSp=BRep_Tool::Surface(theFSp);
636 aOrSr=theFSr.Orientation();
637 aOrSp=theFSp.Orientation();
642 bFound=Standard_False;
643 anExp.Init(theFSp, TopAbs_EDGE);
644 for (; anExp.More(); anExp.Next()) {
645 aESp=TopoDS::Edge(anExp.Current());
646 if (!BRep_Tool::Degenerated(aESp)) {
647 if (!BRep_Tool::IsClosed(aESp, theFSp)) {
657 BRep_Tool::Range(aESp, aT1, aT2);
658 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
659 BOPTools_Tools3D::GetApproxNormalToFaceOnEdge(aESp, theFSp, aT, aPFSp, aDNFSp);
661 // Parts of theContext.ComputeVS(..)
662 GeomAPI_ProjectPointOnSurf& aProjector=theContext.ProjPS(theFSr);
663 aProjector.Perform(aPFSp);
664 if (!aProjector.IsDone()) {
668 aProjector.LowerDistanceParameters(aU, aV);
669 gp_Pnt2d aP2D(aU, aV);
670 bInFace=theContext.IsPointInFace (theFSr, aP2D);
675 aSr->D1(aU, aV, aPFSr, aD1U, aD1V);
678 gp_Dir aDNFSr=aDD1U^aDD1V;
679 if (theFSr.Orientation()==TopAbs_REVERSED){
688 //=======================================================================
689 //function :IsSplitToReverse
691 //=======================================================================
692 Standard_Boolean GEOMAlgo_Tools3D::IsSplitToReverse(const TopoDS_Edge& theSplit,
693 const TopoDS_Edge& theEdge,
694 IntTools_Context& theContext)
696 Standard_Boolean bRet, aFlag, bIsDegenerated;
697 Standard_Real aTE, aTS, aScPr, aTa, aTb, aT1, aT2;
698 TopAbs_Orientation aOrSr, aOrSp;
699 Handle(Geom_Curve) aCEdge, aCSplit;
705 bIsDegenerated=(BRep_Tool::Degenerated(theSplit) ||
706 BRep_Tool::Degenerated(theEdge));
707 if (bIsDegenerated) {
711 aCEdge =BRep_Tool::Curve(theEdge , aT1, aT2);
712 aCSplit=BRep_Tool::Curve(theSplit, aTa, aTb);
714 if (aCEdge==aCSplit) {
715 aOrSr=theEdge.Orientation();
716 aOrSp=theSplit.Orientation();
721 aTS=BOPTools_Tools2D::IntermediatePoint(aTa, aTb);
722 aCSplit->D0(aTS, aP);
723 aFlag=BOPTools_Tools2D::EdgeTangent(theSplit, aTS, aVS);
726 aFlag=theContext.ProjectPointOnEdge(aP, theEdge, aTE);
727 aFlag=BOPTools_Tools2D::EdgeTangent(theEdge, aTE, aVE);
736 //=======================================================================
739 //=======================================================================
740 Standard_Integer GEOMAlgo_Tools3D::Sense (const TopoDS_Face& theF1,
741 const TopoDS_Face& theF2)
743 Standard_Integer iSense=0;
745 TopoDS_Edge aE1, aE2;
746 TopExp_Explorer anExp;
748 anExp.Init(theF1, TopAbs_EDGE);
749 for (; anExp.More(); anExp.Next()) {
750 aE1=TopoDS::Edge(anExp.Current());
751 if (!BRep_Tool::Degenerated(aE1)) {
752 if (!BRep_Tool::IsClosed(aE1, theF1)) {
758 anExp.Init(theF2, TopAbs_EDGE);
759 for (; anExp.More(); anExp.Next()) {
760 aE2=TopoDS::Edge(anExp.Current());
761 if (!BRep_Tool::Degenerated(aE2)) {
762 if (!BRep_Tool::IsClosed(aE2, theF2)) {
763 if (aE2.IsSame(aE1)) {
775 BOPTools_Tools3D::GetNormalToFaceOnEdge(aE1, theF1, aDNF1);
776 BOPTools_Tools3D::GetNormalToFaceOnEdge(aE2, theF2, aDNF2);
778 iSense=BOPTools_Tools3D::SenseFlag(aDNF1, aDNF2);
782 //=======================================================================
783 // function: CopyFace
785 //=======================================================================
786 void GEOMAlgo_Tools3D::CopyFace (const TopoDS_Face& theF1,
790 TopLoc_Location aLoc;
791 TopAbs_Orientation aOr;
795 Handle(Geom_Surface) aSurface=BRep_Tool::Surface(theF1, aLoc);
796 aTol=BRep_Tool::Tolerance(theF1);
797 aOr=theF1.Orientation();
799 aBB.MakeFace (theF2, aSurface, aLoc, aTol);
800 theF2.Orientation(aOr);
802 aIt.Initialize(theF1);
803 for (; aIt.More(); aIt.Next()) {
804 const TopoDS_Shape& aW=aIt.Value();
808 //=======================================================================
809 // function: MakeContainer
811 //=======================================================================
812 void GEOMAlgo_Tools3D::MakeContainer(const TopAbs_ShapeEnum theType,
818 case TopAbs_COMPOUND:{
820 aBB.MakeCompound(aC);
825 case TopAbs_COMPSOLID:{
826 TopoDS_CompSolid aCS;
827 aBB.MakeCompSolid(aCS);
834 aBB.MakeSolid(aSolid);
842 aBB.MakeShell(aShell);
858 //=======================================================================
859 // function: MakeConnexityBlock.
861 //=======================================================================
862 void GEOMAlgo_Tools3D::MakeConnexityBlock (const TopTools_ListOfShape& theLFIn,
863 const TopTools_IndexedMapOfShape& theMEAvoid,
864 TopTools_ListOfShape& theLCB)
866 Standard_Integer aNbF, aNbAdd1;
867 TopExp_Explorer aExp;
868 TopTools_IndexedDataMapOfShapeListOfShape aMEF;
869 TopTools_MapIteratorOfMapOfShape aItM, aItM1;
870 TopTools_MapOfShape aMCB, aMAdd, aMAdd1;
871 TopTools_ListIteratorOfListOfShape aIt;
874 aNbF=theLFIn.Extent();
875 aIt.Initialize(theLFIn);
876 for (; aIt.More(); aIt.Next()) {
877 const TopoDS_Shape& aF=aIt.Value();
878 TopExp::MapShapesAndAncestors(aF, TopAbs_EDGE, TopAbs_FACE, aMEF);
882 const TopoDS_Shape& aF1=theLFIn.First();
887 aItM.Initialize(aMAdd);
888 for (; aItM.More(); aItM.Next()) {
889 const TopoDS_Shape& aF=aItM.Key();
892 aExp.Init(aF, TopAbs_EDGE);
893 for (; aExp.More(); aExp.Next()) {
894 const TopoDS_Shape& aE=aExp.Current();
895 if (theMEAvoid.Contains(aE)){
899 const TopTools_ListOfShape& aLF=aMEF.FindFromKey(aE);
901 for (; aIt.More(); aIt.Next()) {
902 const TopoDS_Shape& aFx=aIt.Value();
903 if (aFx.IsSame(aF)) {
906 if (aMCB.Contains(aFx)) {
911 }//for (; aExp.More(); aExp.Next()){
913 }// for (; aItM.More(); aItM.Next()) {
915 aNbAdd1=aMAdd1.Extent();
921 aItM1.Initialize(aMAdd1);
922 for (; aItM1.More(); aItM1.Next()) {
923 const TopoDS_Shape& aFAdd=aItM1.Key();
931 aItM.Initialize(aMCB);
932 for (; aItM.More(); aItM.Next()) {
933 const TopoDS_Shape& aF=aItM.Key();
938 //=======================================================================
939 //function : FindFacePairs
941 //=======================================================================
942 Standard_Boolean FindFacePairs (const TopoDS_Edge& theE,
943 const TopTools_ListOfShape& thLF,
944 NMTTools_ListOfCoupleOfShape& theLCFF)
946 Standard_Boolean bFound;
947 Standard_Integer i, aNbCEF;
948 TopAbs_Orientation aOr, aOrC;
949 TopTools_MapOfShape aMFP;
950 TopoDS_Face aF1, aF2;
951 TopoDS_Edge aEL, aE1;
952 TopTools_ListIteratorOfListOfShape aItLF;
953 NMTTools_CoupleOfShape aCEF, aCFF;
954 NMTTools_ListOfCoupleOfShape aLCEF, aLCEFx;
955 NMTTools_ListIteratorOfListOfCoupleOfShape aIt;
957 bFound=Standard_True;
960 aItLF.Initialize(thLF);
961 for (; aItLF.More(); aItLF.Next()) {
962 const TopoDS_Face& aFL=TopoDS::Face(aItLF.Value());
964 bFound=GEOMAlgo_Tools3D::GetEdgeOnFace(theE, aFL, aEL);
966 return bFound; // it can not be so
974 aNbCEF=aLCEF.Extent();
979 aIt.Initialize(aLCEF);
980 for (i=0; aIt.More(); aIt.Next(), ++i) {
981 const NMTTools_CoupleOfShape& aCSx=aIt.Value();
982 const TopoDS_Shape& aEx=aCSx.Shape1();
983 const TopoDS_Shape& aFx=aCSx.Shape2();
985 aOr=aEx.Orientation();
988 aOrC=TopAbs::Reverse(aOr);
989 aE1=TopoDS::Edge(aEx);
990 aF1=TopoDS::Face(aFx);
1002 GEOMAlgo_Tools3D::GetFaceOff(aE1, aF1, aLCEFx, aF2);
1004 aCFF.SetShape1(aF1);
1005 aCFF.SetShape2(aF2);
1006 theLCFF.Append(aCFF);
1015 aIt.Initialize(aLCEFx);
1016 for (; aIt.More(); aIt.Next()) {
1017 const NMTTools_CoupleOfShape& aCSx=aIt.Value();
1018 const TopoDS_Shape& aFx=aCSx.Shape2();
1019 if (!aMFP.Contains(aFx)) {
1024 aNbCEF=aLCEF.Extent();
1030 //=======================================================================
1031 //function : AngleWithRef
1033 //=======================================================================
1034 Standard_Real AngleWithRef(const gp_Dir& theD1,
1035 const gp_Dir& theD2,
1036 const gp_Dir& theDRef)
1038 Standard_Real aCosinus, aSinus, aBeta, aHalfPI, aScPr;
1043 const gp_XYZ& aXYZ1=theD1.XYZ();
1044 const gp_XYZ& aXYZ2=theD2.XYZ();
1045 aXYZ=aXYZ1.Crossed(aXYZ2);
1046 aSinus=aXYZ.Modulus();
1047 aCosinus=theD1*theD2;
1051 aBeta=aHalfPI*(1.-aCosinus);
1054 aBeta=2.*PI-aHalfPI*(3.+aCosinus);
1057 aScPr=aXYZ.Dot(theDRef.XYZ());
1066 void Path(const TopoDS_Shape& ,
1067 const TopoDS_Shape& ,
1068 const TopTools_IndexedDataMapOfShapeListOfShape& ,
1069 const TopTools_IndexedMapOfShape& ,
1070 TopTools_IndexedMapOfShape& );
1072 //=======================================================================
1073 // function: MakeConnexityBlock.
1075 //=======================================================================
1076 void GEOMAlgo_Tools3D::MakeConnexityBlock (const TopTools_ListOfShape& theLFIn,
1077 const TopTools_IndexedMapOfShape& theMEAvoid,
1078 TopTools_ListOfShape& theLCB)
1080 Standard_Integer j, aNbF;
1081 TopTools_IndexedDataMapOfShapeListOfShape aEFMap;
1082 TopTools_IndexedMapOfShape aMFP, aCBMap;
1083 TopTools_ListIteratorOfListOfShape aIt;
1084 TopExp_Explorer aExp;
1085 TopAbs_ShapeEnum aType;
1087 aIt.Initialize(theLFIn);
1088 for (; aIt.More(); aIt.Next()) {
1089 const TopoDS_Shape& aF=aIt.Value();
1090 aType=aF.ShapeType();
1091 TopExp::MapShapesAndAncestors(aF, TopAbs_EDGE, TopAbs_FACE, aEFMap);
1095 const TopoDS_Shape& aF=theLFIn.First();
1099 aExp.Init(aF, TopAbs_EDGE);
1100 for (; aExp.More(); aExp.Next()){
1101 const TopoDS_Shape& aE=aExp.Current();
1102 if (theMEAvoid.Contains(aE)){
1106 const TopTools_ListOfShape& aLF=aEFMap.FindFromKey(aE);
1107 aIt.Initialize(aLF);
1108 for (; aIt.More(); aIt.Next()) {
1109 const TopoDS_Shape& aF1=aIt.Value();
1110 if (!aF1.IsSame(aF)) {
1111 Path (aE, aF1, aEFMap, theMEAvoid, aCBMap);
1116 aNbF=aCBMap.Extent();
1117 for (j=1; j<=aNbF; ++j) {
1118 const TopoDS_Shape& aFx=aCBMap(j);
1122 //=======================================================================
1125 //=======================================================================
1126 void Path(const TopoDS_Shape& theE1,
1127 const TopoDS_Shape& theF1,
1128 const TopTools_IndexedDataMapOfShapeListOfShape& theEFMap,
1129 const TopTools_IndexedMapOfShape& theMEAvoid,
1130 TopTools_IndexedMapOfShape& theCBMap)
1132 TopTools_ListIteratorOfListOfShape aIt;
1133 TopExp_Explorer aExp;
1135 if (theCBMap.Contains(theF1)){
1138 theCBMap.Add(theF1);
1140 aExp.Init(theF1, TopAbs_EDGE);
1141 for (; aExp.More(); aExp.Next()){
1142 const TopoDS_Shape& aE=aExp.Current();
1143 if (!aE.IsSame(theE1)){
1144 if (theMEAvoid.Contains(aE)) {
1148 const TopTools_ListOfShape& aLF=theEFMap.FindFromKey(aE);
1149 aIt.Initialize(aLF);
1150 for (; aIt.More(); aIt.Next()) {
1151 const TopoDS_Shape& aF=aIt.Value();
1152 Path (aE, aF, theEFMap, theMEAvoid, theCBMap);