4e57c75e |
1 | // Created by: Peter KURNEV |
973c2be1 |
2 | // Copyright (c) 2010-2014 OPEN CASCADE SAS |
4e57c75e |
3 | // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE |
4 | // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, |
5 | // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS |
6 | // |
973c2be1 |
7 | // This file is part of Open CASCADE Technology software library. |
4e57c75e |
8 | // |
d5f74e42 |
9 | // This library is free software; you can redistribute it and/or modify it under |
10 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
11 | // by the Free Software Foundation, with special exception defined in the file |
12 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
13 | // distribution for complete text of the license and disclaimer of any warranty. |
4e57c75e |
14 | // |
973c2be1 |
15 | // Alternatively, this file may be used under the terms of Open CASCADE |
16 | // commercial license or contractual agreement. |
4e57c75e |
17 | |
18 | #include <BOPAlgo_Builder.hxx> |
a0a3f6ac |
19 | // |
4e57c75e |
20 | #include <NCollection_IncAllocator.hxx> |
db8e4b9a |
21 | #include <NCollection_UBTreeFiller.hxx> |
a0a3f6ac |
22 | // |
db8e4b9a |
23 | #include <Bnd_Box.hxx> |
4e57c75e |
24 | #include <TopAbs_State.hxx> |
a0a3f6ac |
25 | // |
4e57c75e |
26 | #include <TopoDS.hxx> |
27 | #include <TopoDS_Iterator.hxx> |
28 | #include <TopoDS_Solid.hxx> |
29 | #include <TopoDS_Shape.hxx> |
30 | #include <TopoDS_Face.hxx> |
744511c8 |
31 | #include <TopoDS_Edge.hxx> |
4e57c75e |
32 | #include <TopoDS_Solid.hxx> |
33 | #include <TopoDS_Iterator.hxx> |
34 | #include <TopoDS_Shell.hxx> |
35 | #include <TopoDS_Compound.hxx> |
a0a3f6ac |
36 | // |
4e57c75e |
37 | #include <TopExp.hxx> |
38 | #include <TopExp_Explorer.hxx> |
a0a3f6ac |
39 | // |
4e57c75e |
40 | #include <BRep_Builder.hxx> |
41 | #include <BRepTools.hxx> |
42 | #include <BRepClass3d_SolidClassifier.hxx> |
db8e4b9a |
43 | #include <BRepBndLib.hxx> |
4e57c75e |
44 | // |
45 | #include <BOPCol_IndexedMapOfShape.hxx> |
46 | #include <BOPCol_MapOfShape.hxx> |
47 | #include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx> |
48 | #include <BOPCol_ListOfShape.hxx> |
db8e4b9a |
49 | #include <BOPCol_BoxBndTree.hxx> |
50 | #include <BOPCol_ListOfInteger.hxx> |
51 | #include <BOPCol_DataMapOfIntegerShape.hxx> |
a0a3f6ac |
52 | #include <BOPCol_NCVector.hxx> |
53 | #include <BOPCol_TBB.hxx> |
db8e4b9a |
54 | // |
1e143abb |
55 | #include <IntTools_Context.hxx> |
4e57c75e |
56 | // |
57 | #include <BOPDS_DS.hxx> |
58 | #include <BOPDS_ShapeInfo.hxx> |
59 | // |
60 | #include <BOPTools.hxx> |
61 | #include <BOPTools_AlgoTools.hxx> |
4e57c75e |
62 | #include <BOPTools_MapOfSet.hxx> |
63 | #include <BOPTools_Set.hxx> |
64 | // |
65 | #include <BOPAlgo_BuilderSolid.hxx> |
744511c8 |
66 | |
67 | |
4e57c75e |
68 | static |
69 | void OwnInternalShapes(const TopoDS_Shape& , |
70 | BOPCol_IndexedMapOfShape& ); |
71 | |
c884a268 |
72 | static |
73 | void TreatCompound(const TopoDS_Shape& theS, |
74 | BOPCol_MapOfShape& aMFence, |
75 | BOPCol_ListOfShape& theLS); |
76 | |
a0a3f6ac |
77 | //======================================================================= |
78 | // BOPAlgo_BuilderSolid |
79 | // |
80 | typedef BOPCol_NCVector |
81 | <BOPAlgo_BuilderSolid> BOPAlgo_VectorOfBuilderSolid; |
82 | // |
83 | typedef BOPCol_TBBFunctor |
84 | <BOPAlgo_BuilderSolid, |
85 | BOPAlgo_VectorOfBuilderSolid> BOPAlgo_BuilderSolidFunctor; |
86 | // |
87 | typedef BOPCol_TBBCnt |
88 | <BOPAlgo_BuilderSolidFunctor, |
89 | BOPAlgo_VectorOfBuilderSolid> BOPAlgo_BuilderSolidCnt; |
90 | // |
744511c8 |
91 | //======================================================================= |
92 | //class : BOPAlgo_ShapeBox |
93 | //purpose : Auxiliary class |
94 | //======================================================================= |
95 | class BOPAlgo_ShapeBox { |
96 | public: |
97 | BOPAlgo_ShapeBox() { |
98 | }; |
99 | // |
100 | ~BOPAlgo_ShapeBox() { |
101 | }; |
102 | // |
103 | void SetShape(const TopoDS_Shape& aS) { |
104 | myShape=aS; |
105 | }; |
106 | // |
107 | const TopoDS_Shape& Shape()const { |
108 | return myShape; |
109 | }; |
110 | // |
111 | void SetBox(const Bnd_Box& aBox) { |
112 | myBox=aBox; |
113 | }; |
114 | // |
115 | const Bnd_Box& Box()const { |
116 | return myBox; |
117 | }; |
118 | // |
119 | protected: |
120 | TopoDS_Shape myShape; |
121 | Bnd_Box myBox; |
122 | }; |
123 | // |
124 | typedef NCollection_DataMap\ |
125 | <Standard_Integer, BOPAlgo_ShapeBox, TColStd_MapIntegerHasher> \ |
126 | BOPAlgo_DataMapOfIntegerShapeBox; |
127 | // |
128 | typedef BOPAlgo_DataMapOfIntegerShapeBox::Iterator \ |
129 | BOPAlgo_DataMapIteratorOfDataMapOfIntegerShapeBox; |
130 | // |
131 | |
4e57c75e |
132 | //======================================================================= |
133 | //function : FillImagesSolids |
134 | //purpose : |
135 | //======================================================================= |
744511c8 |
136 | void BOPAlgo_Builder::FillImagesSolids() |
4e57c75e |
137 | { |
744511c8 |
138 | Standard_Boolean bHasSolids; |
139 | Standard_Integer i, aNbS; |
140 | // |
4e57c75e |
141 | myErrorStatus=0; |
142 | // |
744511c8 |
143 | bHasSolids=Standard_False; |
144 | aNbS=myDS->NbSourceShapes(); |
145 | for (i=0; i<aNbS; ++i) { |
146 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
147 | if (aSI.ShapeType()==TopAbs_SOLID) { |
148 | bHasSolids=!bHasSolids; |
149 | break; |
150 | } |
151 | } |
152 | // |
153 | if (!bHasSolids) { |
154 | return; |
155 | } |
156 | // |
157 | Handle(NCollection_IncAllocator) aAlr; |
4e57c75e |
158 | // |
744511c8 |
159 | aAlr=new NCollection_IncAllocator(); |
744511c8 |
160 | BOPCol_DataMapOfShapeListOfShape theInParts(100, aAlr); |
161 | BOPCol_DataMapOfShapeShape theDraftSolids(100, aAlr); |
162 | // |
30ecd5f8 |
163 | FillIn3DParts(theInParts, theDraftSolids, aAlr); |
744511c8 |
164 | BuildSplitSolids(theInParts, theDraftSolids, aAlr); |
4e57c75e |
165 | FillInternalShapes(); |
166 | // |
167 | theInParts.Clear(); |
168 | theDraftSolids.Clear(); |
4e57c75e |
169 | } |
170 | //======================================================================= |
171 | //function : FillIn3DParts |
172 | //purpose : |
173 | //======================================================================= |
a0a3f6ac |
174 | void BOPAlgo_Builder::FillIn3DParts |
175 | (BOPCol_DataMapOfShapeListOfShape& theInParts, |
176 | BOPCol_DataMapOfShapeShape& theDraftSolids, |
177 | const BOPCol_BaseAllocator& ) |
4e57c75e |
178 | { |
744511c8 |
179 | Standard_Boolean bHasImage; |
180 | Standard_Integer i, k, aNbS, aNbLIF, nFP, aNbFP, aNbFIN, iIsIN; |
181 | TopoDS_Solid aSD; |
182 | TopoDS_Iterator aIt; |
183 | BRep_Builder aBB; |
184 | BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1; |
185 | BOPCol_ListIteratorOfListOfShape aItLS; |
186 | BOPAlgo_ShapeBox aSB; |
187 | Handle(NCollection_IncAllocator) aAlr0; |
4e57c75e |
188 | // |
744511c8 |
189 | aAlr0=new NCollection_IncAllocator(); |
190 | BOPAlgo_DataMapOfIntegerShapeBox aDMISB(100, aAlr0); |
191 | BOPAlgo_DataMapIteratorOfDataMapOfIntegerShapeBox aItDMISB; |
4e57c75e |
192 | // |
744511c8 |
193 | myErrorStatus=0; |
4e57c75e |
194 | theDraftSolids.Clear(); |
195 | // |
30ecd5f8 |
196 | // 1. aDMISB map Index/FaceBox |
744511c8 |
197 | k=0; |
4e57c75e |
198 | aNbS=myDS->NbSourceShapes(); |
199 | for (i=0; i<aNbS; ++i) { |
200 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
744511c8 |
201 | if (aSI.ShapeType()!=TopAbs_FACE) { |
202 | continue; |
203 | } |
204 | // |
4e57c75e |
205 | const TopoDS_Shape& aS=aSI.Shape(); |
206 | // |
744511c8 |
207 | if (myImages.IsBound(aS)) { |
208 | const BOPCol_ListOfShape& aLS=myImages.Find(aS); |
209 | aItLS.Initialize(aLS); |
210 | for (; aItLS.More(); aItLS.Next()) { |
a0a3f6ac |
211 | const TopoDS_Shape& aSx=aItLS.Value(); |
212 | // |
213 | Bnd_Box aBox; |
214 | BRepBndLib::Add(aSx, aBox); |
215 | // |
216 | aSB.SetShape(aSx); |
217 | aSB.SetBox(aBox); |
218 | // |
219 | aDMISB.Bind(k, aSB); |
220 | ++k; |
4e57c75e |
221 | } |
744511c8 |
222 | } |
223 | else { |
224 | const Bnd_Box& aBox=aSI.Box(); |
4e57c75e |
225 | // |
744511c8 |
226 | aSB.SetShape(aS); |
227 | aSB.SetBox(aBox); |
4e57c75e |
228 | // |
744511c8 |
229 | aDMISB.Bind(k, aSB); |
230 | ++k; |
4e57c75e |
231 | } |
744511c8 |
232 | }//for (i=0; i<aNbS; ++i) { |
4e57c75e |
233 | // |
30ecd5f8 |
234 | // 1.2. Prepare TreeFiller |
db8e4b9a |
235 | BOPCol_BoxBndTree aBBTree; |
30ecd5f8 |
236 | NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree); |
237 | // |
238 | aItDMISB.Initialize(aDMISB); |
239 | for (; aItDMISB.More(); aItDMISB.Next()) { |
240 | k=aItDMISB.Key(); |
241 | const BOPAlgo_ShapeBox& aSBk=aItDMISB.Value(); |
242 | const Bnd_Box& aBk=aSBk.Box(); |
243 | // |
244 | aTreeFiller.Add(k, aBk); |
245 | } |
246 | // |
247 | // 1.3. Shake TreeFiller |
248 | aTreeFiller.Fill(); |
249 | // |
250 | //--------------------------------------------- |
744511c8 |
251 | // 2. Solids |
252 | for (i=0; i<aNbS; ++i) { |
253 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
254 | if (aSI.ShapeType()!=TopAbs_SOLID) { |
255 | continue; |
256 | } |
257 | // |
258 | //--------------------------------------------- |
259 | Handle(NCollection_IncAllocator) aAlr1; |
72e88cf7 |
260 | // |
744511c8 |
261 | aAlr1=new NCollection_IncAllocator(); |
4e57c75e |
262 | // |
744511c8 |
263 | BOPCol_ListOfShape aLFIN(aAlr1); |
264 | BOPCol_ListOfShape aLIF(aAlr1); |
265 | BOPCol_IndexedMapOfShape aMF(100, aAlr1); |
266 | BOPCol_IndexedDataMapOfShapeListOfShape aMEF(100, aAlr1); |
db8e4b9a |
267 | BOPCol_BoxBndTreeSelector aSelector; |
744511c8 |
268 | Bnd_Box aBoxS; |
72e88cf7 |
269 | // |
744511c8 |
270 | const TopoDS_Shape& aS=aSI.Shape(); |
271 | const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS)); |
4e57c75e |
272 | // |
744511c8 |
273 | // 2.0 Flag bHasImage |
4e57c75e |
274 | bHasImage=Standard_False; |
744511c8 |
275 | aIt.Initialize(aS); |
4e57c75e |
276 | for (; aIt.More(); aIt.Next()) { |
277 | const TopoDS_Shape& aShell=aIt.Value(); |
744511c8 |
278 | bHasImage=myImages.IsBound(aShell); |
279 | if (bHasImage){ |
a0a3f6ac |
280 | break; |
4e57c75e |
281 | } |
282 | } |
283 | // |
30ecd5f8 |
284 | // 2.1 Bounding box for the solid aS [ aBoxS ] |
285 | aBoxS=aSI.Box(); |
744511c8 |
286 | //----- |
4e57c75e |
287 | // |
744511c8 |
288 | // 2.2 Build Draft Solid [aSD] |
289 | aBB.MakeSolid(aSD); |
4e57c75e |
290 | // |
744511c8 |
291 | BuildDraftSolid(aSolid, aSD, aLIF); |
292 | aNbLIF=aLIF.Extent(); |
293 | // |
294 | BOPTools::MapShapesAndAncestors(aSD, TopAbs_EDGE, TopAbs_FACE, aMEF); |
295 | // |
296 | // 2.3 Faces from aSD and own internal faces => aMF |
297 | BOPTools::MapShapes(aSD, TopAbs_FACE, aMF); |
298 | // |
299 | aItLS.Initialize(aLIF); |
300 | for (; aItLS.More(); aItLS.Next()) { |
301 | const TopoDS_Shape& aFI=aItLS.Value(); |
302 | aMF.Add(aFI); |
4e57c75e |
303 | } |
304 | // |
30ecd5f8 |
305 | // 2.4. Select boxes of faces that are not out of aBoxS |
744511c8 |
306 | aSelector.Clear(); |
307 | aSelector.SetBox(aBoxS); |
308 | // |
309 | aNbFP=aBBTree.Select(aSelector); |
4e57c75e |
310 | // |
744511c8 |
311 | const BOPCol_ListOfInteger& aLIFP=aSelector.Indices(); |
312 | // |
30ecd5f8 |
313 | // 2.5. Collect faces that are IN aSolid [ aLFIN ] |
744511c8 |
314 | BOPCol_ListOfShape aLFP(aAlr1); |
315 | BOPCol_ListOfShape aLCBF(aAlr1); |
316 | BOPCol_MapOfShape aMFDone(100, aAlr1); |
317 | BOPCol_IndexedMapOfShape aME(100, aAlr1); |
318 | // |
319 | BOPTools::MapShapes(aSD, TopAbs_EDGE, aME); |
320 | // |
321 | aItLI.Initialize(aLIFP); |
322 | for (; aItLI.More(); aItLI.Next()) { |
323 | nFP=aItLI.Value(); |
324 | const BOPAlgo_ShapeBox& aSBF=aDMISB.Find(nFP); |
325 | const TopoDS_Face& aFP=(*(TopoDS_Face*)&aSBF.Shape()); |
30ecd5f8 |
326 | if (aMF.Contains(aFP)) { |
a0a3f6ac |
327 | continue; |
30ecd5f8 |
328 | } |
744511c8 |
329 | if (aMFDone.Contains(aFP)) { |
a0a3f6ac |
330 | continue; |
4e57c75e |
331 | } |
4e57c75e |
332 | // |
744511c8 |
333 | aMFDone.Add(aFP); |
334 | // |
335 | iIsIN=BOPTools_AlgoTools::IsInternalFace(aFP, aSD, aMEF, 1.e-14, myContext); |
4e57c75e |
336 | // |
4e57c75e |
337 | aLFP.Clear(); |
338 | aLFP.Append(aFP); |
744511c8 |
339 | // |
340 | aItLI1.Initialize(aLIFP); |
341 | for (; aItLI1.More(); aItLI1.Next()) { |
a0a3f6ac |
342 | const TopoDS_Shape& aFx=aDMISB.Find(aItLI1.Value()).Shape(); |
343 | if (!aMFDone.Contains(aFx)) { |
344 | aLFP.Append(aFx); |
345 | } |
4e57c75e |
346 | } |
347 | // |
4e57c75e |
348 | aLCBF.Clear(); |
744511c8 |
349 | //---------------------------------------- |
72e88cf7 |
350 | { |
a0a3f6ac |
351 | Handle(NCollection_IncAllocator) aAlr2; |
352 | aAlr2=new NCollection_IncAllocator(); |
353 | // |
354 | BOPTools_AlgoTools::MakeConnexityBlock(aLFP, aME, aLCBF, aAlr2); |
72e88cf7 |
355 | } |
744511c8 |
356 | //---------------------------------------- |
357 | aItLS.Initialize(aLCBF); |
358 | for (; aItLS.More(); aItLS.Next()) { |
359 | const TopoDS_Shape& aFx=aItLS.Value(); |
360 | aMFDone.Add(aFx); |
361 | if (iIsIN) { |
362 | aLFIN.Append(aFx); |
4e57c75e |
363 | } |
364 | } |
744511c8 |
365 | }// for (; aItLI.More(); aItLI.Next()) { |
4e57c75e |
366 | // |
30ecd5f8 |
367 | // 2.6. Store the results in theInParts, theDraftSolids |
744511c8 |
368 | aNbFIN=aLFIN.Extent(); |
4e57c75e |
369 | if (aNbFIN || aNbLIF) { |
744511c8 |
370 | aItLS.Initialize(aLIF); |
371 | for (; aItLS.More(); aItLS.Next()) { |
a0a3f6ac |
372 | const TopoDS_Shape& aFI=aItLS.Value(); |
373 | aLFIN.Append(aFI); |
4e57c75e |
374 | } |
4e57c75e |
375 | theInParts.Bind(aSolid, aLFIN); |
376 | } |
744511c8 |
377 | // |
4e57c75e |
378 | if (aNbFIN || bHasImage) { |
744511c8 |
379 | theDraftSolids.Bind(aSolid, aSD); |
4e57c75e |
380 | } |
744511c8 |
381 | //--------------------------------------------- |
382 | }// for (i=0; i<aNbS; ++i) { |
4e57c75e |
383 | } |
384 | //======================================================================= |
385 | //function : BuildDraftSolid |
386 | //purpose : |
387 | //======================================================================= |
744511c8 |
388 | void BOPAlgo_Builder::BuildDraftSolid(const TopoDS_Shape& theSolid, |
a0a3f6ac |
389 | TopoDS_Shape& theDraftSolid, |
390 | BOPCol_ListOfShape& theLIF) |
4e57c75e |
391 | { |
392 | myErrorStatus=0; |
393 | // |
394 | Standard_Boolean bToReverse; |
395 | Standard_Integer iFlag; |
396 | TopAbs_Orientation aOrF, aOrSh, aOrSd; |
397 | TopoDS_Iterator aIt1, aIt2; |
398 | TopoDS_Shell aShD; |
399 | TopoDS_Shape aFSDx, aFx; |
400 | BRep_Builder aBB; |
a0a3f6ac |
401 | BOPCol_ListIteratorOfListOfShape aItS; |
4e57c75e |
402 | // |
403 | aOrSd=theSolid.Orientation(); |
404 | theDraftSolid.Orientation(aOrSd); |
405 | // |
406 | aIt1.Initialize(theSolid); |
407 | for (; aIt1.More(); aIt1.Next()) { |
408 | const TopoDS_Shape& aSh=aIt1.Value(); |
409 | if(aSh.ShapeType()!=TopAbs_SHELL) { |
410 | continue; // mb internal edges,vertices |
411 | } |
412 | // |
413 | aOrSh=aSh.Orientation(); |
414 | aBB.MakeShell(aShD); |
415 | aShD.Orientation(aOrSh); |
416 | iFlag=0; |
417 | // |
418 | aIt2.Initialize(aSh); |
419 | for (; aIt2.More(); aIt2.Next()) { |
420 | const TopoDS_Shape& aF=aIt2.Value(); |
421 | aOrF=aF.Orientation(); |
422 | // |
423 | if (myImages.IsBound(aF)) { |
424 | const BOPCol_ListOfShape& aLSp=myImages.Find(aF); |
425 | aItS.Initialize(aLSp); |
426 | for (; aItS.More(); aItS.Next()) { |
427 | aFx=aItS.Value(); |
428 | // |
429 | if (myShapesSD.IsBound(aFx)) { |
430 | aFSDx=myShapesSD.Find(aFx); |
431 | // |
432 | if (aOrF==TopAbs_INTERNAL) { |
433 | aFSDx.Orientation(aOrF); |
434 | theLIF.Append(aFSDx); |
435 | } |
436 | else { |
1e143abb |
437 | bToReverse=BOPTools_AlgoTools::IsSplitToReverse |
438 | (aFSDx, aF, myContext); |
4e57c75e |
439 | if (bToReverse) { |
440 | aFSDx.Reverse(); |
441 | } |
442 | // |
443 | iFlag=1; |
444 | aBB.Add(aShD, aFSDx); |
445 | } |
446 | }//if (myShapesSD.IsBound(aFx)) { |
447 | else { |
448 | aFx.Orientation(aOrF); |
449 | if (aOrF==TopAbs_INTERNAL) { |
450 | theLIF.Append(aFx); |
451 | } |
452 | else{ |
453 | iFlag=1; |
454 | aBB.Add(aShD, aFx); |
455 | } |
456 | } |
457 | } |
458 | } // if (myImages.IsBound(aF)) { |
459 | // |
460 | else { |
461 | if (aOrF==TopAbs_INTERNAL) { |
462 | theLIF.Append(aF); |
463 | } |
464 | else{ |
465 | iFlag=1; |
466 | aBB.Add(aShD, aF); |
467 | } |
468 | } |
469 | } //for (; aIt2.More(); aIt2.Next()) { |
470 | // |
471 | if (iFlag) { |
472 | aBB.Add(theDraftSolid, aShD); |
473 | } |
474 | } //for (; aIt1.More(); aIt1.Next()) { |
475 | } |
476 | //======================================================================= |
477 | //function : BuildSplitSolids |
478 | //purpose : |
479 | //======================================================================= |
a0a3f6ac |
480 | void BOPAlgo_Builder::BuildSplitSolids |
481 | (BOPCol_DataMapOfShapeListOfShape& theInParts, |
482 | BOPCol_DataMapOfShapeShape& theDraftSolids, |
483 | const BOPCol_BaseAllocator& ) |
4e57c75e |
484 | { |
485 | myErrorStatus=0; |
486 | // |
487 | Standard_Boolean bFlagSD; |
96a95605 |
488 | Standard_Integer i, aNbS; |
4e57c75e |
489 | TopExp_Explorer aExp; |
490 | BOPCol_ListIteratorOfListOfShape aIt; |
491 | BOPCol_DataMapIteratorOfDataMapOfShapeShape aIt1; |
492 | // |
744511c8 |
493 | Handle(NCollection_IncAllocator) aAlr0; |
494 | aAlr0=new NCollection_IncAllocator(); |
495 | // |
496 | BOPCol_ListOfShape aSFS(aAlr0), aLSEmpty(aAlr0); |
497 | BOPCol_MapOfShape aMFence(100, aAlr0); |
498 | BOPTools_MapOfSet aMST(100, aAlr0); |
30ecd5f8 |
499 | BOPAlgo_VectorOfBuilderSolid aVBS; |
4e57c75e |
500 | // |
501 | // 0. Find same domain solids for non-interferred solids |
502 | aNbS=myDS->NbSourceShapes(); |
503 | for (i=0; i<aNbS; ++i) { |
504 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
505 | // |
506 | if (aSI.ShapeType()!=TopAbs_SOLID) { |
507 | continue; |
508 | } |
509 | // |
510 | const TopoDS_Shape& aS=aSI.Shape(); |
511 | if (!aMFence.Add(aS)) { |
512 | continue; |
513 | } |
514 | if(theDraftSolids.IsBound(aS)) { |
515 | continue; |
516 | } |
517 | // |
518 | BOPTools_Set aST; |
519 | // |
520 | aST.Add(aS, TopAbs_FACE); |
521 | aMST.Add(aST); |
522 | // |
523 | } //for (i=1; i<=aNbS; ++i) |
524 | // |
525 | // 1. Build solids for interferred source solids |
526 | for (i=0; i<aNbS; ++i) { |
527 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
528 | // |
529 | if (aSI.ShapeType()!=TopAbs_SOLID) { |
530 | continue; |
531 | } |
532 | // |
533 | const TopoDS_Shape& aS=aSI.Shape(); |
30ecd5f8 |
534 | const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS)); |
4e57c75e |
535 | if(!theDraftSolids.IsBound(aS)) { |
536 | continue; |
537 | } |
538 | const TopoDS_Shape& aSD=theDraftSolids.Find(aS); |
539 | const BOPCol_ListOfShape& aLFIN= |
540 | (theInParts.IsBound(aS)) ? theInParts.Find(aS) : aLSEmpty; |
541 | // |
542 | // 1.1 Fill Shell Faces Set |
543 | aSFS.Clear(); |
544 | aExp.Init(aSD, TopAbs_FACE); |
545 | for (; aExp.More(); aExp.Next()) { |
546 | const TopoDS_Shape& aF=aExp.Current(); |
547 | aSFS.Append(aF); |
548 | } |
549 | // |
550 | aIt.Initialize(aLFIN); |
551 | for (; aIt.More(); aIt.Next()) { |
552 | TopoDS_Shape aF=aIt.Value(); |
553 | // |
554 | aF.Orientation(TopAbs_FORWARD); |
555 | aSFS.Append(aF); |
556 | aF.Orientation(TopAbs_REVERSED); |
557 | aSFS.Append(aF); |
558 | } |
559 | // |
744511c8 |
560 | // 1.3 Build new solids |
561 | Handle(NCollection_IncAllocator) aAlr1; |
562 | aAlr1=new NCollection_IncAllocator(); |
563 | // |
30ecd5f8 |
564 | BOPAlgo_BuilderSolid& aBS=aVBS.Append1(); |
565 | aBS.SetSolid(aSolid); |
566 | aBS.SetShapes(aSFS); |
567 | }//for (i=0; i<aNbS; ++i) { |
568 | // |
569 | Standard_Integer k, aNbBS; |
570 | // |
571 | aNbBS=aVBS.Extent(); |
572 | // |
573 | //=================================================== |
574 | BOPAlgo_BuilderSolidCnt::Perform(myRunParallel, aVBS); |
575 | //=================================================== |
576 | // |
577 | for (k=0; k<aNbBS; ++k) { |
578 | BOPAlgo_BuilderSolid& aBS=aVBS(k); |
579 | const TopoDS_Solid& aS=aBS.Solid(); |
580 | const BOPCol_ListOfShape& aLSR=aBS.Areas(); |
4e57c75e |
581 | // |
4e57c75e |
582 | if (!myImages.IsBound(aS)) { |
583 | BOPCol_ListOfShape aLSx; |
584 | // |
585 | myImages.Bind(aS, aLSx); |
586 | BOPCol_ListOfShape& aLSIm=myImages.ChangeFind(aS); |
587 | // |
588 | aIt.Initialize(aLSR); |
589 | for (; aIt.More(); aIt.Next()) { |
590 | BOPTools_Set aST; |
591 | // |
592 | const TopoDS_Shape& aSR=aIt.Value(); |
593 | aST.Add(aSR, TopAbs_FACE); |
594 | // |
595 | bFlagSD=aMST.Contains(aST); |
596 | // |
597 | const BOPTools_Set& aSTx=aMST.Added(aST); |
598 | const TopoDS_Shape& aSx=aSTx.Shape(); |
599 | aLSIm.Append(aSx); |
600 | // |
601 | if (bFlagSD) { |
602 | myShapesSD.Bind(aSR, aSx); |
603 | } |
604 | } |
605 | } |
30ecd5f8 |
606 | } |
4e57c75e |
607 | } |
4e57c75e |
608 | //======================================================================= |
609 | //function :FillInternalShapes |
610 | //purpose : |
611 | //======================================================================= |
744511c8 |
612 | void BOPAlgo_Builder::FillInternalShapes() |
4e57c75e |
613 | { |
614 | myErrorStatus=0; |
615 | // |
96a95605 |
616 | Standard_Integer i, j, aNbS, aNbSI, aNbSx; |
4e57c75e |
617 | TopAbs_ShapeEnum aType; |
618 | TopAbs_State aState; |
619 | TopoDS_Iterator aItS; |
620 | BRep_Builder aBB; |
621 | BOPCol_MapIteratorOfMapOfShape aItM; |
622 | BOPCol_ListIteratorOfListOfShape aIt, aIt1; |
623 | // |
624 | Handle(NCollection_IncAllocator) aAllocator; |
625 | //-----------------------------------------------------scope f |
626 | aAllocator=new NCollection_IncAllocator(); |
627 | // |
628 | BOPCol_IndexedDataMapOfShapeListOfShape aMSx(100, aAllocator); |
629 | BOPCol_IndexedMapOfShape aMx(100, aAllocator); |
630 | BOPCol_MapOfShape aMSI(100, aAllocator); |
631 | BOPCol_MapOfShape aMFence(100, aAllocator); |
632 | BOPCol_MapOfShape aMSOr(100, aAllocator); |
633 | BOPCol_ListOfShape aLSd(aAllocator); |
634 | BOPCol_ListOfShape aLArgs(aAllocator); |
c884a268 |
635 | BOPCol_ListOfShape aLSC(aAllocator); |
4e57c75e |
636 | // |
637 | // 1. Shapes to process |
638 | // |
639 | // 1.1 Shapes from pure arguments aMSI |
640 | // 1.1.1 vertex, edge, wire |
641 | // |
8620e18d |
642 | const BOPCol_ListOfShape& aArguments=myDS->Arguments(); |
643 | aIt.Initialize(aArguments); |
4e57c75e |
644 | for (; aIt.More(); aIt.Next()) { |
645 | const TopoDS_Shape& aS=aIt.Value(); |
c884a268 |
646 | TreatCompound(aS, aMFence, aLSC); |
647 | } |
648 | aIt.Initialize(aLSC); |
649 | for (; aIt.More(); aIt.Next()) { |
650 | const TopoDS_Shape& aS=aIt.Value(); |
4e57c75e |
651 | aType=aS.ShapeType(); |
652 | if (aType==TopAbs_WIRE) { |
653 | aItS.Initialize(aS); |
654 | for(; aItS.More(); aItS.Next()) { |
655 | const TopoDS_Shape& aE=aItS.Value(); |
656 | if (aMFence.Add(aE)) { |
657 | aLArgs.Append(aE); |
658 | } |
659 | } |
660 | } |
661 | else if (aType==TopAbs_VERTEX || aType==TopAbs_EDGE){ |
662 | aLArgs.Append(aS); |
663 | } |
664 | } |
665 | aMFence.Clear(); |
666 | // |
667 | aIt.Initialize(aLArgs); |
668 | for (; aIt.More(); aIt.Next()) { |
669 | const TopoDS_Shape& aS=aIt.Value(); |
670 | aType=aS.ShapeType(); |
a0a3f6ac |
671 | if (aType==TopAbs_VERTEX || |
672 | aType==TopAbs_EDGE || |
673 | aType==TopAbs_WIRE) { |
4e57c75e |
674 | if (aMFence.Add(aS)) { |
675 | if (myImages.IsBound(aS)) { |
676 | const BOPCol_ListOfShape &aLSp=myImages.Find(aS); |
677 | aIt1.Initialize(aLSp); |
678 | for (; aIt1.More(); aIt1.Next()) { |
679 | const TopoDS_Shape& aSp=aIt1.Value(); |
680 | aMSI.Add(aSp); |
681 | } |
682 | } |
683 | else { |
684 | aMSI.Add(aS); |
685 | } |
686 | } |
687 | } |
688 | } |
689 | |
690 | aNbSI=aMSI.Extent(); |
691 | // |
692 | // 2. Internal vertices, edges from source solids |
693 | aMFence.Clear(); |
694 | aLSd.Clear(); |
695 | // |
696 | aNbS=myDS->NbSourceShapes(); |
697 | for (i=0; i<aNbS; ++i) { |
698 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
699 | // |
700 | if (aSI.ShapeType()!=TopAbs_SOLID) { |
701 | continue; |
702 | } |
703 | // |
704 | const TopoDS_Shape& aS=aSI.Shape(); |
705 | // |
706 | aMx.Clear(); |
707 | OwnInternalShapes(aS, aMx); |
708 | // |
709 | aNbSx=aMx.Extent(); |
710 | for (j=1; j<=aNbSx; ++j) { |
711 | const TopoDS_Shape& aSi=aMx(j); |
712 | if (myImages.IsBound(aSi)) { |
713 | const BOPCol_ListOfShape &aLSp=myImages.Find(aSi); |
714 | aIt1.Initialize(aLSp); |
715 | for (; aIt1.More(); aIt1.Next()) { |
716 | const TopoDS_Shape& aSp=aIt1.Value(); |
717 | aMSI.Add(aSp); |
718 | } |
719 | } |
720 | else { |
721 | aMSI.Add(aSi); |
722 | } |
723 | } |
724 | // |
725 | // build aux map from splits of solids |
726 | if (myImages.IsBound(aS)) { |
727 | const BOPCol_ListOfShape &aLSp=myImages.Find(aS); |
728 | aIt.Initialize(aLSp); |
729 | for (; aIt.More(); aIt.Next()) { |
730 | const TopoDS_Shape& aSp=aIt.Value(); |
731 | if (aMFence.Add(aSp)) { |
732 | BOPTools::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_EDGE, aMSx); |
733 | BOPTools::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_FACE, aMSx); |
734 | BOPTools::MapShapesAndAncestors(aSp, TopAbs_EDGE , TopAbs_FACE, aMSx); |
735 | aLSd.Append(aSp); |
736 | } |
737 | } |
738 | } |
739 | else { |
740 | if (aMFence.Add(aS)) { |
741 | BOPTools::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_EDGE, aMSx); |
742 | BOPTools::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_FACE, aMSx); |
743 | BOPTools::MapShapesAndAncestors(aS, TopAbs_EDGE , TopAbs_FACE, aMSx); |
744 | aLSd.Append(aS); |
745 | aMSOr.Add(aS); |
746 | } |
747 | } |
748 | }// for (i=0; i<aNbS; ++i) { |
749 | // |
4e57c75e |
750 | // 3. Some shapes of aMSI can be already tied with faces of |
751 | // split solids |
752 | aItM.Initialize(aMSI); |
753 | for (; aItM.More(); aItM.Next()) { |
754 | const TopoDS_Shape& aSI=aItM.Key(); |
755 | if (aMSx.Contains(aSI)) { |
756 | const BOPCol_ListOfShape &aLSx=aMSx.FindFromKey(aSI); |
757 | aNbSx=aLSx.Extent(); |
758 | if (aNbSx) { |
759 | aMSI.Remove(aSI); |
760 | } |
761 | } |
762 | } |
763 | // |
764 | // 4. Just check it |
765 | aNbSI=aMSI.Extent(); |
766 | if (!aNbSI) { |
767 | return; |
768 | } |
769 | // |
770 | // 5 Settle internal vertices and edges into solids |
771 | aMx.Clear(); |
772 | aIt.Initialize(aLSd); |
773 | for (; aIt.More(); aIt.Next()) { |
774 | TopoDS_Solid aSd=TopoDS::Solid(aIt.Value()); |
775 | // |
776 | aItM.Initialize(aMSI); |
777 | for (; aItM.More(); aItM.Next()) { |
778 | TopoDS_Shape aSI=aItM.Key(); |
779 | aSI.Orientation(TopAbs_INTERNAL); |
780 | // |
781 | aState=BOPTools_AlgoTools::ComputeStateByOnePoint(aSI, aSd, 1.e-11, myContext); |
782 | if (aState==TopAbs_IN) { |
783 | // |
784 | if(aMSOr.Contains(aSd)) { |
785 | // |
786 | TopoDS_Solid aSdx; |
787 | // |
788 | aBB.MakeSolid(aSdx); |
789 | aItS.Initialize(aSd); |
790 | for (; aItS.More(); aItS.Next()) { |
791 | const TopoDS_Shape& aSh=aItS.Value(); |
792 | aBB.Add(aSdx, aSh); |
793 | } |
794 | // |
795 | aBB.Add(aSdx, aSI); |
796 | // |
797 | if (myImages.IsBound(aSdx)) { |
798 | BOPCol_ListOfShape& aLS=myImages.ChangeFind(aSdx); |
799 | aLS.Append(aSdx); |
800 | } |
801 | else { |
802 | BOPCol_ListOfShape aLS; |
803 | aLS.Append(aSdx); |
804 | myImages.Bind(aSd, aLS); |
805 | } |
806 | // |
807 | aMSOr.Remove(aSd); |
808 | aSd=aSdx; |
809 | } |
810 | else { |
811 | aBB.Add(aSd, aSI); |
812 | } |
813 | // |
814 | aMSI.Remove(aSI); |
815 | } //if (aState==TopAbs_IN) { |
816 | }// for (; aItM.More(); aItM.Next()) { |
817 | }//for (; aIt1.More(); aIt1.Next()) { |
818 | // |
819 | //-----------------------------------------------------scope t |
820 | aLArgs.Clear(); |
821 | aLSd.Clear(); |
822 | aMSOr.Clear(); |
823 | aMFence.Clear(); |
824 | aMSI.Clear(); |
825 | aMx.Clear(); |
826 | aMSx.Clear(); |
827 | } |
828 | //======================================================================= |
829 | //function : OwnInternalShapes |
830 | //purpose : |
831 | //======================================================================= |
a0a3f6ac |
832 | void OwnInternalShapes(const TopoDS_Shape& theS, |
833 | BOPCol_IndexedMapOfShape& theMx) |
4e57c75e |
834 | { |
835 | TopoDS_Iterator aIt; |
836 | // |
837 | aIt.Initialize(theS); |
838 | for (; aIt.More(); aIt.Next()) { |
839 | const TopoDS_Shape& aSx=aIt.Value(); |
840 | if (aSx.ShapeType()!=TopAbs_SHELL) { |
841 | theMx.Add(aSx); |
842 | } |
843 | } |
844 | } |
744511c8 |
845 | //======================================================================= |
c884a268 |
846 | //function : TreatCompound |
847 | //purpose : |
848 | //======================================================================= |
849 | void TreatCompound(const TopoDS_Shape& theS, |
850 | BOPCol_MapOfShape& aMFence, |
851 | BOPCol_ListOfShape& theLS) |
852 | { |
853 | TopAbs_ShapeEnum aType; |
854 | // |
855 | aType = theS.ShapeType(); |
856 | if (aType != TopAbs_COMPOUND) { |
857 | if (aMFence.Add(theS)) { |
858 | theLS.Append(theS); |
859 | } |
860 | return; |
861 | } |
862 | // |
863 | TopoDS_Iterator aIt; |
864 | // |
865 | aIt.Initialize(theS); |
866 | for (; aIt.More(); aIt.Next()) { |
867 | const TopoDS_Shape& aS = aIt.Value(); |
868 | TreatCompound(aS, aMFence, theLS); |
869 | } |
870 | } |
744511c8 |
871 | |
4e57c75e |
872 | // |
873 | // ErrorStatus |
874 | // 30 - SolidBuilder failed |
875 | // A |