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 //modified by NIZNHY-PKV Tue Jul 14 07:24:10 2009f
103 void GetApproxNormalToFaceOnEdge (const TopoDS_Edge& aE,
104 const TopoDS_Face& aF,
108 IntTools_Context& aCtx);
109 //modified by NIZNHY-PKV Tue Jul 14 07:24:15 2009t
111 //=======================================================================
112 //function : IsInternalFace
114 //=======================================================================
115 Standard_Boolean GEOMAlgo_Tools3D::IsInternalFace(const TopoDS_Face& theFace,
116 const TopoDS_Solid& theSolid,
117 const TopTools_IndexedDataMapOfShapeListOfShape& theMEF,
118 const Standard_Real theTol,
119 IntTools_Context& theContext)
121 Standard_Boolean bRet;
122 Standard_Integer aNbF;
124 TopExp_Explorer aExp;
125 TopTools_ListIteratorOfListOfShape aItF;
129 // 1 Try to find an edge from theFace in theMEF
130 aExp.Init(theFace, TopAbs_EDGE);
131 for(; aExp.More(); aExp.Next()) {
132 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
133 if (!theMEF.Contains(aE)) {
137 const TopTools_ListOfShape& aLF=theMEF.FindFromKey(aE);
140 return bRet; // it can not be so
143 // aE is internal edge on aLF.First()
144 const TopoDS_Face& aF1=TopoDS::Face(aLF.First());
145 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, aE, aF1, aF1, theContext);
149 const TopoDS_Face& aF1=TopoDS::Face(aLF.First());
150 const TopoDS_Face& aF2=TopoDS::Face(aLF.Last());
152 if (aF2.IsSame(aF1) && BRep_Tool::IsClosed(aE, aF1)) {
153 // treat as it was for 1 face
154 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, aE, aF1, aF2, theContext);
159 return bRet; // it can not be so
161 else { // aNbF=2,4,6,8,...
162 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, aE, aLF, theContext);
165 }//for(; aExp.More(); aExp.Next()) {
167 //========================================
168 // 2. Classify face using classifier
171 TopTools_IndexedMapOfShape aBounds;
173 aState=GEOMAlgo_Tools3D::ComputeState(theFace, theSolid, theTol, aBounds, theContext);
174 bRet=(aState==TopAbs_IN);
178 //=======================================================================
179 //function : IsInternalFace
181 //=======================================================================
182 Standard_Boolean GEOMAlgo_Tools3D::IsInternalFace(const TopoDS_Face& theFace,
183 const TopoDS_Edge& theEdge,
184 const TopTools_ListOfShape& theLF,
185 IntTools_Context& theContext)
187 Standard_Boolean bRet;
188 Standard_Boolean aNbF;
194 const TopoDS_Face& aF1=TopoDS::Face(theLF.First());
195 const TopoDS_Face& aF2=TopoDS::Face(theLF.Last());
196 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, theEdge, aF1, aF2, theContext);
201 NMTTools_ListOfCoupleOfShape aLCFF;
202 NMTTools_ListIteratorOfListOfCoupleOfShape aIt;
204 FindFacePairs(theEdge, theLF, aLCFF);
206 aIt.Initialize(aLCFF);
207 for (; aIt.More(); aIt.Next()) {
208 const NMTTools_CoupleOfShape& aCSFF=aIt.Value();
210 const TopoDS_Face& aF1=TopoDS::Face(aCSFF.Shape1());
211 const TopoDS_Face& aF2=TopoDS::Face(aCSFF.Shape2());
212 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, theEdge, aF1, aF2, theContext);
220 //=======================================================================
221 //function : IsInternalFace
223 //=======================================================================
224 Standard_Boolean GEOMAlgo_Tools3D::IsInternalFace(const TopoDS_Face& theFace,
225 const TopoDS_Edge& theEdge,
226 const TopoDS_Face& theFace1,
227 const TopoDS_Face& theFace2,
228 IntTools_Context& theContext)
230 Standard_Boolean bRet;
231 Standard_Real aT1, aT2, aT, aDt2D, aDt2Dx;
232 Standard_Real aA12, aA1x, aTwoPI;
233 gp_Pnt aPx, aPF, aPF1, aPF2;
234 gp_Pnt2d aP2D, aPF2D;
236 TopoDS_Edge aE1, aE2;
237 Handle(Geom_Curve)aC3D;
239 aC3D =BRep_Tool::Curve(theEdge, aT1, aT2);
240 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
244 aDt2D=BOPTools_Tools3D::MinStepIn2d();
246 BOPTools_Tools3D::PointNearEdge (theEdge, theFace, aT, aDt2Dx, aPF2D, aPF);
249 GEOMAlgo_Tools3D::GetEdgeOnFace(theEdge, theFace1, aE1);
250 if (aE1.Orientation()==TopAbs_INTERNAL) {
252 aE1.Orientation(TopAbs_FORWARD);
253 aE2.Orientation(TopAbs_REVERSED);
255 else if (theFace1==theFace2) {
257 aE1.Orientation(TopAbs_FORWARD);
258 aE2.Orientation(TopAbs_REVERSED);
261 GEOMAlgo_Tools3D::GetEdgeOnFace(theEdge, theFace2, aE2);
267 //modified by NIZNHY-PKV Tue Jul 14 07:22:38 2009f
268 GetApproxNormalToFaceOnEdge (aE1, theFace1, aT, aPF1, aDNF1, theContext);
269 GetApproxNormalToFaceOnEdge (aE2, theFace2, aT, aPF2, aDNF2, theContext);
271 //BOPTools_Tools3D::GetApproxNormalToFaceOnEdge (aE1, theFace1, aT, aPF1, aDNF1);
272 //BOPTools_Tools3D::GetApproxNormalToFaceOnEdge (aE2, theFace2, aT, aPF2, aDNF2);
273 //modified by NIZNHY-PKV Tue Jul 14 07:22:42 2009t
276 gp_Vec aVBF (aPx, aPF );
277 gp_Vec aVBF1(aPx, aPF1);
278 gp_Vec aVBF2(aPx, aPF2);
286 aA12=AngleWithRef(aDBF1, aDBF2, aDTF1);
291 aA1x=AngleWithRef(aDBF1, aDBF , aDTF1);
297 bRet=!bRet; //TopAbs_IN;
302 //=======================================================================
303 //function : GetFaceOff
305 //=======================================================================
306 void GEOMAlgo_Tools3D::GetFaceOff(const TopoDS_Edge& theE1,
307 const TopoDS_Face& theF1,
308 const NMTTools_ListOfCoupleOfShape& theLCSOff,
309 TopoDS_Face& theFOff)
311 Standard_Real aT, aT1, aT2, aAngle, aTwoPI, aAngleMin;
315 NMTTools_ListIteratorOfListOfCoupleOfShape aIt;
319 BRep_Tool::Range(theE1, aT1, aT2);
320 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
322 BOPTools_Tools2D::EdgeTangent(theE1, aT, aVTgt);
323 gp_Dir aDTtgt(aVTgt);
326 BOPTools_Tools3D::GetApproxNormalToFaceOnEdge(theE1, theF1, aT, aPn1, aDN1);
328 aIt.Initialize(theLCSOff);
329 for (; aIt.More(); aIt.Next()) {
330 const NMTTools_CoupleOfShape& aCS=aIt.Value();
331 const TopoDS_Edge& aE2=TopoDS::Edge(aCS.Shape1());
332 const TopoDS_Face& aF2=TopoDS::Face(aCS.Shape2());
337 else if (aF2.IsSame(theF1)) {
341 BOPTools_Tools3D::GetApproxNormalToFaceOnEdge (aE2, aF2, aT, aPn2, aDN2);
344 aAngle=AngleWithRef(aDN1, aDN2, aDTtgt);
346 aAngle=aTwoPI+aAngle;
350 if (aAngle<aAngleMin){
356 //=======================================================================
357 //function : GetEdgeOnFace
359 //=======================================================================
360 Standard_Boolean GEOMAlgo_Tools3D::GetEdgeOnFace(const TopoDS_Edge& theE1,
361 const TopoDS_Face& theF2,
364 Standard_Boolean bFound;
365 TopoDS_Iterator aItF, aItW;
367 bFound=Standard_False;
369 aItF.Initialize(theF2);
370 for (; aItF.More(); aItF.Next()) {
371 const TopoDS_Shape& aW=aItF.Value();
373 for (; aItW.More(); aItW.Next()) {
374 const TopoDS_Shape& aE=aItW.Value();
375 if (aE.IsSame(theE1)) {
376 theE2=TopoDS::Edge(aE);
384 //=======================================================================
385 //function : GetEdgeOff
387 //=======================================================================
388 Standard_Boolean GEOMAlgo_Tools3D::GetEdgeOff(const TopoDS_Edge& theE1,
389 const TopoDS_Face& theF2,
393 Standard_Boolean bFound;
394 TopAbs_Orientation aOr1, aOr1C, aOr2;
395 TopExp_Explorer anExp;
397 bFound=Standard_False;
398 aOr1=theE1.Orientation();
399 aOr1C=TopAbs::Reverse(aOr1);
401 anExp.Init(theF2, TopAbs_EDGE);
402 for (; anExp.More(); anExp.Next()) {
403 const TopoDS_Edge& aEF2=TopoDS::Edge(anExp.Current());
404 if (aEF2.IsSame(theE1)) {
405 aOr2=aEF2.Orientation();
415 //=======================================================================
416 // function: ComputeState
418 //=======================================================================
419 TopAbs_State GEOMAlgo_Tools3D::ComputeState(const TopoDS_Face& theF,
420 const TopoDS_Solid& theRef,
421 const Standard_Real theTol,
422 const TopTools_IndexedMapOfShape& theBounds,
423 IntTools_Context& theCtx)
426 TopExp_Explorer aExp;
431 aState=TopAbs_UNKNOWN;
433 aExp.Init(theF, TopAbs_EDGE);
434 for (; aExp.More(); aExp.Next()) {
435 const TopoDS_Edge& aSE=TopoDS::Edge(aExp.Current());
436 if (BRep_Tool::Degenerated(aSE)) {
440 if (!theBounds.Contains(aSE)) {
441 const TopoDS_Edge& aE=TopoDS::Edge(aSE);
442 aState= GEOMAlgo_Tools3D::ComputeState(aE, theRef, theTol, theCtx);
446 aE1=TopoDS::Edge(aSE);
449 // !!<- process edges that are all on theRef
451 BOPTools_Tools3D::PointNearEdge(aE1, theF, aP2D, aP3D);
452 aState=GEOMAlgo_Tools3D::ComputeState(aP3D, theRef, theTol, theCtx);
457 //=======================================================================
458 // function: ComputeStateByOnePoint
460 //=======================================================================
461 TopAbs_State GEOMAlgo_Tools3D::ComputeStateByOnePoint(const TopoDS_Shape& theS,
462 const TopoDS_Solid& theRef,
463 const Standard_Real theTol,
464 IntTools_Context& theCtx)
467 TopAbs_ShapeEnum aType;
469 aState=TopAbs_UNKNOWN;
470 aType=theS.ShapeType();
471 if (aType==TopAbs_VERTEX) {
472 const TopoDS_Vertex& aV=TopoDS::Vertex(theS);
473 aState=GEOMAlgo_Tools3D::ComputeState(aV, theRef, theTol, theCtx);
475 else if (aType==TopAbs_EDGE) {
476 const TopoDS_Edge& aE=TopoDS::Edge(theS);
477 aState=GEOMAlgo_Tools3D::ComputeState(aE, theRef, theTol, theCtx);
481 //=======================================================================
482 // function: ComputeState
484 //=======================================================================
485 TopAbs_State GEOMAlgo_Tools3D::ComputeState(const TopoDS_Vertex& theV,
486 const TopoDS_Solid& theRef,
487 const Standard_Real theTol,
488 IntTools_Context& theCtx)
493 aP3D=BRep_Tool::Pnt(theV);
494 aState=GEOMAlgo_Tools3D::ComputeState(aP3D, theRef, theTol, theCtx);
497 //=======================================================================
498 // function: ComputeState
500 //=======================================================================
501 TopAbs_State GEOMAlgo_Tools3D::ComputeState(const TopoDS_Edge& theE,
502 const TopoDS_Solid& theRef,
503 const Standard_Real theTol,
504 IntTools_Context& theCtx)
506 Standard_Real aT1, aT2, aT = 0.;
508 Handle(Geom_Curve) aC3D;
511 aC3D = BRep_Tool::Curve(theE, aT1, aT2);
514 //it means that we are in degenerated edge
515 const TopoDS_Vertex& aV = TopExp::FirstVertex(theE);
517 return TopAbs_UNKNOWN;
519 aP3D=BRep_Tool::Pnt(aV);
522 Standard_Boolean bF2Inf, bL2Inf;
523 Standard_Real dT=10.;
525 bF2Inf = Precision::IsNegativeInfinite(aT1);
526 bL2Inf = Precision::IsPositiveInfinite(aT2);
528 if (bF2Inf && !bL2Inf) {
531 else if (!bF2Inf && bL2Inf) {
534 else if (bF2Inf && bL2Inf) {
538 aT=IntTools_Tools::IntermediatePoint(aT1, aT2);
543 aState=GEOMAlgo_Tools3D::ComputeState(aP3D, theRef, theTol, theCtx);
547 //=======================================================================
548 // function: ComputeState
550 //=======================================================================
551 TopAbs_State GEOMAlgo_Tools3D::ComputeState(const gp_Pnt& theP,
552 const TopoDS_Solid& theRef,
553 const Standard_Real theTol,
554 IntTools_Context& theCtx)
558 BRepClass3d_SolidClassifier& aSC=theCtx.SolidClassifier(theRef);
559 aSC.Perform(theP, theTol);
565 //=======================================================================
566 // function: IsSplitToReverse
568 //=======================================================================
569 Standard_Boolean GEOMAlgo_Tools3D::IsSplitToReverse(const TopoDS_Shape& theSp,
570 const TopoDS_Shape& theSr,
571 IntTools_Context& theCtx)
573 Standard_Boolean bRet;
574 TopAbs_ShapeEnum aType;
578 aType=theSp.ShapeType();
581 const TopoDS_Edge& aESp=TopoDS::Edge(theSp);
582 const TopoDS_Edge& aESr=TopoDS::Edge(theSr);
583 bRet=GEOMAlgo_Tools3D::IsSplitToReverse(aESp, aESr, theCtx);
588 const TopoDS_Face& aFSp=TopoDS::Face(theSp);
589 const TopoDS_Face& aFSr=TopoDS::Face(theSr);
590 bRet=GEOMAlgo_Tools3D::IsSplitToReverse(aFSp, aFSr, theCtx);
599 //=======================================================================
600 //function :IsSplitToReverse
602 //=======================================================================
603 Standard_Boolean GEOMAlgo_Tools3D::IsSplitToReverse(const TopoDS_Face& theFSp,
604 const TopoDS_Face& theFSr,
605 IntTools_Context& theContext)
607 Standard_Boolean bRet, bFound, bInFace;
608 Standard_Real aT1, aT2, aT, aU, aV, aScPr;
612 Handle(Geom_Surface) aSr, aSp;
613 TopAbs_Orientation aOrSr, aOrSp;
614 TopExp_Explorer anExp;
619 aSr=BRep_Tool::Surface(theFSr);
620 aSp=BRep_Tool::Surface(theFSp);
622 aOrSr=theFSr.Orientation();
623 aOrSp=theFSp.Orientation();
628 bFound=Standard_False;
629 anExp.Init(theFSp, TopAbs_EDGE);
630 for (; anExp.More(); anExp.Next()) {
631 aESp=TopoDS::Edge(anExp.Current());
632 if (!BRep_Tool::Degenerated(aESp)) {
633 if (!BRep_Tool::IsClosed(aESp, theFSp)) {
643 BRep_Tool::Range(aESp, aT1, aT2);
644 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
645 BOPTools_Tools3D::GetApproxNormalToFaceOnEdge(aESp, theFSp, aT, aPFSp, aDNFSp);
647 // Parts of theContext.ComputeVS(..)
648 GeomAPI_ProjectPointOnSurf& aProjector=theContext.ProjPS(theFSr);
649 aProjector.Perform(aPFSp);
650 if (!aProjector.IsDone()) {
654 aProjector.LowerDistanceParameters(aU, aV);
655 gp_Pnt2d aP2D(aU, aV);
656 bInFace=theContext.IsPointInFace (theFSr, aP2D);
661 aSr->D1(aU, aV, aPFSr, aD1U, aD1V);
664 gp_Dir aDNFSr=aDD1U^aDD1V;
665 if (theFSr.Orientation()==TopAbs_REVERSED){
674 //=======================================================================
675 //function :IsSplitToReverse
677 //=======================================================================
678 Standard_Boolean GEOMAlgo_Tools3D::IsSplitToReverse(const TopoDS_Edge& theSplit,
679 const TopoDS_Edge& theEdge,
680 IntTools_Context& theContext)
682 Standard_Boolean bRet, aFlag, bIsDegenerated;
683 Standard_Real aTE, aTS, aScPr, aTa, aTb, aT1, aT2;
684 TopAbs_Orientation aOrSr, aOrSp;
685 Handle(Geom_Curve) aCEdge, aCSplit;
691 bIsDegenerated=(BRep_Tool::Degenerated(theSplit) ||
692 BRep_Tool::Degenerated(theEdge));
693 if (bIsDegenerated) {
697 aCEdge =BRep_Tool::Curve(theEdge , aT1, aT2);
698 aCSplit=BRep_Tool::Curve(theSplit, aTa, aTb);
700 if (aCEdge==aCSplit) {
701 aOrSr=theEdge.Orientation();
702 aOrSp=theSplit.Orientation();
707 aTS=BOPTools_Tools2D::IntermediatePoint(aTa, aTb);
708 aCSplit->D0(aTS, aP);
709 aFlag=BOPTools_Tools2D::EdgeTangent(theSplit, aTS, aVS);
712 aFlag=theContext.ProjectPointOnEdge(aP, theEdge, aTE);
713 aFlag=BOPTools_Tools2D::EdgeTangent(theEdge, aTE, aVE);
722 //=======================================================================
725 //=======================================================================
726 Standard_Integer GEOMAlgo_Tools3D::Sense (const TopoDS_Face& theF1,
727 const TopoDS_Face& theF2)
729 Standard_Integer iSense=0;
731 TopoDS_Edge aE1, aE2;
732 TopExp_Explorer anExp;
734 anExp.Init(theF1, TopAbs_EDGE);
735 for (; anExp.More(); anExp.Next()) {
736 aE1=TopoDS::Edge(anExp.Current());
737 if (!BRep_Tool::Degenerated(aE1)) {
738 if (!BRep_Tool::IsClosed(aE1, theF1)) {
744 anExp.Init(theF2, TopAbs_EDGE);
745 for (; anExp.More(); anExp.Next()) {
746 aE2=TopoDS::Edge(anExp.Current());
747 if (!BRep_Tool::Degenerated(aE2)) {
748 if (!BRep_Tool::IsClosed(aE2, theF2)) {
749 if (aE2.IsSame(aE1)) {
761 BOPTools_Tools3D::GetNormalToFaceOnEdge(aE1, theF1, aDNF1);
762 BOPTools_Tools3D::GetNormalToFaceOnEdge(aE2, theF2, aDNF2);
764 iSense=BOPTools_Tools3D::SenseFlag(aDNF1, aDNF2);
768 //=======================================================================
769 // function: CopyFace
771 //=======================================================================
772 void GEOMAlgo_Tools3D::CopyFace (const TopoDS_Face& theF1,
776 TopLoc_Location aLoc;
777 TopAbs_Orientation aOr;
781 Handle(Geom_Surface) aSurface=BRep_Tool::Surface(theF1, aLoc);
782 aTol=BRep_Tool::Tolerance(theF1);
783 aOr=theF1.Orientation();
785 aBB.MakeFace (theF2, aSurface, aLoc, aTol);
786 theF2.Orientation(aOr);
788 aIt.Initialize(theF1);
789 for (; aIt.More(); aIt.Next()) {
790 const TopoDS_Shape& aW=aIt.Value();
794 //=======================================================================
795 // function: MakeContainer
797 //=======================================================================
798 void GEOMAlgo_Tools3D::MakeContainer(const TopAbs_ShapeEnum theType,
804 case TopAbs_COMPOUND:{
806 aBB.MakeCompound(aC);
811 case TopAbs_COMPSOLID:{
812 TopoDS_CompSolid aCS;
813 aBB.MakeCompSolid(aCS);
820 aBB.MakeSolid(aSolid);
828 aBB.MakeShell(aShell);
844 //=======================================================================
845 // function: MakeConnexityBlock.
847 //=======================================================================
848 void GEOMAlgo_Tools3D::MakeConnexityBlock (const TopTools_ListOfShape& theLFIn,
849 const TopTools_IndexedMapOfShape& theMEAvoid,
850 TopTools_ListOfShape& theLCB)
852 Standard_Integer aNbF, aNbAdd1;
853 TopExp_Explorer aExp;
854 TopTools_IndexedDataMapOfShapeListOfShape aMEF;
855 TopTools_MapIteratorOfMapOfShape aItM, aItM1;
856 TopTools_MapOfShape aMCB, aMAdd, aMAdd1;
857 TopTools_ListIteratorOfListOfShape aIt;
860 aNbF=theLFIn.Extent();
861 aIt.Initialize(theLFIn);
862 for (; aIt.More(); aIt.Next()) {
863 const TopoDS_Shape& aF=aIt.Value();
864 TopExp::MapShapesAndAncestors(aF, TopAbs_EDGE, TopAbs_FACE, aMEF);
868 const TopoDS_Shape& aF1=theLFIn.First();
873 aItM.Initialize(aMAdd);
874 for (; aItM.More(); aItM.Next()) {
875 const TopoDS_Shape& aF=aItM.Key();
878 aExp.Init(aF, TopAbs_EDGE);
879 for (; aExp.More(); aExp.Next()) {
880 const TopoDS_Shape& aE=aExp.Current();
881 if (theMEAvoid.Contains(aE)){
885 const TopTools_ListOfShape& aLF=aMEF.FindFromKey(aE);
887 for (; aIt.More(); aIt.Next()) {
888 const TopoDS_Shape& aFx=aIt.Value();
889 if (aFx.IsSame(aF)) {
892 if (aMCB.Contains(aFx)) {
897 }//for (; aExp.More(); aExp.Next()){
899 }// for (; aItM.More(); aItM.Next()) {
901 aNbAdd1=aMAdd1.Extent();
907 aItM1.Initialize(aMAdd1);
908 for (; aItM1.More(); aItM1.Next()) {
909 const TopoDS_Shape& aFAdd=aItM1.Key();
917 aItM.Initialize(aMCB);
918 for (; aItM.More(); aItM.Next()) {
919 const TopoDS_Shape& aF=aItM.Key();
923 //=======================================================================
924 //function : FindFacePairs
926 //=======================================================================
927 Standard_Boolean FindFacePairs (const TopoDS_Edge& theE,
928 const TopTools_ListOfShape& thLF,
929 NMTTools_ListOfCoupleOfShape& theLCFF)
931 Standard_Boolean bFound;
932 Standard_Integer i, aNbCEF;
933 TopAbs_Orientation aOr, aOrC;
934 TopTools_MapOfShape aMFP;
935 TopoDS_Face aF1, aF2;
936 TopoDS_Edge aEL, aE1;
937 TopTools_ListIteratorOfListOfShape aItLF;
938 NMTTools_CoupleOfShape aCEF, aCFF;
939 NMTTools_ListOfCoupleOfShape aLCEF, aLCEFx;
940 NMTTools_ListIteratorOfListOfCoupleOfShape aIt;
942 bFound=Standard_True;
945 aItLF.Initialize(thLF);
946 for (; aItLF.More(); aItLF.Next()) {
947 const TopoDS_Face& aFL=TopoDS::Face(aItLF.Value());
949 bFound=GEOMAlgo_Tools3D::GetEdgeOnFace(theE, aFL, aEL);
951 return bFound; // it can not be so
959 aNbCEF=aLCEF.Extent();
964 aIt.Initialize(aLCEF);
965 for (i=0; aIt.More(); aIt.Next(), ++i) {
966 const NMTTools_CoupleOfShape& aCSx=aIt.Value();
967 const TopoDS_Shape& aEx=aCSx.Shape1();
968 const TopoDS_Shape& aFx=aCSx.Shape2();
970 aOr=aEx.Orientation();
973 aOrC=TopAbs::Reverse(aOr);
974 aE1=TopoDS::Edge(aEx);
975 aF1=TopoDS::Face(aFx);
987 GEOMAlgo_Tools3D::GetFaceOff(aE1, aF1, aLCEFx, aF2);
991 theLCFF.Append(aCFF);
1000 aIt.Initialize(aLCEFx);
1001 for (; aIt.More(); aIt.Next()) {
1002 const NMTTools_CoupleOfShape& aCSx=aIt.Value();
1003 const TopoDS_Shape& aFx=aCSx.Shape2();
1004 if (!aMFP.Contains(aFx)) {
1009 aNbCEF=aLCEF.Extent();
1015 //=======================================================================
1016 //function : AngleWithRef
1018 //=======================================================================
1019 Standard_Real AngleWithRef(const gp_Dir& theD1,
1020 const gp_Dir& theD2,
1021 const gp_Dir& theDRef)
1023 Standard_Real aCosinus, aSinus, aBeta, aHalfPI, aScPr;
1028 const gp_XYZ& aXYZ1=theD1.XYZ();
1029 const gp_XYZ& aXYZ2=theD2.XYZ();
1030 aXYZ=aXYZ1.Crossed(aXYZ2);
1031 aSinus=aXYZ.Modulus();
1032 aCosinus=theD1*theD2;
1036 aBeta=aHalfPI*(1.-aCosinus);
1039 aBeta=2.*PI-aHalfPI*(3.+aCosinus);
1042 aScPr=aXYZ.Dot(theDRef.XYZ());
1048 //modified by NIZNHY-PKV Tue Jul 14 07:49:55 2009f
1049 //=======================================================================
1050 //function : GetApproxNormalToFaceOnEdge
1052 //=======================================================================
1053 void GetApproxNormalToFaceOnEdge (const TopoDS_Edge& aEx,
1054 const TopoDS_Face& aFx,
1058 IntTools_Context& aCtx)
1060 Standard_Boolean bReverse;
1061 Standard_Real aT1, aT2, dT, aU, aV;
1062 gp_Dir aDTT, aDNFT, aDBT;
1064 Handle(Geom_Curve) aC3D;
1068 bReverse=Standard_False;
1071 if (aF.Orientation()==TopAbs_REVERSED){
1075 aF.Orientation(TopAbs_FORWARD);
1076 //GEOMAlgo_Tools3D::GetEdgeOnFace(aEx, aF, aE);
1080 aC3D =BRep_Tool::Curve(aE, aT1, aT2);
1084 BOPTools_Tools3D::GetNormalToFaceOnEdge (aE, aF, aT, aDNFT);
1087 BOPTools_Tools3D::GetTangentToEdge(aE, aT, aDTT);
1092 dT=BOPTools_Tools3D::MinStepIn2d();//~1.e-5;
1093 aPFx.SetXYZ(aPFT.XYZ()+dT*aDBT.XYZ());
1101 GeomAPI_ProjectPointOnSurf& aProjector=aCtx.ProjPS(aF);
1102 aProjector.Perform(aPFx);
1103 if(aProjector.IsDone()) {
1104 Handle(Geom_Surface) aS;
1106 aProjector.LowerDistanceParameters (aU, aV);
1107 aS=BRep_Tool::Surface(aF);
1108 aS->D0(aU, aV, aPF);
1109 BOPTools_Tools3D::GetNormalToSurface (aS, aU, aV, aDNF);
1115 //modified by NIZNHY-PKV Tue Jul 14 07:49:58 2009t