1 // Copyright (C) 2007-2008 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: BlockFix_CheckTool.cxx
23 // Created: 17.12.04 11:15:25
24 // Author: Sergey KUUL
26 #include <BlockFix_CheckTool.ixx>
28 //#include <BlockFix_UnionEdges.hxx>
29 //#include <BlockFix_UnionFaces.hxx>
31 #include <BRep_Tool.hxx>
34 #include <TopExp_Explorer.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Solid.hxx>
39 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
40 #include <TopTools_MapOfShape.hxx>
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 //=======================================================================
46 //function : BlockFix_CheckTool()
47 //purpose : Constructor
48 //=======================================================================
50 BlockFix_CheckTool::BlockFix_CheckTool( )
52 myHasCheck = Standard_False;
53 myPossibleBlocks.Clear();
57 //=======================================================================
60 //=======================================================================
62 void BlockFix_CheckTool::SetShape(const TopoDS_Shape& aShape)
64 myHasCheck = Standard_False;
66 myPossibleBlocks.Clear();
70 //=======================================================================
73 //=======================================================================
75 void BlockFix_CheckTool::Perform()
84 TopExp_Explorer exps (myShape, TopAbs_SOLID);
85 TopTools_MapOfShape mapS;
86 for (; exps.More(); exps.Next()) {
87 TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
88 if (!mapS.Add(aSolid)) continue;
90 Standard_Boolean IsBlock=Standard_True;
91 Standard_Boolean MayBeUF=Standard_False;
92 Standard_Boolean MayBeUE=Standard_False;
93 Standard_Integer nf=0;
94 TopExp_Explorer expf (aSolid, TopAbs_FACE);
95 TopTools_MapOfShape mapF;
96 for (; expf.More(); expf.Next()) {
97 if (mapF.Add(expf.Current()))
102 IsBlock = Standard_False;
105 IsBlock = Standard_False;
106 // check faces unification
107 TopTools_SequenceOfShape faces;
109 for (expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
110 if (mapF.Add(expf.Current())) {
111 TopoDS_Face aFace = TopoDS::Face(expf.Current());
115 Standard_Boolean HasFacesForUnification = Standard_False;
116 for (Standard_Integer i=1; i<faces.Length() && !HasFacesForUnification; i++) {
117 TopoDS_Face F1 = TopoDS::Face(faces.Value(i));
118 TopTools_MapOfShape Edges;
119 for (TopExp_Explorer expe(F1,TopAbs_EDGE); expe.More(); expe.Next())
120 Edges.Add(expe.Current().Oriented(TopAbs_FORWARD));
122 Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1,L1);
123 for(Standard_Integer j=i+1; j<=faces.Length() && !HasFacesForUnification; j++) {
124 TopoDS_Face F2 = TopoDS::Face(faces.Value(j));
126 Handle(Geom_Surface) S2 = BRep_Tool::Surface(F2,L2);
127 if( S1==S2 && L1==L2 ) {
128 // faces have equal based surface
129 // now check common edge
130 for(TopExp_Explorer expe2(F2,TopAbs_EDGE); expe2.More(); expe2.Next()) {
131 if(Edges.Contains(expe2.Current().Oriented(TopAbs_FORWARD))) {
132 HasFacesForUnification = Standard_True;
139 if (HasFacesForUnification) {
140 MayBeUF=Standard_True;
144 Standard_Integer nbe=0;
145 TopTools_MapOfShape DegenEdges;
146 TopExp_Explorer expe (aSolid, TopAbs_EDGE);
147 TopTools_MapOfShape mapE;
148 for (; expe.More(); expe.Next()) {
149 TopoDS_Edge E = TopoDS::Edge(expe.Current());
150 if (!mapE.Add(E)) continue;
151 if (BRep_Tool::Degenerated(E)) {
158 if (nbe == 12 && DegenEdges.Extent() > 0) {
159 IsBlock = Standard_False;
161 myPossibleBlocks.Append(aSolid);
165 IsBlock = Standard_False;
167 IsBlock = Standard_False;
168 // check edges unification
169 // creating map of edge faces
170 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
171 TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
174 for (expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
175 TopoDS_Face aFace = TopoDS::Face(expf.Current());
176 if (!mapF.Add(aFace)) continue;
177 TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
179 TopTools_MapOfShape mapEe;
180 for (expe.Init(aFace, TopAbs_EDGE); expe.More(); expe.Next()) {
181 TopoDS_Edge edge = TopoDS::Edge(expe.Current());
182 if (!mapEe.Add(edge)) continue;
183 if (!aMapEdgeFaces.Contains(edge)) continue;
184 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
185 TopTools_ListIteratorOfListOfShape anIter (aList);
186 for (; anIter.More(); anIter.Next()) {
187 TopoDS_Face face = TopoDS::Face(anIter.Value());
188 if (face.IsSame(aFace)) continue;
189 if (aMapFacesEdges.Contains(face)) {
190 aMapFacesEdges.ChangeFromKey(face).Append(edge);
193 TopTools_ListOfShape ListEdges;
194 ListEdges.Append(edge);
195 aMapFacesEdges.Add(face,ListEdges);
199 Standard_Integer i = 1;
200 for (; i <= aMapFacesEdges.Extent(); i++) {
201 const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
202 if (ListEdges.Extent() > 1) break;
204 if (i <= aMapFacesEdges.Extent()) {
205 MayBeUE = Standard_True;
215 myPossibleBlocks.Append(aSolid);
223 myPossibleBlocks.Append(aSolid);
228 myHasCheck = Standard_True;
232 //=======================================================================
233 //function : NbPossibleBlocks
235 //=======================================================================
237 Standard_Integer BlockFix_CheckTool::NbPossibleBlocks() const
239 return myPossibleBlocks.Length();
243 //=======================================================================
244 //function : PossibleBlock
246 //=======================================================================
248 TopoDS_Shape BlockFix_CheckTool::PossibleBlock(const Standard_Integer num) const
251 if( num>0 && num<=myPossibleBlocks.Length() )
252 res = myPossibleBlocks.Value(num);
257 //=======================================================================
258 //function : DumpCheckResult
260 //=======================================================================
262 void BlockFix_CheckTool::DumpCheckResult(Standard_OStream& S) const
265 S<<"Check not performed!"<<endl;
267 S<<"dump results of check:"<<endl;
268 S<<" total number of solids = "<<myNbSolids<<endl;
269 S<<" including: number of good blocks = "<<myNbBlocks<<endl;
270 S<<" number of possible blocks = "<<NbPossibleBlocks()<<endl;
271 S<<" including: need remove degenerative = "<<myNbDegen<<endl;
272 S<<" need unionfaces = "<<myNbUF<<endl;
273 S<<" need unionedges = "<<myNbUE<<endl;
274 S<<" need both unionfaces and unionedges = "<<myNbUFUE<<endl;
275 Standard_Integer nbtmp = myNbSolids - myNbBlocks - NbPossibleBlocks();
276 S<<" number of impossible blocks = "<<nbtmp<<endl;