1 // Copyright (C) 2007-2012 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.hxx>
28 #include <Precision.hxx>
33 #include <gp_Pnt2d.hxx>
36 #include <gp_Dir2d.hxx>
38 #include <Geom_Curve.hxx>
39 #include <Geom_Surface.hxx>
41 #include <Geom2d_Curve.hxx>
42 #include <Geom2d_TrimmedCurve.hxx>
43 #include <Geom2d_Line.hxx>
45 #include <Geom2dHatch_Intersector.hxx>
46 #include <Geom2dHatch_Hatcher.hxx>
47 #include <HatchGen_Domain.hxx>
49 #include <GeomAPI_ProjectPointOnSurf.hxx>
51 #include <TopAbs_ShapeEnum.hxx>
52 #include <TopAbs_State.hxx>
54 #include <TopLoc_Location.hxx>
57 #include <TopoDS_Edge.hxx>
58 #include <TopoDS_CompSolid.hxx>
59 #include <TopoDS_Wire.hxx>
60 #include <TopoDS_Compound.hxx>
61 #include <TopoDS_Face.hxx>
62 #include <TopoDS_Vertex.hxx>
63 #include <TopoDS_Solid.hxx>
64 #include <TopoDS_Shell.hxx>
65 #include <TopoDS_Iterator.hxx>
68 #include <TopExp_Explorer.hxx>
70 #include <BRep_Builder.hxx>
71 #include <BRep_Tool.hxx>
73 #include <TopTools_ListOfShape.hxx>
74 #include <TopTools_IndexedMapOfShape.hxx>
75 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
76 #include <TopTools_IndexedMapOfShape.hxx>
77 #include <TopTools_ListIteratorOfListOfShape.hxx>
78 #include <TopTools_MapOfShape.hxx>
80 #include <BRepClass3d_SolidClassifier.hxx>
81 #include <BRepTools.hxx>
83 #include <IntTools_Context.hxx>
84 #include <IntTools_Tools.hxx>
86 #include <BOPTools_Tools3D.hxx>
87 #include <BOPTools_Tools2D.hxx>
88 #include <BOPTools_Tools.hxx>
90 #include <NMTTools_ListOfCoupleOfShape.hxx>
91 #include <NMTTools_ListIteratorOfListOfCoupleOfShape.hxx>
92 #include <NMTTools_CoupleOfShape.hxx>
93 #include <TopTools_DataMapOfShapeListOfShape.hxx>
94 #include <TopTools_DataMapOfShapeListOfShape.hxx>
95 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
96 #include <TopTools_MapOfShape.hxx>
97 #include <TopTools_MapIteratorOfMapOfShape.hxx>
99 #include <GeomAdaptor_Surface.hxx>
104 Standard_Boolean FindFacePairs (const TopoDS_Edge& ,
105 const TopTools_ListOfShape& ,
106 NMTTools_ListOfCoupleOfShape& );
110 Standard_Real AngleWithRef(const gp_Dir& ,
115 void GetApproxNormalToFaceOnEdge (const TopoDS_Edge& aE,
116 const TopoDS_Face& aF,
120 const Handle(IntTools_Context)& aCtx);
122 //=======================================================================
123 //function : IsInternalFace
125 //=======================================================================
126 Standard_Boolean GEOMAlgo_Tools3D::IsInternalFace(const TopoDS_Face& theFace,
127 const TopoDS_Solid& theSolid,
128 const TopTools_IndexedDataMapOfShapeListOfShape& theMEF,
129 const Standard_Real theTol,
130 const Handle(IntTools_Context)& theContext)
132 Standard_Boolean bRet;
133 Standard_Integer aNbF;
135 TopExp_Explorer aExp;
136 TopTools_ListIteratorOfListOfShape aItF;
140 // 1 Try to find an edge from theFace in theMEF
141 aExp.Init(theFace, TopAbs_EDGE);
142 for(; aExp.More(); aExp.Next()) {
143 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
144 if (!theMEF.Contains(aE)) {
148 const TopTools_ListOfShape& aLF=theMEF.FindFromKey(aE);
151 return bRet; // it can not be so
154 // aE is internal edge on aLF.First()
155 const TopoDS_Face& aF1=TopoDS::Face(aLF.First());
156 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, aE, aF1, aF1, theContext);
160 const TopoDS_Face& aF1=TopoDS::Face(aLF.First());
161 const TopoDS_Face& aF2=TopoDS::Face(aLF.Last());
163 if (aF2.IsSame(aF1) && BRep_Tool::IsClosed(aE, aF1)) {
164 // treat as it was for 1 face
165 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, aE, aF1, aF2, theContext);
170 return bRet; // it can not be so
172 else { // aNbF=2,4,6,8,...
173 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, aE, aLF, theContext);
176 }//for(; aExp.More(); aExp.Next()) {
178 //========================================
179 // 2. Classify face using classifier
182 TopTools_IndexedMapOfShape aBounds;
184 aState=GEOMAlgo_Tools3D::ComputeState(theFace, theSolid, theTol, aBounds, theContext);
185 bRet=(aState==TopAbs_IN);
189 //=======================================================================
190 //function : IsInternalFace
192 //=======================================================================
193 Standard_Boolean GEOMAlgo_Tools3D::IsInternalFace(const TopoDS_Face& theFace,
194 const TopoDS_Edge& theEdge,
195 const TopTools_ListOfShape& theLF,
196 const Handle(IntTools_Context)& theContext)
198 Standard_Boolean bRet;
199 Standard_Boolean aNbF;
205 const TopoDS_Face& aF1=TopoDS::Face(theLF.First());
206 const TopoDS_Face& aF2=TopoDS::Face(theLF.Last());
207 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, theEdge, aF1, aF2, theContext);
212 NMTTools_ListOfCoupleOfShape aLCFF;
213 NMTTools_ListIteratorOfListOfCoupleOfShape aIt;
215 FindFacePairs(theEdge, theLF, aLCFF);
217 aIt.Initialize(aLCFF);
218 for (; aIt.More(); aIt.Next()) {
219 const NMTTools_CoupleOfShape& aCSFF=aIt.Value();
221 const TopoDS_Face& aF1=TopoDS::Face(aCSFF.Shape1());
222 const TopoDS_Face& aF2=TopoDS::Face(aCSFF.Shape2());
223 bRet=GEOMAlgo_Tools3D::IsInternalFace(theFace, theEdge, aF1, aF2, theContext);
231 //=======================================================================
232 //function : IsInternalFace
234 //=======================================================================
235 Standard_Boolean GEOMAlgo_Tools3D::IsInternalFace(const TopoDS_Face& theFace,
236 const TopoDS_Edge& theEdge,
237 const TopoDS_Face& theFace1,
238 const TopoDS_Face& theFace2,
239 const Handle(IntTools_Context)& theContext)
241 Standard_Boolean bRet;
242 Standard_Real aT1, aT2, aT, aDt2D, aDt2Dx;
243 Standard_Real aA12, aA1x, aTwoPI;
244 gp_Pnt aPx, aPF, aPF1, aPF2;
245 gp_Pnt2d aP2D, aPF2D;
247 TopoDS_Edge aE1, aE2;
248 Handle(Geom_Curve)aC3D;
250 aC3D =BRep_Tool::Curve(theEdge, aT1, aT2);
251 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
255 aDt2D=BOPTools_Tools3D::MinStepIn2d();
257 BOPTools_Tools3D::PointNearEdge (theEdge, theFace, aT, aDt2Dx, aPF2D, aPF);
260 GEOMAlgo_Tools3D::GetEdgeOnFace(theEdge, theFace1, aE1);
261 if (aE1.Orientation()==TopAbs_INTERNAL) {
263 aE1.Orientation(TopAbs_FORWARD);
264 aE2.Orientation(TopAbs_REVERSED);
266 else if (theFace1==theFace2) {
268 aE1.Orientation(TopAbs_FORWARD);
269 aE2.Orientation(TopAbs_REVERSED);
272 GEOMAlgo_Tools3D::GetEdgeOnFace(theEdge, theFace2, aE2);
278 GetApproxNormalToFaceOnEdge (aE1, theFace1, aT, aPF1, aDNF1, theContext);
279 GetApproxNormalToFaceOnEdge (aE2, theFace2, aT, aPF2, aDNF2, theContext);
282 gp_Vec aVBF (aPx, aPF );
283 gp_Vec aVBF1(aPx, aPF1);
284 gp_Vec aVBF2(aPx, aPF2);
292 aA12=AngleWithRef(aDBF1, aDBF2, aDTF1);
297 aA1x=AngleWithRef(aDBF1, aDBF , aDTF1);
303 bRet=!bRet; //TopAbs_IN;
308 //=======================================================================
309 //function : GetFaceOff
311 //=======================================================================
312 void GEOMAlgo_Tools3D::GetFaceOff(const TopoDS_Edge& theE1,
313 const TopoDS_Face& theF1,
314 const NMTTools_ListOfCoupleOfShape& theLCSOff,
315 TopoDS_Face& theFOff)
317 Standard_Real aT, aT1, aT2, aAngle, aTwoPI, aAngleMin;
321 NMTTools_ListIteratorOfListOfCoupleOfShape aIt;
325 BRep_Tool::Range(theE1, aT1, aT2);
326 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
328 BOPTools_Tools2D::EdgeTangent(theE1, aT, aVTgt);
329 gp_Dir aDTtgt(aVTgt);
332 BOPTools_Tools3D::GetApproxNormalToFaceOnEdge(theE1, theF1, aT, aPn1, aDN1);
334 aIt.Initialize(theLCSOff);
335 for (; aIt.More(); aIt.Next()) {
336 const NMTTools_CoupleOfShape& aCS=aIt.Value();
337 const TopoDS_Edge& aE2=TopoDS::Edge(aCS.Shape1());
338 const TopoDS_Face& aF2=TopoDS::Face(aCS.Shape2());
343 else if (aF2.IsSame(theF1)) {
347 BOPTools_Tools3D::GetApproxNormalToFaceOnEdge (aE2, aF2, aT, aPn2, aDN2);
350 aAngle=AngleWithRef(aDN1, aDN2, aDTtgt);
352 aAngle=aTwoPI+aAngle;
356 if (aAngle<aAngleMin){
362 //=======================================================================
363 //function : GetEdgeOnFace
365 //=======================================================================
366 Standard_Boolean GEOMAlgo_Tools3D::GetEdgeOnFace(const TopoDS_Edge& theE1,
367 const TopoDS_Face& theF2,
370 Standard_Boolean bFound;
371 TopoDS_Iterator aItF, aItW;
373 bFound=Standard_False;
375 aItF.Initialize(theF2);
376 for (; aItF.More(); aItF.Next()) {
377 const TopoDS_Shape& aW=aItF.Value();
379 for (; aItW.More(); aItW.Next()) {
380 const TopoDS_Shape& aE=aItW.Value();
381 if (aE.IsSame(theE1)) {
382 theE2=TopoDS::Edge(aE);
390 //=======================================================================
391 //function : GetEdgeOff
393 //=======================================================================
394 Standard_Boolean GEOMAlgo_Tools3D::GetEdgeOff (const TopoDS_Edge& theE1,
395 const TopoDS_Face& theF2,
399 Standard_Boolean bFound;
400 TopAbs_Orientation aOr1, aOr1C, aOr2;
401 TopExp_Explorer anExp;
403 bFound=Standard_False;
404 aOr1=theE1.Orientation();
405 aOr1C=TopAbs::Reverse(aOr1);
407 anExp.Init(theF2, TopAbs_EDGE);
408 for (; anExp.More(); anExp.Next()) {
409 const TopoDS_Edge& aEF2=TopoDS::Edge(anExp.Current());
410 if (aEF2.IsSame(theE1)) {
411 aOr2=aEF2.Orientation();
421 //=======================================================================
422 // function: ComputeState
424 //=======================================================================
425 TopAbs_State GEOMAlgo_Tools3D::ComputeState(const TopoDS_Face& theF,
426 const TopoDS_Solid& theRef,
427 const Standard_Real theTol,
428 const TopTools_IndexedMapOfShape& theBounds,
429 const Handle(IntTools_Context)& theCtx)
432 TopExp_Explorer aExp;
437 aState=TopAbs_UNKNOWN;
439 aExp.Init(theF, TopAbs_EDGE);
440 for (; aExp.More(); aExp.Next()) {
441 const TopoDS_Edge& aSE=TopoDS::Edge(aExp.Current());
442 if (BRep_Tool::Degenerated(aSE)) {
446 if (!theBounds.Contains(aSE)) {
447 const TopoDS_Edge& aE=TopoDS::Edge(aSE);
448 aState= GEOMAlgo_Tools3D::ComputeState(aE, theRef, theTol, theCtx);
452 aE1=TopoDS::Edge(aSE);
455 // !!<- process edges that are all on theRef
457 BOPTools_Tools3D::PointNearEdge(aE1, theF, aP2D, aP3D);
458 aState=GEOMAlgo_Tools3D::ComputeState(aP3D, theRef, theTol, theCtx);
463 //=======================================================================
464 // function: ComputeStateByOnePoint
466 //=======================================================================
467 TopAbs_State GEOMAlgo_Tools3D::ComputeStateByOnePoint(const TopoDS_Shape& theS,
468 const TopoDS_Solid& theRef,
469 const Standard_Real theTol,
470 const Handle(IntTools_Context)& theCtx)
473 TopAbs_ShapeEnum aType;
475 aState=TopAbs_UNKNOWN;
476 aType=theS.ShapeType();
477 if (aType==TopAbs_VERTEX) {
478 const TopoDS_Vertex& aV=TopoDS::Vertex(theS);
479 aState=GEOMAlgo_Tools3D::ComputeState(aV, theRef, theTol, theCtx);
481 else if (aType==TopAbs_EDGE) {
482 const TopoDS_Edge& aE=TopoDS::Edge(theS);
483 aState=GEOMAlgo_Tools3D::ComputeState(aE, theRef, theTol, theCtx);
487 //=======================================================================
488 // function: ComputeState
490 //=======================================================================
491 TopAbs_State GEOMAlgo_Tools3D::ComputeState(const TopoDS_Vertex& theV,
492 const TopoDS_Solid& theRef,
493 const Standard_Real theTol,
494 const Handle(IntTools_Context)& theCtx)
499 aP3D=BRep_Tool::Pnt(theV);
500 aState=GEOMAlgo_Tools3D::ComputeState(aP3D, theRef, theTol, theCtx);
503 //=======================================================================
504 // function: ComputeState
506 //=======================================================================
507 TopAbs_State GEOMAlgo_Tools3D::ComputeState(const TopoDS_Edge& theE,
508 const TopoDS_Solid& theRef,
509 const Standard_Real theTol,
510 const Handle(IntTools_Context)& theCtx)
512 Standard_Real aT1, aT2, aT = 0.;
514 Handle(Geom_Curve) aC3D;
517 aC3D = BRep_Tool::Curve(theE, aT1, aT2);
520 //it means that we are in degenerated edge
521 const TopoDS_Vertex& aV = TopExp::FirstVertex(theE);
523 return TopAbs_UNKNOWN;
525 aP3D=BRep_Tool::Pnt(aV);
528 Standard_Boolean bF2Inf, bL2Inf;
529 Standard_Real dT=10.;
531 bF2Inf = Precision::IsNegativeInfinite(aT1);
532 bL2Inf = Precision::IsPositiveInfinite(aT2);
534 if (bF2Inf && !bL2Inf) {
537 else if (!bF2Inf && bL2Inf) {
540 else if (bF2Inf && bL2Inf) {
544 aT=IntTools_Tools::IntermediatePoint(aT1, aT2);
549 aState=GEOMAlgo_Tools3D::ComputeState(aP3D, theRef, theTol, theCtx);
553 //=======================================================================
554 // function: ComputeState
556 //=======================================================================
557 TopAbs_State GEOMAlgo_Tools3D::ComputeState(const gp_Pnt& theP,
558 const TopoDS_Solid& theRef,
559 const Standard_Real theTol,
560 const Handle(IntTools_Context)& theCtx)
564 BRepClass3d_SolidClassifier& aSC=theCtx->SolidClassifier(theRef);
565 aSC.Perform(theP, theTol);
571 //=======================================================================
572 // function: IsSplitToReverse
574 //=======================================================================
575 Standard_Boolean GEOMAlgo_Tools3D::IsSplitToReverse(const TopoDS_Shape& theSp,
576 const TopoDS_Shape& theSr,
577 const Handle(IntTools_Context)& theCtx)
579 Standard_Boolean bRet;
580 TopAbs_ShapeEnum aType;
584 aType=theSp.ShapeType();
587 const TopoDS_Edge& aESp=TopoDS::Edge(theSp);
588 const TopoDS_Edge& aESr=TopoDS::Edge(theSr);
589 bRet=GEOMAlgo_Tools3D::IsSplitToReverse(aESp, aESr, theCtx);
594 const TopoDS_Face& aFSp=TopoDS::Face(theSp);
595 const TopoDS_Face& aFSr=TopoDS::Face(theSr);
596 bRet=GEOMAlgo_Tools3D::IsSplitToReverse(aFSp, aFSr, theCtx);
605 //=======================================================================
606 //function :IsSplitToReverse
608 //=======================================================================
609 Standard_Boolean GEOMAlgo_Tools3D::IsSplitToReverse(const TopoDS_Face& theFSp,
610 const TopoDS_Face& theFSr,
611 const Handle(IntTools_Context)& theContext)
613 Standard_Boolean bRet, bFound, bInFace;
614 Standard_Real aT1, aT2, aT, aU, aV, aScPr;
618 Handle(Geom_Surface) aSr, aSp;
619 TopAbs_Orientation aOrSr, aOrSp;
620 TopExp_Explorer anExp;
625 aSr=BRep_Tool::Surface(theFSr);
626 aSp=BRep_Tool::Surface(theFSp);
628 aOrSr=theFSr.Orientation();
629 aOrSp=theFSp.Orientation();
634 bFound=Standard_False;
635 anExp.Init(theFSp, TopAbs_EDGE);
636 for (; anExp.More(); anExp.Next()) {
637 aESp=TopoDS::Edge(anExp.Current());
638 if (!BRep_Tool::Degenerated(aESp)) {
639 if (!BRep_Tool::IsClosed(aESp, theFSp)) {
646 //modified by NIZNHY-PKV Tue Nov 22 10:50:30 2011f
648 Standard_Boolean bFlag;
649 Standard_Integer iErr;
652 iErr=GEOMAlgo_Tools3D::PntInFace(theFSp, aPFSp, aP2DFSp);
657 aP2DFSp.Coord(aU, aV);
658 bFlag=BOPTools_Tools3D::GetNormalToSurface(aSp, aU, aV, aDNFSp);
664 BRep_Tool::Range(aESp, aT1, aT2);
665 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
666 BOPTools_Tools3D::GetApproxNormalToFaceOnEdge(aESp, theFSp, aT, aPFSp, aDNFSp);
673 BRep_Tool::Range(aESp, aT1, aT2);
674 aT=BOPTools_Tools2D::IntermediatePoint(aT1, aT2);
675 BOPTools_Tools3D::GetApproxNormalToFaceOnEdge(aESp, theFSp, aT, aPFSp, aDNFSp);
677 //modified by NIZNHY-PKV Tue Nov 22 10:50:37 2011t
679 // Parts of theContext.ComputeVS(..)
680 GeomAPI_ProjectPointOnSurf& aProjector=theContext->ProjPS(theFSr);
681 aProjector.Perform(aPFSp);
682 if (!aProjector.IsDone()) {
686 aProjector.LowerDistanceParameters(aU, aV);
687 gp_Pnt2d aP2D(aU, aV);
688 bInFace=theContext->IsPointInFace (theFSr, aP2D);
693 aSr->D1(aU, aV, aPFSr, aD1U, aD1V);
696 gp_Dir aDNFSr=aDD1U^aDD1V;
697 if (theFSr.Orientation()==TopAbs_REVERSED){
706 //=======================================================================
707 //function :IsSplitToReverse
709 //=======================================================================
710 Standard_Boolean GEOMAlgo_Tools3D::IsSplitToReverse(const TopoDS_Edge& theSplit,
711 const TopoDS_Edge& theEdge,
712 const Handle(IntTools_Context)& theContext)
714 Standard_Boolean bRet, aFlag, bIsDegenerated;
715 Standard_Real aTE, aTS, aScPr, aTa, aTb, aT1, aT2;
716 TopAbs_Orientation aOrSr, aOrSp;
717 Handle(Geom_Curve) aCEdge, aCSplit;
723 bIsDegenerated=(BRep_Tool::Degenerated(theSplit) ||
724 BRep_Tool::Degenerated(theEdge));
725 if (bIsDegenerated) {
729 aCEdge =BRep_Tool::Curve(theEdge , aT1, aT2);
730 aCSplit=BRep_Tool::Curve(theSplit, aTa, aTb);
732 if (aCEdge==aCSplit) {
733 aOrSr=theEdge.Orientation();
734 aOrSp=theSplit.Orientation();
739 aTS=BOPTools_Tools2D::IntermediatePoint(aTa, aTb);
740 aCSplit->D0(aTS, aP);
741 aFlag=BOPTools_Tools2D::EdgeTangent(theSplit, aTS, aVS);
744 aFlag=theContext->ProjectPointOnEdge(aP, theEdge, aTE);
745 aFlag=BOPTools_Tools2D::EdgeTangent(theEdge, aTE, aVE);
754 //=======================================================================
757 //=======================================================================
758 Standard_Integer GEOMAlgo_Tools3D::Sense (const TopoDS_Face& theF1,
759 const TopoDS_Face& theF2)
761 Standard_Integer iSense=0;
763 TopoDS_Edge aE1, aE2;
764 TopExp_Explorer anExp;
766 anExp.Init(theF1, TopAbs_EDGE);
767 for (; anExp.More(); anExp.Next()) {
768 aE1=TopoDS::Edge(anExp.Current());
769 if (!BRep_Tool::Degenerated(aE1)) {
770 if (!BRep_Tool::IsClosed(aE1, theF1)) {
776 anExp.Init(theF2, TopAbs_EDGE);
777 for (; anExp.More(); anExp.Next()) {
778 aE2=TopoDS::Edge(anExp.Current());
779 if (!BRep_Tool::Degenerated(aE2)) {
780 if (!BRep_Tool::IsClosed(aE2, theF2)) {
781 if (aE2.IsSame(aE1)) {
793 BOPTools_Tools3D::GetNormalToFaceOnEdge(aE1, theF1, aDNF1);
794 BOPTools_Tools3D::GetNormalToFaceOnEdge(aE2, theF2, aDNF2);
796 iSense=BOPTools_Tools3D::SenseFlag(aDNF1, aDNF2);
800 //=======================================================================
801 // function: CopyFace
803 //=======================================================================
804 void GEOMAlgo_Tools3D::CopyFace (const TopoDS_Face& theF1,
808 TopLoc_Location aLoc;
809 TopAbs_Orientation aOr;
813 Handle(Geom_Surface) aSurface=BRep_Tool::Surface(theF1, aLoc);
814 aTol=BRep_Tool::Tolerance(theF1);
815 aOr=theF1.Orientation();
817 aBB.MakeFace (theF2, aSurface, aLoc, aTol);
818 theF2.Orientation(aOr);
820 aIt.Initialize(theF1);
821 for (; aIt.More(); aIt.Next()) {
822 const TopoDS_Shape& aW=aIt.Value();
826 //=======================================================================
827 // function: MakeContainer
829 //=======================================================================
830 void GEOMAlgo_Tools3D::MakeContainer(const TopAbs_ShapeEnum theType,
836 case TopAbs_COMPOUND:{
838 aBB.MakeCompound(aC);
843 case TopAbs_COMPSOLID:{
844 TopoDS_CompSolid aCS;
845 aBB.MakeCompSolid(aCS);
852 aBB.MakeSolid(aSolid);
860 aBB.MakeShell(aShell);
876 //=======================================================================
877 // function: MakeConnexityBlock.
879 //=======================================================================
880 void GEOMAlgo_Tools3D::MakeConnexityBlock (const TopTools_ListOfShape& theLFIn,
881 const TopTools_IndexedMapOfShape& theMEAvoid,
882 TopTools_ListOfShape& theLCB)
884 Standard_Integer aNbF, aNbAdd1;
885 TopExp_Explorer aExp;
886 TopTools_IndexedDataMapOfShapeListOfShape aMEF;
887 TopTools_MapIteratorOfMapOfShape aItM, aItM1;
888 TopTools_MapOfShape aMCB, aMAdd, aMAdd1;
889 TopTools_ListIteratorOfListOfShape aIt;
892 aNbF=theLFIn.Extent();
893 aIt.Initialize(theLFIn);
894 for (; aIt.More(); aIt.Next()) {
895 const TopoDS_Shape& aF=aIt.Value();
896 TopExp::MapShapesAndAncestors(aF, TopAbs_EDGE, TopAbs_FACE, aMEF);
900 const TopoDS_Shape& aF1=theLFIn.First();
905 aItM.Initialize(aMAdd);
906 for (; aItM.More(); aItM.Next()) {
907 const TopoDS_Shape& aF=aItM.Key();
910 aExp.Init(aF, TopAbs_EDGE);
911 for (; aExp.More(); aExp.Next()) {
912 const TopoDS_Shape& aE=aExp.Current();
913 if (theMEAvoid.Contains(aE)){
917 const TopTools_ListOfShape& aLF=aMEF.FindFromKey(aE);
919 for (; aIt.More(); aIt.Next()) {
920 const TopoDS_Shape& aFx=aIt.Value();
921 if (aFx.IsSame(aF)) {
924 if (aMCB.Contains(aFx)) {
929 }//for (; aExp.More(); aExp.Next()){
931 }// for (; aItM.More(); aItM.Next()) {
933 aNbAdd1=aMAdd1.Extent();
939 aItM1.Initialize(aMAdd1);
940 for (; aItM1.More(); aItM1.Next()) {
941 const TopoDS_Shape& aFAdd=aItM1.Key();
949 aItM.Initialize(aMCB);
950 for (; aItM.More(); aItM.Next()) {
951 const TopoDS_Shape& aF=aItM.Key();
955 //=======================================================================
956 //function : FindFacePairs
958 //=======================================================================
959 Standard_Boolean FindFacePairs (const TopoDS_Edge& theE,
960 const TopTools_ListOfShape& thLF,
961 NMTTools_ListOfCoupleOfShape& theLCFF)
963 Standard_Boolean bFound;
964 Standard_Integer i, aNbCEF;
965 TopAbs_Orientation aOr, aOrC;
966 TopTools_MapOfShape aMFP;
967 TopoDS_Face aF1, aF2;
968 TopoDS_Edge aEL, aE1;
969 TopTools_ListIteratorOfListOfShape aItLF;
970 NMTTools_CoupleOfShape aCEF, aCFF;
971 NMTTools_ListOfCoupleOfShape aLCEF, aLCEFx;
972 NMTTools_ListIteratorOfListOfCoupleOfShape aIt;
974 bFound=Standard_True;
977 aItLF.Initialize(thLF);
978 for (; aItLF.More(); aItLF.Next()) {
979 const TopoDS_Face& aFL=TopoDS::Face(aItLF.Value());
981 bFound=GEOMAlgo_Tools3D::GetEdgeOnFace(theE, aFL, aEL);
983 return bFound; // it can not be so
991 aNbCEF=aLCEF.Extent();
996 aIt.Initialize(aLCEF);
997 for (i=0; aIt.More(); aIt.Next(), ++i) {
998 const NMTTools_CoupleOfShape& aCSx=aIt.Value();
999 const TopoDS_Shape& aEx=aCSx.Shape1();
1000 const TopoDS_Shape& aFx=aCSx.Shape2();
1002 aOr=aEx.Orientation();
1005 aOrC=TopAbs::Reverse(aOr);
1006 aE1=TopoDS::Edge(aEx);
1007 aF1=TopoDS::Face(aFx);
1013 aLCEFx.Append(aCSx);
1019 GEOMAlgo_Tools3D::GetFaceOff(aE1, aF1, aLCEFx, aF2);
1021 aCFF.SetShape1(aF1);
1022 aCFF.SetShape2(aF2);
1023 theLCFF.Append(aCFF);
1032 aIt.Initialize(aLCEFx);
1033 for (; aIt.More(); aIt.Next()) {
1034 const NMTTools_CoupleOfShape& aCSx=aIt.Value();
1035 const TopoDS_Shape& aFx=aCSx.Shape2();
1036 if (!aMFP.Contains(aFx)) {
1041 aNbCEF=aLCEF.Extent();
1047 //=======================================================================
1048 //function : AngleWithRef
1050 //=======================================================================
1051 Standard_Real AngleWithRef(const gp_Dir& theD1,
1052 const gp_Dir& theD2,
1053 const gp_Dir& theDRef)
1055 Standard_Real aCosinus, aSinus, aBeta, aHalfPI, aScPr;
1060 const gp_XYZ& aXYZ1=theD1.XYZ();
1061 const gp_XYZ& aXYZ2=theD2.XYZ();
1062 aXYZ=aXYZ1.Crossed(aXYZ2);
1063 aSinus=aXYZ.Modulus();
1064 aCosinus=theD1*theD2;
1068 aBeta=aHalfPI*(1.-aCosinus);
1071 aBeta=2.*M_PI-aHalfPI*(3.+aCosinus);
1074 aScPr=aXYZ.Dot(theDRef.XYZ());
1080 //=======================================================================
1081 //function : GetApproxNormalToFaceOnEdge
1083 //=======================================================================
1084 void GetApproxNormalToFaceOnEdge (const TopoDS_Edge& aEx,
1085 const TopoDS_Face& aFx,
1089 const Handle(IntTools_Context)& aCtx)
1091 Standard_Boolean bReverse;
1092 Standard_Real aT1, aT2, dT, aU, aV;
1093 gp_Dir aDTT, aDNFT, aDBT;
1095 Handle(Geom_Curve) aC3D;
1096 Handle(Geom_Surface) aS;
1097 GeomAdaptor_Surface aGAS;
1098 GeomAbs_SurfaceType aTS;
1102 bReverse=Standard_False;
1105 if (aF.Orientation()==TopAbs_REVERSED){
1109 aF.Orientation(TopAbs_FORWARD);
1113 aC3D =BRep_Tool::Curve(aE, aT1, aT2);
1117 BOPTools_Tools3D::GetNormalToFaceOnEdge (aE, aF, aT, aDNFT);
1120 BOPTools_Tools3D::GetTangentToEdge(aE, aT, aDTT);
1125 dT=BOPTools_Tools3D::MinStepIn2d();//~1.e-5;
1127 //----------------------------------------------
1129 aS=BRep_Tool::Surface(aF);
1132 if (aTS==GeomAbs_BSplineSurface ||
1133 aTS==GeomAbs_BezierSurface ||
1134 aTS==GeomAbs_Plane){
1135 Standard_Real aTolEx, aTolFx, aTol, dUR, dVR, dR;
1137 aTolEx=BRep_Tool::Tolerance(aEx);
1138 aTolFx=BRep_Tool::Tolerance(aFx);
1139 aTol=2.*aTolEx+aTolFx;
1140 dUR=aGAS.UResolution(aTol);
1141 dVR=aGAS.VResolution(aTol);
1142 dR=(dUR>dVR)? dUR : dVR;
1147 else if (GeomAbs_Torus ||
1148 aTS==GeomAbs_Cylinder){
1149 Standard_Real aTolEx, aTolFx, aTol;
1151 aTolEx=BRep_Tool::Tolerance(aEx);
1152 aTolFx=BRep_Tool::Tolerance(aFx);
1153 aTol=2.*aTolEx+aTolFx;
1159 //----------------------------------------------
1161 aPFx.SetXYZ(aPFT.XYZ()+dT*aDBT.XYZ());
1169 GeomAPI_ProjectPointOnSurf& aProjector=aCtx->ProjPS(aF);
1171 aProjector.Perform(aPFx);
1172 if(aProjector.IsDone()) {
1173 aProjector.LowerDistanceParameters (aU, aV);
1174 aS->D0(aU, aV, aPF);
1175 BOPTools_Tools3D::GetNormalToSurface (aS, aU, aV, aDNF);
1182 //modified by NIZNHY-PKV Tue Nov 22 10:36:59 2011f
1183 //=======================================================================
1184 //function : PntInFace
1186 //=======================================================================
1187 Standard_Integer GEOMAlgo_Tools3D::PntInFace(const TopoDS_Face& aF,
1191 Standard_Boolean bIsDone, bHasFirstPoint, bHasSecondPoint;
1192 Standard_Integer iErr, aIx, aNbDomains, i;
1193 Standard_Real aUMin, aUMax, aVMin, aVMax;
1194 Standard_Real aVx, aUx, aV1, aV2, aU1, aU2, aEpsT;
1195 Standard_Real aTotArcIntr, aTolTangfIntr, aTolHatch2D, aTolHatch3D;
1196 gp_Dir2d aD2D (0., 1.);
1199 Handle(Geom2d_Curve) aC2D;
1200 Handle(Geom2d_TrimmedCurve) aCT2D;
1201 Handle(Geom2d_Line) aL2D;
1202 Handle(Geom_Surface) aS;
1203 TopAbs_Orientation aOrE;
1205 TopExp_Explorer aExp;
1210 aTolTangfIntr=1.e-10;
1212 Geom2dHatch_Intersector aIntr(aTotArcIntr, aTolTangfIntr);
1213 Geom2dHatch_Hatcher aHatcher(aIntr,
1214 aTolHatch2D, aTolHatch3D,
1215 Standard_True, Standard_False);
1221 aFF.Orientation (TopAbs_FORWARD);
1223 aS=BRep_Tool::Surface(aFF);
1224 BRepTools::UVBounds(aFF, aUMin, aUMax, aVMin, aVMax);
1227 aExp.Init (aFF, TopAbs_EDGE);
1228 for (; aExp.More() ; aExp.Next()) {
1229 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aExp.Current());
1230 aOrE=aE.Orientation();
1232 aC2D=BRep_Tool::CurveOnSurface (aE, aFF, aU1, aU2);
1233 if (aC2D.IsNull() ) {
1237 if (fabs(aU1-aU2) < aEpsT) {
1242 aCT2D=new Geom2d_TrimmedCurve(aC2D, aU1, aU2);
1243 aHatcher.AddElement(aCT2D, aOrE);
1244 }// for (; aExp.More() ; aExp.Next()) {
1247 aUx=IntTools_Tools::IntermediatePoint(aUMin, aUMax);
1248 aP2D.SetCoord(aUx, 0.);
1249 aL2D=new Geom2d_Line (aP2D, aD2D);
1250 Geom2dAdaptor_Curve aHCur(aL2D);
1252 aIx=aHatcher.AddHatching(aHCur) ;
1256 bIsDone=aHatcher.TrimDone(aIx);
1262 aHatcher.ComputeDomains(aIx);
1263 bIsDone=aHatcher.IsDone(aIx);
1270 aNbDomains=aHatcher.NbDomains(aIx);
1271 for (i=1; i<=aNbDomains; ++i) {
1272 const HatchGen_Domain& aDomain=aHatcher.Domain (aIx, i) ;
1273 bHasFirstPoint=aDomain.HasFirstPoint();
1274 if (!bHasFirstPoint) {
1279 aV1=aDomain.FirstPoint().Parameter();
1281 bHasSecondPoint=aDomain.HasSecondPoint();
1282 if (!bHasSecondPoint) {
1287 aV2=aDomain.SecondPoint().Parameter();
1289 aVx=IntTools_Tools::IntermediatePoint(aV1, aV2);
1294 aS->D0(aUx, aVx, aPx);
1296 theP2D.SetCoord(aUx, aVx);
1301 //modified by NIZNHY-PKV Tue Nov 22 10:37:01 2011t