0026619: Tolerances of operands are modified using bop
[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//
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
72static
4e57c75e 73 void OwnInternalShapes(const TopoDS_Shape& ,
74 BOPCol_IndexedMapOfShape& );
75
c884a268 76static
77 void TreatCompound(const TopoDS_Shape& theS,
78 BOPCol_MapOfShape& aMFence,
79 BOPCol_ListOfShape& theLS);
80
4e57c75e 81//=======================================================================
a0a3f6ac 82// BOPAlgo_BuilderSolid
83//
84typedef BOPCol_NCVector
85 <BOPAlgo_BuilderSolid> BOPAlgo_VectorOfBuilderSolid;
86//
c7b59798 87typedef BOPCol_Functor
a0a3f6ac 88 <BOPAlgo_BuilderSolid,
89 BOPAlgo_VectorOfBuilderSolid> BOPAlgo_BuilderSolidFunctor;
90//
c7b59798 91typedef BOPCol_Cnt
a0a3f6ac 92 <BOPAlgo_BuilderSolidFunctor,
93 BOPAlgo_VectorOfBuilderSolid> BOPAlgo_BuilderSolidCnt;
94//
95//=======================================================================
0090ae85 96// class: BOPAlgo_ShapeBox
97//
98//=======================================================================
744511c8 99//class : BOPAlgo_ShapeBox
100//purpose : Auxiliary class
101//=======================================================================
102class 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 131typedef BOPCol_NCVector<BOPAlgo_ShapeBox> BOPAlgo_VectorOfShapeBox;
132//
133//=======================================================================
134// class: BOPAlgo_FillIn3DParts
744511c8 135//
0090ae85 136//=======================================================================
137//class : BOPAlgo_FillIn3DParts
138//purpose :
139//=======================================================================
140class 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
249//=======================================================================
0090ae85 250//function : BOPAlgo_FillIn3DParts::Perform
251//purpose :
252//=======================================================================
253void 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) {
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 }
488e5b9d 521 //
522 Handle(NCollection_BaseAllocator) aAlr;
744511c8 523 //
488e5b9d 524 aAlr=NCollection_BaseAllocator::CommonBaseAllocator();
4e57c75e 525 //
744511c8 526 BOPCol_DataMapOfShapeListOfShape theInParts(100, aAlr);
527 BOPCol_DataMapOfShapeShape theDraftSolids(100, aAlr);
528 //
30ecd5f8 529 FillIn3DParts(theInParts, theDraftSolids, aAlr);
744511c8 530 BuildSplitSolids(theInParts, theDraftSolids, aAlr);
4e57c75e 531 FillInternalShapes();
532 //
533 theInParts.Clear();
534 theDraftSolids.Clear();
4e57c75e 535}
536//=======================================================================
537//function : FillIn3DParts
538//purpose :
539//=======================================================================
a0a3f6ac 540void BOPAlgo_Builder::FillIn3DParts
541 (BOPCol_DataMapOfShapeListOfShape& theInParts,
542 BOPCol_DataMapOfShapeShape& theDraftSolids,
543 const BOPCol_BaseAllocator& )
4e57c75e 544{
744511c8 545 Standard_Boolean bHasImage;
0090ae85 546 Standard_Integer i, k, aNbS, aNbLIF, aNbFIN, aNbVSB, aNbVFIP;
488e5b9d 547 Handle(NCollection_BaseAllocator) aAlr0;
744511c8 548 TopoDS_Solid aSD;
549 TopoDS_Iterator aIt;
550 BRep_Builder aBB;
0090ae85 551 //
744511c8 552 BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1;
553 BOPCol_ListIteratorOfListOfShape aItLS;
4e57c75e 554 //
488e5b9d 555 aAlr0=
556 NCollection_BaseAllocator::CommonBaseAllocator();
0090ae85 557 //
558 BOPCol_MapOfShape aMFence(100, aAlr0);
559 BOPAlgo_VectorOfShapeBox aVSB(256, aAlr0);
4e57c75e 560 //
744511c8 561 myErrorStatus=0;
4e57c75e 562 theDraftSolids.Clear();
563 //
0090ae85 564 // 1. aVSB vector Index/FaceBox
4e57c75e 565 aNbS=myDS->NbSourceShapes();
566 for (i=0; i<aNbS; ++i) {
567 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
744511c8 568 if (aSI.ShapeType()!=TopAbs_FACE) {
569 continue;
570 }
571 //
4e57c75e 572 const TopoDS_Shape& aS=aSI.Shape();
573 //
744511c8 574 if (myImages.IsBound(aS)) {
575 const BOPCol_ListOfShape& aLS=myImages.Find(aS);
576 aItLS.Initialize(aLS);
577 for (; aItLS.More(); aItLS.Next()) {
a0a3f6ac 578 const TopoDS_Shape& aSx=aItLS.Value();
0090ae85 579 if (!aMFence.Add(aSx)) {
580 continue;
581 }
a0a3f6ac 582 Bnd_Box aBox;
583 BRepBndLib::Add(aSx, aBox);
3510db62 584 aBox.SetGap(aBox.GetGap() + Precision::Confusion());
a0a3f6ac 585 //
0090ae85 586 BOPAlgo_ShapeBox& aSB=aVSB.Append1();
a0a3f6ac 587 aSB.SetShape(aSx);
588 aSB.SetBox(aBox);
4e57c75e 589 }
744511c8 590 }
591 else {
592 const Bnd_Box& aBox=aSI.Box();
4e57c75e 593 //
0090ae85 594 BOPAlgo_ShapeBox& aSB=aVSB.Append1();
744511c8 595 aSB.SetShape(aS);
596 aSB.SetBox(aBox);
4e57c75e 597 }
744511c8 598 }//for (i=0; i<aNbS; ++i) {
0090ae85 599 aMFence.Clear();
4e57c75e 600 //
30ecd5f8 601 // 1.2. Prepare TreeFiller
db8e4b9a 602 BOPCol_BoxBndTree aBBTree;
0090ae85 603 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box>
604 aTreeFiller(aBBTree);
30ecd5f8 605 //
0090ae85 606 aNbVSB=aVSB.Extent();
607 for (k=0; k<aNbVSB; ++k) {
608 const BOPAlgo_ShapeBox& aSBk=aVSB(k);
30ecd5f8 609 const Bnd_Box& aBk=aSBk.Box();
610 //
611 aTreeFiller.Add(k, aBk);
612 }
613 //
614 // 1.3. Shake TreeFiller
615 aTreeFiller.Fill();
616 //
617 //---------------------------------------------
744511c8 618 // 2. Solids
0090ae85 619 BOPAlgo_VectorOfFillIn3DParts aVFIP;
620 //
744511c8 621 for (i=0; i<aNbS; ++i) {
622 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
623 if (aSI.ShapeType()!=TopAbs_SOLID) {
624 continue;
625 }
72e88cf7 626 //
744511c8 627 const TopoDS_Shape& aS=aSI.Shape();
628 const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS));
4e57c75e 629 //
744511c8 630 // 2.0 Flag bHasImage
4e57c75e 631 bHasImage=Standard_False;
744511c8 632 aIt.Initialize(aS);
4e57c75e 633 for (; aIt.More(); aIt.Next()) {
634 const TopoDS_Shape& aShell=aIt.Value();
744511c8 635 bHasImage=myImages.IsBound(aShell);
636 if (bHasImage){
a0a3f6ac 637 break;
4e57c75e 638 }
639 }
640 //
30ecd5f8 641 // 2.1 Bounding box for the solid aS [ aBoxS ]
0090ae85 642 Bnd_Box aBoxS;
30ecd5f8 643 aBoxS=aSI.Box();
4e57c75e 644 //
744511c8 645 // 2.2 Build Draft Solid [aSD]
0090ae85 646 BOPCol_ListOfShape aLIF;
4e57c75e 647 //
0090ae85 648 aBB.MakeSolid(aSD);
744511c8 649 BuildDraftSolid(aSolid, aSD, aLIF);
744511c8 650 //
0090ae85 651 BOPAlgo_FillIn3DParts& aFIP=aVFIP.Append1();
744511c8 652 //
0090ae85 653 aFIP.SetSolid(aSolid);
654 aFIP.SetDraftSolid(aSD);
655 aFIP.SetHasImage(bHasImage);
656 aFIP.SetBoxS(aBoxS);
657 aFIP.SetLIF(aLIF);
658 aFIP.SetBBTree(aBBTree);
659 aFIP.SetVSB(aVSB);
660 }//for (i=0; i<aNbS; ++i) {
661 //
662 aNbVFIP=aVFIP.Extent();
663 //================================================================
664 BOPAlgo_FillIn3DPartsCnt::Perform(myRunParallel, aVFIP, myContext);
665 //================================================================
666 for (k=0; k<aNbVFIP; ++k) {
667 BOPAlgo_FillIn3DParts& aFIP=aVFIP(k);
668 bHasImage=aFIP.HasImage();
669 const TopoDS_Solid& aSolid=aFIP.Solid();
51740958 670 const TopoDS_Solid& aSDraft =aFIP.DraftSolid();
0090ae85 671 const BOPCol_ListOfShape& aLFIN=aFIP.LFIN();
672 const BOPCol_ListOfShape& aLIF=aFIP.LIF();
744511c8 673 //
0090ae85 674 aNbLIF=aLIF.Extent();
744511c8 675 //
0090ae85 676 // Store the results in theInParts, theDraftSolids
677 BOPCol_ListOfShape aLFINx;
4e57c75e 678 //
744511c8 679 aNbFIN=aLFIN.Extent();
4e57c75e 680 if (aNbFIN || aNbLIF) {
0090ae85 681 aItLS.Initialize(aLFIN);
682 for (; aItLS.More(); aItLS.Next()) {
683 const TopoDS_Shape& aFI=aItLS.Value();
684 aLFINx.Append(aFI);
685 }
744511c8 686 aItLS.Initialize(aLIF);
687 for (; aItLS.More(); aItLS.Next()) {
a0a3f6ac 688 const TopoDS_Shape& aFI=aItLS.Value();
0090ae85 689 aLFINx.Append(aFI);
4e57c75e 690 }
0090ae85 691 theInParts.Bind(aSolid, aLFINx);
4e57c75e 692 }
744511c8 693 //
4e57c75e 694 if (aNbFIN || bHasImage) {
51740958 695 theDraftSolids.Bind(aSolid, aSDraft);
4e57c75e 696 }
0090ae85 697 }
4e57c75e 698}
699//=======================================================================
700//function : BuildDraftSolid
701//purpose :
702//=======================================================================
744511c8 703void BOPAlgo_Builder::BuildDraftSolid(const TopoDS_Shape& theSolid,
a0a3f6ac 704 TopoDS_Shape& theDraftSolid,
705 BOPCol_ListOfShape& theLIF)
4e57c75e 706{
707 myErrorStatus=0;
708 //
709 Standard_Boolean bToReverse;
710 Standard_Integer iFlag;
711 TopAbs_Orientation aOrF, aOrSh, aOrSd;
712 TopoDS_Iterator aIt1, aIt2;
713 TopoDS_Shell aShD;
714 TopoDS_Shape aFSDx, aFx;
715 BRep_Builder aBB;
a0a3f6ac 716 BOPCol_ListIteratorOfListOfShape aItS;
4e57c75e 717 //
718 aOrSd=theSolid.Orientation();
719 theDraftSolid.Orientation(aOrSd);
720 //
721 aIt1.Initialize(theSolid);
722 for (; aIt1.More(); aIt1.Next()) {
723 const TopoDS_Shape& aSh=aIt1.Value();
724 if(aSh.ShapeType()!=TopAbs_SHELL) {
725 continue; // mb internal edges,vertices
726 }
727 //
728 aOrSh=aSh.Orientation();
729 aBB.MakeShell(aShD);
730 aShD.Orientation(aOrSh);
731 iFlag=0;
732 //
733 aIt2.Initialize(aSh);
734 for (; aIt2.More(); aIt2.Next()) {
735 const TopoDS_Shape& aF=aIt2.Value();
736 aOrF=aF.Orientation();
737 //
738 if (myImages.IsBound(aF)) {
739 const BOPCol_ListOfShape& aLSp=myImages.Find(aF);
740 aItS.Initialize(aLSp);
741 for (; aItS.More(); aItS.Next()) {
742 aFx=aItS.Value();
743 //
744 if (myShapesSD.IsBound(aFx)) {
745 aFSDx=myShapesSD.Find(aFx);
746 //
747 if (aOrF==TopAbs_INTERNAL) {
748 aFSDx.Orientation(aOrF);
749 theLIF.Append(aFSDx);
750 }
751 else {
1e143abb 752 bToReverse=BOPTools_AlgoTools::IsSplitToReverse
753 (aFSDx, aF, myContext);
4e57c75e 754 if (bToReverse) {
755 aFSDx.Reverse();
756 }
757 //
758 iFlag=1;
759 aBB.Add(aShD, aFSDx);
760 }
761 }//if (myShapesSD.IsBound(aFx)) {
762 else {
763 aFx.Orientation(aOrF);
764 if (aOrF==TopAbs_INTERNAL) {
765 theLIF.Append(aFx);
766 }
767 else{
768 iFlag=1;
769 aBB.Add(aShD, aFx);
770 }
771 }
772 }
773 } // if (myImages.IsBound(aF)) {
774 //
775 else {
776 if (aOrF==TopAbs_INTERNAL) {
777 theLIF.Append(aF);
778 }
779 else{
780 iFlag=1;
781 aBB.Add(aShD, aF);
782 }
783 }
784 } //for (; aIt2.More(); aIt2.Next()) {
785 //
786 if (iFlag) {
ab860031 787 aShD.Closed (BRep_Tool::IsClosed (aShD));
4e57c75e 788 aBB.Add(theDraftSolid, aShD);
789 }
790 } //for (; aIt1.More(); aIt1.Next()) {
791}
792//=======================================================================
793//function : BuildSplitSolids
794//purpose :
795//=======================================================================
a0a3f6ac 796void BOPAlgo_Builder::BuildSplitSolids
797 (BOPCol_DataMapOfShapeListOfShape& theInParts,
798 BOPCol_DataMapOfShapeShape& theDraftSolids,
799 const BOPCol_BaseAllocator& )
4e57c75e 800{
801 myErrorStatus=0;
802 //
803 Standard_Boolean bFlagSD;
96a95605 804 Standard_Integer i, aNbS;
4e57c75e 805 TopExp_Explorer aExp;
806 BOPCol_ListIteratorOfListOfShape aIt;
4e57c75e 807 //
488e5b9d 808 Handle(NCollection_BaseAllocator) aAlr0;
809 aAlr0=NCollection_BaseAllocator::CommonBaseAllocator();
744511c8 810 //
811 BOPCol_ListOfShape aSFS(aAlr0), aLSEmpty(aAlr0);
812 BOPCol_MapOfShape aMFence(100, aAlr0);
813 BOPTools_MapOfSet aMST(100, aAlr0);
30ecd5f8 814 BOPAlgo_VectorOfBuilderSolid aVBS;
4e57c75e 815 //
816 // 0. Find same domain solids for non-interferred solids
817 aNbS=myDS->NbSourceShapes();
818 for (i=0; i<aNbS; ++i) {
819 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
820 //
821 if (aSI.ShapeType()!=TopAbs_SOLID) {
822 continue;
823 }
824 //
825 const TopoDS_Shape& aS=aSI.Shape();
826 if (!aMFence.Add(aS)) {
827 continue;
828 }
829 if(theDraftSolids.IsBound(aS)) {
830 continue;
831 }
832 //
833 BOPTools_Set aST;
834 //
835 aST.Add(aS, TopAbs_FACE);
836 aMST.Add(aST);
837 //
838 } //for (i=1; i<=aNbS; ++i)
839 //
840 // 1. Build solids for interferred source solids
841 for (i=0; i<aNbS; ++i) {
842 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
843 //
844 if (aSI.ShapeType()!=TopAbs_SOLID) {
845 continue;
846 }
847 //
848 const TopoDS_Shape& aS=aSI.Shape();
30ecd5f8 849 const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS));
4e57c75e 850 if(!theDraftSolids.IsBound(aS)) {
851 continue;
852 }
853 const TopoDS_Shape& aSD=theDraftSolids.Find(aS);
854 const BOPCol_ListOfShape& aLFIN=
855 (theInParts.IsBound(aS)) ? theInParts.Find(aS) : aLSEmpty;
856 //
857 // 1.1 Fill Shell Faces Set
858 aSFS.Clear();
859 aExp.Init(aSD, TopAbs_FACE);
860 for (; aExp.More(); aExp.Next()) {
861 const TopoDS_Shape& aF=aExp.Current();
862 aSFS.Append(aF);
863 }
864 //
865 aIt.Initialize(aLFIN);
866 for (; aIt.More(); aIt.Next()) {
867 TopoDS_Shape aF=aIt.Value();
868 //
869 aF.Orientation(TopAbs_FORWARD);
870 aSFS.Append(aF);
871 aF.Orientation(TopAbs_REVERSED);
872 aSFS.Append(aF);
873 }
874 //
488e5b9d 875 // 1.3 Build new solids
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 //
488e5b9d 937 Handle(NCollection_BaseAllocator) aAllocator;
4e57c75e 938 //-----------------------------------------------------scope f
488e5b9d 939 aAllocator=NCollection_BaseAllocator::CommonBaseAllocator();
4e57c75e 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