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_RemoverWebs.cxx
23 // Created: Thu Mar 28 07:40:32 2013
24 // Author: Peter KURNEV
27 #include <GEOMAlgo_RemoverWebs.hxx>
29 #include <TopoDS_Iterator.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Solid.hxx>
32 #include <BRep_Builder.hxx>
34 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
35 #include <TopTools_IndexedMapOfShape.hxx>
36 #include <TopTools_ListIteratorOfListOfShape.hxx>
37 #include <TopTools_ListOfShape.hxx>
41 #include <BRepClass3d_SolidClassifier.hxx>
43 #include <IntTools_Context.hxx>
45 #include <GEOMAlgo_ShapeAlgo.hxx>
46 #include <GEOMAlgo_BuilderSolid.hxx>
47 #include <GEOMAlgo_Tools3D.hxx>
50 //=======================================================================
53 //=======================================================================
54 GEOMAlgo_RemoverWebs::GEOMAlgo_RemoverWebs()
59 //=======================================================================
62 //=======================================================================
63 GEOMAlgo_RemoverWebs::~GEOMAlgo_RemoverWebs()
66 //=======================================================================
67 //function : CheckData
69 //=======================================================================
70 void GEOMAlgo_RemoverWebs::CheckData()
76 if (myShape.IsNull()) {
81 aIt.Initialize(myShape);
82 for (; aIt.More(); aIt.Next()) {
83 const TopoDS_Shape& aS=aIt.Value();
84 if (aS.ShapeType()!=TopAbs_SOLID) {
90 //=======================================================================
93 //=======================================================================
94 void GEOMAlgo_RemoverWebs::Perform()
106 if (!myContext.IsNull()) {
109 myContext=new IntTools_Context;
115 //=======================================================================
116 //function : BuildSolid
118 //=======================================================================
119 void GEOMAlgo_RemoverWebs::BuildSolid()
121 Standard_Integer i, aNbF, aNbSx, iErr, aNbSI, aNbF2;
122 TopAbs_Orientation aOr;
123 TopoDS_Iterator aIt1, aIt2;
125 TopTools_IndexedMapOfShape aMSI;
126 TopTools_IndexedDataMapOfShapeListOfShape aMFS;
127 TopTools_ListOfShape aSFS;
128 TopTools_ListIteratorOfListOfShape aItLS;
129 GEOMAlgo_BuilderSolid aSB;
134 TopExp::MapShapesAndAncestors(myShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
137 for (i=1; i<=aNbF; ++i) {
138 const TopoDS_Shape& aFx=aMFS.FindKey(i);
139 aOr=aFx.Orientation();
140 if (aOr==TopAbs_INTERNAL) {
144 aFi.Orientation(TopAbs_FORWARD);
146 aFi.Orientation(TopAbs_REVERSED);
150 const TopTools_ListOfShape& aLSx=aMFS(i);
161 if (!aNbF2) { // nothing to do here
166 // 2 Internal shapes: edges, vertices
167 aIt1.Initialize(myShape);
168 for (; aIt1.More(); aIt1.Next()) {
169 const TopoDS_Shape& aSD=aIt1.Value();
171 aIt2.Initialize(aSD);
172 for (; aIt2.More(); aIt2.Next()) {
173 const TopoDS_Shape& aSi=aIt2.Value();
174 if (aSi.ShapeType()!=TopAbs_SHELL) {
175 aOr=aSi.Orientation();
176 if (aOr==TopAbs_INTERNAL) {
184 // 3 Solids without internals
185 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, myResult);
187 aSB.SetContext(myContext);
190 iErr=aSB.ErrorStatus();
192 myErrorStatus=20; // SolidBuilder failed
196 const TopTools_ListOfShape& aLSR=aSB.Areas();
198 // 4 Add the internals
200 AddInternalShapes(aLSR, aMSI);
203 aItLS.Initialize(aLSR);
204 for (; aItLS.More(); aItLS.Next()) {
205 const TopoDS_Shape& aSR=aItLS.Value();
206 aBB.Add(myResult, aSR);
210 //=======================================================================
211 //function : AddInternalShapes
213 //=======================================================================
214 void GEOMAlgo_RemoverWebs::AddInternalShapes(const TopTools_ListOfShape& aLSR,
215 const TopTools_IndexedMapOfShape& aMSI)
217 Standard_Integer i, aNbSI;
221 TopTools_ListIteratorOfListOfShape aItLS;
222 Handle(IntTools_Context) aCtx;
224 aCtx=new IntTools_Context;
227 for (i=1; i<=aNbSI; ++i) {
228 const TopoDS_Shape& aSI=aMSI(i);
230 aItLS.Initialize(aLSR);
231 for (; aItLS.More(); aItLS.Next()) {
232 aSd=*((TopoDS_Solid*)&aItLS.Value());
234 aState=GEOMAlgo_Tools3D::ComputeStateByOnePoint(aSI, aSd, 1.e-11, aCtx);
235 if (aState==TopAbs_IN) {
238 BRepClass3d_SolidClassifier& aSC=aCtx->SolidClassifier(aSd);
247 // 10 - myShape is Null
248 // 11 - myShape contains non-solids
249 // 20 - BuilderSolid failed