1 // File: BlockFix_CheckTool.cxx
2 // Created: 17.12.04 11:15:25
4 // Copyright: Open CASCADE SA 2004
6 #include <BlockFix_CheckTool.ixx>
8 #include <BRep_Tool.hxx>
9 #include <BlockFix_UnionEdges.hxx>
10 #include <BlockFix_UnionFaces.hxx>
12 #include <TopExp_Explorer.hxx>
14 #include <TopoDS_Edge.hxx>
15 #include <TopoDS_Face.hxx>
16 #include <TopoDS_Solid.hxx>
17 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
18 #include <TopTools_MapOfShape.hxx>
19 #include <TopTools_ListOfShape.hxx>
20 #include <TopTools_ListIteratorOfListOfShape.hxx>
23 //=======================================================================
24 //function : BlockFix_CheckTool()
25 //purpose : Constructor
26 //=======================================================================
28 BlockFix_CheckTool::BlockFix_CheckTool( )
30 myHasCheck = Standard_False;
31 myPossibleBlocks.Clear();
35 //=======================================================================
38 //=======================================================================
40 void BlockFix_CheckTool::SetShape(const TopoDS_Shape& aShape)
42 myHasCheck = Standard_False;
44 myPossibleBlocks.Clear();
48 //=======================================================================
51 //=======================================================================
53 void BlockFix_CheckTool::Perform()
62 for(exps.Init(myShape, TopAbs_SOLID); exps.More(); exps.Next()) {
63 TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
65 Standard_Boolean IsBlock=Standard_True;
66 Standard_Boolean MayBeUF=Standard_False;
67 Standard_Boolean MayBeUE=Standard_False;
68 Standard_Integer nf=0;
70 for(expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) nf++;
73 IsBlock=Standard_False;
76 IsBlock=Standard_False;
77 // check faces unification
78 TopTools_SequenceOfShape faces;
79 for( expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
80 TopoDS_Face aFace = TopoDS::Face(expf.Current());
83 Standard_Boolean HasFacesForUnification = Standard_False;
84 for(Standard_Integer i=1; i<faces.Length() && !HasFacesForUnification; i++) {
85 TopoDS_Face F1 = TopoDS::Face(faces.Value(i));
86 TopTools_MapOfShape Edges;
87 for(TopExp_Explorer expe(F1,TopAbs_EDGE); expe.More(); expe.Next())
88 Edges.Add(expe.Current().Oriented(TopAbs_FORWARD));
90 Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1,L1);
91 for(Standard_Integer j=i+1; j<=faces.Length() && !HasFacesForUnification; j++) {
92 TopoDS_Face F2 = TopoDS::Face(faces.Value(j));
94 Handle(Geom_Surface) S2 = BRep_Tool::Surface(F2,L2);
95 if( S1==S2 && L1==L2 ) {
96 // faces have equal based surface
97 // now check common edge
98 for(TopExp_Explorer expe2(F2,TopAbs_EDGE); expe2.More(); expe2.Next()) {
99 if(Edges.Contains(expe2.Current().Oriented(TopAbs_FORWARD))) {
100 HasFacesForUnification = Standard_True;
107 if(HasFacesForUnification) {
108 MayBeUF=Standard_True;
112 Standard_Integer nbe=0;
113 TopTools_MapOfShape DegenEdges;
114 TopExp_Explorer expe;
115 for(expe.Init(aSolid, TopAbs_EDGE); expe.More(); expe.Next()) {
116 TopoDS_Edge E = TopoDS::Edge(expe.Current());
117 if(BRep_Tool::Degenerated(E)) {
118 if(!DegenEdges.Contains(E)) {
126 if( nbe==24 && DegenEdges.Extent()>0 ) {
127 IsBlock=Standard_False;
129 myPossibleBlocks.Append(aSolid);
133 IsBlock=Standard_False;
135 IsBlock=Standard_False;
136 // check edges unification
137 // creating map of edge faces
138 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
139 TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
140 for(expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
141 TopoDS_Face aFace = TopoDS::Face(expf.Current());
142 TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
143 for(expe.Init(aFace,TopAbs_EDGE); expe.More(); expe.Next()) {
144 TopoDS_Edge edge = TopoDS::Edge(expe.Current());
145 if(!aMapEdgeFaces.Contains(edge)) continue;
146 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
147 TopTools_ListIteratorOfListOfShape anIter(aList);
148 for( ; anIter.More(); anIter.Next()) {
149 TopoDS_Face face = TopoDS::Face(anIter.Value());
150 if(face.IsSame(aFace)) continue;
151 if(aMapFacesEdges.Contains(face)) {
152 aMapFacesEdges.ChangeFromKey(face).Append(edge);
155 TopTools_ListOfShape ListEdges;
156 ListEdges.Append(edge);
157 aMapFacesEdges.Add(face,ListEdges);
161 Standard_Integer i=1;
162 for(; i<=aMapFacesEdges.Extent(); i++) {
163 const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
164 if(ListEdges.Extent()>1) break;
166 if(i<=aMapFacesEdges.Extent()) {
167 MayBeUE=Standard_True;
177 myPossibleBlocks.Append(aSolid);
185 myPossibleBlocks.Append(aSolid);
191 myHasCheck = Standard_True;
195 //=======================================================================
196 //function : NbPossibleBlocks
198 //=======================================================================
200 Standard_Integer BlockFix_CheckTool::NbPossibleBlocks() const
202 return myPossibleBlocks.Length();
206 //=======================================================================
207 //function : PossibleBlock
209 //=======================================================================
211 TopoDS_Shape BlockFix_CheckTool::PossibleBlock(const Standard_Integer num) const
214 if( num>0 && num<=myPossibleBlocks.Length() )
215 res = myPossibleBlocks.Value(num);
220 //=======================================================================
221 //function : DumpCheckResult
223 //=======================================================================
225 void BlockFix_CheckTool::DumpCheckResult(Standard_OStream& S) const
228 S<<"Check not performed!"<<endl;
230 S<<"dump results of check:"<<endl;
231 S<<" total number of solids = "<<myNbSolids<<endl;
232 S<<" including: number of good blocks = "<<myNbBlocks<<endl;
233 S<<" number of possible blocks = "<<NbPossibleBlocks()<<endl;
234 S<<" including: need remove degenerative = "<<myNbDegen<<endl;
235 S<<" need unionfaces = "<<myNbUF<<endl;
236 S<<" need unionedges = "<<myNbUE<<endl;
237 S<<" need both unionfaces and unionedges = "<<myNbUFUE<<endl;
238 Standard_Integer nbtmp = myNbSolids - myNbBlocks - NbPossibleBlocks();
239 S<<" number of impossible blocks = "<<nbtmp<<endl;