1 // Copyright (C) 2007-2010 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
23 // File: GEOMAlgo_Tools3D.cxx
25 // Author: Peter KURNEV
27 #include <GEOMAlgo_Tools3D.ixx>
29 #include <Precision.hxx>
34 #include <gp_Pnt2d.hxx>
38 #include <Geom_Curve.hxx>
39 #include <Geom_Surface.hxx>
40 #include <Geom2d_Curve.hxx>
41 #include <GeomAPI_ProjectPointOnSurf.hxx>
43 #include <TopAbs_ShapeEnum.hxx>
44 #include <TopAbs_State.hxx>
46 #include <TopLoc_Location.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_CompSolid.hxx>
51 #include <TopoDS_Wire.hxx>
52 #include <TopoDS_Compound.hxx>
53 #include <TopoDS_Face.hxx>
54 #include <TopoDS_Vertex.hxx>
55 #include <TopoDS_Solid.hxx>
56 #include <TopoDS_Shell.hxx>
57 #include <TopoDS_Iterator.hxx>
60 #include <TopExp_Explorer.hxx>
62 #include <BRep_Builder.hxx>
63 #include <BRep_Tool.hxx>
65 #include <TopTools_ListOfShape.hxx>
66 #include <TopTools_IndexedMapOfShape.hxx>
67 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
68 #include <TopTools_IndexedMapOfShape.hxx>
69 #include <TopTools_ListIteratorOfListOfShape.hxx>
70 #include <TopTools_MapOfShape.hxx>
72 #include <BRepClass3d_SolidClassifier.hxx>
74 #include <IntTools_Context.hxx>
75 #include <IntTools_Tools.hxx>
77 #include <BOPTools_Tools3D.hxx>
78 #include <BOPTools_Tools2D.hxx>
79 #include <BOPTools_Tools.hxx>
81 #include <NMTTools_ListOfCoupleOfShape.hxx>
82 #include <NMTTools_ListIteratorOfListOfCoupleOfShape.hxx>
83 #include <NMTTools_CoupleOfShape.hxx>
84 #include <TopTools_DataMapOfShapeListOfShape.hxx>
85 #include <TopTools_DataMapOfShapeListOfShape.hxx>
86 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
87 #include <TopTools_MapOfShape.hxx>
88 #include <TopTools_MapIteratorOfMapOfShape.hxx>
90 #include <GeomAdaptor_Surface.hxx>
95 Standard_Boolean FindFacePairs (const TopoDS_Edge& ,
96 const TopTools_ListOfShape& ,
97 NMTTools_ListOfCoupleOfShape& );
101 Standard_Real AngleWithRef(const gp_Dir& ,
106 void GetApproxNormalToFaceOnEdge (const TopoDS_Edge& aE,
107 const TopoDS_Face& aF,
111 IntTools_Context& aCtx);
113 //=======================================================================
114 //function : IsInternalFace
116 //=======================================================================
117 Standard_Boolean GEOMAlgo_Tools3D::IsInternalFace(const TopoDS_Face& theFace,
118 const TopoDS_Solid& theSolid,
119 const TopTools_IndexedDataMapOfShapeListOfShape& theMEF,
120 const Standard_Real theTol,
121 IntTools_Context& theContext)
123 Standard_Boolean bRet;
124 Standard_Integer aNbF;
126 TopExp_Explorer aExp;
127 TopTools_ListIteratorOfListOfShape aItF;
131 // 1 Try to find an edge from theFace in theMEF
132 aExp.Init(theFace, TopAbs_EDGE);
133 for(; aExp.More(); aExp.Next()) {
134 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
135 if (!theMEF.Contains(aE)) {
139 const TopTools_ListOfShape& aLF=theMEF.FindFromKey(aE);
142 return bRet; // it can not be so
145 // aE is internal edge on aLF.First()
146 const TopoDS_Face& aF1=TopoDS::Face(aLF.First());
147 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, aE, aF1, aF1, theContext);
151 const TopoDS_Face& aF1=TopoDS::Face(aLF.First());
152 const TopoDS_Face& aF2=TopoDS::Face(aLF.Last());
154 if (aF2.IsSame(aF1) && BRep_Tool::IsClosed(aE, aF1)) {
155 // treat as it was for 1 face
156 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, aE, aF1, aF2, theContext);
161 return bRet; // it can not be so
163 else { // aNbF=2,4,6,8,...
164 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, aE, aLF, theContext);
167 }//for(; aExp.More(); aExp.Next()) {
169 //========================================
170 // 2. Classify face using classifier
173 TopTools_IndexedMapOfShape aBounds;
175 aState=GEOMAlgo_Tools3D::ComputeState(theFace, theSolid, theTol, aBounds, theContext);
176 bRet=(aState==TopAbs_IN);
180 //=======================================================================
181 //function : IsInternalFace
183 //=======================================================================
184 Standard_Boolean GEOMAlgo_Tools3D::IsInternalFace(const TopoDS_Face& theFace,
185 const TopoDS_Edge& theEdge,
186 const TopTools_ListOfShape& theLF,
187 IntTools_Context& theContext)
189 Standard_Boolean bRet;
190 Standard_Boolean aNbF;
196 const TopoDS_Face& aF1=TopoDS::Face(theLF.First());
197 const TopoDS_Face& aF2=TopoDS::Face(theLF.Last());
198 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, theEdge, aF1, aF2, theContext);
203 NMTTools_ListOfCoupleOfShape aLCFF;
204 NMTTools_ListIteratorOfListOfCoupleOfShape aIt;
206 FindFacePairs(theEdge, theLF, aLCFF);
208 aIt.Initialize(aLCFF);
209 for (; aIt.More(); aIt.Next()) {
210 const NMTTools_CoupleOfShape& aCSFF=aIt.Value();
212 const TopoDS_Face& aF1=TopoDS::Face(aCSFF.Shape1());
213 const TopoDS_Face& aF2=TopoDS::Face(aCSFF.Shape2());
214 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, theEdge, aF1, aF2, theContext);
222 //=======================================================================
223 //function : IsInternalFace
225 //=======================================================================
226 Standard_Boolean GEOMAlgo_Tools3D::IsInternalFace(const TopoDS_Face& theFace,
227 const TopoDS_Edge& theEdge,
228 const TopoDS_Face& theFace1,
229 const TopoDS_Face& theFace2,
230 IntTools_Context& theContext)
232 Standard_Boolean bRet;
233 Standard_Real aT1, aT2, aT, aDt2D, aDt2Dx;
234 Standard_Real aA12, aA1x, aTwoPI;
235 gp_Pnt aPx, aPF, aPF1, aPF2;
236 gp_Pnt2d aP2D, aPF2D;
238 TopoDS_Edge aE1, aE2;
239 Handle(Geom_Curve)aC3D;
241 aC3D =BRep_Tool::Curve(theEdge, aT1, aT2);
242 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
246 aDt2D=BOPTools_Tools3D::MinStepIn2d();
248 BOPTools_Tools3D::PointNearEdge (theEdge, theFace, aT, aDt2Dx, aPF2D, aPF);
251 GEOMAlgo_Tools3D::GetEdgeOnFace(theEdge, theFace1, aE1);
252 if (aE1.Orientation()==TopAbs_INTERNAL) {
254 aE1.Orientation(TopAbs_FORWARD);
255 aE2.Orientation(TopAbs_REVERSED);
257 else if (theFace1==theFace2) {
259 aE1.Orientation(TopAbs_FORWARD);
260 aE2.Orientation(TopAbs_REVERSED);
263 GEOMAlgo_Tools3D::GetEdgeOnFace(theEdge, theFace2, aE2);
269 GetApproxNormalToFaceOnEdge (aE1, theFace1, aT, aPF1, aDNF1, theContext);
270 GetApproxNormalToFaceOnEdge (aE2, theFace2, aT, aPF2, aDNF2, theContext);
272 //BOPTools_Tools3D::GetApproxNormalToFaceOnEdge (aE1, theFace1, aT, aPF1, aDNF1);
273 //BOPTools_Tools3D::GetApproxNormalToFaceOnEdge (aE2, theFace2, aT, aPF2, aDNF2);
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 //=======================================================================
1049 //function : GetApproxNormalToFaceOnEdge
1051 //=======================================================================
1052 void GetApproxNormalToFaceOnEdge (const TopoDS_Edge& aEx,
1053 const TopoDS_Face& aFx,
1057 IntTools_Context& aCtx)
1059 Standard_Boolean bReverse;
1060 Standard_Real aT1, aT2, dT, aU, aV;
1061 gp_Dir aDTT, aDNFT, aDBT;
1063 Handle(Geom_Curve) aC3D;
1064 Handle(Geom_Surface) aS;
1065 GeomAdaptor_Surface aGAS;
1066 GeomAbs_SurfaceType aTS;
1070 bReverse=Standard_False;
1073 if (aF.Orientation()==TopAbs_REVERSED){
1077 aF.Orientation(TopAbs_FORWARD);
1081 aC3D =BRep_Tool::Curve(aE, aT1, aT2);
1085 BOPTools_Tools3D::GetNormalToFaceOnEdge (aE, aF, aT, aDNFT);
1088 BOPTools_Tools3D::GetTangentToEdge(aE, aT, aDTT);
1093 dT=BOPTools_Tools3D::MinStepIn2d();//~1.e-5;
1095 //----------------------------------------------
1097 aS=BRep_Tool::Surface(aF);
1100 if (aTS==GeomAbs_BSplineSurface ||
1101 aTS==GeomAbs_BezierSurface ||
1102 aTS==GeomAbs_Plane) {//modified by NIZNHY-PKV Fri Dec 4 08:23:24 2009ft
1103 Standard_Real aTolEx, aTolFx, aTol, dUR, dVR, dR;
1105 aTolEx=BRep_Tool::Tolerance(aEx);
1106 aTolFx=BRep_Tool::Tolerance(aFx);
1107 aTol=2.*aTolEx+aTolFx;
1108 dUR=aGAS.UResolution(aTol);
1109 dVR=aGAS.VResolution(aTol);
1110 dR=(dUR>dVR)? dUR : dVR;
1116 //----------------------------------------------
1118 aPFx.SetXYZ(aPFT.XYZ()+dT*aDBT.XYZ());
1126 GeomAPI_ProjectPointOnSurf& aProjector=aCtx.ProjPS(aF);
1128 aProjector.Perform(aPFx);
1129 if(aProjector.IsDone()) {
1130 aProjector.LowerDistanceParameters (aU, aV);
1131 aS->D0(aU, aV, aPF);
1132 BOPTools_Tools3D::GetNormalToSurface (aS, aU, aV, aDNF);