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. |
465d1fba |
17 | // |
4e57c75e |
18 | #include <BOPAlgo_Builder.hxx> |
a0a3f6ac |
19 | // |
92ae0f2f |
20 | #include <Precision.hxx> |
21 | // |
db8e4b9a |
22 | #include <NCollection_UBTreeFiller.hxx> |
a0a3f6ac |
23 | // |
db8e4b9a |
24 | #include <Bnd_Box.hxx> |
4e57c75e |
25 | #include <TopAbs_State.hxx> |
a0a3f6ac |
26 | // |
4e57c75e |
27 | #include <TopoDS.hxx> |
28 | #include <TopoDS_Iterator.hxx> |
29 | #include <TopoDS_Solid.hxx> |
30 | #include <TopoDS_Shape.hxx> |
31 | #include <TopoDS_Face.hxx> |
744511c8 |
32 | #include <TopoDS_Edge.hxx> |
4e57c75e |
33 | #include <TopoDS_Solid.hxx> |
34 | #include <TopoDS_Iterator.hxx> |
35 | #include <TopoDS_Shell.hxx> |
36 | #include <TopoDS_Compound.hxx> |
a0a3f6ac |
37 | // |
4e57c75e |
38 | #include <TopExp.hxx> |
39 | #include <TopExp_Explorer.hxx> |
a0a3f6ac |
40 | // |
4e57c75e |
41 | #include <BRep_Builder.hxx> |
42 | #include <BRepTools.hxx> |
43 | #include <BRepClass3d_SolidClassifier.hxx> |
db8e4b9a |
44 | #include <BRepBndLib.hxx> |
4e57c75e |
45 | // |
46 | #include <BOPCol_IndexedMapOfShape.hxx> |
47 | #include <BOPCol_MapOfShape.hxx> |
48 | #include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx> |
49 | #include <BOPCol_ListOfShape.hxx> |
db8e4b9a |
50 | #include <BOPCol_BoxBndTree.hxx> |
51 | #include <BOPCol_ListOfInteger.hxx> |
52 | #include <BOPCol_DataMapOfIntegerShape.hxx> |
a0a3f6ac |
53 | #include <BOPCol_NCVector.hxx> |
c7b59798 |
54 | #include <BOPCol_Parallel.hxx> |
db8e4b9a |
55 | // |
1e143abb |
56 | #include <IntTools_Context.hxx> |
4e57c75e |
57 | // |
58 | #include <BOPDS_DS.hxx> |
59 | #include <BOPDS_ShapeInfo.hxx> |
60 | // |
61 | #include <BOPTools.hxx> |
62 | #include <BOPTools_AlgoTools.hxx> |
4e57c75e |
63 | #include <BOPTools_MapOfSet.hxx> |
64 | #include <BOPTools_Set.hxx> |
65 | // |
66 | #include <BOPAlgo_BuilderSolid.hxx> |
4691b61a |
67 | #include <NCollection_Array1.hxx> |
744511c8 |
68 | |
0644bfa4 |
69 | #include <algorithm> |
0090ae85 |
70 | #include <BOPAlgo_Algo.hxx> |
744511c8 |
71 | |
4e57c75e |
72 | static |
73 | void OwnInternalShapes(const TopoDS_Shape& , |
74 | BOPCol_IndexedMapOfShape& ); |
75 | |
c884a268 |
76 | static |
77 | void TreatCompound(const TopoDS_Shape& theS, |
78 | BOPCol_MapOfShape& aMFence, |
79 | BOPCol_ListOfShape& theLS); |
80 | |
a0a3f6ac |
81 | //======================================================================= |
82 | // BOPAlgo_BuilderSolid |
83 | // |
84 | typedef BOPCol_NCVector |
85 | <BOPAlgo_BuilderSolid> BOPAlgo_VectorOfBuilderSolid; |
86 | // |
c7b59798 |
87 | typedef BOPCol_Functor |
a0a3f6ac |
88 | <BOPAlgo_BuilderSolid, |
89 | BOPAlgo_VectorOfBuilderSolid> BOPAlgo_BuilderSolidFunctor; |
90 | // |
c7b59798 |
91 | typedef BOPCol_Cnt |
a0a3f6ac |
92 | <BOPAlgo_BuilderSolidFunctor, |
93 | BOPAlgo_VectorOfBuilderSolid> BOPAlgo_BuilderSolidCnt; |
94 | // |
744511c8 |
95 | //======================================================================= |
0090ae85 |
96 | // class: BOPAlgo_ShapeBox |
97 | // |
98 | //======================================================================= |
744511c8 |
99 | //class : BOPAlgo_ShapeBox |
100 | //purpose : Auxiliary class |
101 | //======================================================================= |
102 | class BOPAlgo_ShapeBox { |
103 | public: |
104 | BOPAlgo_ShapeBox() { |
105 | }; |
106 | // |
107 | ~BOPAlgo_ShapeBox() { |
108 | }; |
109 | // |
110 | void SetShape(const TopoDS_Shape& aS) { |
111 | myShape=aS; |
112 | }; |
113 | // |
114 | const TopoDS_Shape& Shape()const { |
115 | return myShape; |
116 | }; |
117 | // |
118 | void SetBox(const Bnd_Box& aBox) { |
119 | myBox=aBox; |
120 | }; |
121 | // |
122 | const Bnd_Box& Box()const { |
123 | return myBox; |
124 | }; |
125 | // |
126 | protected: |
127 | TopoDS_Shape myShape; |
128 | Bnd_Box myBox; |
129 | }; |
130 | // |
0090ae85 |
131 | typedef BOPCol_NCVector<BOPAlgo_ShapeBox> BOPAlgo_VectorOfShapeBox; |
132 | // |
133 | //======================================================================= |
134 | // class: BOPAlgo_FillIn3DParts |
744511c8 |
135 | // |
0090ae85 |
136 | //======================================================================= |
137 | //class : BOPAlgo_FillIn3DParts |
138 | //purpose : |
139 | //======================================================================= |
140 | class BOPAlgo_FillIn3DParts : public BOPAlgo_Algo { |
141 | public: |
142 | DEFINE_STANDARD_ALLOC |
143 | |
144 | BOPAlgo_FillIn3DParts(){ |
145 | myHasImage=Standard_False; |
146 | myBBTree=NULL; |
147 | myVSB=NULL; |
148 | }; |
149 | // |
150 | virtual ~BOPAlgo_FillIn3DParts(){ |
151 | }; |
152 | // |
153 | void SetSolid(const TopoDS_Solid& aS) { |
154 | mySolid=aS; |
155 | }; |
156 | // |
157 | const TopoDS_Solid& Solid()const { |
158 | return mySolid; |
159 | }; |
160 | // |
161 | void SetDraftSolid(const TopoDS_Solid& aS) { |
162 | myDraftSolid=aS; |
163 | }; |
164 | // |
165 | const TopoDS_Solid& DraftSolid()const { |
166 | return myDraftSolid; |
167 | }; |
168 | // |
169 | void SetHasImage(const Standard_Boolean bFlag) { |
170 | myHasImage=bFlag; |
171 | }; |
172 | // |
173 | Standard_Boolean HasImage()const { |
174 | return myHasImage; |
175 | }; |
176 | // |
177 | void SetBoxS(const Bnd_Box& aBox) { |
178 | myBoxS=aBox; |
179 | }; |
180 | // |
181 | const Bnd_Box& BoxS()const { |
182 | return myBoxS; |
183 | }; |
184 | // |
185 | void SetLIF(const BOPCol_ListOfShape& aLIF) { |
186 | myLIF=aLIF; |
187 | }; |
188 | // |
189 | const BOPCol_ListOfShape& LIF()const { |
190 | return myLIF; |
191 | }; |
192 | // |
193 | void SetBBTree(const BOPCol_BoxBndTree& aBBTree) { |
194 | myBBTree=(BOPCol_BoxBndTree*)&aBBTree; |
195 | }; |
196 | // |
197 | void SetVSB(const BOPAlgo_VectorOfShapeBox& aVSB) { |
198 | myVSB=(BOPAlgo_VectorOfShapeBox*)&aVSB; |
199 | }; |
200 | // |
201 | // |
202 | void SetContext(const Handle(IntTools_Context)& aContext) { |
203 | myContext=aContext; |
204 | } |
205 | // |
206 | const Handle(IntTools_Context)& Context()const { |
207 | return myContext; |
208 | } |
209 | // |
210 | virtual void Perform(); |
211 | // |
212 | |
213 | // |
214 | const BOPCol_ListOfShape& LFIN()const { |
215 | return myLFIN; |
216 | }; |
217 | |
218 | protected: |
219 | void MapEdgesAndFaces |
220 | (const TopoDS_Shape& , |
221 | BOPCol_IndexedDataMapOfShapeListOfShape& , |
222 | const Handle(NCollection_BaseAllocator)& ); |
223 | |
224 | void MakeConnexityBlock |
225 | (const BOPCol_ListOfShape& , |
226 | const BOPCol_IndexedMapOfShape& , |
227 | const BOPCol_MapOfShape& , |
228 | const BOPCol_IndexedDataMapOfShapeListOfShape& , |
229 | BOPCol_ListOfShape& , |
230 | const Handle(NCollection_BaseAllocator)& ); |
231 | // |
232 | protected: |
233 | TopoDS_Solid mySolid; |
234 | TopoDS_Solid myDraftSolid; |
235 | Standard_Boolean myHasImage; |
236 | Bnd_Box myBoxS; |
237 | BOPCol_ListOfShape myLIF; |
238 | BOPCol_ListOfShape myLFIN; |
239 | // |
240 | BOPCol_BoxBndTree* myBBTree; |
241 | BOPAlgo_VectorOfShapeBox* myVSB; |
242 | // |
243 | TopoDS_Iterator myItF; |
244 | TopoDS_Iterator myItW; |
245 | |
246 | Handle(IntTools_Context) myContext; |
247 | }; |
744511c8 |
248 | |
0090ae85 |
249 | //======================================================================= |
250 | //function : BOPAlgo_FillIn3DParts::Perform |
251 | //purpose : |
252 | //======================================================================= |
253 | void BOPAlgo_FillIn3DParts::Perform() |
254 | { |
488e5b9d |
255 | Handle(NCollection_BaseAllocator) aAlr1; |
0090ae85 |
256 | BOPAlgo_Algo::UserBreak(); |
257 | // |
258 | Standard_Integer aNbFP, k, nFP, iIsIN; |
259 | Standard_Real aTolPC; |
260 | BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1; |
261 | BOPCol_ListIteratorOfListOfShape aItLS; |
262 | BOPCol_BoxBndTreeSelector aSelector; |
263 | // |
488e5b9d |
264 | aAlr1= |
265 | NCollection_BaseAllocator::CommonBaseAllocator(); |
0090ae85 |
266 | // |
267 | BOPCol_ListOfShape aLFP(aAlr1); |
268 | BOPCol_ListOfShape aLCBF(aAlr1); |
269 | BOPCol_MapOfShape aMFDone(100, aAlr1); |
270 | BOPCol_IndexedMapOfShape aME(100, aAlr1); |
271 | BOPCol_IndexedMapOfShape aMF(100, aAlr1); |
272 | BOPCol_IndexedDataMapOfShapeListOfShape aMEFP(100, aAlr1); |
273 | BOPCol_IndexedDataMapOfShapeListOfShape aMEF(100, aAlr1); |
274 | // |
275 | aTolPC=Precision::Confusion(); |
276 | myLFIN.Clear(); |
277 | BOPAlgo_VectorOfShapeBox& aVSB=*myVSB; |
278 | // |
279 | // 1. aMEF - EF map for myDraftSolid |
280 | BOPTools::MapShapesAndAncestors(myDraftSolid, |
281 | TopAbs_EDGE, |
282 | TopAbs_FACE, |
283 | aMEF); |
284 | |
285 | // |
286 | // 2. Faces from myDraftSolid and its own internal faces => aMF |
287 | BOPTools::MapShapes(myDraftSolid, TopAbs_FACE, aMF); |
288 | aItLS.Initialize(myLIF); |
289 | for (; aItLS.More(); aItLS.Next()) { |
290 | const TopoDS_Shape& aFI=aItLS.Value(); |
291 | aMF.Add(aFI); |
292 | } |
293 | // aME - Edges from DraftSolid [i.e. edges to stop] |
294 | BOPTools::MapShapes(myDraftSolid, TopAbs_EDGE, aME); |
295 | // |
296 | // 3. Select boxes of faces that are not out of aBoxS |
297 | aSelector.Clear(); |
298 | aSelector.SetBox(myBoxS); |
299 | // |
300 | aNbFP=myBBTree->Select(aSelector); |
301 | const BOPCol_ListOfInteger& aLIFPx=aSelector.Indices(); |
302 | // |
303 | // 4. aIVec, aLIFP - faces to process |
304 | BOPCol_ListOfInteger aLIFP(aAlr1); |
305 | BOPCol_NCVector<Standard_Integer> aIVec(256, aAlr1); |
306 | // |
307 | k=0; |
308 | aItLI.Initialize(aLIFPx); |
309 | for (; aItLI.More(); aItLI.Next()) { |
310 | nFP=aItLI.Value(); |
311 | const TopoDS_Shape& aFP=aVSB(nFP).Shape(); |
312 | if (!aMF.Contains(aFP)) { |
313 | MapEdgesAndFaces(aFP, aMEFP, aAlr1); |
314 | aLIFP.Append(nFP); |
315 | aIVec.Append1()=nFP; |
316 | ++k; |
317 | } |
318 | } |
319 | aNbFP=k; |
320 | // |
321 | // sort indices |
322 | std::sort(aIVec.begin(), aIVec.end()); |
323 | // |
324 | // 5. Collect faces that are IN mySolid [ myLFIN ] |
325 | for (k=0; k<aNbFP; ++k) { |
326 | nFP = aIVec(k); |
327 | const BOPAlgo_ShapeBox& aSBF=aVSB(nFP); |
328 | const TopoDS_Face& aFP=(*(TopoDS_Face*)&aSBF.Shape()); |
329 | // |
330 | if (!aMFDone.Add(aFP)) { |
331 | continue; |
332 | } |
333 | // |
334 | iIsIN=BOPTools_AlgoTools::IsInternalFace |
335 | (aFP, myDraftSolid, aMEF, aTolPC, myContext); |
336 | // |
337 | aLFP.Clear(); |
338 | aLFP.Append(aFP); |
339 | // |
340 | aItLI1.Initialize(aLIFP); |
341 | for (; aItLI1.More(); aItLI1.Next()) { |
342 | const TopoDS_Shape& aFx=aVSB(aItLI1.Value()).Shape(); |
343 | if (!aMFDone.Contains(aFx)) { |
344 | aLFP.Append(aFx); |
345 | } |
346 | } |
347 | // |
348 | aLCBF.Clear(); |
349 | // |
350 | MakeConnexityBlock(aLFP, aME, aMFDone, aMEFP, aLCBF, aAlr1); |
351 | // |
352 | aItLS.Initialize(aLCBF); |
353 | for (; aItLS.More(); aItLS.Next()) { |
354 | const TopoDS_Shape& aFx=aItLS.Value(); |
355 | aMFDone.Add(aFx); |
356 | if (iIsIN) { |
357 | myLFIN.Append(aFx); |
358 | } |
359 | } |
360 | } // for (k=0; k<aNbFP; ++k) { |
a3f6f591 |
361 | } |
0090ae85 |
362 | //======================================================================= |
363 | // function: MapEdgesAndFaces |
364 | // purpose: |
365 | //======================================================================= |
366 | void BOPAlgo_FillIn3DParts::MapEdgesAndFaces |
367 | (const TopoDS_Shape& aF, |
368 | BOPCol_IndexedDataMapOfShapeListOfShape& aMEF, |
369 | const Handle(NCollection_BaseAllocator)& theAllocator) |
370 | { |
371 | myItF.Initialize(aF); |
372 | for (; myItF.More(); myItF.Next()) { |
373 | const TopoDS_Shape& aW=myItF.Value(); |
374 | if (aW.ShapeType()!=TopAbs_WIRE) { |
375 | continue; |
376 | } |
377 | // |
378 | myItW.Initialize(aW); |
379 | for (; myItW.More(); myItW.Next()) { |
380 | const TopoDS_Shape& aE=myItW.Value(); |
381 | // |
382 | if (aMEF.Contains(aE)) { |
383 | BOPCol_ListOfShape& aLF=aMEF.ChangeFromKey(aE); |
384 | aLF.Append(aF); |
385 | } |
386 | else { |
387 | BOPCol_ListOfShape aLS(theAllocator); |
388 | // |
389 | aLS.Append(aF); |
390 | aMEF.Add(aE, aLS); |
391 | } |
392 | } |
393 | } |
394 | } |
395 | //======================================================================= |
396 | // function: MakeConnexityBlock |
397 | // purpose: |
398 | //======================================================================= |
399 | void BOPAlgo_FillIn3DParts::MakeConnexityBlock |
400 | (const BOPCol_ListOfShape& theLFIn, |
401 | const BOPCol_IndexedMapOfShape& theMEAvoid, |
402 | const BOPCol_MapOfShape& aMFDone, |
403 | const BOPCol_IndexedDataMapOfShapeListOfShape& aMEF, |
404 | BOPCol_ListOfShape& theLCB, |
405 | const Handle(NCollection_BaseAllocator)& theAlr) |
406 | { |
407 | Standard_Integer aNbF, aNbAdd1, aNbAdd, i; |
408 | BOPCol_ListIteratorOfListOfShape aIt; |
409 | // |
410 | BOPCol_IndexedMapOfShape aMCB(100, theAlr); |
411 | BOPCol_IndexedMapOfShape aMAdd(100, theAlr); |
412 | BOPCol_IndexedMapOfShape aMAdd1(100, theAlr); |
413 | // |
414 | aNbF=theLFIn.Extent(); |
415 | // |
416 | // 2. aMCB |
417 | const TopoDS_Shape& aF1=theLFIn.First(); |
418 | aMAdd.Add(aF1); |
419 | // |
420 | for(;;) { |
421 | aMAdd1.Clear(); |
422 | aNbAdd = aMAdd.Extent(); |
423 | for (i=1; i<=aNbAdd; ++i) { |
424 | const TopoDS_Shape& aF=aMAdd(i); |
425 | // |
426 | myItF.Initialize(aF); |
427 | for (; myItF.More(); myItF.Next()) { |
428 | const TopoDS_Shape& aW=myItF.Value(); |
429 | if (aW.ShapeType()!=TopAbs_WIRE) { |
430 | continue; |
431 | } |
432 | // |
433 | myItW.Initialize(aW); |
434 | for (; myItW.More(); myItW.Next()) { |
435 | const TopoDS_Shape& aE=myItW.Value(); |
436 | if (theMEAvoid.Contains(aE)){ |
437 | continue; |
438 | } |
439 | // |
440 | const BOPCol_ListOfShape& aLF=aMEF.FindFromKey(aE); |
441 | aIt.Initialize(aLF); |
442 | for (; aIt.More(); aIt.Next()) { |
443 | const TopoDS_Shape& aFx=aIt.Value(); |
444 | if (aFx.IsSame(aF)) { |
445 | continue; |
446 | } |
447 | if (aMCB.Contains(aFx)) { |
448 | continue; |
449 | } |
450 | if (aMFDone.Contains(aFx)) { |
451 | continue; |
452 | } |
453 | aMAdd1.Add(aFx); |
454 | } |
455 | }// for (; myItW.More(); myItW.Next()) { |
456 | }// for (; myItF.More(); myItF.Next()) { |
457 | aMCB.Add(aF); |
458 | }// for (i=1; i<=aNbAdd; ++i) { |
459 | // |
460 | aNbAdd1=aMAdd1.Extent(); |
461 | if (!aNbAdd1) { |
462 | break; |
463 | } |
464 | // |
465 | aMAdd.Clear(); |
466 | for (i=1; i<=aNbAdd1; ++i) { |
467 | const TopoDS_Shape& aFAdd=aMAdd1(i); |
468 | aMAdd.Add(aFAdd); |
469 | } |
470 | // |
471 | }//while(1) { |
472 | // |
473 | aNbF=aMCB.Extent(); |
474 | for (i=1; i<=aNbF; ++i) { |
475 | const TopoDS_Shape& aF=aMCB(i); |
476 | theLCB.Append(aF); |
477 | } |
478 | } |
479 | // |
480 | typedef BOPCol_NCVector<BOPAlgo_FillIn3DParts> \ |
481 | BOPAlgo_VectorOfFillIn3DParts; |
482 | // |
483 | typedef BOPCol_ContextFunctor |
484 | <BOPAlgo_FillIn3DParts, |
485 | BOPAlgo_VectorOfFillIn3DParts, |
486 | Handle(IntTools_Context), |
487 | IntTools_Context> BOPCol_FillIn3DPartsFunctor; |
488 | // |
489 | typedef BOPCol_ContextCnt |
490 | <BOPCol_FillIn3DPartsFunctor, |
491 | BOPAlgo_VectorOfFillIn3DParts, |
492 | Handle(IntTools_Context)> BOPAlgo_FillIn3DPartsCnt; |
493 | // |
494 | //======================================================================= |
495 | // class: BOPAlgo_Builder |
496 | // |
4e57c75e |
497 | //======================================================================= |
498 | //function : FillImagesSolids |
499 | //purpose : |
500 | //======================================================================= |
744511c8 |
501 | void BOPAlgo_Builder::FillImagesSolids() |
4e57c75e |
502 | { |
744511c8 |
503 | Standard_Boolean bHasSolids; |
504 | Standard_Integer i, aNbS; |
505 | // |
744511c8 |
506 | bHasSolids=Standard_False; |
507 | aNbS=myDS->NbSourceShapes(); |
508 | for (i=0; i<aNbS; ++i) { |
509 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
510 | if (aSI.ShapeType()==TopAbs_SOLID) { |
511 | bHasSolids=!bHasSolids; |
512 | break; |
513 | } |
514 | } |
515 | // |
516 | if (!bHasSolids) { |
517 | return; |
518 | } |
488e5b9d |
519 | // |
520 | Handle(NCollection_BaseAllocator) aAlr; |
744511c8 |
521 | // |
488e5b9d |
522 | aAlr=NCollection_BaseAllocator::CommonBaseAllocator(); |
4e57c75e |
523 | // |
744511c8 |
524 | BOPCol_DataMapOfShapeListOfShape theInParts(100, aAlr); |
525 | BOPCol_DataMapOfShapeShape theDraftSolids(100, aAlr); |
526 | // |
30ecd5f8 |
527 | FillIn3DParts(theInParts, theDraftSolids, aAlr); |
744511c8 |
528 | BuildSplitSolids(theInParts, theDraftSolids, aAlr); |
4e57c75e |
529 | FillInternalShapes(); |
530 | // |
531 | theInParts.Clear(); |
532 | theDraftSolids.Clear(); |
4e57c75e |
533 | } |
534 | //======================================================================= |
535 | //function : FillIn3DParts |
536 | //purpose : |
537 | //======================================================================= |
a0a3f6ac |
538 | void BOPAlgo_Builder::FillIn3DParts |
539 | (BOPCol_DataMapOfShapeListOfShape& theInParts, |
540 | BOPCol_DataMapOfShapeShape& theDraftSolids, |
541 | const BOPCol_BaseAllocator& ) |
4e57c75e |
542 | { |
744511c8 |
543 | Standard_Boolean bHasImage; |
0090ae85 |
544 | Standard_Integer i, k, aNbS, aNbLIF, aNbFIN, aNbVSB, aNbVFIP; |
488e5b9d |
545 | Handle(NCollection_BaseAllocator) aAlr0; |
744511c8 |
546 | TopoDS_Solid aSD; |
547 | TopoDS_Iterator aIt; |
548 | BRep_Builder aBB; |
0090ae85 |
549 | // |
744511c8 |
550 | BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1; |
551 | BOPCol_ListIteratorOfListOfShape aItLS; |
4e57c75e |
552 | // |
488e5b9d |
553 | aAlr0= |
554 | NCollection_BaseAllocator::CommonBaseAllocator(); |
0090ae85 |
555 | // |
556 | BOPCol_MapOfShape aMFence(100, aAlr0); |
557 | BOPAlgo_VectorOfShapeBox aVSB(256, aAlr0); |
4e57c75e |
558 | // |
559 | theDraftSolids.Clear(); |
560 | // |
0090ae85 |
561 | // 1. aVSB vector Index/FaceBox |
4e57c75e |
562 | aNbS=myDS->NbSourceShapes(); |
563 | for (i=0; i<aNbS; ++i) { |
564 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
744511c8 |
565 | if (aSI.ShapeType()!=TopAbs_FACE) { |
566 | continue; |
567 | } |
568 | // |
4e57c75e |
569 | const TopoDS_Shape& aS=aSI.Shape(); |
570 | // |
744511c8 |
571 | if (myImages.IsBound(aS)) { |
572 | const BOPCol_ListOfShape& aLS=myImages.Find(aS); |
573 | aItLS.Initialize(aLS); |
574 | for (; aItLS.More(); aItLS.Next()) { |
a0a3f6ac |
575 | const TopoDS_Shape& aSx=aItLS.Value(); |
0090ae85 |
576 | if (!aMFence.Add(aSx)) { |
577 | continue; |
578 | } |
a0a3f6ac |
579 | Bnd_Box aBox; |
580 | BRepBndLib::Add(aSx, aBox); |
3510db62 |
581 | aBox.SetGap(aBox.GetGap() + Precision::Confusion()); |
a0a3f6ac |
582 | // |
0090ae85 |
583 | BOPAlgo_ShapeBox& aSB=aVSB.Append1(); |
a0a3f6ac |
584 | aSB.SetShape(aSx); |
585 | aSB.SetBox(aBox); |
4e57c75e |
586 | } |
744511c8 |
587 | } |
588 | else { |
589 | const Bnd_Box& aBox=aSI.Box(); |
4e57c75e |
590 | // |
0090ae85 |
591 | BOPAlgo_ShapeBox& aSB=aVSB.Append1(); |
744511c8 |
592 | aSB.SetShape(aS); |
593 | aSB.SetBox(aBox); |
4e57c75e |
594 | } |
744511c8 |
595 | }//for (i=0; i<aNbS; ++i) { |
0090ae85 |
596 | aMFence.Clear(); |
4e57c75e |
597 | // |
30ecd5f8 |
598 | // 1.2. Prepare TreeFiller |
db8e4b9a |
599 | BOPCol_BoxBndTree aBBTree; |
0090ae85 |
600 | NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> |
601 | aTreeFiller(aBBTree); |
30ecd5f8 |
602 | // |
0090ae85 |
603 | aNbVSB=aVSB.Extent(); |
604 | for (k=0; k<aNbVSB; ++k) { |
605 | const BOPAlgo_ShapeBox& aSBk=aVSB(k); |
30ecd5f8 |
606 | const Bnd_Box& aBk=aSBk.Box(); |
607 | // |
608 | aTreeFiller.Add(k, aBk); |
609 | } |
610 | // |
611 | // 1.3. Shake TreeFiller |
612 | aTreeFiller.Fill(); |
613 | // |
614 | //--------------------------------------------- |
744511c8 |
615 | // 2. Solids |
0090ae85 |
616 | BOPAlgo_VectorOfFillIn3DParts aVFIP; |
617 | // |
744511c8 |
618 | for (i=0; i<aNbS; ++i) { |
619 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
620 | if (aSI.ShapeType()!=TopAbs_SOLID) { |
621 | continue; |
622 | } |
72e88cf7 |
623 | // |
744511c8 |
624 | const TopoDS_Shape& aS=aSI.Shape(); |
625 | const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS)); |
4e57c75e |
626 | // |
744511c8 |
627 | // 2.0 Flag bHasImage |
4e57c75e |
628 | bHasImage=Standard_False; |
744511c8 |
629 | aIt.Initialize(aS); |
4e57c75e |
630 | for (; aIt.More(); aIt.Next()) { |
631 | const TopoDS_Shape& aShell=aIt.Value(); |
744511c8 |
632 | bHasImage=myImages.IsBound(aShell); |
633 | if (bHasImage){ |
a0a3f6ac |
634 | break; |
4e57c75e |
635 | } |
636 | } |
637 | // |
30ecd5f8 |
638 | // 2.1 Bounding box for the solid aS [ aBoxS ] |
0090ae85 |
639 | Bnd_Box aBoxS; |
30ecd5f8 |
640 | aBoxS=aSI.Box(); |
4e57c75e |
641 | // |
744511c8 |
642 | // 2.2 Build Draft Solid [aSD] |
0090ae85 |
643 | BOPCol_ListOfShape aLIF; |
4e57c75e |
644 | // |
0090ae85 |
645 | aBB.MakeSolid(aSD); |
744511c8 |
646 | BuildDraftSolid(aSolid, aSD, aLIF); |
744511c8 |
647 | // |
0090ae85 |
648 | BOPAlgo_FillIn3DParts& aFIP=aVFIP.Append1(); |
744511c8 |
649 | // |
0090ae85 |
650 | aFIP.SetSolid(aSolid); |
651 | aFIP.SetDraftSolid(aSD); |
652 | aFIP.SetHasImage(bHasImage); |
653 | aFIP.SetBoxS(aBoxS); |
654 | aFIP.SetLIF(aLIF); |
655 | aFIP.SetBBTree(aBBTree); |
656 | aFIP.SetVSB(aVSB); |
657 | }//for (i=0; i<aNbS; ++i) { |
658 | // |
659 | aNbVFIP=aVFIP.Extent(); |
660 | //================================================================ |
661 | BOPAlgo_FillIn3DPartsCnt::Perform(myRunParallel, aVFIP, myContext); |
662 | //================================================================ |
663 | for (k=0; k<aNbVFIP; ++k) { |
664 | BOPAlgo_FillIn3DParts& aFIP=aVFIP(k); |
665 | bHasImage=aFIP.HasImage(); |
666 | const TopoDS_Solid& aSolid=aFIP.Solid(); |
51740958 |
667 | const TopoDS_Solid& aSDraft =aFIP.DraftSolid(); |
0090ae85 |
668 | const BOPCol_ListOfShape& aLFIN=aFIP.LFIN(); |
669 | const BOPCol_ListOfShape& aLIF=aFIP.LIF(); |
744511c8 |
670 | // |
0090ae85 |
671 | aNbLIF=aLIF.Extent(); |
744511c8 |
672 | // |
0090ae85 |
673 | // Store the results in theInParts, theDraftSolids |
674 | BOPCol_ListOfShape aLFINx; |
4e57c75e |
675 | // |
744511c8 |
676 | aNbFIN=aLFIN.Extent(); |
4e57c75e |
677 | if (aNbFIN || aNbLIF) { |
0090ae85 |
678 | aItLS.Initialize(aLFIN); |
679 | for (; aItLS.More(); aItLS.Next()) { |
680 | const TopoDS_Shape& aFI=aItLS.Value(); |
681 | aLFINx.Append(aFI); |
682 | } |
744511c8 |
683 | aItLS.Initialize(aLIF); |
684 | for (; aItLS.More(); aItLS.Next()) { |
a0a3f6ac |
685 | const TopoDS_Shape& aFI=aItLS.Value(); |
0090ae85 |
686 | aLFINx.Append(aFI); |
4e57c75e |
687 | } |
0090ae85 |
688 | theInParts.Bind(aSolid, aLFINx); |
4e57c75e |
689 | } |
744511c8 |
690 | // |
4e57c75e |
691 | if (aNbFIN || bHasImage) { |
51740958 |
692 | theDraftSolids.Bind(aSolid, aSDraft); |
4e57c75e |
693 | } |
0090ae85 |
694 | } |
4e57c75e |
695 | } |
696 | //======================================================================= |
697 | //function : BuildDraftSolid |
698 | //purpose : |
699 | //======================================================================= |
744511c8 |
700 | void BOPAlgo_Builder::BuildDraftSolid(const TopoDS_Shape& theSolid, |
a0a3f6ac |
701 | TopoDS_Shape& theDraftSolid, |
702 | BOPCol_ListOfShape& theLIF) |
4e57c75e |
703 | { |
4e57c75e |
704 | Standard_Boolean bToReverse; |
705 | Standard_Integer iFlag; |
706 | TopAbs_Orientation aOrF, aOrSh, aOrSd; |
707 | TopoDS_Iterator aIt1, aIt2; |
708 | TopoDS_Shell aShD; |
709 | TopoDS_Shape aFSDx, aFx; |
710 | BRep_Builder aBB; |
a0a3f6ac |
711 | BOPCol_ListIteratorOfListOfShape aItS; |
4e57c75e |
712 | // |
713 | aOrSd=theSolid.Orientation(); |
714 | theDraftSolid.Orientation(aOrSd); |
715 | // |
716 | aIt1.Initialize(theSolid); |
717 | for (; aIt1.More(); aIt1.Next()) { |
718 | const TopoDS_Shape& aSh=aIt1.Value(); |
719 | if(aSh.ShapeType()!=TopAbs_SHELL) { |
720 | continue; // mb internal edges,vertices |
721 | } |
722 | // |
723 | aOrSh=aSh.Orientation(); |
724 | aBB.MakeShell(aShD); |
725 | aShD.Orientation(aOrSh); |
726 | iFlag=0; |
727 | // |
728 | aIt2.Initialize(aSh); |
729 | for (; aIt2.More(); aIt2.Next()) { |
730 | const TopoDS_Shape& aF=aIt2.Value(); |
731 | aOrF=aF.Orientation(); |
732 | // |
733 | if (myImages.IsBound(aF)) { |
734 | const BOPCol_ListOfShape& aLSp=myImages.Find(aF); |
735 | aItS.Initialize(aLSp); |
736 | for (; aItS.More(); aItS.Next()) { |
737 | aFx=aItS.Value(); |
738 | // |
739 | if (myShapesSD.IsBound(aFx)) { |
740 | aFSDx=myShapesSD.Find(aFx); |
741 | // |
742 | if (aOrF==TopAbs_INTERNAL) { |
743 | aFSDx.Orientation(aOrF); |
744 | theLIF.Append(aFSDx); |
745 | } |
746 | else { |
1e143abb |
747 | bToReverse=BOPTools_AlgoTools::IsSplitToReverse |
748 | (aFSDx, aF, myContext); |
4e57c75e |
749 | if (bToReverse) { |
750 | aFSDx.Reverse(); |
751 | } |
752 | // |
753 | iFlag=1; |
754 | aBB.Add(aShD, aFSDx); |
755 | } |
756 | }//if (myShapesSD.IsBound(aFx)) { |
757 | else { |
758 | aFx.Orientation(aOrF); |
759 | if (aOrF==TopAbs_INTERNAL) { |
760 | theLIF.Append(aFx); |
761 | } |
762 | else{ |
763 | iFlag=1; |
764 | aBB.Add(aShD, aFx); |
765 | } |
766 | } |
767 | } |
768 | } // if (myImages.IsBound(aF)) { |
769 | // |
770 | else { |
771 | if (aOrF==TopAbs_INTERNAL) { |
772 | theLIF.Append(aF); |
773 | } |
774 | else{ |
775 | iFlag=1; |
776 | aBB.Add(aShD, aF); |
777 | } |
778 | } |
779 | } //for (; aIt2.More(); aIt2.Next()) { |
780 | // |
781 | if (iFlag) { |
ab860031 |
782 | aShD.Closed (BRep_Tool::IsClosed (aShD)); |
4e57c75e |
783 | aBB.Add(theDraftSolid, aShD); |
784 | } |
785 | } //for (; aIt1.More(); aIt1.Next()) { |
786 | } |
787 | //======================================================================= |
788 | //function : BuildSplitSolids |
789 | //purpose : |
790 | //======================================================================= |
a0a3f6ac |
791 | void BOPAlgo_Builder::BuildSplitSolids |
792 | (BOPCol_DataMapOfShapeListOfShape& theInParts, |
793 | BOPCol_DataMapOfShapeShape& theDraftSolids, |
794 | const BOPCol_BaseAllocator& ) |
4e57c75e |
795 | { |
4e57c75e |
796 | Standard_Boolean bFlagSD; |
96a95605 |
797 | Standard_Integer i, aNbS; |
4e57c75e |
798 | TopExp_Explorer aExp; |
799 | BOPCol_ListIteratorOfListOfShape aIt; |
4e57c75e |
800 | // |
488e5b9d |
801 | Handle(NCollection_BaseAllocator) aAlr0; |
802 | aAlr0=NCollection_BaseAllocator::CommonBaseAllocator(); |
744511c8 |
803 | // |
804 | BOPCol_ListOfShape aSFS(aAlr0), aLSEmpty(aAlr0); |
805 | BOPCol_MapOfShape aMFence(100, aAlr0); |
806 | BOPTools_MapOfSet aMST(100, aAlr0); |
30ecd5f8 |
807 | BOPAlgo_VectorOfBuilderSolid aVBS; |
4e57c75e |
808 | // |
809 | // 0. Find same domain solids for non-interferred solids |
810 | aNbS=myDS->NbSourceShapes(); |
811 | for (i=0; i<aNbS; ++i) { |
812 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
813 | // |
814 | if (aSI.ShapeType()!=TopAbs_SOLID) { |
815 | continue; |
816 | } |
817 | // |
818 | const TopoDS_Shape& aS=aSI.Shape(); |
819 | if (!aMFence.Add(aS)) { |
820 | continue; |
821 | } |
822 | if(theDraftSolids.IsBound(aS)) { |
823 | continue; |
824 | } |
825 | // |
826 | BOPTools_Set aST; |
827 | // |
828 | aST.Add(aS, TopAbs_FACE); |
829 | aMST.Add(aST); |
830 | // |
831 | } //for (i=1; i<=aNbS; ++i) |
832 | // |
833 | // 1. Build solids for interferred source solids |
834 | for (i=0; i<aNbS; ++i) { |
835 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
836 | // |
837 | if (aSI.ShapeType()!=TopAbs_SOLID) { |
838 | continue; |
839 | } |
840 | // |
841 | const TopoDS_Shape& aS=aSI.Shape(); |
30ecd5f8 |
842 | const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS)); |
4e57c75e |
843 | if(!theDraftSolids.IsBound(aS)) { |
844 | continue; |
845 | } |
846 | const TopoDS_Shape& aSD=theDraftSolids.Find(aS); |
847 | const BOPCol_ListOfShape& aLFIN= |
848 | (theInParts.IsBound(aS)) ? theInParts.Find(aS) : aLSEmpty; |
849 | // |
850 | // 1.1 Fill Shell Faces Set |
851 | aSFS.Clear(); |
852 | aExp.Init(aSD, TopAbs_FACE); |
853 | for (; aExp.More(); aExp.Next()) { |
854 | const TopoDS_Shape& aF=aExp.Current(); |
855 | aSFS.Append(aF); |
856 | } |
857 | // |
858 | aIt.Initialize(aLFIN); |
859 | for (; aIt.More(); aIt.Next()) { |
860 | TopoDS_Shape aF=aIt.Value(); |
861 | // |
862 | aF.Orientation(TopAbs_FORWARD); |
863 | aSFS.Append(aF); |
864 | aF.Orientation(TopAbs_REVERSED); |
865 | aSFS.Append(aF); |
866 | } |
867 | // |
488e5b9d |
868 | // 1.3 Build new solids |
30ecd5f8 |
869 | BOPAlgo_BuilderSolid& aBS=aVBS.Append1(); |
870 | aBS.SetSolid(aSolid); |
871 | aBS.SetShapes(aSFS); |
465d1fba |
872 | aBS.SetRunParallel(myRunParallel); |
36f4947b |
873 | aBS.SetProgressIndicator(myProgressIndicator); |
30ecd5f8 |
874 | }//for (i=0; i<aNbS; ++i) { |
875 | // |
876 | Standard_Integer k, aNbBS; |
877 | // |
878 | aNbBS=aVBS.Extent(); |
879 | // |
880 | //=================================================== |
881 | BOPAlgo_BuilderSolidCnt::Perform(myRunParallel, aVBS); |
882 | //=================================================== |
883 | // |
884 | for (k=0; k<aNbBS; ++k) { |
885 | BOPAlgo_BuilderSolid& aBS=aVBS(k); |
886 | const TopoDS_Solid& aS=aBS.Solid(); |
887 | const BOPCol_ListOfShape& aLSR=aBS.Areas(); |
4e57c75e |
888 | // |
4e57c75e |
889 | if (!myImages.IsBound(aS)) { |
b18a83d4 |
890 | BOPCol_ListOfShape* pLSx = myImages.Bound(aS, BOPCol_ListOfShape()); |
4e57c75e |
891 | // |
892 | aIt.Initialize(aLSR); |
893 | for (; aIt.More(); aIt.Next()) { |
894 | BOPTools_Set aST; |
895 | // |
896 | const TopoDS_Shape& aSR=aIt.Value(); |
897 | aST.Add(aSR, TopAbs_FACE); |
898 | // |
899 | bFlagSD=aMST.Contains(aST); |
900 | // |
901 | const BOPTools_Set& aSTx=aMST.Added(aST); |
902 | const TopoDS_Shape& aSx=aSTx.Shape(); |
b18a83d4 |
903 | pLSx->Append(aSx); |
904 | // |
905 | BOPCol_ListOfShape* pLOr = myOrigins.ChangeSeek(aSx); |
906 | if (!pLOr) { |
907 | pLOr = myOrigins.Bound(aSx, BOPCol_ListOfShape()); |
908 | } |
909 | pLOr->Append(aS); |
4e57c75e |
910 | // |
911 | if (bFlagSD) { |
912 | myShapesSD.Bind(aSR, aSx); |
913 | } |
914 | } |
915 | } |
30ecd5f8 |
916 | } |
4e57c75e |
917 | } |
4e57c75e |
918 | //======================================================================= |
919 | //function :FillInternalShapes |
920 | //purpose : |
921 | //======================================================================= |
744511c8 |
922 | void BOPAlgo_Builder::FillInternalShapes() |
4e57c75e |
923 | { |
96a95605 |
924 | Standard_Integer i, j, aNbS, aNbSI, aNbSx; |
4e57c75e |
925 | TopAbs_ShapeEnum aType; |
926 | TopAbs_State aState; |
927 | TopoDS_Iterator aItS; |
928 | BRep_Builder aBB; |
4e57c75e |
929 | BOPCol_ListIteratorOfListOfShape aIt, aIt1; |
930 | // |
488e5b9d |
931 | Handle(NCollection_BaseAllocator) aAllocator; |
4e57c75e |
932 | //-----------------------------------------------------scope f |
488e5b9d |
933 | aAllocator=NCollection_BaseAllocator::CommonBaseAllocator(); |
4e57c75e |
934 | // |
935 | BOPCol_IndexedDataMapOfShapeListOfShape aMSx(100, aAllocator); |
936 | BOPCol_IndexedMapOfShape aMx(100, aAllocator); |
319da2e4 |
937 | BOPCol_IndexedMapOfShape aMSI(100, aAllocator); |
4e57c75e |
938 | BOPCol_MapOfShape aMFence(100, aAllocator); |
939 | BOPCol_MapOfShape aMSOr(100, aAllocator); |
940 | BOPCol_ListOfShape aLSd(aAllocator); |
941 | BOPCol_ListOfShape aLArgs(aAllocator); |
c884a268 |
942 | BOPCol_ListOfShape aLSC(aAllocator); |
319da2e4 |
943 | BOPCol_ListOfShape aLSI(aAllocator); |
4e57c75e |
944 | // |
945 | // 1. Shapes to process |
946 | // |
947 | // 1.1 Shapes from pure arguments aMSI |
948 | // 1.1.1 vertex, edge, wire |
949 | // |
8620e18d |
950 | const BOPCol_ListOfShape& aArguments=myDS->Arguments(); |
951 | aIt.Initialize(aArguments); |
4e57c75e |
952 | for (; aIt.More(); aIt.Next()) { |
953 | const TopoDS_Shape& aS=aIt.Value(); |
c884a268 |
954 | TreatCompound(aS, aMFence, aLSC); |
955 | } |
956 | aIt.Initialize(aLSC); |
957 | for (; aIt.More(); aIt.Next()) { |
958 | const TopoDS_Shape& aS=aIt.Value(); |
4e57c75e |
959 | aType=aS.ShapeType(); |
960 | if (aType==TopAbs_WIRE) { |
961 | aItS.Initialize(aS); |
962 | for(; aItS.More(); aItS.Next()) { |
963 | const TopoDS_Shape& aE=aItS.Value(); |
964 | if (aMFence.Add(aE)) { |
965 | aLArgs.Append(aE); |
966 | } |
967 | } |
968 | } |
969 | else if (aType==TopAbs_VERTEX || aType==TopAbs_EDGE){ |
970 | aLArgs.Append(aS); |
971 | } |
972 | } |
973 | aMFence.Clear(); |
974 | // |
975 | aIt.Initialize(aLArgs); |
976 | for (; aIt.More(); aIt.Next()) { |
977 | const TopoDS_Shape& aS=aIt.Value(); |
978 | aType=aS.ShapeType(); |
a0a3f6ac |
979 | if (aType==TopAbs_VERTEX || |
980 | aType==TopAbs_EDGE || |
981 | aType==TopAbs_WIRE) { |
4e57c75e |
982 | if (aMFence.Add(aS)) { |
983 | if (myImages.IsBound(aS)) { |
984 | const BOPCol_ListOfShape &aLSp=myImages.Find(aS); |
985 | aIt1.Initialize(aLSp); |
986 | for (; aIt1.More(); aIt1.Next()) { |
987 | const TopoDS_Shape& aSp=aIt1.Value(); |
988 | aMSI.Add(aSp); |
989 | } |
990 | } |
991 | else { |
992 | aMSI.Add(aS); |
993 | } |
994 | } |
995 | } |
996 | } |
997 | |
998 | aNbSI=aMSI.Extent(); |
999 | // |
1000 | // 2. Internal vertices, edges from source solids |
1001 | aMFence.Clear(); |
1002 | aLSd.Clear(); |
1003 | // |
1004 | aNbS=myDS->NbSourceShapes(); |
1005 | for (i=0; i<aNbS; ++i) { |
1006 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
1007 | // |
1008 | if (aSI.ShapeType()!=TopAbs_SOLID) { |
1009 | continue; |
1010 | } |
1011 | // |
36f4947b |
1012 | UserBreak(); |
1013 | // |
4e57c75e |
1014 | const TopoDS_Shape& aS=aSI.Shape(); |
1015 | // |
1016 | aMx.Clear(); |
1017 | OwnInternalShapes(aS, aMx); |
1018 | // |
1019 | aNbSx=aMx.Extent(); |
1020 | for (j=1; j<=aNbSx; ++j) { |
1021 | const TopoDS_Shape& aSi=aMx(j); |
1022 | if (myImages.IsBound(aSi)) { |
1023 | const BOPCol_ListOfShape &aLSp=myImages.Find(aSi); |
1024 | aIt1.Initialize(aLSp); |
1025 | for (; aIt1.More(); aIt1.Next()) { |
1026 | const TopoDS_Shape& aSp=aIt1.Value(); |
1027 | aMSI.Add(aSp); |
1028 | } |
1029 | } |
1030 | else { |
1031 | aMSI.Add(aSi); |
1032 | } |
1033 | } |
1034 | // |
1035 | // build aux map from splits of solids |
1036 | if (myImages.IsBound(aS)) { |
1037 | const BOPCol_ListOfShape &aLSp=myImages.Find(aS); |
1038 | aIt.Initialize(aLSp); |
1039 | for (; aIt.More(); aIt.Next()) { |
1040 | const TopoDS_Shape& aSp=aIt.Value(); |
1041 | if (aMFence.Add(aSp)) { |
1042 | BOPTools::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_EDGE, aMSx); |
1043 | BOPTools::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_FACE, aMSx); |
1044 | BOPTools::MapShapesAndAncestors(aSp, TopAbs_EDGE , TopAbs_FACE, aMSx); |
1045 | aLSd.Append(aSp); |
1046 | } |
1047 | } |
1048 | } |
1049 | else { |
1050 | if (aMFence.Add(aS)) { |
1051 | BOPTools::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_EDGE, aMSx); |
1052 | BOPTools::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_FACE, aMSx); |
1053 | BOPTools::MapShapesAndAncestors(aS, TopAbs_EDGE , TopAbs_FACE, aMSx); |
1054 | aLSd.Append(aS); |
1055 | aMSOr.Add(aS); |
1056 | } |
1057 | } |
1058 | }// for (i=0; i<aNbS; ++i) { |
1059 | // |
4e57c75e |
1060 | // 3. Some shapes of aMSI can be already tied with faces of |
1061 | // split solids |
319da2e4 |
1062 | aNbSI = aMSI.Extent(); |
1063 | for (i = 1; i <= aNbSI; ++i) { |
1064 | const TopoDS_Shape& aSI = aMSI(i); |
4e57c75e |
1065 | if (aMSx.Contains(aSI)) { |
1066 | const BOPCol_ListOfShape &aLSx=aMSx.FindFromKey(aSI); |
319da2e4 |
1067 | aNbSx = aLSx.Extent(); |
1068 | if (!aNbSx) { |
1069 | aLSI.Append(aSI); |
4e57c75e |
1070 | } |
1071 | } |
319da2e4 |
1072 | else { |
1073 | aLSI.Append(aSI); |
1074 | } |
4e57c75e |
1075 | } |
1076 | // |
1077 | // 4. Just check it |
319da2e4 |
1078 | aNbSI = aLSI.Extent(); |
4e57c75e |
1079 | if (!aNbSI) { |
1080 | return; |
1081 | } |
1082 | // |
1083 | // 5 Settle internal vertices and edges into solids |
1084 | aMx.Clear(); |
1085 | aIt.Initialize(aLSd); |
1086 | for (; aIt.More(); aIt.Next()) { |
1087 | TopoDS_Solid aSd=TopoDS::Solid(aIt.Value()); |
1088 | // |
319da2e4 |
1089 | aIt1.Initialize(aLSI); |
1090 | for (; aIt1.More();) { |
1091 | TopoDS_Shape aSI = aIt1.Value(); |
4e57c75e |
1092 | aSI.Orientation(TopAbs_INTERNAL); |
1093 | // |
0090ae85 |
1094 | aState=BOPTools_AlgoTools::ComputeStateByOnePoint |
1095 | (aSI, aSd, 1.e-11, myContext); |
319da2e4 |
1096 | // |
1097 | if (aState != TopAbs_IN) { |
1098 | aIt1.Next(); |
1099 | continue; |
1100 | } |
1101 | // |
b18a83d4 |
1102 | if (aMSOr.Contains(aSd)) { |
1103 | // make new solid |
319da2e4 |
1104 | TopoDS_Solid aSdx; |
1105 | // |
1106 | aBB.MakeSolid(aSdx); |
1107 | aItS.Initialize(aSd); |
1108 | for (; aItS.More(); aItS.Next()) { |
1109 | const TopoDS_Shape& aSh=aItS.Value(); |
1110 | aBB.Add(aSdx, aSh); |
4e57c75e |
1111 | } |
319da2e4 |
1112 | // |
1113 | aBB.Add(aSdx, aSI); |
1114 | // |
b18a83d4 |
1115 | // no need to check for images of aSd as aMSOr contains only original solids |
1116 | BOPCol_ListOfShape* pLS = myImages.Bound(aSd, BOPCol_ListOfShape()); |
1117 | pLS->Append(aSdx); |
1118 | // |
1119 | BOPCol_ListOfShape* pLOr = myOrigins.Bound(aSdx, BOPCol_ListOfShape()); |
1120 | pLOr->Append(aSd); |
4e57c75e |
1121 | // |
319da2e4 |
1122 | aMSOr.Remove(aSd); |
1123 | aSd=aSdx; |
1124 | } |
1125 | else { |
1126 | aBB.Add(aSd, aSI); |
1127 | } |
1128 | // |
1129 | aLSI.Remove(aIt1); |
1130 | }//for (; aIt1.More();) { |
1131 | }//for (; aIt.More(); aIt.Next()) { |
4e57c75e |
1132 | // |
1133 | //-----------------------------------------------------scope t |
1134 | aLArgs.Clear(); |
1135 | aLSd.Clear(); |
1136 | aMSOr.Clear(); |
1137 | aMFence.Clear(); |
1138 | aMSI.Clear(); |
1139 | aMx.Clear(); |
1140 | aMSx.Clear(); |
1141 | } |
1142 | //======================================================================= |
1143 | //function : OwnInternalShapes |
1144 | //purpose : |
1145 | //======================================================================= |
a0a3f6ac |
1146 | void OwnInternalShapes(const TopoDS_Shape& theS, |
1147 | BOPCol_IndexedMapOfShape& theMx) |
4e57c75e |
1148 | { |
1149 | TopoDS_Iterator aIt; |
1150 | // |
1151 | aIt.Initialize(theS); |
1152 | for (; aIt.More(); aIt.Next()) { |
1153 | const TopoDS_Shape& aSx=aIt.Value(); |
1154 | if (aSx.ShapeType()!=TopAbs_SHELL) { |
1155 | theMx.Add(aSx); |
1156 | } |
1157 | } |
1158 | } |
744511c8 |
1159 | //======================================================================= |
c884a268 |
1160 | //function : TreatCompound |
1161 | //purpose : |
1162 | //======================================================================= |
1163 | void TreatCompound(const TopoDS_Shape& theS, |
1164 | BOPCol_MapOfShape& aMFence, |
1165 | BOPCol_ListOfShape& theLS) |
1166 | { |
1167 | TopAbs_ShapeEnum aType; |
1168 | // |
1169 | aType = theS.ShapeType(); |
1170 | if (aType != TopAbs_COMPOUND) { |
1171 | if (aMFence.Add(theS)) { |
1172 | theLS.Append(theS); |
1173 | } |
1174 | return; |
1175 | } |
1176 | // |
1177 | TopoDS_Iterator aIt; |
1178 | // |
1179 | aIt.Initialize(theS); |
1180 | for (; aIt.More(); aIt.Next()) { |
1181 | const TopoDS_Shape& aS = aIt.Value(); |
1182 | TreatCompound(aS, aMFence, theLS); |
1183 | } |
1184 | } |