Back to index

salome-geom  6.5.0
GEOMAlgo_VertexSolid.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_VertexSolid.cxx
00024 // Created:     Wed Jan 12 16:36:40 2005
00025 // Author:      Peter KURNEV
00026 //              <pkv@irinox>
00027 //
00028 #include <GEOMAlgo_VertexSolid.hxx>
00029 
00030 #include <gp_Pnt.hxx>
00031 
00032 #include <TopAbs_ShapeEnum.hxx>
00033 #include <TopAbs_State.hxx>
00034 
00035 #include <TopTools_ListIteratorOfListOfShape.hxx>
00036 #include <TopTools_ListOfShape.hxx>
00037 #include <TopTools_IndexedMapOfShape.hxx>
00038 
00039 #include <TopoDS.hxx>
00040 #include <TopoDS_Solid.hxx>
00041 #include <TopoDS_Vertex.hxx>
00042 
00043 #include <TopExp.hxx>
00044 
00045 #include <BRep_Tool.hxx>
00046 #include <BRepClass3d_SolidClassifier.hxx>
00047 
00048 #include <BOPTColStd_Dump.hxx>
00049 
00050 #include <IntTools_Context.hxx>
00051 
00052 #include <BooleanOperations_StateOfShape.hxx>
00053 #include <BooleanOperations_ShapesDataStructure.hxx>
00054 
00055 #include <BOPTools_InterferencePool.hxx>
00056 #include <BOPTools_CArray1OfVVInterference.hxx>
00057 #include <BOPTools_VVInterference.hxx>
00058 #include <BOPTools_PaveFiller.hxx>
00059 #include <BOPTools_DSFiller.hxx>
00060 
00061 //=======================================================================
00062 //function : GEOMAlgo_VertexSolid
00063 //purpose  :
00064 //=======================================================================
00065 GEOMAlgo_VertexSolid::GEOMAlgo_VertexSolid()
00066 :
00067   GEOMAlgo_ShapeSolid()
00068 {
00069 }
00070 //=======================================================================
00071 //function : ~
00072 //purpose  :
00073 //=======================================================================
00074 GEOMAlgo_VertexSolid::~GEOMAlgo_VertexSolid()
00075 {
00076 }
00077 //=======================================================================
00078 // function: Perform
00079 // purpose:
00080 //=======================================================================
00081 void GEOMAlgo_VertexSolid::Perform()
00082 {
00083   myErrorStatus=0;
00084   //
00085   try {
00086     if (myDSFiller==NULL) {
00087       myErrorStatus=10;
00088       return;
00089     }
00090     if(!myDSFiller->IsDone()) {
00091       myErrorStatus=11;
00092       return;
00093     }
00094     //
00095     Standard_Boolean bIsNewFiller;
00096     Standard_Integer aNbF;
00097     TopTools_IndexedMapOfShape aM;
00098     //
00099     const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
00100     const TopoDS_Shape& aObj=aDS.Object();
00101     //
00102     TopExp::MapShapes(aObj, TopAbs_FACE, aM);
00103     aNbF=aM.Extent();
00104     myRank=(aNbF) ? 2 : 1;
00105     //
00106     bIsNewFiller=myDSFiller->IsNewFiller();
00107 
00108     if (bIsNewFiller) {
00109       Prepare();
00110       myDSFiller->SetNewFiller(!bIsNewFiller);
00111     }
00112     BuildResult();
00113   }
00114   //
00115   catch (Standard_Failure) {
00116     myErrorStatus = 12;
00117   }
00118 }
00119 //=======================================================================
00120 // function: Prepare
00121 // purpose:
00122 //=======================================================================
00123 void GEOMAlgo_VertexSolid::Prepare()
00124 {
00125   Standard_Integer i, iBeg, iEnd, aNbVV, j, n1, n2, iFound;
00126   Standard_Real aTol;
00127   TopAbs_State aSt;
00128   TopAbs_ShapeEnum aType;
00129   BooleanOperations_StateOfShape aState;
00130   gp_Pnt aP3D;
00131   //
00132   const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
00133   BooleanOperations_ShapesDataStructure* pDS=(BooleanOperations_ShapesDataStructure*)&aDS;
00134   const BOPTools_InterferencePool& aIP=myDSFiller->InterfPool();
00135   BOPTools_InterferencePool* pIP=(BOPTools_InterferencePool*) &aIP;
00136   BOPTools_CArray1OfVVInterference& aVVs=pIP->VVInterferences();
00137   const BOPTools_PaveFiller& aPF=myDSFiller->PaveFiller();
00138   BOPTools_PaveFiller* pPF=(BOPTools_PaveFiller*)&aPF;
00139   const Handle(IntTools_Context)& aCtx=pPF->Context();
00140   //
00141   const TopoDS_Shape& aObj=aDS.Object();
00142   const TopoDS_Shape& aTool=aDS.Tool();
00143   //
00144   const TopoDS_Solid& aSolid=(myRank==1) ? TopoDS::Solid(aTool) : TopoDS::Solid(aObj);
00145   //
00146   BRepClass3d_SolidClassifier& aSC=aCtx->SolidClassifier(aSolid);
00147   //
00148   iBeg=1;
00149   iEnd=aDS.NumberOfShapesOfTheObject();
00150   if (myRank==2) {
00151     iBeg=iEnd+1;
00152     iEnd=aDS.NumberOfSourceShapes();
00153   }
00154   //
00155   for (i=iBeg; i<=iEnd; ++i) {
00156     aType=aDS.GetShapeType(i);
00157     if (aType!=TopAbs_VERTEX) {
00158       continue;
00159     }
00160     //
00161     const TopoDS_Vertex& aV=TopoDS::Vertex(aDS.Shape(i));
00162     //
00163     aState=aDS.GetState(i);
00164     if (aState==BooleanOperations_ON ||
00165         aState==BooleanOperations_IN ||
00166         aState==BooleanOperations_OUT) {
00167       continue;
00168     }
00169     //
00170     iFound=0;
00171     aNbVV=aVVs.Extent();
00172     for (j=1; j<=aNbVV; ++j) {
00173       BOPTools_VVInterference& aVV=aVVs(j);
00174       aVV.Indices(n1, n2);
00175       if (n1==i || n2==i) {
00176         pDS->SetState (n1, BooleanOperations_ON);
00177         pDS->SetState (n2, BooleanOperations_ON);
00178         iFound=1;
00179         break;
00180       }
00181     }
00182     if (iFound) {
00183       continue;
00184     }
00185     //
00186     aP3D=BRep_Tool::Pnt(aV);
00187     aTol=1.E-7;
00188     aSC.Perform(aP3D, aTol);
00189     aSt=aSC.State();
00190     if (aSt==TopAbs_IN) {
00191       pDS->SetState (i, BooleanOperations_IN);
00192     }
00193     else if (aSt==TopAbs_OUT) {
00194       pDS->SetState (i, BooleanOperations_OUT);
00195     }
00196   }
00197 }
00198 //=======================================================================
00199 // function: BuildResult
00200 // purpose:
00201 //=======================================================================
00202 void GEOMAlgo_VertexSolid::BuildResult()
00203 {
00204   const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
00205   //
00206   Standard_Integer i, iBeg, iEnd;
00207   TopAbs_ShapeEnum aType;
00208   BooleanOperations_StateOfShape aState;
00209   //
00210   myLSIN.Clear();
00211   myLSOUT.Clear();
00212   myLSON.Clear();
00213   //
00214   iBeg=1;
00215   iEnd=aDS.NumberOfShapesOfTheObject();
00216   if (myRank==2) {
00217     iBeg=iEnd+1;
00218     iEnd=aDS.NumberOfSourceShapes();
00219   }
00220   //
00221   for (i=iBeg; i<=iEnd; ++i) {
00222     aType=aDS.GetShapeType(i);
00223     if (aType!=TopAbs_VERTEX) {
00224       continue;
00225     }
00226     const TopoDS_Shape& aV=aDS.Shape(i);
00227     aState=aDS.GetState(i);
00228     //
00229     if (aState==BooleanOperations_IN) {
00230       myLSIN.Append(aV);
00231     }
00232     else if (aState==BooleanOperations_OUT) {
00233       myLSOUT.Append(aV);
00234     }
00235     else if (aState==BooleanOperations_ON) {
00236       myLSON.Append(aV);
00237     }
00238   }
00239 }