0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / ShapeUpgrade / ShapeUpgrade_RemoveInternalWires.cxx
CommitLineData
7fd59977 1#include <ShapeUpgrade_RemoveInternalWires.ixx>
2#include <TopExp_Explorer.hxx>
3#include <TopExp.hxx>
4#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
5#include <TopTools_ListOfShape.hxx>
6#include <TopTools_ListIteratorOfListOfShape.hxx>
7#include <TopoDS_Face.hxx>
8#include <TopoDS_Wire.hxx>
9#include <TopoDS_Iterator.hxx>
10#include <TopoDS.hxx>
11#include <ShapeAnalysis.hxx>
12#include <ShapeExtend.hxx>
13#include <TopTools_SequenceOfShape.hxx>
14#include <ShapeExtend_WireData.hxx>
15#include <ShapeBuild_ReShape.hxx>
16#include <Precision.hxx>
17#include <TopoDS_Edge.hxx>
18#include <TopTools_IndexedMapOfShape.hxx>
19
20//=======================================================================
21//function : ShapeUpgrade_RemoveInternalWires
22//purpose :
23//=======================================================================
24
25ShapeUpgrade_RemoveInternalWires::ShapeUpgrade_RemoveInternalWires()
26{
27 myMinArea =0.;
28 myRemoveFacesMode = Standard_True;
29 myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
30 Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
31 SetContext(aContext);
32
33}
34
35//=======================================================================
36//function : ShapeUpgrade_RemoveInternalWires
37//purpose :
38//=======================================================================
39
40ShapeUpgrade_RemoveInternalWires::ShapeUpgrade_RemoveInternalWires(const TopoDS_Shape& theShape)
41{
42 Handle(ShapeBuild_ReShape) aContext = new ShapeBuild_ReShape;
43 SetContext(aContext);
44 Init(theShape);
45}
46
47//=======================================================================
48//function : Init
49//purpose :
50//=======================================================================
51
52 void ShapeUpgrade_RemoveInternalWires::Init(const TopoDS_Shape& theShape)
53{
54 myShape = theShape;
55 Context()->Apply(theShape);
56 TopExp::MapShapesAndAncestors(myShape,TopAbs_EDGE,TopAbs_FACE,myEdgeFaces);
57 myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
58 myMinArea =0.;
59 myRemoveFacesMode = Standard_True;
60}
61
62//=======================================================================
63//function : Perform
64//purpose :
65//=======================================================================
66
67 Standard_Boolean ShapeUpgrade_RemoveInternalWires::Perform()
68{
69 Clear();
70 if(myShape.IsNull()) {
71 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
72 return Standard_False;
73 }
74 TopExp_Explorer aExpF(myShape,TopAbs_FACE);
75 for( ; aExpF.More(); aExpF.Next()) {
76 TopoDS_Face aF = TopoDS::Face(aExpF.Current());
77 removeSmallWire(aF,TopoDS_Wire());
78 }
79 if(myRemoveFacesMode)
80 removeSmallFaces();
81
82 myResult = Context()->Apply(myShape);
83 return Status( ShapeExtend_DONE );
84}
85
86//=======================================================================
87//function : Perform
88//purpose :
89//=======================================================================
90
91 Standard_Boolean ShapeUpgrade_RemoveInternalWires::Perform(const TopTools_SequenceOfShape& theSeqShapes)
92{
93 if(myShape.IsNull()) {
94 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL1);
95 return Standard_False;
96 }
97 Clear();
98 TopTools_IndexedDataMapOfShapeListOfShape aWireFaces;
99 Standard_Integer i =1, nb = theSeqShapes.Length();
100 for( ; i <= nb; i++) {
101 TopoDS_Shape aS = theSeqShapes.Value(i);
102 if(aS.ShapeType() == TopAbs_FACE)
103 removeSmallWire(aS,TopoDS_Wire());
104 else if(aS.ShapeType() == TopAbs_WIRE) {
105 if(!aWireFaces.Extent())
106 TopExp::MapShapesAndAncestors(myShape,TopAbs_WIRE,TopAbs_FACE,aWireFaces);
107 if(aWireFaces.Contains(aS)) {
108 const TopTools_ListOfShape& alfaces = aWireFaces.FindFromKey(aS);
109 TopTools_ListIteratorOfListOfShape liter(alfaces);
110 for( ; liter.More(); liter.Next())
111 removeSmallWire(liter.Value(),aS);
112 }
113
114 }
115
116 }
117 if(myRemoveFacesMode)
118 removeSmallFaces();
119 myResult = Context()->Apply(myShape);
120 return Status( ShapeExtend_DONE );
121}
122
123//=======================================================================
124//function : removeSmallWire
125//purpose :
126//=======================================================================
127
128void ShapeUpgrade_RemoveInternalWires::removeSmallWire (const TopoDS_Shape& theFace,
129 const TopoDS_Shape& theWire)
130{
131 TopoDS_Face aF = TopoDS::Face(theFace);
132 TopoDS_Wire anOutW = ShapeAnalysis::OuterWire(aF);
133 TopoDS_Iterator aIt(aF);
134 for( ; aIt.More(); aIt.Next()) {
135 if(aIt.Value().ShapeType() != TopAbs_WIRE || aIt.Value().IsSame(anOutW))
136 continue;
137 //Handle(ShapeExtend_WireData) asewd = new ShapeExtend_WireData();
138 TopoDS_Wire aW = TopoDS::Wire(aIt.Value());
139 if(!theWire.IsNull() && !theWire.IsSame(aW))
140 continue;
141 Standard_Real anArea = ShapeAnalysis::ContourArea(aW);
142 if(anArea < myMinArea -Precision::Confusion()) {
143 Context()->Remove(aW);
144 myRemoveWires.Append(aW);
145 myStatus |= ShapeExtend::EncodeStatus(ShapeExtend_DONE1);
146 if(!myRemoveFacesMode )
147 continue;
148
149 TopoDS_Iterator aIte(aW,Standard_False);
150 for( ; aIte.More(); aIte.Next()) {
151 TopoDS_Shape aE = aIte.Value();
152 if(myRemoveEdges.IsBound(aE))
153 myRemoveEdges.ChangeFind(aE).Append(aF);
154 else {
155 TopTools_ListOfShape alfaces;
156 alfaces.Append(aF);
157 myRemoveEdges.Bind(aE,alfaces);
158 }
159 }
160 }
161
162 }
163}
164
165//=======================================================================
166//function : removeSmallFaces
167//purpose :
168//=======================================================================
169
170void ShapeUpgrade_RemoveInternalWires::removeSmallFaces ()
171{
172
173 Standard_Integer i =1;
174 for( ; i <= myRemoveWires.Length() ; i++) {
175 TopoDS_Shape aWire = myRemoveWires.Value(i);
176 TopoDS_Iterator aIte(aWire,Standard_False);
177 TopTools_IndexedMapOfShape aFaceCandidates;
178 //collecting all faces containing edges from removed wire
179 for( ; aIte.More(); aIte.Next()) {
180
181 TopoDS_Shape aEdge = aIte.Value();
182 if(!myEdgeFaces.Contains(aEdge)) {
183 myStatus |= ShapeExtend::EncodeStatus (ShapeExtend_FAIL2);
184 continue;
185 }
186 const TopTools_ListOfShape& aLface1 = myEdgeFaces.FindFromKey(aEdge);
187 const TopTools_ListOfShape& aLface2 = myRemoveEdges.Find(aEdge);
188 TopTools_ListIteratorOfListOfShape aliter(aLface1);
189 TopTools_ListIteratorOfListOfShape aliter2(aLface2);
190 for( ; aliter.More(); aliter.Next()) {
191 TopoDS_Shape aF = Context()->Apply(aliter.Value());
192 if(aF.IsNull())
193 continue;
194 Standard_Boolean isFind = Standard_False;
195 for( ; aliter2.More() && !isFind; aliter2.Next()) {
196 TopoDS_Shape aF2 = Context()->Apply(aliter2.Value());
197 isFind = aF.IsSame(aF2);
198 }
199
200 if(!isFind) {
201 TopoDS_Wire aWout = ShapeAnalysis::OuterWire(TopoDS::Face(aF));
202 Standard_Boolean isOuter = Standard_False;
203 TopoDS_Iterator aIter(aWout,Standard_False);
204 for( ; aIter.More() && !isOuter; aIter.Next())
205 isOuter = aEdge.IsSame(aIter.Value());
206 if(isOuter)
207 aFaceCandidates.Add(aF);
208 }
209 }
210
211 }
212
213 //remove faces which have outer wire consist of only
214 //edges from removed wires and
215 //seam edges for faces based on conic surface or
216 //in the case of a few faces based on the same conic surface
217 //the edges belogining these faces.
218 Standard_Integer k =1;
219 for( ; k <= aFaceCandidates.Extent(); k++) {
220 TopoDS_Shape aF = aFaceCandidates.FindKey(k);
221 TopoDS_Wire anOutW = ShapeAnalysis::OuterWire(TopoDS::Face(aF));
222 Handle(ShapeExtend_WireData) asewd = new ShapeExtend_WireData(anOutW);
223 Standard_Integer n =1, nbE = asewd->NbEdges();
224 Standard_Integer nbNotRemoved =0;
225 for( ; n <= nbE; n++) {
226 if(asewd->IsSeam(n))
227 continue;
228 TopoDS_Edge aE = asewd->Edge(n);
229 if(!myRemoveEdges.IsBound(aE) ) {
230 const TopTools_ListOfShape& aLface3 = myEdgeFaces.FindFromKey(aE);
231 TopTools_ListIteratorOfListOfShape aliter3(aLface3);
7fd59977 232 for( ; aliter3.More();aliter3.Next()) {
233 TopoDS_Shape aF2 = Context()->Apply(aliter3.Value());
234 if(aF2.IsNull())
235 continue;
236 if(!aF.IsSame(aF2) && !aFaceCandidates.Contains(aF2))
237 nbNotRemoved++;
238 }
239 }
240
241 }
242
243 if(!nbNotRemoved) {
244 Context()->Remove(aF);
245 myRemovedFaces.Append(aF);
246 }
247 }
248 }
249
250 if(myRemovedFaces.Length())
251 myStatus |= ShapeExtend::EncodeStatus(ShapeExtend_DONE2);
252}
253
254//=======================================================================
255//function : Clear
256//purpose :
257//=======================================================================
258
259void ShapeUpgrade_RemoveInternalWires::Clear()
260{
261 myRemoveEdges.Clear();
262 myRemovedFaces.Clear();
263 myRemoveWires.Clear();
264 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
265}
266