0026586: Eliminate compile warnings obtained by building occt with vc14: declaration...
[occt.git] / src / BOPAlgo / BOPAlgo_Builder_3.cxx
CommitLineData
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//
4e57c75e 22#include <NCollection_IncAllocator.hxx>
db8e4b9a 23#include <NCollection_UBTreeFiller.hxx>
a0a3f6ac 24//
db8e4b9a 25#include <Bnd_Box.hxx>
4e57c75e 26#include <TopAbs_State.hxx>
a0a3f6ac 27//
4e57c75e 28#include <TopoDS.hxx>
29#include <TopoDS_Iterator.hxx>
30#include <TopoDS_Solid.hxx>
31#include <TopoDS_Shape.hxx>
32#include <TopoDS_Face.hxx>
744511c8 33#include <TopoDS_Edge.hxx>
4e57c75e 34#include <TopoDS_Solid.hxx>
35#include <TopoDS_Iterator.hxx>
36#include <TopoDS_Shell.hxx>
37#include <TopoDS_Compound.hxx>
a0a3f6ac 38//
4e57c75e 39#include <TopExp.hxx>
40#include <TopExp_Explorer.hxx>
a0a3f6ac 41//
4e57c75e 42#include <BRep_Builder.hxx>
43#include <BRepTools.hxx>
44#include <BRepClass3d_SolidClassifier.hxx>
db8e4b9a 45#include <BRepBndLib.hxx>
4e57c75e 46//
47#include <BOPCol_IndexedMapOfShape.hxx>
48#include <BOPCol_MapOfShape.hxx>
49#include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx>
50#include <BOPCol_ListOfShape.hxx>
db8e4b9a 51#include <BOPCol_BoxBndTree.hxx>
52#include <BOPCol_ListOfInteger.hxx>
53#include <BOPCol_DataMapOfIntegerShape.hxx>
a0a3f6ac 54#include <BOPCol_NCVector.hxx>
c7b59798 55#include <BOPCol_Parallel.hxx>
db8e4b9a 56//
1e143abb 57#include <IntTools_Context.hxx>
4e57c75e 58//
59#include <BOPDS_DS.hxx>
60#include <BOPDS_ShapeInfo.hxx>
61//
62#include <BOPTools.hxx>
63#include <BOPTools_AlgoTools.hxx>
4e57c75e 64#include <BOPTools_MapOfSet.hxx>
65#include <BOPTools_Set.hxx>
66//
67#include <BOPAlgo_BuilderSolid.hxx>
4691b61a 68#include <NCollection_Array1.hxx>
744511c8 69
0644bfa4 70#include <algorithm>
0090ae85 71#include <BOPAlgo_Algo.hxx>
744511c8 72
73static
4e57c75e 74 void OwnInternalShapes(const TopoDS_Shape& ,
75 BOPCol_IndexedMapOfShape& );
76
c884a268 77static
78 void TreatCompound(const TopoDS_Shape& theS,
79 BOPCol_MapOfShape& aMFence,
80 BOPCol_ListOfShape& theLS);
81
4e57c75e 82//=======================================================================
a0a3f6ac 83// BOPAlgo_BuilderSolid
84//
85typedef BOPCol_NCVector
86 <BOPAlgo_BuilderSolid> BOPAlgo_VectorOfBuilderSolid;
87//
c7b59798 88typedef BOPCol_Functor
a0a3f6ac 89 <BOPAlgo_BuilderSolid,
90 BOPAlgo_VectorOfBuilderSolid> BOPAlgo_BuilderSolidFunctor;
91//
c7b59798 92typedef BOPCol_Cnt
a0a3f6ac 93 <BOPAlgo_BuilderSolidFunctor,
94 BOPAlgo_VectorOfBuilderSolid> BOPAlgo_BuilderSolidCnt;
95//
96//=======================================================================
0090ae85 97// class: BOPAlgo_ShapeBox
98//
99//=======================================================================
744511c8 100//class : BOPAlgo_ShapeBox
101//purpose : Auxiliary class
102//=======================================================================
103class BOPAlgo_ShapeBox {
104 public:
105 BOPAlgo_ShapeBox() {
106 };
107 //
108 ~BOPAlgo_ShapeBox() {
109 };
110 //
111 void SetShape(const TopoDS_Shape& aS) {
112 myShape=aS;
113 };
114 //
115 const TopoDS_Shape& Shape()const {
116 return myShape;
117 };
118 //
119 void SetBox(const Bnd_Box& aBox) {
120 myBox=aBox;
121 };
122 //
123 const Bnd_Box& Box()const {
124 return myBox;
125 };
126 //
127 protected:
128 TopoDS_Shape myShape;
129 Bnd_Box myBox;
130};
131//
0090ae85 132typedef BOPCol_NCVector<BOPAlgo_ShapeBox> BOPAlgo_VectorOfShapeBox;
133//
134//=======================================================================
135// class: BOPAlgo_FillIn3DParts
744511c8 136//
0090ae85 137//=======================================================================
138//class : BOPAlgo_FillIn3DParts
139//purpose :
140//=======================================================================
141class BOPAlgo_FillIn3DParts : public BOPAlgo_Algo {
142 public:
143 DEFINE_STANDARD_ALLOC
144
145 BOPAlgo_FillIn3DParts(){
146 myHasImage=Standard_False;
147 myBBTree=NULL;
148 myVSB=NULL;
149 };
150 //
151 virtual ~BOPAlgo_FillIn3DParts(){
152 };
153 //
154 void SetSolid(const TopoDS_Solid& aS) {
155 mySolid=aS;
156 };
157 //
158 const TopoDS_Solid& Solid()const {
159 return mySolid;
160 };
161 //
162 void SetDraftSolid(const TopoDS_Solid& aS) {
163 myDraftSolid=aS;
164 };
165 //
166 const TopoDS_Solid& DraftSolid()const {
167 return myDraftSolid;
168 };
169 //
170 void SetHasImage(const Standard_Boolean bFlag) {
171 myHasImage=bFlag;
172 };
173 //
174 Standard_Boolean HasImage()const {
175 return myHasImage;
176 };
177 //
178 void SetBoxS(const Bnd_Box& aBox) {
179 myBoxS=aBox;
180 };
181 //
182 const Bnd_Box& BoxS()const {
183 return myBoxS;
184 };
185 //
186 void SetLIF(const BOPCol_ListOfShape& aLIF) {
187 myLIF=aLIF;
188 };
189 //
190 const BOPCol_ListOfShape& LIF()const {
191 return myLIF;
192 };
193 //
194 void SetBBTree(const BOPCol_BoxBndTree& aBBTree) {
195 myBBTree=(BOPCol_BoxBndTree*)&aBBTree;
196 };
197 //
198 void SetVSB(const BOPAlgo_VectorOfShapeBox& aVSB) {
199 myVSB=(BOPAlgo_VectorOfShapeBox*)&aVSB;
200 };
201 //
202 //
203 void SetContext(const Handle(IntTools_Context)& aContext) {
204 myContext=aContext;
205 }
206 //
207 const Handle(IntTools_Context)& Context()const {
208 return myContext;
209 }
210 //
211 virtual void Perform();
212 //
213
214 //
215 const BOPCol_ListOfShape& LFIN()const {
216 return myLFIN;
217 };
218
219 protected:
220 void MapEdgesAndFaces
221 (const TopoDS_Shape& ,
222 BOPCol_IndexedDataMapOfShapeListOfShape& ,
223 const Handle(NCollection_BaseAllocator)& );
224
225 void MakeConnexityBlock
226 (const BOPCol_ListOfShape& ,
227 const BOPCol_IndexedMapOfShape& ,
228 const BOPCol_MapOfShape& ,
229 const BOPCol_IndexedDataMapOfShapeListOfShape& ,
230 BOPCol_ListOfShape& ,
231 const Handle(NCollection_BaseAllocator)& );
232 //
233 protected:
234 TopoDS_Solid mySolid;
235 TopoDS_Solid myDraftSolid;
236 Standard_Boolean myHasImage;
237 Bnd_Box myBoxS;
238 BOPCol_ListOfShape myLIF;
239 BOPCol_ListOfShape myLFIN;
240 //
241 BOPCol_BoxBndTree* myBBTree;
242 BOPAlgo_VectorOfShapeBox* myVSB;
243 //
244 TopoDS_Iterator myItF;
245 TopoDS_Iterator myItW;
246
247 Handle(IntTools_Context) myContext;
248};
744511c8 249
250//=======================================================================
0090ae85 251//function : BOPAlgo_FillIn3DParts::Perform
252//purpose :
253//=======================================================================
254void BOPAlgo_FillIn3DParts::Perform()
255{
256 Handle(NCollection_IncAllocator) aAlr1;
257 BOPAlgo_Algo::UserBreak();
258 //
259 Standard_Integer aNbFP, k, nFP, iIsIN;
260 Standard_Real aTolPC;
261 BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1;
262 BOPCol_ListIteratorOfListOfShape aItLS;
263 BOPCol_BoxBndTreeSelector aSelector;
264 //
265 aAlr1=new NCollection_IncAllocator();
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) {
361};
362//=======================================================================
363// function: MapEdgesAndFaces
364// purpose:
365//=======================================================================
366void 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//=======================================================================
399void 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//
480typedef BOPCol_NCVector<BOPAlgo_FillIn3DParts> \
481 BOPAlgo_VectorOfFillIn3DParts;
482//
483typedef BOPCol_ContextFunctor
484 <BOPAlgo_FillIn3DParts,
485 BOPAlgo_VectorOfFillIn3DParts,
486 Handle(IntTools_Context),
487 IntTools_Context> BOPCol_FillIn3DPartsFunctor;
488//
489typedef BOPCol_ContextCnt
490 <BOPCol_FillIn3DPartsFunctor,
491 BOPAlgo_VectorOfFillIn3DParts,
492 Handle(IntTools_Context)> BOPAlgo_FillIn3DPartsCnt;
493//
494//=======================================================================
495// class: BOPAlgo_Builder
496//
497//=======================================================================
4e57c75e 498//function : FillImagesSolids
499//purpose :
500//=======================================================================
744511c8 501void BOPAlgo_Builder::FillImagesSolids()
4e57c75e 502{
744511c8 503 Standard_Boolean bHasSolids;
504 Standard_Integer i, aNbS;
505 //
4e57c75e 506 myErrorStatus=0;
507 //
744511c8 508 bHasSolids=Standard_False;
509 aNbS=myDS->NbSourceShapes();
510 for (i=0; i<aNbS; ++i) {
511 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
512 if (aSI.ShapeType()==TopAbs_SOLID) {
513 bHasSolids=!bHasSolids;
514 break;
515 }
516 }
517 //
518 if (!bHasSolids) {
519 return;
520 }
521 //
522 Handle(NCollection_IncAllocator) aAlr;
4e57c75e 523 //
744511c8 524 aAlr=new NCollection_IncAllocator();
744511c8 525 BOPCol_DataMapOfShapeListOfShape theInParts(100, aAlr);
526 BOPCol_DataMapOfShapeShape theDraftSolids(100, aAlr);
527 //
30ecd5f8 528 FillIn3DParts(theInParts, theDraftSolids, aAlr);
744511c8 529 BuildSplitSolids(theInParts, theDraftSolids, aAlr);
4e57c75e 530 FillInternalShapes();
531 //
532 theInParts.Clear();
533 theDraftSolids.Clear();
4e57c75e 534}
535//=======================================================================
536//function : FillIn3DParts
537//purpose :
538//=======================================================================
a0a3f6ac 539void BOPAlgo_Builder::FillIn3DParts
540 (BOPCol_DataMapOfShapeListOfShape& theInParts,
541 BOPCol_DataMapOfShapeShape& theDraftSolids,
542 const BOPCol_BaseAllocator& )
4e57c75e 543{
744511c8 544 Standard_Boolean bHasImage;
0090ae85 545 Standard_Integer i, k, aNbS, aNbLIF, aNbFIN, aNbVSB, aNbVFIP;
546 Handle(NCollection_IncAllocator) aAlr0;
744511c8 547 TopoDS_Solid aSD;
548 TopoDS_Iterator aIt;
549 BRep_Builder aBB;
0090ae85 550 //
744511c8 551 BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1;
552 BOPCol_ListIteratorOfListOfShape aItLS;
4e57c75e 553 //
744511c8 554 aAlr0=new NCollection_IncAllocator();
0090ae85 555 //
556 BOPCol_MapOfShape aMFence(100, aAlr0);
557 BOPAlgo_VectorOfShapeBox aVSB(256, aAlr0);
4e57c75e 558 //
744511c8 559 myErrorStatus=0;
4e57c75e 560 theDraftSolids.Clear();
561 //
0090ae85 562 // 1. aVSB vector Index/FaceBox
4e57c75e 563 aNbS=myDS->NbSourceShapes();
564 for (i=0; i<aNbS; ++i) {
565 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
744511c8 566 if (aSI.ShapeType()!=TopAbs_FACE) {
567 continue;
568 }
569 //
4e57c75e 570 const TopoDS_Shape& aS=aSI.Shape();
571 //
744511c8 572 if (myImages.IsBound(aS)) {
573 const BOPCol_ListOfShape& aLS=myImages.Find(aS);
574 aItLS.Initialize(aLS);
575 for (; aItLS.More(); aItLS.Next()) {
a0a3f6ac 576 const TopoDS_Shape& aSx=aItLS.Value();
0090ae85 577 if (!aMFence.Add(aSx)) {
578 continue;
579 }
a0a3f6ac 580 Bnd_Box aBox;
581 BRepBndLib::Add(aSx, aBox);
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 700void BOPAlgo_Builder::BuildDraftSolid(const TopoDS_Shape& theSolid,
a0a3f6ac 701 TopoDS_Shape& theDraftSolid,
702 BOPCol_ListOfShape& theLIF)
4e57c75e 703{
704 myErrorStatus=0;
705 //
706 Standard_Boolean bToReverse;
707 Standard_Integer iFlag;
708 TopAbs_Orientation aOrF, aOrSh, aOrSd;
709 TopoDS_Iterator aIt1, aIt2;
710 TopoDS_Shell aShD;
711 TopoDS_Shape aFSDx, aFx;
712 BRep_Builder aBB;
a0a3f6ac 713 BOPCol_ListIteratorOfListOfShape aItS;
4e57c75e 714 //
715 aOrSd=theSolid.Orientation();
716 theDraftSolid.Orientation(aOrSd);
717 //
718 aIt1.Initialize(theSolid);
719 for (; aIt1.More(); aIt1.Next()) {
720 const TopoDS_Shape& aSh=aIt1.Value();
721 if(aSh.ShapeType()!=TopAbs_SHELL) {
722 continue; // mb internal edges,vertices
723 }
724 //
725 aOrSh=aSh.Orientation();
726 aBB.MakeShell(aShD);
727 aShD.Orientation(aOrSh);
728 iFlag=0;
729 //
730 aIt2.Initialize(aSh);
731 for (; aIt2.More(); aIt2.Next()) {
732 const TopoDS_Shape& aF=aIt2.Value();
733 aOrF=aF.Orientation();
734 //
735 if (myImages.IsBound(aF)) {
736 const BOPCol_ListOfShape& aLSp=myImages.Find(aF);
737 aItS.Initialize(aLSp);
738 for (; aItS.More(); aItS.Next()) {
739 aFx=aItS.Value();
740 //
741 if (myShapesSD.IsBound(aFx)) {
742 aFSDx=myShapesSD.Find(aFx);
743 //
744 if (aOrF==TopAbs_INTERNAL) {
745 aFSDx.Orientation(aOrF);
746 theLIF.Append(aFSDx);
747 }
748 else {
1e143abb 749 bToReverse=BOPTools_AlgoTools::IsSplitToReverse
750 (aFSDx, aF, myContext);
4e57c75e 751 if (bToReverse) {
752 aFSDx.Reverse();
753 }
754 //
755 iFlag=1;
756 aBB.Add(aShD, aFSDx);
757 }
758 }//if (myShapesSD.IsBound(aFx)) {
759 else {
760 aFx.Orientation(aOrF);
761 if (aOrF==TopAbs_INTERNAL) {
762 theLIF.Append(aFx);
763 }
764 else{
765 iFlag=1;
766 aBB.Add(aShD, aFx);
767 }
768 }
769 }
770 } // if (myImages.IsBound(aF)) {
771 //
772 else {
773 if (aOrF==TopAbs_INTERNAL) {
774 theLIF.Append(aF);
775 }
776 else{
777 iFlag=1;
778 aBB.Add(aShD, aF);
779 }
780 }
781 } //for (; aIt2.More(); aIt2.Next()) {
782 //
783 if (iFlag) {
ab860031 784 aShD.Closed (BRep_Tool::IsClosed (aShD));
4e57c75e 785 aBB.Add(theDraftSolid, aShD);
786 }
787 } //for (; aIt1.More(); aIt1.Next()) {
788}
789//=======================================================================
790//function : BuildSplitSolids
791//purpose :
792//=======================================================================
a0a3f6ac 793void BOPAlgo_Builder::BuildSplitSolids
794 (BOPCol_DataMapOfShapeListOfShape& theInParts,
795 BOPCol_DataMapOfShapeShape& theDraftSolids,
796 const BOPCol_BaseAllocator& )
4e57c75e 797{
798 myErrorStatus=0;
799 //
800 Standard_Boolean bFlagSD;
96a95605 801 Standard_Integer i, aNbS;
4e57c75e 802 TopExp_Explorer aExp;
803 BOPCol_ListIteratorOfListOfShape aIt;
4e57c75e 804 //
744511c8 805 Handle(NCollection_IncAllocator) aAlr0;
806 aAlr0=new NCollection_IncAllocator();
807 //
808 BOPCol_ListOfShape aSFS(aAlr0), aLSEmpty(aAlr0);
809 BOPCol_MapOfShape aMFence(100, aAlr0);
810 BOPTools_MapOfSet aMST(100, aAlr0);
30ecd5f8 811 BOPAlgo_VectorOfBuilderSolid aVBS;
4e57c75e 812 //
813 // 0. Find same domain solids for non-interferred solids
814 aNbS=myDS->NbSourceShapes();
815 for (i=0; i<aNbS; ++i) {
816 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
817 //
818 if (aSI.ShapeType()!=TopAbs_SOLID) {
819 continue;
820 }
821 //
822 const TopoDS_Shape& aS=aSI.Shape();
823 if (!aMFence.Add(aS)) {
824 continue;
825 }
826 if(theDraftSolids.IsBound(aS)) {
827 continue;
828 }
829 //
830 BOPTools_Set aST;
831 //
832 aST.Add(aS, TopAbs_FACE);
833 aMST.Add(aST);
834 //
835 } //for (i=1; i<=aNbS; ++i)
836 //
837 // 1. Build solids for interferred source solids
838 for (i=0; i<aNbS; ++i) {
839 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
840 //
841 if (aSI.ShapeType()!=TopAbs_SOLID) {
842 continue;
843 }
844 //
845 const TopoDS_Shape& aS=aSI.Shape();
30ecd5f8 846 const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS));
4e57c75e 847 if(!theDraftSolids.IsBound(aS)) {
848 continue;
849 }
850 const TopoDS_Shape& aSD=theDraftSolids.Find(aS);
851 const BOPCol_ListOfShape& aLFIN=
852 (theInParts.IsBound(aS)) ? theInParts.Find(aS) : aLSEmpty;
853 //
854 // 1.1 Fill Shell Faces Set
855 aSFS.Clear();
856 aExp.Init(aSD, TopAbs_FACE);
857 for (; aExp.More(); aExp.Next()) {
858 const TopoDS_Shape& aF=aExp.Current();
859 aSFS.Append(aF);
860 }
861 //
862 aIt.Initialize(aLFIN);
863 for (; aIt.More(); aIt.Next()) {
864 TopoDS_Shape aF=aIt.Value();
865 //
866 aF.Orientation(TopAbs_FORWARD);
867 aSFS.Append(aF);
868 aF.Orientation(TopAbs_REVERSED);
869 aSFS.Append(aF);
870 }
871 //
744511c8 872 // 1.3 Build new solids
873 Handle(NCollection_IncAllocator) aAlr1;
874 aAlr1=new NCollection_IncAllocator();
875 //
30ecd5f8 876 BOPAlgo_BuilderSolid& aBS=aVBS.Append1();
877 aBS.SetSolid(aSolid);
878 aBS.SetShapes(aSFS);
465d1fba 879 aBS.SetRunParallel(myRunParallel);
36f4947b 880 aBS.SetProgressIndicator(myProgressIndicator);
30ecd5f8 881 }//for (i=0; i<aNbS; ++i) {
882 //
883 Standard_Integer k, aNbBS;
884 //
885 aNbBS=aVBS.Extent();
886 //
887 //===================================================
888 BOPAlgo_BuilderSolidCnt::Perform(myRunParallel, aVBS);
889 //===================================================
890 //
891 for (k=0; k<aNbBS; ++k) {
892 BOPAlgo_BuilderSolid& aBS=aVBS(k);
893 const TopoDS_Solid& aS=aBS.Solid();
894 const BOPCol_ListOfShape& aLSR=aBS.Areas();
4e57c75e 895 //
4e57c75e 896 if (!myImages.IsBound(aS)) {
897 BOPCol_ListOfShape aLSx;
898 //
899 myImages.Bind(aS, aLSx);
900 BOPCol_ListOfShape& aLSIm=myImages.ChangeFind(aS);
901 //
902 aIt.Initialize(aLSR);
903 for (; aIt.More(); aIt.Next()) {
904 BOPTools_Set aST;
905 //
906 const TopoDS_Shape& aSR=aIt.Value();
907 aST.Add(aSR, TopAbs_FACE);
908 //
909 bFlagSD=aMST.Contains(aST);
910 //
911 const BOPTools_Set& aSTx=aMST.Added(aST);
912 const TopoDS_Shape& aSx=aSTx.Shape();
913 aLSIm.Append(aSx);
914 //
915 if (bFlagSD) {
916 myShapesSD.Bind(aSR, aSx);
917 }
918 }
919 }
30ecd5f8 920 }
4e57c75e 921}
4e57c75e 922//=======================================================================
923//function :FillInternalShapes
924//purpose :
925//=======================================================================
744511c8 926void BOPAlgo_Builder::FillInternalShapes()
4e57c75e 927{
928 myErrorStatus=0;
929 //
96a95605 930 Standard_Integer i, j, aNbS, aNbSI, aNbSx;
4e57c75e 931 TopAbs_ShapeEnum aType;
932 TopAbs_State aState;
933 TopoDS_Iterator aItS;
934 BRep_Builder aBB;
4e57c75e 935 BOPCol_ListIteratorOfListOfShape aIt, aIt1;
936 //
937 Handle(NCollection_IncAllocator) aAllocator;
938 //-----------------------------------------------------scope f
939 aAllocator=new NCollection_IncAllocator();
940 //
941 BOPCol_IndexedDataMapOfShapeListOfShape aMSx(100, aAllocator);
942 BOPCol_IndexedMapOfShape aMx(100, aAllocator);
319da2e4 943 BOPCol_IndexedMapOfShape aMSI(100, aAllocator);
4e57c75e 944 BOPCol_MapOfShape aMFence(100, aAllocator);
945 BOPCol_MapOfShape aMSOr(100, aAllocator);
946 BOPCol_ListOfShape aLSd(aAllocator);
947 BOPCol_ListOfShape aLArgs(aAllocator);
c884a268 948 BOPCol_ListOfShape aLSC(aAllocator);
319da2e4 949 BOPCol_ListOfShape aLSI(aAllocator);
4e57c75e 950 //
951 // 1. Shapes to process
952 //
953 // 1.1 Shapes from pure arguments aMSI
954 // 1.1.1 vertex, edge, wire
955 //
8620e18d 956 const BOPCol_ListOfShape& aArguments=myDS->Arguments();
957 aIt.Initialize(aArguments);
4e57c75e 958 for (; aIt.More(); aIt.Next()) {
959 const TopoDS_Shape& aS=aIt.Value();
c884a268 960 TreatCompound(aS, aMFence, aLSC);
961 }
962 aIt.Initialize(aLSC);
963 for (; aIt.More(); aIt.Next()) {
964 const TopoDS_Shape& aS=aIt.Value();
4e57c75e 965 aType=aS.ShapeType();
966 if (aType==TopAbs_WIRE) {
967 aItS.Initialize(aS);
968 for(; aItS.More(); aItS.Next()) {
969 const TopoDS_Shape& aE=aItS.Value();
970 if (aMFence.Add(aE)) {
971 aLArgs.Append(aE);
972 }
973 }
974 }
975 else if (aType==TopAbs_VERTEX || aType==TopAbs_EDGE){
976 aLArgs.Append(aS);
977 }
978 }
979 aMFence.Clear();
980 //
981 aIt.Initialize(aLArgs);
982 for (; aIt.More(); aIt.Next()) {
983 const TopoDS_Shape& aS=aIt.Value();
984 aType=aS.ShapeType();
a0a3f6ac 985 if (aType==TopAbs_VERTEX ||
986 aType==TopAbs_EDGE ||
987 aType==TopAbs_WIRE) {
4e57c75e 988 if (aMFence.Add(aS)) {
989 if (myImages.IsBound(aS)) {
990 const BOPCol_ListOfShape &aLSp=myImages.Find(aS);
991 aIt1.Initialize(aLSp);
992 for (; aIt1.More(); aIt1.Next()) {
993 const TopoDS_Shape& aSp=aIt1.Value();
994 aMSI.Add(aSp);
995 }
996 }
997 else {
998 aMSI.Add(aS);
999 }
1000 }
1001 }
1002 }
1003
1004 aNbSI=aMSI.Extent();
1005 //
1006 // 2. Internal vertices, edges from source solids
1007 aMFence.Clear();
1008 aLSd.Clear();
1009 //
1010 aNbS=myDS->NbSourceShapes();
1011 for (i=0; i<aNbS; ++i) {
1012 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
1013 //
1014 if (aSI.ShapeType()!=TopAbs_SOLID) {
1015 continue;
1016 }
1017 //
36f4947b 1018 UserBreak();
1019 //
4e57c75e 1020 const TopoDS_Shape& aS=aSI.Shape();
1021 //
1022 aMx.Clear();
1023 OwnInternalShapes(aS, aMx);
1024 //
1025 aNbSx=aMx.Extent();
1026 for (j=1; j<=aNbSx; ++j) {
1027 const TopoDS_Shape& aSi=aMx(j);
1028 if (myImages.IsBound(aSi)) {
1029 const BOPCol_ListOfShape &aLSp=myImages.Find(aSi);
1030 aIt1.Initialize(aLSp);
1031 for (; aIt1.More(); aIt1.Next()) {
1032 const TopoDS_Shape& aSp=aIt1.Value();
1033 aMSI.Add(aSp);
1034 }
1035 }
1036 else {
1037 aMSI.Add(aSi);
1038 }
1039 }
1040 //
1041 // build aux map from splits of solids
1042 if (myImages.IsBound(aS)) {
1043 const BOPCol_ListOfShape &aLSp=myImages.Find(aS);
1044 aIt.Initialize(aLSp);
1045 for (; aIt.More(); aIt.Next()) {
1046 const TopoDS_Shape& aSp=aIt.Value();
1047 if (aMFence.Add(aSp)) {
1048 BOPTools::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_EDGE, aMSx);
1049 BOPTools::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_FACE, aMSx);
1050 BOPTools::MapShapesAndAncestors(aSp, TopAbs_EDGE , TopAbs_FACE, aMSx);
1051 aLSd.Append(aSp);
1052 }
1053 }
1054 }
1055 else {
1056 if (aMFence.Add(aS)) {
1057 BOPTools::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_EDGE, aMSx);
1058 BOPTools::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_FACE, aMSx);
1059 BOPTools::MapShapesAndAncestors(aS, TopAbs_EDGE , TopAbs_FACE, aMSx);
1060 aLSd.Append(aS);
1061 aMSOr.Add(aS);
1062 }
1063 }
1064 }// for (i=0; i<aNbS; ++i) {
1065 //
4e57c75e 1066 // 3. Some shapes of aMSI can be already tied with faces of
1067 // split solids
319da2e4 1068 aNbSI = aMSI.Extent();
1069 for (i = 1; i <= aNbSI; ++i) {
1070 const TopoDS_Shape& aSI = aMSI(i);
4e57c75e 1071 if (aMSx.Contains(aSI)) {
1072 const BOPCol_ListOfShape &aLSx=aMSx.FindFromKey(aSI);
319da2e4 1073 aNbSx = aLSx.Extent();
1074 if (!aNbSx) {
1075 aLSI.Append(aSI);
4e57c75e 1076 }
1077 }
319da2e4 1078 else {
1079 aLSI.Append(aSI);
1080 }
4e57c75e 1081 }
1082 //
1083 // 4. Just check it
319da2e4 1084 aNbSI = aLSI.Extent();
4e57c75e 1085 if (!aNbSI) {
1086 return;
1087 }
1088 //
1089 // 5 Settle internal vertices and edges into solids
1090 aMx.Clear();
1091 aIt.Initialize(aLSd);
1092 for (; aIt.More(); aIt.Next()) {
1093 TopoDS_Solid aSd=TopoDS::Solid(aIt.Value());
1094 //
319da2e4 1095 aIt1.Initialize(aLSI);
1096 for (; aIt1.More();) {
1097 TopoDS_Shape aSI = aIt1.Value();
4e57c75e 1098 aSI.Orientation(TopAbs_INTERNAL);
1099 //
0090ae85 1100 aState=BOPTools_AlgoTools::ComputeStateByOnePoint
1101 (aSI, aSd, 1.e-11, myContext);
319da2e4 1102 //
1103 if (aState != TopAbs_IN) {
1104 aIt1.Next();
1105 continue;
1106 }
1107 //
1108 if(aMSOr.Contains(aSd)) {
4e57c75e 1109 //
319da2e4 1110 TopoDS_Solid aSdx;
1111 //
1112 aBB.MakeSolid(aSdx);
1113 aItS.Initialize(aSd);
1114 for (; aItS.More(); aItS.Next()) {
1115 const TopoDS_Shape& aSh=aItS.Value();
1116 aBB.Add(aSdx, aSh);
4e57c75e 1117 }
319da2e4 1118 //
1119 aBB.Add(aSdx, aSI);
1120 //
1121 if (myImages.IsBound(aSdx)) {
1122 BOPCol_ListOfShape& aLS=myImages.ChangeFind(aSdx);
1123 aLS.Append(aSdx);
1124 }
4e57c75e 1125 else {
319da2e4 1126 BOPCol_ListOfShape aLS;
1127 aLS.Append(aSdx);
1128 myImages.Bind(aSd, aLS);
4e57c75e 1129 }
1130 //
319da2e4 1131 aMSOr.Remove(aSd);
1132 aSd=aSdx;
1133 }
1134 else {
1135 aBB.Add(aSd, aSI);
1136 }
1137 //
1138 aLSI.Remove(aIt1);
1139 }//for (; aIt1.More();) {
1140 }//for (; aIt.More(); aIt.Next()) {
4e57c75e 1141 //
1142 //-----------------------------------------------------scope t
1143 aLArgs.Clear();
1144 aLSd.Clear();
1145 aMSOr.Clear();
1146 aMFence.Clear();
1147 aMSI.Clear();
1148 aMx.Clear();
1149 aMSx.Clear();
1150}
1151//=======================================================================
1152//function : OwnInternalShapes
1153//purpose :
1154//=======================================================================
a0a3f6ac 1155void OwnInternalShapes(const TopoDS_Shape& theS,
1156 BOPCol_IndexedMapOfShape& theMx)
4e57c75e 1157{
1158 TopoDS_Iterator aIt;
1159 //
1160 aIt.Initialize(theS);
1161 for (; aIt.More(); aIt.Next()) {
1162 const TopoDS_Shape& aSx=aIt.Value();
1163 if (aSx.ShapeType()!=TopAbs_SHELL) {
1164 theMx.Add(aSx);
1165 }
1166 }
1167}
744511c8 1168//=======================================================================
c884a268 1169//function : TreatCompound
1170//purpose :
1171//=======================================================================
1172void TreatCompound(const TopoDS_Shape& theS,
1173 BOPCol_MapOfShape& aMFence,
1174 BOPCol_ListOfShape& theLS)
1175{
1176 TopAbs_ShapeEnum aType;
1177 //
1178 aType = theS.ShapeType();
1179 if (aType != TopAbs_COMPOUND) {
1180 if (aMFence.Add(theS)) {
1181 theLS.Append(theS);
1182 }
1183 return;
1184 }
1185 //
1186 TopoDS_Iterator aIt;
1187 //
1188 aIt.Initialize(theS);
1189 for (; aIt.More(); aIt.Next()) {
1190 const TopoDS_Shape& aS = aIt.Value();
1191 TreatCompound(aS, aMFence, theLS);
1192 }
1193}
4e57c75e 1194//
1195// ErrorStatus
1196// 30 - SolidBuilder failed
0090ae85 1197