Back to index

salome-geom  6.5.0
GEOMAlgo_BuilderFace.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File:        GEOMAlgo_BuilderFace.cxx
00024 // Created:
00025 // Author:      Peter KURNEV
00026 //
00027 #include <GEOMAlgo_BuilderFace.hxx>
00028 
00029 #include <gp_Pnt2d.hxx>
00030 #include <gp_Pln.hxx>
00031 #include <gp_Vec.hxx>
00032 #include <gp_Dir.hxx>
00033 #include <gp_Pnt.hxx>
00034 
00035 #include <Geom_Surface.hxx>
00036 
00037 #include <TopAbs.hxx>
00038 #include <TopLoc_Location.hxx>
00039 
00040 #include <TopoDS_Iterator.hxx>
00041 #include <TopoDS_Face.hxx>
00042 #include <TopoDS.hxx>
00043 #include <TopoDS_Shape.hxx>
00044 #include <TopoDS_Wire.hxx>
00045 #include <TopoDS_Edge.hxx>
00046 #include <TopoDS_Vertex.hxx>
00047 
00048 #include <BRep_Builder.hxx>
00049 #include <BRep_Tool.hxx>
00050 #include <BRepTools.hxx>
00051 
00052 #include <TopExp.hxx>
00053 #include <TopExp_Explorer.hxx>
00054 
00055 #include <TopTools_MapOfShape.hxx>
00056 #include <TopTools_MapIteratorOfMapOfShape.hxx>
00057 #include <TopTools_MapOfOrientedShape.hxx>
00058 #include <TopTools_MapIteratorOfMapOfOrientedShape.hxx>
00059 #include <TopTools_ListOfShape.hxx>
00060 #include <TopTools_ListIteratorOfListOfShape.hxx>
00061 #include <TopTools_DataMapOfShapeShape.hxx>
00062 #include <TopTools_IndexedMapOfShape.hxx>
00063 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
00064 #include <TopTools_DataMapOfShapeListOfShape.hxx>
00065 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
00066 
00067 #include <IntTools_FClass2d.hxx>
00068 #include <IntTools_Context.hxx>
00069 
00070 #include <BOPTools_Tools2D.hxx>
00071 #include <BOP_WireEdgeSet.hxx>
00072 #include <BOP_WESCorrector.hxx>
00073 
00074 #include <NMTTools_ListOfCoupleOfShape.hxx>
00075 #include <NMTTools_CoupleOfShape.hxx>
00076 #include <NMTTools_ListIteratorOfListOfCoupleOfShape.hxx>
00077 
00078 #include <GEOMAlgo_Tools3D.hxx>
00079 #include <GEOMAlgo_BuilderTools.hxx>
00080 #include <GEOMAlgo_WireEdgeSet.hxx>
00081 #include <GEOMAlgo_WESCorrector.hxx>
00082 
00083 //
00084 static
00085   Standard_Boolean IsGrowthWire(const TopoDS_Shape& ,
00086 
00087                                 const TopTools_IndexedMapOfShape& );
00088 
00089 static
00090   Standard_Boolean IsInside(const TopoDS_Shape& ,
00091                             const TopoDS_Shape& ,
00092                             const Handle(IntTools_Context)& );
00093 static
00094   void MakeInternalWires(const TopTools_MapOfShape& ,
00095                          TopTools_ListOfShape& );
00096 
00097 //=======================================================================
00098 //function :
00099 //purpose  :
00100 //=======================================================================
00101   GEOMAlgo_BuilderFace::GEOMAlgo_BuilderFace()
00102 :
00103   GEOMAlgo_BuilderArea()
00104 {
00105 }
00106 //=======================================================================
00107 //function : ~
00108 //purpose  :
00109 //=======================================================================
00110   GEOMAlgo_BuilderFace::~GEOMAlgo_BuilderFace()
00111 {
00112 }
00113 //=======================================================================
00114 //function : SetFace
00115 //purpose  :
00116 //=======================================================================
00117   void GEOMAlgo_BuilderFace::SetFace(const TopoDS_Face& theFace)
00118 {
00119   myFace=theFace;
00120 }
00121 //=======================================================================
00122 //function : Face
00123 //purpose  :
00124 //=======================================================================
00125   const TopoDS_Face& GEOMAlgo_BuilderFace::Face()const
00126 {
00127   return myFace;
00128 }
00129 //=======================================================================
00130 //function : Perform
00131 //purpose  :
00132 //=======================================================================
00133   void GEOMAlgo_BuilderFace::Perform()
00134 {
00135   myErrorStatus=0;
00136   //
00137   if (myFace.IsNull()) {
00138     myErrorStatus=12;// Null face generix
00139     return;
00140   }
00141   // Initialize the context
00142   GEOMAlgo_BuilderArea::Perform();
00143   //
00144   PerformShapesToAvoid();
00145   if (myErrorStatus) {
00146     return;
00147   }
00148   //
00149   PerformLoops();
00150   if (myErrorStatus) {
00151     return;
00152   }
00153   //
00154   PerformAreas();
00155   if (myErrorStatus) {
00156     return;
00157   }
00158   //
00159   PerformInternalShapes();
00160   if (myErrorStatus) {
00161     return;
00162   }
00163 }
00164 //=======================================================================
00165 //function :PerformShapesToAvoid
00166 //purpose  :
00167 //=======================================================================
00168   void GEOMAlgo_BuilderFace::PerformShapesToAvoid()
00169 {
00170   Standard_Boolean bFound;
00171   Standard_Integer i, iCnt, aNbV, aNbE;
00172   TopTools_IndexedDataMapOfShapeListOfShape aMVE;
00173   TopTools_ListIteratorOfListOfShape aIt;
00174   //
00175   myShapesToAvoid.Clear();
00176   //
00177   iCnt=0;
00178   while (1) {
00179     ++iCnt;
00180     bFound=Standard_False;
00181     //
00182     // 1. MEF
00183     aMVE.Clear();
00184     aIt.Initialize (myShapes);
00185     for (; aIt.More(); aIt.Next()) {
00186       const TopoDS_Shape& aE=aIt.Value();
00187       if (!myShapesToAvoid.Contains(aE)) {
00188         TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
00189       }
00190 //       else {
00191 //         int a=0;
00192 //       }
00193     }
00194     aNbV=aMVE.Extent();
00195     //
00196     // 2. myEdgesToAvoid
00197     for (i=1; i<=aNbV; ++i) {
00198       const TopoDS_Vertex& aV=TopoDS::Vertex(aMVE.FindKey(i));
00199       //
00200       TopTools_ListOfShape& aLE=aMVE.ChangeFromKey(aV);
00201       aNbE=aLE.Extent();
00202       if (!aNbE) {
00203         continue;
00204       }
00205       //
00206       const TopoDS_Edge& aE1=TopoDS::Edge(aLE.First());
00207       if (aNbE==1) {
00208         if (BRep_Tool::Degenerated(aE1)) {
00209           continue;
00210         }
00211         if (aV.Orientation()==TopAbs_INTERNAL) {
00212           continue;
00213         }
00214         bFound=Standard_True;
00215         myShapesToAvoid.Add(aE1);
00216       }
00217       else if (aNbE==2) {
00218         const TopoDS_Edge& aE2=TopoDS::Edge(aLE.Last());
00219         if (aE2.IsSame(aE1)) {
00220           TopoDS_Vertex aV1x, aV2x;
00221           //
00222           TopExp::Vertices(aE1, aV1x, aV2x);
00223           if (aV1x.IsSame(aV2x)) {
00224             continue;
00225           }
00226           bFound=Standard_True;
00227           myShapesToAvoid.Add(aE1);
00228           myShapesToAvoid.Add(aE2);
00229         }
00230       }
00231     }// for (i=1; i<=aNbE; ++i) {
00232     //
00233     if (!bFound) {
00234       break;
00235     }
00236     //
00237   }//while (1)
00238   //printf(" EdgesToAvoid=%d, iCnt=%d\n", EdgesToAvoid.Extent(), iCnt);
00239 }
00240 //=======================================================================
00241 //function : PerformLoops
00242 //purpose  :
00243 //=======================================================================
00244   void GEOMAlgo_BuilderFace::PerformLoops()
00245 {
00246   myErrorStatus=0;
00247   //
00248   Standard_Boolean bFlag;
00249   Standard_Integer aNbEA;
00250   TopTools_ListIteratorOfListOfShape aIt;
00251   TopTools_MapIteratorOfMapOfOrientedShape aItM;
00252   TopTools_IndexedDataMapOfShapeListOfShape aVEMap;
00253   TopTools_MapOfOrientedShape aMAdded;
00254   TopoDS_Iterator aItW;
00255   BRep_Builder aBB;
00256   GEOMAlgo_WireEdgeSet aWES;
00257   GEOMAlgo_WESCorrector aWESCor;
00258   //
00259   // 1. Usual Wires
00260   myLoops.Clear();
00261   aWES.SetFace(myFace);
00262   //
00263   aIt.Initialize (myShapes);
00264   for (; aIt.More(); aIt.Next()) {
00265     const TopoDS_Shape& aE=aIt.Value();
00266     if (!myShapesToAvoid.Contains(aE)) {
00267       aWES.AddStartElement(aE);
00268     }
00269   }
00270   //
00271   aWESCor.SetWES(aWES);
00272   aWESCor.Perform();
00273   //
00274   GEOMAlgo_WireEdgeSet& aWESN=aWESCor.NewWES();
00275   const TopTools_ListOfShape& aLW=aWESN.Shapes();
00276   //
00277   aIt.Initialize (aLW);
00278   for (; aIt.More(); aIt.Next()) {
00279     const TopoDS_Shape& aW=aIt.Value();
00280     myLoops.Append(aW);
00281   }
00282   //modified by NIZNHY-PKV Tue Aug  5 15:09:29 2008f
00283   // Post Treatment
00284   TopTools_MapOfOrientedShape aMEP;
00285   //
00286   // a. collect all edges that are in loops
00287   aIt.Initialize (myLoops);
00288   for (; aIt.More(); aIt.Next()) {
00289     const TopoDS_Shape& aW=aIt.Value();
00290     aItW.Initialize(aW);
00291     for (; aItW.More(); aItW.Next()) {
00292       const TopoDS_Shape& aE=aItW.Value();
00293       aMEP.Add(aE);
00294     }
00295   }
00296   //
00297   // b. collect all edges that are to avoid
00298   aItM.Initialize(myShapesToAvoid);
00299   for (; aItM.More(); aItM.Next()) {
00300     const TopoDS_Shape& aE=aItM.Key();
00301     aMEP.Add(aE);
00302   }
00303   //
00304   // c. add all edges that are not processed to myShapesToAvoid
00305   aIt.Initialize (myShapes);
00306   for (; aIt.More(); aIt.Next()) {
00307     const TopoDS_Shape& aE=aIt.Value();
00308     if (!aMEP.Contains(aE)) {
00309       myShapesToAvoid.Add(aE);
00310     }
00311   }
00312   //modified by NIZNHY-PKV Tue Aug  5 15:09:35 2008t
00313   //
00314   // 2. Internal Wires
00315   myLoopsInternal.Clear();
00316   //
00317   aNbEA=myShapesToAvoid.Extent();
00318   aItM.Initialize(myShapesToAvoid);
00319   for (; aItM.More(); aItM.Next()) {
00320     const TopoDS_Shape& aEE=aItM.Key();
00321     TopExp::MapShapesAndAncestors(aEE, TopAbs_VERTEX, TopAbs_EDGE, aVEMap);
00322   }
00323   //
00324   bFlag=Standard_True;
00325   aItM.Initialize(myShapesToAvoid);
00326   for (; aItM.More()&&bFlag; aItM.Next()) {
00327     const TopoDS_Shape& aEE=aItM.Key();
00328     if (!aMAdded.Add(aEE)) {
00329       continue;
00330     }
00331     //
00332     // make new wire
00333     TopoDS_Wire aW;
00334     aBB.MakeWire(aW);
00335     aBB.Add(aW, aEE);
00336     //
00337     aItW.Initialize(aW);
00338     for (; aItW.More()&&bFlag; aItW.Next()) {
00339       const TopoDS_Edge& aE=TopoDS::Edge(aItW.Value());
00340       //
00341       TopoDS_Iterator aItE(aE);
00342       for (; aItE.More()&&bFlag; aItE.Next()) {
00343         const TopoDS_Vertex& aV = TopoDS::Vertex(aItE.Value());
00344         const TopTools_ListOfShape& aLE=aVEMap.FindFromKey(aV);
00345         aIt.Initialize(aLE);
00346         for (; aIt.More()&&bFlag; aIt.Next()) {
00347           const TopoDS_Shape& aEx=aIt.Value();
00348           if (aMAdded.Add(aEx)) {
00349             aBB.Add(aW, aEx);
00350             if(aMAdded.Extent()==aNbEA) {
00351               bFlag=!bFlag;
00352             }
00353           }
00354         }//for (; aIt.More(); aIt.Next()) {
00355       }//for (; aItE.More(); aItE.Next()) {
00356     }//for (; aItW.More(); aItW.Next()) {
00357     myLoopsInternal.Append(aW);
00358   }//for (; aItM.More(); aItM.Next()) {
00359 }
00360 //=======================================================================
00361 //function : PerformAreas
00362 //purpose  :
00363 //=======================================================================
00364   void GEOMAlgo_BuilderFace::PerformAreas()
00365 {
00366   myErrorStatus=0;
00367   //
00368   Standard_Boolean bIsGrowth, bIsHole;
00369   Standard_Real aTol;
00370   TopTools_ListOfShape aNewFaces, aHoleWires;
00371   TopoDS_Shape anInfinitePointShape;
00372   TopTools_DataMapOfShapeShape aInOutMap;
00373   TopTools_DataMapOfShapeListOfShape aMSH;
00374   TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItMSH;
00375   TopTools_ListIteratorOfListOfShape aIt1, aIt2;
00376   TopTools_IndexedMapOfShape aMHE;
00377   BRep_Builder aBB;
00378   Handle(Geom_Surface) aS;
00379   TopLoc_Location aLoc;
00380   //
00381   aTol=BRep_Tool::Tolerance(myFace);
00382   aS=BRep_Tool::Surface(myFace, aLoc);
00383   //
00384   myAreas.Clear();
00385   //
00386   //  Draft faces [aNewFaces]
00387   aIt1.Initialize(myLoops);
00388   for ( ; aIt1.More(); aIt1.Next()) {
00389     const TopoDS_Shape& aWire=aIt1.Value();
00390     //
00391     bIsGrowth=IsGrowthWire(aWire, aMHE);
00392     if (bIsGrowth) {
00393       // make a growth face from a wire
00394       TopoDS_Face aFace;
00395       aBB.MakeFace(aFace, aS, aLoc, aTol);
00396       aBB.Add (aFace, aWire);
00397       //
00398       aNewFaces.Append (aFace);
00399     }
00400     else{
00401       // check if a wire is a hole
00402       //XX
00403       //bIsHole=IsHole(aWire, myFace, myContext);
00404       bIsHole=GEOMAlgo_BuilderTools::IsHole(aWire, myFace);
00405       //XX
00406       if (bIsHole) {
00407         aHoleWires.Append(aWire);
00408         TopExp::MapShapes(aWire, TopAbs_EDGE, aMHE);
00409       }
00410       else {
00411         // make a growth face from a wire
00412         TopoDS_Face aFace;
00413         aBB.MakeFace(aFace, aS, aLoc, aTol);
00414         aBB.Add (aFace, aWire);
00415         //
00416         aNewFaces.Append (aFace);
00417       }
00418     }
00419   }
00420   //
00421   // 2. Find outer growth shell that is most close to each hole shell
00422   aIt2.Initialize(aHoleWires);
00423   for (; aIt2.More(); aIt2.Next()) {
00424     const TopoDS_Shape& aHole = aIt2.Value();
00425     //
00426     aIt1.Initialize(aNewFaces);
00427     for ( ; aIt1.More(); aIt1.Next()) {
00428       const TopoDS_Shape& aF=aIt1.Value();
00429       //
00430       if (!IsInside(aHole, aF, myContext)){
00431         continue;
00432       }
00433       //
00434       if ( aInOutMap.IsBound (aHole)){
00435         const TopoDS_Shape& aF2=aInOutMap(aHole);
00436         if (IsInside(aF, aF2, myContext)) {
00437           aInOutMap.UnBind(aHole);
00438           aInOutMap.Bind (aHole, aF);
00439         }
00440       }
00441       else{
00442         aInOutMap.Bind (aHole, aF);
00443       }
00444     }
00445     //
00446     // Add aHole to a map Face/ListOfHoles [aMSH]
00447     if (aInOutMap.IsBound(aHole)){
00448       const TopoDS_Shape& aF=aInOutMap(aHole);
00449       if (aMSH.IsBound(aF)) {
00450         TopTools_ListOfShape& aLH=aMSH.ChangeFind(aF);
00451         aLH.Append(aHole);
00452       }
00453       else {
00454         TopTools_ListOfShape aLH;
00455         aLH.Append(aHole);
00456         aMSH.Bind(aF, aLH);
00457       }
00458     }
00459   }// for (; aIt2.More(); aIt2.Next())
00460   //
00461   // 3. Add aHoles to Faces
00462   aItMSH.Initialize(aMSH);
00463   for (; aItMSH.More(); aItMSH.Next()) {
00464     TopoDS_Face aF=TopoDS::Face(aItMSH.Key());
00465     //
00466     const TopTools_ListOfShape& aLH=aItMSH.Value();
00467     aIt2.Initialize(aLH);
00468     for (; aIt2.More(); aIt2.Next()) {
00469       const TopoDS_Shape& aHole = aIt2.Value();
00470       aBB.Add (aF, aHole);
00471     }
00472     //
00473     // update classifier
00474     aTol=BRep_Tool::Tolerance(aF);
00475     IntTools_FClass2d& aClsf=myContext->FClass2d(aF);
00476     aClsf.Init(aF, aTol);
00477   }
00478   //
00479   // These aNewFaces are draft faces that
00480   // do not contain any internal shapes
00481   //
00482   myAreas.Append(aNewFaces);
00483 }
00484 //=======================================================================
00485 //function : PerformInternalShapes
00486 //purpose  :
00487 //=======================================================================
00488   void GEOMAlgo_BuilderFace::PerformInternalShapes()
00489 {
00490   myErrorStatus=0;
00491   //
00492   Standard_Integer aNbWI=myLoopsInternal.Extent();
00493   if (!aNbWI) {// nothing to do
00494     return;
00495   }
00496   //
00497   //Standard_Real aTol;
00498   BRep_Builder aBB;
00499   TopTools_ListIteratorOfListOfShape aIt1, aIt2;
00500   TopoDS_Iterator aIt;
00501   TopTools_MapOfShape aME, aMEP;
00502   TopTools_MapIteratorOfMapOfShape aItME;
00503   TopTools_IndexedDataMapOfShapeListOfShape aMVE;
00504   TopTools_ListOfShape aLSI;
00505   //
00506   // 1. All internal edges
00507   aIt1.Initialize(myLoopsInternal);
00508   for (; aIt1.More(); aIt1.Next()) {
00509     const TopoDS_Shape& aWire=aIt1.Value();
00510     aIt.Initialize(aWire);
00511     for (; aIt.More(); aIt.Next()) {
00512       const TopoDS_Shape& aE=aIt.Value();
00513       aME.Add(aE);
00514     }
00515   }
00516   aNbWI=aME.Extent();
00517   //
00518   // 2 Process faces
00519   aIt2.Initialize(myAreas);
00520   for ( ; aIt2.More(); aIt2.Next()) {
00521     TopoDS_Face& aF=TopoDS::Face(aIt2.Value());
00522     //
00523     aMVE.Clear();
00524     TopExp::MapShapesAndAncestors(aF, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
00525     //
00526     // 2.1 Separate faces to process aMEP
00527     aMEP.Clear();
00528     aItME.Initialize(aME);
00529     for (; aItME.More(); aItME.Next()) {
00530       const TopoDS_Edge& aE=TopoDS::Edge(aItME.Key());
00531       if (IsInside(aE, aF, myContext)) {
00532         aMEP.Add(aE);
00533       }
00534     }
00535     //
00536     // 2.2 Make Internal Wires
00537     aLSI.Clear();
00538     MakeInternalWires(aMEP, aLSI);
00539     //
00540     // 2.3 Add them to aF
00541     aIt1.Initialize(aLSI);
00542     for (; aIt1.More(); aIt1.Next()) {
00543       const TopoDS_Shape& aSI=aIt1.Value();
00544       aBB.Add (aF, aSI);
00545     }
00546     //
00547     // 2.4 Remove faces aMFP from aMF
00548     aItME.Initialize(aMEP);
00549     for (; aItME.More(); aItME.Next()) {
00550       const TopoDS_Shape& aE=aItME.Key();
00551       aME.Remove(aE);
00552     }
00553     //
00554     aNbWI=aME.Extent();
00555     if (!aNbWI) {
00556       break;
00557     }
00558   } //for ( ; aIt2.More(); aIt2.Next()) {
00559 }
00560 //=======================================================================
00561 //function : MakeInternalWires
00562 //purpose  :
00563 //=======================================================================
00564 void MakeInternalWires(const TopTools_MapOfShape& theME,
00565                        TopTools_ListOfShape& theWires)
00566 {
00567   TopTools_MapIteratorOfMapOfShape aItM;
00568   TopTools_MapOfShape aAddedMap;
00569   TopTools_ListIteratorOfListOfShape aItE;
00570   TopTools_IndexedDataMapOfShapeListOfShape aMVE;
00571   BRep_Builder aBB;
00572   //
00573   aItM.Initialize(theME);
00574   for (; aItM.More(); aItM.Next()) {
00575     const TopoDS_Shape& aE=aItM.Key();
00576     TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
00577   }
00578   //
00579   aItM.Initialize(theME);
00580   for (; aItM.More(); aItM.Next()) {
00581     TopoDS_Shape aEE=aItM.Key();
00582     if (!aAddedMap.Add(aEE)) {
00583       continue;
00584     }
00585     //
00586     // make a new shell
00587     TopoDS_Wire aW;
00588     aBB.MakeWire(aW);
00589     aEE.Orientation(TopAbs_INTERNAL);
00590     aBB.Add(aW, aEE);
00591     //
00592     TopoDS_Iterator aItAdded (aW);
00593     for (; aItAdded.More(); aItAdded.Next()) {
00594       const TopoDS_Shape& aE =aItAdded.Value();
00595       //
00596       TopExp_Explorer aExp(aE, TopAbs_VERTEX);
00597       for (; aExp.More(); aExp.Next()) {
00598         const TopoDS_Shape& aV =aExp.Current();
00599         const TopTools_ListOfShape& aLE=aMVE.FindFromKey(aV);
00600         aItE.Initialize(aLE);
00601         for (; aItE.More(); aItE.Next()) {
00602           TopoDS_Shape aEL=aItE.Value();
00603           if (aAddedMap.Add(aEL)){
00604             aEL.Orientation(TopAbs_INTERNAL);
00605             aBB.Add(aW, aEL);
00606           }
00607         }
00608       }
00609     }
00610     theWires.Append(aW);
00611   }
00612 }
00613 //=======================================================================
00614 //function : IsInside
00615 //purpose  :
00616 //=======================================================================
00617 Standard_Boolean IsInside(const TopoDS_Shape& theHole,
00618                           const TopoDS_Shape& theF2,
00619                           const Handle(IntTools_Context)& theContext)
00620 {
00621   Standard_Boolean bRet;
00622   Standard_Real aT, aU, aV;
00623 
00624   TopAbs_State aState;
00625   TopExp_Explorer aExp;
00626   TopTools_IndexedMapOfShape aME2;
00627   gp_Pnt2d aP2D;
00628   //
00629   bRet=Standard_False;
00630   aState=TopAbs_UNKNOWN;
00631   const TopoDS_Face& aF2=TopoDS::Face(theF2);
00632   //
00633   TopExp::MapShapes(aF2, TopAbs_EDGE, aME2);
00634   //
00635   aExp.Init(theHole, TopAbs_EDGE);
00636   if (aExp.More()) {
00637     const TopoDS_Edge& aE = TopoDS::Edge(aExp.Current());
00638     if (aME2.Contains(aE)) {
00639       return bRet;
00640     }
00641     //
00642     aT=BOPTools_Tools2D::IntermediatePoint(aE);
00643     BOPTools_Tools2D::PointOnSurface(aE, aF2, aT, aU, aV);
00644     aP2D.SetCoord(aU, aV);
00645     //
00646     IntTools_FClass2d& aClsf=theContext->FClass2d(aF2);
00647     aState=aClsf.Perform(aP2D);
00648     bRet=(aState==TopAbs_IN);
00649   }
00650   //
00651   return bRet;
00652 }
00653 
00654 //=======================================================================
00655 //function : IsGrowthWire
00656 //purpose  :
00657 //=======================================================================
00658 Standard_Boolean IsGrowthWire(const TopoDS_Shape& theWire,
00659                               const TopTools_IndexedMapOfShape& theMHE)
00660 {
00661   Standard_Boolean bRet;
00662   TopoDS_Iterator aIt;
00663   //
00664   bRet=Standard_False;
00665   if (theMHE.Extent()) {
00666     aIt.Initialize(theWire);
00667     for(; aIt.More(); aIt.Next()) {
00668       const TopoDS_Shape& aE=aIt.Value();
00669       if (theMHE.Contains(aE)) {
00670         return !bRet;
00671       }
00672     }
00673   }
00674   return bRet;
00675 }
00676 
00677 //BRepTools::Write(aFF, "ff");
00678 //
00679 //  ErrorStatus :
00680 // 11 - Null Context
00681 // 12 - Null face generix
00682 
00683 /*
00684 //=======================================================================
00685 //function : IsInside
00686 //purpose  :
00687 //=======================================================================
00688 Standard_Boolean IsInside(const TopoDS_Shape& theHole,
00689                           const TopoDS_Shape& theF2,
00690                           IntTools_PContext& theContext)
00691 {
00692   Standard_Real aT, aU, aV;
00693   TopExp_Explorer aExp;
00694   TopAbs_State aState=TopAbs_UNKNOWN;
00695   gp_Pnt2d aP2D;
00696   //
00697   const TopoDS_Face& aF2=TopoDS::Face(theF2);
00698   //
00699   aExp.Init(theHole, TopAbs_EDGE);
00700   if (aExp.More()){
00701     const TopoDS_Edge& aE = TopoDS::Edge(aExp.Current());
00702     aT=BOPTools_Tools2D::IntermediatePoint(aE);
00703     BOPTools_Tools2D::PointOnSurface(aE, aF2, aT, aU, aV);
00704     aP2D.SetCoord(aU, aV);
00705     //
00706     IntTools_FClass2d& aClsf=theContext->FClass2d(aF2);
00707     aState=aClsf.Perform(aP2D);
00708   }
00709   return (aState==TopAbs_IN);
00710 }
00711 */