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