Back to index

salome-geom  6.5.0
GEOMAlgo_ShellSolid.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_ShellSolid.cxx
00024 // Created:     Wed Jan 12 12:49:45 2005
00025 // Author:      Peter KURNEV
00026 //              <pkv@irinox>
00027 //
00028 #include <GEOMAlgo_ShellSolid.hxx>
00029 
00030 #include <Standard_Failure.hxx>
00031 
00032 #include <gp_Pnt2d.hxx>
00033 #include <gp_Pnt.hxx>
00034 #include <gp_Dir.hxx>
00035 
00036 #include <TopoDS.hxx>
00037 #include <TopoDS_Face.hxx>
00038 #include <TopoDS_Edge.hxx>
00039 #include <TopoDS_Shape.hxx>
00040 #include <TopoDS_Solid.hxx>
00041 
00042 #include <BRep_Tool.hxx>
00043 #include <BRepTools.hxx>
00044 
00045 #include <TopTools_ListOfShape.hxx>
00046 #include <TopTools_ListIteratorOfListOfShape.hxx>
00047 #include <TopExp_Explorer.hxx>
00048 
00049 #include <BRepClass3d_SolidClassifier.hxx>
00050 
00051 #include <IntTools_Context.hxx>
00052 #include <BOPTColStd_Dump.hxx>
00053 #include <BooleanOperations_ShapesDataStructure.hxx>
00054 
00055 #include <BOPTools_PaveFiller.hxx>
00056 #include <BOPTools_SolidStateFiller.hxx>
00057 #include <BOPTools_PCurveMaker.hxx>
00058 #include <BOPTools_DEProcessor.hxx>
00059 #include <BOPTools_InterferencePool.hxx>
00060 #include <BOPTools_CArray1OfSSInterference.hxx>
00061 #include <BOPTools_ListOfPaveBlock.hxx>
00062 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
00063 #include <BOPTools_PaveBlock.hxx>
00064 #include <BOPTools_SSInterference.hxx>
00065 #include <BOPTools_SequenceOfCurves.hxx>
00066 #include <BOPTools_Curve.hxx>
00067 #include <BOPTools_PaveFiller.hxx>
00068 #include <BOPTools_SplitShapesPool.hxx>
00069 #include <BOPTools_Tools3D.hxx>
00070 #include <BOPTools_DSFiller.hxx>
00071 
00072 #include <BOP_WireEdgeSet.hxx>
00073 #include <BOP_SDFWESFiller.hxx>
00074 #include <BOP_FaceBuilder.hxx>
00075 
00076 //=======================================================================
00077 //function : GEOMAlgo_ShellSolid
00078 //purpose  :
00079 //=======================================================================
00080 GEOMAlgo_ShellSolid::GEOMAlgo_ShellSolid()
00081 :
00082   GEOMAlgo_ShapeSolid()
00083 {
00084 }
00085 //=======================================================================
00086 //function : ~
00087 //purpose  :
00088 //=======================================================================
00089 GEOMAlgo_ShellSolid::~GEOMAlgo_ShellSolid()
00090 {
00091 }
00092 //=======================================================================
00093 // function:
00094 // purpose:
00095 //=======================================================================
00096 void GEOMAlgo_ShellSolid::Perform()
00097 {
00098   myErrorStatus=0;
00099   //
00100   try {
00101     if (myDSFiller==NULL) {
00102       myErrorStatus=10;
00103       return;
00104     }
00105     if(!myDSFiller->IsDone()) {
00106       myErrorStatus=11;
00107       return;
00108     }
00109     //
00110     Standard_Boolean bIsNewFiller;
00111     //
00112     bIsNewFiller=myDSFiller->IsNewFiller();
00113     if (bIsNewFiller) {
00114       Prepare();
00115       myDSFiller->SetNewFiller(!bIsNewFiller);
00116     }
00117     //
00118     myRank=(myDSFiller->DS().Object().ShapeType()==TopAbs_SHELL) ? 1 : 2;
00119     BuildResult();
00120   }
00121   catch (Standard_Failure) {
00122     myErrorStatus=12;
00123   }
00124 }
00125 //=======================================================================
00126 // function: Prepare
00127 // purpose:
00128 //=======================================================================
00129 void GEOMAlgo_ShellSolid::Prepare()
00130 {
00131   const BOPTools_PaveFiller& aPaveFiller=myDSFiller->PaveFiller();
00132   //
00133   // 1 States
00134   BOPTools_SolidStateFiller aStateFiller(aPaveFiller);
00135   aStateFiller.Do();
00136   //
00137   // 2 Project section edges on corresp. faces -> P-Curves on edges.
00138   BOPTools_PCurveMaker aPCurveMaker(aPaveFiller);
00139   aPCurveMaker.Do();
00140   //
00141   // 3. Degenerated Edges Processing
00142   BOPTools_DEProcessor aDEProcessor(aPaveFiller);
00143   aDEProcessor.Do();
00144   //
00145   // 4. Detect Same Domain Faces
00146   DetectSDFaces();
00147 }
00148 //=================================================================================
00149 // function: BuildResult
00150 // purpose:
00151 //=================================================================================
00152 void GEOMAlgo_ShellSolid::BuildResult()
00153 {
00154   Standard_Boolean bIsTouchCase;
00155   Standard_Integer i, j, nF1, nF2, aNbFFs, aNbS, aNbCurves, nSp, iRank1;
00156   Standard_Integer nE, nF, aNbPB, iBeg, iEnd;
00157   BooleanOperations_StateOfShape aState;
00158   TopExp_Explorer anExp;
00159   TopAbs_ShapeEnum aType;
00160   gp_Pnt2d aP2D;
00161   gp_Pnt aP3D;
00162   //
00163   const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
00164   const BOPTools_InterferencePool& anInterfPool=myDSFiller->InterfPool();
00165   BOPTools_InterferencePool* pInterfPool=(BOPTools_InterferencePool*) &anInterfPool;
00166   BOPTools_CArray1OfSSInterference& aFFs=pInterfPool->SSInterferences();
00167   const BOPTools_PaveFiller& aPaveFiller=myDSFiller->PaveFiller();
00168   const BOPTools_SplitShapesPool& aSplitShapesPool=aPaveFiller.SplitShapesPool();
00169   //
00170   // 1. process pf non-interferring faces
00171   iBeg=1;
00172   iEnd=aDS.NumberOfShapesOfTheObject();
00173   if (myRank==2) {
00174     iBeg=iEnd+1;
00175     iEnd=aDS.NumberOfSourceShapes();
00176   }
00177   //
00178   for (i=iBeg; i<=iEnd; ++i) {
00179     aType=aDS.GetShapeType(i);
00180     if (aType!=TopAbs_FACE) {
00181       continue;
00182     }
00183     //
00184     const TopoDS_Face& aF1=TopoDS::Face(aDS.Shape(i));
00185     aState=aDS.GetState(i);
00186     if (aState==BooleanOperations_IN) {
00187       myLSIN.Append(aF1);
00188     }
00189     else if (aState==BooleanOperations_OUT) {
00190       myLSOUT.Append(aF1);
00191     }
00192   }
00193   //
00194   // 2. process pf interferred faces
00195   aNbFFs=aFFs.Extent();
00196   for (i=1; i<=aNbFFs; ++i) {
00197     BOPTools_SSInterference& aFFi=aFFs(i);
00198     //
00199     nF1=aFFi.Index1();
00200     nF2=aFFi.Index2();
00201     iRank1=aDS.Rank(nF1);
00202     nF=(iRank1==myRank) ? nF1 : nF2;
00203     const TopoDS_Face& aF1=TopoDS::Face(aDS.Shape(nF));
00204     //
00205     bIsTouchCase=aFFi.IsTangentFaces();
00206     //
00207     if (bIsTouchCase) {
00208       myLSON.Append(aF1);
00209       continue;
00210     }
00211     //
00212     // Has section edges ?
00213     aNbS=0;
00214     BOPTools_SequenceOfCurves& aBCurves=aFFi.Curves();
00215     aNbCurves=aBCurves.Length();
00216     for (j=1; j<=aNbCurves; j++) {
00217       BOPTools_Curve& aBC=aBCurves(j);
00218       const BOPTools_ListOfPaveBlock& aSectEdges=aBC.NewPaveBlocks();
00219       aNbS=aSectEdges.Extent();
00220       if (aNbS) {
00221         break;
00222       }
00223     }
00224     //
00225     if (aNbS) { // it has
00226       continue;
00227     }
00228     //
00229     anExp.Init(aF1, TopAbs_EDGE);
00230     for (; anExp.More(); anExp.Next()) {
00231       const TopoDS_Edge& aE=TopoDS::Edge(anExp.Current());
00232       if (BRep_Tool::Degenerated(aE)) {
00233         continue;
00234       }
00235       //
00236       nE=aDS.ShapeIndex(aE, myRank);
00237       const BOPTools_ListOfPaveBlock& aLPB=aSplitShapesPool(aDS.RefEdge(nE));
00238       aNbPB=aLPB.Extent();
00239       //
00240       if (aNbPB<2) {
00241         nSp=nE;
00242         if (aNbPB) {
00243           const BOPTools_PaveBlock& aPB=aLPB.First();
00244           nSp=aPB.Edge();
00245         }
00246         /*const TopoDS_Shape& aSp=*/aDS.Shape(nSp);
00247         //
00248         aState=aDS.GetState(nSp);
00249         if (aState==BooleanOperations_IN) {
00250           myLSIN.Append(aF1);
00251         }
00252         else if (aState==BooleanOperations_OUT) {
00253           myLSOUT.Append(aF1);
00254         }
00255         else if (aState==BooleanOperations_ON) {
00256           Standard_Real aTol;
00257           TopAbs_State aSt;
00258           //
00259           //const TopoDS_Face& aF2=TopoDS::Face(aDS.Shape((iRank1==myRank)? nF2 : nF1));
00260           //aTol=BRep_Tool::Tolerance(aF2);
00261           aTol=1.e-7;
00262           //
00263           BOPTools_Tools3D::PointNearEdge(aE, aF1, aP2D, aP3D);
00264           const TopoDS_Solid& aRefSolid=(myRank==1) ?
00265             TopoDS::Solid(aDS.Tool()) : TopoDS::Solid(aDS.Object());
00266           //
00267           BOPTools_PaveFiller* pPF=(BOPTools_PaveFiller*)& aPaveFiller;
00268           const Handle(IntTools_Context)& aCtx=pPF->Context();
00269           //
00270           BRepClass3d_SolidClassifier& aSC=aCtx->SolidClassifier(aRefSolid);
00271           aSC.Perform(aP3D, aTol);
00272           aSt=aSC.State();
00273           if (aSt==TopAbs_IN) {
00274             myLSIN.Append(aF1);
00275           }
00276           else if (aSt==TopAbs_OUT) {
00277             myLSOUT.Append(aF1);
00278           }
00279         }
00280         break;
00281       } // if (aNbPB<2) {
00282     } //for (; anExp.More(); anExp.Next())
00283   }
00284 }
00285 //=======================================================================
00286 // function: DetectSDFaces
00287 // purpose:
00288 //=======================================================================
00289 void GEOMAlgo_ShellSolid::DetectSDFaces()
00290 {
00291   const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
00292   BOPTools_InterferencePool* pIntrPool=(BOPTools_InterferencePool*)&myDSFiller->InterfPool();
00293   BOPTools_CArray1OfSSInterference& aFFs=pIntrPool->SSInterferences();
00294   //
00295   Standard_Boolean bFlag;
00296   Standard_Integer i, aNb, nF1, nF2,  iZone, aNbSps, iSenseFlag;
00297   gp_Dir aDNF1, aDNF2;
00298 
00299   aNb=aFFs.Extent();
00300   for (i=1; i<=aNb; i++) {
00301     bFlag=Standard_False;
00302 
00303     BOPTools_SSInterference& aFF=aFFs(i);
00304 
00305     nF1=aFF.Index1();
00306     nF2=aFF.Index2();
00307     const TopoDS_Face& aF1=TopoDS::Face(aDS.Shape(nF1));
00308     const TopoDS_Face& aF2=TopoDS::Face(aDS.Shape(nF2));
00309     //
00310     // iSenseFlag;
00311     const BOPTools_ListOfPaveBlock& aLPB=aFF.PaveBlocks();
00312     aNbSps=aLPB.Extent();
00313 
00314     if (!aNbSps) {
00315       continue;
00316     }
00317 
00318     const BOPTools_PaveBlock& aPB=aLPB.First();
00319     const TopoDS_Edge& aSpE=TopoDS::Edge(aDS.Shape(aPB.Edge()));
00320 
00321     BOPTools_Tools3D::GetNormalToFaceOnEdge (aSpE, aF1, aDNF1);
00322     BOPTools_Tools3D::GetNormalToFaceOnEdge (aSpE, aF2, aDNF2);
00323     iSenseFlag=BOPTools_Tools3D::SenseFlag (aDNF1, aDNF2);
00324     //
00325     if (iSenseFlag==1 || iSenseFlag==-1) {
00326     //
00327     //
00328       TopoDS_Face aF1FWD=aF1;
00329       aF1FWD.Orientation (TopAbs_FORWARD);
00330 
00331       BOP_WireEdgeSet aWES (aF1FWD);
00332       BOP_SDFWESFiller aWESFiller(nF1, nF2, *myDSFiller);
00333       aWESFiller.SetSenseFlag(iSenseFlag);
00334       aWESFiller.SetOperation(BOP_COMMON);
00335       aWESFiller.Do(aWES);
00336 
00337       BOP_FaceBuilder aFB;
00338       aFB.Do(aWES);
00339       const TopTools_ListOfShape& aLF=aFB.NewFaces();
00340 
00341       iZone=0;
00342       TopTools_ListIteratorOfListOfShape anIt(aLF);
00343       for (; anIt.More(); anIt.Next()) {
00344         const TopoDS_Shape& aFR=anIt.Value();
00345 
00346         if (aFR.ShapeType()==TopAbs_FACE) {
00347           const TopoDS_Face& aFaceResult=TopoDS::Face(aFR);
00348           //
00349           Standard_Boolean bIsValidIn2D, bNegativeFlag;
00350           bIsValidIn2D=BOPTools_Tools3D::IsValidArea (aFaceResult, bNegativeFlag);
00351           if (bIsValidIn2D) {
00352             //if(CheckSameDomainFaceInside(aFaceResult, aF2)) {
00353             iZone=1;
00354             break;
00355             //}
00356           }
00357           //
00358         }
00359       }
00360 
00361       if (iZone) {
00362         bFlag=Standard_True;
00363         aFF.SetStatesMap(aWESFiller.StatesMap());
00364       }
00365 
00366     }// if (iSenseFlag)
00367 
00368   aFF.SetTangentFacesFlag(bFlag);
00369   aFF.SetSenseFlag (iSenseFlag);
00370   }// end of for (i=1; i<=aNb; i++)
00371 }