ecf4f17c |
1 | // Created on: 2016 |
2 | // Created by: Eugeny MALTCHIKOV |
3 | // Copyright (c) 2016 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | |
17 | // This is the implementation of the extension of the 3D offset algorithm |
18 | // to work in mode Complete and Join Type Intersection. |
19 | // Currently only the Planar cases are supported. |
20 | |
21 | |
22 | #include <BRepOffset_MakeOffset.hxx> |
23 | |
24 | #include <Precision.hxx> |
25 | #include <TopoDS.hxx> |
26 | |
27 | #include <BRepAlgo_AsDes.hxx> |
28 | #include <BRepAlgo_Image.hxx> |
29 | |
30 | #include <BRep_Builder.hxx> |
31 | #include <BRep_Tool.hxx> |
32 | |
f16a6cc5 |
33 | #include <BRepLib.hxx> |
ecf4f17c |
34 | #include <BRepTools.hxx> |
35 | |
36 | #include <BRepAdaptor_Curve.hxx> |
37 | |
38 | #include <TopExp.hxx> |
39 | #include <TopExp_Explorer.hxx> |
40 | |
41 | #include <TopTools_DataMapOfShapeInteger.hxx> |
42 | |
43 | #include <BRepOffset_Tool.hxx> |
44 | |
45 | #include <BRepClass3d_SolidClassifier.hxx> |
46 | |
47 | #include <BOPDS_DS.hxx> |
48 | |
49 | #include <BOPAlgo_PaveFiller.hxx> |
50 | #include <BOPAlgo_Builder.hxx> |
51 | #include <BOPAlgo_Section.hxx> |
52 | #include <BOPAlgo_MakerVolume.hxx> |
a8232603 |
53 | #include <BOPAlgo_BuilderFace.hxx> |
ecf4f17c |
54 | |
1155d05a |
55 | #include <TopTools_ListOfShape.hxx> |
56 | #include <TopTools_DataMapOfShapeShape.hxx> |
57 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
2ebb1098 |
58 | #include <TopTools_MapOfOrientedShape.hxx> |
ecf4f17c |
59 | |
ecf4f17c |
60 | #include <BOPTools_AlgoTools3D.hxx> |
61 | #include <BOPTools_AlgoTools.hxx> |
a8232603 |
62 | #include <BOPTools_AlgoTools2D.hxx> |
ecf4f17c |
63 | |
64 | #include <IntTools_Context.hxx> |
65 | #include <IntTools_ShrunkRange.hxx> |
66 | |
bc4a3867 |
67 | #ifdef OFFSET_DEBUG |
68 | #include <BRepAlgoAPI_Check.hxx> |
69 | #endif |
70 | |
baaacd46 |
71 | typedef NCollection_DataMap |
72 | <TopoDS_Shape, TopTools_MapOfShape, TopTools_ShapeMapHasher> BRepOffset_DataMapOfShapeMapOfShape; |
ecf4f17c |
73 | |
74 | static |
75 | void IntersectTrimmedEdges(const TopTools_ListOfShape& theLF, |
76 | const Handle(BRepAlgo_AsDes)& theAsDes, |
77 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
78 | TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
79 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
80 | Handle(IntTools_Context)& theCtx, |
81 | TopTools_MapOfShape& theNewEdges, |
82 | TopTools_DataMapOfShapeShape& theETrimEInf); |
83 | |
84 | static |
85 | Standard_Boolean GetEdges(const TopoDS_Face& theFace, |
86 | const Handle(BRepAlgo_AsDes)& theAsDes, |
87 | const TopTools_DataMapOfShapeListOfShape& theEImages, |
88 | const TopTools_MapOfShape& theLastInvEdges, |
89 | const TopTools_IndexedMapOfShape& theInvEdges, |
90 | Handle(IntTools_Context)& theCtx, |
91 | const TopTools_MapOfShape& theModifiedEdges, |
92 | TopoDS_Shape& theEdges, |
93 | TopTools_IndexedMapOfShape& theInv); |
94 | |
a8232603 |
95 | static |
96 | void BuildSplitsOfTrimmedFace(const TopoDS_Face& theFace, |
97 | const TopoDS_Shape& theEdges, |
98 | TopTools_ListOfShape& theLFImages); |
99 | |
ecf4f17c |
100 | static |
101 | void BuildSplitsOfFace(const TopoDS_Face& theFace, |
102 | const TopoDS_Shape& theEdges, |
ecf4f17c |
103 | TopTools_DataMapOfShapeShape& theOrigins, |
104 | TopTools_ListOfShape& theLFImages); |
105 | |
106 | static |
107 | void BuildSplitsOfFaces(const TopTools_ListOfShape& theLF, |
108 | const TopTools_MapOfShape& theModifiedEdges, |
109 | const TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
110 | Handle(BRepAlgo_AsDes)& theAsDes, |
111 | TopTools_DataMapOfShapeShape& theFacesOrigins, |
112 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
113 | TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
114 | TopTools_MapOfShape& theLastInvEdges, |
115 | TopTools_IndexedMapOfShape& theEdgesToAvoid, |
116 | TopTools_IndexedMapOfShape& theInvEdges, |
117 | TopTools_IndexedMapOfShape& theValidEdges, |
118 | TopTools_MapOfShape& theInvertedEdges, |
119 | TopTools_DataMapOfShapeInteger& theAlreadyInvFaces, |
120 | TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
121 | TopTools_DataMapOfShapeShape& theArtInvFaces, |
122 | TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
0da0275c |
123 | TopTools_DataMapOfShapeListOfShape& theDMFNewHoles, |
ecf4f17c |
124 | TopoDS_Shape& theSolids, |
125 | TopTools_DataMapOfShapeListOfShape& theSSInterfs); |
126 | |
127 | static |
128 | void BuildSplitsOfInvFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebuild, |
129 | const TopTools_MapOfShape& theModifiedEdges, |
130 | TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
0da0275c |
131 | TopTools_DataMapOfShapeListOfShape& theDMFNewHoles, |
ecf4f17c |
132 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
133 | TopTools_DataMapOfShapeShape& theFacesOrigins, |
134 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
135 | TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
136 | TopTools_MapOfShape& theLastInvEdges, |
137 | TopTools_IndexedMapOfShape& theEdgesToAvoid, |
138 | TopTools_MapOfShape& theVertsToAvoid, |
139 | TopTools_DataMapOfShapeInteger& theAlreadyInvFaces, |
140 | TopTools_IndexedMapOfShape& theValidEdges, |
141 | TopTools_DataMapOfShapeShape& theETrimEInf, |
142 | Handle(BRepAlgo_AsDes)& theAsDes); |
143 | |
144 | static |
145 | Standard_Boolean CheckIfArtificial(const TopoDS_Shape& theF, |
146 | const TopTools_ListOfShape& theLFImages, |
147 | const TopoDS_Shape& theCE, |
148 | const TopTools_IndexedMapOfShape& theMapEInv, |
149 | const TopTools_DataMapOfShapeListOfShape& theOEImages, |
150 | TopTools_MapOfShape& theMENInv, |
151 | Handle(BRepAlgo_AsDes)& theAsDes); |
152 | |
153 | static |
154 | void FindInvalidEdges(const TopoDS_Face& theF, |
155 | const TopTools_ListOfShape& theLFImages, |
156 | const TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
157 | const TopTools_DataMapOfShapeShape& theFacesOrigins, |
158 | const TopTools_DataMapOfShapeListOfShape& theOEImages, |
159 | const TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
160 | TopTools_IndexedMapOfShape& theInvEdges, |
161 | TopTools_IndexedMapOfShape& theValidEdges, |
162 | TopTools_DataMapOfShapeListOfShape& theDMFLVE, |
163 | TopTools_DataMapOfShapeListOfShape& theDMFLNE, |
164 | TopTools_DataMapOfShapeListOfShape& theDMFLIE, |
165 | TopTools_DataMapOfShapeListOfShape& theDMFLVIE, |
0da0275c |
166 | TopTools_DataMapOfShapeListOfShape& theDMEOrLEIm, |
ecf4f17c |
167 | TopTools_MapOfShape& theMEInverted, |
168 | TopTools_MapOfShape& theEdgesInvalidByVertex); |
169 | |
170 | static |
171 | void FindInvalidFaces(TopTools_ListOfShape& theLFImages, |
172 | const TopTools_IndexedMapOfShape& theInvEdges, |
173 | const TopTools_IndexedMapOfShape& theValidEdges, |
174 | const TopTools_DataMapOfShapeListOfShape& theDMFLVE, |
175 | const TopTools_DataMapOfShapeListOfShape& theDMFLIE, |
176 | const TopTools_ListOfShape& theLENeutral, |
177 | const TopTools_ListOfShape& theLEValInverted, |
178 | const TopTools_MapOfShape& theMEInverted, |
179 | const TopTools_MapOfShape& theEdgesInvalidByVertex, |
0da0275c |
180 | const TopTools_MapOfShape& theMFHoles, |
181 | TopTools_IndexedMapOfShape& theMFInvInHole, |
e08a9b03 |
182 | TopTools_ListOfShape& theInvFaces, |
183 | TopTools_ListOfShape& theInvertedFaces); |
ecf4f17c |
184 | |
0da0275c |
185 | static |
186 | void FindFacesInsideHoleWires(const TopoDS_Face& theFOrigin, |
187 | const TopoDS_Face& theFOffset, |
188 | const TopTools_ListOfShape& theLFImages, |
189 | const TopTools_MapOfShape& theInvertedEdges, |
190 | const TopTools_DataMapOfShapeListOfShape& theDMEOrLEIm, |
2ebb1098 |
191 | const TopTools_IndexedDataMapOfShapeListOfShape& theEFMap, |
0da0275c |
192 | TopTools_MapOfShape& theMFHoles, |
193 | TopTools_DataMapOfShapeListOfShape& theDMFNewHoles, |
194 | Handle(IntTools_Context)& theContext); |
195 | |
ecf4f17c |
196 | static |
197 | gp_Vec GetAverageTangent(const TopoDS_Shape& theS, |
198 | const Standard_Integer theNbP); |
199 | |
200 | static |
201 | Standard_Boolean CheckInverted(const TopoDS_Edge& theEIm, |
202 | const TopoDS_Face& theFOr, |
203 | const TopTools_DataMapOfShapeListOfShape& theOEImages, |
204 | const TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
205 | const TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
ecf4f17c |
206 | const TopTools_IndexedDataMapOfShapeListOfShape& theDMVE, |
207 | const TopTools_IndexedMapOfShape& theMEdges, |
208 | TopTools_MapOfShape& theMEInverted); |
209 | |
baaacd46 |
210 | static |
211 | Standard_Boolean CheckInvertedBlock(const TopoDS_Shape& theCB, |
212 | const TopTools_ListOfShape& theLCBF, |
213 | const TopTools_MapOfShape& theMEInverted, |
214 | const TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
215 | BRepOffset_DataMapOfShapeMapOfShape& theDMCBVInverted, |
216 | BRepOffset_DataMapOfShapeMapOfShape& theDMCBVAll); |
217 | |
218 | static |
219 | void GetVerticesOnEdges(const TopoDS_Shape& theCB, |
220 | const TopTools_MapOfShape& theEdges, |
221 | TopTools_MapOfShape& theVerticesOnEdges, |
222 | TopTools_MapOfShape& theAllVertices); |
ecf4f17c |
223 | |
224 | static |
225 | void RemoveInvalidSplitsByInvertedEdges(const TopTools_MapOfShape& theMEInverted, |
baaacd46 |
226 | const TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
ecf4f17c |
227 | TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
228 | TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
229 | TopTools_IndexedMapOfShape& theMERemoved); |
230 | |
231 | static |
232 | void RemoveInvalidSplitsFromValid(const TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
233 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
234 | const TopTools_MapOfShape& theMEInverted, |
235 | TopTools_IndexedDataMapOfShapeListOfShape& theFImages); |
236 | |
237 | static |
238 | void RemoveInsideFaces(TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
239 | TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
240 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
241 | const TopTools_IndexedMapOfShape& theInvEdges, |
e08a9b03 |
242 | const TopTools_MapOfShape& theInvertedEdges, |
243 | const TopTools_ListOfShape& theInvertedFaces, |
ecf4f17c |
244 | const TopTools_IndexedMapOfShape& theMFToCheckInt, |
0da0275c |
245 | const TopTools_IndexedMapOfShape& theMFInvInHole, |
246 | const TopoDS_Shape& theFHoles, |
ecf4f17c |
247 | TopTools_DataMapOfShapeListOfShape& theSSInterfs, |
248 | TopTools_IndexedMapOfShape& theMERemoved, |
baaacd46 |
249 | TopTools_IndexedMapOfShape& theMEInside, |
ecf4f17c |
250 | TopoDS_Shape& theSolids); |
251 | |
252 | static |
253 | void ShapesConnections(const TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
254 | const TopTools_IndexedMapOfShape& theInvEdges, |
255 | const TopTools_DataMapOfShapeShape& theDMFOr, |
256 | BOPAlgo_Builder& theBuilder, |
257 | TopTools_DataMapOfShapeListOfShape& theSSInterfs); |
258 | |
bc4a3867 |
259 | static |
260 | void RemoveHangingParts(const BOPAlgo_MakerVolume& theMV, |
261 | const TopTools_DataMapOfShapeShape& theDMFImF, |
262 | const TopTools_IndexedMapOfShape& theMFInv, |
263 | const TopTools_IndexedMapOfShape& theInvEdges, |
e08a9b03 |
264 | const TopTools_MapOfShape& theInvertedEdges, |
bc4a3867 |
265 | TopTools_MapOfShape& theMFToRem); |
266 | |
ecf4f17c |
267 | static |
268 | void RemoveValidSplits(const TopTools_MapOfShape& theSpRem, |
269 | TopTools_IndexedDataMapOfShapeListOfShape& theImages, |
270 | BOPAlgo_Builder& theGF, |
271 | TopTools_IndexedMapOfShape& theMERemoved); |
272 | |
273 | static |
274 | void RemoveInvalidSplits(const TopTools_MapOfShape& theSpRem, |
275 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
276 | const TopTools_IndexedMapOfShape& theInvEdges, |
277 | TopTools_IndexedDataMapOfShapeListOfShape& theImages, |
278 | BOPAlgo_Builder& theGF, |
279 | TopTools_IndexedMapOfShape& theMERemoved); |
280 | |
281 | static |
282 | void FilterEdgesImages(const TopoDS_Shape& theS, |
283 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
284 | TopTools_DataMapOfShapeListOfShape& theOEOrigins); |
285 | |
286 | static |
287 | void FilterInvalidFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
baaacd46 |
288 | const TopTools_IndexedDataMapOfShapeListOfShape& theDMEF, |
289 | const TopTools_IndexedMapOfShape& theMERemoved, |
ecf4f17c |
290 | TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
291 | TopTools_DataMapOfShapeShape& theArtInvFaces); |
292 | |
293 | static |
294 | void FilterInvalidEdges(const TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
295 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
296 | const TopTools_DataMapOfShapeListOfShape& theDMFLIE, |
297 | const TopTools_IndexedMapOfShape& theMERemoved, |
298 | TopTools_IndexedMapOfShape& theInvEdges); |
299 | |
300 | static |
301 | void FindFacesToRebuild(const TopTools_IndexedDataMapOfShapeListOfShape& theLFImages, |
302 | const TopTools_IndexedMapOfShape& theInvEdges, |
303 | const TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
304 | const TopTools_DataMapOfShapeListOfShape& theSSInterfs, |
305 | TopTools_IndexedDataMapOfShapeListOfShape& theFToRebuild, |
306 | TopTools_MapOfShape& theFSelfRebAvoid); |
307 | |
308 | static |
309 | void RebuildFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebuild, |
310 | const TopTools_MapOfShape& theFSelfRebAvoid, |
311 | const TopoDS_Shape& theSolids, |
312 | const TopTools_DataMapOfShapeListOfShape& theSSInterfs, |
313 | TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
0da0275c |
314 | TopTools_DataMapOfShapeListOfShape& theDMFNewHoles, |
ecf4f17c |
315 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
316 | TopTools_DataMapOfShapeShape& theFacesOrigins, |
317 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
318 | TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
319 | TopTools_MapOfShape& theLastInvEdges, |
320 | TopTools_IndexedMapOfShape& theEdgesToAvoid, |
321 | TopTools_IndexedMapOfShape& theInvEdges, |
322 | TopTools_IndexedMapOfShape& theValidEdges, |
323 | const TopTools_MapOfShape& theInvertedEdges, |
324 | TopTools_DataMapOfShapeInteger& theAlreadyInvFaces, |
325 | TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
326 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
327 | TopTools_MapOfShape& theVertsToAvoid, |
328 | TopTools_DataMapOfShapeShape& theETrimEInf, |
329 | Handle(BRepAlgo_AsDes)& theAsDes); |
330 | |
331 | static |
332 | void IntersectFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebuild, |
333 | const TopTools_MapOfShape& theFSelfRebAvoid, |
334 | const TopoDS_Shape& theSolids, |
335 | const TopTools_DataMapOfShapeListOfShape& theSSInterfs, |
336 | TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
337 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
338 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
339 | TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
340 | TopTools_IndexedMapOfShape& theInvEdges, |
341 | TopTools_IndexedMapOfShape& theValidEdges, |
342 | const TopTools_MapOfShape& theInvertedEdges, |
343 | TopTools_IndexedMapOfShape& theEdgesToAvoid, |
344 | TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
345 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
346 | TopTools_MapOfShape& theVertsToAvoid, |
347 | TopTools_DataMapOfShapeShape& theETrimEInf, |
348 | TopTools_MapOfShape& theModifiedEdges, |
349 | Handle(BRepAlgo_AsDes)& theAsDes); |
350 | |
351 | static |
352 | void PrepareFacesForIntersection(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebuild, |
353 | const TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
354 | const TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
355 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
356 | const Standard_Boolean bLookVertToAvoid, |
357 | TopTools_IndexedDataMapOfShapeListOfShape& theFLE, |
358 | TopTools_DataMapOfShapeListOfShape& theMDone, |
359 | TopTools_DataMapOfShapeListOfShape& theDMSF, |
360 | TopTools_DataMapOfShapeListOfShape& theMEInfETrim, |
361 | TopTools_DataMapOfShapeListOfShape& theDMVEFull, |
362 | TopTools_DataMapOfShapeShape& theETrimEInf, |
363 | TopTools_IndexedDataMapOfShapeListOfShape& theDMEFInv); |
364 | |
365 | static |
366 | void FindVerticesToAvoid(const TopTools_IndexedDataMapOfShapeListOfShape& theDMEFInv, |
367 | const TopTools_IndexedMapOfShape& theInvEdges, |
368 | const TopTools_IndexedMapOfShape& theValidEdges, |
bc4a3867 |
369 | const TopTools_MapOfShape& theInvertedEdges, |
370 | const TopTools_DataMapOfShapeListOfShape& theDMVEFull, |
371 | const TopTools_DataMapOfShapeListOfShape& theOEImages, |
372 | const TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
ecf4f17c |
373 | TopTools_MapOfShape& theMVRInv); |
374 | |
375 | static |
376 | void FindFacesForIntersection(const TopoDS_Shape& theFInv, |
377 | const TopTools_IndexedMapOfShape& theME, |
378 | const TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
379 | const TopTools_DataMapOfShapeListOfShape& theDMSF, |
380 | const TopTools_MapOfShape& theMVInvAll, |
381 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
382 | const Standard_Boolean theArtCase, |
383 | const TopTools_DataMapOfShapeListOfShape& theSSInterfs, |
384 | TopTools_IndexedMapOfShape& theMFAvoid, |
385 | TopTools_IndexedMapOfShape& theMFInt, |
386 | TopTools_IndexedMapOfShape& theMFIntExt, |
387 | TopTools_ListOfShape& theLFImInt); |
388 | |
389 | static |
390 | void ProcessCommonEdges(const TopTools_ListOfShape& theLEC, |
391 | const TopTools_IndexedMapOfShape& theInvEdges, |
392 | const TopTools_IndexedMapOfShape& theValidEdges, |
393 | const TopTools_IndexedMapOfShape& theME, |
394 | const TopTools_DataMapOfShapeShape& theETrimEInf, |
395 | const TopTools_DataMapOfShapeListOfShape& theMEInfETrim, |
396 | const TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
41aa3c3d |
397 | const TopTools_MapOfShape& theAllInvs, |
ecf4f17c |
398 | const Standard_Boolean theForceUse, |
399 | TopTools_IndexedMapOfShape& theMECV, |
41aa3c3d |
400 | TopTools_MapOfShape& theMECheckExt, |
ecf4f17c |
401 | TopTools_DataMapOfShapeListOfShape& theDMEETrim, |
402 | TopTools_ListOfShape& theLFEi, |
403 | TopTools_ListOfShape& theLFEj, |
404 | TopTools_IndexedMapOfShape& theMEToInt); |
405 | |
406 | static |
407 | void UpdateIntersectedFaces(const TopoDS_Shape& theFInv, |
408 | const TopoDS_Shape& theFi, |
409 | const TopoDS_Shape& theFj, |
410 | const TopTools_ListOfShape& theLFInv, |
411 | const TopTools_ListOfShape& theLFImi, |
412 | const TopTools_ListOfShape& theLFImj, |
413 | const TopTools_ListOfShape& theLFEi, |
414 | const TopTools_ListOfShape& theLFEj, |
415 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
416 | TopTools_IndexedMapOfShape& theMEToInt); |
417 | |
418 | static |
419 | void IntersectFaces(const TopoDS_Shape& theFInv, |
420 | const TopoDS_Shape& theFi, |
421 | const TopoDS_Shape& theFj, |
422 | const TopTools_ListOfShape& theLFInv, |
423 | const TopTools_ListOfShape& theLFImi, |
424 | const TopTools_ListOfShape& theLFImj, |
425 | TopTools_ListOfShape& theLFEi, |
426 | TopTools_ListOfShape& theLFEj, |
427 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
428 | TopTools_IndexedMapOfShape& theMECV, |
429 | TopTools_IndexedMapOfShape& theMEToInt); |
430 | |
431 | static |
432 | void FindOrigins(const TopTools_ListOfShape& theLFIm1, |
433 | const TopTools_ListOfShape& theLFIm2, |
434 | const TopTools_IndexedMapOfShape& theME, |
435 | const TopTools_DataMapOfShapeListOfShape& theOrigins, |
436 | TopTools_ListOfShape& theLEOr); |
437 | |
438 | static |
439 | void IntersectAndTrimEdges(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebuild, |
440 | const TopTools_IndexedMapOfShape& theMFInt, |
441 | const TopTools_IndexedMapOfShape& theMEInt, |
442 | const TopTools_DataMapOfShapeListOfShape& theDMEETrim, |
443 | const TopTools_IndexedMapOfShape& theMSInv, |
444 | const TopTools_IndexedMapOfShape& theMVE, |
445 | const TopTools_MapOfShape& theVertsToAvoid, |
446 | const TopTools_MapOfShape& theNewVertsToAvoid, |
41aa3c3d |
447 | const TopTools_MapOfShape& theMECheckExt, |
ecf4f17c |
448 | TopTools_MapOfShape& theMVBounds, |
449 | TopTools_DataMapOfShapeListOfShape& theEImages); |
450 | |
451 | static |
452 | void GetInvalidEdges(const TopTools_MapOfShape& theVertsToAvoid, |
453 | const TopTools_MapOfShape& theMVBounds, |
454 | BOPAlgo_Builder& theGF, |
455 | TopTools_MapOfShape& theMEInv); |
456 | |
41aa3c3d |
457 | static |
458 | void UpdateValidEdges(const TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
ecf4f17c |
459 | const TopTools_IndexedDataMapOfShapeListOfShape& theFLE, |
dcba2e5c |
460 | const TopTools_IndexedDataMapOfShapeListOfShape& theOENEdges, |
ecf4f17c |
461 | const TopTools_MapOfShape& theMVBounds, |
462 | const TopoDS_Shape& theSolids, |
463 | const TopTools_IndexedMapOfShape& theInvEdges, |
464 | const TopTools_MapOfShape& theInvertedEdges, |
a8232603 |
465 | const TopTools_MapOfShape& theMEInvOnArt, |
41aa3c3d |
466 | TopTools_MapOfShape& theMECheckExt, |
ecf4f17c |
467 | TopTools_IndexedMapOfShape& theEdgesToAvoid, |
468 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
469 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
470 | TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
471 | TopTools_MapOfShape& theVertsToAvoid, |
472 | TopTools_DataMapOfShapeShape& theETrimEInf, |
473 | TopTools_DataMapOfShapeListOfShape& theEImages, |
474 | TopTools_DataMapOfShapeListOfShape& theEETrim, |
475 | TopTools_MapOfShape& theModifiedEdges, |
476 | Handle(BRepAlgo_AsDes)& theAsDes); |
477 | |
478 | static |
479 | void TrimNewIntersectionEdges(const TopTools_ListOfShape& theLE, |
480 | const TopTools_DataMapOfShapeListOfShape& theEETrim, |
481 | const TopTools_MapOfShape& theMVBounds, |
41aa3c3d |
482 | TopTools_MapOfShape& theMECheckExt, |
ecf4f17c |
483 | TopTools_DataMapOfShapeListOfShape& theEImages, |
484 | TopTools_MapOfShape& theMEB, |
485 | TopTools_MapOfShape& theMVOld, |
dcba2e5c |
486 | TopTools_MapOfShape& theMENew, |
41aa3c3d |
487 | TopTools_DataMapOfShapeListOfShape& theDMEOr, |
488 | TopTools_DataMapOfShapeListOfShape& theMELF); |
ecf4f17c |
489 | |
490 | static |
1155d05a |
491 | void IntersectEdges(const TopTools_ListOfShape& theLA, |
ecf4f17c |
492 | const TopTools_ListOfShape& theLE, |
ecf4f17c |
493 | const TopTools_MapOfShape& theMVBounds, |
494 | const TopTools_MapOfShape& theVertsToAvoid, |
dcba2e5c |
495 | TopTools_MapOfShape& theMENew, |
41aa3c3d |
496 | TopTools_MapOfShape& theMECheckExt, |
ecf4f17c |
497 | TopTools_DataMapOfShapeListOfShape& theEImages, |
498 | TopTools_MapOfShape& theModifiedEdges, |
499 | TopTools_DataMapOfShapeListOfShape& theDMEOr, |
41aa3c3d |
500 | TopTools_DataMapOfShapeListOfShape& theMELF, |
ecf4f17c |
501 | TopoDS_Shape& theSplits); |
502 | |
503 | static |
dcba2e5c |
504 | void GetBounds(const TopTools_ListOfShape& theLFaces, |
505 | const TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
ecf4f17c |
506 | const TopTools_MapOfShape& theMEB, |
507 | TopoDS_Shape& theBounds); |
508 | |
509 | static |
510 | void GetBoundsToUpdate(const TopTools_ListOfShape& theLF, |
511 | const TopTools_DataMapOfShapeListOfShape& theOEImages, |
512 | const TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
513 | const TopTools_MapOfShape& theMEB, |
514 | TopTools_ListOfShape& theLABounds, |
515 | TopTools_ListOfShape& theLAValid, |
516 | TopoDS_Shape& theBounds, |
517 | Handle(BRepAlgo_AsDes)& theAsDes); |
518 | |
519 | static |
520 | void GetInvalidEdgesByBounds(const TopoDS_Shape& theSplits, |
521 | const TopoDS_Shape& theBounds, |
ecf4f17c |
522 | const TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
523 | const TopoDS_Shape& theSolids, |
524 | const TopTools_IndexedMapOfShape& theInvEdges, |
525 | const TopTools_MapOfShape& theMVOld, |
526 | const TopTools_MapOfShape& theMENew, |
527 | const TopTools_DataMapOfShapeListOfShape& theDMEOr, |
41aa3c3d |
528 | const TopTools_DataMapOfShapeListOfShape& theMELF, |
ecf4f17c |
529 | const TopTools_DataMapOfShapeListOfShape& theEImages, |
41aa3c3d |
530 | const TopTools_MapOfShape& theMECheckExt, |
a8232603 |
531 | const TopTools_MapOfShape& theMEInvOnArt, |
dcba2e5c |
532 | Handle(IntTools_Context)& theCtx, |
ecf4f17c |
533 | TopTools_MapOfShape& theVertsToAvoid, |
534 | TopTools_MapOfShape& theMEInv); |
535 | |
dcba2e5c |
536 | static |
537 | void FilterSplits(const TopTools_ListOfShape& theLE, |
538 | const TopTools_MapOfShape& theMEFilter, |
539 | const Standard_Boolean theIsInv, |
540 | TopTools_DataMapOfShapeListOfShape& theEImages, |
541 | TopoDS_Shape& theSplits); |
542 | |
ecf4f17c |
543 | static |
544 | void UpdateNewIntersectionEdges(const TopTools_ListOfShape& theLE, |
545 | const TopTools_DataMapOfShapeListOfShape& theMELF, |
546 | const TopTools_DataMapOfShapeListOfShape& theEImages, |
547 | const TopTools_IndexedMapOfShape& theInvEdges, |
548 | const TopTools_MapOfShape& theInvertedEdges, |
549 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
550 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
551 | TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
552 | TopTools_DataMapOfShapeShape& theETrimEInf, |
553 | TopTools_DataMapOfShapeListOfShape& theEETrim, |
554 | TopTools_MapOfShape& theModifiedEdges, |
555 | Handle(BRepAlgo_AsDes)& theAsDes); |
556 | |
2ebb1098 |
557 | static |
558 | void FillGaps(TopTools_IndexedDataMapOfShapeListOfShape& theFImages); |
559 | |
ecf4f17c |
560 | static |
561 | void FillHistory(const TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
562 | const TopTools_DataMapOfShapeListOfShape& theEImages, |
563 | BRepAlgo_Image& theImage); |
564 | |
565 | static |
566 | void UpdateOrigins(const TopTools_ListOfShape& theLA, |
567 | TopTools_DataMapOfShapeListOfShape& theOrigins, |
568 | BOPAlgo_Builder& theGF); |
569 | |
570 | static |
571 | void UpdateImages(const TopTools_ListOfShape& theLA, |
572 | TopTools_DataMapOfShapeListOfShape& theImages, |
573 | BOPAlgo_Builder& theGF, |
574 | TopTools_MapOfShape& theModified); |
575 | |
576 | static |
577 | void UpdateIntersectedEdges(const TopTools_ListOfShape& theLA, |
578 | TopTools_DataMapOfShapeShape& theETrimEInf, |
579 | BOPAlgo_Builder& theGF); |
580 | |
581 | static |
582 | Standard_Boolean ProcessMicroEdge(const TopoDS_Edge& theEdge, |
583 | const Handle(IntTools_Context)& theCtx); |
584 | |
585 | static |
586 | void FindCommonParts(const TopTools_ListOfShape& theLS1, |
587 | const TopTools_ListOfShape& theLS2, |
588 | TopTools_ListOfShape& theLSC, |
589 | const TopAbs_ShapeEnum theType = TopAbs_EDGE); |
590 | |
591 | static |
592 | Standard_Integer NbPoints(const TopoDS_Edge& theE); |
593 | |
594 | static |
595 | Standard_Boolean FindShape(const TopoDS_Shape& theSWhat, |
596 | const TopoDS_Shape& theSWhere, |
597 | TopoDS_Shape& theRes); |
598 | |
599 | static |
600 | void AppendToList(TopTools_ListOfShape& theL, |
601 | const TopoDS_Shape& theS); |
602 | |
e08a9b03 |
603 | template <class ContainerType, class FenceMapType> |
604 | static Standard_Boolean TakeModified(const TopoDS_Shape& theS, |
605 | const TopTools_DataMapOfShapeListOfShape& theImages, |
606 | ContainerType& theMapOut, |
607 | FenceMapType* theMFence); |
608 | |
609 | template <class ContainerType> |
610 | static Standard_Boolean TakeModified(const TopoDS_Shape& theS, |
611 | const TopTools_DataMapOfShapeListOfShape& theImages, |
612 | ContainerType& theMapOut) |
613 | { |
614 | TopTools_MapOfShape* aDummy = NULL; |
615 | return TakeModified (theS, theImages, theMapOut, aDummy); |
616 | } |
617 | |
ecf4f17c |
618 | //======================================================================= |
619 | //function : BuildSplitsOfTrimmedFaces |
620 | //purpose : Building splits of already trimmed faces |
621 | //======================================================================= |
622 | void BRepOffset_MakeOffset::BuildSplitsOfTrimmedFaces(const TopTools_ListOfShape& theLF, |
623 | Handle(BRepAlgo_AsDes)& theAsDes, |
624 | BRepAlgo_Image& theImage) |
625 | { |
626 | TopTools_DataMapOfShapeListOfShape anEImages, anEOrigins; |
627 | TopTools_IndexedDataMapOfShapeListOfShape aDMFFIm; |
628 | TopTools_IndexedMapOfShape anEmptyIM; |
629 | TopTools_DataMapOfShapeListOfShape anEmptyDMSLS; |
630 | TopTools_DataMapOfShapeShape anEmptyDMSS; |
631 | TopTools_MapOfShape aNewEdges, anEmptyM; |
632 | // |
633 | // firstly it is necessary to fuse all the edges |
634 | Handle(IntTools_Context) aCtx = new IntTools_Context(); |
635 | // |
636 | IntersectTrimmedEdges(theLF, theAsDes, anEImages, anEOrigins, anEmptyDMSLS, aCtx, aNewEdges, anEmptyDMSS); |
637 | // |
638 | TopTools_ListIteratorOfListOfShape aItLF(theLF); |
639 | for (; aItLF.More(); aItLF.Next()) { |
640 | const TopoDS_Face& aF = *(TopoDS_Face*)&aItLF.Value(); |
641 | // |
642 | TopoDS_Shape aCE; |
643 | TopTools_ListOfShape aLFImages; |
644 | // |
645 | Standard_Boolean bFound = GetEdges(aF, theAsDes, anEImages, anEmptyM, |
646 | anEmptyIM, aCtx, aNewEdges, aCE, anEmptyIM); |
647 | // split the face by the edges |
648 | if (!bFound) { |
649 | if (!theImage.HasImage(aF)) { |
650 | aLFImages.Append(aF); |
651 | aDMFFIm.Add(aF, aLFImages); |
652 | } |
653 | continue; |
654 | } |
655 | // |
a8232603 |
656 | BuildSplitsOfTrimmedFace(aF, aCE, aLFImages); |
ecf4f17c |
657 | aDMFFIm.Add(aF, aLFImages); |
658 | } |
659 | // Fill history for faces and edges |
660 | FillHistory(aDMFFIm, anEImages, theImage); |
661 | } |
662 | |
663 | //======================================================================= |
664 | //function : BuildSplitsOfExtendedFaces |
665 | //purpose : Building splits of not-trimmed offset faces. |
666 | // For the cases in which invalidity will be found, |
667 | // these invalidities will be rebuilt. |
668 | //======================================================================= |
669 | void BRepOffset_MakeOffset::BuildSplitsOfExtendedFaces(const TopTools_ListOfShape& theLF, |
670 | Handle(BRepAlgo_AsDes)& theAsDes, |
671 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
672 | TopTools_DataMapOfShapeShape& theFacesOrigins, |
673 | TopTools_DataMapOfShapeShape& theETrimEInf, |
674 | BRepAlgo_Image& theImage) |
675 | { |
676 | Handle(IntTools_Context) aCtx = new IntTools_Context(); |
677 | // images and origins for offset edges |
678 | TopTools_DataMapOfShapeListOfShape anOEImages, anOEOrigins; |
679 | TopTools_MapOfShape aNewEdges; |
680 | // fusing all trimmed offset edges to avoid self-intersections in the splits |
681 | IntersectTrimmedEdges(theLF, theAsDes, anOEImages, anOEOrigins, |
682 | theEdgesOrigins, aCtx, aNewEdges, theETrimEInf); |
683 | // |
684 | // valid/invalid edges |
685 | TopTools_IndexedMapOfShape anInvEdges, aValidEdges, anEdgesToAvoid; |
686 | // inverted edges |
687 | TopTools_MapOfShape anInvertedEdges; |
688 | // splits of faces |
689 | TopTools_IndexedDataMapOfShapeListOfShape aFImages; |
690 | // found invalid faces |
691 | TopTools_IndexedDataMapOfShapeListOfShape anInvFaces; |
692 | // artificially invalid faces - it will be empty here, |
693 | // but may be filled on the following rebuilding steps |
694 | TopTools_DataMapOfShapeShape anArtInvFaces; |
695 | // shapes connections for using in rebuilding |
696 | TopTools_DataMapOfShapeListOfShape aSSInterfs; |
697 | // edges to avoid on second steps |
698 | TopTools_MapOfShape aLastInvEdges; |
699 | // keep information of already invalid faces to avoid |
700 | // infinite rebuilding of the same invalid face |
701 | TopTools_DataMapOfShapeInteger anAlreadyInvFaces; |
0da0275c |
702 | // images of the hole faces of the original faces |
703 | TopTools_DataMapOfShapeListOfShape aDMFNewHoles; |
ecf4f17c |
704 | // solid build from the new splits |
705 | TopoDS_Shape aSolids; |
706 | // now we can split the faces |
707 | BuildSplitsOfFaces(theLF, aNewEdges, theEdgesOrigins, theAsDes, theFacesOrigins, |
708 | anOEImages, anOEOrigins, aLastInvEdges, anEdgesToAvoid, anInvEdges, aValidEdges, |
0da0275c |
709 | anInvertedEdges, anAlreadyInvFaces, anInvFaces, anArtInvFaces, aFImages, |
710 | aDMFNewHoles, aSolids, aSSInterfs); |
ecf4f17c |
711 | // |
712 | // Find faces to rebuild |
713 | if (anInvFaces.Extent()) { |
714 | TopTools_IndexedDataMapOfShapeListOfShape aFToRebuild; |
715 | TopTools_MapOfShape aFSelfRebAvoid; |
716 | FindFacesToRebuild(aFImages, anInvEdges, anInvFaces, aSSInterfs, aFToRebuild, aFSelfRebAvoid); |
717 | // |
718 | if (aFToRebuild.Extent()) { |
719 | // vertices to avoid |
720 | TopTools_MapOfShape aVAEmpty; |
0da0275c |
721 | RebuildFaces(aFToRebuild, aFSelfRebAvoid, aSolids, aSSInterfs, aFImages, aDMFNewHoles, |
722 | theEdgesOrigins, theFacesOrigins, anOEImages, anOEOrigins, aLastInvEdges, |
723 | anEdgesToAvoid, anInvEdges, aValidEdges, anInvertedEdges, anAlreadyInvFaces, |
724 | anInvFaces, anArtInvFaces, aVAEmpty, theETrimEInf, theAsDes); |
ecf4f17c |
725 | } |
726 | } |
2ebb1098 |
727 | |
728 | // Fill possible gaps in the splits of offset faces to increase possibility of |
729 | // creating closed volume from these splits |
730 | FillGaps(aFImages); |
731 | |
ecf4f17c |
732 | // Fill history for faces and edges |
733 | FillHistory(aFImages, anOEImages, theImage); |
734 | } |
735 | |
736 | //======================================================================= |
737 | //function : BuildSplitsOfInvFaces |
738 | //purpose : Rebuilding splits of faces with new intersection edges |
739 | //======================================================================= |
740 | void BuildSplitsOfInvFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebuild, |
741 | const TopTools_MapOfShape& theModifiedEdges, |
742 | TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
0da0275c |
743 | TopTools_DataMapOfShapeListOfShape& theDMFNewHoles, |
ecf4f17c |
744 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
745 | TopTools_DataMapOfShapeShape& theFacesOrigins, |
746 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
747 | TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
748 | TopTools_MapOfShape& theLastInvEdges, |
749 | TopTools_IndexedMapOfShape& theEdgesToAvoid, |
750 | TopTools_MapOfShape& theVertsToAvoid, |
751 | TopTools_DataMapOfShapeInteger& theAlreadyInvFaces, |
752 | TopTools_IndexedMapOfShape& theValidEdges, |
753 | TopTools_DataMapOfShapeShape& theETrimEInf, |
754 | Handle(BRepAlgo_AsDes)& theAsDes) |
755 | { |
756 | Standard_Integer aNb = theFToRebuild.Extent(); |
757 | if (!aNb) { |
758 | return; |
759 | } |
760 | // |
761 | TopTools_ListOfShape aLF; |
762 | aNb = theFImages.Extent(); |
763 | for (Standard_Integer i = 1; i <= aNb; ++i) { |
764 | const TopoDS_Shape& aF = theFImages.FindKey(i); |
765 | aLF.Append(aF); |
766 | } |
767 | // |
768 | // invalid faces |
769 | TopTools_IndexedDataMapOfShapeListOfShape anInvFaces; |
770 | // artificially invalid faces |
771 | TopTools_DataMapOfShapeShape anArtInvFaces; |
772 | // invalid edges |
773 | TopTools_IndexedMapOfShape anInvEdges; |
774 | // inverted edges |
775 | TopTools_MapOfShape anInvertedEdges; |
776 | // shapes connection for using in rebuilding process |
777 | TopTools_DataMapOfShapeListOfShape aSSInterfs; |
778 | // |
779 | TopoDS_Shape aSolids; |
780 | // |
781 | BuildSplitsOfFaces(aLF, theModifiedEdges, theEdgesOrigins, theAsDes, theFacesOrigins, |
782 | theOEImages, theOEOrigins, theLastInvEdges, theEdgesToAvoid, anInvEdges, theValidEdges, |
0da0275c |
783 | anInvertedEdges, theAlreadyInvFaces, anInvFaces, anArtInvFaces, theFImages, |
784 | theDMFNewHoles, aSolids, aSSInterfs); |
ecf4f17c |
785 | // |
786 | if (anInvFaces.Extent()) { |
787 | TopTools_IndexedDataMapOfShapeListOfShape aFToRebuild; |
788 | TopTools_MapOfShape aFSelfRebAvoid; |
789 | FindFacesToRebuild(theFImages, anInvEdges, anInvFaces, aSSInterfs, aFToRebuild, aFSelfRebAvoid); |
790 | // |
791 | if (aFToRebuild.Extent()) { |
0da0275c |
792 | RebuildFaces(aFToRebuild, aFSelfRebAvoid, aSolids, aSSInterfs, theFImages, theDMFNewHoles, |
793 | theEdgesOrigins, theFacesOrigins, theOEImages, theOEOrigins, theLastInvEdges, |
794 | theEdgesToAvoid, anInvEdges, theValidEdges, anInvertedEdges, theAlreadyInvFaces, |
795 | anInvFaces, anArtInvFaces, theVertsToAvoid, theETrimEInf, theAsDes); |
ecf4f17c |
796 | } |
797 | } |
798 | } |
799 | |
800 | //======================================================================= |
801 | //function : BuildSplitsOfFaces |
802 | //purpose : Building the splits of offset faces and |
803 | // looking for the invalid splits |
804 | //======================================================================= |
805 | void BuildSplitsOfFaces(const TopTools_ListOfShape& theLF, |
806 | const TopTools_MapOfShape& theModifiedEdges, |
807 | const TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
808 | Handle(BRepAlgo_AsDes)& theAsDes, |
809 | TopTools_DataMapOfShapeShape& theFacesOrigins, |
810 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
811 | TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
812 | TopTools_MapOfShape& theLastInvEdges, |
813 | TopTools_IndexedMapOfShape& theEdgesToAvoid, |
814 | TopTools_IndexedMapOfShape& theInvEdges, |
815 | TopTools_IndexedMapOfShape& theValidEdges, |
816 | TopTools_MapOfShape& theInvertedEdges, |
817 | TopTools_DataMapOfShapeInteger& theAlreadyInvFaces, |
818 | TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
819 | TopTools_DataMapOfShapeShape& theArtInvFaces, |
820 | TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
0da0275c |
821 | TopTools_DataMapOfShapeListOfShape& theDMFNewHoles, |
ecf4f17c |
822 | TopoDS_Shape& theSolids, |
823 | TopTools_DataMapOfShapeListOfShape& theSSInterfs) |
824 | { |
825 | if (theLF.IsEmpty()) { |
826 | return; |
827 | } |
828 | // |
829 | BRep_Builder aBB; |
830 | Standard_Integer i, aNb; |
831 | // |
832 | // processed faces |
833 | TopTools_ListOfShape aLFDone; |
834 | // extended face - list of neutral edges, i.e. in one splits - valid and in others - invalid |
835 | TopTools_DataMapOfShapeListOfShape aDMFLNE; |
836 | // list of valid edges for each face |
837 | TopTools_DataMapOfShapeListOfShape aDMFLVE; |
838 | // list of invalid edges for each face |
839 | TopTools_DataMapOfShapeListOfShape aDMFLIE; |
840 | // map of valid inverted edges for the face |
841 | TopTools_DataMapOfShapeListOfShape aDMFLVIE; |
842 | // map of splits to check for internals |
843 | TopTools_IndexedMapOfShape aMFToCheckInt; |
844 | // map of edges created from vertex and marked as invalid |
845 | TopTools_MapOfShape aMEdgeInvalidByVertex; |
0da0275c |
846 | // connection map from old edges to new ones |
847 | TopTools_DataMapOfShapeListOfShape aDMEOrLEIm; |
ecf4f17c |
848 | // |
849 | Handle(IntTools_Context) aCtx = new IntTools_Context; |
850 | // build splits of faces |
851 | TopTools_ListIteratorOfListOfShape aItLF(theLF); |
852 | for (; aItLF.More(); aItLF.Next()) { |
853 | const TopoDS_Face& aF = *(TopoDS_Face*)&aItLF.Value(); |
854 | // |
855 | TopTools_ListOfShape* pLFIm = theFImages.ChangeSeek(aF); |
856 | if (pLFIm && pLFIm->IsEmpty()) { |
857 | continue; |
858 | } |
859 | // get edges by which the face should be split |
860 | TopoDS_Shape aCE; |
861 | TopTools_IndexedMapOfShape aMapEInv; |
862 | Standard_Boolean bFound = |
863 | GetEdges(aF, theAsDes, theOEImages, theLastInvEdges, |
864 | theEdgesToAvoid, aCtx, theModifiedEdges, aCE, aMapEInv); |
865 | if (!bFound) { |
866 | continue; |
867 | } |
868 | // |
bc4a3867 |
869 | #ifdef OFFSET_DEBUG |
870 | // check the found edges on self-intersection |
871 | BRepAlgoAPI_Check aChecker(aCE); |
872 | if (!aChecker.IsValid()) |
873 | { |
874 | cout << "Offset_i_c Error: set of edges to build faces is self-intersecting\n"; |
875 | } |
876 | #endif |
ecf4f17c |
877 | // build splits |
878 | TopTools_ListOfShape aLFImages; |
a8232603 |
879 | BuildSplitsOfFace(aF, aCE, theFacesOrigins, aLFImages); |
ecf4f17c |
880 | // |
881 | if (aMapEInv.Extent()) { |
882 | // check if all possible faces are built |
883 | TopTools_MapOfShape aMENInv; |
884 | Standard_Boolean bArtificialCase = aLFImages.IsEmpty() || |
885 | CheckIfArtificial(aF, aLFImages, aCE, aMapEInv, theOEImages, aMENInv, theAsDes); |
886 | // |
887 | // try to build splits using invalid edges |
888 | TopoDS_Compound aCE1; |
889 | aBB.MakeCompound(aCE1); |
890 | aBB.Add(aCE1, aCE); |
891 | for (i = 1; i <= aMapEInv.Extent(); ++i) { |
892 | aBB.Add(aCE1, aMapEInv(i)); |
893 | } |
894 | // |
895 | TopTools_ListOfShape aLFImages1; |
a8232603 |
896 | BuildSplitsOfFace(aF, aCE1, theFacesOrigins, aLFImages1); |
ecf4f17c |
897 | // |
b443d536 |
898 | // check if the rebuilding has added some new faces to the splits |
45d0af05 |
899 | for (TopTools_ListIteratorOfListOfShape aItLFIm(aLFImages1); aItLFIm.More();) |
900 | { |
b443d536 |
901 | Standard_Boolean bAllInv = Standard_True; |
ecf4f17c |
902 | const TopoDS_Shape& aFIm = aItLFIm.Value(); |
903 | TopExp_Explorer aExpE(aFIm, TopAbs_EDGE); |
904 | for (; aExpE.More(); aExpE.Next()) { |
905 | const TopoDS_Shape& aE = aExpE.Current(); |
b443d536 |
906 | if (!aMapEInv.Contains(aE)) { |
907 | bAllInv = Standard_False; |
908 | if (!aMENInv.Contains(aE)) { |
909 | break; |
910 | } |
ecf4f17c |
911 | } |
912 | } |
913 | // |
914 | if (!aExpE.More()) { |
915 | if (bAllInv) { |
916 | aMFToCheckInt.Add(aFIm); |
917 | } |
918 | aLFImages1.Remove(aItLFIm); |
919 | } |
920 | else { |
921 | aItLFIm.Next(); |
922 | } |
923 | } |
924 | // |
925 | if (bArtificialCase) { |
926 | if (aLFImages.Extent() == aLFImages1.Extent()) { |
927 | bArtificialCase = Standard_False; |
928 | } |
929 | else { |
930 | aLFImages = aLFImages1; |
931 | } |
932 | } |
933 | // |
934 | if (bArtificialCase) { |
935 | TopTools_ListOfShape aLEInv; |
936 | // make the face invalid |
937 | theArtInvFaces.Bind(aF, aCE); |
938 | // |
939 | *pLFIm = aLFImages; |
940 | TopTools_ListIteratorOfListOfShape aItLFIm(aLFImages); |
941 | for (; aItLFIm.More(); aItLFIm.Next()) { |
942 | const TopoDS_Shape& aFIm = aItLFIm.Value(); |
943 | TopExp_Explorer aExpE(aFIm, TopAbs_EDGE); |
944 | for (; aExpE.More(); aExpE.Next()) { |
945 | const TopoDS_Shape& aE = aExpE.Current(); |
946 | if (aMapEInv.Contains(aE)) { |
947 | theInvEdges.Add(aE); |
948 | AppendToList(aLEInv, aE); |
949 | } |
950 | else { |
951 | theValidEdges.Add(aE); |
952 | } |
953 | } |
954 | } |
955 | // |
956 | aDMFLIE.Bind(aF, aLEInv); |
957 | aLFDone.Append(aF); |
958 | // |
959 | continue; |
960 | } |
961 | } |
962 | // |
963 | // find invalid edges |
964 | FindInvalidEdges(aF, aLFImages, theEdgesOrigins, theFacesOrigins, theOEImages, |
965 | theOEOrigins, theInvEdges, theValidEdges, aDMFLVE, aDMFLNE, aDMFLIE, |
0da0275c |
966 | aDMFLVIE, aDMEOrLEIm, theInvertedEdges, aMEdgeInvalidByVertex); |
ecf4f17c |
967 | // |
968 | // save the new splits |
969 | if (!pLFIm) { |
970 | pLFIm = &theFImages(theFImages.Add(aF, TopTools_ListOfShape())); |
971 | } |
972 | else { |
973 | pLFIm->Clear(); |
974 | } |
975 | pLFIm->Append(aLFImages); |
976 | // |
977 | aLFDone.Append(aF); |
978 | } |
979 | // |
980 | if (theInvEdges.IsEmpty() && theArtInvFaces.IsEmpty()) { |
981 | return; |
982 | } |
983 | // |
984 | #ifdef OFFSET_DEBUG |
985 | // show invalid edges |
986 | TopoDS_Compound aCEInv1; |
987 | BRep_Builder().MakeCompound(aCEInv1); |
988 | Standard_Integer aNbEInv = theInvEdges.Extent(); |
989 | for (i = 1; i <= aNbEInv; ++i) { |
990 | const TopoDS_Shape& aE = theInvEdges(i); |
991 | BRep_Builder().Add(aCEInv1, aE); |
992 | } |
baaacd46 |
993 | // show valid edges |
ecf4f17c |
994 | TopoDS_Compound aCEVal1; |
995 | BRep_Builder().MakeCompound(aCEVal1); |
996 | aNbEInv = theValidEdges.Extent(); |
997 | for (i = 1; i <= aNbEInv; ++i) { |
998 | const TopoDS_Shape& aE = theValidEdges(i); |
999 | BRep_Builder().Add(aCEVal1, aE); |
1000 | } |
baaacd46 |
1001 | // show inverted edges |
1002 | TopoDS_Compound aCEInverted; |
1003 | BRep_Builder().MakeCompound(aCEInverted); |
1004 | TopTools_MapIteratorOfMapOfShape aItM(theInvertedEdges); |
1005 | for (; aItM.More(); aItM.Next()) { |
1006 | BRep_Builder().Add(aCEInverted, aItM.Value()); |
1007 | } |
ecf4f17c |
1008 | #endif |
2ebb1098 |
1009 | |
e08a9b03 |
1010 | #ifdef OFFSET_DEBUG |
1011 | // Show all obtained splits of faces |
1012 | TopoDS_Compound aCFIm1; |
1013 | BRep_Builder().MakeCompound(aCFIm1); |
1014 | #endif |
1015 | |
2ebb1098 |
1016 | // Build Edge-Face connectivity map to find faces which removal |
1017 | // may potentially lead to creation of the holes in the faces |
1018 | // preventing from obtaining closed volume in the result |
1019 | TopTools_IndexedDataMapOfShapeListOfShape anEFMap; |
1020 | const Standard_Integer aNbF = theFImages.Extent(); |
1021 | for (i = 1; i <= aNbF; ++i) |
1022 | { |
1023 | TopTools_ListIteratorOfListOfShape itLFIm(theFImages(i)); |
1024 | for (; itLFIm.More(); itLFIm.Next()) |
e08a9b03 |
1025 | { |
2ebb1098 |
1026 | TopExp::MapShapesAndAncestors(itLFIm.Value(), TopAbs_EDGE, TopAbs_FACE, anEFMap); |
e08a9b03 |
1027 | #ifdef OFFSET_DEBUG |
1028 | BRep_Builder().Add(aCFIm1, itLFIm.Value()); |
1029 | #endif |
1030 | } |
2ebb1098 |
1031 | } |
1032 | |
ecf4f17c |
1033 | TopTools_ListOfShape anEmptyList; |
0da0275c |
1034 | // invalid faces inside the holes |
1035 | TopTools_IndexedMapOfShape aMFInvInHole; |
1036 | // all hole faces |
1037 | TopoDS_Compound aFHoles; |
1038 | aBB.MakeCompound(aFHoles); |
e08a9b03 |
1039 | // Find the faces containing only the inverted edges and the invalid ones |
1040 | TopTools_ListOfShape anInvertedFaces; |
ecf4f17c |
1041 | // find invalid faces |
1042 | // considering faces containing only invalid edges as invalid |
1043 | aItLF.Initialize(aLFDone); |
1044 | for (; aItLF.More(); aItLF.Next()) { |
0da0275c |
1045 | const TopoDS_Face& aF = TopoDS::Face(aItLF.Value()); |
ecf4f17c |
1046 | TopTools_ListOfShape& aLFImages = theFImages.ChangeFromKey(aF); |
1047 | // |
1048 | TopTools_ListOfShape aLFInv; |
1049 | Standard_Boolean bArtificialCase = theArtInvFaces.IsBound(aF); |
1050 | if (bArtificialCase) { |
1051 | aLFInv = aLFImages; |
1052 | } |
1053 | else { |
1054 | // neutral edges |
1055 | TopTools_ListOfShape* pLNE = aDMFLNE.ChangeSeek(aF); |
1056 | if (!pLNE) { |
1057 | pLNE = &anEmptyList; |
1058 | } |
1059 | // valid inverted edges |
1060 | TopTools_ListOfShape* pLIVE = aDMFLVIE.ChangeSeek(aF); |
1061 | if (!pLIVE) { |
1062 | pLIVE = &anEmptyList; |
1063 | } |
1064 | // |
0da0275c |
1065 | // find faces inside holes wires |
1066 | TopTools_MapOfShape aMFHoles; |
1067 | const TopoDS_Face& aFOr = TopoDS::Face(theFacesOrigins.Find(aF)); |
1068 | FindFacesInsideHoleWires(aFOr, aF, aLFImages, theInvertedEdges, |
2ebb1098 |
1069 | aDMEOrLEIm, anEFMap, aMFHoles, theDMFNewHoles, aCtx); |
0da0275c |
1070 | // |
1071 | TopTools_MapIteratorOfMapOfShape aItMH(aMFHoles); |
1072 | for (; aItMH.More(); aItMH.Next()) { |
1073 | aBB.Add(aFHoles, aItMH.Value()); |
1074 | } |
1075 | // |
1076 | // find invalid faces |
ecf4f17c |
1077 | FindInvalidFaces(aLFImages, theInvEdges, theValidEdges, aDMFLVE, aDMFLIE, |
0da0275c |
1078 | *pLNE, *pLIVE, theInvertedEdges, aMEdgeInvalidByVertex, |
e08a9b03 |
1079 | aMFHoles, aMFInvInHole, aLFInv, anInvertedFaces); |
ecf4f17c |
1080 | } |
1081 | // |
1082 | if (aLFInv.Extent()) { |
1083 | if (theAlreadyInvFaces.IsBound(aF)) { |
1084 | if (theAlreadyInvFaces.Find(aF) > 2) { |
1085 | if (aLFInv.Extent() == aLFImages.Extent() && !bArtificialCase) { |
1086 | aLFImages.Clear(); |
1087 | } |
1088 | // |
1089 | aLFInv.Clear(); |
1090 | } |
1091 | } |
1092 | theInvFaces.Add(aF, aLFInv); |
1093 | } |
1094 | } |
1095 | // |
1096 | if (theInvFaces.IsEmpty()) { |
1097 | theInvEdges.Clear(); |
1098 | return; |
1099 | } |
1100 | // |
1101 | #ifdef OFFSET_DEBUG |
1102 | // show invalid faces |
1103 | TopoDS_Compound aCFInv1; |
1104 | BRep_Builder().MakeCompound(aCFInv1); |
1105 | Standard_Integer aNbFInv = theInvFaces.Extent(); |
1106 | for (i = 1; i <= aNbFInv; ++i) { |
1107 | const TopTools_ListOfShape& aLFInv = theInvFaces(i); |
1108 | TopTools_ListIteratorOfListOfShape aItLFInv(aLFInv); |
1109 | for (; aItLFInv.More(); aItLFInv.Next()) { |
1110 | const TopoDS_Shape& aFIm = aItLFInv.Value(); |
1111 | BRep_Builder().Add(aCFInv1, aFIm); |
1112 | } |
1113 | } |
1114 | #endif |
1115 | // |
1116 | TopTools_IndexedMapOfShape aMERemoved; |
1117 | // remove invalid splits of faces using inverted edges |
baaacd46 |
1118 | RemoveInvalidSplitsByInvertedEdges(theInvertedEdges, theOEOrigins, |
1119 | theInvFaces, theFImages, aMERemoved); |
ecf4f17c |
1120 | if (theInvFaces.IsEmpty()) { |
1121 | theInvEdges.Clear(); |
1122 | return; |
1123 | } |
1124 | // |
1125 | // remove invalid splits from valid splits |
1126 | RemoveInvalidSplitsFromValid(theInvFaces, theArtInvFaces, theInvertedEdges, theFImages); |
1127 | // |
1128 | // remove inside faces |
baaacd46 |
1129 | TopTools_IndexedMapOfShape aMEInside; |
e08a9b03 |
1130 | RemoveInsideFaces(theFImages, theInvFaces, theArtInvFaces, theInvEdges, theInvertedEdges, |
1131 | anInvertedFaces, aMFToCheckInt, aMFInvInHole, aFHoles, theSSInterfs, |
0da0275c |
1132 | aMERemoved, aMEInside, theSolids); |
ecf4f17c |
1133 | // |
1134 | // make compound of valid splits |
1135 | TopoDS_Compound aCFIm; |
1136 | aBB.MakeCompound(aCFIm); |
1137 | // |
1138 | aNb = theFImages.Extent(); |
1139 | for (i = 1; i <= aNb; ++i) { |
1140 | const TopTools_ListOfShape& aLFIm = theFImages(i); |
1141 | aItLF.Initialize(aLFIm); |
1142 | for (; aItLF.More(); aItLF.Next()) { |
1143 | const TopoDS_Shape& aFIm = aItLF.Value(); |
1144 | aBB.Add(aCFIm, aFIm); |
1145 | } |
1146 | } |
1147 | // |
baaacd46 |
1148 | TopTools_IndexedDataMapOfShapeListOfShape aDMEF; |
1149 | TopExp::MapShapesAndAncestors(aCFIm, TopAbs_EDGE, TopAbs_FACE, aDMEF); |
ecf4f17c |
1150 | // |
1151 | // filter maps of images and origins |
1152 | FilterEdgesImages(aCFIm, theOEImages, theOEOrigins); |
1153 | // |
1154 | // filter invalid faces |
baaacd46 |
1155 | FilterInvalidFaces(theFImages, aDMEF, aMEInside, theInvFaces, theArtInvFaces); |
ecf4f17c |
1156 | aNb = theInvFaces.Extent(); |
1157 | if (!aNb) { |
1158 | theInvEdges.Clear(); |
1159 | return; |
1160 | } |
1161 | // |
1162 | #ifdef OFFSET_DEBUG |
1163 | // show invalid faces |
1164 | TopoDS_Compound aCFInv; |
1165 | BRep_Builder().MakeCompound(aCFInv); |
1166 | aNbFInv = theInvFaces.Extent(); |
1167 | for (i = 1; i <= aNbFInv; ++i) { |
1168 | const TopTools_ListOfShape& aLFInv = theInvFaces(i); |
1169 | TopTools_ListIteratorOfListOfShape aItLFInv(aLFInv); |
1170 | for (; aItLFInv.More(); aItLFInv.Next()) { |
1171 | const TopoDS_Shape& aFIm = aItLFInv.Value(); |
1172 | BRep_Builder().Add(aCFInv, aFIm); |
1173 | } |
1174 | } |
1175 | #endif |
1176 | // |
1177 | // filter invalid edges |
1178 | FilterInvalidEdges(theInvFaces, theArtInvFaces, aDMFLIE, aMERemoved, theInvEdges); |
1179 | // |
1180 | #ifdef OFFSET_DEBUG |
1181 | // show invalid edges |
1182 | TopoDS_Compound aCEInv; |
1183 | BRep_Builder().MakeCompound(aCEInv); |
1184 | aNbEInv = theInvEdges.Extent(); |
1185 | for (i = 1; i <= aNbEInv; ++i) { |
1186 | const TopoDS_Shape& aE = theInvEdges(i); |
1187 | BRep_Builder().Add(aCEInv, aE); |
1188 | } |
1189 | #endif |
1190 | // |
1191 | theLastInvEdges.Clear(); |
1192 | aNb = theInvEdges.Extent(); |
1193 | for (i = 1; i <= aNb; ++i) { |
1194 | const TopoDS_Shape& aE = theInvEdges(i); |
1195 | theEdgesToAvoid.Add(aE); |
1196 | theLastInvEdges.Add(aE); |
1197 | } |
1198 | // |
1199 | aNb = theInvFaces.Extent(); |
1200 | for (i = 1; i <= aNb; ++i) { |
1201 | const TopoDS_Shape& aF = theInvFaces.FindKey(i); |
1202 | if (theAlreadyInvFaces.IsBound(aF)) { |
1203 | theAlreadyInvFaces.ChangeFind(aF)++; |
1204 | } |
1205 | else { |
1206 | theAlreadyInvFaces.Bind(aF, 1); |
1207 | } |
1208 | } |
1209 | } |
1210 | |
1211 | //======================================================================= |
1212 | //function : IntersectTrimmedEdges |
1213 | //purpose : Intersection of the trimmed edges among themselves |
1214 | //======================================================================= |
1215 | void IntersectTrimmedEdges(const TopTools_ListOfShape& theLF, |
1216 | const Handle(BRepAlgo_AsDes)& theAsDes, |
1217 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
1218 | TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
1219 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
1220 | Handle(IntTools_Context)& theCtx, |
1221 | TopTools_MapOfShape& theNewEdges, |
1222 | TopTools_DataMapOfShapeShape& theETrimEInf) |
1223 | { |
1224 | if (theLF.IsEmpty()) { |
1225 | return; |
1226 | } |
1227 | // |
1228 | // get edges to intersect from descendants of the offset faces |
1155d05a |
1229 | TopTools_ListOfShape aLS; |
ecf4f17c |
1230 | // |
1231 | TopTools_ListIteratorOfListOfShape aItLF(theLF); |
1232 | for (; aItLF.More(); aItLF.Next()) { |
1233 | const TopoDS_Face& aF = *(TopoDS_Face*)&aItLF.Value(); |
1234 | // |
1235 | const TopTools_ListOfShape& aLE = theAsDes->Descendant(aF); |
1236 | TopTools_ListIteratorOfListOfShape aItLE(aLE); |
1237 | for (; aItLE.More(); aItLE.Next()) { |
1238 | const TopoDS_Edge& aE = *(TopoDS_Edge*)&aItLE.Value(); |
1239 | // |
1240 | if (ProcessMicroEdge(aE, theCtx)) { |
1241 | continue; |
1242 | } |
1243 | // |
1244 | if (theNewEdges.Add(aE)) { |
1245 | aLS.Append(aE); |
1246 | } |
1247 | } |
1248 | } |
1249 | // |
1250 | if (aLS.Extent() < 2) { |
1251 | // nothing to intersect |
1252 | return; |
1253 | } |
1254 | // |
1255 | // perform intersection of the edges |
1256 | BOPAlgo_Builder aGFE; |
1257 | aGFE.SetArguments(aLS); |
1258 | aGFE.Perform(); |
33ba8565 |
1259 | if (aGFE.HasErrors()) { |
ecf4f17c |
1260 | return; |
1261 | } |
1262 | // |
1263 | TopTools_ListOfShape aLA; |
1264 | // fill map with edges images |
1155d05a |
1265 | TopTools_ListIteratorOfListOfShape aIt(aLS); |
ecf4f17c |
1266 | for (; aIt.More(); aIt.Next()) { |
1267 | const TopoDS_Shape& aE = aIt.Value(); |
1268 | const TopTools_ListOfShape& aLEIm = aGFE.Modified(aE); |
1269 | if (aLEIm.IsEmpty()) { |
1270 | continue; |
1271 | } |
1272 | // |
1273 | aLA.Append(aE); |
1274 | // save images |
1275 | theOEImages.Bind(aE, aLEIm); |
1276 | // save origins |
1277 | TopTools_ListIteratorOfListOfShape aItLE(aLEIm); |
1278 | for (; aItLE.More(); aItLE.Next()) { |
1279 | const TopoDS_Shape& aEIm = aItLE.Value(); |
1280 | TopTools_ListOfShape* pLEOr = theOEOrigins.ChangeSeek(aEIm); |
1281 | if (!pLEOr) { |
1282 | pLEOr = theOEOrigins.Bound(aEIm, TopTools_ListOfShape()); |
1283 | } |
1284 | AppendToList(*pLEOr, aE); |
1285 | } |
1286 | } |
1287 | // |
1288 | UpdateOrigins(aLA, theEdgesOrigins, aGFE); |
1289 | UpdateIntersectedEdges(aLA, theETrimEInf, aGFE); |
1290 | } |
1291 | |
1292 | //======================================================================= |
1293 | //function : GetEdges |
1294 | //purpose : Getting edges from AsDes map to build the splits of faces |
1295 | //======================================================================= |
1296 | Standard_Boolean GetEdges(const TopoDS_Face& theFace, |
1297 | const Handle(BRepAlgo_AsDes)& theAsDes, |
1298 | const TopTools_DataMapOfShapeListOfShape& theEImages, |
1299 | const TopTools_MapOfShape& theLastInvEdges, |
1300 | const TopTools_IndexedMapOfShape& theInvEdges, |
1301 | Handle(IntTools_Context)& theCtx, |
1302 | const TopTools_MapOfShape& theModifiedEdges, |
1303 | TopoDS_Shape& theEdges, |
1304 | TopTools_IndexedMapOfShape& theInv) |
1305 | { |
1306 | // get boundary edges |
1307 | TopTools_MapOfShape aMFBounds; |
1308 | TopExp_Explorer aExp(theFace, TopAbs_EDGE); |
1309 | for (; aExp.More(); aExp.Next()) { |
1310 | const TopoDS_Shape& aE = aExp.Current(); |
1311 | const TopTools_ListOfShape* pLEIm = theEImages.Seek(aE); |
1312 | if (!pLEIm) { |
1313 | aMFBounds.Add(aE); |
1314 | } |
1315 | else { |
1316 | TopTools_ListIteratorOfListOfShape aItLE(*pLEIm); |
1317 | for (; aItLE.More(); aItLE.Next()) { |
1318 | const TopoDS_Shape& aEIm = aItLE.Value(); |
1319 | aMFBounds.Add(aEIm); |
1320 | } |
1321 | } |
1322 | } |
1323 | // |
1324 | BRep_Builder aBB; |
1325 | Standard_Boolean bFound(Standard_False), bUpdate(Standard_False); |
1326 | // the resulting edges |
1327 | TopoDS_Compound anEdges; |
1328 | aBB.MakeCompound(anEdges); |
bc4a3867 |
1329 | // Fence map |
1330 | TopTools_MapOfShape aMEFence; |
ecf4f17c |
1331 | // the edges by which the offset face should be split |
1332 | const TopTools_ListOfShape& aLE = theAsDes->Descendant(theFace); |
1333 | TopTools_ListIteratorOfListOfShape aItLE(aLE); |
1334 | for (; aItLE.More(); aItLE.Next()) { |
1335 | const TopoDS_Edge& aE = TopoDS::Edge(aItLE.Value()); |
1336 | // |
1337 | if (!bUpdate) { |
1338 | bUpdate = theModifiedEdges.Contains(aE); |
1339 | } |
1340 | // |
1341 | const TopTools_ListOfShape* pLEIm = theEImages.Seek(aE); |
1342 | if (pLEIm) { |
1343 | TopTools_ListIteratorOfListOfShape aItLEIm(*pLEIm); |
1344 | for (; aItLEIm.More(); aItLEIm.Next()) { |
1345 | const TopoDS_Edge& aEIm = TopoDS::Edge(aItLEIm.Value()); |
1346 | // |
bc4a3867 |
1347 | if (!aMEFence.Add(aEIm)) |
1348 | continue; |
1349 | |
ecf4f17c |
1350 | if (theInvEdges.Contains(aEIm)) { |
1351 | theInv.Add(aEIm); |
1352 | if (!bUpdate) { |
1353 | bUpdate = theLastInvEdges.Contains(aEIm); |
1354 | } |
1355 | continue; |
1356 | } |
1357 | // check for micro edge |
1358 | if (ProcessMicroEdge(aEIm, theCtx)) { |
1359 | continue; |
1360 | } |
1361 | // |
1362 | aBB.Add(anEdges, aEIm); |
1363 | if (!bFound) { |
1364 | bFound = !aMFBounds.Contains(aEIm); |
1365 | } |
1366 | // |
1367 | if (!bUpdate) { |
1368 | bUpdate = theModifiedEdges.Contains(aEIm); |
1369 | } |
1370 | } |
1371 | } |
1372 | else { |
1373 | if (theInvEdges.Contains(aE)) { |
1374 | theInv.Add(aE); |
1375 | if (!bUpdate) { |
1376 | bUpdate = theLastInvEdges.Contains(aE); |
1377 | } |
1378 | continue; |
1379 | } |
1380 | // |
1381 | if (ProcessMicroEdge(aE, theCtx)) { |
1382 | continue; |
1383 | } |
1384 | aBB.Add(anEdges, aE); |
1385 | if (!bFound) { |
1386 | bFound = !aMFBounds.Contains(aE); |
1387 | } |
1388 | } |
1389 | } |
1390 | // |
1391 | theEdges = anEdges; |
1392 | return bFound && bUpdate; |
1393 | } |
1394 | |
1395 | //======================================================================= |
1396 | //function : BuildSplitsOfFace |
1397 | //purpose : Building the splits of offset face |
1398 | //======================================================================= |
1399 | void BuildSplitsOfFace(const TopoDS_Face& theFace, |
1400 | const TopoDS_Shape& theEdges, |
ecf4f17c |
1401 | TopTools_DataMapOfShapeShape& theFacesOrigins, |
1402 | TopTools_ListOfShape& theLFImages) |
a8232603 |
1403 | { |
1404 | theLFImages.Clear(); |
1405 | // |
1406 | // take edges to split the face |
1155d05a |
1407 | TopTools_ListOfShape aLE; |
a8232603 |
1408 | TopExp_Explorer aExp(theEdges, TopAbs_EDGE); |
1409 | for (; aExp.More(); aExp.Next()) { |
1410 | TopoDS_Edge aE = TopoDS::Edge(aExp.Current()); |
1411 | aE.Orientation(TopAbs_FORWARD); |
1412 | aLE.Append(aE); |
1413 | aE.Orientation(TopAbs_REVERSED); |
1414 | aLE.Append(aE); |
1415 | } |
1416 | // |
1417 | TopoDS_Face aFF = theFace; |
1418 | TopAbs_Orientation anOr = theFace.Orientation(); |
1419 | aFF.Orientation(TopAbs_FORWARD); |
1420 | // |
1421 | // build pcurves for edges on the face |
f16a6cc5 |
1422 | BRepLib::BuildPCurveForEdgesOnPlane(aLE, aFF); |
a8232603 |
1423 | // |
1424 | // build splits of faces |
1425 | BOPAlgo_BuilderFace aBF; |
1426 | aBF.SetFace(aFF); |
1427 | aBF.SetShapes(aLE); |
1428 | aBF.Perform(); |
1429 | // |
1155d05a |
1430 | const TopTools_ListOfShape& aLFSp = aBF.Areas(); |
1431 | TopTools_ListIteratorOfListOfShape aItLF(aLFSp); |
a8232603 |
1432 | for (; aItLF.More(); aItLF.Next()) { |
1433 | TopoDS_Shape& aFSp = aItLF.ChangeValue(); |
1434 | aFSp.Orientation(anOr); |
1435 | theLFImages.Append(aFSp); |
1436 | // |
1437 | theFacesOrigins.Bind(aFSp, theFace); |
1438 | } |
1439 | } |
1440 | |
1441 | //======================================================================= |
1442 | //function : BuildSplitsOfFace |
1443 | //purpose : Building the splits of offset face |
1444 | //======================================================================= |
1445 | void BuildSplitsOfTrimmedFace(const TopoDS_Face& theFace, |
1446 | const TopoDS_Shape& theEdges, |
1447 | TopTools_ListOfShape& theLFImages) |
ecf4f17c |
1448 | { |
1449 | BOPAlgo_Builder aGF; |
1450 | // |
1451 | aGF.AddArgument(theFace); |
1452 | aGF.AddArgument(theEdges); |
1453 | aGF.Perform(); |
33ba8565 |
1454 | if (aGF.HasErrors()) { |
ecf4f17c |
1455 | return; |
1456 | } |
1457 | // |
1458 | // splits of the offset shape |
1459 | theLFImages = aGF.Modified(theFace); |
ecf4f17c |
1460 | } |
1461 | |
1462 | //======================================================================= |
1463 | //function : CheckIfArtificial |
1464 | //purpose : Checks if the face is artificially invalid |
1465 | //======================================================================= |
1466 | Standard_Boolean CheckIfArtificial(const TopoDS_Shape& theF, |
1467 | const TopTools_ListOfShape& theLFImages, |
1468 | const TopoDS_Shape& theCE, |
1469 | const TopTools_IndexedMapOfShape& theMapEInv, |
1470 | const TopTools_DataMapOfShapeListOfShape& theOEImages, |
1471 | TopTools_MapOfShape& theMENInv, |
1472 | Handle(BRepAlgo_AsDes)& theAsDes) |
1473 | { |
1474 | // all boundary edges should be used |
1475 | TopTools_IndexedMapOfShape aMEUsed; |
1476 | TopTools_ListIteratorOfListOfShape aItLFIm(theLFImages); |
1477 | for (; aItLFIm.More(); aItLFIm.Next()) { |
1478 | const TopoDS_Shape& aFIm = aItLFIm.Value(); |
1479 | TopExp::MapShapes(aFIm, TopAbs_EDGE, aMEUsed); |
1480 | TopExp::MapShapes(aFIm, TopAbs_VERTEX, aMEUsed); |
1481 | } |
1482 | // |
1483 | TopTools_IndexedDataMapOfShapeListOfShape aMVE; |
1484 | TopExp::MapShapesAndAncestors(theCE, TopAbs_VERTEX, TopAbs_EDGE, aMVE); |
1485 | // |
1486 | Standard_Integer i, aNb = theMapEInv.Extent(); |
1487 | for (i = 1; i <= aNb; ++i) { |
1488 | const TopoDS_Shape& aEInv = theMapEInv(i); |
1489 | TopExp_Explorer aExpV(aEInv, TopAbs_VERTEX); |
1490 | for (; aExpV.More(); aExpV.Next()) { |
1491 | const TopoDS_Shape& aVEInv = aExpV.Current(); |
b443d536 |
1492 | const TopTools_ListOfShape* pLENInv = aMVE.Seek(aVEInv); |
1493 | if (pLENInv) { |
1494 | TopTools_ListIteratorOfListOfShape aItLEInv(*pLENInv); |
ecf4f17c |
1495 | for (; aItLEInv.More(); aItLEInv.Next()) { |
1496 | const TopoDS_Shape& aENInv = aItLEInv.Value(); |
b443d536 |
1497 | if (!aMEUsed.Contains(aENInv)) { |
1498 | theMENInv.Add(aENInv); |
1499 | } |
ecf4f17c |
1500 | } |
1501 | } |
1502 | } |
1503 | } |
1504 | // |
1505 | if (theMENInv.IsEmpty()) { |
1506 | return Standard_False; |
1507 | } |
1508 | // |
1509 | TopTools_IndexedMapOfShape aMEFound; |
1510 | TopExp::MapShapes(theCE, TopAbs_EDGE, aMEFound); |
1511 | // |
1512 | const TopTools_ListOfShape& aLE = theAsDes->Descendant(theF); |
1513 | TopTools_ListIteratorOfListOfShape aItLE(aLE); |
1514 | for (; aItLE.More(); aItLE.Next()) { |
1515 | const TopoDS_Edge& aE = TopoDS::Edge(aItLE.Value()); |
1516 | // |
1517 | if (theOEImages.IsBound(aE)) { |
1518 | Standard_Boolean bChecked = Standard_False; |
1519 | const TopTools_ListOfShape& aLEIm = theOEImages.Find(aE); |
1520 | TopTools_ListIteratorOfListOfShape aItLEIm(aLEIm); |
1521 | for (; aItLEIm.More(); aItLEIm.Next()) { |
1522 | const TopoDS_Edge& aEIm = TopoDS::Edge(aItLEIm.Value()); |
1523 | if (!aMEFound.Contains(aEIm) || theMENInv.Contains(aEIm)) { |
1524 | continue; |
1525 | } |
1526 | // |
1527 | bChecked = Standard_True; |
1528 | if (aMEUsed.Contains(aEIm)) { |
1529 | break; |
1530 | } |
1531 | } |
1532 | // |
1533 | if (bChecked && !aItLEIm.More()) { |
1534 | break; |
1535 | } |
1536 | } |
1537 | else { |
1538 | if (aMEFound.Contains(aE) && !theMENInv.Contains(aE) && !aMEUsed.Contains(aE)) { |
1539 | break; |
1540 | } |
1541 | } |
1542 | } |
1543 | // |
1544 | return aItLE.More(); |
1545 | } |
1546 | |
1547 | //======================================================================= |
1548 | //function : FindInvalidEdges |
1549 | //purpose : Looking for the invalid edges |
1550 | //======================================================================= |
1551 | void FindInvalidEdges(const TopoDS_Face& theF, |
1552 | const TopTools_ListOfShape& theLFImages, |
1553 | const TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
1554 | const TopTools_DataMapOfShapeShape& theFacesOrigins, |
1555 | const TopTools_DataMapOfShapeListOfShape& theOEImages, |
1556 | const TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
1557 | TopTools_IndexedMapOfShape& theInvEdges, |
1558 | TopTools_IndexedMapOfShape& theValidEdges, |
1559 | TopTools_DataMapOfShapeListOfShape& theDMFLVE, |
1560 | TopTools_DataMapOfShapeListOfShape& theDMFLNE, |
1561 | TopTools_DataMapOfShapeListOfShape& theDMFLIE, |
1562 | TopTools_DataMapOfShapeListOfShape& theDMFLVIE, |
0da0275c |
1563 | TopTools_DataMapOfShapeListOfShape& theDMEOrLEIm, |
ecf4f17c |
1564 | TopTools_MapOfShape& theMEInverted, |
1565 | TopTools_MapOfShape& theEdgesInvalidByVertex) |
1566 | { |
1567 | // Edge is considered as invalid in the following cases: |
1568 | // 1. Its orientation on the face has changed comparing to the originals edge and face; |
1569 | // 2. The vertices of the edge have changed places comparing to the originals edge and face. |
1570 | // |
1571 | // The edges created from vertices, i.e. as intersection between two faces connected only |
1572 | // by VERTEX, will also be checked on validity. For these edges the correct orientation will |
1573 | // be defined by the edges on the original face adjacent to the connection vertex |
0da0275c |
1574 | |
1575 | // original face |
ecf4f17c |
1576 | const TopoDS_Face& aFOr = *(TopoDS_Face*)&theFacesOrigins.Find(theF); |
b443d536 |
1577 | // invalid edges |
ecf4f17c |
1578 | TopTools_IndexedMapOfShape aMEInv; |
1579 | // valid edges |
1580 | TopTools_MapOfShape aMEVal; |
1581 | // internal edges |
1582 | TopTools_MapOfShape aMEInt; |
1583 | // |
1584 | // maps for checking the inverted edges |
1585 | TopTools_IndexedDataMapOfShapeListOfShape aDMVE, aDMEF; |
1586 | TopTools_IndexedMapOfShape aMEdges; |
1587 | // |
1588 | TopTools_ListIteratorOfListOfShape aItLF(theLFImages); |
1589 | for (; aItLF.More(); aItLF.Next()) { |
1590 | const TopoDS_Face& aFIm = *(TopoDS_Face*)&aItLF.Value(); |
1591 | // |
1592 | TopExp_Explorer aExp(aFIm, TopAbs_EDGE); |
1593 | for (; aExp.More(); aExp.Next()) { |
1594 | const TopoDS_Shape& aE = aExp.Current(); |
1595 | // keep all edges |
1596 | aMEdges.Add(aE); |
1597 | // |
1598 | // keep connection from edges to faces |
1599 | TopTools_ListOfShape* pLF = aDMEF.ChangeSeek(aE); |
1600 | if (!pLF) { |
1601 | pLF = &aDMEF(aDMEF.Add(aE, TopTools_ListOfShape())); |
1602 | } |
1603 | AppendToList(*pLF, aFIm); |
1604 | // |
1605 | // keep connection from vertices to edges |
1606 | TopoDS_Iterator aItV(aE); |
1607 | for (; aItV.More(); aItV.Next()) { |
1608 | const TopoDS_Shape& aV = aItV.Value(); |
1609 | // |
1610 | TopTools_ListOfShape* pLE = aDMVE.ChangeSeek(aV); |
1611 | if (!pLE) { |
1612 | pLE = &aDMVE(aDMVE.Add(aV, TopTools_ListOfShape())); |
1613 | } |
1614 | AppendToList(*pLE, aE); |
1615 | } |
1616 | } |
1617 | } |
1618 | // |
1619 | // the map will be used to find the edges on the original face |
1620 | // adjacent to the same vertex. It will be filled at first necessity; |
1621 | TopTools_IndexedDataMapOfShapeListOfShape aDMVEFOr; |
1622 | // |
1623 | aItLF.Initialize(theLFImages); |
1624 | for (; aItLF.More(); aItLF.Next()) { |
1625 | const TopoDS_Face& aFIm = *(TopoDS_Face*)&aItLF.Value(); |
1626 | // |
1627 | // valid edges for this split |
1628 | TopTools_ListOfShape aLVE; |
1629 | // invalid edges for this split |
1630 | TopTools_ListOfShape aLIE; |
1631 | // |
1632 | TopExp_Explorer aExp(aFIm, TopAbs_EDGE); |
1633 | for (; aExp.More(); aExp.Next()) { |
1634 | const TopoDS_Edge& aEIm = *(TopoDS_Edge*)&aExp.Current(); |
1635 | // |
1636 | if (aEIm.Orientation() == TopAbs_INTERNAL) { |
1637 | aMEInt.Add(aEIm); |
1638 | continue; |
1639 | } |
1640 | // |
1641 | if (!theEdgesOrigins.IsBound(aEIm)) { |
1642 | continue; |
1643 | } |
1644 | // |
1645 | const TopTools_ListOfShape& aLEOr = theEdgesOrigins.Find(aEIm); |
1646 | if (aLEOr.IsEmpty()) { |
1647 | continue; |
1648 | } |
1649 | // |
1650 | Standard_Integer aNbVOr = 0; |
1651 | TopTools_ListIteratorOfListOfShape aItLEO(aLEOr); |
1652 | for (; aItLEO.More(); aItLEO.Next()) { |
1653 | if (aItLEO.Value().ShapeType() == TopAbs_VERTEX) { |
1654 | ++aNbVOr; |
1655 | } |
1656 | } |
1657 | // |
1658 | TopTools_MapOfShape aME, aMV; |
1659 | Standard_Boolean bInvalid = Standard_False, bChecked = Standard_False; |
1660 | Standard_Integer aNbP = NbPoints(aEIm); |
b443d536 |
1661 | Standard_Boolean bUseVertex = !aNbVOr ? Standard_False : |
1662 | (aNbVOr == 1 && |
1663 | aDMEF.FindFromKey(aEIm).Extent() == 1 && |
1664 | !theOEOrigins.IsBound(aEIm)); |
1665 | // |
ecf4f17c |
1666 | aItLEO.Initialize(aLEOr); |
1667 | for (; aItLEO.More(); aItLEO.Next()) { |
1668 | const TopoDS_Shape& aSOr = aItLEO.Value(); |
1669 | Standard_Boolean bVertex = (aSOr.ShapeType() == TopAbs_VERTEX); |
1670 | // |
1671 | TopoDS_Shape aEOrF; |
1672 | if (bVertex) { |
1673 | // for some cases it is impossible to check the validity of the edge |
b443d536 |
1674 | if (!bUseVertex) { |
ecf4f17c |
1675 | continue; |
1676 | } |
ecf4f17c |
1677 | // find edges on the original face adjacent to this vertex |
1678 | if (aDMVEFOr.IsEmpty()) { |
1679 | // fill the map |
1680 | TopExp::MapShapesAndAncestors(aFOr, TopAbs_VERTEX, TopAbs_EDGE, aDMVEFOr); |
1681 | } |
1682 | // |
1683 | TopTools_ListOfShape *pLEFOr = aDMVEFOr.ChangeSeek(aSOr); |
1684 | if (pLEFOr) { |
1685 | TopoDS_Compound aCEOr; |
1686 | BRep_Builder().MakeCompound(aCEOr); |
1687 | TopTools_ListIteratorOfListOfShape aItLEFOr(*pLEFOr); |
1688 | for (; aItLEFOr.More(); aItLEFOr.Next()) { |
1689 | const TopoDS_Shape& aEOr = aItLEFOr.Value(); |
1690 | BRep_Builder().Add(aCEOr, aEOr); |
1691 | } |
1692 | aEOrF = aCEOr; |
1693 | } |
1694 | } |
1695 | else { |
1696 | FindShape(aSOr, aFOr, aEOrF); |
0da0275c |
1697 | // |
1698 | TopTools_ListOfShape *pLEIm = theDMEOrLEIm.ChangeSeek(aSOr); |
1699 | if (!pLEIm) { |
1700 | pLEIm = theDMEOrLEIm.Bound(aSOr, TopTools_ListOfShape()); |
1701 | } |
1702 | AppendToList(*pLEIm, aEIm); |
ecf4f17c |
1703 | } |
1704 | // |
1705 | if (aEOrF.IsNull()) { |
1706 | // the edge has not been found |
1707 | continue; |
1708 | } |
1709 | // |
1710 | // Check orientations of the image edge and original edge. |
1711 | // In case the 3d curves are having the same direction the orientations |
1712 | // must be the same. Otherwise the orientations should also be different. |
1713 | // |
1714 | // get average tangent vector for each curve taking into account |
1715 | // the orientations of the edges, i.e. the edge is reversed |
1716 | // the vector is reversed as well |
1717 | gp_Vec aVSum1 = GetAverageTangent(aEIm, aNbP); |
1718 | gp_Vec aVSum2 = GetAverageTangent(aEOrF, aNbP); |
1719 | // |
1720 | aVSum1.Normalize(); |
1721 | aVSum2.Normalize(); |
1722 | // |
1723 | Standard_Real aCos = aVSum1.Dot(aVSum2); |
1724 | if (!bVertex) { |
1725 | if (Abs(aCos) < 0.9999) { |
1726 | continue; |
1727 | } |
1728 | // |
1729 | aME.Add(aEOrF); |
1730 | TopExp_Explorer aExpE(aEOrF, TopAbs_VERTEX); |
1731 | for (; aExpE.More(); aExpE.Next()) { |
1732 | const TopoDS_Shape& aV = aExpE.Current(); |
1733 | aMV.Add(aV); |
1734 | } |
1735 | } |
1736 | // |
1737 | if (aCos < Precision::Confusion()) { |
1738 | bInvalid = Standard_True; |
1739 | if (bVertex) { |
1740 | theEdgesInvalidByVertex.Add(aEIm); |
1741 | } |
1742 | } |
1743 | bChecked = Standard_True; |
1744 | } |
1745 | // |
1746 | if (!bChecked) { |
1747 | continue; |
1748 | } |
1749 | // |
1750 | Standard_Integer aNbE = aME.Extent(), aNbV = aMV.Extent(); |
1751 | if ((aNbE > 1) && (aNbV == 2*aNbE)) { |
1752 | continue; |
1753 | } |
1754 | // |
1755 | if (bInvalid) { |
1756 | theInvEdges.Add(aEIm); |
1757 | aLIE.Append(aEIm); |
1758 | aMEInv.Add(aEIm); |
1759 | continue; |
1760 | } |
1761 | // |
1762 | // check if the edge has been inverted |
b443d536 |
1763 | Standard_Boolean bInverted = !aNbE ? Standard_False : |
1764 | CheckInverted(aEIm, aFOr, theOEImages, theOEOrigins, |
b6725456 |
1765 | theEdgesOrigins, aDMVE, aMEdges, theMEInverted); |
ecf4f17c |
1766 | // |
1767 | if (!bInverted || !aNbVOr) { |
1768 | theValidEdges.Add(aEIm); |
1769 | aLVE.Append(aEIm); |
1770 | aMEVal.Add(aEIm); |
1771 | } |
1772 | } |
1773 | // |
1774 | // valid edges |
1775 | if (aLVE.Extent()) { |
1776 | theDMFLVE.Bind(aFIm, aLVE); |
1777 | } |
1778 | // |
1779 | // invalid edges |
1780 | if (aLIE.Extent()) { |
1781 | theDMFLIE.Bind(aFIm, aLIE); |
1782 | } |
1783 | } |
1784 | // |
1785 | // process invalid edges: |
1786 | // check for the inverted edges |
1787 | TopTools_ListOfShape aLVIE; |
1788 | // fill neutral edges |
1789 | TopTools_ListOfShape aLNE; |
1790 | // |
1791 | Standard_Integer i, aNbEInv = aMEInv.Extent(); |
1792 | for (i = 1; i <= aNbEInv; ++i) { |
1793 | const TopoDS_Shape& aEIm = aMEInv(i); |
1794 | // |
1795 | // neutral edges - on the splits of the same offset face |
1796 | // it is valid for one split and invalid for other |
1797 | if (aMEVal.Contains(aEIm)) { |
1798 | aLNE.Append(aEIm); |
1799 | continue; |
1800 | } |
1801 | // |
1802 | // the inverted images of the origins of invalid edges should also be invalid |
1803 | if (!theMEInverted.Contains(aEIm)) { |
1804 | continue; |
1805 | } |
1806 | // |
1807 | const TopTools_ListOfShape* pLOEOr = theOEOrigins.Seek(aEIm); |
1808 | if (!pLOEOr) { |
1809 | continue; |
1810 | } |
1811 | // |
1812 | TopTools_ListIteratorOfListOfShape aItLOEOr(*pLOEOr); |
1813 | for (; aItLOEOr.More(); aItLOEOr.Next()) { |
1814 | const TopoDS_Shape& aOEOr = aItLOEOr.Value(); |
1815 | const TopTools_ListOfShape& aLEIm1 = theOEImages.Find(aOEOr); |
1816 | // |
1817 | TopTools_ListIteratorOfListOfShape aItLEIm1(aLEIm1); |
1818 | for (; aItLEIm1.More(); aItLEIm1.Next()) { |
1819 | const TopoDS_Shape& aEIm1 = aItLEIm1.Value(); |
1820 | if (aMEdges.Contains(aEIm1) && |
1821 | !aMEInv.Contains(aEIm1) && !aMEInt.Contains(aEIm1) && |
1822 | theMEInverted.Contains(aEIm1)) { |
1823 | theInvEdges.Add(aEIm1); |
1824 | aLVIE.Append(aEIm1); |
1825 | } |
1826 | } |
1827 | } |
1828 | } |
1829 | // |
1830 | if (aLNE.Extent()) { |
1831 | theDMFLNE.Bind(theF, aLNE); |
1832 | } |
1833 | // |
1834 | if (aLVIE.Extent()) { |
1835 | theDMFLVIE.Bind(theF, aLVIE); |
1836 | } |
1837 | } |
1838 | |
1839 | //======================================================================= |
1840 | //function : FindInvalidFaces |
1841 | //purpose : Looking for the invalid faces by analyzing their invalid edges |
1842 | //======================================================================= |
1843 | void FindInvalidFaces(TopTools_ListOfShape& theLFImages, |
1844 | const TopTools_IndexedMapOfShape& theInvEdges, |
1845 | const TopTools_IndexedMapOfShape& theValidEdges, |
1846 | const TopTools_DataMapOfShapeListOfShape& theDMFLVE, |
1847 | const TopTools_DataMapOfShapeListOfShape& theDMFLIE, |
1848 | const TopTools_ListOfShape& theLENeutral, |
1849 | const TopTools_ListOfShape& theLEValInverted, |
1850 | const TopTools_MapOfShape& theMEInverted, |
1851 | const TopTools_MapOfShape& theEdgesInvalidByVertex, |
0da0275c |
1852 | const TopTools_MapOfShape& theMFHoles, |
1853 | TopTools_IndexedMapOfShape& theMFInvInHole, |
e08a9b03 |
1854 | TopTools_ListOfShape& theInvFaces, |
1855 | TopTools_ListOfShape& theInvertedFaces) |
ecf4f17c |
1856 | { |
1857 | // The face should be considered as invalid in the following cases: |
1858 | // 1. It has been reverted, i.e. at least two not connected edges |
1859 | // have changed orientation (i.e. invalid). In this case all edges, |
1860 | // should be invalid for that face, because edges have also been reverted; |
1861 | // 2. All checked edges of the face are invalid for this face; |
1862 | // The face should be removed from the splits in the following cases: |
1863 | // 1. All checked edges of the face are invalid for this one, but valid for |
1864 | // some other face in this list of splits. |
1865 | // The face will be kept in the following cases: |
1866 | // 1. Some of the edges are valid for this face. |
1867 | Standard_Boolean bHasValid, bAllValid, bAllInvalid, bHasReallyInvalid, bAllInvNeutral; |
e08a9b03 |
1868 | Standard_Boolean bValid, bValidLoc, bInvalid, bInvalidLoc, bNeutral, bInverted; |
1869 | Standard_Boolean bIsInvalidByInverted; |
ecf4f17c |
1870 | Standard_Integer i, aNbChecked; |
1871 | // |
1872 | // neutral edges |
1873 | TopTools_MapOfShape aMEN; |
45d0af05 |
1874 | for (TopTools_ListIteratorOfListOfShape aItLE(theLENeutral); aItLE.More(); aItLE.Next()) |
1875 | { |
ecf4f17c |
1876 | aMEN.Add(aItLE.Value()); |
1877 | } |
1878 | // |
1879 | // valid inverted edges |
1880 | TopTools_MapOfShape aMEValInverted; |
45d0af05 |
1881 | for (TopTools_ListIteratorOfListOfShape aItLE(theLEValInverted); aItLE.More(); aItLE.Next()) |
1882 | { |
ecf4f17c |
1883 | aMEValInverted.Add(aItLE.Value()); |
1884 | } |
1885 | // |
e08a9b03 |
1886 | Standard_Boolean bTreatInvertedAsInvalid = (theLFImages.Extent() == 1); |
ecf4f17c |
1887 | // |
1888 | // neutral edges to remove |
1889 | TopTools_IndexedMapOfShape aMENRem; |
1890 | // |
1891 | // faces for post treat |
1892 | TopTools_ListOfShape aLFPT; |
1893 | // |
1894 | TopTools_ListIteratorOfListOfShape aItLF(theLFImages); |
1895 | for (; aItLF.More(); ) { |
1896 | const TopoDS_Face& aFIm = *(TopoDS_Face*)&aItLF.Value(); |
1897 | // |
1898 | // valid edges for this split |
1899 | TopTools_MapOfShape aMVE; |
1900 | // invalid edges for this split |
1901 | TopTools_MapOfShape aMIE; |
1902 | // |
1903 | for (i = 0; i < 2; ++i) { |
1904 | TopTools_MapOfShape& aME = !i ? aMVE : aMIE; |
1905 | const TopTools_ListOfShape* pLE = !i ? theDMFLVE.Seek(aFIm) : theDMFLIE.Seek(aFIm); |
1906 | if (pLE) { |
1907 | TopTools_ListIteratorOfListOfShape aItLE(*pLE); |
1908 | for (; aItLE.More(); aItLE.Next()) { |
1909 | const TopoDS_Shape& aE = aItLE.Value(); |
1910 | aME.Add(aE); |
1911 | } |
1912 | } |
1913 | } |
1914 | // |
1915 | bHasValid = Standard_False; |
1916 | bAllValid = Standard_True; |
1917 | bAllInvalid = Standard_True; |
1918 | bHasReallyInvalid = Standard_False; |
1919 | bAllInvNeutral = Standard_True; |
e08a9b03 |
1920 | bIsInvalidByInverted = Standard_True; |
ecf4f17c |
1921 | aNbChecked = 0; |
1922 | // |
1923 | const TopoDS_Wire& aWIm = BRepTools::OuterWire(aFIm); |
1924 | TopExp_Explorer aExp(aWIm, TopAbs_EDGE); |
1925 | for (; aExp.More(); aExp.Next()) { |
1926 | const TopoDS_Shape& aEIm = aExp.Current(); |
1927 | // |
1928 | bValid = theValidEdges.Contains(aEIm); |
1929 | bInvalid = theInvEdges.Contains(aEIm); |
1930 | // |
1931 | if (!bValid && !bInvalid) { |
1932 | // edge has not been checked for some reason |
1933 | continue; |
1934 | } |
1935 | // |
1936 | ++aNbChecked; |
1937 | // |
1938 | bInvalidLoc = aMIE.Contains(aEIm); |
1939 | bHasReallyInvalid = bInvalidLoc && !bValid && !theEdgesInvalidByVertex.Contains(aEIm); |
1940 | if (bHasReallyInvalid) { |
1941 | break; |
1942 | } |
1943 | // |
1944 | bNeutral = aMEN.Contains(aEIm); |
1945 | bValidLoc = aMVE.Contains(aEIm); |
1946 | // |
e08a9b03 |
1947 | bInverted = theMEInverted.Contains(aEIm); |
1948 | if (!bInvalid && bTreatInvertedAsInvalid) { |
1949 | bInvalid = bInverted; |
ecf4f17c |
1950 | } |
1951 | // |
1952 | if (bValidLoc && (bNeutral || aMEValInverted.Contains(aEIm))) { |
1953 | bHasValid = Standard_True; |
1954 | } |
1955 | // |
e08a9b03 |
1956 | bAllValid &= bValidLoc; |
1957 | bAllInvalid &= bInvalid; |
1958 | bAllInvNeutral &= (bAllInvalid && bNeutral); |
1959 | bIsInvalidByInverted &= (bInvalidLoc || bInverted); |
ecf4f17c |
1960 | } |
1961 | // |
1962 | if (!aNbChecked) { |
1963 | aItLF.Next(); |
1964 | continue; |
1965 | } |
1966 | // |
1967 | if (!bHasReallyInvalid && (bAllInvNeutral && !bHasValid) && (aNbChecked > 1)) { |
1968 | // remove edges from neutral |
1969 | TopExp::MapShapes(aFIm, TopAbs_EDGE, aMENRem); |
1970 | // remove face |
1971 | theLFImages.Remove(aItLF); |
1972 | continue; |
1973 | } |
1974 | // |
1975 | if (bHasReallyInvalid || (bAllInvalid && |
1976 | !(bHasValid || bAllValid) && |
1977 | !(bAllInvNeutral && (aNbChecked == 1)))) { |
1978 | theInvFaces.Append(aFIm); |
0da0275c |
1979 | if (theMFHoles.Contains(aFIm)) { |
1980 | theMFInvInHole.Add(aFIm); |
1981 | } |
a8232603 |
1982 | aItLF.Next(); |
1983 | continue; |
ecf4f17c |
1984 | } |
1985 | // |
0da0275c |
1986 | if (theMFHoles.Contains(aFIm)) { |
1987 | // remove edges from neutral |
1988 | TopExp::MapShapes(aFIm, TopAbs_EDGE, aMENRem); |
1989 | // remove face |
1990 | theLFImages.Remove(aItLF); |
1991 | continue; |
1992 | } |
1993 | // |
e08a9b03 |
1994 | if (bIsInvalidByInverted && !(bHasValid || bAllValid)) |
1995 | { |
1996 | // The face contains only the inverted and locally invalid edges |
1997 | theInvertedFaces.Append(aFIm); |
1998 | } |
1999 | |
ecf4f17c |
2000 | if (!bAllInvNeutral) { |
2001 | aLFPT.Append(aFIm); |
2002 | } |
2003 | else { |
2004 | // remove edges from neutral |
2005 | TopExp::MapShapes(aFIm, TopAbs_EDGE, aMENRem); |
2006 | } |
2007 | aItLF.Next(); |
2008 | } |
2009 | // |
2010 | if (aLFPT.IsEmpty() || aMENRem.IsEmpty()) { |
2011 | return; |
2012 | } |
2013 | // |
2014 | Standard_Integer aNb = aMENRem.Extent(); |
2015 | for (i = 1; i <= aNb; ++i) { |
2016 | aMEN.Remove(aMENRem(i)); |
2017 | } |
2018 | // |
2019 | // check the splits once more |
2020 | aItLF.Initialize(aLFPT); |
2021 | for (; aItLF.More(); aItLF.Next()) { |
2022 | const TopoDS_Face& aFIm = *(TopoDS_Face*)&aItLF.Value(); |
2023 | // |
2024 | // valid edges for this split |
2025 | TopTools_MapOfShape aMVE; |
2026 | const TopTools_ListOfShape* pLVE = theDMFLVE.Seek(aFIm); |
2027 | if (pLVE) { |
2028 | TopTools_ListIteratorOfListOfShape aItLE(*pLVE); |
2029 | for (; aItLE.More(); aItLE.Next()) { |
2030 | const TopoDS_Shape& aE = aItLE.Value(); |
2031 | aMVE.Add(aE); |
2032 | } |
2033 | } |
2034 | // |
2035 | bHasValid = Standard_False; |
2036 | bAllValid = Standard_True; |
2037 | bAllInvalid = Standard_True; |
2038 | // |
2039 | const TopoDS_Wire& aWIm = BRepTools::OuterWire(aFIm); |
2040 | TopExp_Explorer aExp(aWIm, TopAbs_EDGE); |
2041 | for (; aExp.More(); aExp.Next()) { |
2042 | const TopoDS_Shape& aEIm = aExp.Current(); |
2043 | // |
2044 | bValid = theValidEdges.Contains(aEIm); |
2045 | bInvalid = theInvEdges.Contains(aEIm); |
2046 | bNeutral = aMEN.Contains(aEIm); |
2047 | bValidLoc = aMVE.Contains(aEIm); |
2048 | // |
e08a9b03 |
2049 | if (!bInvalid && bTreatInvertedAsInvalid) { |
ecf4f17c |
2050 | bInvalid = theMEInverted.Contains(aEIm); |
2051 | } |
2052 | // |
2053 | if (bValidLoc && (bNeutral || aMEValInverted.Contains(aEIm))) { |
2054 | bHasValid = Standard_True; |
2055 | } |
2056 | // |
2057 | bAllValid = bAllValid && bValidLoc; |
2058 | bAllInvalid = bAllInvalid && bInvalid; |
2059 | } |
2060 | // |
2061 | if (bAllInvalid && !bHasValid && !bAllValid) { |
2062 | theInvFaces.Append(aFIm); |
2063 | } |
2064 | } |
2065 | } |
2066 | |
0da0275c |
2067 | //======================================================================= |
2068 | //function : FindFacesInsideHoleWires |
2069 | //purpose : Find faces inside holes wires from the original face |
2070 | //======================================================================= |
2071 | void FindFacesInsideHoleWires(const TopoDS_Face& theFOrigin, |
2072 | const TopoDS_Face& theFOffset, |
2073 | const TopTools_ListOfShape& theLFImages, |
2074 | const TopTools_MapOfShape& theInvertedEdges, |
2075 | const TopTools_DataMapOfShapeListOfShape& theDMEOrLEIm, |
2ebb1098 |
2076 | const TopTools_IndexedDataMapOfShapeListOfShape& theEFMap, |
0da0275c |
2077 | TopTools_MapOfShape& theMFHoles, |
2078 | TopTools_DataMapOfShapeListOfShape& theDMFNewHoles, |
2079 | Handle(IntTools_Context)& theContext) |
2080 | { |
2081 | if (theLFImages.IsEmpty()) { |
2082 | return; |
2083 | } |
2084 | // |
2085 | // find all hole wires in the original face |
2086 | TopTools_ListOfShape aLHoleWires; |
2087 | const TopoDS_Wire& anOuterWire = BRepTools::OuterWire(theFOrigin); |
2088 | TopExp_Explorer aExpW(theFOrigin, TopAbs_WIRE); |
2089 | for (; aExpW.More(); aExpW.Next()) { |
2090 | const TopoDS_Wire& aHoleWire = TopoDS::Wire(aExpW.Current()); |
2091 | if (!aHoleWire.IsSame(anOuterWire) && aHoleWire.Orientation() != TopAbs_INTERNAL) { |
2092 | aLHoleWires.Append(aHoleWire); |
2093 | } |
2094 | } |
2095 | // |
2096 | if (aLHoleWires.IsEmpty()) { |
2097 | // no holes in the face |
2098 | return; |
2099 | } |
2100 | // |
2101 | TopTools_ListOfShape *pLFNewHoles = theDMFNewHoles.ChangeSeek(theFOrigin); |
2102 | // |
2103 | if (!pLFNewHoles) { |
2104 | pLFNewHoles = theDMFNewHoles.Bound(theFOrigin, TopTools_ListOfShape()); |
2105 | } |
2106 | if (pLFNewHoles->IsEmpty()) { |
2107 | // |
2108 | // find the faces representing holes in the images of the faces: |
2109 | // 1. for each original hole wire try to build its image |
2110 | // 2. build the new planar face from the images |
2111 | // |
2112 | // map vertices and edges of the splits |
2113 | TopTools_IndexedMapOfShape aMESplits; |
2114 | TopTools_ListIteratorOfListOfShape aItLF(theLFImages); |
2115 | for (; aItLF.More(); aItLF.Next()) { |
2116 | TopExp::MapShapes(aItLF.Value(), TopAbs_EDGE, aMESplits); |
2117 | } |
2118 | // |
2119 | TopTools_ListIteratorOfListOfShape aItLW(aLHoleWires); |
2120 | for (; aItLW.More(); aItLW.Next()) { |
2121 | const TopoDS_Wire& aHoleWire = TopoDS::Wire(aItLW.Value()); |
2122 | // find images of all edges of the original wire |
2123 | TopTools_IndexedMapOfShape aMEImWire; |
2124 | TopoDS_Iterator aItE(aHoleWire); |
2125 | for (; aItE.More(); aItE.Next()) { |
2126 | const TopoDS_Shape& aEOr = aItE.Value(); |
2127 | const TopTools_ListOfShape *pLEIm = theDMEOrLEIm.Seek(aEOr); |
2128 | if (!pLEIm || pLEIm->IsEmpty()) { |
2129 | continue; |
2130 | } |
2131 | TopTools_ListIteratorOfListOfShape aItLEIm(*pLEIm); |
2132 | for (; aItLEIm.More(); aItLEIm.Next()) { |
2133 | const TopoDS_Shape& aEIm = aItLEIm.Value(); |
2134 | if (aMESplits.Contains(aEIm)) { |
2135 | aMEImWire.Add(aEIm); |
2136 | } |
2137 | } |
2138 | } |
2139 | // |
2140 | if (aMEImWire.IsEmpty()) { |
2141 | continue; |
2142 | } |
2143 | // |
2144 | // build new planar face using these edges |
1155d05a |
2145 | TopTools_ListOfShape aLE; |
0da0275c |
2146 | Standard_Integer i, aNbE = aMEImWire.Extent(); |
2147 | for (i = 1; i <= aNbE; ++i) { |
2148 | aLE.Append(aMEImWire(i).Oriented(TopAbs_FORWARD)); |
2149 | aLE.Append(aMEImWire(i).Oriented(TopAbs_REVERSED)); |
2150 | } |
2151 | // |
2152 | BOPAlgo_BuilderFace aBF; |
2153 | aBF.SetFace(TopoDS::Face(theFOffset.Oriented(TopAbs_FORWARD))); |
2154 | aBF.SetShapes(aLE); |
2155 | aBF.Perform(); |
2156 | // |
1155d05a |
2157 | const TopTools_ListOfShape& aLFNew = aBF.Areas(); |
0da0275c |
2158 | if (aLFNew.IsEmpty()) { |
2159 | continue; |
2160 | } |
2161 | // |
2162 | // check if outer edges in the new faces are not inverted |
2163 | // because the inverted edges mean that the hole has been |
2164 | // filled during offset and there will be no faces to remove |
2165 | TopTools_IndexedDataMapOfShapeListOfShape aDMEFNew; |
2166 | TopTools_ListIteratorOfListOfShape aItLFNew(aLFNew); |
2167 | for (; aItLFNew.More(); aItLFNew.Next()) { |
2168 | TopExp::MapShapesAndAncestors(aItLFNew.Value(), TopAbs_EDGE, TopAbs_FACE, aDMEFNew); |
2169 | } |
2170 | // |
2171 | aNbE = aDMEFNew.Extent(); |
2172 | for (i = 1; i <= aNbE; ++i) { |
2173 | if (aDMEFNew(i).Extent() == 1) { |
2174 | const TopoDS_Shape& aE = aDMEFNew.FindKey(i); |
2175 | if (theInvertedEdges.Contains(aE)) { |
2176 | break; |
2177 | } |
2178 | } |
2179 | } |
2180 | // |
2181 | if (i <= aNbE) { |
2182 | continue; |
2183 | } |
2184 | // |
2185 | aItLFNew.Initialize(aLFNew); |
2186 | for (; aItLFNew.More(); aItLFNew.Next()) { |
2187 | pLFNewHoles->Append(aItLFNew.Value()); |
2188 | } |
2189 | } |
2190 | } |
2ebb1098 |
2191 | |
2192 | // Build Edge-Face map for splits of current offset face |
2193 | TopTools_IndexedDataMapOfShapeListOfShape anEFSplitsMap; |
2194 | // Build Edge-Face map for holes |
2195 | TopTools_IndexedDataMapOfShapeListOfShape anEFHolesMap; |
2196 | |
0da0275c |
2197 | // among the splits of the offset face find those that are |
2198 | // located inside the hole faces |
0da0275c |
2199 | TopTools_ListIteratorOfListOfShape aItLF(theLFImages); |
2200 | for (; aItLF.More(); aItLF.Next()) { |
2201 | const TopoDS_Face& aFIm = TopoDS::Face(aItLF.Value()); |
2ebb1098 |
2202 | TopExp::MapShapesAndAncestors(aFIm, TopAbs_EDGE, TopAbs_FACE, anEFSplitsMap); |
0da0275c |
2203 | // get the point inside the face and classify it relatively hole faces |
2204 | gp_Pnt aP3D; |
2205 | gp_Pnt2d aP2D; |
2206 | Standard_Integer iErr = BOPTools_AlgoTools3D::PointInFace(aFIm, aP3D, aP2D, theContext); |
2207 | if (iErr) { |
2208 | continue; |
2209 | } |
2210 | // |
2211 | Standard_Real aTol = BRep_Tool::Tolerance(aFIm); |
2212 | // |
2213 | TopTools_ListIteratorOfListOfShape aItLFNew(*pLFNewHoles); |
2214 | for (; aItLFNew.More(); aItLFNew.Next()) { |
2215 | const TopoDS_Face& aFNew = TopoDS::Face(aItLFNew.Value()); |
2216 | if (theContext->IsValidPointForFace(aP3D, aFNew, aTol)) { |
2217 | // the face is classified as IN |
2218 | theMFHoles.Add(aFIm); |
2ebb1098 |
2219 | TopExp::MapShapesAndAncestors(aFIm, TopAbs_EDGE, TopAbs_FACE, anEFHolesMap); |
0da0275c |
2220 | break; |
2221 | } |
2222 | } |
2223 | } |
2ebb1098 |
2224 | |
2225 | // Out of all found holes find those which cannot be removed |
2226 | // by checking their connectivity to splits of other offset faces. |
2227 | // These are the faces, which will create uncovered holes if removed. |
2228 | const Standard_Integer aNbE = anEFHolesMap.Extent(); |
2229 | for (Standard_Integer i = 1; i <= aNbE; ++i) |
2230 | { |
2231 | const TopoDS_Shape& anEdge = anEFHolesMap.FindKey(i); |
2232 | const TopTools_ListOfShape& aLFHoles = anEFHolesMap(i); |
2233 | // Check if the edge is outer for holes |
2234 | if (aLFHoles.Extent() != 1) |
2235 | continue; |
2236 | |
2237 | const TopoDS_Shape& aFHole = aLFHoles.First(); |
2238 | if (!theMFHoles.Contains(aFHole)) |
2239 | // Already removed |
2240 | continue; |
2241 | |
2242 | // Check if the edge is not outer for splits |
2243 | const TopTools_ListOfShape& aLSplits = anEFSplitsMap.FindFromKey(anEdge); |
2244 | if (aLSplits.Extent() == 1) |
2245 | continue; |
2246 | |
2247 | // Check if edge is only connected to splits of the current offset face |
2248 | const TopTools_ListOfShape& aLFAll = theEFMap.FindFromKey(anEdge); |
2249 | if (aLFAll.Extent() == 2) |
2250 | // Avoid removal of the hole from the splits |
2251 | theMFHoles.Remove(aFHole); |
2252 | } |
0da0275c |
2253 | } |
2254 | |
ecf4f17c |
2255 | //======================================================================= |
2256 | //function : GetAverageTangent |
2257 | //purpose : Computes average tangent vector along the curve |
2258 | //======================================================================= |
2259 | gp_Vec GetAverageTangent(const TopoDS_Shape& theS, |
2260 | const Standard_Integer theNbP) |
2261 | { |
2262 | gp_Vec aVA; |
2263 | TopExp_Explorer aExp(theS, TopAbs_EDGE); |
2264 | for (; aExp.More(); aExp.Next()) { |
2265 | const TopoDS_Edge& aE = *(TopoDS_Edge*)&aExp.Current(); |
2266 | // |
2267 | Standard_Real aT1, aT2; |
2268 | const Handle(Geom_Curve)& aC = BRep_Tool::Curve(aE, aT1, aT2); |
2269 | // |
2270 | gp_Pnt aP; |
2271 | gp_Vec aV, aVSum; |
2272 | Standard_Real aT = aT1; |
2273 | Standard_Real aDt = (aT2 - aT1) / theNbP; |
2274 | while (aT <= aT2) { |
2275 | aC->D1(aT, aP, aV); |
2276 | aVSum += aV.Normalized(); |
2277 | aT += aDt; |
2278 | } |
2279 | // |
2280 | if (aE.Orientation() == TopAbs_REVERSED) { |
2281 | aVSum.Reverse(); |
2282 | } |
2283 | // |
2284 | aVA += aVSum; |
2285 | } |
2286 | return aVA; |
2287 | } |
2288 | |
2289 | //======================================================================= |
2290 | //function : CheckInverted |
2291 | //purpose : Checks if the edge has been inverted |
2292 | //======================================================================= |
2293 | Standard_Boolean CheckInverted(const TopoDS_Edge& theEIm, |
2294 | const TopoDS_Face& theFOr, |
2295 | const TopTools_DataMapOfShapeListOfShape& theOEImages, |
2296 | const TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
2297 | const TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
ecf4f17c |
2298 | const TopTools_IndexedDataMapOfShapeListOfShape& theDMVE, |
2299 | const TopTools_IndexedMapOfShape& theMEdges, |
2300 | TopTools_MapOfShape& theMEInverted) |
2301 | { |
b6725456 |
2302 | // It is necessary to compare the direction from first vertex |
ecf4f17c |
2303 | // to the last vertex on the original edge with the |
2304 | // same direction on the new edge. If the directions |
2305 | // will be different - the edge has been inverted. |
2306 | // |
2307 | TopoDS_Vertex aVI1, aVI2; // vertices on the offset edge |
2308 | TopoDS_Vertex aVO1, aVO2; // vertices on the original edge |
2309 | // |
2310 | Standard_Integer i; |
2311 | // find vertices of the offset shape |
2312 | TopExp::Vertices(theEIm, aVI1, aVI2); |
2313 | // |
2314 | // find images |
2315 | TopTools_ListOfShape aLEImages; |
2316 | if (theOEOrigins.IsBound(theEIm)) { |
2317 | TopoDS_Wire anImages; |
2318 | BRep_Builder().MakeWire(anImages); |
2319 | // |
2320 | TopTools_MapOfShape aMImFence; |
2321 | const TopTools_ListOfShape& aLOffsetOr = theOEOrigins.Find(theEIm); |
2322 | TopTools_ListIteratorOfListOfShape aItOffset(aLOffsetOr); |
2323 | for (; aItOffset.More(); aItOffset.Next()) { |
2324 | const TopoDS_Shape& aEOffsetOr = aItOffset.Value(); |
2325 | const TopTools_ListOfShape& aLImages = theOEImages.Find(aEOffsetOr); |
2326 | // |
2327 | TopTools_ListIteratorOfListOfShape aItImages(aLImages); |
2328 | for (; aItImages.More(); aItImages.Next()) { |
2329 | const TopoDS_Edge& anIm = *(TopoDS_Edge*)&aItImages.Value(); |
2330 | if (theMEdges.Contains(anIm) && aMImFence.Add(anIm)) { |
2331 | BRep_Builder().Add(anImages, anIm); |
2332 | aLEImages.Append(anIm); |
2333 | } |
2334 | } |
2335 | } |
2336 | // |
2337 | // find alone vertices |
2338 | TopoDS_Vertex aVW1, aVW2; |
2339 | TopTools_IndexedDataMapOfShapeListOfShape aDMImVE; |
2340 | TopExp::MapShapesAndAncestors(anImages, TopAbs_VERTEX, TopAbs_EDGE, aDMImVE); |
2341 | // |
2342 | TopTools_ListOfShape aLVAlone; |
2343 | Standard_Integer aNb = aDMImVE.Extent(); |
2344 | for (i = 1; i <= aNb; ++i) { |
2345 | const TopTools_ListOfShape& aLImE = aDMImVE(i); |
2346 | if (aLImE.Extent() == 1) { |
2347 | aLVAlone.Append(aDMImVE.FindKey(i)); |
2348 | } |
2349 | } |
2350 | // |
2351 | if (aLVAlone.Extent() > 1) { |
2352 | aVW1 = *(TopoDS_Vertex*)&aLVAlone.First(); |
2353 | aVW2 = *(TopoDS_Vertex*)&aLVAlone.Last(); |
2354 | // |
2355 | // check distances |
2356 | const gp_Pnt& aPI1 = BRep_Tool::Pnt(aVI1); |
2357 | const gp_Pnt& aPW1 = BRep_Tool::Pnt(aVW1); |
2358 | const gp_Pnt& aPW2 = BRep_Tool::Pnt(aVW2); |
2359 | // |
2360 | Standard_Real aDist1 = aPI1.SquareDistance(aPW1); |
2361 | Standard_Real aDist2 = aPI1.SquareDistance(aPW2); |
2362 | // |
2363 | if (aDist1 < aDist2) { |
2364 | aVI1 = aVW1; |
2365 | aVI2 = aVW2; |
2366 | } |
2367 | else { |
2368 | aVI1 = aVW2; |
2369 | aVI2 = aVW1; |
2370 | } |
2371 | } |
2372 | } |
2373 | else { |
2374 | aLEImages.Append(theEIm); |
2375 | } |
2376 | // |
2377 | // Find edges connected to these vertices |
2378 | const TopTools_ListOfShape& aLIE1 = theDMVE.FindFromKey(aVI1); |
2379 | const TopTools_ListOfShape& aLIE2 = theDMVE.FindFromKey(aVI2); |
2380 | // |
2381 | // Find vertices on the original face corresponding to vertices on the offset edge |
2382 | // |
2383 | // find original edges for both lists |
2384 | TopTools_ListOfShape aLOE1, aLOE2; |
2385 | for (i = 0; i < 2; ++i) { |
2386 | const TopTools_ListOfShape& aLIE = !i ? aLIE1 : aLIE2; |
2387 | TopTools_ListOfShape& aLOE = !i ? aLOE1 : aLOE2; |
2388 | // |
2389 | TopTools_MapOfShape aMFence; |
2390 | // |
2391 | TopTools_ListIteratorOfListOfShape aItLIE(aLIE); |
2392 | for (; aItLIE.More(); aItLIE.Next()) { |
2393 | const TopoDS_Shape& aEI = aItLIE.Value(); |
2394 | if (theEdgesOrigins.IsBound(aEI)) { |
2395 | const TopTools_ListOfShape& aLEOrigins = theEdgesOrigins.Find(aEI); |
2396 | // |
2397 | TopTools_ListIteratorOfListOfShape aItLOE(aLEOrigins); |
2398 | for (; aItLOE.More(); aItLOE.Next()) { |
2399 | const TopoDS_Shape& aEO = aItLOE.Value(); |
2400 | if (aEO.ShapeType() == TopAbs_EDGE && aMFence.Add(aEO)) { |
2401 | TopoDS_Shape aEOin; |
2402 | if (FindShape(aEO, theFOr, aEOin)) { |
b443d536 |
2403 | AppendToList(aLOE, aEO); |
ecf4f17c |
2404 | } |
2405 | } |
2406 | } |
2407 | } |
2408 | } |
2409 | } |
2410 | // |
2411 | if (aLOE1.Extent() < 2 || aLOE2.Extent() < 2) { |
2412 | return Standard_False; |
2413 | } |
2414 | // |
2415 | // find vertices common for all edges in the lists |
2416 | for (i = 0; i < 2; ++i) { |
2417 | const TopTools_ListOfShape& aLOE = !i ? aLOE1 : aLOE2; |
2418 | TopoDS_Vertex& aVO = !i ? aVO1 : aVO2; |
2419 | // |
2420 | const TopoDS_Shape& aEO = aLOE.First(); |
2421 | TopExp_Explorer aExpV(aEO, TopAbs_VERTEX); |
2422 | for (; aExpV.More(); aExpV.Next()) { |
2423 | const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&aExpV.Current(); |
2424 | // |
2425 | Standard_Boolean bVertValid = Standard_True; |
2426 | TopTools_ListIteratorOfListOfShape aItLOE(aLOE); |
2427 | for (aItLOE.Next(); aItLOE.More(); aItLOE.Next()) { |
2428 | const TopoDS_Shape& aEOx = aItLOE.Value(); |
2429 | TopExp_Explorer aExpVx(aEOx, TopAbs_VERTEX); |
2430 | for (; aExpVx.More(); aExpVx.Next()) { |
2431 | const TopoDS_Shape& aVx = aExpVx.Current(); |
2432 | if (aVx.IsSame(aV)) { |
2433 | break; |
2434 | } |
2435 | } |
2436 | // |
2437 | if (!aExpVx.More()) { |
2438 | bVertValid = Standard_False; |
2439 | break; |
2440 | } |
2441 | } |
2442 | // |
2443 | if (bVertValid) { |
2444 | aVO = aV; |
2445 | break; |
2446 | } |
2447 | } |
2448 | } |
2449 | // |
2450 | if (aVO1.IsNull() || aVO2.IsNull() || aVO1.IsSame(aVO2)) { |
2451 | return Standard_False; |
2452 | } |
2453 | // |
2454 | // check positions of the offset and original vertices |
2455 | const gp_Pnt& aPI1 = BRep_Tool::Pnt(aVI1); |
2456 | const gp_Pnt& aPI2 = BRep_Tool::Pnt(aVI2); |
2457 | const gp_Pnt& aPO1 = BRep_Tool::Pnt(aVO1); |
2458 | const gp_Pnt& aPO2 = BRep_Tool::Pnt(aVO2); |
2459 | // |
2460 | gp_Vec aVI(aPI1, aPI2); |
2461 | gp_Vec aVO(aPO1, aPO2); |
2462 | // |
2463 | Standard_Real anAngle = aVI.Angle(aVO); |
2464 | Standard_Boolean bInverted = Abs(anAngle - M_PI) < 1.e-4; |
2465 | if (bInverted) { |
2466 | TopTools_ListIteratorOfListOfShape aItLEIm(aLEImages); |
2467 | for (; aItLEIm.More(); aItLEIm.Next()) { |
2468 | const TopoDS_Shape& aEInvr = aItLEIm.Value(); |
2469 | theMEInverted.Add(aEInvr); |
2470 | } |
2471 | } |
2472 | return bInverted; |
2473 | } |
2474 | |
baaacd46 |
2475 | //======================================================================= |
2476 | //function : CheckInvertedBlock |
2477 | //purpose : Checks if it is possible to remove the block containing |
2478 | // inverted edges |
2479 | //======================================================================= |
2480 | Standard_Boolean CheckInvertedBlock(const TopoDS_Shape& theCB, |
2481 | const TopTools_ListOfShape& theLCBF, |
2482 | const TopTools_MapOfShape& theMEInverted, |
2483 | const TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
2484 | BRepOffset_DataMapOfShapeMapOfShape& theDMCBVInverted, |
2485 | BRepOffset_DataMapOfShapeMapOfShape& theDMCBVAll) |
2486 | { |
2487 | // For possible removal of the block: |
2488 | // 1. There should be more than just one face in the block |
b2d1851c |
2489 | if (theCB.NbChildren() < 2) { |
baaacd46 |
2490 | return Standard_False; |
2491 | } |
2492 | // |
2493 | // 2. The block should at least contain two connected inverted edges with |
2494 | // different origins (not just two images/splits of the same edge) |
2495 | TopTools_MapOfShape aMECBInv; |
2496 | TopoDS_Compound aCECBInv; |
2497 | BRep_Builder().MakeCompound(aCECBInv); |
2498 | // |
2499 | TopExp_Explorer aExp(theCB, TopAbs_EDGE); |
2500 | for (; aExp.More(); aExp.Next()) { |
2501 | const TopoDS_Shape& aE = aExp.Current(); |
2502 | if (theMEInverted.Contains(aE)) { |
2503 | if (aMECBInv.Add(aE)) { |
2504 | BRep_Builder().Add(aCECBInv, aE); |
2505 | } |
2506 | } |
2507 | } |
2508 | // |
2509 | if (aMECBInv.Extent() < 2) { |
2510 | return Standard_False; |
2511 | } |
2512 | // |
2513 | // check that the edges are connected and different |
2514 | TopTools_ListOfShape aLCBE; |
2515 | BOPTools_AlgoTools::MakeConnexityBlocks(aCECBInv, TopAbs_VERTEX, TopAbs_EDGE, aLCBE); |
2516 | // |
2517 | TopTools_ListIteratorOfListOfShape aItLCBE(aLCBE); |
2518 | for (; aItLCBE.More(); aItLCBE.Next()) { |
2519 | const TopoDS_Shape& aCBE = aItLCBE.Value(); |
2520 | // count the unique edges in the block |
2521 | Standard_Integer aNbUnique = 0; |
2522 | TopTools_MapOfShape aMEOrigins; |
2523 | TopoDS_Iterator aItE(aCBE); |
2524 | for (; aItE.More(); aItE.Next()) { |
2525 | const TopoDS_Shape& aE = aItE.Value(); |
2526 | const TopTools_ListOfShape *pLEOr = theOEOrigins.Seek(aE); |
2527 | if (!pLEOr) { |
2528 | aMEOrigins.Add(aE); |
2529 | ++aNbUnique; |
2530 | continue; |
2531 | } |
2532 | TopTools_ListIteratorOfListOfShape aItLEOr(*pLEOr); |
2533 | for (; aItLEOr.More(); aItLEOr.Next()) { |
2534 | const TopoDS_Shape& aEOr = aItLEOr.Value(); |
2535 | if (aMEOrigins.Add(aEOr)) { |
2536 | ++aNbUnique; |
2537 | } |
2538 | } |
2539 | } |
2540 | // |
2541 | if (aNbUnique >= 2) { |
2542 | break; |
2543 | } |
2544 | } |
2545 | // |
2546 | if (!aItLCBE.More()) { |
2547 | return Standard_False; |
2548 | } |
2549 | // |
2550 | // 3. the block should not contain inverted edges which vertices |
2551 | // are contained in other blocks |
2552 | // |
2553 | // collect vertices from inverted edges and compare them with |
2554 | // vertices from other blocks |
2555 | TopTools_MapOfShape* pMVInverted = theDMCBVInverted.ChangeSeek(theCB); |
2556 | TopTools_MapOfShape* pMVAll = theDMCBVAll.ChangeSeek(theCB); |
2557 | if (!pMVInverted) { |
2558 | pMVInverted = theDMCBVInverted.Bound(theCB, TopTools_MapOfShape()); |
2559 | pMVAll = theDMCBVAll.Bound(theCB, TopTools_MapOfShape()); |
2560 | // |
2561 | GetVerticesOnEdges(theCB, theMEInverted, *pMVInverted, *pMVAll); |
2562 | } |
2563 | // |
2564 | TopTools_ListIteratorOfListOfShape aItLCB1(theLCBF); |
2565 | for (; aItLCB1.More(); aItLCB1.Next()) { |
2566 | const TopoDS_Shape& aCB1 = aItLCB1.Value(); |
2567 | if (aCB1.IsSame(theCB)) { |
2568 | continue; |
2569 | } |
2570 | // |
2571 | // collect vertices from inverted edges |
2572 | TopTools_MapOfShape* pMVInverted1 = theDMCBVInverted.ChangeSeek(aCB1); |
2573 | TopTools_MapOfShape* pMVAll1 = theDMCBVAll.ChangeSeek(aCB1); |
2574 | if (!pMVInverted1) { |
2575 | pMVInverted1 = theDMCBVInverted.Bound(aCB1, TopTools_MapOfShape()); |
2576 | pMVAll1 = theDMCBVAll.Bound(aCB1, TopTools_MapOfShape()); |
2577 | // |
2578 | GetVerticesOnEdges(aCB1, theMEInverted, *pMVInverted1, *pMVAll1); |
2579 | } |
2580 | // |
2581 | if (pMVInverted->HasIntersection(*pMVAll1)) { |
2582 | return Standard_False; |
2583 | } |
2584 | } |
2585 | // |
2586 | return Standard_True; |
2587 | } |
2588 | |
2589 | //======================================================================= |
2590 | //function : GetVerticesOnEdges |
2591 | //purpose : Get vertices from the given shape belonging to the given edges |
2592 | //======================================================================= |
2593 | void GetVerticesOnEdges(const TopoDS_Shape& theCB, |
2594 | const TopTools_MapOfShape& theEdges, |
2595 | TopTools_MapOfShape& theVerticesOnEdges, |
2596 | TopTools_MapOfShape& theAllVertices) |
2597 | { |
2598 | TopExp_Explorer aExp(theCB, TopAbs_EDGE); |
2599 | for (; aExp.More(); aExp.Next()) { |
2600 | const TopoDS_Shape& aE = aExp.Current(); |
2601 | Standard_Boolean bOnGivenEdge = theEdges.Contains(aE); |
2602 | for (TopoDS_Iterator aItV(aE); aItV.More(); aItV.Next()) { |
2603 | theAllVertices.Add(aItV.Value()); |
2604 | if (bOnGivenEdge) { |
2605 | theVerticesOnEdges.Add(aItV.Value()); |
2606 | } |
2607 | } |
2608 | } |
2609 | } |
2610 | |
ecf4f17c |
2611 | //======================================================================= |
2612 | //function : RemoveInvalidSplitsByInvertedEdges |
2613 | //purpose : Looking for the invalid faces containing inverted edges |
2614 | // that can be safely removed |
2615 | //======================================================================= |
2616 | void RemoveInvalidSplitsByInvertedEdges(const TopTools_MapOfShape& theMEInverted, |
baaacd46 |
2617 | const TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
ecf4f17c |
2618 | TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
2619 | TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
2620 | TopTools_IndexedMapOfShape& theMERemoved) |
2621 | { |
2622 | if (theMEInverted.IsEmpty()) { |
2623 | return; |
2624 | } |
2625 | // |
2626 | // check the faces on regularity, i.e. the splits of the same face |
2627 | // should not be connected only by vertex. Such irregular splits |
2628 | // will have to be rebuilt and cannot be removed. |
2629 | // |
baaacd46 |
2630 | BRep_Builder aBB; |
2631 | TopTools_IndexedMapOfShape aMEAvoid; |
ecf4f17c |
2632 | TopTools_DataMapOfShapeListOfShape aDMVF; |
2633 | Standard_Integer aNb = theFImages.Extent(), i; |
2634 | for (i = 1; i <= aNb; ++i) { |
2635 | const TopTools_ListOfShape& aLFIm = theFImages(i); |
2636 | // |
2637 | TopoDS_Compound aCFIm; |
baaacd46 |
2638 | aBB.MakeCompound(aCFIm); |
ecf4f17c |
2639 | // |
2640 | TopTools_DataMapOfShapeListOfShape aDMEF; |
2641 | TopTools_ListIteratorOfListOfShape aIt(aLFIm); |
2642 | for (; aIt.More(); aIt.Next()) { |
2643 | const TopoDS_Shape& aF = aIt.Value(); |
baaacd46 |
2644 | aBB.Add(aCFIm, aF); |
ecf4f17c |
2645 | // |
2646 | // make a map to use only outer edges |
2647 | TopExp_Explorer aExp(aF, TopAbs_EDGE); |
2648 | for (; aExp.More(); aExp.Next()) { |
2649 | const TopoDS_Shape& aE = aExp.Current(); |
2650 | // |
2651 | TopTools_ListOfShape *pLF = aDMEF.ChangeSeek(aE); |
2652 | if (!pLF) { |
baaacd46 |
2653 | pLF = aDMEF.Bound(aE, TopTools_ListOfShape()); |
ecf4f17c |
2654 | } |
2655 | else { |
ecf4f17c |
2656 | // internal edges should not be used |
2657 | aMEAvoid.Add(aE); |
2658 | } |
baaacd46 |
2659 | AppendToList(*pLF, aF); |
ecf4f17c |
2660 | } |
2661 | // |
2662 | // fill connection map of the vertices of inverted edges to faces |
2663 | aExp.Init(aF, TopAbs_VERTEX); |
2664 | for (; aExp.More(); aExp.Next()) { |
2665 | const TopoDS_Shape& aV = aExp.Current(); |
2666 | // |
2667 | TopTools_ListOfShape *pLF = aDMVF.ChangeSeek(aV); |
2668 | if (!pLF) { |
baaacd46 |
2669 | pLF = aDMVF.Bound(aV, TopTools_ListOfShape()); |
ecf4f17c |
2670 | } |
baaacd46 |
2671 | AppendToList(*pLF, aF); |
ecf4f17c |
2672 | } |
2673 | } |
2674 | // |
2675 | // for the splits to be regular they should form only one block |
2676 | TopTools_ListOfShape aLCBF; |
2677 | BOPTools_AlgoTools::MakeConnexityBlocks(aCFIm, TopAbs_EDGE, TopAbs_FACE, aLCBF); |
baaacd46 |
2678 | if (aLCBF.Extent() == 1) { |
2679 | continue; |
2680 | } |
ecf4f17c |
2681 | // |
baaacd46 |
2682 | // check if the inverted edges create the irregularity |
2683 | BRepOffset_DataMapOfShapeMapOfShape aDMCBVInverted, aDMCBVAll; |
2684 | // |
2685 | TopTools_ListIteratorOfListOfShape aItLCB(aLCBF); |
2686 | for (; aItLCB.More(); aItLCB.Next()) { |
2687 | const TopoDS_Shape& aCB = aItLCB.Value(); |
2688 | // |
2689 | // check if it is possible to remove the block |
2690 | if (!CheckInvertedBlock(aCB, aLCBF, theMEInverted, theOEOrigins, aDMCBVInverted, aDMCBVAll)) { |
2691 | // non of the edges in this block should be removed |
2692 | TopExp::MapShapes(aCB, TopAbs_EDGE, aMEAvoid); |
2693 | continue; |
ecf4f17c |
2694 | } |
2695 | } |
2696 | } |
2697 | // |
2698 | // all edges not included in aMEAvoid can be removed |
2699 | TopTools_MapOfShape aMERem; |
2700 | TopTools_MapIteratorOfMapOfShape aItM(theMEInverted); |
2701 | for (; aItM.More(); aItM.Next()) { |
2702 | const TopoDS_Shape& aE = aItM.Value(); |
2703 | if (!aMEAvoid.Contains(aE)) { |
2704 | TopoDS_Iterator aIt(aE); |
2705 | for (; aIt.More(); aIt.Next()) { |
2706 | const TopoDS_Shape& aV = aIt.Value(); |
2707 | const TopTools_ListOfShape *pLF = aDMVF.Seek(aV); |
2708 | if (pLF && (pLF->Extent() > 3)) { |
2709 | aMERem.Add(aE); |
2710 | break; |
2711 | } |
2712 | } |
2713 | } |
2714 | } |
2715 | // |
2716 | if (aMERem.IsEmpty()) { |
2717 | return; |
2718 | } |
2719 | // |
2720 | // all invalid faces containing these edges can be removed |
2721 | TopTools_IndexedDataMapOfShapeListOfShape aInvFaces; |
2722 | TopTools_MapOfShape aMFRem; |
2723 | TopTools_IndexedMapOfShape aMFToUpdate; |
2724 | aNb = theInvFaces.Extent(); |
2725 | for (i = 1; i <= aNb; ++i) { |
2726 | const TopoDS_Shape& aF = theInvFaces.FindKey(i); |
2727 | TopTools_ListOfShape& aLFIm = theInvFaces(i); |
2728 | // |
2729 | TopTools_ListIteratorOfListOfShape aIt(aLFIm); |
2730 | for (; aIt.More(); ) { |
2731 | const TopoDS_Shape& aFIm = aIt.Value(); |
2732 | // |
2733 | // to be removed the face should have at least two not connected |
2734 | // inverted edges |
2735 | TopoDS_Compound aCEInv; |
baaacd46 |
2736 | aBB.MakeCompound(aCEInv); |
ecf4f17c |
2737 | TopExp_Explorer aExp(aFIm, TopAbs_EDGE); |
2738 | for (; aExp.More(); aExp.Next()) { |
2739 | const TopoDS_Shape& aE = aExp.Current(); |
ecf4f17c |
2740 | if (aMERem.Contains(aE)) { |
baaacd46 |
2741 | aBB.Add(aCEInv, aE); |
ecf4f17c |
2742 | } |
2743 | } |
2744 | // |
2745 | // check connectivity |
2746 | TopTools_ListOfShape aLCBE; |
2747 | BOPTools_AlgoTools::MakeConnexityBlocks(aCEInv, TopAbs_VERTEX, TopAbs_EDGE, aLCBE); |
2748 | // |
2749 | if (aLCBE.Extent() >= 2) { |
2750 | aMFToUpdate.Add(aF); |
2751 | aMFRem.Add(aFIm); |
2752 | aLFIm.Remove(aIt); |
2753 | } |
2754 | else { |
2755 | aIt.Next(); |
2756 | } |
2757 | } |
2758 | // |
2759 | if (aLFIm.Extent()) { |
2760 | aInvFaces.Add(aF, aLFIm); |
2761 | } |
2762 | } |
2763 | // |
2764 | if (aMFRem.IsEmpty()) { |
2765 | return; |
2766 | } |
2767 | // |
2768 | theInvFaces = aInvFaces; |
2769 | // remove from splits |
2770 | aNb = aMFToUpdate.Extent(); |
2771 | for (i = 1; i <= aNb; ++i) { |
2772 | const TopoDS_Shape& aF = aMFToUpdate(i); |
2773 | TopTools_ListOfShape& aLFIm = theFImages.ChangeFromKey(aF); |
2774 | // |
2775 | TopTools_ListIteratorOfListOfShape aIt(aLFIm); |
2776 | for (; aIt.More(); ) { |
2777 | const TopoDS_Shape& aFIm = aIt.Value(); |
2778 | if (aMFRem.Contains(aFIm)) { |
2779 | TopExp::MapShapes(aFIm, TopAbs_EDGE, theMERemoved); |
2780 | aLFIm.Remove(aIt); |
2781 | } |
2782 | else { |
2783 | aIt.Next(); |
2784 | } |
2785 | } |
2786 | } |
2787 | } |
2788 | |
2789 | //======================================================================= |
2790 | //function : RemoveInvalidSplitsFromValid |
2791 | //purpose : Removing invalid splits of faces from valid |
2792 | //======================================================================= |
2793 | void RemoveInvalidSplitsFromValid(const TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
2794 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
2795 | const TopTools_MapOfShape& theMEInverted, |
2796 | TopTools_IndexedDataMapOfShapeListOfShape& theFImages) |
2797 | { |
2798 | // Decide whether to remove the found invalid faces or not. |
2799 | // The procedure is the following: |
2800 | // 1. Make connexity blocks from invalid faces; |
2801 | // 2. Find free edges in this blocks; |
2802 | // 3. If all free edges are valid for the faces - remove block. |
2803 | // |
2804 | TopTools_MapOfShape aMFence, aMFToRem; |
2805 | TopoDS_Compound aCFInv; |
2806 | BRep_Builder aBB; |
2807 | aBB.MakeCompound(aCFInv); |
2808 | TopTools_ListIteratorOfListOfShape aItLF; |
2809 | // |
2810 | // make compound of invalid faces |
2811 | TopTools_DataMapOfShapeShape aDMIFOF; |
2812 | Standard_Integer i, aNb = theInvFaces.Extent(); |
2813 | for (i = 1; i <= aNb; ++i) { |
2814 | const TopoDS_Shape& aF = theInvFaces.FindKey(i); |
2815 | // artificially invalid faces should not be removed |
2816 | if (theArtInvFaces.IsBound(aF)) { |
2817 | continue; |
2818 | } |
2819 | const TopTools_ListOfShape& aLFInv = theInvFaces(i); |
2820 | aItLF.Initialize(aLFInv); |
2821 | for (; aItLF.More(); aItLF.Next()) { |
2822 | const TopoDS_Shape& aFIm = aItLF.Value(); |
2823 | if (aMFence.Add(aFIm)) { |
2824 | aBB.Add(aCFInv, aFIm); |
2825 | aDMIFOF.Bind(aFIm, aF); |
2826 | } |
2827 | } |
2828 | } |
2829 | // |
2830 | // make connexity blocks |
2831 | TopTools_ListOfShape aLCBInv; |
2832 | BOPTools_AlgoTools::MakeConnexityBlocks(aCFInv, TopAbs_EDGE, TopAbs_FACE, aLCBInv); |
2833 | // |
2834 | // analyze each block |
2835 | aItLF.Initialize(aLCBInv); |
2836 | for (; aItLF.More(); aItLF.Next()) { |
2837 | const TopoDS_Shape& aCB = aItLF.Value(); |
2838 | // |
2839 | // if connexity block contains only one face - it should be removed; |
2840 | TopExp_Explorer aExp(aCB, TopAbs_FACE); |
2841 | aExp.Next(); |
2842 | if (aExp.More()) { |
2843 | // check if there are valid images left |
2844 | aExp.Init(aCB, TopAbs_FACE); |
2845 | for (; aExp.More(); aExp.Next()) { |
2846 | const TopoDS_Shape& aFIm = aExp.Current(); |
2847 | const TopoDS_Shape& aF = aDMIFOF.Find(aFIm); |
2848 | // |
2849 | const TopTools_ListOfShape& aLFIm = theFImages.FindFromKey(aF); |
2850 | const TopTools_ListOfShape& aLFInv = theInvFaces.FindFromKey(aF); |
2851 | // |
2852 | if (aLFIm.Extent() == aLFInv.Extent()) { |
2853 | break; |
2854 | } |
2855 | } |
2856 | } |
2857 | // |
2858 | if (!aExp.More()) { |
2859 | aExp.Init(aCB, TopAbs_FACE); |
2860 | for (; aExp.More(); aExp.Next()) { |
2861 | const TopoDS_Shape& aF = aExp.Current(); |
2862 | aMFToRem.Add(aF); |
2863 | } |
2864 | continue; |
2865 | } |
2866 | // |
2867 | // remove faces connected by inverted edges |
2868 | TopTools_IndexedDataMapOfShapeListOfShape aDMEF; |
2869 | TopExp::MapShapesAndAncestors(aCB, TopAbs_EDGE, TopAbs_FACE, aDMEF); |
2870 | // |
2871 | aExp.Init(aCB, TopAbs_FACE); |
2872 | for (; aExp.More(); aExp.Next()) { |
2873 | const TopoDS_Shape& aFCB = aExp.Current(); |
2874 | // |
2875 | TopExp_Explorer aExpE(aFCB, TopAbs_EDGE); |
2876 | for (; aExpE.More(); aExpE.Next()) { |
2877 | const TopoDS_Shape& aECB = aExpE.Current(); |
2878 | if (aDMEF.FindFromKey(aECB).Extent() > 1) { |
2879 | if (!theMEInverted.Contains(aECB)) { |
2880 | break; |
2881 | } |
2882 | } |
2883 | } |
2884 | // |
2885 | if (!aExpE.More()) { |
2886 | aMFToRem.Add(aFCB); |
2887 | } |
2888 | } |
2889 | } |
2890 | // |
2891 | if (aMFToRem.Extent()) { |
2892 | // remove invalid faces from images |
2893 | aNb = theInvFaces.Extent(); |
2894 | for (i = 1; i <= aNb; ++i) { |
2895 | const TopoDS_Shape& aF = theInvFaces.FindKey(i); |
2896 | TopTools_ListOfShape& aLFImages = theFImages.ChangeFromKey(aF); |
2897 | aItLF.Initialize(aLFImages); |
2898 | for (; aItLF.More();) { |
2899 | const TopoDS_Shape& aFIm = aItLF.Value(); |
2900 | if (aMFToRem.Contains(aFIm)) { |
2901 | aLFImages.Remove(aItLF); |
2902 | } |
2903 | else { |
2904 | aItLF.Next(); |
2905 | } |
2906 | } |
2907 | } |
2908 | } |
2909 | } |
2910 | |
2911 | //======================================================================= |
2912 | //function : RemoveInsideFaces |
2913 | //purpose : Looking for the inside faces that can be safely removed |
2914 | //======================================================================= |
2915 | void RemoveInsideFaces(TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
2916 | TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
2917 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
2918 | const TopTools_IndexedMapOfShape& theInvEdges, |
e08a9b03 |
2919 | const TopTools_MapOfShape& theInvertedEdges, |
2920 | const TopTools_ListOfShape& theInvertedFaces, |
ecf4f17c |
2921 | const TopTools_IndexedMapOfShape& theMFToCheckInt, |
0da0275c |
2922 | const TopTools_IndexedMapOfShape& theMFInvInHole, |
2923 | const TopoDS_Shape& theFHoles, |
ecf4f17c |
2924 | TopTools_DataMapOfShapeListOfShape& theSSInterfs, |
2925 | TopTools_IndexedMapOfShape& theMERemoved, |
baaacd46 |
2926 | TopTools_IndexedMapOfShape& theMEInside, |
ecf4f17c |
2927 | TopoDS_Shape& theSolids) |
2928 | { |
1155d05a |
2929 | TopTools_ListOfShape aLS; |
ecf4f17c |
2930 | TopTools_MapOfShape aMFence; |
2931 | TopTools_IndexedMapOfShape aMFInv; |
2932 | TopTools_ListIteratorOfListOfShape aItLF; |
2933 | TopTools_DataMapOfShapeShape aDMFImF; |
2934 | // |
2935 | Standard_Integer i, aNb = theFImages.Extent(); |
2936 | for (i = 1; i <= aNb; ++i) { |
2937 | const TopoDS_Shape& aF = theFImages.FindKey(i); |
2938 | // to avoid intersection of the splits of the same |
2939 | // offset faces among themselves make compound of the |
2940 | // splits and use it as one argument |
2941 | TopoDS_Compound aCFImi; |
2942 | BRep_Builder().MakeCompound(aCFImi); |
2943 | // |
2944 | for (Standard_Integer j = 0; j < 2; ++j) { |
2945 | const TopTools_ListOfShape* pLFSp = !j ? theInvFaces.Seek(aF) : &theFImages(i); |
2946 | if (!pLFSp) { |
2947 | continue; |
2948 | } |
2949 | // |
2950 | aItLF.Initialize(*pLFSp); |
2951 | for (; aItLF.More(); aItLF.Next()) { |
2952 | const TopoDS_Shape& aFIm = aItLF.Value(); |
2953 | if (aMFence.Add(aFIm)) { |
2954 | BRep_Builder().Add(aCFImi, aFIm); |
2955 | aDMFImF.Bind(aFIm, aF); |
2956 | if (!j) { |
2957 | aMFInv.Add(aFIm); |
2958 | } |
2959 | } |
2960 | } |
2961 | } |
2962 | // |
2963 | aLS.Append(aCFImi); |
2964 | } |
2965 | // |
2966 | // to make the solids more complete add for intersection also the faces |
2967 | // consisting only of invalid edges and not included into splits |
2968 | aNb = theMFToCheckInt.Extent(); |
2969 | for (i = 1; i <= aNb; ++i) { |
2970 | const TopoDS_Shape& aFSp = theMFToCheckInt(i); |
2971 | if (aMFence.Add(aFSp)) { |
2972 | aLS.Append(aFSp); |
2973 | } |
2974 | } |
2975 | // |
2976 | BOPAlgo_MakerVolume aMV; |
2977 | aMV.SetArguments(aLS); |
2978 | aMV.SetIntersect(Standard_True); |
2979 | aMV.Perform(); |
e08a9b03 |
2980 | if (aMV.HasErrors()) |
2981 | return; |
2982 | |
ecf4f17c |
2983 | // |
2984 | // get shapes connection for using in the rebuilding process |
2985 | // for the cases in which some of the intersection left undetected |
2986 | ShapesConnections(theInvFaces, theInvEdges, aDMFImF, aMV, theSSInterfs); |
2987 | // |
2988 | // find faces to remove |
2989 | const TopoDS_Shape& aSols = aMV.Shape(); |
2990 | // |
2991 | TopTools_IndexedDataMapOfShapeListOfShape aDMFS; |
2992 | TopExp::MapShapesAndAncestors(aSols, TopAbs_FACE, TopAbs_SOLID, aDMFS); |
2993 | // |
2994 | aNb = aDMFS.Extent(); |
2995 | if (!aNb) { |
2996 | return; |
2997 | } |
2998 | // |
2999 | // To use the created solids for classifications, firstly, it is necessary |
3000 | // to check them on validity - the created solids should be complete, |
3001 | // i.e. all faces should be included. |
3002 | // |
0da0275c |
3003 | TopTools_MapOfShape aMFToRem; |
ecf4f17c |
3004 | // Check completeness |
3005 | if (aMV.HasDeleted()) { |
0da0275c |
3006 | TopTools_IndexedMapOfShape aMEHoles; |
3007 | TopExp::MapShapes(theFHoles, TopAbs_EDGE, aMEHoles); |
bc4a3867 |
3008 | |
3009 | // Map edges of the solids to check the connectivity |
3010 | // of the removed invalid splits |
3011 | TopTools_IndexedMapOfShape aMESols; |
3012 | TopExp::MapShapes(aSols, TopAbs_EDGE, aMESols); |
3013 | |
ecf4f17c |
3014 | // perform additional check on faces |
3015 | aNb = theFImages.Extent(); |
3016 | for (i = 1; i <= aNb; ++i) { |
3017 | const TopTools_ListOfShape& aLFIm = theFImages(i); |
3018 | if (aLFIm.IsEmpty()) { |
3019 | continue; |
3020 | } |
bc4a3867 |
3021 | |
3022 | const TopoDS_Shape& aF = theFImages.FindKey(i); |
3023 | Standard_Boolean bInvalid = theInvFaces.Contains(aF); |
3024 | // For invalid faces it is allowed to be at least connected |
3025 | // to the solids, otherwise the solids are considered as broken |
3026 | Standard_Boolean bConnected = Standard_False; |
3027 | |
0da0275c |
3028 | Standard_Boolean bFaceKept = Standard_False; |
ecf4f17c |
3029 | aItLF.Initialize(aLFIm); |
3030 | for (; aItLF.More(); aItLF.Next()) { |
3031 | const TopoDS_Shape& aFIm = aItLF.Value(); |
3032 | if (!aMV.IsDeleted(aFIm)) { |
0da0275c |
3033 | bFaceKept = Standard_True; |
3034 | continue; |
3035 | } |
3036 | // |
3037 | TopExp_Explorer aExpE(aFIm, TopAbs_EDGE); |
3038 | for (; aExpE.More(); aExpE.Next()) { |
3039 | if (aMEHoles.Contains(aExpE.Current())) { |
3040 | bFaceKept = Standard_True; |
3041 | aMFToRem.Add(aFIm); |
3042 | break; |
3043 | } |
bc4a3867 |
3044 | if (!bFaceKept && bInvalid && !bConnected) |
3045 | bConnected = aMESols.Contains(aExpE.Current()); |
ecf4f17c |
3046 | } |
3047 | } |
3048 | // |
bc4a3867 |
3049 | if (!bFaceKept && !bConnected) { |
ecf4f17c |
3050 | return; |
3051 | } |
3052 | } |
3053 | } |
3054 | // |
baaacd46 |
3055 | TopTools_IndexedMapOfShape aMEBoundary; |
ecf4f17c |
3056 | aNb = aDMFS.Extent(); |
3057 | for (i = 1; i <= aNb; ++i) { |
baaacd46 |
3058 | const TopoDS_Shape& aFIm = aDMFS.FindKey(i); |
ecf4f17c |
3059 | const TopTools_ListOfShape& aLSol = aDMFS(i); |
3060 | if (aLSol.Extent() > 1) { |
ecf4f17c |
3061 | aMFToRem.Add(aFIm); |
3062 | } |
baaacd46 |
3063 | else if (aFIm.Orientation() != TopAbs_INTERNAL) { |
3064 | TopExp::MapShapes(aFIm, TopAbs_EDGE, aMEBoundary); |
3065 | } |
ecf4f17c |
3066 | } |
e08a9b03 |
3067 | |
3068 | // Tool for getting the splits of faces |
3069 | const TopTools_DataMapOfShapeListOfShape& aMVIms = aMV.Images(); |
3070 | |
ecf4f17c |
3071 | // update invalid faces with images |
3072 | aNb = aMFInv.Extent(); |
3073 | for (i = 1; i <= aNb; ++i) { |
3074 | const TopoDS_Shape& aFInv = aMFInv(i); |
e08a9b03 |
3075 | TakeModified(aFInv, aMVIms, aMFInv); |
ecf4f17c |
3076 | } |
e08a9b03 |
3077 | |
3078 | // Take into account the faces invalid by inverted edges |
3079 | for (TopTools_ListOfShape::Iterator itLF(theInvertedFaces); itLF.More(); itLF.Next()) |
3080 | TakeModified(itLF.Value(), aMVIms, aMFInv); |
3081 | |
0da0275c |
3082 | // check if the invalid faces inside the holes are really invalid: |
3083 | // check its normal direction - if it has changed relatively the |
3084 | // original face the offset face is invalid and should be kept for rebuilding |
3085 | Standard_Integer aNbFH = theMFInvInHole.Extent(); |
3086 | for (i = 1; i <= aNbFH; ++i) { |
3087 | const TopoDS_Shape& aFInv = theMFInvInHole(i); |
3088 | TopTools_ListOfShape aLFInvIm = aMV.Modified(aFInv); |
3089 | if (aLFInvIm.IsEmpty()) { |
3090 | aLFInvIm.Append(aFInv); |
3091 | } |
3092 | // |
3093 | const TopoDS_Shape *pFOffset = aDMFImF.Seek(aFInv); |
3094 | if (!pFOffset) { |
3095 | continue; |
3096 | } |
3097 | TopTools_ListIteratorOfListOfShape aItLFInv(aLFInvIm); |
3098 | for (; aItLFInv.More(); aItLFInv.Next()) { |
3099 | const TopoDS_Shape& aFInvIm = aItLFInv.Value(); |
3100 | const TopTools_ListOfShape* pLSols = aDMFS.Seek(aFInvIm); |
3101 | if (!pLSols || pLSols->Extent() != 1) { |
3102 | continue; |
3103 | } |
3104 | // |
3105 | const TopoDS_Shape& aFSol = pLSols->First(); |
3106 | // |
3107 | TopoDS_Shape aFx; |
3108 | if (!FindShape(aFInvIm, aFSol, aFx)) { |
3109 | continue; |
3110 | } |
3111 | // |
3112 | if (BRepOffset_Tool::CheckPlanesNormals(TopoDS::Face(aFx), TopoDS::Face(*pFOffset))) { |
3113 | // the normal direction has not changed, thus the face can be removed |
3114 | aMFToRem.Add(aFInvIm); |
3115 | } |
3116 | } |
3117 | } |
3118 | // |
ecf4f17c |
3119 | TopoDS_Compound aSolids; |
3120 | BRep_Builder().MakeCompound(aSolids); |
b443d536 |
3121 | TopTools_MapOfShape aMFKeep; |
ecf4f17c |
3122 | // |
3123 | TopExp_Explorer aExpS(aSols, TopAbs_SOLID); |
3124 | for (; aExpS.More(); aExpS.Next()) { |
3125 | const TopoDS_Shape& aSol = aExpS.Current(); |
3126 | // |
3127 | Standard_Boolean bAllInv(Standard_True), bAllRemoved(Standard_True); |
3128 | |
45d0af05 |
3129 | for (TopExp_Explorer aExpF(aSol, TopAbs_FACE); aExpF.More(); aExpF.Next()) |
3130 | { |
ecf4f17c |
3131 | const TopoDS_Shape& aFS = aExpF.Current(); |
3132 | // |
3133 | if (aFS.Orientation() == TopAbs_INTERNAL) { |
3134 | aMFToRem.Add(aFS); |
e08a9b03 |
3135 | continue; |
ecf4f17c |
3136 | } |
e08a9b03 |
3137 | |
3138 | if (aMFToRem.Contains(aFS)) |
3139 | continue; |
3140 | |
3141 | bAllRemoved = false; |
3142 | bAllInv &= aMFInv.Contains(aFS); |
ecf4f17c |
3143 | } |
3144 | // |
3145 | if (bAllInv && !bAllRemoved) { |
3146 | // remove invalid faces but keep those that have already been marked for removal |
3147 | TopExp_Explorer aExpF(aSol, TopAbs_FACE); |
3148 | for (; aExpF.More(); aExpF.Next()) { |
3149 | const TopoDS_Shape& aFS = aExpF.Current(); |
3150 | // |
3151 | if (aMFToRem.Contains(aFS)) { |
b443d536 |
3152 | if (!aMFKeep.Add(aFS)) { |
3153 | aMFKeep.Remove(aFS); |
3154 | } |
ecf4f17c |
3155 | } |
3156 | else { |
3157 | aMFToRem.Add(aFS); |
3158 | } |
3159 | } |
3160 | } |
3161 | else { |
3162 | BRep_Builder().Add(aSolids, aSol); |
3163 | theSolids = aSolids; |
3164 | } |
3165 | } |
3166 | // |
b443d536 |
3167 | TopTools_MapIteratorOfMapOfShape aItM(aMFKeep); |
3168 | for (; aItM.More(); aItM.Next()) { |
3169 | aMFToRem.Remove(aItM.Value()); |
3170 | } |
bc4a3867 |
3171 | |
3172 | // Remove the invalid hanging parts external to the solids |
e08a9b03 |
3173 | RemoveHangingParts(aMV, aDMFImF, aMFInv, theInvEdges, theInvertedEdges, aMFToRem); |
bc4a3867 |
3174 | |
3175 | // Remove newly found internal and hanging faces |
ecf4f17c |
3176 | RemoveValidSplits(aMFToRem, theFImages, aMV, theMERemoved); |
3177 | RemoveInvalidSplits(aMFToRem, theArtInvFaces, theInvEdges, theInvFaces, aMV, theMERemoved); |
baaacd46 |
3178 | // |
3179 | // Get inside faces from the removed ones comparing them with boundary edges |
3180 | aNb = theMERemoved.Extent(); |
3181 | for (i = 1; i <= aNb; ++i) { |
3182 | const TopoDS_Shape& aE = theMERemoved(i); |
3183 | if (!aMEBoundary.Contains(aE)) { |
3184 | theMEInside.Add(aE); |
3185 | } |
3186 | } |
ecf4f17c |
3187 | } |
3188 | |
3189 | //======================================================================= |
3190 | //function : ShapesConnections |
3191 | //purpose : Looking for the connections between faces not to miss |
3192 | // some necessary intersection |
3193 | //======================================================================= |
3194 | void ShapesConnections(const TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
3195 | const TopTools_IndexedMapOfShape& theInvEdges, |
3196 | const TopTools_DataMapOfShapeShape& theDMFOr, |
3197 | BOPAlgo_Builder& theBuilder, |
3198 | TopTools_DataMapOfShapeListOfShape& theSSInterfs) |
3199 | { |
3200 | // update invalid edges with images and keep connection to original edge |
3201 | TopTools_DataMapOfShapeListOfShape aDMEOr; |
45d0af05 |
3202 | Standard_Integer aNb = theInvEdges.Extent(); |
3203 | for (Standard_Integer i = 1; i <= aNb; ++i) { |
ecf4f17c |
3204 | const TopoDS_Shape& aEInv = theInvEdges(i); |
3205 | const TopTools_ListOfShape& aLEIm = theBuilder.Modified(aEInv); |
3206 | if (aLEIm.IsEmpty()) { |
3207 | aDMEOr.Bound(aEInv, TopTools_ListOfShape())->Append(aEInv); |
3208 | continue; |
3209 | } |
3210 | // |
3211 | TopTools_ListIteratorOfListOfShape aItLEIm(aLEIm); |
3212 | for (; aItLEIm.More(); aItLEIm.Next()) { |
3213 | const TopoDS_Shape& aEIm = aItLEIm.Value(); |
3214 | // |
3215 | TopTools_ListOfShape* pLEOr = aDMEOr.ChangeSeek(aEIm); |
3216 | if (!pLEOr) { |
3217 | pLEOr = aDMEOr.Bound(aEIm, TopTools_ListOfShape()); |
3218 | } |
3219 | AppendToList(*pLEOr, aEInv); |
3220 | } |
3221 | } |
3222 | // |
3223 | // get shapes connections for using in the rebuilding process |
3224 | const BOPDS_PDS& pDS = theBuilder.PDS(); |
3225 | // analyze all Face/Face intersections |
3226 | const BOPDS_VectorOfInterfFF& aFFs = pDS->InterfFF(); |
1155d05a |
3227 | Standard_Integer iInt, aNbFF = aFFs.Length(); |
ecf4f17c |
3228 | for (iInt = 0; iInt < aNbFF; ++iInt) { |
3229 | const BOPDS_InterfFF& aFF = aFFs(iInt); |
3230 | const BOPDS_VectorOfCurve& aVNC = aFF.Curves(); |
1155d05a |
3231 | Standard_Integer aNbC = aVNC.Length(); |
ecf4f17c |
3232 | if (!aNbC) { |
3233 | continue; |
3234 | } |
3235 | // |
3236 | const TopoDS_Shape& aFIm1 = pDS->Shape(aFF.Index1()); |
3237 | const TopoDS_Shape& aFIm2 = pDS->Shape(aFF.Index2()); |
3238 | // |
3239 | const TopoDS_Shape* pF1 = theDMFOr.Seek(aFIm1); |
3240 | const TopoDS_Shape* pF2 = theDMFOr.Seek(aFIm2); |
3241 | // |
3242 | if (!pF1 || !pF2) { |
3243 | continue; |
3244 | } |
3245 | // |
3246 | if (pF1->IsSame(*pF2)) { |
3247 | continue; |
3248 | } |
3249 | // |
3250 | Standard_Boolean bInv1 = theInvFaces.Contains(*pF1); |
3251 | Standard_Boolean bInv2 = theInvFaces.Contains(*pF2); |
3252 | // |
3253 | if (!bInv1 && !bInv2) { |
3254 | continue; |
3255 | } |
3256 | // |
3257 | // check if it is real Face/Face intersection |
3258 | TopTools_MapOfShape aMEInt; |
3259 | for (Standard_Integer iC = 0; iC < aNbC; ++iC) { |
3260 | const BOPDS_Curve& aNC = aVNC(iC); |
3261 | const BOPDS_ListOfPaveBlock& aLPB = aNC.PaveBlocks(); |
3262 | BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPB); |
3263 | for (; aItLPB.More(); aItLPB.Next()) { |
3264 | const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value(); |
3265 | Standard_Integer nEInt; |
3266 | if (aPB->HasEdge(nEInt)) { |
3267 | const TopoDS_Shape& aEInt = pDS->Shape(nEInt); |
3268 | aMEInt.Add(aEInt); |
3269 | } |
3270 | } |
3271 | } |
3272 | // |
3273 | if (aMEInt.IsEmpty()) { |
3274 | continue; |
3275 | } |
3276 | // |
3277 | // check if invalid edges of the face are in the same splits with intersection edges |
3278 | for (Standard_Integer i = 0; i < 2; ++i) { |
3279 | if ((!i && !bInv1) || (i && !bInv2)) { |
3280 | continue; |
3281 | } |
3282 | // |
3283 | const TopoDS_Shape& aF = !i ? *pF1 : *pF2; |
3284 | const TopoDS_Shape& aFOp = !i ? *pF2 : *pF1; |
3285 | const TopoDS_Shape& aFIm = !i ? aFIm1 : aFIm2; |
3286 | // |
3287 | Standard_Boolean bFound = Standard_False; |
3288 | // |
3289 | TopTools_ListOfShape aLFIm = theBuilder.Modified(aFIm); |
3290 | if (aLFIm.IsEmpty()) { |
3291 | aLFIm.Append(aFIm); |
3292 | } |
3293 | // |
3294 | TopTools_ListIteratorOfListOfShape aItLFIm(aLFIm); |
3295 | for (; aItLFIm.More(); aItLFIm.Next()) { |
3296 | const TopoDS_Shape& aFImIm = aItLFIm.Value(); |
3297 | // |
3298 | Standard_Boolean bInv(Standard_False), bInt(Standard_False); |
3299 | TopExp_Explorer aExpE(aFImIm, TopAbs_EDGE); |
3300 | for (; aExpE.More(); aExpE.Next()) { |
3301 | const TopoDS_Shape& aE = aExpE.Current(); |
3302 | if (!bInv) { |
3303 | bInv = aDMEOr.IsBound(aE); |
3304 | } |
3305 | if (!bInt) { |
3306 | bInt = aMEInt.Contains(aE); |
3307 | } |
3308 | if (bInv && bInt) { |
3309 | break; |
3310 | } |
3311 | } |
3312 | // |
3313 | if (!bInt || !bInv) { |
3314 | continue; |
3315 | } |
3316 | // |
3317 | bFound = Standard_True; |
3318 | // |
3319 | // append opposite face to all invalid edges in the split |
3320 | aExpE.Init(aFImIm, TopAbs_EDGE); |
3321 | for (; aExpE.More(); aExpE.Next()) { |
3322 | const TopoDS_Shape& aE = aExpE.Current(); |
3323 | const TopTools_ListOfShape* pLEOr = aDMEOr.Seek(aE); |
3324 | if (!pLEOr) { |
3325 | continue; |
3326 | } |
3327 | // |
3328 | TopTools_ListIteratorOfListOfShape aItLE(*pLEOr); |
3329 | for (; aItLE.More(); aItLE.Next()) { |
3330 | const TopoDS_Shape& aEOr = aItLE.Value(); |
3331 | TopTools_ListOfShape *pLFE = theSSInterfs.ChangeSeek(aEOr); |
3332 | if (!pLFE) { |
3333 | pLFE = theSSInterfs.Bound(aEOr, TopTools_ListOfShape()); |
3334 | } |
3335 | AppendToList(*pLFE, aFOp); |
3336 | } |
3337 | } |
3338 | } |
3339 | if (bFound) { |
3340 | // save connection between offset faces |
3341 | TopTools_ListOfShape *pLF = theSSInterfs.ChangeSeek(aF); |
3342 | if (!pLF) { |
3343 | pLF = theSSInterfs.Bound(aF, TopTools_ListOfShape()); |
3344 | } |
3345 | AppendToList(*pLF, aFOp); |
3346 | } |
3347 | } |
3348 | } |
3349 | } |
3350 | |
bc4a3867 |
3351 | //======================================================================= |
3352 | //function : RemoveHangingParts |
3353 | //purpose : Remove isolated invalid hanging parts |
3354 | //======================================================================= |
3355 | void RemoveHangingParts(const BOPAlgo_MakerVolume& theMV, |
3356 | const TopTools_DataMapOfShapeShape& theDMFImF, |
3357 | const TopTools_IndexedMapOfShape& theMFInv, |
3358 | const TopTools_IndexedMapOfShape& theInvEdges, |
e08a9b03 |
3359 | const TopTools_MapOfShape& theInvertedEdges, |
bc4a3867 |
3360 | TopTools_MapOfShape& theMFToRem) |
3361 | { |
3362 | // Map the faces of the result solids to filter them from avoided faces |
3363 | TopTools_IndexedMapOfShape aMFS; |
3364 | TopExp::MapShapes(theMV.Shape(), TopAbs_FACE, aMFS); |
3365 | |
3366 | BRep_Builder aBB; |
3367 | // Build compound of all faces not included into solids |
3368 | TopoDS_Compound aCFHangs; |
3369 | aBB.MakeCompound(aCFHangs); |
3370 | |
3371 | // Tool for getting the splits of faces |
1155d05a |
3372 | const TopTools_DataMapOfShapeListOfShape& aMVIms = theMV.Images(); |
bc4a3867 |
3373 | |
3374 | TopTools_ListIteratorOfListOfShape aItLArgs(theMV.Arguments()); |
3375 | for (; aItLArgs.More(); aItLArgs.Next()) |
3376 | { |
3377 | TopExp_Explorer anExpF(aItLArgs.Value(), TopAbs_FACE); |
3378 | for (; anExpF.More(); anExpF.Next()) |
3379 | { |
3380 | const TopoDS_Shape& aF = anExpF.Current(); |
e08a9b03 |
3381 | TakeModified(aF, aMVIms, aCFHangs, &aMFS); |
bc4a3867 |
3382 | } |
3383 | } |
3384 | |
3385 | // Make connexity blocks of all hanging parts and check that they are isolated |
1155d05a |
3386 | TopTools_ListOfShape aLCBHangs; |
bc4a3867 |
3387 | BOPTools_AlgoTools::MakeConnexityBlocks(aCFHangs, TopAbs_EDGE, TopAbs_FACE, aLCBHangs); |
3388 | if (aLCBHangs.IsEmpty()) |
3389 | return; |
3390 | |
3391 | // To be removed, the block should contain invalid splits of offset faces and should |
3392 | // meet one of the following conditions: |
3393 | // 1. The block should not be connected to any invalid parts (Faces or Edges) |
3394 | // contained in solids; |
3395 | // 2. The block should be isolated from other faces, i.e. it should consist of |
3396 | // the splits of the single offset face. |
3397 | |
3398 | // Map the edges and vertices of the result solids to check connectivity |
3399 | // of the hanging blocks to invalid parts contained in solids |
3400 | TopTools_IndexedDataMapOfShapeListOfShape aDMEF, aDMVE; |
3401 | TopExp::MapShapesAndAncestors(theMV.Shape(), TopAbs_EDGE , TopAbs_FACE, aDMEF); |
3402 | TopExp::MapShapesAndAncestors(theMV.Shape(), TopAbs_VERTEX, TopAbs_EDGE, aDMVE); |
3403 | |
3404 | // Update invalid edges with intersection results |
3405 | TopTools_MapOfShape aMEInv; |
3406 | Standard_Integer i, aNbE = theInvEdges.Extent(); |
e08a9b03 |
3407 | for (i = 1; i <= aNbE; ++i) |
3408 | TakeModified(theInvEdges(i), aMVIms, aMEInv); |
3409 | |
3410 | // Update inverted edges with intersection results |
3411 | TopTools_MapOfShape aMEInverted; |
3412 | for (TopTools_MapIteratorOfMapOfShape itM(theInvertedEdges); itM.More(); itM.Next()) |
3413 | TakeModified(itM.Value(), aMVIms, aMEInverted); |
bc4a3867 |
3414 | |
3415 | // Tool for getting the origins of the splits |
1155d05a |
3416 | const TopTools_DataMapOfShapeListOfShape& aMVOrs = theMV.Origins(); |
bc4a3867 |
3417 | |
e08a9b03 |
3418 | // Find hanging blocks to remove |
3419 | TopTools_ListOfShape aBlocksToRemove; |
3420 | |
1155d05a |
3421 | TopTools_ListIteratorOfListOfShape aItLCBH(aLCBHangs); |
bc4a3867 |
3422 | for (; aItLCBH.More(); aItLCBH.Next()) |
3423 | { |
3424 | const TopoDS_Shape& aCBH = aItLCBH.Value(); |
3425 | |
e08a9b03 |
3426 | // Remove the block containing the inverted edges |
3427 | Standard_Boolean bHasInverted = Standard_False; |
3428 | TopExp_Explorer anExpE(aCBH, TopAbs_EDGE); |
3429 | for (; anExpE.More() && !bHasInverted; anExpE.Next()) |
3430 | { |
3431 | const TopoDS_Shape& aE = anExpE.Current(); |
3432 | bHasInverted = !aDMEF .Contains(aE) && |
3433 | aMEInverted.Contains(aE); |
3434 | } |
3435 | |
3436 | if (bHasInverted) |
3437 | { |
3438 | aBlocksToRemove.Append(aCBH); |
3439 | continue; |
3440 | } |
3441 | |
bc4a3867 |
3442 | // Check the block to contain invalid split |
3443 | Standard_Boolean bHasInvalidFace = Standard_False; |
3444 | // Check connectivity to invalid parts |
3445 | Standard_Boolean bIsConnected = Standard_False; |
3446 | TopTools_IndexedMapOfShape aBlockME; |
3447 | TopExp::MapShapes(aCBH, TopAbs_EDGE, aBlockME); |
3448 | // Map to collect all original faces |
3449 | TopTools_MapOfShape aMOffsetF; |
3450 | |
3451 | TopExp_Explorer anExpF(aCBH, TopAbs_FACE); |
3452 | for (; anExpF.More(); anExpF.Next()) |
3453 | { |
3454 | const TopoDS_Shape& aF = anExpF.Current(); |
3455 | // Check block to contain invalid face |
3456 | if (!bHasInvalidFace) |
3457 | bHasInvalidFace = theMFInv.Contains(aF); |
3458 | |
3459 | // Check block for connectivity to invalid parts |
3460 | if (!bIsConnected) |
3461 | { |
3462 | // check edges |
e08a9b03 |
3463 | anExpE.Init(aF, TopAbs_EDGE); |
bc4a3867 |
3464 | for (; anExpE.More() && !bIsConnected; anExpE.Next()) |
3465 | { |
3466 | const TopoDS_Shape& aE = anExpE.Current(); |
3467 | const TopTools_ListOfShape *pLF = aDMEF.Seek(aE); |
3468 | if (pLF) |
3469 | { |
3470 | TopTools_ListIteratorOfListOfShape aItLF(*pLF); |
3471 | for (; aItLF.More() && !bIsConnected; aItLF.Next()) |
3472 | bIsConnected = theMFInv.Contains(aItLF.Value()); |
3473 | } |
3474 | } |
3475 | // check vertices |
e08a9b03 |
3476 | if (!bIsConnected) |
bc4a3867 |
3477 | { |
e08a9b03 |
3478 | TopExp_Explorer anExpV(aF, TopAbs_VERTEX); |
3479 | for (; anExpV.More() && !bIsConnected; anExpV.Next()) |
bc4a3867 |
3480 | { |
e08a9b03 |
3481 | const TopoDS_Shape& aV = anExpV.Current(); |
3482 | const TopTools_ListOfShape *pLE = aDMVE.Seek(aV); |
3483 | if (pLE) |
3484 | { |
3485 | TopTools_ListIteratorOfListOfShape aItLE(*pLE); |
3486 | for (; aItLE.More() && !bIsConnected; aItLE.Next()) |
3487 | bIsConnected = !aBlockME.Contains(aItLE.Value()) && |
3488 | aMEInv .Contains(aItLE.Value()); |
3489 | } |
bc4a3867 |
3490 | } |
3491 | } |
3492 | } |
3493 | |
3494 | // Check block to be isolated |
1155d05a |
3495 | const TopTools_ListOfShape* pLFOr = aMVOrs.Seek(aF); |
bc4a3867 |
3496 | if (pLFOr) |
3497 | { |
3498 | TopTools_ListIteratorOfListOfShape aItLFOr(*pLFOr); |
3499 | for (; aItLFOr.More(); aItLFOr.Next()) |
3500 | { |
3501 | const TopoDS_Shape* pFOffset = theDMFImF.Seek(aItLFOr.Value()); |
3502 | if (pFOffset) |
3503 | aMOffsetF.Add(*pFOffset); |
3504 | } |
3505 | } |
3506 | else |
3507 | { |
3508 | const TopoDS_Shape* pFOffset = theDMFImF.Seek(aF); |
3509 | if (pFOffset) |
3510 | aMOffsetF.Add(*pFOffset); |
3511 | } |
3512 | } |
3513 | |
3514 | Standard_Boolean bRemove = bHasInvalidFace && |
3515 | (!bIsConnected || aMOffsetF.Extent() == 1); |
3516 | |
3517 | if (bRemove) |
e08a9b03 |
3518 | aBlocksToRemove.Append(aCBH); |
3519 | } |
3520 | |
3521 | // remove the invalidated blocks |
3522 | aItLCBH.Initialize(aBlocksToRemove); |
3523 | for (; aItLCBH.More(); aItLCBH.Next()) |
3524 | { |
3525 | const TopoDS_Shape& aCBH = aItLCBH.Value(); |
3526 | TopExp_Explorer anExpF(aCBH, TopAbs_FACE); |
3527 | for (; anExpF.More(); anExpF.Next()) |
3528 | theMFToRem.Add(anExpF.Current()); |
bc4a3867 |
3529 | } |
3530 | } |
3531 | |
ecf4f17c |
3532 | //======================================================================= |
3533 | //function : RemoveValidSplits |
3534 | //purpose : Removing valid splits according to results of intersection |
3535 | //======================================================================= |
3536 | void RemoveValidSplits(const TopTools_MapOfShape& theSpRem, |
3537 | TopTools_IndexedDataMapOfShapeListOfShape& theImages, |
3538 | BOPAlgo_Builder& theGF, |
3539 | TopTools_IndexedMapOfShape& theMERemoved) |
3540 | { |
3541 | Standard_Integer i, aNb = theImages.Extent(); |
3542 | if (!aNb) { |
3543 | return; |
3544 | } |
3545 | // |
3546 | for (i = 1; i <= aNb; ++i) { |
3547 | TopTools_ListOfShape& aLSIm = theImages(i); |
3548 | TopTools_ListIteratorOfListOfShape aIt(aLSIm); |
3549 | for (; aIt.More(); ) { |
3550 | const TopoDS_Shape& aSIm = aIt.Value(); |
3551 | if (theSpRem.Contains(aSIm)) { |
3552 | TopExp::MapShapes(aSIm, TopAbs_EDGE, theMERemoved); |
3553 | aLSIm.Remove(aIt); |
3554 | continue; |
3555 | } |
3556 | // |
3557 | // check if all its images are have to be removed |
3558 | const TopTools_ListOfShape& aLSImIm = theGF.Modified(aSIm); |
3559 | if (aLSImIm.Extent()) { |
3560 | Standard_Boolean bAllRem = Standard_True; |
3561 | TopTools_ListIteratorOfListOfShape aIt1(aLSImIm); |
3562 | for (; aIt1.More(); aIt1.Next()) { |
3563 | const TopoDS_Shape& aSImIm = aIt1.Value(); |
3564 | if (theSpRem.Contains(aSImIm)) { |
3565 | TopExp::MapShapes(aSImIm, TopAbs_EDGE, theMERemoved); |
3566 | } |
3567 | else { |
3568 | bAllRem = Standard_False; |
3569 | } |
3570 | } |
3571 | // |
3572 | if (bAllRem) { |
3573 | TopExp::MapShapes(aSIm, TopAbs_EDGE, theMERemoved); |
3574 | aLSIm.Remove(aIt); |
3575 | continue; |
3576 | } |
3577 | } |
3578 | aIt.Next(); |
3579 | } |
3580 | } |
3581 | } |
3582 | |
3583 | //======================================================================= |
3584 | //function : RemoveInvalidSplits |
3585 | //purpose : Removing invalid splits according to the results of intersection |
3586 | //======================================================================= |
3587 | void RemoveInvalidSplits(const TopTools_MapOfShape& theSpRem, |
3588 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
3589 | const TopTools_IndexedMapOfShape& theInvEdges, |
3590 | TopTools_IndexedDataMapOfShapeListOfShape& theImages, |
3591 | BOPAlgo_Builder& theGF, |
3592 | TopTools_IndexedMapOfShape& theMERemoved) |
3593 | { |
3594 | Standard_Integer i, aNb = theImages.Extent(); |
3595 | if (!aNb) { |
3596 | return; |
3597 | } |
3598 | // |
3599 | for (i = 1; i <= aNb; ++i) { |
3600 | const TopoDS_Shape& aS = theImages.FindKey(i); |
3601 | Standard_Boolean bArt = theArtInvFaces.IsBound(aS); |
3602 | // |
3603 | TopTools_ListOfShape& aLSIm = theImages(i); |
3604 | TopTools_ListIteratorOfListOfShape aIt(aLSIm); |
3605 | for (; aIt.More();) { |
3606 | const TopoDS_Shape& aSIm = aIt.Value(); |
3607 | if (theSpRem.Contains(aSIm)) { |
3608 | TopExp::MapShapes(aSIm, TopAbs_EDGE, theMERemoved); |
3609 | aLSIm.Remove(aIt); |
3610 | continue; |
3611 | } |
3612 | // |
3613 | // check if all its images are have to be removed |
3614 | const TopTools_ListOfShape& aLSImIm = theGF.Modified(aSIm); |
3615 | if (aLSImIm.IsEmpty()) { |
3616 | aIt.Next(); |
3617 | continue; |
3618 | } |
3619 | // |
3620 | Standard_Boolean bAllRem = Standard_True; |
3621 | TopTools_IndexedMapOfShape aMERemoved; |
3622 | TopTools_ListIteratorOfListOfShape aIt1(aLSImIm); |
3623 | for (; aIt1.More(); aIt1.Next()) { |
3624 | const TopoDS_Shape& aSImIm = aIt1.Value(); |
3625 | if (theSpRem.Contains(aSImIm)) { |
3626 | TopExp::MapShapes(aSImIm, TopAbs_EDGE, aMERemoved); |
3627 | } |
3628 | else { |
3629 | bAllRem = Standard_False; |
3630 | } |
3631 | } |
3632 | // |
3633 | if (bAllRem) { |
3634 | aLSIm.Remove(aIt); |
3635 | continue; |
3636 | } |
3637 | // |
3638 | if (bArt) { |
3639 | aIt.Next(); |
3640 | continue; |
3641 | } |
3642 | // |
3643 | // remove the face from invalid if all invalid edges of this face |
3644 | // have been marked for removal |
3645 | TopExp_Explorer aExpE(aSIm, TopAbs_EDGE); |
3646 | for (; aExpE.More(); aExpE.Next()) { |
3647 | const TopoDS_Shape& aEInv = aExpE.Current(); |
3648 | if (theInvEdges.Contains(aEInv) && !aMERemoved.Contains(aEInv)) { |
3649 | break; |
3650 | } |
3651 | } |
3652 | if (!aExpE.More()) { |
3653 | TopExp::MapShapes(aSIm, TopAbs_EDGE, theMERemoved); |
3654 | aLSIm.Remove(aIt); |
3655 | } |
3656 | else { |
3657 | aIt.Next(); |
3658 | } |
3659 | } |
3660 | } |
3661 | } |
3662 | |
3663 | //======================================================================= |
3664 | //function : FilterEdgesImages |
3665 | //purpose : Updating the maps of images and origins of the offset edges |
3666 | //======================================================================= |
3667 | void FilterEdgesImages(const TopoDS_Shape& theS, |
3668 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
3669 | TopTools_DataMapOfShapeListOfShape& theOEOrigins) |
3670 | { |
3671 | // map edges |
3672 | TopTools_IndexedMapOfShape aME; |
3673 | TopExp::MapShapes(theS, TopAbs_EDGE, aME); |
3674 | // |
3675 | theOEOrigins.Clear(); |
3676 | TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDM(theOEImages); |
3677 | for (; aItDM.More(); aItDM.Next()) { |
3678 | const TopoDS_Shape& aE = aItDM.Key(); |
3679 | TopTools_ListOfShape& aLEIm = aItDM.ChangeValue(); |
3680 | // |
3681 | TopTools_ListIteratorOfListOfShape aIt(aLEIm); |
3682 | for (; aIt.More(); ) { |
3683 | const TopoDS_Shape& aEIm = aIt.Value(); |
3684 | // filter images |
3685 | if (!aME.Contains(aEIm)) { |
3686 | // remove the image |
3687 | // edges with no images left should be kept in the map |
3688 | // to avoid their usage when building the splits of faces |
3689 | aLEIm.Remove(aIt); |
3690 | continue; |
3691 | } |
3692 | // |
3693 | // save origins |
3694 | if (theOEOrigins.IsBound(aEIm)) { |
3695 | AppendToList(theOEOrigins.ChangeFind(aEIm), aE); |
3696 | } |
3697 | else { |
3698 | TopTools_ListOfShape aLOr; |
3699 | aLOr.Append(aE); |
3700 | theOEOrigins.Bind(aEIm, aLOr); |
3701 | } |
3702 | // |
3703 | aIt.Next(); |
3704 | } |
3705 | } |
3706 | } |
3707 | |
3708 | //======================================================================= |
3709 | //function : FilterInvalidFaces |
3710 | //purpose : Filtering of the invalid faces |
3711 | //======================================================================= |
3712 | void FilterInvalidFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
baaacd46 |
3713 | const TopTools_IndexedDataMapOfShapeListOfShape& theDMEF, |
3714 | const TopTools_IndexedMapOfShape& theMERemoved, |
ecf4f17c |
3715 | TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
3716 | TopTools_DataMapOfShapeShape& theArtInvFaces) |
3717 | { |
3718 | // |
3719 | // filter invalid faces, considering faces having only valid |
3720 | // images left with non-free edges as valid |
3721 | // do not remove invalid faces if it creates free edges |
3722 | // |
3723 | TopTools_IndexedDataMapOfShapeListOfShape aReallyInvFaces; |
3724 | TopTools_ListIteratorOfListOfShape aItLF; |
3725 | // |
3726 | Standard_Integer i, aNb = theInvFaces.Extent(); |
3727 | for (i = 1; i <= aNb; ++i) { |
3728 | const TopoDS_Shape& aF = theInvFaces.FindKey(i); |
3729 | const TopTools_ListOfShape& aLFInv = theInvFaces(i); |
3730 | // |
3731 | if (theArtInvFaces.IsBound(aF)) { |
3732 | if (aLFInv.IsEmpty()) { |
3733 | theArtInvFaces.UnBind(aF); |
3734 | } |
3735 | else { |
3736 | aReallyInvFaces.Add(aF, aLFInv); |
3737 | } |
3738 | continue; |
3739 | } |
3740 | // |
3741 | if (aLFInv.IsEmpty()) { |
3742 | continue; |
3743 | } |
3744 | // |
3745 | const TopTools_ListOfShape& aLFIm = theFImages.FindFromKey(aF); |
3746 | Standard_Boolean bInvalid = aLFIm.IsEmpty(); |
3747 | // |
3748 | if (!bInvalid) { |
3749 | // check two lists on common splits |
3750 | aItLF.Initialize(aLFInv); |
3751 | for (; aItLF.More(); aItLF.Next()) { |
3752 | const TopoDS_Shape& aFInv = aItLF.Value(); |
3753 | // |
3754 | TopTools_ListIteratorOfListOfShape aItLFIm(aLFIm); |
3755 | for (; aItLFIm.More(); aItLFIm.Next()) { |
3756 | const TopoDS_Shape& aFIm = aItLFIm.Value(); |
3757 | // |
3758 | if (aFInv.IsSame(aFIm)) { |
3759 | break; |
3760 | } |
3761 | } |
3762 | // |
3763 | if (aItLFIm.More()) { |
3764 | break; |
3765 | } |
3766 | } |
3767 | // |
3768 | bInvalid = aItLF.More(); |
3769 | } |
3770 | // |
3771 | if (!bInvalid) { |
3772 | // check for free edges |
3773 | for (Standard_Integer j = 0; !bInvalid && j < 2; ++j) { |
3774 | const TopTools_ListOfShape& aLI = !j ? aLFIm : aLFInv; |
3775 | aItLF.Initialize(aLI); |
3776 | for (; aItLF.More(); aItLF.Next()) { |
3777 | const TopoDS_Shape& aFIm = aItLF.Value(); |
3778 | // |
3779 | TopExp_Explorer aExp(aFIm, TopAbs_EDGE); |
3780 | for (; aExp.More(); aExp.Next()) { |
3781 | const TopoDS_Shape& aE = aExp.Current(); |
baaacd46 |
3782 | if (!theMERemoved.Contains(aE)) { |
3783 | const TopTools_ListOfShape* pLEF = theDMEF.Seek(aE); |
3784 | if (pLEF && pLEF->Extent() == 1) { |
ecf4f17c |
3785 | break; |
3786 | } |
3787 | } |
3788 | } |
3789 | // |
3790 | if (aExp.More()) { |
3791 | break; |
3792 | } |
3793 | } |
3794 | bInvalid = aItLF.More(); |
3795 | } |
3796 | } |
3797 | // |
3798 | if (bInvalid) { |
3799 | aReallyInvFaces.Add(aF, aLFInv); |
3800 | } |
3801 | } |
3802 | // |
3803 | theInvFaces = aReallyInvFaces; |
3804 | } |
3805 | |
3806 | //======================================================================= |
3807 | //function : FilterInvalidEdges |
3808 | //purpose : Filtering the invalid edges according to currently invalid faces |
3809 | //======================================================================= |
3810 | void FilterInvalidEdges(const TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
3811 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
3812 | const TopTools_DataMapOfShapeListOfShape& theDMFLIE, |
3813 | const TopTools_IndexedMapOfShape& theMERemoved, |
3814 | TopTools_IndexedMapOfShape& theInvEdges) |
3815 | { |
3816 | TopoDS_Compound aCEInv; |
3817 | TopTools_IndexedMapOfShape aMEInv; |
3818 | BRep_Builder aBB; |
3819 | aBB.MakeCompound(aCEInv); |
3820 | TopTools_ListIteratorOfListOfShape aItLF; |
3821 | // |
3822 | Standard_Integer i, aNb = theInvFaces.Extent(); |
3823 | for (i = 1; i <= aNb; ++i) { |
3824 | const TopTools_ListOfShape& aLFInv = theInvFaces(i); |
3825 | aItLF.Initialize(aLFInv); |
3826 | for (; aItLF.More(); aItLF.Next()) { |
3827 | const TopoDS_Shape& aFIm = aItLF.Value(); |
3828 | TopExp::MapShapes(aFIm, TopAbs_EDGE, aMEInv); |
3829 | // |
3830 | TopExp_Explorer aExpE(aFIm, TopAbs_EDGE); |
3831 | for (; aExpE.More(); aExpE.Next()) { |
3832 | const TopoDS_Shape& aE = aExpE.Current(); |
3833 | if (theInvEdges.Contains(aE)) { |
3834 | aBB.Add(aCEInv, aE); |
3835 | } |
3836 | } |
3837 | } |
3838 | } |
3839 | // |
3840 | // remove edges which have been marked for removal |
3841 | TopTools_IndexedMapOfShape aMEInvToAvoid; |
3842 | TopTools_ListOfShape aLCBE; |
3843 | BOPTools_AlgoTools::MakeConnexityBlocks(aCEInv, TopAbs_VERTEX, TopAbs_EDGE, aLCBE); |
3844 | // |
3845 | TopTools_ListIteratorOfListOfShape aItLCBE(aLCBE); |
3846 | for (; aItLCBE.More(); aItLCBE.Next()) { |
3847 | const TopoDS_Shape& aCBE = aItLCBE.Value(); |
3848 | TopExp_Explorer aExpCB(aCBE, TopAbs_EDGE); |
3849 | for (; aExpCB.More(); aExpCB.Next()) { |
3850 | const TopoDS_Shape& aE = aExpCB.Current(); |
3851 | if (!theMERemoved.Contains(aE)) { |
3852 | break; |
3853 | } |
3854 | } |
3855 | // |
3856 | if (!aExpCB.More()) { |
3857 | TopExp::MapShapes(aCBE, TopAbs_EDGE, aMEInvToAvoid); |
3858 | } |
3859 | } |
3860 | // |
3861 | TopTools_IndexedMapOfShape aReallyInvEdges; |
3862 | // |
3863 | aNb = theInvFaces.Extent(); |
3864 | for (i = 1; i <= aNb; ++i) { |
3865 | const TopoDS_Shape& aF = theInvFaces.FindKey(i); |
3866 | if (theArtInvFaces.IsBound(aF)) { |
3867 | const TopTools_ListOfShape& aLEInv = theDMFLIE.Find(aF); |
3868 | aItLF.Initialize(aLEInv); |
3869 | for (; aItLF.More(); aItLF.Next()) { |
3870 | const TopoDS_Shape& aE = aItLF.Value(); |
3871 | if (aMEInv.Contains(aE) && !aMEInvToAvoid.Contains(aE)) { |
3872 | aReallyInvEdges.Add(aE); |
3873 | } |
3874 | } |
3875 | } |
3876 | else { |
3877 | const TopTools_ListOfShape& aLFInv = theInvFaces(i); |
3878 | aItLF.Initialize(aLFInv); |
3879 | for (; aItLF.More(); aItLF.Next()) { |
3880 | const TopoDS_Shape& aFIm = aItLF.Value(); |
3881 | TopExp_Explorer aExpE(aFIm, TopAbs_EDGE); |
3882 | for (; aExpE.More(); aExpE.Next()) { |
3883 | const TopoDS_Shape& aE = aExpE.Current(); |
3884 | if (theInvEdges.Contains(aE) && !aMEInvToAvoid.Contains(aE)) { |
3885 | aReallyInvEdges.Add(aE); |
3886 | } |
3887 | } |
3888 | } |
3889 | } |
3890 | } |
3891 | // |
3892 | theInvEdges = aReallyInvEdges; |
3893 | } |
3894 | |
3895 | //======================================================================= |
3896 | //function : FindFacesToRebuild |
3897 | //purpose : Looking for the faces that have to be rebuilt: |
3898 | // 1. Faces close to invalidity |
3899 | // 2. Faces containing some invalid parts |
3900 | //======================================================================= |
3901 | void FindFacesToRebuild(const TopTools_IndexedDataMapOfShapeListOfShape& theLFImages, |
3902 | const TopTools_IndexedMapOfShape& theInvEdges, |
3903 | const TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
3904 | const TopTools_DataMapOfShapeListOfShape& theSSInterfs, |
3905 | TopTools_IndexedDataMapOfShapeListOfShape& theFToRebuild, |
3906 | TopTools_MapOfShape& theFSelfRebAvoid) |
3907 | { |
3908 | Standard_Integer i, aNb = theLFImages.Extent(); |
3909 | if (!aNb) { |
3910 | return; |
3911 | } |
3912 | // |
3913 | Standard_Boolean bRebuild; |
3914 | TopTools_ListIteratorOfListOfShape aItLF; |
3915 | TopTools_ListOfShape aLEValid; |
3916 | TopTools_MapOfShape aMFence, aMEReb, aMFReb; |
3917 | TopExp_Explorer aExp; |
3918 | // |
3919 | TopTools_DataMapOfShapeListOfShape aDMFLV; |
3920 | // get edges from invalid faces |
3921 | aNb = theInvFaces.Extent(); |
3922 | for (i = 1; i <= aNb; i++) { |
3923 | const TopoDS_Shape& aF = theInvFaces.FindKey(i); |
3924 | aMFence.Clear(); |
3925 | TopTools_ListOfShape aLVAvoid; |
3926 | const TopTools_ListOfShape& aLFIm = theInvFaces(i); |
3927 | aItLF.Initialize(aLFIm); |
3928 | for (; aItLF.More(); aItLF.Next()) { |
3929 | const TopoDS_Shape& aFIm = aItLF.Value(); |
3930 | aExp.Init(aFIm, TopAbs_EDGE); |
3931 | for (; aExp.More(); aExp.Next()) { |
3932 | const TopoDS_Shape& aE = aExp.Current(); |
3933 | aMEReb.Add(aE); |
3934 | if (theInvEdges.Contains(aE)) { |
3935 | TopExp_Explorer aExpV(aE, TopAbs_VERTEX); |
3936 | for (; aExpV.More(); aExpV.Next()) { |
3937 | const TopoDS_Shape& aV = aExpV.Current(); |
3938 | if (aMFence.Add(aV)) { |
3939 | aLVAvoid.Append(aV); |
3940 | aMEReb.Add(aV); |
3941 | } |
3942 | } |
3943 | } |
3944 | } |
3945 | } |
3946 | // |
3947 | if (aLVAvoid.Extent()) { |
3948 | aDMFLV.Bind(aF, aLVAvoid); |
3949 | } |
3950 | // |
3951 | const TopTools_ListOfShape* pLF = theSSInterfs.Seek(aF); |
3952 | if (pLF) { |
3953 | TopTools_ListIteratorOfListOfShape aItLFE(*pLF); |
3954 | for (; aItLFE.More(); aItLFE.Next()) { |
3955 | const TopoDS_Shape& aFE = aItLFE.Value(); |
3956 | aMFReb.Add(aFE); |
3957 | } |
3958 | } |
3959 | } |
3960 | // |
3961 | // get face to rebuild |
3962 | aNb = theLFImages.Extent(); |
3963 | for (i = 1; i <= aNb; i++) { |
3964 | const TopoDS_Shape& aF = theLFImages.FindKey(i); |
3965 | const TopTools_ListOfShape& aLFIm = theLFImages(i); |
3966 | TopTools_MapOfShape aMVAvoid; |
3967 | if (aDMFLV.IsBound(aF)) { |
3968 | const TopTools_ListOfShape& aLVAvoid = aDMFLV.Find(aF); |
3969 | TopTools_ListIteratorOfListOfShape aItLV(aLVAvoid); |
3970 | for (; aItLV.More(); aItLV.Next()) { |
3971 | const TopoDS_Shape& aV = aItLV.Value(); |
3972 | aMVAvoid.Add(aV); |
3973 | } |
3974 | } |
3975 | // |
3976 | bRebuild = aMFReb.Contains(aF); |
3977 | aLEValid.Clear(); |
3978 | aMFence.Clear(); |
3979 | // |
3980 | aItLF.Initialize(aLFIm); |
3981 | for (; aItLF.More(); aItLF.Next()) { |
3982 | const TopoDS_Shape& aFIm = aItLF.Value(); |
3983 | aExp.Init(aFIm, TopAbs_EDGE); |
3984 | for (; aExp.More(); aExp.Next()) { |
3985 | const TopoDS_Edge& anEIm = TopoDS::Edge(aExp.Current()); |
3986 | if (!theInvEdges.Contains(anEIm)) { |
3987 | if (aMFence.Add(anEIm)) { |
3988 | aLEValid.Append(anEIm); |
3989 | } |
3990 | } |
3991 | // |
3992 | if (!bRebuild) { |
3993 | bRebuild = aMEReb.Contains(anEIm); |
3994 | } |
3995 | // |
3996 | if (!bRebuild) { |
3997 | // check vertices |
3998 | TopExp_Explorer aExpV(anEIm, TopAbs_VERTEX); |
3999 | for (; aExpV.More() && !bRebuild; aExpV.Next()) { |
4000 | const TopoDS_Shape& aV = aExpV.Current(); |
4001 | if (!aMVAvoid.Contains(aV)) { |
4002 | bRebuild = aMEReb.Contains(aV); |
4003 | } |
4004 | } |
4005 | } |
4006 | } |
4007 | } |
4008 | // |
4009 | if (!bRebuild) { |
4010 | bRebuild = aLFIm.Extent() && theInvFaces.Contains(aF); |
4011 | if (bRebuild) { |
4012 | theFSelfRebAvoid.Add(aF); |
4013 | } |
4014 | } |
4015 | // |
4016 | if (bRebuild) { |
4017 | theFToRebuild.Add(aF, aLEValid); |
4018 | } |
4019 | } |
4020 | } |
4021 | |
4022 | //======================================================================= |
4023 | //function : RebuildFaces |
4024 | //purpose : Rebuilding of the faces |
4025 | //======================================================================= |
4026 | void RebuildFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebuild, |
4027 | const TopTools_MapOfShape& theFSelfRebAvoid, |
4028 | const TopoDS_Shape& theSolids, |
4029 | const TopTools_DataMapOfShapeListOfShape& theSSInterfs, |
4030 | TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
0da0275c |
4031 | TopTools_DataMapOfShapeListOfShape& theDMFNewHoles, |
ecf4f17c |
4032 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
4033 | TopTools_DataMapOfShapeShape& theFacesOrigins, |
4034 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
4035 | TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
4036 | TopTools_MapOfShape& theLastInvEdges, |
4037 | TopTools_IndexedMapOfShape& theEdgesToAvoid, |
4038 | TopTools_IndexedMapOfShape& theInvEdges, |
4039 | TopTools_IndexedMapOfShape& theValidEdges, |
4040 | const TopTools_MapOfShape& theInvertedEdges, |
4041 | TopTools_DataMapOfShapeInteger& theAlreadyInvFaces, |
4042 | TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
4043 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
4044 | TopTools_MapOfShape& theVertsToAvoid, |
4045 | TopTools_DataMapOfShapeShape& theETrimEInf, |
4046 | Handle(BRepAlgo_AsDes)& theAsDes) |
4047 | { |
4048 | TopTools_MapOfShape aModifiedEdges; |
4049 | // |
4050 | // 1. Intersect faces |
4051 | IntersectFaces(theFToRebuild, theFSelfRebAvoid, theSolids, theSSInterfs, theFImages, theEdgesOrigins, theOEImages, |
4052 | theOEOrigins, theInvEdges, theValidEdges, theInvertedEdges, theEdgesToAvoid, |
4053 | theInvFaces, theArtInvFaces, theVertsToAvoid, theETrimEInf, aModifiedEdges, theAsDes); |
4054 | // |
4055 | // 2. Repeat steps to build the correct faces |
0da0275c |
4056 | BuildSplitsOfInvFaces(theFToRebuild, aModifiedEdges, theFImages, theDMFNewHoles, theEdgesOrigins, |
ecf4f17c |
4057 | theFacesOrigins, theOEImages, theOEOrigins, theLastInvEdges, |
4058 | theEdgesToAvoid, theVertsToAvoid, theAlreadyInvFaces, theValidEdges, |
4059 | theETrimEInf, theAsDes); |
4060 | } |
4061 | |
4062 | //======================================================================= |
4063 | //function : IntersectFaces |
4064 | //purpose : Intersection of the faces that should be rebuild |
4065 | // to resolve all invalidities |
4066 | //======================================================================= |
4067 | void IntersectFaces(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebuild, |
4068 | const TopTools_MapOfShape& theFSelfRebAvoid, |
4069 | const TopoDS_Shape& theSolids, |
4070 | const TopTools_DataMapOfShapeListOfShape& theSSInterfs, |
4071 | TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
4072 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
4073 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
4074 | TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
4075 | TopTools_IndexedMapOfShape& theInvEdges, |
4076 | TopTools_IndexedMapOfShape& theValidEdges, |
4077 | const TopTools_MapOfShape& theInvertedEdges, |
4078 | TopTools_IndexedMapOfShape& theEdgesToAvoid, |
4079 | TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
4080 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
4081 | TopTools_MapOfShape& theVertsToAvoid, |
4082 | TopTools_DataMapOfShapeShape& theETrimEInf, |
4083 | TopTools_MapOfShape& theModifiedEdges, |
4084 | Handle(BRepAlgo_AsDes)& theAsDes) |
4085 | { |
4086 | Standard_Integer aNbFR = theFToRebuild.Extent(); |
4087 | if (!aNbFR) { |
4088 | return; |
4089 | } |
4090 | // |
4091 | Standard_Integer i, j, k, aNbInv; |
4092 | TopTools_ListIteratorOfListOfShape aItLF, aItLE; |
ecf4f17c |
4093 | // |
4094 | // get vertices from invalid edges |
4095 | TopTools_MapOfShape aMVInv, aMVInvAll; |
4096 | aNbInv = theInvEdges.Extent(); |
4097 | for (i = 1; i <= aNbInv; ++i) { |
4098 | const TopoDS_Shape& aEInv = theInvEdges(i); |
4099 | Standard_Boolean bValid = theValidEdges.Contains(aEInv); |
45d0af05 |
4100 | for (TopExp_Explorer aExp (aEInv, TopAbs_VERTEX); aExp.More(); aExp.Next()) { |
ecf4f17c |
4101 | const TopoDS_Shape& aV = aExp.Current(); |
4102 | aMVInvAll.Add(aV); |
4103 | if (!bValid) { |
4104 | aMVInv.Add(aV); |
4105 | } |
4106 | } |
4107 | } |
4108 | // |
4109 | Standard_Boolean bLookVertToAvoid = (aMVInv.Extent() > 0); |
4110 | // |
4111 | TopTools_DataMapOfShapeListOfShape aDMSF, aMDone, aMEInfETrim, aDMVEFull; |
4112 | TopTools_IndexedDataMapOfShapeListOfShape aFLE, aDMEFInv; |
4113 | // |
4114 | // Add all faces to rebuild to outgoing map <aFLE>, |
4115 | // plus link edges and vertices to the faces to |
4116 | // define intersection faces |
4117 | PrepareFacesForIntersection(theFToRebuild, theFImages, theInvFaces, theArtInvFaces, |
4118 | bLookVertToAvoid, aFLE, aMDone, aDMSF, aMEInfETrim, |
4119 | aDMVEFull, theETrimEInf, aDMEFInv); |
4120 | |
4121 | // Find vertices to avoid while trimming the edges. |
4122 | // These vertices are taken from the invalid edges common between |
4123 | // splits of different invalid, but not artificially, faces. |
4124 | // Additional condition for these vertices is that all |
4125 | // edges adjacent to this vertex must be either invalid |
4126 | // or contained in invalid faces |
4127 | TopTools_MapOfShape aMVRInv = theVertsToAvoid; |
bc4a3867 |
4128 | FindVerticesToAvoid(aDMEFInv, theInvEdges, theValidEdges, theInvertedEdges, |
4129 | aDMVEFull, theOEImages, theOEOrigins, aMVRInv); |
ecf4f17c |
4130 | // |
4131 | // The faces should be intersected selectively - |
4132 | // intersect only faces neighboring to the same invalid face |
4133 | // and connected to its invalid edges; |
4134 | // when dealing with artificially invalid faces for intersection to be |
4135 | // complete we need to use not only invalid edges, but also the |
4136 | // edges connected to invalid ones |
b443d536 |
4137 | |
4138 | // find blocks of artificially invalid faces |
4139 | TopTools_DataMapOfShapeShape aDMFImF; |
4140 | TopoDS_Compound aCFArt; |
4141 | BRep_Builder().MakeCompound(aCFArt); |
ecf4f17c |
4142 | TopTools_DataMapIteratorOfDataMapOfShapeShape aItM(theArtInvFaces); |
4143 | for (; aItM.More(); aItM.Next()) { |
4144 | const TopoDS_Shape& aF = aItM.Key(); |
4145 | const TopTools_ListOfShape& aLFInv = theInvFaces.FindFromKey(aF); |
4146 | aItLF.Initialize(aLFInv); |
4147 | for (; aItLF.More(); aItLF.Next()) { |
b443d536 |
4148 | BRep_Builder().Add(aCFArt, aItLF.Value()); |
4149 | aDMFImF.Bind(aItLF.Value(), aF); |
ecf4f17c |
4150 | } |
4151 | } |
4152 | // |
b443d536 |
4153 | // make connexity blocks |
4154 | TopTools_ListOfShape aLCBArt; |
4155 | BOPTools_AlgoTools::MakeConnexityBlocks(aCFArt, TopAbs_VERTEX, TopAbs_FACE, aLCBArt); |
4156 | // |
4157 | // alone edges |
a8232603 |
4158 | TopTools_MapOfShape aMEAlone, aMEInvOnArt; |
b443d536 |
4159 | // |
4160 | TopTools_ListIteratorOfListOfShape aItLCBArt(aLCBArt); |
4161 | for (; aItLCBArt.More(); aItLCBArt.Next()) { |
4162 | const TopoDS_Shape& aCB = aItLCBArt.Value(); |
41aa3c3d |
4163 | // |
b443d536 |
4164 | // check if aCB contains splits of only one offset face |
4165 | TopTools_MapOfShape aMFArt; |
4166 | TopExp_Explorer aExpF(aCB, TopAbs_FACE); |
4167 | for (; aExpF.More(); aExpF.Next()) { |
4168 | aMFArt.Add(aDMFImF.Find(aExpF.Current())); |
41aa3c3d |
4169 | } |
4170 | // |
b443d536 |
4171 | Standard_Boolean bAlone = (aMFArt.Extent() == 1); |
41aa3c3d |
4172 | // |
b443d536 |
4173 | // vertices on invalid edges |
4174 | TopTools_MapOfShape aMVEInv; |
4175 | TopTools_MapOfShape aMFence; |
4176 | // edges that should not be marked as alone - edges having same origins as invalid ones |
4177 | TopTools_MapOfShape aMEAvoid; |
4178 | // map to find alone edges by looking for free vertices |
4179 | TopTools_IndexedDataMapOfShapeListOfShape aDMVEVal; |
4180 | // |
4181 | TopExp_Explorer aExpE(aCB, TopAbs_EDGE); |
4182 | for (; aExpE.More(); aExpE.Next()) { |
4183 | const TopoDS_Shape& aE = aExpE.Current(); |
4184 | if (theInvEdges.Contains(aE)) { |
a8232603 |
4185 | aMEInvOnArt.Add(aE); |
b443d536 |
4186 | for (TopoDS_Iterator aItV(aE); aItV.More(); aItV.Next()) { |
4187 | aMVEInv.Add(aItV.Value()); |
4188 | } |
4189 | // |
4190 | if (bAlone) { |
4191 | const TopTools_ListOfShape *pLEOr = theOEOrigins.Seek(aE); |
4192 | if (pLEOr) { |
4193 | TopTools_ListIteratorOfListOfShape aItLEOr(*pLEOr); |
4194 | for (; aItLEOr.More(); aItLEOr.Next()) { |
4195 | TopTools_ListIteratorOfListOfShape aItLEIm(theOEImages.Find(aItLEOr.Value())); |
4196 | for (; aItLEIm.More(); aItLEIm.Next()) { |
4197 | aMEAvoid.Add(aItLEIm.Value()); |
4198 | } |
4199 | } |
4200 | } |
4201 | } |
4202 | continue; |
4203 | } |
4204 | // |
4205 | if (aMFence.Add(aE)) { |
4206 | TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aDMVEVal); |
ecf4f17c |
4207 | } |
41aa3c3d |
4208 | } |
4209 | // |
b443d536 |
4210 | // find edges with free vertices |
4211 | Standard_Integer aNbV = aDMVEVal.Extent(); |
4212 | for (i = 1; i <= aNbV; ++i) { |
4213 | const TopoDS_Shape& aV = aDMVEVal.FindKey(i); |
4214 | if (!aMVEInv.Contains(aV)) { |
4215 | continue; |
4216 | } |
ecf4f17c |
4217 | // |
b443d536 |
4218 | const TopTools_ListOfShape& aLEV = aDMVEVal(i); |
4219 | if (aLEV.Extent() > 1) { |
4220 | continue; |
4221 | } |
4222 | // |
4223 | const TopoDS_Shape& aE = aLEV.First(); |
4224 | if (aMEAvoid.Contains(aE)) { |
4225 | continue; |
4226 | } |
4227 | // |
4228 | aMEAlone.Add(aE); |
4229 | // |
4230 | // if this alone edge adds nothing to the intersection list |
4231 | // it means that the origin of this edge has been split and we need to |
4232 | // add the neighboring images of the same origins |
4233 | if (aDMSF.Find(aE).Extent() > 1) { |
4234 | continue; |
4235 | } |
4236 | // |
4237 | // check also its vertices |
4238 | TopoDS_Iterator aItE(aE); |
4239 | for (; aItE.More(); aItE.Next()) { |
4240 | const TopoDS_Shape& aVE = aItE.Value(); |
4241 | if (aDMSF.Find(aVE).Extent() > 2) { |
4242 | break; |
4243 | } |
4244 | } |
4245 | // |
4246 | if (aItE.More()) { |
4247 | continue; |
4248 | } |
4249 | // |
4250 | // the edge is useless - look for other images |
4251 | const TopTools_ListOfShape *pLEOr = theOEOrigins.Seek(aE); |
4252 | if (!pLEOr) { |
4253 | continue; |
4254 | } |
4255 | // |
4256 | TopTools_ListIteratorOfListOfShape aItLEOr(*pLEOr); |
4257 | for (; aItLEOr.More(); aItLEOr.Next()) { |
4258 | const TopoDS_Shape& aEOr = aItLEOr.Value(); |
41aa3c3d |
4259 | // |
b443d536 |
4260 | const TopTools_ListOfShape& aLEIm = theOEImages.Find(aEOr); |
4261 | TopTools_ListIteratorOfListOfShape aItLEIm(aLEIm); |
4262 | for (; aItLEIm.More(); aItLEIm.Next()) { |
4263 | const TopoDS_Shape& aEIm = aItLEIm.Value(); |
4264 | // |
4265 | if (aMFence.Contains(aEIm)) { |
4266 | aMEAlone.Add(aEIm); |
4267 | } |
ecf4f17c |
4268 | } |
4269 | } |
41aa3c3d |
4270 | } |
4271 | } |
4272 | // |
4273 | // Get all invalidities from all faces to be used for avoiding |
4274 | // repeated usage of the common edges |
4275 | TopTools_MapOfShape aMAllInvs; |
4276 | aNbInv = theInvFaces.Extent(); |
4277 | for (k = 1; k <= aNbInv; ++k) { |
4278 | TopTools_ListIteratorOfListOfShape aIt(theInvFaces(k)); |
4279 | for (; aIt.More(); aIt.Next()) { |
4280 | TopExp_Explorer aExp(aIt.Value(), TopAbs_EDGE); |
4281 | for (; aExp.More(); aExp.Next()) { |
4282 | const TopoDS_Shape& aE = aExp.Current(); |
4283 | if (theInvEdges.Contains(aE) || aMEAlone.Contains(aE)) { |
4284 | aMAllInvs.Add(aE); |
4285 | TopoDS_Iterator aItV(aE); |
4286 | for (; aItV.More(); aItV.Next()) { |
4287 | aMAllInvs.Add(aItV.Value()); |
ecf4f17c |
4288 | } |
4289 | } |
4290 | } |
4291 | } |
4292 | } |
4293 | // |
4294 | // Bounding vertices of not trimmed edges |
4295 | TopTools_MapOfShape aMVBounds; |
41aa3c3d |
4296 | // |
4297 | TopTools_MapOfShape aMECheckExt; |
ecf4f17c |
4298 | // Save connections between not trimmed edge and its trimmed parts |
4299 | TopTools_DataMapOfShapeListOfShape aDMEETrim; |
4300 | // Splits of the new edges |
4301 | TopTools_DataMapOfShapeListOfShape aEImages; |
4302 | BRep_Builder aBB; |
dcba2e5c |
4303 | |
4304 | // Keep connection between blocks of invalid edges to the lists of |
4305 | // found edges to be intersected for its treatment |
4306 | TopTools_IndexedDataMapOfShapeListOfShape aDMOENEdges; |
4307 | |
ecf4f17c |
4308 | aNbInv = theInvFaces.Extent(); |
4309 | for (k = 1; k <= aNbInv; ++k) { |
4310 | const TopoDS_Shape& aFInv = theInvFaces.FindKey(k); |
4311 | Standard_Boolean bSelfRebAvoid = theFSelfRebAvoid.Contains(aFInv); |
4312 | const TopTools_ListOfShape& aLFInv = theInvFaces(k); |
4313 | // |
4314 | TopTools_ListOfShape aLCB; |
4315 | if (aLFInv.Extent() > 1) { |
4316 | // make compound of invalid faces |
4317 | TopoDS_Compound aCFInv; |
4318 | aBB.MakeCompound(aCFInv); |
4319 | // |
4320 | TopTools_ListIteratorOfListOfShape aIt(aLFInv); |
4321 | for (; aIt.More(); aIt.Next()) { |
4322 | const TopoDS_Shape& aFIm = aIt.Value(); |
4323 | aBB.Add(aCFInv, aFIm); |
4324 | } |
4325 | // |
4326 | // make connexity blocks |
4327 | BOPTools_AlgoTools::MakeConnexityBlocks(aCFInv, TopAbs_EDGE, TopAbs_FACE, aLCB); |
4328 | } |
4329 | else { |
4330 | aLCB = aLFInv; |
4331 | } |
4332 | // |
4333 | Standard_Boolean bArtificial = theArtInvFaces.IsBound(aFInv); |
4334 | TopTools_ListIteratorOfListOfShape aItLCB(aLCB); |
4335 | for (; aItLCB.More(); aItLCB.Next()) { |
4336 | const TopoDS_Shape& aCBInv = aItLCB.Value(); |
4337 | // |
4338 | TopTools_MapOfShape aMEFence; |
4339 | // |
4340 | TopoDS_Compound aCBE; |
4341 | aBB.MakeCompound(aCBE); |
4342 | // |
4343 | TopExp_Explorer aExp(aCBInv, TopAbs_EDGE); |
4344 | for (; aExp.More(); aExp.Next()) { |
4345 | const TopoDS_Shape& aE = aExp.Current(); |
4346 | if (theInvEdges.Contains(aE) || (bArtificial && aMEAlone.Contains(aE))) { |
4347 | if (aMEFence.Add(aE)) { |
4348 | aBB.Add(aCBE, aE); |
4349 | } |
4350 | } |
4351 | } |
4352 | // |
4353 | // make connexity blocks of edges |
4354 | TopTools_ListOfShape aLCBE; |
4355 | BOPTools_AlgoTools::MakeConnexityBlocks(aCBE, TopAbs_VERTEX, TopAbs_EDGE, aLCBE); |
4356 | // |
4357 | TopTools_ListIteratorOfListOfShape aItLCBE(aLCBE); |
4358 | for (; aItLCBE.More(); aItLCBE.Next()) { |
4359 | const TopoDS_Shape& aCBELoc = aItLCBE.Value(); |
4360 | // |
4361 | // map of edges and vertices of processing invalidity |
4362 | TopTools_IndexedMapOfShape aME; |
4363 | // map of vertices to trim the new edges |
4364 | TopTools_IndexedMapOfShape aMECV; |
4365 | TopExp::MapShapes(aCBELoc, TopAbs_EDGE, aME); |
4366 | aMECV = aME; |
4367 | TopExp::MapShapes(aCBELoc, TopAbs_VERTEX, aME); |
4368 | // |
4369 | // Using the map <aME> find chain of faces to be intersected; |
4370 | // |
4371 | // faces for intersection |
4372 | TopTools_IndexedMapOfShape aMFInt; |
4373 | // additional faces for intersection |
4374 | TopTools_IndexedMapOfShape aMFIntExt; |
4375 | // splits of faces for intersection |
4376 | TopTools_ListOfShape aLFInt; |
4377 | // faces to avoid intersection |
4378 | TopTools_IndexedMapOfShape aMFAvoid; |
4379 | // |
4380 | FindFacesForIntersection(aFInv, aME, theFImages, aDMSF, aMVInvAll, |
4381 | theArtInvFaces, bArtificial, theSSInterfs, aMFAvoid, aMFInt, aMFIntExt, aLFInt); |
4382 | if (aMFInt.Extent() < 3) { |
4383 | // nothing to intersect |
4384 | continue; |
4385 | } |
4386 | // |
4387 | // intersect the faces, but do not intersect the invalid ones |
4388 | // among each other (except for the artificially invalid faces) |
4389 | TopTools_IndexedMapOfShape aMEToInt; |
4390 | Standard_Integer aNb = aMFInt.Extent(); |
4391 | for (i = 1; i <= aNb; ++i) { |
4392 | const TopoDS_Face& aFi = TopoDS::Face(aMFInt(i)); |
4393 | if (bSelfRebAvoid && aFi.IsSame(aFInv)) { |
4394 | continue; |
4395 | } |
4396 | // |
4397 | const TopTools_ListOfShape& aLFImi = theFImages.FindFromKey(aFi); |
4398 | // |
4399 | TopTools_ListOfShape& aLFEi = aFLE.ChangeFromKey(aFi); |
4400 | // |
4401 | TopTools_ListOfShape& aLFDone = aMDone.ChangeFind(aFi); |
4402 | // |
4403 | for (j = i + 1; j <= aNb; ++j) { |
4404 | const TopoDS_Face& aFj = TopoDS::Face(aMFInt(j)); |
4405 | if (bSelfRebAvoid && aFj.IsSame(aFInv)) { |
4406 | continue; |
4407 | } |
4408 | // |
4409 | const TopTools_ListOfShape& aLFImj = theFImages.FindFromKey(aFj); |
4410 | // |
4411 | TopTools_ListOfShape& aLFEj = aFLE.ChangeFromKey(aFj); |
4412 | // |
4413 | // if there are some common edges between faces |
4414 | // we should use these edges and do not intersect again. |
4415 | TopTools_ListOfShape aLEC; |
4416 | FindCommonParts(aLFImi, aLFImj, aLEC); |
4417 | // |
4418 | if (aLEC.Extent()) { |
4419 | // no need to intersect if we have common edges between faces |
4420 | Standard_Boolean bForceUse = aMFIntExt.Contains(aFi) || aMFIntExt.Contains(aFj); |
4421 | ProcessCommonEdges(aLEC, theInvEdges, theValidEdges, aME, theETrimEInf, aMEInfETrim, |
41aa3c3d |
4422 | theOEOrigins, aMAllInvs, bForceUse, aMECV, aMECheckExt, aDMEETrim, aLFEi, aLFEj, aMEToInt); |
ecf4f17c |
4423 | continue; |
4424 | } |
4425 | // |
4426 | // check if both these faces are invalid and sharing edges |
4427 | if (theInvFaces.Contains(aFi) && theInvFaces.Contains(aFj) && |
4428 | !theArtInvFaces.IsBound(aFi) && !theArtInvFaces.IsBound(aFj)) { |
4429 | continue; |
4430 | } |
4431 | // |
4432 | // check if these two faces have already been treated |
4433 | aItLE.Initialize(aLFDone); |
4434 | for (; aItLE.More(); aItLE.Next()) { |
4435 | const TopoDS_Shape& aF = aItLE.Value(); |
4436 | if (aF.IsSame(aFj)) { |
4437 | break; |
4438 | } |
4439 | } |
4440 | // |
4441 | if (aItLE.More()) { |
4442 | // use intersection line obtained on the previous steps |
4443 | // plus, find new origins for these lines |
4444 | UpdateIntersectedFaces(aFInv, aFi, aFj, aLFInv, aLFImi, aLFImj, |
4445 | aLFEi, aLFEj, theEdgesOrigins, aMEToInt); |
4446 | continue; |
4447 | } |
4448 | // |
4449 | if (aMFAvoid.Contains(aFi) || aMFAvoid.Contains(aFj)) { |
4450 | continue; |
4451 | } |
4452 | // |
4453 | aLFDone.Append(aFj); |
4454 | aMDone.ChangeFind(aFj).Append(aFi); |
4455 | // |
4456 | IntersectFaces(aFInv, aFi, aFj, aLFInv, aLFImi, aLFImj, |
4457 | aLFEi, aLFEj, theEdgesOrigins, aMECV, aMEToInt); |
4458 | } |
4459 | } |
4460 | // |
4461 | // intersect and trim edges for this chain |
41aa3c3d |
4462 | IntersectAndTrimEdges(theFToRebuild, aMFInt, aMEToInt, aDMEETrim, aME, aMECV, |
4463 | aMVInv, aMVRInv, aMECheckExt, aMVBounds, aEImages); |
dcba2e5c |
4464 | // |
dcba2e5c |
4465 | Standard_Integer iE, aNbEToInt = aMEToInt.Extent(); |
4466 | for (iE = 1; iE <= aNbEToInt; ++iE) |
bc4a3867 |
4467 | { |
4468 | const TopoDS_Shape& aEInt = aMEToInt(iE); |
4469 | TopExp_Explorer anExpE(aCBELoc, TopAbs_EDGE); |
4470 | for (; anExpE.More(); anExpE.Next()) |
4471 | { |
4472 | const TopoDS_Shape& aE = anExpE.Current(); |
4473 | TopTools_ListOfShape* pLEToInt = aDMOENEdges.ChangeSeek(aE); |
4474 | if (!pLEToInt) |
4475 | pLEToInt = &aDMOENEdges(aDMOENEdges.Add(aE, TopTools_ListOfShape())); |
4476 | AppendToList(*pLEToInt, aEInt); |
4477 | } |
4478 | } |
ecf4f17c |
4479 | } |
4480 | } |
4481 | } |
4482 | // |
4483 | // filter the obtained edges |
dcba2e5c |
4484 | UpdateValidEdges(theFImages, aFLE, aDMOENEdges, aMVBounds, theSolids, theInvEdges, theInvertedEdges, aMEInvOnArt, |
41aa3c3d |
4485 | aMECheckExt, theEdgesToAvoid, theEdgesOrigins, theOEImages, theOEOrigins, |
ecf4f17c |
4486 | theVertsToAvoid, theETrimEInf, aEImages, aDMEETrim, theModifiedEdges, theAsDes); |
4487 | } |
4488 | |
4489 | //======================================================================= |
4490 | //function : PrepareFacesForIntersection |
4491 | //purpose : Preparation of the maps for analyzing intersections of the faces |
4492 | //======================================================================= |
4493 | void PrepareFacesForIntersection(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebuild, |
4494 | const TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
4495 | const TopTools_IndexedDataMapOfShapeListOfShape& theInvFaces, |
4496 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
4497 | const Standard_Boolean bLookVertToAvoid, |
4498 | TopTools_IndexedDataMapOfShapeListOfShape& theFLE, |
4499 | TopTools_DataMapOfShapeListOfShape& theMDone, |
4500 | TopTools_DataMapOfShapeListOfShape& theDMSF, |
4501 | TopTools_DataMapOfShapeListOfShape& theMEInfETrim, |
4502 | TopTools_DataMapOfShapeListOfShape& theDMVEFull, |
4503 | TopTools_DataMapOfShapeShape& theETrimEInf, |
4504 | TopTools_IndexedDataMapOfShapeListOfShape& theDMEFInv) |
4505 | { |
4506 | Standard_Integer i, aNb = theFToRebuild.Extent(); |
4507 | for (i = 1; i <= aNb; ++i) { |
4508 | const TopoDS_Shape& aF = theFToRebuild.FindKey(i); |
4509 | // |
4510 | TopTools_ListOfShape aLE; |
4511 | theFLE.Add(aF, aLE); |
4512 | theMDone.Bind(aF, aLE); |
4513 | // |
4514 | const TopTools_ListOfShape& aLFIm = theFImages.FindFromKey(aF); |
4515 | TopTools_ListIteratorOfListOfShape aItLF(aLFIm); |
4516 | for (; aItLF.More(); aItLF.Next()) { |
4517 | const TopoDS_Shape& aFIm = aItLF.Value(); |
4518 | TopExp_Explorer aExp(aFIm, TopAbs_EDGE); |
4519 | for (; aExp.More(); aExp.Next()) { |
4520 | const TopoDS_Shape& aE = aExp.Current(); |
4521 | // save connection to untrimmed face |
4522 | TopTools_ListOfShape *pLF = theDMSF.ChangeSeek(aE); |
4523 | if (!pLF) { |
4524 | pLF = theDMSF.Bound(aE, TopTools_ListOfShape()); |
4525 | } |
4526 | AppendToList(*pLF, aF); |
4527 | // |
4528 | // save connection to untrimmed edge |
4529 | const TopoDS_Shape& aEInf = theETrimEInf.Find(aE); |
4530 | TopTools_ListOfShape *pLETrim = theMEInfETrim.ChangeSeek(aEInf); |
4531 | if (!pLETrim) { |
4532 | pLETrim = theMEInfETrim.Bound(aEInf, TopTools_ListOfShape()); |
4533 | } |
4534 | AppendToList(*pLETrim, aE); |
4535 | // |
4536 | TopExp_Explorer aExpV(aE, TopAbs_VERTEX); |
4537 | for (; aExpV.More(); aExpV.Next()) { |
4538 | const TopoDS_Shape& aV = aExpV.Current(); |
4539 | // save connection to face |
4540 | TopTools_ListOfShape *pLFV = theDMSF.ChangeSeek(aV); |
4541 | if (!pLFV) { |
4542 | pLFV = theDMSF.Bound(aV, TopTools_ListOfShape()); |
4543 | } |
4544 | AppendToList(*pLFV, aF); |
4545 | // |
4546 | if (bLookVertToAvoid) { |
4547 | // save connection to edges |
4548 | TopTools_ListOfShape *pLEV = theDMVEFull.ChangeSeek(aV); |
4549 | if (!pLEV) { |
4550 | pLEV = theDMVEFull.Bound(aV, TopTools_ListOfShape()); |
4551 | } |
4552 | AppendToList(*pLEV, aE); |
4553 | } |
4554 | } |
4555 | } |
4556 | } |
4557 | // |
4558 | if (bLookVertToAvoid) { |
4559 | // get edges of invalid faces (from invalid splits only) |
4560 | const TopTools_ListOfShape *pLFInv = theInvFaces.Seek(aF); |
4561 | if (!pLFInv || theArtInvFaces.IsBound(aF)) { |
4562 | continue; |
4563 | } |
4564 | // |
4565 | aItLF.Initialize(*pLFInv); |
4566 | for (; aItLF.More(); aItLF.Next()) { |
4567 | const TopoDS_Shape& aFInv = aItLF.Value(); |
4568 | TopExp_Explorer aExp(aFInv, TopAbs_EDGE); |
4569 | for (; aExp.More(); aExp.Next()) { |
4570 | const TopoDS_Shape& aE = aExp.Current(); |
4571 | TopTools_ListOfShape *pLF = theDMEFInv.ChangeSeek(aE); |
4572 | if (!pLF) { |
4573 | pLF = &theDMEFInv(theDMEFInv.Add(aE, TopTools_ListOfShape())); |
4574 | } |
4575 | AppendToList(*pLF, aF); |
4576 | } |
4577 | } |
4578 | } |
4579 | } |
4580 | } |
4581 | |
4582 | //======================================================================= |
4583 | //function : FindVerticesToAvoid |
4584 | //purpose : Looking for the invalid vertices |
4585 | //======================================================================= |
4586 | void FindVerticesToAvoid(const TopTools_IndexedDataMapOfShapeListOfShape& theDMEFInv, |
4587 | const TopTools_IndexedMapOfShape& theInvEdges, |
4588 | const TopTools_IndexedMapOfShape& theValidEdges, |
bc4a3867 |
4589 | const TopTools_MapOfShape& theInvertedEdges, |
4590 | const TopTools_DataMapOfShapeListOfShape& theDMVEFull, |
4591 | const TopTools_DataMapOfShapeListOfShape& theOEImages, |
4592 | const TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
ecf4f17c |
4593 | TopTools_MapOfShape& theMVRInv) |
4594 | { |
4595 | TopTools_MapOfShape aMFence; |
4596 | Standard_Integer i, aNb = theDMEFInv.Extent(); |
4597 | for (i = 1; i <= aNb; ++i) { |
4598 | const TopTools_ListOfShape& aLFInv = theDMEFInv(i); |
4599 | if (aLFInv.Extent() == 1) { |
4600 | continue; |
4601 | } |
4602 | // |
4603 | const TopoDS_Shape& aE = theDMEFInv.FindKey(i); |
4604 | if (!theInvEdges.Contains(aE) || theValidEdges.Contains(aE)) { |
4605 | continue; |
4606 | } |
bc4a3867 |
4607 | |
4608 | if (!aMFence.Add(aE)) |
4609 | continue; |
4610 | |
4611 | TopTools_IndexedDataMapOfShapeListOfShape aMVEEdges; |
4612 | // Do not check the splitting vertices, but check only the ending ones |
4613 | const TopTools_ListOfShape *pLEOr = theOEOrigins.Seek(aE); |
4614 | if (pLEOr) |
4615 | { |
4616 | TopTools_ListIteratorOfListOfShape aItLEOr(*pLEOr); |
4617 | for (; aItLEOr.More(); aItLEOr.Next()) |
4618 | { |
4619 | const TopTools_ListOfShape& aLEIm = theOEImages.Find(aItLEOr.Value()); |
4620 | TopTools_ListIteratorOfListOfShape aItLEIm(aLEIm); |
4621 | for (; aItLEIm.More(); aItLEIm.Next()) |
4622 | { |
4623 | aMFence.Add(aItLEIm.Value()); |
4624 | TopExp::MapShapesAndAncestors(aItLEIm.Value(), TopAbs_VERTEX, TopAbs_EDGE, aMVEEdges); |
4625 | } |
4626 | } |
4627 | } |
4628 | else |
4629 | { |
4630 | TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMVEEdges); |
4631 | } |
4632 | |
4633 | Standard_Integer j, aNbV = aMVEEdges.Extent(); |
4634 | for (j = 1; j <= aNbV; ++j) |
4635 | { |
4636 | if (aMVEEdges(j).Extent() != 1) |
4637 | continue; |
4638 | |
4639 | const TopoDS_Shape& aV = aMVEEdges.FindKey(j); |
4640 | if (!aMFence.Add(aV)) |
4641 | continue; |
4642 | const TopTools_ListOfShape *pLE = theDMVEFull.Seek(aV); |
ecf4f17c |
4643 | if (!pLE) { |
bc4a3867 |
4644 | // isolated vertex |
ecf4f17c |
4645 | theMVRInv.Add(aV); |
4646 | continue; |
4647 | } |
4648 | // |
bc4a3867 |
4649 | // If all edges sharing the vertex are either invalid or |
4650 | // the vertex is connected to at least two inverted edges |
4651 | // mark the vertex to be avoided in the new splits |
4652 | Standard_Integer iNbEInverted = 0; |
4653 | Standard_Boolean bAllEdgesInv = Standard_True; |
ecf4f17c |
4654 | TopTools_ListIteratorOfListOfShape aItLE(*pLE); |
4655 | for (; aItLE.More(); aItLE.Next()) { |
4656 | const TopoDS_Shape& aEV = aItLE.Value(); |
bc4a3867 |
4657 | |
4658 | if (theInvertedEdges.Contains(aEV)) |
4659 | ++iNbEInverted; |
4660 | |
4661 | if (bAllEdgesInv) |
4662 | bAllEdgesInv = theInvEdges.Contains(aEV); |
ecf4f17c |
4663 | } |
bc4a3867 |
4664 | |
4665 | if (iNbEInverted > 1 || bAllEdgesInv) |
4666 | { |
ecf4f17c |
4667 | theMVRInv.Add(aV); |
4668 | } |
4669 | } |
4670 | } |
4671 | } |
4672 | |
4673 | //======================================================================= |
4674 | //function : FindFacesForIntersection |
4675 | //purpose : Looking for the faces around each invalidity for intersection |
4676 | //======================================================================= |
4677 | void FindFacesForIntersection(const TopoDS_Shape& theFInv, |
4678 | const TopTools_IndexedMapOfShape& theME, |
4679 | const TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
4680 | const TopTools_DataMapOfShapeListOfShape& theDMSF, |
4681 | const TopTools_MapOfShape& theMVInvAll, |
4682 | const TopTools_DataMapOfShapeShape& theArtInvFaces, |
4683 | const Standard_Boolean theArtCase, |
4684 | const TopTools_DataMapOfShapeListOfShape& theSSInterfs, |
4685 | TopTools_IndexedMapOfShape& theMFAvoid, |
4686 | TopTools_IndexedMapOfShape& theMFInt, |
4687 | TopTools_IndexedMapOfShape& theMFIntExt, |
4688 | TopTools_ListOfShape& theLFImInt) |
4689 | { |
4690 | Standard_Integer i, aNbE = theME.Extent(); |
4691 | // |
4692 | TopTools_IndexedMapOfShape aMShapes; |
4693 | // |
4694 | for (i = 1; i <= aNbE; ++i) { |
4695 | const TopoDS_Shape& aS = theME(i); |
4696 | if (!theDMSF.IsBound(aS)) { |
4697 | continue; |
4698 | } |
4699 | // |
4700 | // in artificial case we intersect the faces which are close to invalidity |
4701 | Standard_Boolean bAvoid = theArtCase ? |
4702 | ((aS.ShapeType() == TopAbs_VERTEX) && !theMVInvAll.Contains(aS)) : Standard_False; |
4703 | // |
4704 | const TopTools_ListOfShape& aLF = theDMSF.Find(aS); |
4705 | TopTools_ListIteratorOfListOfShape aItLF(aLF); |
4706 | for (; aItLF.More(); aItLF.Next()) { |
4707 | const TopoDS_Shape& aF = aItLF.Value(); |
4708 | if (theMFInt.Contains(aF)) { |
4709 | continue; |
4710 | } |
4711 | // |
4712 | if (bAvoid && theArtInvFaces.IsBound(aF)) { |
4713 | theMFAvoid.Add(aF); |
4714 | } |
4715 | // |
4716 | theMFInt.Add(aF); |
4717 | // |
4718 | Standard_Boolean bUse = !aF.IsSame(theFInv); |
4719 | // |
4720 | const TopTools_ListOfShape& aLFIm = theFImages.FindFromKey(aF); |
4721 | TopTools_ListIteratorOfListOfShape aItLFIm(aLFIm); |
4722 | for (; aItLFIm.More(); aItLFIm.Next()) { |
4723 | const TopoDS_Shape& aFIm = aItLFIm.Value(); |
4724 | theLFImInt.Append(aFIm); |
4725 | if (bUse) { |
4726 | TopExp::MapShapes(aFIm, TopAbs_EDGE, aMShapes); |
4727 | } |
4728 | } |
4729 | } |
4730 | } |
4731 | // |
4732 | if (theArtCase) { |
4733 | return; |
4734 | } |
4735 | // |
4736 | const TopTools_ListOfShape* pLFInv = theSSInterfs.Seek(theFInv); |
4737 | if (!pLFInv) { |
4738 | return; |
4739 | } |
4740 | // |
4741 | TopTools_MapOfShape aMF; |
4742 | TopTools_ListIteratorOfListOfShape aItLF(*pLFInv); |
4743 | for (; aItLF.More(); aItLF.Next()) { |
4744 | const TopoDS_Shape& aF = aItLF.Value(); |
4745 | aMF.Add(aF); |
4746 | } |
4747 | // |
4748 | // the faces should be unique in each place |
4749 | TopoDS_Compound aCF; |
4750 | BRep_Builder().MakeCompound(aCF); |
4751 | // |
4752 | TopTools_IndexedMapOfShape aMFToAdd; |
4753 | TopTools_DataMapOfShapeShape aDMFOr; |
4754 | // |
4755 | for (i = 1; i <= aNbE; ++i) { |
4756 | const TopoDS_Shape& aS = theME(i); |
4757 | const TopTools_ListOfShape* pLF = theSSInterfs.Seek(aS); |
4758 | if (!pLF) { |
4759 | continue; |
4760 | } |
4761 | // |
4762 | aItLF.Initialize(*pLF); |
4763 | for (; aItLF.More(); aItLF.Next()) { |
4764 | const TopoDS_Shape& aF = aItLF.Value(); |
4765 | if (theMFInt.Contains(aF) || aMFToAdd.Contains(aF) || !aMF.Contains(aF)) { |
4766 | continue; |
4767 | } |
4768 | // |
4769 | // check if the face has some connection to already added for intersection faces |
4770 | const TopTools_ListOfShape& aLFIm = theFImages.FindFromKey(aF); |
4771 | TopTools_ListIteratorOfListOfShape aItLFIm(aLFIm); |
4772 | for (; aItLFIm.More(); aItLFIm.Next()) { |
4773 | const TopoDS_Shape& aFIm = aItLFIm.Value(); |
4774 | TopExp_Explorer aExp(aFIm, TopAbs_EDGE); |
4775 | for (; aExp.More(); aExp.Next()) { |
4776 | if (aMShapes.Contains(aExp.Current())) { |
4777 | break; |
4778 | } |
4779 | } |
4780 | if (aExp.More()) { |
4781 | break; |
4782 | } |
4783 | } |
4784 | if (!aItLFIm.More()) { |
4785 | continue; |
4786 | } |
4787 | // |
4788 | aMFToAdd.Add(aF); |
4789 | aItLFIm.Initialize(aLFIm); |
4790 | for (; aItLFIm.More(); aItLFIm.Next()) { |
4791 | const TopoDS_Shape& aFIm = aItLFIm.Value(); |
4792 | aDMFOr.Bind(aFIm, aF); |
4793 | BRep_Builder().Add(aCF, aFIm); |
4794 | } |
4795 | } |
4796 | } |
4797 | // |
4798 | if (aMFToAdd.IsEmpty()) { |
4799 | return; |
4800 | } |
4801 | // |
4802 | TopTools_ListOfShape aLCB; |
4803 | BOPTools_AlgoTools::MakeConnexityBlocks(aCF, TopAbs_EDGE, TopAbs_FACE, aLCB); |
4804 | // |
4805 | if ((aLCB.Extent() == 1) && (aMFToAdd.Extent() > 1)) { |
4806 | return; |
4807 | } |
4808 | // |
4809 | TopTools_ListIteratorOfListOfShape aItLCB(aLCB); |
4810 | for (; aItLCB.More(); aItLCB.Next()) { |
4811 | const TopoDS_Shape& aCB = aItLCB.Value(); |
4812 | aMFToAdd.Clear(); |
4813 | TopExp_Explorer aExpF(aCB, TopAbs_FACE); |
4814 | for (; aExpF.More(); aExpF.Next()) { |
4815 | const TopoDS_Shape& aFIm = aExpF.Current(); |
4816 | aMFToAdd.Add(aDMFOr.Find(aFIm)); |
4817 | } |
4818 | // |
4819 | if (aMFToAdd.Extent() == 1) { |
4820 | const TopoDS_Shape& aF = aMFToAdd(1); |
4821 | // |
4822 | theMFInt.Add(aF); |
4823 | theMFIntExt.Add(aF); |
4824 | // |
4825 | const TopTools_ListOfShape& aLFIm = theFImages.FindFromKey(aF); |
4826 | TopTools_ListIteratorOfListOfShape aItLFIm(aLFIm); |
4827 | for (; aItLFIm.More(); aItLFIm.Next()) { |
4828 | const TopoDS_Shape& aFIm = aItLFIm.Value(); |
4829 | theLFImInt.Append(aFIm); |
4830 | } |
4831 | } |
4832 | } |
4833 | } |
4834 | |
4835 | //======================================================================= |
4836 | //function : ProcessCommonEdges |
4837 | //purpose : Analyzing the common edges between splits of offset faces |
4838 | //======================================================================= |
4839 | void ProcessCommonEdges(const TopTools_ListOfShape& theLEC, |
4840 | const TopTools_IndexedMapOfShape& theInvEdges, |
4841 | const TopTools_IndexedMapOfShape& theValidEdges, |
4842 | const TopTools_IndexedMapOfShape& theME, |
4843 | const TopTools_DataMapOfShapeShape& theETrimEInf, |
4844 | const TopTools_DataMapOfShapeListOfShape& theMEInfETrim, |
4845 | const TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
41aa3c3d |
4846 | const TopTools_MapOfShape& theAllInvs, |
ecf4f17c |
4847 | const Standard_Boolean theForceUse, |
4848 | TopTools_IndexedMapOfShape& theMECV, |
41aa3c3d |
4849 | TopTools_MapOfShape& theMECheckExt, |
ecf4f17c |
4850 | TopTools_DataMapOfShapeListOfShape& theDMEETrim, |
4851 | TopTools_ListOfShape& theLFEi, |
4852 | TopTools_ListOfShape& theLFEj, |
4853 | TopTools_IndexedMapOfShape& theMEToInt) |
4854 | { |
4855 | TopTools_ListOfShape aLEC; |
4856 | // process common edges |
4857 | TopTools_ListIteratorOfListOfShape aItLE(theLEC); |
4858 | for (; aItLE.More(); aItLE.Next()) { |
4859 | const TopoDS_Shape& aEC = aItLE.Value(); |
4860 | // |
4861 | // check first if common edges are valid |
4862 | if (theInvEdges.Contains(aEC) && !theValidEdges.Contains(aEC)) { |
4863 | continue; |
4864 | } |
4865 | // |
4866 | // common edge should have connection to current invalidity |
4867 | if (theME.Contains(aEC)) { |
4868 | aLEC.Append(aEC); |
4869 | continue; |
4870 | } |
4871 | // |
4872 | TopoDS_Iterator aItV(aEC); |
4873 | for (; aItV.More(); aItV.Next()) { |
4874 | const TopoDS_Shape& aVE = aItV.Value(); |
4875 | if (theME.Contains(aVE)) { |
4876 | aLEC.Append(aEC); |
4877 | break; |
4878 | } |
4879 | } |
4880 | } |
4881 | // |
41aa3c3d |
4882 | Standard_Boolean bUseOnlyInf = aLEC.IsEmpty(); |
ecf4f17c |
4883 | if (bUseOnlyInf) { |
41aa3c3d |
4884 | if (theForceUse) { |
4885 | aLEC = theLEC; |
4886 | } |
4887 | else { |
4888 | aItLE.Initialize(theLEC); |
4889 | for (; aItLE.More(); aItLE.Next()) { |
4890 | const TopoDS_Shape& aEC = aItLE.Value(); |
b443d536 |
4891 | // check if all images of the origin of this edge |
4892 | // are not connected to any invalidity |
4893 | const TopoDS_Shape& aEInt = theETrimEInf.Find(aEC); |
4894 | const TopTools_ListOfShape& aLVE = theMEInfETrim.Find(aEInt); |
4895 | TopTools_ListIteratorOfListOfShape aItLVE(aLVE); |
4896 | for (; aItLVE.More(); aItLVE.Next()) { |
4897 | const TopoDS_Shape& aECx = aItLVE.Value(); |
4898 | if (theAllInvs.Contains(aECx) || theInvEdges.Contains(aECx)) { |
41aa3c3d |
4899 | return; |
4900 | } |
b443d536 |
4901 | // |
4902 | TopoDS_Iterator aItV(aECx); |
4903 | for (; aItV.More(); aItV.Next()) { |
4904 | if (theAllInvs.Contains(aItV.Value())) { |
4905 | return; |
4906 | } |
4907 | } |
41aa3c3d |
4908 | } |
41aa3c3d |
4909 | // use only one element |
4910 | if (aLEC.IsEmpty()) { |
4911 | aLEC.Append(aEC); |
4912 | } |
4913 | } |
4914 | } |
ecf4f17c |
4915 | } |
4916 | // |
4917 | aItLE.Initialize(aLEC); |
4918 | for (; aItLE.More(); aItLE.Next()) { |
4919 | const TopoDS_Shape& aEC = aItLE.Value(); |
4920 | // |
4921 | const TopoDS_Shape& aEInt = theETrimEInf.Find(aEC); |
4922 | if (!bUseOnlyInf) { |
4923 | // find the edges of the same original edge |
4924 | // and take their vertices as well |
4925 | const TopTools_ListOfShape& aLVE = theMEInfETrim.Find(aEInt); |
4926 | TopTools_ListIteratorOfListOfShape aItLVE(aLVE); |
4927 | for (; aItLVE.More(); aItLVE.Next()) { |
4928 | const TopoDS_Shape& aECx = aItLVE.Value(); |
4929 | // |
4930 | const TopTools_ListOfShape* pLEOr = theOEOrigins.Seek(aECx); |
4931 | if (!pLEOr || (pLEOr->Extent() == 1)) { |
4932 | TopExp::MapShapes(aECx, TopAbs_VERTEX, theMECV); |
4933 | } |
4934 | } |
4935 | // |
4936 | // bind unlimited edge to its trimmed part in face to update maps of |
4937 | // images and origins in the future |
4938 | TopTools_ListOfShape* pLTAdded = theDMEETrim.ChangeSeek(aEInt); |
4939 | if (!pLTAdded) { |
4940 | pLTAdded = theDMEETrim.Bound(aEInt, TopTools_ListOfShape()); |
4941 | } |
4942 | AppendToList(*pLTAdded, aEC); |
4943 | } |
41aa3c3d |
4944 | else if (!theForceUse) { |
4945 | theMECheckExt.Add(aEInt); |
4946 | } |
ecf4f17c |
4947 | // |
4948 | AppendToList(theLFEi, aEInt); |
4949 | AppendToList(theLFEj, aEInt); |
4950 | theMEToInt.Add(aEInt); |
4951 | } |
4952 | } |
4953 | |
4954 | //======================================================================= |
4955 | //function : UpdateIntersectedFaces |
4956 | //purpose : Updating the already interfered faces |
4957 | //======================================================================= |
4958 | void UpdateIntersectedFaces(const TopoDS_Shape& theFInv, |
4959 | const TopoDS_Shape& theFi, |
4960 | const TopoDS_Shape& theFj, |
4961 | const TopTools_ListOfShape& theLFInv, |
4962 | const TopTools_ListOfShape& theLFImi, |
4963 | const TopTools_ListOfShape& theLFImj, |
4964 | const TopTools_ListOfShape& theLFEi, |
4965 | const TopTools_ListOfShape& theLFEj, |
4966 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
4967 | TopTools_IndexedMapOfShape& theMEToInt) |
4968 | { |
4969 | // Find common edges in these two lists |
4970 | TopTools_MapOfShape aMEi; |
4971 | TopTools_ListIteratorOfListOfShape aItLE(theLFEi); |
4972 | for (; aItLE.More(); aItLE.Next()) { |
4973 | const TopoDS_Shape& aE = aItLE.Value(); |
4974 | aMEi.Add(aE); |
4975 | } |
4976 | // |
4977 | // find origins |
4978 | TopTools_IndexedMapOfShape aMEToFindOrigins; |
4979 | TopTools_ListOfShape aLEToFindOrigins; |
4980 | if (!theFi.IsSame(theFInv)) { |
4981 | FindCommonParts(theLFImi, theLFInv, aLEToFindOrigins); |
4982 | } |
4983 | if (!theFj.IsSame(theFInv)) { |
4984 | FindCommonParts(theLFImj, theLFInv, aLEToFindOrigins); |
4985 | } |
4986 | // |
4987 | TopTools_ListOfShape aLEOrInit; |
4988 | aItLE.Initialize(aLEToFindOrigins); |
4989 | for (; aItLE.More(); aItLE.Next()) { |
4990 | const TopoDS_Shape& aEC = aItLE.Value(); |
4991 | aMEToFindOrigins.Add(aEC); |
4992 | } |
4993 | // |
4994 | FindOrigins(theLFImi, theLFImj, aMEToFindOrigins, theEdgesOrigins, aLEOrInit); |
4995 | // |
4996 | aItLE.Initialize(theLFEj); |
4997 | for (; aItLE.More(); aItLE.Next()) { |
4998 | const TopoDS_Shape& aE = aItLE.Value(); |
4999 | if (aMEi.Contains(aE)) { |
5000 | theMEToInt.Add(aE); |
5001 | if (aLEOrInit.Extent()) { |
5002 | if (theEdgesOrigins.IsBound(aE)) { |
5003 | TopTools_ListOfShape& aLEOr = theEdgesOrigins.ChangeFind(aE); |
5004 | TopTools_ListIteratorOfListOfShape aItLEOr(aLEOrInit); |
5005 | for (; aItLEOr.More(); aItLEOr.Next()) { |
5006 | const TopoDS_Shape& aEOr = aItLEOr.Value(); |
5007 | AppendToList(aLEOr, aEOr); |
5008 | } |
5009 | } |
5010 | else { |
5011 | theEdgesOrigins.Bind(aE, aLEOrInit); |
5012 | } |
5013 | } |
5014 | } |
5015 | } |
5016 | } |
5017 | |
5018 | //======================================================================= |
5019 | //function : IntersectFaces |
5020 | //purpose : Intersection of the pair of faces |
5021 | //======================================================================= |
5022 | void IntersectFaces(const TopoDS_Shape& theFInv, |
5023 | const TopoDS_Shape& theFi, |
5024 | const TopoDS_Shape& theFj, |
5025 | const TopTools_ListOfShape& theLFInv, |
5026 | const TopTools_ListOfShape& theLFImi, |
5027 | const TopTools_ListOfShape& theLFImj, |
5028 | TopTools_ListOfShape& theLFEi, |
5029 | TopTools_ListOfShape& theLFEj, |
5030 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
5031 | TopTools_IndexedMapOfShape& theMECV, |
5032 | TopTools_IndexedMapOfShape& theMEToInt) |
5033 | { |
5034 | // intersect faces |
5035 | TopAbs_State aSide = TopAbs_OUT; |
5036 | TopTools_ListOfShape aLInt1, aLInt2; |
5037 | TopoDS_Edge aNullEdge; |
5038 | BRepOffset_Tool::Inter3D(TopoDS::Face(theFi), TopoDS::Face(theFj), aLInt1, aLInt2, aSide, aNullEdge); |
5039 | // |
5040 | if (aLInt1.IsEmpty()) { |
5041 | return; |
5042 | } |
5043 | // |
5044 | // find common vertices for trimming edges |
5045 | TopTools_ListOfShape aLCV; |
5046 | TopTools_ListIteratorOfListOfShape aItLE; |
5047 | FindCommonParts(theLFImi, theLFImj, aLCV, TopAbs_VERTEX); |
5048 | if (aLCV.Extent() > 1) { |
5049 | aItLE.Initialize(aLCV); |
5050 | for (; aItLE.More(); aItLE.Next()) { |
5051 | const TopoDS_Shape& aCV = aItLE.Value(); |
5052 | theMECV.Add(aCV); |
5053 | } |
5054 | } |
5055 | // |
5056 | // find origins |
5057 | TopTools_IndexedMapOfShape aMEToFindOrigins; |
5058 | TopTools_ListOfShape aLEToFindOrigins; |
5059 | if (!theFi.IsSame(theFInv)) { |
5060 | FindCommonParts(theLFImi, theLFInv, aLEToFindOrigins); |
5061 | } |
5062 | if (!theFj.IsSame(theFInv)) { |
5063 | FindCommonParts(theLFImj, theLFInv, aLEToFindOrigins); |
5064 | } |
5065 | TopTools_ListOfShape aLEOrInit; |
5066 | aItLE.Initialize(aLEToFindOrigins); |
5067 | for (; aItLE.More(); aItLE.Next()) { |
5068 | const TopoDS_Shape& aEC = aItLE.Value(); |
5069 | aMEToFindOrigins.Add(aEC); |
5070 | } |
5071 | // |
5072 | FindOrigins(theLFImi, theLFImj, aMEToFindOrigins, theEdgesOrigins, aLEOrInit); |
5073 | // |
5074 | aItLE.Initialize(aLInt1); |
5075 | for (; aItLE.More(); aItLE.Next()) { |
5076 | const TopoDS_Shape& aEInt = aItLE.Value(); |
5077 | theLFEi.Append(aEInt); |
5078 | theLFEj.Append(aEInt); |
5079 | // |
5080 | if (aLEOrInit.Extent()) { |
5081 | theEdgesOrigins.Bind(aEInt, aLEOrInit); |
5082 | } |
5083 | // |
5084 | theMEToInt.Add(aEInt); |
5085 | } |
5086 | } |
5087 | |
5088 | //======================================================================= |
5089 | //function : FindOrigins |
5090 | //purpose : Looking for the origin edges |
5091 | //======================================================================= |
5092 | void FindOrigins(const TopTools_ListOfShape& theLFIm1, |
5093 | const TopTools_ListOfShape& theLFIm2, |
5094 | const TopTools_IndexedMapOfShape& theME, |
5095 | const TopTools_DataMapOfShapeListOfShape& theOrigins, |
5096 | TopTools_ListOfShape& theLEOr) |
5097 | { |
5098 | Standard_Integer i; |
5099 | TopTools_MapOfShape aMFence; |
5100 | TopExp_Explorer aExp; |
5101 | TopTools_ListIteratorOfListOfShape aIt, aItLE; |
5102 | // |
5103 | for (i = 0; i < 2; ++i) { |
5104 | const TopTools_ListOfShape& aLF = !i ? theLFIm1 : theLFIm2; |
5105 | aIt.Initialize(aLF); |
5106 | for (; aIt.More(); aIt.Next()) { |
5107 | const TopoDS_Shape& aF = aIt.Value(); |
5108 | // |
5109 | aExp.Init(aF, TopAbs_EDGE); |
5110 | for (; aExp.More(); aExp.Next()) { |
5111 | const TopoDS_Shape& aE = aExp.Current(); |
5112 | // |
5113 | if (theME.Contains(aE) && theOrigins.IsBound(aE)) { |
5114 | const TopTools_ListOfShape& aLEOr = theOrigins.Find(aE); |
5115 | aItLE.Initialize(aLEOr); |
5116 | for (; aItLE.More(); aItLE.Next()) { |
5117 | const TopoDS_Shape& aEOr = aItLE.Value(); |
5118 | // |
5119 | if (aMFence.Add(aEOr) && (aEOr.ShapeType() == TopAbs_EDGE)) { |
5120 | theLEOr.Append(aEOr); |
5121 | } |
5122 | } // for (; aItLE.More(); aItLE.Next()) { |
5123 | } // if (theME.Contains(aE) && theOrigins.IsBound(aE)) { |
5124 | } // aExp.Init(aF, TopAbs_EDGE); |
5125 | } // for (; aIt.More(); aIt.Next()) { |
5126 | } // for (i = 0; i < 2; ++i) { |
5127 | } |
5128 | |
5129 | //======================================================================= |
5130 | //function : IntersectAndTrimEdges |
5131 | //purpose : Intersection of the new intersection edges among themselves |
5132 | //======================================================================= |
5133 | void IntersectAndTrimEdges(const TopTools_IndexedDataMapOfShapeListOfShape& theFToRebuild, |
5134 | const TopTools_IndexedMapOfShape& theMFInt, |
5135 | const TopTools_IndexedMapOfShape& theMEInt, |
5136 | const TopTools_DataMapOfShapeListOfShape& theDMEETrim, |
5137 | const TopTools_IndexedMapOfShape& theMSInv, |
5138 | const TopTools_IndexedMapOfShape& theMVE, |
5139 | const TopTools_MapOfShape& theVertsToAvoid, |
5140 | const TopTools_MapOfShape& theNewVertsToAvoid, |
41aa3c3d |
5141 | const TopTools_MapOfShape& theMECheckExt, |
ecf4f17c |
5142 | TopTools_MapOfShape& theMVBounds, |
5143 | TopTools_DataMapOfShapeListOfShape& theEImages) |
5144 | { |
5145 | Standard_Integer i, aNb = theMEInt.Extent(); |
5146 | if (!aNb) { |
5147 | return; |
5148 | } |
5149 | // |
1155d05a |
5150 | TopTools_ListOfShape aLArgs; |
ecf4f17c |
5151 | TopTools_MapOfShape aMFence; |
5152 | TopTools_ListIteratorOfListOfShape aIt, aIt1; |
5153 | TopExp_Explorer aExp; |
5154 | // |
5155 | // get vertices from the splits of intersected faces. |
5156 | // vertices are taken from the edges close to invalidity |
5157 | // |
5158 | TopTools_IndexedDataMapOfShapeListOfShape aDMVE; |
5159 | aNb = theMFInt.Extent(); |
5160 | for (i = 1; i <= aNb; ++i) { |
5161 | const TopoDS_Shape& aF = theMFInt(i); |
5162 | const TopTools_ListOfShape& aLE = theFToRebuild.FindFromKey(aF); |
5163 | // |
5164 | aIt.Initialize(aLE); |
5165 | for (; aIt.More(); aIt.Next()) { |
5166 | const TopoDS_Shape& aE = aIt.Value(); |
5167 | TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aDMVE); |
5168 | // |
5169 | aExp.Init(aE, TopAbs_VERTEX); |
5170 | for (; aExp.More(); aExp.Next()) { |
5171 | const TopoDS_Shape& aV1 = aExp.Current(); |
5172 | if (!theVertsToAvoid.Contains(aV1) && theMVE.Contains(aV1) && aMFence.Add(aV1)) { |
5173 | aLArgs.Append(aV1); |
5174 | } |
5175 | } |
5176 | } |
5177 | } |
5178 | // |
5179 | aNb = theMSInv.Extent(); |
5180 | for (i = 1; i <= aNb; ++i) { |
5181 | const TopoDS_Shape& aV = theMSInv(i); |
5182 | if (aV.ShapeType() != TopAbs_VERTEX) { |
5183 | continue; |
5184 | } |
5185 | // |
5186 | TopTools_ListOfShape *pLVE = aDMVE.ChangeSeek(aV); |
5187 | if (!pLVE) { |
5188 | continue; |
5189 | } |
5190 | // |
5191 | aIt.Initialize(*pLVE); |
5192 | for (; aIt.More(); aIt.Next()) { |
5193 | const TopoDS_Shape& aE = aIt.Value(); |
5194 | // |
5195 | aExp.Init(aE, TopAbs_VERTEX); |
5196 | for (; aExp.More(); aExp.Next()) { |
5197 | const TopoDS_Shape& aV1 = aExp.Current(); |
5198 | if (!theVertsToAvoid.Contains(aV1) && aMFence.Add(aV1)) { |
5199 | aLArgs.Append(aV1); |
5200 | } |
5201 | } |
5202 | } |
5203 | } |
5204 | // |
5205 | // bounding vertices of untrimmed edges |
5206 | TopTools_ListOfShape aLVBounds; |
5207 | // new intersection edges |
5208 | TopTools_ListOfShape aLENew; |
5209 | // get edges to intersect |
5210 | TopTools_ListOfShape aLEInt; |
dcba2e5c |
5211 | // Common intersection edges. Should be intersected separately |
41aa3c3d |
5212 | TopTools_ListOfShape aLCE; |
5213 | // |
ecf4f17c |
5214 | aNb = theMEInt.Extent(); |
5215 | for (i = 1; i <= aNb; ++i) { |
5216 | const TopoDS_Shape& aE = theMEInt(i); |
41aa3c3d |
5217 | if (theMECheckExt.Contains(aE)) { |
5218 | // avoid trimming of the intersection edges by additional common edges |
5219 | aLCE.Append(aE); |
ecf4f17c |
5220 | continue; |
5221 | } |
5222 | // |
5223 | if (!theDMEETrim.IsBound(aE)) { |
5224 | aLENew.Append(aE); |
5225 | } |
5226 | // |
5227 | aLEInt.Append(aE); |
5228 | aLArgs.Append(aE); |
5229 | // |
5230 | aExp.Init(aE, TopAbs_VERTEX); |
5231 | for (; aExp.More(); aExp.Next()) { |
5232 | const TopoDS_Shape& aV = aExp.Current(); |
5233 | aLVBounds.Append(aV); |
5234 | } |
5235 | } |
5236 | // |
5237 | // Intersect Edges |
5238 | BOPAlgo_Builder aGF; |
5239 | aGF.SetArguments(aLArgs); |
5240 | aGF.Perform(); |
33ba8565 |
5241 | if (aGF.HasErrors()) { |
ecf4f17c |
5242 | return; |
5243 | } |
5244 | // |
5245 | // update vertices to avoid with SD vertices |
5246 | aIt.Initialize(aLVBounds); |
5247 | for (; aIt.More(); aIt.Next()) { |
5248 | const TopoDS_Shape& aV = aIt.Value(); |
5249 | const TopTools_ListOfShape& aLVIm = aGF.Modified(aV); |
5250 | if (aLVIm.IsEmpty()) { |
5251 | theMVBounds.Add(aV); |
5252 | } |
5253 | else { |
5254 | const TopoDS_Shape& aVIm = aLVIm.First(); |
5255 | theMVBounds.Add(aVIm); |
5256 | } |
5257 | } |
5258 | // |
5259 | // find invalid splits of edges |
5260 | TopTools_MapOfShape aMEInv; |
5261 | GetInvalidEdges(theNewVertsToAvoid, theMVBounds, aGF, aMEInv); |
5262 | // |
41aa3c3d |
5263 | BRep_Builder aBB; |
5264 | // get valid splits to intersect with the commons |
5265 | TopoDS_Compound aCEIm; |
5266 | aBB.MakeCompound(aCEIm); |
5267 | // |
ecf4f17c |
5268 | // remove the splits containing vertices from invalid edges |
5269 | aIt.Initialize(aLEInt); |
5270 | for (; aIt.More(); aIt.Next()) { |
5271 | const TopoDS_Shape& aE = aIt.Value(); |
5272 | // |
5273 | TopTools_ListOfShape aLEIm = aGF.Modified(aE); |
5274 | if (aLEIm.IsEmpty()) { |
5275 | continue; |
5276 | } |
5277 | // |
5278 | aIt1.Initialize(aLEIm); |
5279 | for (; aIt1.More(); ) { |
5280 | const TopoDS_Shape& aEIm = aIt1.Value(); |
5281 | // |
5282 | if (aMEInv.Contains(aEIm)) { |
5283 | aLEIm.Remove(aIt1); |
5284 | } |
5285 | else { |
41aa3c3d |
5286 | aBB.Add(aCEIm, aEIm); |
ecf4f17c |
5287 | aIt1.Next(); |
5288 | } |
5289 | } |
5290 | // |
5291 | if (aLEIm.Extent()) { |
41aa3c3d |
5292 | TopTools_ListOfShape* pLEIm = theEImages.ChangeSeek(aE); |
5293 | if (!pLEIm) { |
5294 | pLEIm = theEImages.Bound(aE, TopTools_ListOfShape()); |
ecf4f17c |
5295 | } |
41aa3c3d |
5296 | pLEIm->Append(aLEIm); |
5297 | } |
5298 | } |
5299 | // |
5300 | if (!aLCE.Extent()) { |
5301 | return; |
5302 | } |
5303 | // |
5304 | // trim common edges by other intersection edges |
5305 | BOPAlgo_Builder aGFCE; |
5306 | aGFCE.SetArguments(aLCE); |
5307 | aGFCE.AddArgument(aCEIm); |
5308 | aGFCE.Perform(); |
5309 | // |
33ba8565 |
5310 | if (aGFCE.HasErrors()) { |
41aa3c3d |
5311 | return; |
5312 | } |
5313 | // |
5314 | const BOPDS_PDS& pDS = aGFCE.PDS(); |
5315 | TopTools_ListIteratorOfListOfShape aItLCE(aLCE); |
5316 | for (; aItLCE.More(); aItLCE.Next()) { |
5317 | const TopoDS_Shape& aE = aItLCE.Value(); |
5318 | TopTools_ListOfShape aLEIm = aGFCE.Modified(aE); |
5319 | if (aLEIm.IsEmpty()) { |
5320 | continue; |
5321 | } |
5322 | // |
5323 | // check if it's not coincide with some intersection edge |
5324 | BOPDS_ListIteratorOfListOfPaveBlock aItLPB(pDS->PaveBlocks(pDS->Index(aE))); |
5325 | for (; aItLPB.More(); aItLPB.Next()) { |
5326 | if (pDS->IsCommonBlock(aItLPB.Value())) { |
5327 | // find with what it is a common |
5328 | const BOPDS_ListOfPaveBlock& aLPBC = pDS->CommonBlock(aItLPB.Value())->PaveBlocks(); |
5329 | BOPDS_ListIteratorOfListOfPaveBlock aItLPBC(aLPBC); |
5330 | for (; aItLPBC.More(); aItLPBC.Next()) { |
5331 | const TopoDS_Shape& aEC = pDS->Shape(aItLPBC.Value()->OriginalEdge()); |
5332 | if (!theMECheckExt.Contains(aEC)) { |
5333 | break; |
5334 | } |
5335 | } |
5336 | if (aItLPBC.More()) { |
5337 | break; |
5338 | } |
ecf4f17c |
5339 | } |
5340 | } |
41aa3c3d |
5341 | if (aItLPB.More()) { |
5342 | // avoid creation of unnecessary splits from commons which |
5343 | // coincide with intersection edges |
5344 | continue; |
5345 | } |
5346 | // |
5347 | // save the images |
5348 | TopTools_ListOfShape* pLEIm = theEImages.ChangeSeek(aE); |
5349 | if (!pLEIm) { |
5350 | pLEIm = theEImages.Bound(aE, TopTools_ListOfShape()); |
5351 | } |
5352 | pLEIm->Append(aLEIm); |
5353 | // |
5354 | // save bounding vertices |
5355 | for (TopoDS_Iterator aItV(aE); aItV.More(); aItV.Next()) { |
5356 | const TopoDS_Shape& aV = aItV.Value(); |
5357 | const TopTools_ListOfShape& aLVIm = aGFCE.Modified(aV); |
5358 | theMVBounds.Add(aLVIm.IsEmpty() ? aV : aLVIm.First()); |
5359 | } |
ecf4f17c |
5360 | } |
5361 | } |
5362 | |
5363 | //======================================================================= |
5364 | //function : GetInvalidEdges |
5365 | //purpose : Looking for the invalid edges by intersecting with invalid vertices |
5366 | //======================================================================= |
5367 | void GetInvalidEdges(const TopTools_MapOfShape& theVertsToAvoid, |
5368 | const TopTools_MapOfShape& theMVBounds, |
5369 | BOPAlgo_Builder& theGF, |
5370 | TopTools_MapOfShape& theMEInv) |
5371 | { |
5372 | if (theVertsToAvoid.IsEmpty()) { |
5373 | return; |
5374 | } |
5375 | // |
5376 | TopTools_ListIteratorOfListOfShape aIt, aIt1; |
5377 | // get vertices created with intersection edges |
5378 | const TopoDS_Shape& aRes = theGF.Shape(); |
5379 | TopTools_IndexedDataMapOfShapeListOfShape aDMVE; |
5380 | TopExp::MapShapesAndAncestors(aRes, TopAbs_VERTEX, TopAbs_EDGE, aDMVE); |
5381 | // |
5382 | const BOPDS_PDS& pDS = theGF.PDS(); |
5383 | // |
5384 | // find invalid splits of edges |
5385 | // check if the vertex is invalid: |
5386 | // a. it may be the vertex SD with the vertices to avoid |
5387 | // b. or it may be the vertex which is created by the intersection |
5388 | // of only existing edges, i.e. no new intersection edges goes |
5389 | // through this vertex |
5390 | // |
5391 | TopTools_MapOfShape aMVInv; |
5392 | Standard_Integer i, aNb = aDMVE.Extent(); |
5393 | for (i = 1; i <= aNb; ++i) { |
5394 | const TopoDS_Vertex& aV = TopoDS::Vertex(aDMVE.FindKey(i)); |
5395 | if (theMVBounds.Contains(aV)) { |
5396 | continue; |
5397 | } |
5398 | // |
5399 | Standard_Integer nV = pDS->Index(aV); |
5400 | if ((nV >= 0) && !pDS->IsNewShape(nV)) { |
5401 | continue; |
5402 | } |
5403 | // |
5404 | TopTools_MapIteratorOfMapOfShape aItM(theVertsToAvoid); |
5405 | for (; aItM.More(); aItM.Next()) { |
5406 | const TopoDS_Vertex& aVInv = *(TopoDS_Vertex*)&aItM.Value(); |
5407 | Standard_Integer iFlag = BOPTools_AlgoTools::ComputeVV(aV, aVInv); |
5408 | if (!iFlag) { |
5409 | aMVInv.Add(aV); |
5410 | break; |
5411 | } |
5412 | } |
5413 | // |
5414 | if (aItM.More()) { |
5415 | const TopTools_ListOfShape& aLVE = aDMVE.FindFromKey(aV); |
5416 | aIt.Initialize(aLVE); |
5417 | for (; aIt.More(); aIt.Next()) { |
5418 | const TopoDS_Shape& aE = aIt.Value(); |
5419 | theMEInv.Add(aE); |
5420 | } |
5421 | } |
5422 | } |
5423 | } |
5424 | |
5425 | //======================================================================= |
5426 | //function : UpdateValidEdges |
5427 | //purpose : Making the new splits and updating the maps |
5428 | //======================================================================= |
41aa3c3d |
5429 | void UpdateValidEdges(const TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
ecf4f17c |
5430 | const TopTools_IndexedDataMapOfShapeListOfShape& theFLE, |
dcba2e5c |
5431 | const TopTools_IndexedDataMapOfShapeListOfShape& theOENEdges, |
ecf4f17c |
5432 | const TopTools_MapOfShape& theMVBounds, |
5433 | const TopoDS_Shape& theSolids, |
5434 | const TopTools_IndexedMapOfShape& theInvEdges, |
5435 | const TopTools_MapOfShape& theInvertedEdges, |
a8232603 |
5436 | const TopTools_MapOfShape& theMEInvOnArt, |
41aa3c3d |
5437 | TopTools_MapOfShape& theMECheckExt, |
ecf4f17c |
5438 | TopTools_IndexedMapOfShape& theEdgesToAvoid, |
5439 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
5440 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
5441 | TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
5442 | TopTools_MapOfShape& theVertsToAvoid, |
5443 | TopTools_DataMapOfShapeShape& theETrimEInf, |
5444 | TopTools_DataMapOfShapeListOfShape& theEImages, |
5445 | TopTools_DataMapOfShapeListOfShape& theEETrim, |
5446 | TopTools_MapOfShape& theModifiedEdges, |
5447 | Handle(BRepAlgo_AsDes)& theAsDes) |
5448 | { |
5449 | // update images and origins of edges, plus update AsDes |
5450 | // |
5451 | // new edges |
5452 | TopTools_ListOfShape aLE; |
5453 | // back connection from edges to faces |
5454 | TopTools_DataMapOfShapeListOfShape aMELF; |
5455 | // |
b443d536 |
5456 | TopTools_MapOfShape aMETmp; |
ecf4f17c |
5457 | Standard_Integer i, aNb = theFLE.Extent(); |
5458 | for (i = 1; i <= aNb; ++i) { |
5459 | const TopoDS_Face& aF = TopoDS::Face(theFLE.FindKey(i)); |
5460 | // |
5461 | const TopTools_ListOfShape& aLEInt = theFLE(i); |
5462 | TopTools_ListIteratorOfListOfShape aItLE(aLEInt); |
5463 | for (; aItLE.More(); aItLE.Next()) { |
5464 | const TopoDS_Shape& aE = aItLE.Value(); |
b443d536 |
5465 | if ((theMECheckExt.Contains(aE) || aMETmp.Contains(aE)) && !theEImages.IsBound(aE)) { |
5466 | theMECheckExt.Remove(aE); |
5467 | aMETmp.Add(aE); |
5468 | continue; |
5469 | } |
ecf4f17c |
5470 | TopTools_ListOfShape* pLF = aMELF.ChangeSeek(aE); |
5471 | if (!pLF) { |
5472 | pLF = aMELF.Bound(aE, TopTools_ListOfShape()); |
5473 | aLE.Append(aE); |
5474 | } |
5475 | pLF->Append(aF); |
5476 | } |
5477 | } |
5478 | // |
5479 | if (aLE.IsEmpty()) { |
5480 | return; |
5481 | } |
5482 | // |
5483 | // bounding edges, that are going to be replaced |
5484 | TopTools_MapOfShape aMEB; |
5485 | // |
5486 | // new intersection edges |
ecf4f17c |
5487 | TopTools_MapOfShape aMENew; |
5488 | // map of old vertices |
5489 | TopTools_MapOfShape aMVOld; |
5490 | // back connection to untrimmed edges |
5491 | TopTools_DataMapOfShapeListOfShape aDMEOr; |
5492 | // |
5493 | // trim the new intersection edges |
dcba2e5c |
5494 | TrimNewIntersectionEdges(aLE, theEETrim, theMVBounds, theMECheckExt, |
5495 | theEImages, aMEB, aMVOld, aMENew, aDMEOr, aMELF); |
ecf4f17c |
5496 | // |
dcba2e5c |
5497 | if (theEImages.IsEmpty()) |
5498 | { |
5499 | // No new splits is preserved |
5500 | // update intersection edges and exit |
ecf4f17c |
5501 | UpdateNewIntersectionEdges(aLE, aMELF, theEImages, theInvEdges, theInvertedEdges, theEdgesOrigins, |
5502 | theOEImages, theOEOrigins, theETrimEInf, theEETrim, theModifiedEdges, theAsDes); |
5503 | return; |
5504 | } |
dcba2e5c |
5505 | |
5506 | BRep_Builder aBB; |
5507 | |
5508 | // Make connexity blocks of the invalid edges |
5509 | // and treat each block separately |
5510 | |
5511 | // Compound of all invalid edges to make the blocks |
5512 | TopoDS_Compound aCEAll; |
5513 | aBB.MakeCompound(aCEAll); |
5514 | |
5515 | Standard_Integer aNbE = theOENEdges.Extent(); |
5516 | for (i = 1; i <= aNbE; ++i) |
5517 | aBB.Add(aCEAll, theOENEdges.FindKey(i)); |
5518 | |
5519 | // Separate the edges into blocks |
5520 | TopTools_ListOfShape aLBlocks; |
5521 | BOPTools_AlgoTools::MakeConnexityBlocks(aCEAll, TopAbs_VERTEX, TopAbs_EDGE, aLBlocks); |
5522 | |
5523 | // Perform intersection of the new splits for each block |
5524 | |
5525 | // Intersected splits |
5526 | TopTools_IndexedDataMapOfShapeListOfShape aMBlocksSp; |
5527 | |
5528 | TopTools_ListIteratorOfListOfShape aItLB(aLBlocks); |
5529 | for (; aItLB.More(); aItLB.Next()) |
5530 | { |
5531 | const TopoDS_Shape& aBlock = aItLB.Value(); |
5532 | |
5533 | // Get the list of new edges for the block |
5534 | TopTools_ListOfShape aBlockLENew; |
5535 | { |
5536 | // Fence map |
5537 | TopTools_MapOfShape aMEFence; |
5538 | TopExp_Explorer anExpE(aBlock, TopAbs_EDGE); |
5539 | for (; anExpE.More(); anExpE.Next()) |
5540 | { |
5541 | const TopoDS_Shape& aE = anExpE.Current(); |
5542 | const TopTools_ListOfShape& aLEInt = theOENEdges.FindFromKey(aE); |
5543 | TopTools_ListIteratorOfListOfShape aItLEInt(aLEInt); |
5544 | for (; aItLEInt.More(); aItLEInt.Next()) |
5545 | { |
5546 | if (aMEFence.Add(aItLEInt.Value())) |
5547 | aBlockLENew.Append(aItLEInt.Value()); |
5548 | } |
5549 | } |
5550 | } |
5551 | |
5552 | if (aBlockLENew.IsEmpty()) |
5553 | continue; |
5554 | |
5555 | // Get the splits of new edges to intersect |
1155d05a |
5556 | TopTools_ListOfShape aLSplits; |
dcba2e5c |
5557 | |
5558 | TopTools_ListIteratorOfListOfShape aItLE(aBlockLENew); |
5559 | for (; aItLE.More(); aItLE.Next()) |
5560 | { |
ecf4f17c |
5561 | const TopoDS_Shape& aE = aItLE.Value(); |
ecf4f17c |
5562 | TopTools_ListOfShape* pLEIm = theEImages.ChangeSeek(aE); |
dcba2e5c |
5563 | if (!pLEIm || pLEIm->IsEmpty()) |
ecf4f17c |
5564 | continue; |
dcba2e5c |
5565 | |
ecf4f17c |
5566 | TopTools_ListIteratorOfListOfShape aItLEIm(*pLEIm); |
dcba2e5c |
5567 | for (; aItLEIm.More(); aItLEIm.Next()) |
5568 | aLSplits.Append(aItLEIm.Value()); |
5569 | } |
5570 | |
5571 | if (aLSplits.IsEmpty()) |
5572 | continue; |
5573 | |
5574 | TopoDS_Shape aCE; |
5575 | if (aLSplits.Extent() > 1) |
5576 | // Intersect the new splits among themselves to avoid self-intersections |
5577 | IntersectEdges(aLSplits, aBlockLENew, theMVBounds, theVertsToAvoid, aMENew, theMECheckExt, |
5578 | theEImages, theModifiedEdges, aDMEOr, aMELF, aCE); |
5579 | else |
5580 | aCE = aLSplits.First(); |
5581 | |
5582 | aMBlocksSp.Add(aCE, aBlockLENew); |
5583 | } |
5584 | |
5585 | // Perform filtering of the edges in two steps: |
5586 | // - Check each block separately using localized bounds |
5587 | // taken only from the splits of faces of the current block; |
5588 | // - Intersect all splits together and filter the splits by all bounds. |
5589 | |
5590 | // FIRST STAGE - separate treatment of the blocks |
5591 | |
5592 | // Valid splits to be preserved on the first stage |
5593 | TopTools_MapOfShape aMEVal; |
5594 | |
5595 | // Blocks of valid edges on the first stage |
1155d05a |
5596 | TopTools_ListOfShape aLValBlocks; |
dcba2e5c |
5597 | |
5598 | // Context for caching the classification tools |
5599 | Handle(IntTools_Context) aCtx = new IntTools_Context; |
5600 | |
5601 | Standard_Integer aNbB = aMBlocksSp.Extent(); |
5602 | for (i = 1; i <= aNbB; ++i) |
5603 | { |
5604 | const TopoDS_Shape& aCE = aMBlocksSp.FindKey(i); |
5605 | const TopTools_ListOfShape& aBlockLENew = aMBlocksSp(i); |
5606 | |
5607 | // Get all participating faces to get the bounds |
5608 | TopTools_ListOfShape aLFaces; |
5609 | TopTools_ListIteratorOfListOfShape aItLE(aBlockLENew); |
5610 | for (; aItLE.More(); aItLE.Next()) |
5611 | { |
5612 | const TopTools_ListOfShape *pLF = aMELF.Seek(aItLE.Value()); |
5613 | if (!pLF) |
5614 | continue; |
5615 | TopTools_ListIteratorOfListOfShape aItLF(*pLF); |
5616 | for (; aItLF.More(); aItLF.Next()) |
5617 | AppendToList(aLFaces, aItLF.Value()); |
5618 | } |
5619 | |
5620 | // Localized bounds of the splits of the offset faces |
5621 | // to filter the new splits of the current block |
5622 | TopoDS_Shape aFilterBounds; |
5623 | GetBounds(aLFaces, theFImages, aMEB, aFilterBounds); |
5624 | |
5625 | // Filter the splits by bounds |
5626 | TopTools_MapOfShape aMEInvLoc; |
5627 | GetInvalidEdgesByBounds(aCE, aFilterBounds, theFImages, theSolids, |
5628 | theInvEdges, aMVOld, aMENew, aDMEOr, aMELF, theEImages, |
5629 | theMECheckExt, theMEInvOnArt, aCtx, theVertsToAvoid, aMEInvLoc); |
5630 | |
5631 | // Keep only valid edges of the block |
5632 | TopoDS_Compound aCEVal; |
5633 | aBB.MakeCompound(aCEVal); |
5634 | |
5635 | Standard_Boolean bKept = Standard_False; |
5636 | |
5637 | TopExp_Explorer anExpE(aCE, TopAbs_EDGE); |
5638 | for (; anExpE.More(); anExpE.Next()) |
5639 | { |
5640 | const TopoDS_Shape& aESp = anExpE.Current(); |
5641 | if (!aMEInvLoc.Contains(aESp) && aMEVal.Add(aESp)) |
5642 | { |
5643 | aBB.Add(aCEVal, aESp); |
5644 | bKept = Standard_True; |
ecf4f17c |
5645 | } |
5646 | } |
dcba2e5c |
5647 | |
5648 | if (bKept) |
5649 | aLValBlocks.Append(aCEVal); |
ecf4f17c |
5650 | } |
dcba2e5c |
5651 | |
5652 | // Filter the images of edges after the first filtering stage |
5653 | TopoDS_Shape aSplits1; |
5654 | FilterSplits(aLE, aMEVal, Standard_False, theEImages, aSplits1); |
5655 | |
5656 | if (aLValBlocks.IsEmpty()) |
5657 | { |
5658 | // update intersection edges |
5659 | UpdateNewIntersectionEdges(aLE, aMELF, theEImages, theInvEdges, theInvertedEdges, theEdgesOrigins, |
5660 | theOEImages, theOEOrigins, theETrimEInf, theEETrim, theModifiedEdges, theAsDes); |
5661 | return; |
ecf4f17c |
5662 | } |
dcba2e5c |
5663 | |
5664 | // SECOND STAGE - Filter the remaining splits together |
5665 | |
5666 | // Add for intersection already removed new edges using them |
5667 | // as markers for other invalid edges |
5668 | aNbB = aMBlocksSp.Extent(); |
5669 | for (i = 1; i <= aNbB; ++i) |
5670 | { |
5671 | const TopoDS_Shape& aCE = aMBlocksSp.FindKey(i); |
5672 | for (TopExp_Explorer anExp(aCE, TopAbs_EDGE); anExp.More(); anExp.Next()) |
5673 | { |
5674 | const TopoDS_Shape& aEIm = anExp.Current(); |
5675 | if (aMENew.Contains(aEIm) && !aMEVal.Contains(aEIm)) |
5676 | aLValBlocks.Append(aEIm); |
5677 | } |
5678 | } |
5679 | |
5680 | if (aLValBlocks.Extent() > 1) |
5681 | // intersect the new splits among themselves to avoid self-intersections |
5682 | IntersectEdges(aLValBlocks, aLE, theMVBounds, theVertsToAvoid, aMENew, theMECheckExt, |
5683 | theEImages, theModifiedEdges, aDMEOr, aMELF, aSplits1); |
5684 | else |
5685 | aSplits1 = aLValBlocks.First(); |
5686 | |
5687 | // Get all faces to get the bounds from their splits |
5688 | TopTools_ListOfShape aLFaces; |
5689 | for (i = 1; i <= theFImages.Extent(); ++i) |
5690 | aLFaces.Append(theFImages.FindKey(i)); |
5691 | |
5692 | // Bounds of the splits of the offset faces to filter the new splits |
5693 | TopoDS_Shape aFilterBounds; |
5694 | GetBounds(aLFaces, theFImages, aMEB, aFilterBounds); |
5695 | |
5696 | // Filter the splits by intersection with bounds |
5697 | TopTools_MapOfShape aMEInv; |
5698 | GetInvalidEdgesByBounds(aSplits1, aFilterBounds, theFImages, theSolids, |
5699 | theInvEdges, aMVOld, aMENew, aDMEOr, aMELF, theEImages, |
5700 | theMECheckExt, theMEInvOnArt, aCtx, theVertsToAvoid, aMEInv); |
5701 | |
5702 | // Filter the images of edges after the second filtering stage |
5703 | // and combine all valid edges into a single compound |
5704 | TopoDS_Shape aSplits; |
5705 | FilterSplits(aLE, aMEInv, Standard_True, theEImages, aSplits); |
5706 | |
ecf4f17c |
5707 | // get bounds to update |
5708 | // we need to update the edges of all the affected faces |
5709 | TopTools_ListOfShape aLF; |
5710 | // prepare the vertices from new splits of edges |
5711 | TopTools_IndexedMapOfShape aMVSp; |
5712 | TopExp::MapShapes(aSplits, TopAbs_VERTEX, aMVSp); |
5713 | // |
5714 | Standard_Integer aNbF = theFImages.Extent(); |
5715 | for (i = 1; i <= aNbF; ++i) { |
5716 | const TopoDS_Shape& aF = theFImages.FindKey(i); |
5717 | if (theFLE.Contains(aF)) { |
5718 | aLF.Append(aF); |
5719 | continue; |
5720 | } |
5721 | // |
5722 | // check the splits of faces to have vertices from splits |
5723 | const TopTools_ListOfShape& aLFIm = theFImages(i); |
5724 | TopTools_ListIteratorOfListOfShape aItLFIm(aLFIm); |
5725 | for (; aItLFIm.More(); aItLFIm.Next()) { |
5726 | const TopoDS_Shape& aFIm = aItLFIm.Value(); |
5727 | // |
5728 | TopExp_Explorer aExpV(aFIm, TopAbs_VERTEX); |
5729 | for (; aExpV.More(); aExpV.Next()) { |
5730 | const TopoDS_Shape& aV = aExpV.Current(); |
5731 | if (aMVSp.Contains(aV)) { |
5732 | break; |
5733 | } |
5734 | } |
5735 | // |
5736 | if (aExpV.More()) { |
5737 | break; |
5738 | } |
5739 | } |
5740 | // |
5741 | if (aItLFIm.More()) { |
5742 | aLF.Append(aF); |
5743 | } |
5744 | } |
5745 | // |
5746 | // get bounds from splits of faces of aLF |
5747 | TopoDS_Shape aBounds; |
5748 | TopTools_ListOfShape aLAValid, aLABounds; |
5749 | GetBoundsToUpdate(aLF, theOEImages, theOEOrigins, aMEB, |
5750 | aLABounds, aLAValid, aBounds, theAsDes); |
5751 | // |
81a55a69 |
5752 | // Intersect valid splits with bounds and update both |
ecf4f17c |
5753 | BOPAlgo_Builder aGF; |
ecf4f17c |
5754 | aGF.AddArgument(aBounds); |
edfa30de |
5755 | aGF.AddArgument(aSplits); |
ecf4f17c |
5756 | aGF.Perform(); |
5757 | // |
5758 | // update splits |
5759 | UpdateImages(aLE, theEImages, aGF, theModifiedEdges); |
5760 | // |
5761 | // update new intersection edges |
5762 | UpdateNewIntersectionEdges(aLE, aMELF, theEImages, theInvEdges, theInvertedEdges, theEdgesOrigins, |
5763 | theOEImages, theOEOrigins, theETrimEInf, theEETrim, theModifiedEdges, theAsDes); |
5764 | // |
5765 | // update bounds |
5766 | UpdateImages(aLAValid, theOEImages, aGF, theModifiedEdges); |
5767 | UpdateOrigins(aLABounds, theOEOrigins, aGF); |
5768 | UpdateOrigins(aLABounds, theEdgesOrigins, aGF); |
5769 | UpdateIntersectedEdges(aLABounds, theETrimEInf, aGF); |
5770 | // |
edfa30de |
5771 | // update the EdgesToAvoid with the splits |
ecf4f17c |
5772 | TopTools_IndexedMapOfShape aNewEdges; |
5773 | const TopTools_ListOfShape* pSplitsIm = aGF.Images().Seek(aSplits); |
5774 | if (pSplitsIm) { |
5775 | TopTools_ListIteratorOfListOfShape aItSpIm(*pSplitsIm); |
5776 | for (; aItSpIm.More(); aItSpIm.Next()) { |
5777 | TopExp::MapShapes(aItSpIm.Value(), TopAbs_EDGE, aNewEdges); |
5778 | } |
5779 | } |
5780 | // |
81a55a69 |
5781 | // Rebuild the map of edges to avoid, using the intersection results |
5782 | TopTools_IndexedMapOfShape aMEAvoid; |
5783 | // GF's data structure |
5784 | const BOPDS_PDS& pDS = aGF.PDS(); |
5785 | |
dcba2e5c |
5786 | aNbE = theEdgesToAvoid.Extent(); |
81a55a69 |
5787 | for (i = 1; i <= aNbE; ++i) |
5788 | { |
ecf4f17c |
5789 | const TopoDS_Shape& aE = theEdgesToAvoid(i); |
5790 | const TopTools_ListOfShape& aLEIm = aGF.Modified(aE); |
81a55a69 |
5791 | |
5792 | // Only untouched and fully coinciding edges should be kept in the avoid map |
5793 | Standard_Boolean bKeep = aLEIm.IsEmpty(); |
5794 | if (aLEIm.Extent() == 1 && aE.IsSame(aLEIm.First())) |
5795 | { |
5796 | const BOPDS_ListOfPaveBlock& aLPB = pDS->PaveBlocks(pDS->Index(aE)); |
5797 | if (aLPB.Extent() == 1) |
5798 | { |
5799 | const Handle(BOPDS_PaveBlock)& aPB = aLPB.First(); |
5800 | const Handle(BOPDS_CommonBlock)& aCB = pDS->CommonBlock(aPB); |
5801 | if (!aCB.IsNull()) |
5802 | { |
5803 | const BOPDS_ListOfPaveBlock& aLPBCB = aCB->PaveBlocks(); |
5804 | BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPBCB); |
5805 | for (; aItLPB.More(); aItLPB.Next()) |
5806 | { |
5807 | if (pDS->PaveBlocks(aItLPB.Value()->OriginalEdge()).Extent() > 1) |
5808 | break; |
5809 | } |
5810 | bKeep = !aItLPB.More(); |
5811 | } |
5812 | } |
5813 | } |
5814 | |
5815 | if (bKeep) |
5816 | { |
5817 | // keep the original edge |
5818 | aMEAvoid.Add(aE); |
5819 | continue; |
5820 | } |
5821 | |
ecf4f17c |
5822 | TopTools_ListIteratorOfListOfShape aItLEIm(aLEIm); |
81a55a69 |
5823 | for (; aItLEIm.More(); aItLEIm.Next()) |
5824 | { |
ecf4f17c |
5825 | const TopoDS_Shape& aEIm = aItLEIm.Value(); |
81a55a69 |
5826 | if (!aNewEdges.Contains(aEIm)) |
5827 | aMEAvoid.Add(aEIm); |
ecf4f17c |
5828 | } |
5829 | } |
81a55a69 |
5830 | theEdgesToAvoid = aMEAvoid; |
ecf4f17c |
5831 | } |
5832 | |
5833 | //======================================================================= |
5834 | //function : TrimNewIntersectionEdges |
5835 | //purpose : |
5836 | //======================================================================= |
5837 | void TrimNewIntersectionEdges(const TopTools_ListOfShape& theLE, |
5838 | const TopTools_DataMapOfShapeListOfShape& theEETrim, |
5839 | const TopTools_MapOfShape& theMVBounds, |
41aa3c3d |
5840 | TopTools_MapOfShape& theMECheckExt, |
ecf4f17c |
5841 | TopTools_DataMapOfShapeListOfShape& theEImages, |
5842 | TopTools_MapOfShape& theMEB, |
5843 | TopTools_MapOfShape& theMVOld, |
dcba2e5c |
5844 | TopTools_MapOfShape& theMENew, |
41aa3c3d |
5845 | TopTools_DataMapOfShapeListOfShape& theDMEOr, |
5846 | TopTools_DataMapOfShapeListOfShape& theMELF) |
ecf4f17c |
5847 | { |
5848 | TopTools_ListIteratorOfListOfShape aIt, aIt1; |
5849 | aIt.Initialize(theLE); |
5850 | for (; aIt.More(); aIt.Next()) { |
5851 | const TopoDS_Shape& aE = aIt.Value(); |
5852 | // |
b443d536 |
5853 | Standard_Boolean bCheckExt = theMECheckExt.Remove(aE); |
5854 | // |
41aa3c3d |
5855 | Standard_Boolean bOld = theEETrim.IsBound(aE); |
5856 | if (bOld) { |
ecf4f17c |
5857 | const TopTools_ListOfShape& aLET = theEETrim.Find(aE); |
5858 | aIt1.Initialize(aLET); |
5859 | for (; aIt1.More(); aIt1.Next()) { |
5860 | const TopoDS_Shape& aET = aIt1.Value(); |
5861 | theMEB.Add(aET); |
5862 | TopExp_Explorer aExpV(aET, TopAbs_VERTEX); |
5863 | for (; aExpV.More(); aExpV.Next()) { |
5864 | const TopoDS_Shape& aV = aExpV.Current(); |
5865 | theMVOld.Add(aV); |
5866 | } |
5867 | } |
5868 | } |
5869 | // |
5870 | if (!theEImages.IsBound(aE)) { |
5871 | continue; |
5872 | } |
5873 | // |
5874 | TopTools_ListOfShape& aLEIm = theEImages.ChangeFind(aE); |
5875 | if (aLEIm.IsEmpty()) { |
5876 | theEImages.UnBind(aE); |
5877 | continue; |
5878 | } |
5879 | // |
5880 | TopoDS_Shape aCEIm; |
5881 | TopTools_MapOfShape aMEVBounds; |
5882 | // |
a8232603 |
5883 | if (aLEIm.Extent() > 1) { |
ecf4f17c |
5884 | TopTools_IndexedMapOfShape aMV; |
5885 | // fuse these parts |
5886 | BOPAlgo_Builder aGFE; |
5887 | TopTools_ListIteratorOfListOfShape aItLEIm(aLEIm); |
5888 | for (; aItLEIm.More(); aItLEIm.Next()) { |
5889 | const TopoDS_Shape& aEIm = aItLEIm.Value(); |
5890 | aGFE.AddArgument(aEIm); |
5891 | TopExp::MapShapes(aEIm, TopAbs_VERTEX, aMV); |
5892 | } |
5893 | // |
5894 | // add two bounding vertices of this edge to the operation |
5895 | TopoDS_Vertex aV1, aV2; |
5896 | TopExp::Vertices(TopoDS::Edge(aE), aV1, aV2); |
5897 | // |
5898 | aGFE.AddArgument(aV1); |
5899 | aGFE.AddArgument(aV2); |
5900 | aMV.Add(aV1); |
5901 | aMV.Add(aV2); |
5902 | // |
5903 | aGFE.Perform(); |
33ba8565 |
5904 | if (!aGFE.HasErrors()) { |
ecf4f17c |
5905 | // get images of bounding vertices to remove splits containing them |
5906 | // in case some of the bounding edges has been interfered |
5907 | // during operation it is necessary to update their images as well |
5908 | Standard_Integer iV, aNbV = aMV.Extent(); |
5909 | for (iV = 1; iV <= aNbV; ++iV) { |
5910 | const TopoDS_Shape& aV = aMV(iV); |
5911 | if (theMVBounds.Contains(aV) || aV.IsSame(aV1) || aV.IsSame(aV2)) { |
5912 | const TopTools_ListOfShape& aLVIm = aGFE.Modified(aV); |
41aa3c3d |
5913 | aMEVBounds.Add(aLVIm.IsEmpty() ? aV : aLVIm.First()); |
ecf4f17c |
5914 | } |
5915 | } |
5916 | // |
5917 | aCEIm = aGFE.Shape(); |
5918 | } |
5919 | } |
5920 | else { |
5921 | aCEIm = aLEIm.First(); |
5922 | } |
5923 | // |
5924 | aLEIm.Clear(); |
5925 | // |
5926 | TopExp_Explorer aExp(aCEIm, TopAbs_EDGE); |
5927 | for (; aExp.More(); aExp.Next()) { |
5928 | const TopoDS_Shape& aEIm = aExp.Current(); |
5929 | // |
5930 | // check the split not to contain bounding vertices |
5931 | TopoDS_Iterator aItV(aEIm); |
5932 | for (; aItV.More(); aItV.Next()) { |
5933 | const TopoDS_Shape& aV = aItV.Value(); |
5934 | if (aMEVBounds.Contains(aV) || theMVBounds.Contains(aV)) { |
5935 | break; |
5936 | } |
5937 | } |
5938 | // |
5939 | if (!aItV.More()) { |
ecf4f17c |
5940 | aLEIm.Append(aEIm); |
5941 | // |
5942 | theDMEOr.Bound(aEIm, TopTools_ListOfShape())->Append(aE); |
5943 | } |
5944 | } |
5945 | // |
5946 | if (aLEIm.IsEmpty()) { |
5947 | theEImages.UnBind(aE); |
5948 | } |
5949 | else { |
41aa3c3d |
5950 | const TopTools_ListOfShape& aLFE = theMELF.Find(aE); |
5951 | TopTools_ListIteratorOfListOfShape aItLEIm(aLEIm); |
5952 | for (; aItLEIm.More(); aItLEIm.Next()) { |
5953 | const TopoDS_Shape& aEIm = aItLEIm.Value(); |
5954 | TopTools_ListOfShape* pLFEIm = theMELF.ChangeSeek(aEIm); |
5955 | if (!pLFEIm) { |
5956 | pLFEIm = theMELF.Bound(aEIm, TopTools_ListOfShape()); |
5957 | } |
5958 | TopTools_ListIteratorOfListOfShape aItLF(aLFE); |
5959 | for (; aItLF.More(); aItLF.Next()) { |
5960 | AppendToList(*pLFEIm, aItLF.Value()); |
5961 | } |
5962 | // |
5963 | if (bCheckExt) { |
5964 | theMECheckExt.Add(aEIm); |
5965 | } |
5966 | else if (!bOld) { |
dcba2e5c |
5967 | theMENew.Add(aEIm); |
ecf4f17c |
5968 | } |
5969 | } |
5970 | } |
5971 | } |
5972 | } |
5973 | |
5974 | //======================================================================= |
5975 | //function : IntersectEdges |
5976 | //purpose : Intersecting the trimmed edges to avoid self-intersections |
5977 | //======================================================================= |
1155d05a |
5978 | void IntersectEdges(const TopTools_ListOfShape& theLA, |
ecf4f17c |
5979 | const TopTools_ListOfShape& theLE, |
ecf4f17c |
5980 | const TopTools_MapOfShape& theMVBounds, |
5981 | const TopTools_MapOfShape& theVertsToAvoid, |
dcba2e5c |
5982 | TopTools_MapOfShape& theMENew, |
41aa3c3d |
5983 | TopTools_MapOfShape& theMECheckExt, |
ecf4f17c |
5984 | TopTools_DataMapOfShapeListOfShape& theEImages, |
5985 | TopTools_MapOfShape& theModifiedEdges, |
5986 | TopTools_DataMapOfShapeListOfShape& theDMEOr, |
41aa3c3d |
5987 | TopTools_DataMapOfShapeListOfShape& theMELF, |
ecf4f17c |
5988 | TopoDS_Shape& theSplits) |
5989 | { |
5990 | BOPAlgo_Builder aGFA; |
5991 | aGFA.SetArguments(theLA); |
5992 | aGFA.Perform(); |
33ba8565 |
5993 | if (aGFA.HasErrors()) { |
ecf4f17c |
5994 | // just copy input to the result |
5995 | TopoDS_Compound aSp; |
5996 | BRep_Builder aBB; |
5997 | aBB.MakeCompound(aSp); |
1155d05a |
5998 | TopTools_ListIteratorOfListOfShape anIt(theLA); |
ecf4f17c |
5999 | for (; anIt.More(); anIt.Next()) { |
6000 | const TopoDS_Shape& aE = anIt.Value(); |
6001 | aBB.Add(aSp, aE); |
6002 | } |
6003 | theSplits = aSp; |
6004 | return; |
6005 | } |
6006 | // |
6007 | UpdateImages(theLE, theEImages, aGFA, theModifiedEdges); |
6008 | // |
6009 | // compound of valid splits |
6010 | theSplits = aGFA.Shape(); |
6011 | // |
ecf4f17c |
6012 | TopTools_ListIteratorOfListOfShape aIt, aIt1; |
dcba2e5c |
6013 | |
6014 | // prepare list of edges to update |
6015 | TopTools_ListOfShape aLEInput; |
6016 | for (aIt.Initialize(theLA); aIt.More(); aIt.Next()) |
6017 | { |
6018 | TopExp_Explorer anExpE(aIt.Value(), TopAbs_EDGE); |
6019 | for (; anExpE.More(); anExpE.Next()) |
6020 | aLEInput.Append(anExpE.Current()); |
6021 | } |
6022 | |
6023 | // update new edges |
6024 | aIt.Initialize(aLEInput); |
ecf4f17c |
6025 | for (; aIt.More(); aIt.Next()) { |
6026 | const TopoDS_Shape& aE = aIt.Value(); |
dcba2e5c |
6027 | if (!theMENew.Contains(aE)) |
6028 | continue; |
6029 | |
ecf4f17c |
6030 | const TopTools_ListOfShape& aLEIm = aGFA.Modified(aE); |
dcba2e5c |
6031 | if (aLEIm.IsEmpty()) |
6032 | continue; |
6033 | |
6034 | theMENew.Remove(aE); |
6035 | aIt1.Initialize(aLEIm); |
6036 | for (; aIt1.More(); aIt1.Next()) |
6037 | theMENew.Add(aIt1.Value()); |
ecf4f17c |
6038 | } |
6039 | // |
41aa3c3d |
6040 | // update edges after intersection for extended checking |
dcba2e5c |
6041 | aIt.Initialize(aLEInput); |
41aa3c3d |
6042 | for (; aIt.More(); aIt.Next()) { |
6043 | const TopoDS_Shape& aE = aIt.Value(); |
6044 | const TopTools_ListOfShape& aLEIm = aGFA.Modified(aE); |
6045 | if (aLEIm.IsEmpty()) { |
6046 | continue; |
6047 | } |
6048 | // |
6049 | if (theMECheckExt.Contains(aE)) { |
6050 | aIt1.Initialize(aLEIm); |
6051 | for (; aIt1.More(); aIt1.Next()) { |
6052 | theMECheckExt.Add(aIt1.Value()); |
6053 | } |
6054 | theMECheckExt.Remove(aE); |
6055 | } |
6056 | // |
6057 | const TopTools_ListOfShape& aLFE = theMELF.Find(aE); |
6058 | aIt1.Initialize(aLEIm); |
6059 | for (; aIt1.More(); aIt1.Next()) { |
6060 | const TopoDS_Shape& aEIm = aIt1.Value(); |
6061 | TopTools_ListOfShape* pLFEIm = theMELF.ChangeSeek(aEIm); |
6062 | if (!pLFEIm) { |
6063 | pLFEIm = theMELF.Bound(aEIm, TopTools_ListOfShape()); |
6064 | } |
6065 | TopTools_ListIteratorOfListOfShape aItLF(aLFE); |
6066 | for (; aItLF.More(); aItLF.Next()) { |
6067 | AppendToList(*pLFEIm, aItLF.Value()); |
6068 | } |
6069 | } |
6070 | } |
6071 | // |
ecf4f17c |
6072 | TopTools_MapOfShape aMEInv; |
6073 | GetInvalidEdges(theVertsToAvoid, theMVBounds, aGFA, aMEInv); |
6074 | if (aMEInv.Extent()) { |
6075 | // update shape |
6076 | TopoDS_Compound aSp; |
6077 | BRep_Builder aBB; |
6078 | aBB.MakeCompound(aSp); |
6079 | TopExp_Explorer aExp(theSplits, TopAbs_EDGE); |
6080 | for (; aExp.More(); aExp.Next()) { |
6081 | const TopoDS_Shape& aE = aExp.Current(); |
6082 | if (!aMEInv.Contains(aE)) { |
6083 | aBB.Add(aSp, aE); |
6084 | } |
6085 | } |
6086 | theSplits = aSp; |
6087 | } |
6088 | // |
dcba2e5c |
6089 | // update origins |
6090 | UpdateOrigins(aLEInput, theDMEOr, aGFA); |
ecf4f17c |
6091 | } |
6092 | |
6093 | //======================================================================= |
6094 | //function : GetBounds |
6095 | //purpose : Getting edges from the splits of offset faces |
6096 | //======================================================================= |
dcba2e5c |
6097 | void GetBounds(const TopTools_ListOfShape& theLFaces, |
6098 | const TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
ecf4f17c |
6099 | const TopTools_MapOfShape& theMEB, |
6100 | TopoDS_Shape& theBounds) |
6101 | { |
ecf4f17c |
6102 | BRep_Builder aBB; |
dcba2e5c |
6103 | // Make compound of edges contained in the splits of faces |
6104 | TopoDS_Compound aBounds; |
ecf4f17c |
6105 | aBB.MakeCompound(aBounds); |
dcba2e5c |
6106 | // Fence map |
ecf4f17c |
6107 | TopTools_MapOfShape aMFence; |
dcba2e5c |
6108 | |
6109 | TopTools_ListIteratorOfListOfShape aItLF(theLFaces); |
6110 | for (; aItLF.More(); aItLF.Next()) |
6111 | { |
6112 | const TopTools_ListOfShape* pLFIm = theFImages.Seek(aItLF.Value()); |
6113 | if (!pLFIm) |
6114 | continue; |
6115 | TopTools_ListIteratorOfListOfShape aIt(*pLFIm); |
6116 | for (; aIt.More(); aIt.Next()) |
6117 | { |
ecf4f17c |
6118 | const TopoDS_Shape& aFIm = aIt.Value(); |
6119 | // |
6120 | TopExp_Explorer aExpE(aFIm, TopAbs_EDGE); |
dcba2e5c |
6121 | for (; aExpE.More(); aExpE.Next()) |
6122 | { |
ecf4f17c |
6123 | const TopoDS_Shape& aEIm = aExpE.Current(); |
6124 | if (!theMEB.Contains(aEIm) && aMFence.Add(aEIm)) { |
6125 | aBB.Add(aBounds, aEIm); |
6126 | } |
6127 | } |
6128 | } |
6129 | } |
6130 | theBounds = aBounds; |
6131 | } |
6132 | |
6133 | //======================================================================= |
6134 | //function : GetBoundsToUpdate |
6135 | //purpose : Get bounding edges that should be updated |
6136 | //======================================================================= |
6137 | void GetBoundsToUpdate(const TopTools_ListOfShape& theLF, |
6138 | const TopTools_DataMapOfShapeListOfShape& theOEImages, |
6139 | const TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
6140 | const TopTools_MapOfShape& theMEB, |
6141 | TopTools_ListOfShape& theLABounds, |
6142 | TopTools_ListOfShape& theLAValid, |
6143 | TopoDS_Shape& theBounds, |
6144 | Handle(BRepAlgo_AsDes)& theAsDes) |
6145 | { |
6146 | // get all edges |
6147 | TopoDS_Compound aBounds; |
6148 | BRep_Builder aBB; |
6149 | aBB.MakeCompound(aBounds); |
6150 | // |
6151 | TopTools_MapOfShape aMAValid, aMFence; |
6152 | // |
6153 | TopTools_ListIteratorOfListOfShape aItLF(theLF); |
6154 | for (; aItLF.More(); aItLF.Next()) { |
6155 | const TopoDS_Shape& aF = aItLF.Value(); |
6156 | // |
6157 | TopTools_IndexedMapOfShape aMDE; |
6158 | const TopTools_ListOfShape& aLFDes = theAsDes->Descendant(aF); |
6159 | TopTools_ListIteratorOfListOfShape aItLFDes(aLFDes); |
6160 | for (; aItLFDes.More(); aItLFDes.Next()) { |
6161 | const TopoDS_Shape& aED = aItLFDes.Value(); |
6162 | const TopTools_ListOfShape *pLEDIm = theOEImages.Seek(aED); |
6163 | if (!pLEDIm) { |
6164 | aMDE.Add(aED); |
6165 | continue; |
6166 | } |
6167 | // |
6168 | TopTools_ListIteratorOfListOfShape aItLEDIm(*pLEDIm); |
6169 | for (; aItLEDIm.More(); aItLEDIm.Next()) { |
6170 | const TopoDS_Shape& aEDIm = aItLEDIm.Value(); |
6171 | aMDE.Add(aEDIm); |
6172 | } |
6173 | } |
6174 | // |
6175 | Standard_Integer j, aNbE = aMDE.Extent(); |
6176 | for (j = 1; j <= aNbE; ++j) { |
6177 | const TopoDS_Edge& aEIm = TopoDS::Edge(aMDE(j)); |
6178 | // |
6179 | if (!theMEB.Contains(aEIm) && aMFence.Add(aEIm)) { |
6180 | aBB.Add(aBounds, aEIm); |
6181 | theLABounds.Append(aEIm); |
6182 | } |
6183 | // |
6184 | const TopTools_ListOfShape *pLO = theOEOrigins.Seek(aEIm); |
6185 | if (pLO) { |
6186 | TopTools_ListIteratorOfListOfShape aItLO(*pLO); |
6187 | for (; aItLO.More(); aItLO.Next()) { |
6188 | const TopoDS_Shape& aEO = aItLO.Value(); |
6189 | // |
6190 | if (aMAValid.Add(aEO)) { |
6191 | theLAValid.Append(aEO); |
6192 | } |
6193 | } |
6194 | } |
6195 | else { |
6196 | if (aMAValid.Add(aEIm)) { |
6197 | theLAValid.Append(aEIm); |
6198 | } |
6199 | } |
6200 | } |
6201 | } |
6202 | theBounds = aBounds; |
6203 | } |
6204 | |
6205 | //======================================================================= |
6206 | //function : GetInvalidEdgesByBounds |
6207 | //purpose : Filter new splits by intersection with bounds |
6208 | //======================================================================= |
6209 | void GetInvalidEdgesByBounds(const TopoDS_Shape& theSplits, |
6210 | const TopoDS_Shape& theBounds, |
ecf4f17c |
6211 | const TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
6212 | const TopoDS_Shape& theSolids, |
6213 | const TopTools_IndexedMapOfShape& theInvEdges, |
6214 | const TopTools_MapOfShape& theMVOld, |
6215 | const TopTools_MapOfShape& theMENew, |
6216 | const TopTools_DataMapOfShapeListOfShape& theDMEOr, |
41aa3c3d |
6217 | const TopTools_DataMapOfShapeListOfShape& theMELF, |
ecf4f17c |
6218 | const TopTools_DataMapOfShapeListOfShape& theEImages, |
41aa3c3d |
6219 | const TopTools_MapOfShape& theMECheckExt, |
a8232603 |
6220 | const TopTools_MapOfShape& theMEInvOnArt, |
dcba2e5c |
6221 | Handle(IntTools_Context)& theCtx, |
ecf4f17c |
6222 | TopTools_MapOfShape& theVertsToAvoid, |
6223 | TopTools_MapOfShape& theMEInv) |
6224 | { |
a8232603 |
6225 | // map splits to check the vertices of edges |
6226 | TopTools_IndexedDataMapOfShapeListOfShape aDMVE; |
6227 | TopExp::MapShapesAndAncestors(theSplits, TopAbs_VERTEX, TopAbs_EDGE, aDMVE); |
6228 | // |
ecf4f17c |
6229 | BOPAlgo_Section aSec; |
6230 | aSec.AddArgument(theSplits); |
6231 | aSec.AddArgument(theBounds); |
6232 | // |
6233 | aSec.Perform(); |
6234 | // |
6235 | // invalid vertices |
6236 | TopTools_IndexedMapOfShape aMVInv; |
6237 | // vertices to check additionally by classification relatively to solid |
6238 | TopTools_MapOfShape aMVCheckAdd; |
6239 | // collect parts for removal |
6240 | const BOPDS_PDS& pDS = aSec.PDS(); |
6241 | // |
6242 | // check edge/edge intersections |
6243 | const BOPDS_VectorOfInterfEE& aEEs = pDS->InterfEE(); |
1155d05a |
6244 | Standard_Integer i, aNb = aEEs.Length(); |
ecf4f17c |
6245 | for (i = 0; i < aNb; ++i) { |
6246 | const BOPDS_InterfEE& aEE = aEEs(i); |
ecf4f17c |
6247 | // |
6248 | const TopoDS_Shape& aE1 = pDS->Shape(aEE.Index1()); |
6249 | const TopoDS_Shape& aE2 = pDS->Shape(aEE.Index2()); |
6250 | // |
41aa3c3d |
6251 | if (!aEE.HasIndexNew()) { |
6252 | if (theMECheckExt.Contains(aE1) && (aEE.CommonPart().Type() == TopAbs_EDGE)) { |
6253 | theMEInv.Add(aE1); |
6254 | } |
6255 | continue; |
6256 | } |
6257 | // |
ecf4f17c |
6258 | if (theInvEdges.Contains(aE2)) { |
6259 | theMEInv.Add(aE1); |
6260 | } |
6261 | // |
a8232603 |
6262 | if (theMEInvOnArt.Contains(aE2)) { |
6263 | // avoid checking of the vertices of the split edge intersected by |
6264 | // the invalid edge from artificial face |
6265 | TopoDS_Vertex aV1, aV2; |
6266 | TopExp::Vertices(TopoDS::Edge(aE2), aV1, aV2); |
6267 | if (aDMVE.Contains(aV1) && aDMVE.Contains(aV2)) { |
6268 | continue; |
6269 | } |
6270 | } |
6271 | // |
41aa3c3d |
6272 | // add vertices of all images of the edge from splits for checking |
ecf4f17c |
6273 | const TopTools_ListOfShape& aLEOr = theDMEOr.Find(aE1); |
6274 | TopTools_ListIteratorOfListOfShape aItLEOr(aLEOr); |
6275 | for (; aItLEOr.More(); aItLEOr.Next()) { |
6276 | const TopoDS_Shape& aEOr = aItLEOr.Value(); |
6277 | // |
dcba2e5c |
6278 | const TopTools_ListOfShape *pLEIm = theEImages.Seek(aEOr); |
6279 | if (!pLEIm) |
6280 | continue; |
6281 | TopTools_ListIteratorOfListOfShape aItLEIm(*pLEIm); |
ecf4f17c |
6282 | for (; aItLEIm.More(); aItLEIm.Next()) { |
6283 | const TopoDS_Shape& aEIm = aItLEIm.Value(); |
6284 | // |
6285 | TopoDS_Iterator aItV(aEIm); |
6286 | for (; aItV.More(); aItV.Next()) { |
6287 | const TopoDS_Shape& aV = aItV.Value(); |
6288 | if (!theMVOld.Contains(aV)) { |
6289 | aMVInv.Add(aV); |
6290 | aMVCheckAdd.Add(aV); |
6291 | } |
6292 | } |
6293 | } |
6294 | } |
6295 | } |
6296 | // |
ecf4f17c |
6297 | // to avoid unnecessary filling of parts due to extra trim of the edges |
41aa3c3d |
6298 | // process Edge/Edge interferences of type EDGE, i.e. common blocks and check |
6299 | // not the bounding vertices of the edges, but check the edge itself |
6300 | // to be lying on some face |
ecf4f17c |
6301 | // |
6302 | // all common blocks are contained in the result of SECTION operation |
6303 | // between sets of edges |
6304 | const TopoDS_Shape& aSecR = aSec.Shape(); |
6305 | // |
6306 | TopTools_IndexedMapOfShape aMSSec; |
6307 | TopExp::MapShapes(aSecR, aMSSec); |
6308 | // |
1155d05a |
6309 | const TopTools_DataMapOfShapeListOfShape& anIm = aSec.Images(); |
45d0af05 |
6310 | for (TopExp_Explorer aExp(theSplits, TopAbs_EDGE); aExp.More(); aExp.Next()) |
6311 | { |
ecf4f17c |
6312 | const TopoDS_Shape& aE = aExp.Current(); |
6313 | if (aSec.IsDeleted(aE)) { |
6314 | // no common blocks for this edge |
6315 | continue; |
6316 | } |
6317 | // |
1155d05a |
6318 | const TopTools_ListOfShape* pLEIm = anIm.Seek(aE); |
ecf4f17c |
6319 | if (!pLEIm) { |
6320 | // no splits, i.e. completely coincides with some edge from boundary |
6321 | continue; |
6322 | } |
6323 | // |
1155d05a |
6324 | TopTools_ListIteratorOfListOfShape aItLEIm(*pLEIm); |
ecf4f17c |
6325 | for (; aItLEIm.More(); aItLEIm.Next()) { |
6326 | const TopoDS_Shape& aEIm = aItLEIm.Value(); |
6327 | if (!aMSSec.Contains(aEIm)) { |
6328 | // the edge included in section only partially. |
41aa3c3d |
6329 | // the part not included in section may be excessive |
ecf4f17c |
6330 | // |
6331 | // check vertices of this edge - if one of them is new |
6332 | // the edge might be removed |
6333 | TopoDS_Vertex aV1, aV2; |
6334 | TopExp::Vertices(TopoDS::Edge(aEIm), aV1, aV2); |
6335 | if (!theMVOld.Contains(aV1) || !theMVOld.Contains(aV2)) { |
41aa3c3d |
6336 | // add this edge for checking by making new vertex in the middle of the edge |
ecf4f17c |
6337 | TopoDS_Vertex aV; |
6338 | Standard_Real f, l; |
6339 | const Handle(Geom_Curve)& aC = BRep_Tool::Curve(TopoDS::Edge(aEIm), f, l); |
6340 | BRep_Builder().MakeVertex(aV, aC->Value((f+l)*0.5), Precision::Confusion()); |
41aa3c3d |
6341 | // and adding this vertex for checking |
6342 | aDMVE.ChangeFromIndex(aDMVE.Add(aV, TopTools_ListOfShape())).Append(aE); |
ecf4f17c |
6343 | aMVInv.Add(aV); |
6344 | break; |
6345 | } |
6346 | } |
6347 | } |
6348 | } |
6349 | // |
41aa3c3d |
6350 | // Add for check also the edges created from common between splits |
6351 | // of offset faces edges not connected to any invalidity. |
6352 | // These edges may also accidentally fill some part. |
6353 | TopTools_MapIteratorOfMapOfShape aItM(theMECheckExt); |
6354 | for (; aItM.More(); aItM.Next()) { |
6355 | const TopoDS_Shape& aE = aItM.Value(); |
6356 | // |
6357 | // make new vertex in the middle of the edge |
6358 | TopoDS_Vertex aV; |
6359 | Standard_Real f, l; |
6360 | const Handle(Geom_Curve)& aC = BRep_Tool::Curve(TopoDS::Edge(aE), f, l); |
6361 | BRep_Builder().MakeVertex(aV, aC->Value((f + l)*0.5), Precision::Confusion()); |
6362 | // add this vertex for checking |
6363 | aDMVE.ChangeFromIndex(aDMVE.Add(aV, TopTools_ListOfShape())).Append(aE); |
6364 | aMVInv.Add(aV); |
6365 | } |
6366 | // |
6367 | // add for check also the vertices connected only to new or old edges |
ecf4f17c |
6368 | aNb = aDMVE.Extent(); |
6369 | for (i = 1; i <= aNb; ++i) { |
6370 | const TopoDS_Shape& aV = aDMVE.FindKey(i); |
6371 | if (theMVOld.Contains(aV)) { |
6372 | continue; |
6373 | } |
6374 | // |
6375 | Standard_Boolean bNew = Standard_False, bOld = Standard_False; |
6376 | const TopTools_ListOfShape& aLEx = aDMVE(i); |
6377 | TopTools_ListIteratorOfListOfShape aIt(aLEx); |
6378 | for (; aIt.More(); aIt.Next()) { |
6379 | const TopoDS_Shape& aE = aIt.Value(); |
41aa3c3d |
6380 | if (theMECheckExt.Contains(aE)) { |
6381 | continue; |
6382 | } |
6383 | // |
ecf4f17c |
6384 | if (theMENew.Contains(aE)) { |
6385 | bNew = Standard_True; |
6386 | } |
6387 | else { |
6388 | bOld = Standard_True; |
6389 | } |
6390 | // |
6391 | if (bNew && bOld) { |
6392 | break; |
6393 | } |
6394 | } |
6395 | // |
6396 | if (!bNew || !bOld) { |
6397 | aMVInv.Add(aV); |
6398 | aMVCheckAdd.Remove(aV); |
6399 | } |
6400 | } |
6401 | // |
dcba2e5c |
6402 | // perform the checking of the vertices |
41aa3c3d |
6403 | Standard_Integer iv, aNbIV = aMVInv.Extent(); |
ecf4f17c |
6404 | for (iv = 1; iv <= aNbIV; ++iv) { |
6405 | const TopoDS_Vertex& aV = TopoDS::Vertex(aMVInv(iv)); |
41aa3c3d |
6406 | if (theMVOld.Contains(aV)) { |
6407 | continue; |
6408 | } |
6409 | // |
6410 | const TopTools_ListOfShape* pLEInv = aDMVE.Seek(aV); |
6411 | if (!pLEInv) { |
6412 | continue; |
6413 | } |
6414 | // find faces by the edges to check the vertex |
6415 | TopTools_IndexedMapOfShape aMF; |
6416 | TopTools_ListIteratorOfListOfShape aItLE(*pLEInv); |
6417 | for (; aItLE.More(); aItLE.Next()) { |
6418 | const TopoDS_Shape& aE = aItLE.Value(); |
6419 | const TopTools_ListOfShape& aLF = theMELF.Find(aE); |
6420 | TopTools_ListIteratorOfListOfShape aItLF(aLF); |
6421 | for (; aItLF.More(); aItLF.Next()) { |
6422 | aMF.Add(aItLF.Value()); |
6423 | } |
6424 | } |
6425 | // |
6426 | // check the vertex to belong to some split of the faces |
ecf4f17c |
6427 | Standard_Boolean bInvalid = Standard_True; |
6428 | // |
41aa3c3d |
6429 | Standard_Integer aNbF = aMF.Extent(); |
ecf4f17c |
6430 | for (i = 1; i <= aNbF && bInvalid; ++i) { |
41aa3c3d |
6431 | const TopoDS_Face& aF = TopoDS::Face(aMF(i)); |
ecf4f17c |
6432 | const TopTools_ListOfShape& aLFIm = theFImages.FindFromKey(aF); |
6433 | // |
6434 | TopTools_ListIteratorOfListOfShape aItLF(aLFIm); |
6435 | for (; aItLF.More() && bInvalid; aItLF.Next()) { |
6436 | const TopoDS_Face& aFIm = TopoDS::Face(aItLF.Value()); |
6437 | TopExp_Explorer aExp(aFIm, TopAbs_VERTEX); |
6438 | for (; aExp.More() && bInvalid; aExp.Next()) { |
6439 | const TopoDS_Shape& aVF = aExp.Current(); |
6440 | bInvalid = !aVF.IsSame(aV); |
6441 | } |
41aa3c3d |
6442 | } |
6443 | // |
6444 | if (bInvalid) { |
6445 | Standard_Real U, V, aTol; |
dcba2e5c |
6446 | Standard_Integer iStatus = theCtx->ComputeVF(aV, aF, U, V, aTol); |
41aa3c3d |
6447 | if (!iStatus) { |
6448 | // classify the point relatively faces |
6449 | gp_Pnt2d aP2d(U, V); |
6450 | aItLF.Initialize(aLFIm); |
6451 | for (; aItLF.More() && bInvalid; aItLF.Next()) { |
6452 | const TopoDS_Face& aFIm = TopoDS::Face(aItLF.Value()); |
dcba2e5c |
6453 | bInvalid = !theCtx->IsPointInOnFace(aFIm, aP2d); |
41aa3c3d |
6454 | } |
ecf4f17c |
6455 | } |
6456 | } |
6457 | } |
6458 | // |
6459 | if (bInvalid && aMVCheckAdd.Contains(aV)) { |
6460 | // the vertex is invalid for all faces |
6461 | // check the same vertex for the solids |
41aa3c3d |
6462 | const gp_Pnt& aP = BRep_Tool::Pnt(aV); |
6463 | Standard_Real aTolV = BRep_Tool::Tolerance(aV); |
6464 | // |
ecf4f17c |
6465 | TopExp_Explorer aExpS(theSolids, TopAbs_SOLID); |
6466 | for (; aExpS.More() && bInvalid; aExpS.Next()) { |
6467 | const TopoDS_Solid& aSol = TopoDS::Solid(aExpS.Current()); |
dcba2e5c |
6468 | BRepClass3d_SolidClassifier& aSC = theCtx->SolidClassifier(aSol); |
ecf4f17c |
6469 | aSC.Perform(aP, aTolV); |
6470 | bInvalid = (aSC.State() == TopAbs_OUT); |
6471 | } |
6472 | } |
6473 | // |
6474 | if (bInvalid) { |
6475 | theVertsToAvoid.Add(aV); |
41aa3c3d |
6476 | aItLE.Initialize(*pLEInv); |
6477 | for (; aItLE.More(); aItLE.Next()) { |
6478 | theMEInv.Add(aItLE.Value()); |
ecf4f17c |
6479 | } |
6480 | } |
6481 | } |
6482 | } |
6483 | |
dcba2e5c |
6484 | //======================================================================= |
6485 | //function : FilterSplits |
6486 | //purpose : Filter the images of edges from the invalid edges |
6487 | //======================================================================= |
6488 | void FilterSplits(const TopTools_ListOfShape& theLE, |
6489 | const TopTools_MapOfShape& theMEFilter, |
6490 | const Standard_Boolean theIsInv, |
6491 | TopTools_DataMapOfShapeListOfShape& theEImages, |
6492 | TopoDS_Shape& theSplits) |
6493 | { |
6494 | TopoDS_Compound aSplits; |
6495 | BRep_Builder().MakeCompound(aSplits); |
6496 | TopTools_MapOfShape aMFence; |
6497 | |
6498 | TopTools_ListIteratorOfListOfShape aItLE(theLE); |
6499 | for (; aItLE.More(); aItLE.Next()) |
6500 | { |
6501 | const TopoDS_Shape& aE = aItLE.Value(); |
6502 | TopTools_ListOfShape *pLEIm = theEImages.ChangeSeek(aE); |
6503 | if (!pLEIm) |
6504 | continue; |
6505 | |
6506 | TopTools_ListIteratorOfListOfShape aItLEIm(*pLEIm); |
6507 | for (; aItLEIm.More();) |
6508 | { |
6509 | const TopoDS_Shape& aEIm = aItLEIm.Value(); |
6510 | if (theMEFilter.Contains(aEIm) == theIsInv) |
6511 | { |
6512 | pLEIm->Remove(aItLEIm); |
6513 | continue; |
6514 | } |
6515 | |
6516 | if (aMFence.Add(aEIm)) |
6517 | BRep_Builder().Add(aSplits, aEIm); |
6518 | aItLEIm.Next(); |
6519 | } |
6520 | |
6521 | if (pLEIm->IsEmpty()) |
6522 | theEImages.UnBind(aE); |
6523 | } |
6524 | theSplits = aSplits; |
6525 | } |
6526 | |
ecf4f17c |
6527 | //======================================================================= |
6528 | //function : UpdateNewIntersectionEdges |
6529 | //purpose : Updating the maps of images and origins of the offset edges |
6530 | //======================================================================= |
6531 | void UpdateNewIntersectionEdges(const TopTools_ListOfShape& theLE, |
6532 | const TopTools_DataMapOfShapeListOfShape& theMELF, |
6533 | const TopTools_DataMapOfShapeListOfShape& theEImages, |
6534 | const TopTools_IndexedMapOfShape& theInvEdges, |
6535 | const TopTools_MapOfShape& theInvertedEdges, |
6536 | TopTools_DataMapOfShapeListOfShape& theEdgesOrigins, |
6537 | TopTools_DataMapOfShapeListOfShape& theOEImages, |
6538 | TopTools_DataMapOfShapeListOfShape& theOEOrigins, |
6539 | TopTools_DataMapOfShapeShape& theETrimEInf, |
6540 | TopTools_DataMapOfShapeListOfShape& theEETrim, |
6541 | TopTools_MapOfShape& theModifiedEdges, |
6542 | Handle(BRepAlgo_AsDes)& theAsDes) |
6543 | { |
6544 | TopTools_ListOfShape aLEImEmpty; |
6545 | TopTools_ListIteratorOfListOfShape aIt, aIt1; |
6546 | // update global maps of images and origins with new splits |
6547 | aIt.Initialize(theLE); |
6548 | for (; aIt.More(); aIt.Next()) { |
6549 | const TopoDS_Shape& aE = aIt.Value(); |
6550 | // |
6551 | if (!theEImages.IsBound(aE)) { |
6552 | TopTools_ListOfShape* pLET = theEETrim.ChangeSeek(aE); |
6553 | if (!pLET) { |
6554 | continue; |
6555 | } |
6556 | // |
6557 | TopTools_ListIteratorOfListOfShape aItLET(*pLET); |
6558 | for (; aItLET.More();) { |
6559 | const TopoDS_Shape& aET = aItLET.Value(); |
6560 | if (!theInvEdges.Contains(aET) && !theInvertedEdges.Contains(aET)) { |
6561 | pLET->Remove(aItLET); |
6562 | } |
6563 | else { |
6564 | aItLET.Next(); |
6565 | } |
6566 | } |
6567 | // |
6568 | if (pLET->IsEmpty()) { |
6569 | continue; |
6570 | } |
6571 | } |
6572 | // new images |
6573 | const TopTools_ListOfShape& aLENew = |
6574 | theEImages.IsBound(aE) ? theEImages.Find(aE) : aLEImEmpty; |
6575 | // |
6576 | // save connection to untrimmed edge for the next steps |
6577 | aIt1.Initialize(aLENew); |
6578 | for (; aIt1.More(); aIt1.Next()) { |
6579 | const TopoDS_Shape& aET = aIt1.Value(); |
6580 | theETrimEInf.Bind(aET, aE); |
6581 | theModifiedEdges.Add(aET); |
6582 | } |
6583 | // |
6584 | // check if it is existing edge |
6585 | if (!theEETrim.IsBound(aE)) { |
6586 | const TopTools_ListOfShape& aLF = theMELF.Find(aE); |
6587 | // the edge is new |
6588 | // add this edge to AsDes |
6589 | aIt1.Initialize(aLF); |
6590 | for (; aIt1.More(); aIt1.Next()) { |
6591 | const TopoDS_Shape& aF = aIt1.Value(); |
6592 | theAsDes->Add(aF, aE); |
6593 | } |
6594 | // |
6595 | // add aE to the images |
6596 | theOEImages.Bind(aE, aLENew); |
6597 | theModifiedEdges.Add(aE); |
6598 | // |
6599 | // add to origins |
6600 | TopTools_ListIteratorOfListOfShape aItNew(aLENew); |
6601 | for (; aItNew.More(); aItNew.Next()) { |
6602 | const TopoDS_Shape& aENew = aItNew.Value(); |
6603 | if (theOEOrigins.IsBound(aENew)) { |
6604 | TopTools_ListOfShape& aEOrigins = theOEOrigins.ChangeFind(aENew); |
6605 | AppendToList(aEOrigins, aE); |
6606 | } |
6607 | else { |
6608 | TopTools_ListOfShape aEOrigins; |
6609 | aEOrigins.Append(aE); |
6610 | theOEOrigins.Bind(aENew, aEOrigins); |
6611 | } |
6612 | } |
6613 | // |
6614 | // update connection to initial origins |
6615 | if (theEdgesOrigins.IsBound(aE)) { |
6616 | const TopTools_ListOfShape& aLEOrInit = theEdgesOrigins.Find(aE); |
6617 | aIt1.Initialize(aLENew); |
6618 | for (; aIt1.More(); aIt1.Next()) { |
6619 | const TopoDS_Shape& aENew = aIt1.Value(); |
6620 | if (theEdgesOrigins.IsBound(aENew)) { |
6621 | TopTools_ListOfShape& aLENewOr = theEdgesOrigins.ChangeFind(aENew); |
6622 | TopTools_ListIteratorOfListOfShape aItOrInit(aLEOrInit); |
6623 | for (; aItOrInit.More(); aItOrInit.Next()) { |
6624 | const TopoDS_Shape& aEOr = aItOrInit.Value(); |
6625 | AppendToList(aLENewOr, aEOr); |
6626 | } |
6627 | } |
6628 | else { |
6629 | theEdgesOrigins.Bind(aENew, aLEOrInit); |
6630 | } |
6631 | } |
6632 | } |
6633 | // |
6634 | continue; |
6635 | } |
6636 | // |
6637 | // old images |
6638 | const TopTools_ListOfShape& aLEOld = theEETrim.Find(aE); |
6639 | // |
6640 | // list of initial origins |
6641 | TopTools_ListOfShape anInitOrigins; |
6642 | // |
6643 | // it is necessary to replace the old edges with new ones |
6644 | aIt1.Initialize(aLEOld); |
6645 | for (; aIt1.More(); aIt1.Next()) { |
6646 | const TopoDS_Shape& aEOld = aIt1.Value(); |
6647 | // |
6648 | if (theOEOrigins.IsBound(aEOld)) { |
6649 | // get its origins |
6650 | const TopTools_ListOfShape& aEOrigins = theOEOrigins.Find(aEOld); |
6651 | // |
6652 | TopTools_ListIteratorOfListOfShape aItOr(aEOrigins); |
6653 | for (; aItOr.More(); aItOr.Next()) { |
6654 | const TopoDS_Shape& aEOr = aItOr.Value(); |
6655 | // |
6656 | theModifiedEdges.Add(aEOr); |
6657 | // |
6658 | TopTools_ListOfShape& aEImages = theOEImages.ChangeFind(aEOr); |
6659 | // |
6660 | // remove old edge from images |
6661 | TopTools_ListIteratorOfListOfShape aItIm(aEImages); |
6662 | for (; aItIm.More(); ) { |
6663 | const TopoDS_Shape& aEIm = aItIm.Value(); |
6664 | if (aEIm.IsSame(aEOld)) { |
6665 | aEImages.Remove(aItIm); |
6666 | } |
6667 | else { |
6668 | aItIm.Next(); |
6669 | } |
6670 | } |
6671 | // |
6672 | // add new images |
6673 | TopTools_ListIteratorOfListOfShape aItNew(aLENew); |
6674 | for (; aItNew.More(); aItNew.Next()) { |
6675 | const TopoDS_Shape& aENew = aItNew.Value(); |
6676 | AppendToList(aEImages, aENew); |
6677 | if (theOEOrigins.IsBound(aENew)) { |
6678 | TopTools_ListOfShape& aENewOrigins = theOEOrigins.ChangeFind(aENew); |
6679 | AppendToList(aENewOrigins, aEOr); |
6680 | } |
6681 | else { |
6682 | TopTools_ListOfShape aENewOrigins; |
6683 | aENewOrigins.Append(aEOr); |
6684 | theOEOrigins.Bind(aENew, aENewOrigins); |
6685 | } |
6686 | } |
6687 | } |
6688 | } |
6689 | else { |
6690 | // add to images |
6691 | theOEImages.Bind(aEOld, aLENew); |
6692 | // |
6693 | theModifiedEdges.Add(aEOld); |
6694 | // |
6695 | // add to origins |
6696 | TopTools_ListIteratorOfListOfShape aItNew(aLENew); |
6697 | for (; aItNew.More(); aItNew.Next()) { |
6698 | const TopoDS_Shape& aENew = aItNew.Value(); |
6699 | if (theOEOrigins.IsBound(aENew)) { |
6700 | TopTools_ListOfShape& aEOrigins = theOEOrigins.ChangeFind(aENew); |
6701 | AppendToList(aEOrigins, aEOld); |
6702 | } |
6703 | else { |
6704 | TopTools_ListOfShape aEOrigins; |
6705 | aEOrigins.Append(aEOld); |
6706 | theOEOrigins.Bind(aENew, aEOrigins); |
6707 | } |
6708 | } |
6709 | } |
6710 | // |
6711 | // update connection to initial shape |
6712 | if (theEdgesOrigins.IsBound(aEOld)) { |
6713 | const TopTools_ListOfShape& aLEOrInit = theEdgesOrigins.Find(aEOld); |
6714 | TopTools_ListIteratorOfListOfShape aItEOrInit(aLEOrInit); |
6715 | for (; aItEOrInit.More(); aItEOrInit.Next()) { |
6716 | const TopoDS_Shape& aEOrInit = aItEOrInit.Value(); |
6717 | AppendToList(anInitOrigins, aEOrInit); |
6718 | } |
6719 | } |
6720 | } |
6721 | // |
6722 | if (anInitOrigins.Extent()) { |
6723 | TopTools_ListIteratorOfListOfShape aItNew(aLENew); |
6724 | for (; aItNew.More(); aItNew.Next()) { |
6725 | const TopoDS_Shape& aENew = aItNew.Value(); |
6726 | if (theEdgesOrigins.IsBound(aENew)) { |
6727 | TopTools_ListOfShape& aLENewOr = theEdgesOrigins.ChangeFind(aENew); |
6728 | TopTools_ListIteratorOfListOfShape aItOrInit(anInitOrigins); |
6729 | for (; aItOrInit.More(); aItOrInit.Next()) { |
6730 | const TopoDS_Shape& aEOr = aItOrInit.Value(); |
6731 | AppendToList(aLENewOr, aEOr); |
6732 | } |
6733 | } |
6734 | else { |
6735 | theEdgesOrigins.Bind(aENew, anInitOrigins); |
6736 | } |
6737 | } |
6738 | } |
6739 | } |
6740 | } |
6741 | |
2ebb1098 |
6742 | //======================================================================= |
6743 | //function : FillGaps |
6744 | //purpose : Fill possible gaps (holes) in the splits of the offset faces |
6745 | //======================================================================= |
6746 | void FillGaps(TopTools_IndexedDataMapOfShapeListOfShape& theFImages) |
6747 | { |
6748 | Standard_Integer aNbF = theFImages.Extent(); |
6749 | if (!aNbF) |
6750 | return; |
6751 | |
6752 | // Check the splits of offset faces on the free edges and fill the gaps (holes) |
6753 | // in created splits, otherwise the closed volume will not be possible to create. |
6754 | |
6755 | // Map the splits of faces to find free edges |
6756 | TopTools_IndexedDataMapOfShapeListOfShape anEFMap; |
6757 | for (Standard_Integer i = 1; i <= aNbF; ++i) |
6758 | { |
6759 | TopTools_ListIteratorOfListOfShape itLF(theFImages(i)); |
6760 | for (; itLF.More(); itLF.Next()) |
6761 | TopExp::MapShapesAndAncestors(itLF.Value(), TopAbs_EDGE, TopAbs_FACE, anEFMap); |
6762 | } |
6763 | |
6764 | // Analyze images of each offset face on the presence of free edges |
6765 | // and try to fill the holes |
6766 | for (Standard_Integer i = 1; i <= aNbF; ++i) |
6767 | { |
6768 | TopTools_ListOfShape& aLFImages = theFImages(i); |
6769 | if (aLFImages.IsEmpty()) |
6770 | continue; |
6771 | |
6772 | // Collect all edges from the splits |
6773 | TopoDS_Compound anEdges; |
6774 | BRep_Builder().MakeCompound(anEdges); |
6775 | |
6776 | // Collect all free edges into a map with reverted orientation |
6777 | TopTools_MapOfOrientedShape aFreeEdgesMap; |
6778 | TopTools_ListIteratorOfListOfShape itLF(aLFImages); |
6779 | for (; itLF.More(); itLF.Next()) |
6780 | { |
6781 | const TopoDS_Shape& aFIm = itLF.Value(); |
6782 | TopExp_Explorer anExpE(aFIm, TopAbs_EDGE); |
6783 | for (; anExpE.More(); anExpE.Next()) |
6784 | { |
6785 | const TopoDS_Shape& aE = anExpE.Current(); |
6786 | if (aE.Orientation() != TopAbs_FORWARD && |
6787 | aE.Orientation() != TopAbs_REVERSED) |
6788 | // Skip internals |
6789 | continue; |
6790 | |
6791 | const TopTools_ListOfShape& aLF = anEFMap.FindFromKey(aE); |
6792 | if (aLF.Extent() == 1) |
6793 | aFreeEdgesMap.Add(aE.Reversed()); |
6794 | |
6795 | BRep_Builder().Add(anEdges, aE); |
6796 | } |
6797 | } |
6798 | |
6799 | if (aFreeEdgesMap.IsEmpty()) |
6800 | // No free edges |
6801 | continue; |
6802 | |
6803 | // Free edges are found - fill the gaps by creating new splits |
6804 | // of the face using these free edges |
6805 | const TopoDS_Shape& aF = theFImages.FindKey(i); |
6806 | |
6807 | // Build new splits using all kept edges and among new splits |
6808 | // find those containing free edges |
6809 | TopTools_ListOfShape aLFNew; |
6810 | TopTools_DataMapOfShapeShape aDummy; |
6811 | |
6812 | BuildSplitsOfFace(TopoDS::Face(aF), anEdges, aDummy, aLFNew); |
6813 | |
6814 | // Find faces filling holes |
6815 | itLF.Initialize(aLFNew); |
6816 | for (; itLF.More(); itLF.Next()) |
6817 | { |
6818 | const TopoDS_Shape& aFNew = itLF.Value(); |
6819 | TopExp_Explorer anExpE(aFNew, TopAbs_EDGE); |
6820 | for (; anExpE.More(); anExpE.Next()) |
6821 | { |
6822 | const TopoDS_Shape& aE = anExpE.Current(); |
6823 | if (aFreeEdgesMap.Contains(aE)) |
6824 | { |
6825 | // Add face to splits |
6826 | aLFImages.Append(aFNew); |
6827 | break; |
6828 | } |
6829 | } |
6830 | } |
6831 | } |
6832 | } |
6833 | |
ecf4f17c |
6834 | //======================================================================= |
6835 | //function : FillHistory |
6836 | //purpose : Saving obtained results in history tools |
6837 | //======================================================================= |
6838 | void FillHistory(const TopTools_IndexedDataMapOfShapeListOfShape& theFImages, |
6839 | const TopTools_DataMapOfShapeListOfShape& theEImages, |
6840 | BRepAlgo_Image& theImage) |
6841 | { |
2ebb1098 |
6842 | Standard_Integer aNbF = theFImages.Extent(); |
6843 | if (!aNbF) |
ecf4f17c |
6844 | return; |
2ebb1098 |
6845 | |
6846 | #ifdef OFFSET_DEBUG |
6847 | // Build compound of faces to see preliminary result |
6848 | TopoDS_Compound aDFaces; |
6849 | BRep_Builder().MakeCompound(aDFaces); |
6850 | #endif |
6851 | |
6852 | // Map of kept edges |
6853 | TopTools_IndexedMapOfShape anEdgesMap; |
6854 | |
ecf4f17c |
6855 | // Fill history for faces |
2ebb1098 |
6856 | for (Standard_Integer i = 1; i <= aNbF; ++i) |
6857 | { |
ecf4f17c |
6858 | const TopTools_ListOfShape& aLFImages = theFImages(i); |
2ebb1098 |
6859 | if (aLFImages.IsEmpty()) |
6860 | continue; |
6861 | |
6862 | // Add the splits to history map |
6863 | const TopoDS_Shape& aF = theFImages.FindKey(i); |
6864 | if (theImage.HasImage(aF)) |
6865 | theImage.Add(aF, aLFImages); |
6866 | else |
6867 | theImage.Bind(aF, aLFImages); |
6868 | |
6869 | // Collect edges from splits |
6870 | TopTools_ListIteratorOfListOfShape itLF(aLFImages); |
6871 | for (; itLF.More(); itLF.Next()) |
6872 | { |
6873 | const TopoDS_Shape& aFIm = itLF.Value(); |
6874 | TopExp::MapShapes(aFIm, TopAbs_EDGE, anEdgesMap); |
6875 | |
6876 | #ifdef OFFSET_DEBUG |
6877 | BRep_Builder().Add(aDFaces, aFIm); |
6878 | #endif |
ecf4f17c |
6879 | } |
6880 | } |
2ebb1098 |
6881 | |
6882 | // Fill history for edges (iteration by the map is safe because the |
6883 | // order is not important here) |
ecf4f17c |
6884 | TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItEIm(theEImages); |
2ebb1098 |
6885 | for (; aItEIm.More(); aItEIm.Next()) |
6886 | { |
ecf4f17c |
6887 | const TopoDS_Shape& aE = aItEIm.Key(); |
6888 | const TopTools_ListOfShape& aLEIm = aItEIm.Value(); |
2ebb1098 |
6889 | |
ecf4f17c |
6890 | Standard_Boolean bHasImage = theImage.HasImage(aE); |
6891 | TopTools_ListIteratorOfListOfShape aItLE(aLEIm); |
2ebb1098 |
6892 | for (; aItLE.More(); aItLE.Next()) |
6893 | { |
ecf4f17c |
6894 | const TopoDS_Shape& aEIm = aItLE.Value(); |
2ebb1098 |
6895 | if (anEdgesMap.Contains(aEIm)) |
6896 | { |
6897 | if (bHasImage) |
6898 | { |
ecf4f17c |
6899 | theImage.Add(aE, aEIm); |
6900 | } |
2ebb1098 |
6901 | else |
6902 | { |
ecf4f17c |
6903 | theImage.Bind(aE, aEIm); |
6904 | bHasImage = Standard_True; |
6905 | } |
6906 | } |
6907 | } |
6908 | } |
6909 | } |
6910 | |
6911 | //======================================================================= |
6912 | //function : ProcessMicroEdge |
6913 | //purpose : Checking if the edge is micro edge |
6914 | //======================================================================= |
6915 | Standard_Boolean ProcessMicroEdge(const TopoDS_Edge& theEdge, |
6916 | const Handle(IntTools_Context)& theCtx) |
6917 | { |
6918 | TopoDS_Vertex aV1, aV2; |
6919 | TopExp::Vertices(theEdge, aV1, aV2); |
6920 | if (aV1.IsNull() || aV2.IsNull()) { |
6921 | return Standard_False; |
6922 | } |
6923 | // |
6924 | Standard_Boolean bMicro = BOPTools_AlgoTools::IsMicroEdge(theEdge, theCtx); |
6925 | if (bMicro && BRepAdaptor_Curve(theEdge).GetType() == GeomAbs_Line) { |
6926 | Standard_Real aLen = BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2)); |
6927 | BRep_Builder().UpdateVertex(aV1, aLen / 2.); |
6928 | BRep_Builder().UpdateVertex(aV2, aLen / 2.); |
6929 | } |
6930 | // |
6931 | return bMicro; |
6932 | } |
6933 | |
6934 | //======================================================================= |
6935 | //function : UpdateOrigins |
6936 | //purpose : Updating origins |
6937 | //======================================================================= |
6938 | void UpdateOrigins(const TopTools_ListOfShape& theLA, |
6939 | TopTools_DataMapOfShapeListOfShape& theOrigins, |
6940 | BOPAlgo_Builder& theGF) |
6941 | { |
6942 | TopTools_ListIteratorOfListOfShape aItA(theLA); |
6943 | for (; aItA.More(); aItA.Next()) { |
6944 | const TopoDS_Shape& aS = aItA.Value(); |
6945 | // |
6946 | const TopTools_ListOfShape& aLSIm = theGF.Modified(aS); |
6947 | if (aLSIm.IsEmpty()) { |
6948 | continue; |
6949 | } |
6950 | // |
6951 | TopTools_ListOfShape aLSEmpt; |
6952 | TopTools_ListOfShape *pLS = theOrigins.ChangeSeek(aS); |
6953 | if (!pLS) { |
6954 | pLS = &aLSEmpt; |
6955 | pLS->Append(aS); |
6956 | } |
6957 | // |
6958 | TopTools_ListIteratorOfListOfShape aIt(aLSIm); |
6959 | for (; aIt.More(); aIt.Next()) { |
6960 | const TopoDS_Shape& aSIm = aIt.Value(); |
6961 | // |
6962 | TopTools_ListOfShape *pLSOr = theOrigins.ChangeSeek(aSIm); |
6963 | if (!pLSOr) { |
6964 | // just bind the origins |
6965 | theOrigins.Bind(aSIm, *pLS); |
6966 | } |
6967 | else { |
6968 | // merge two lists |
6969 | TopTools_ListIteratorOfListOfShape aIt1(*pLS); |
6970 | for (; aIt1.More(); aIt1.Next()) { |
6971 | const TopoDS_Shape& aS1 = aIt1.Value(); |
6972 | AppendToList(*pLSOr, aS1); |
6973 | } |
6974 | } |
6975 | } |
6976 | } |
6977 | } |
6978 | |
6979 | //======================================================================= |
6980 | //function : UpdateImages |
6981 | //purpose : Updating images of the shapes |
6982 | //======================================================================= |
6983 | void UpdateImages(const TopTools_ListOfShape& theLA, |
6984 | TopTools_DataMapOfShapeListOfShape& theImages, |
6985 | BOPAlgo_Builder& theGF, |
6986 | TopTools_MapOfShape& theModified) |
6987 | { |
6988 | TopTools_ListIteratorOfListOfShape aIt(theLA); |
e08a9b03 |
6989 | for (; aIt.More(); aIt.Next()) |
6990 | { |
ecf4f17c |
6991 | const TopoDS_Shape& aS = aIt.Value(); |
6992 | // |
6993 | TopTools_ListOfShape* pLSIm = theImages.ChangeSeek(aS); |
e08a9b03 |
6994 | if (!pLSIm) |
6995 | { |
ecf4f17c |
6996 | const TopTools_ListOfShape& aLSIm = theGF.Modified(aS); |
e08a9b03 |
6997 | if (aLSIm.Extent()) |
6998 | { |
ecf4f17c |
6999 | theImages.Bind(aS, aLSIm); |
7000 | theModified.Add(aS); |
7001 | } |
7002 | continue; |
7003 | } |
7004 | // |
7005 | TopTools_MapOfShape aMFence; |
7006 | TopTools_ListOfShape aLSImNew; |
7007 | // |
7008 | Standard_Boolean bModified = Standard_False; |
7009 | // |
7010 | // check modifications of the images |
7011 | TopTools_ListIteratorOfListOfShape aIt1(*pLSIm); |
e08a9b03 |
7012 | for (; aIt1.More(); aIt1.Next()) |
7013 | { |
ecf4f17c |
7014 | const TopoDS_Shape& aSIm = aIt1.Value(); |
e08a9b03 |
7015 | bModified |= TakeModified(aSIm, theGF.Images(), aLSImNew, &aMFence); |
ecf4f17c |
7016 | } |
7017 | // |
e08a9b03 |
7018 | if (bModified) |
7019 | { |
ecf4f17c |
7020 | *pLSIm = aLSImNew; |
7021 | theModified.Add(aS); |
7022 | } |
7023 | } |
7024 | } |
7025 | |
7026 | //======================================================================= |
7027 | //function : UpdateIntersectedEdges |
7028 | //purpose : Saving connection from trimmed edges to not trimmed ones |
7029 | //======================================================================= |
7030 | void UpdateIntersectedEdges(const TopTools_ListOfShape& theLA, |
7031 | TopTools_DataMapOfShapeShape& theETrimEInf, |
7032 | BOPAlgo_Builder& theGF) |
7033 | { |
7034 | TopTools_ListIteratorOfListOfShape aItA(theLA); |
7035 | for (; aItA.More(); aItA.Next()) { |
7036 | const TopoDS_Shape& aS = aItA.Value(); |
7037 | // |
7038 | const TopoDS_Shape* pEInf = theETrimEInf.Seek(aS); |
7039 | if (!pEInf) { |
7040 | continue; |
7041 | } |
7042 | // |
7043 | const TopTools_ListOfShape& aLSIm = theGF.Modified(aS); |
7044 | if (aLSIm.IsEmpty()) { |
7045 | continue; |
7046 | } |
7047 | // |
7048 | TopTools_ListIteratorOfListOfShape aIt(aLSIm); |
7049 | for (; aIt.More(); aIt.Next()) { |
7050 | const TopoDS_Shape& aEIm = aIt.Value(); |
7051 | if (!theETrimEInf.IsBound(aEIm)) { |
7052 | theETrimEInf.Bind(aEIm, *pEInf); |
7053 | } |
7054 | } |
7055 | } |
7056 | } |
7057 | |
7058 | //======================================================================= |
7059 | //function : FindCommonParts |
7060 | //purpose : Looking for the parts of type <theType> contained in both lists |
7061 | //======================================================================= |
7062 | void FindCommonParts(const TopTools_ListOfShape& theLS1, |
7063 | const TopTools_ListOfShape& theLS2, |
7064 | TopTools_ListOfShape& theLSC, |
7065 | const TopAbs_ShapeEnum theType) |
7066 | { |
7067 | // map shapes in the first list |
7068 | TopTools_IndexedMapOfShape aMS1; |
7069 | TopTools_ListIteratorOfListOfShape aIt(theLS1); |
7070 | for (; aIt.More(); aIt.Next()) { |
7071 | const TopoDS_Shape& aS = aIt.Value(); |
7072 | TopExp::MapShapes(aS, theType, aMS1); |
7073 | } |
7074 | // |
7075 | if (aMS1.IsEmpty()) { |
7076 | return; |
7077 | } |
7078 | // |
7079 | TopTools_MapOfShape aMFence; |
7080 | // check for such shapes in the other list |
7081 | aIt.Initialize(theLS2); |
7082 | for (; aIt.More(); aIt.Next()) { |
7083 | const TopoDS_Shape& aS = aIt.Value(); |
7084 | // |
7085 | TopExp_Explorer aExp(aS, theType); |
7086 | for(; aExp.More(); aExp.Next()) { |
7087 | const TopoDS_Shape& aST = aExp.Current(); |
7088 | // |
7089 | if (aMS1.Contains(aST) && aMFence.Add(aST)) { |
7090 | theLSC.Append(aST); |
7091 | } |
7092 | } |
7093 | } |
7094 | } |
7095 | |
7096 | //======================================================================= |
7097 | //function : NbPoints |
7098 | //purpose : Defines number of sample points to get average direction of the edge |
7099 | //======================================================================= |
7100 | Standard_Integer NbPoints(const TopoDS_Edge& theEdge) |
7101 | { |
7102 | Standard_Integer aNbP; |
7103 | BRepAdaptor_Curve aBAC(theEdge); |
7104 | switch (aBAC.GetType()) { |
7105 | case GeomAbs_Line: |
7106 | aNbP = 1; |
7107 | break; |
7108 | default: |
7109 | aNbP = 11; |
7110 | } |
7111 | // |
7112 | return aNbP; |
7113 | } |
7114 | |
7115 | //======================================================================= |
7116 | //function : FindShape |
7117 | //purpose : Looking for the same sub-shape in the shape |
7118 | //======================================================================= |
7119 | Standard_Boolean FindShape(const TopoDS_Shape& theSWhat, |
7120 | const TopoDS_Shape& theSWhere, |
7121 | TopoDS_Shape& theRes) |
7122 | { |
7123 | Standard_Boolean bFound = Standard_False; |
7124 | TopAbs_ShapeEnum aType = theSWhat.ShapeType(); |
7125 | TopExp_Explorer aExp(theSWhere, aType); |
7126 | for (; aExp.More(); aExp.Next()) { |
7127 | const TopoDS_Shape& aS = aExp.Current(); |
7128 | if (aS.IsSame(theSWhat)) { |
7129 | theRes = aS; |
7130 | bFound = Standard_True; |
7131 | break; |
7132 | } |
7133 | } |
7134 | return bFound; |
7135 | } |
7136 | |
7137 | |
7138 | //======================================================================= |
7139 | //function : AppendToList |
7140 | //purpose : Add to a list only unique elements |
7141 | //======================================================================= |
7142 | void AppendToList(TopTools_ListOfShape& theList, |
7143 | const TopoDS_Shape& theShape) |
7144 | { |
7145 | TopTools_ListIteratorOfListOfShape aIt(theList); |
7146 | for (; aIt.More(); aIt.Next()) { |
7147 | const TopoDS_Shape& aS = aIt.Value(); |
7148 | if (aS.IsSame(theShape)) { |
7149 | return; |
7150 | } |
7151 | } |
7152 | theList.Append(theShape); |
7153 | } |
e08a9b03 |
7154 | |
7155 | //======================================================================= |
7156 | //function : AddToContainer |
7157 | //purpose : Set of methods to add a shape into container |
7158 | //======================================================================= |
7159 | static void AddToContainer(const TopoDS_Shape& theS, |
7160 | TopTools_ListOfShape& theList) |
7161 | { |
7162 | theList.Append(theS); |
7163 | } |
7164 | static Standard_Boolean AddToContainer(const TopoDS_Shape& theS, |
7165 | TopTools_MapOfShape& theMap) |
7166 | { |
7167 | return theMap.Add(theS); |
7168 | } |
7169 | static Standard_Boolean AddToContainer(const TopoDS_Shape& theS, |
7170 | TopTools_IndexedMapOfShape& theMap) |
7171 | { |
7172 | const Standard_Integer aNb = theMap.Extent(); |
7173 | const Standard_Integer anInd = theMap.Add(theS); |
7174 | return anInd > aNb; |
7175 | } |
7176 | static void AddToContainer(const TopoDS_Shape& theS, |
7177 | TopoDS_Shape& theSOut) |
7178 | { |
7179 | BRep_Builder().Add(theSOut, theS); |
7180 | } |
7181 | |
7182 | //======================================================================= |
7183 | //function : TakeModified |
7184 | //purpose : Check if the shape has images in the given images map. |
7185 | // Puts in the output map either the images or the shape itself. |
7186 | //======================================================================= |
7187 | template <class ContainerType, class FenceMapType> |
7188 | Standard_Boolean TakeModified(const TopoDS_Shape& theS, |
7189 | const TopTools_DataMapOfShapeListOfShape& theImages, |
7190 | ContainerType& theContainer, |
7191 | FenceMapType* theMFence) |
7192 | { |
7193 | const TopTools_ListOfShape *pLSIm = theImages.Seek(theS); |
7194 | if (pLSIm) |
7195 | { |
7196 | TopTools_ListIteratorOfListOfShape itLSIm(*pLSIm); |
7197 | for (; itLSIm.More(); itLSIm.Next()) |
7198 | { |
7199 | const TopoDS_Shape& aSIm = itLSIm.Value(); |
7200 | if (!theMFence || AddToContainer(aSIm, *theMFence)) |
7201 | AddToContainer(aSIm, theContainer); |
7202 | } |
7203 | return Standard_True; |
7204 | } |
7205 | else |
7206 | { |
7207 | if (!theMFence || AddToContainer(theS, *theMFence)) |
7208 | AddToContainer(theS, theContainer); |
7209 | return Standard_False; |
7210 | } |
7211 | } |