0023024: Update headers of OCCT files
[occt.git] / src / BOP / BOP_Refiner.cxx
CommitLineData
b311480e 1// Created on: 2001-12-24
2// Created by: Peter KURNEV
3// Copyright (c) 2001-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21
22#include <BOP_Refiner.ixx>
23
24#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
25#include <TopTools_ListOfShape.hxx>
26#include <TopTools_ListIteratorOfListOfShape.hxx>
27#include <TopTools_IndexedMapOfShape.hxx>
28
29#include <TopExp.hxx>
30#include <TopExp_Explorer.hxx>
31
32#include <TopoDS_Vertex.hxx>
33#include <TopoDS.hxx>
34#include <TopoDS_Face.hxx>
35#include <TopoDS_Shape.hxx>
36#include <TopoDS_Edge.hxx>
37#include <TopoDS_Wire.hxx>
38
39#include <BRep_Builder.hxx>
40
41
42//=======================================================================
43// function: BOP_Refiner::BOP_Refiner
44// purpose:
45//=======================================================================
b311480e 46BOP_Refiner::BOP_Refiner()
7fd59977 47:
48 myIsDone(Standard_False),
49 myErrorStatus(1),
50 myNbRemovedVertices(0),
51 myNbRemovedEdges(0)
52{}
53//=======================================================================
54// function: BOP_Refiner::BOP_Refiner
55// purpose:
56//=======================================================================
57 BOP_Refiner::BOP_Refiner(const TopoDS_Shape& aS)
58:
59 myIsDone(Standard_False),
60 myErrorStatus(1),
61 myNbRemovedVertices(0),
62 myNbRemovedEdges(0)
63{
64 myShape=aS;
65}
66
67//=======================================================================
68// function: SetShape
69// purpose:
70//=======================================================================
71 void BOP_Refiner::SetShape (const TopoDS_Shape& aS)
72{
73 myShape=aS;
74}
75//=======================================================================
76// function: SetInternals
77// purpose:
78//=======================================================================
79 void BOP_Refiner::SetInternals (const TopTools_ListOfShape& aLS)
80{
81 myInternals.Clear();
82 TopTools_ListIteratorOfListOfShape anIt(aLS);
83 for(; anIt.More(); anIt.Next()) {
84 const TopoDS_Shape& aS=anIt.Value();
85 myInternals.Append(aS);
86 }
87}
88//=======================================================================
89// function: IsDone
90// purpose:
91//=======================================================================
92 Standard_Boolean BOP_Refiner::IsDone() const
93{
94 return myIsDone;
95}
96//=======================================================================
97// function: ErrorStatus
98// purpose:
99//=======================================================================
100 Standard_Integer BOP_Refiner::ErrorStatus() const
101{
102 return myErrorStatus;
103}
104//=======================================================================
105// function: Shape
106// purpose:
107//=======================================================================
108 const TopoDS_Shape& BOP_Refiner::Shape() const
109{
110 return myShape;
111}
112//=======================================================================
113// function: NbRemovedVertices
114// purpose:
115//=======================================================================
116 Standard_Integer BOP_Refiner::NbRemovedVertices() const
117{
118 return myNbRemovedVertices;
119}
120//=======================================================================
121// function: NbRemovedEdges
122// purpose:
123//=======================================================================
124 Standard_Integer BOP_Refiner::NbRemovedEdges() const
125{
126 return myNbRemovedEdges;
127}
128//=======================================================================
129// function: Do
130// purpose:
131//=======================================================================
132 void BOP_Refiner::Do()
133{
134 DoInternals();
135}
136//=======================================================================
137// function: DoInternals
138// purpose:
139//=======================================================================
140 void BOP_Refiner::DoInternals()
141{
142 Standard_Integer i, aNb, aNbF, aNbE;
143 BRep_Builder aBB;
144 TopTools_IndexedDataMapOfShapeListOfShape aMVF, aMFV, aMVE;
145 TopTools_IndexedMapOfShape aMInternals;
146 //
147 // 0. Source Internals
148 TopTools_ListIteratorOfListOfShape anItx(myInternals);
149 for(; anItx.More(); anItx.Next()) {
150 const TopoDS_Shape& aS=anItx.Value();
151 aMInternals.Add(aS);
152 }
153 //
154 // 1. Vertices
155 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
156 TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_FACE, aMVF);
157
158 aNb=aMVF.Extent();
159 for (i=1; i<=aNb; ++i) {
160 const TopoDS_Vertex& aV=TopoDS::Vertex(aMVF.FindKey(i));
161
162 if (aV.Orientation()!=TopAbs_INTERNAL) {
163 continue;
164 }
165 // how many edges attached to the vertex ?
166 aNbE=aMVE.FindFromKey(aV).Extent();
167
168 if (aNbE) {
169 continue;
170 }
171
172 const TopTools_ListOfShape& aLF=aMVF(i);
173 // how many edges attached to the vertex ?
174 aNbF=aLF.Extent();
175 if (aNbF==1) {
176 const TopoDS_Face& aF=TopoDS::Face(aLF.First());
177
178 if (aMFV.Contains(aF)) {
179 TopTools_ListOfShape& aLFWithVertex=aMFV.ChangeFromKey(aF);
180 aLFWithVertex.Append(aV);
181 }
182 else {
183 TopTools_ListOfShape aLFWithVertex;
184 aLFWithVertex.Append(aV);
185 aMFV.Add(aF, aLFWithVertex);
186 }
187 }// if (aNbF==1)
188 }// for (i=1; i<=aNb; ++i)
189
190 aNbF=aMFV.Extent();
191 for (i=1; i<=aNbF; ++i) {
192 const TopoDS_Face& aF=TopoDS::Face(aMFV.FindKey(i));
193 TopoDS_Face* pF=(TopoDS_Face*)&aF;
194
195 const TopTools_ListOfShape& aLV=aMFV(i);
196 TopTools_ListIteratorOfListOfShape anIt(aLV);
197 for (; anIt.More(); anIt.Next()) {
198 const TopoDS_Vertex& aV=TopoDS::Vertex(anIt.Value());
199 //
200 if (aMInternals.Contains(aV)) {
201 continue;
202 }
203 //
204 pF->Free(Standard_True);
205 aBB.Remove(*pF, aV);
206 myNbRemovedVertices++;
207 }
208 }
209 //
210 // 2. Edges
211 TopTools_IndexedDataMapOfShapeListOfShape aMEF, aMFE;
212 TopExp::MapShapesAndAncestors(myShape, TopAbs_EDGE, TopAbs_FACE, aMEF);
213
214 aNb=aMEF.Extent();
215 for (i=1; i<=aNb; ++i) {
216 const TopoDS_Edge& aE=TopoDS::Edge(aMEF.FindKey(i));
217 if (aE.Orientation()!=TopAbs_INTERNAL) {
218 continue;
219 }
220 const TopTools_ListOfShape& aLF=aMEF(i);
221 aNbF=aLF.Extent();
222 if (aNbF==1) {
223 const TopoDS_Face& aF=TopoDS::Face(aLF.First());
224
225 if (aMFE.Contains(aF)) {
226 TopTools_ListOfShape& aLFWithEdge=aMFE.ChangeFromKey(aF);
227 aLFWithEdge.Append(aE);
228 }
229 else {
230 TopTools_ListOfShape aLFWithEdge;
231 aLFWithEdge.Append(aE);
232 aMFE.Add(aF, aLFWithEdge);
233 }
234 }// if (aNbF==1)
235 }// for (i=1; i<=aNb; ++i)
a042f2e7
P
236 //
237 //modified by NIZNHY-PKV Wed Nov 03 14:27:22 2010f
238 Standard_Boolean bFound;
239 TopoDS_Iterator aItS;
240 TopAbs_Orientation aOr;
241 //modified by NIZNHY-PKV Wed Nov 03 14:27:24 2010t
242 //
7fd59977 243 aNbF=aMFE.Extent();
244 for (i=1; i<=aNbF; ++i) {
a042f2e7
P
245 //modified by NIZNHY-PKV Wed Nov 03 14:29:03 2010f
246 TopoDS_Face aF=TopoDS::Face(aMFE.FindKey(i));
247 aOr=aF.Orientation();
248 if (aOr==TopAbs_INTERNAL) {
249 aF.Orientation(TopAbs_FORWARD);
250 }
251 //const TopoDS_Face& aF=TopoDS::Face(aMFE.FindKey(i));
252 //modified by NIZNHY-PKV Wed Nov 03 14:29:06 2010t
7fd59977 253 TopoDS_Face* pF=(TopoDS_Face*)&aF;
254
255 const TopTools_ListOfShape& aLE=aMFE(i);
256 TopTools_ListIteratorOfListOfShape anIt(aLE);
257 for (; anIt.More(); anIt.Next()) {
258 const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
259 //
260 if (aMInternals.Contains(aE)) {
261 continue;
262 }
263 //
264 TopTools_IndexedDataMapOfShapeListOfShape aMEW;
265 TopExp::MapShapesAndAncestors(aF, TopAbs_EDGE, TopAbs_WIRE, aMEW);
266 //
267 if (aMEW.Contains(aE)) {
268 const TopTools_ListOfShape& aLW=aMEW.FindFromKey(aE);
269 TopTools_ListIteratorOfListOfShape aWIt(aLW);
270 for (; aWIt.More(); aWIt.Next()) {
271 const TopoDS_Wire& aW=TopoDS::Wire(aWIt.Value());
a042f2e7
P
272 //
273 //modified by NIZNHY-PKV Wed Nov 03 14:12:48 2010f
274 bFound=Standard_False;
275 aItS.Initialize(aW);
276 for(; aItS.More(); aItS.Next()) {
277 const TopoDS_Shape& aEW=aItS.Value();
278 if (aEW==aE) {
279 bFound=Standard_True;
280 break;
281 }
282 }
283 //
284 if (!bFound) {
285 continue;
286 }
287 //modified by NIZNHY-PKV Wed Nov 03 14:14:22 2010t
288 //
7fd59977 289 TopoDS_Wire* pW=(TopoDS_Wire*)&aW;
290 pW->Free(Standard_True);
291 //
292 TopExp_Explorer anExp(*pW, TopAbs_EDGE);
293 for (; anExp.More(); anExp.Next()) {
294 const TopoDS_Edge& anEdge=TopoDS::Edge(anExp.Current());
295 aBB.Remove(*pW, anEdge);
296 anExp.Init(*pW, TopAbs_EDGE);
297 }
298 //
299 pF->Free(Standard_True);
300 aBB.Remove(*pF, aW);
a042f2e7
P
301 //modified by NIZNHY-PKV Wed Nov 03 14:29:56 2010f
302 pF->Orientation(aOr);
303 //modified by NIZNHY-PKV Wed Nov 03 14:29:59 2010t
7fd59977 304 myNbRemovedEdges++;
305 }
306 }
307 }// next inernal edge
308 }// for (i=1; i<=aNbF; ++i)
309 myIsDone=!myIsDone;
310}
311// myErrorStatus:
312// 0 - OK
313// 1 - Nothing has been done after constructor
314//