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 <BRep_Tool.hxx>
29 #include <BlockFix_UnionEdges.hxx>
30 #include <BlockFix_UnionFaces.hxx>
32 #include <TopExp_Explorer.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Solid.hxx>
37 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
38 #include <TopTools_MapOfShape.hxx>
39 #include <TopTools_ListOfShape.hxx>
40 #include <TopTools_ListIteratorOfListOfShape.hxx>
43 //=======================================================================
44 //function : BlockFix_CheckTool()
45 //purpose : Constructor
46 //=======================================================================
48 BlockFix_CheckTool::BlockFix_CheckTool( )
50 myHasCheck = Standard_False;
51 myPossibleBlocks.Clear();
55 //=======================================================================
58 //=======================================================================
60 void BlockFix_CheckTool::SetShape(const TopoDS_Shape& aShape)
62 myHasCheck = Standard_False;
64 myPossibleBlocks.Clear();
68 //=======================================================================
71 //=======================================================================
73 void BlockFix_CheckTool::Perform()
82 TopExp_Explorer exps (myShape, TopAbs_SOLID);
83 TopTools_MapOfShape mapS;
84 for (; exps.More(); exps.Next()) {
85 TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
86 if (!mapS.Add(aSolid)) continue;
88 Standard_Boolean IsBlock=Standard_True;
89 Standard_Boolean MayBeUF=Standard_False;
90 Standard_Boolean MayBeUE=Standard_False;
91 Standard_Integer nf=0;
92 TopExp_Explorer expf (aSolid, TopAbs_FACE);
93 TopTools_MapOfShape mapF;
94 for (; expf.More(); expf.Next()) {
95 if (mapF.Add(expf.Current()))
100 IsBlock = Standard_False;
103 IsBlock = Standard_False;
104 // check faces unification
105 TopTools_SequenceOfShape faces;
107 for (expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
108 if (mapF.Add(expf.Current())) {
109 TopoDS_Face aFace = TopoDS::Face(expf.Current());
113 Standard_Boolean HasFacesForUnification = Standard_False;
114 for (Standard_Integer i=1; i<faces.Length() && !HasFacesForUnification; i++) {
115 TopoDS_Face F1 = TopoDS::Face(faces.Value(i));
116 TopTools_MapOfShape Edges;
117 for (TopExp_Explorer expe(F1,TopAbs_EDGE); expe.More(); expe.Next())
118 Edges.Add(expe.Current().Oriented(TopAbs_FORWARD));
120 Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1,L1);
121 for(Standard_Integer j=i+1; j<=faces.Length() && !HasFacesForUnification; j++) {
122 TopoDS_Face F2 = TopoDS::Face(faces.Value(j));
124 Handle(Geom_Surface) S2 = BRep_Tool::Surface(F2,L2);
125 if( S1==S2 && L1==L2 ) {
126 // faces have equal based surface
127 // now check common edge
128 for(TopExp_Explorer expe2(F2,TopAbs_EDGE); expe2.More(); expe2.Next()) {
129 if(Edges.Contains(expe2.Current().Oriented(TopAbs_FORWARD))) {
130 HasFacesForUnification = Standard_True;
137 if (HasFacesForUnification) {
138 MayBeUF=Standard_True;
142 Standard_Integer nbe=0;
143 TopTools_MapOfShape DegenEdges;
144 TopExp_Explorer expe (aSolid, TopAbs_EDGE);
145 TopTools_MapOfShape mapE;
146 for (; expe.More(); expe.Next()) {
147 TopoDS_Edge E = TopoDS::Edge(expe.Current());
148 if (!mapE.Add(E)) continue;
149 if (BRep_Tool::Degenerated(E)) {
156 if (nbe == 12 && DegenEdges.Extent() > 0) {
157 IsBlock = Standard_False;
159 myPossibleBlocks.Append(aSolid);
163 IsBlock = Standard_False;
165 IsBlock = Standard_False;
166 // check edges unification
167 // creating map of edge faces
168 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
169 TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
172 for (expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
173 TopoDS_Face aFace = TopoDS::Face(expf.Current());
174 if (!mapF.Add(aFace)) continue;
175 TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
177 TopTools_MapOfShape mapEe;
178 for (expe.Init(aFace, TopAbs_EDGE); expe.More(); expe.Next()) {
179 TopoDS_Edge edge = TopoDS::Edge(expe.Current());
180 if (!mapEe.Add(edge)) continue;
181 if (!aMapEdgeFaces.Contains(edge)) continue;
182 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
183 TopTools_ListIteratorOfListOfShape anIter (aList);
184 for (; anIter.More(); anIter.Next()) {
185 TopoDS_Face face = TopoDS::Face(anIter.Value());
186 if (face.IsSame(aFace)) continue;
187 if (aMapFacesEdges.Contains(face)) {
188 aMapFacesEdges.ChangeFromKey(face).Append(edge);
191 TopTools_ListOfShape ListEdges;
192 ListEdges.Append(edge);
193 aMapFacesEdges.Add(face,ListEdges);
197 Standard_Integer i = 1;
198 for (; i <= aMapFacesEdges.Extent(); i++) {
199 const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
200 if (ListEdges.Extent() > 1) break;
202 if (i <= aMapFacesEdges.Extent()) {
203 MayBeUE = Standard_True;
213 myPossibleBlocks.Append(aSolid);
221 myPossibleBlocks.Append(aSolid);
226 myHasCheck = Standard_True;
230 //=======================================================================
231 //function : NbPossibleBlocks
233 //=======================================================================
235 Standard_Integer BlockFix_CheckTool::NbPossibleBlocks() const
237 return myPossibleBlocks.Length();
241 //=======================================================================
242 //function : PossibleBlock
244 //=======================================================================
246 TopoDS_Shape BlockFix_CheckTool::PossibleBlock(const Standard_Integer num) const
249 if( num>0 && num<=myPossibleBlocks.Length() )
250 res = myPossibleBlocks.Value(num);
255 //=======================================================================
256 //function : DumpCheckResult
258 //=======================================================================
260 void BlockFix_CheckTool::DumpCheckResult(Standard_OStream& S) const
263 S<<"Check not performed!"<<endl;
265 S<<"dump results of check:"<<endl;
266 S<<" total number of solids = "<<myNbSolids<<endl;
267 S<<" including: number of good blocks = "<<myNbBlocks<<endl;
268 S<<" number of possible blocks = "<<NbPossibleBlocks()<<endl;
269 S<<" including: need remove degenerative = "<<myNbDegen<<endl;
270 S<<" need unionfaces = "<<myNbUF<<endl;
271 S<<" need unionedges = "<<myNbUE<<endl;
272 S<<" need both unionfaces and unionedges = "<<myNbUFUE<<endl;
273 Standard_Integer nbtmp = myNbSolids - myNbBlocks - NbPossibleBlocks();
274 S<<" number of impossible blocks = "<<nbtmp<<endl;