0028259: Method MakeBlocksCnx is duplicated in two different places in BOPAlgo
[occt.git] / src / BOPAlgo / BOPAlgo_Builder_2.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.
4e57c75e 17
42cf5bc1 18
19#include <BOPAlgo_Builder.hxx>
20#include <BOPAlgo_BuilderFace.hxx>
21#include <BOPAlgo_PaveFiller.hxx>
edfa30de 22#include <BOPAlgo_Tools.hxx>
4e57c75e 23#include <BOPCol_DataMapOfIntegerListOfShape.hxx>
24#include <BOPCol_DataMapOfShapeShape.hxx>
42cf5bc1 25#include <BOPCol_ListOfInteger.hxx>
26#include <BOPCol_ListOfShape.hxx>
27#include <BOPCol_MapOfInteger.hxx>
a0a3f6ac 28#include <BOPCol_NCVector.hxx>
c7b59798 29#include <BOPCol_Parallel.hxx>
4e57c75e 30#include <BOPDS_DS.hxx>
31#include <BOPDS_FaceInfo.hxx>
4e57c75e 32#include <BOPDS_Interf.hxx>
42cf5bc1 33#include <BOPDS_MapOfPaveBlock.hxx>
34#include <BOPDS_PaveBlock.hxx>
35#include <BOPDS_ShapeInfo.hxx>
4e57c75e 36#include <BOPDS_VectorOfCurve.hxx>
42cf5bc1 37#include <BOPDS_VectorOfInterfFF.hxx>
4e57c75e 38#include <BOPDS_VectorOfPoint.hxx>
4e57c75e 39#include <BOPTools.hxx>
40#include <BOPTools_AlgoTools.hxx>
acccace3 41#include <BOPTools_AlgoTools2D.hxx>
4e57c75e 42#include <BOPTools_AlgoTools3D.hxx>
4e57c75e 43#include <BOPTools_CoupleOfShape.hxx>
42cf5bc1 44#include <BOPTools_DataMapOfShapeSet.hxx>
4e57c75e 45#include <BOPTools_ListOfCoupleOfShape.hxx>
46#include <BOPTools_MapOfSet.hxx>
42cf5bc1 47#include <BRep_Builder.hxx>
48#include <BRep_Tool.hxx>
39067947 49#include <GeomAdaptor_Surface.hxx>
50#include <GeomLib.hxx>
51#include <Precision.hxx>
42cf5bc1 52#include <IntTools_Context.hxx>
42cf5bc1 53#include <TopExp_Explorer.hxx>
54#include <TopoDS_Compound.hxx>
55#include <TopoDS_Edge.hxx>
56#include <TopoDS_Face.hxx>
57#include <TopoDS_Shape.hxx>
58#include <TopoDS_Vertex.hxx>
4e57c75e 59
42cf5bc1 60//
4e57c75e 61static
62 Standard_Boolean HasPaveBlocksOnIn(const BOPDS_FaceInfo& aFI1,
63 const BOPDS_FaceInfo& aFI2);
a0a3f6ac 64//
65typedef BOPCol_NCVector<TopoDS_Shape> BOPAlgo_VectorOfShape;
66//
67typedef BOPCol_NCVector<BOPAlgo_VectorOfShape> \
68 BOPAlgo_VectorOfVectorOfShape;
69//
70typedef NCollection_IndexedDataMap\
71 <BOPTools_Set, Standard_Integer, BOPTools_SetMapHasher> \
72 BOPAlgo_IndexedDataMapOfSetInteger;
73//
74//=======================================================================
75//class : BOPAlgo_PairOfShapeBoolean
76//purpose :
77//=======================================================================
36f4947b 78class BOPAlgo_PairOfShapeBoolean : public BOPAlgo_Algo {
79
a0a3f6ac 80 public:
36f4947b 81 DEFINE_STANDARD_ALLOC
82
83 BOPAlgo_PairOfShapeBoolean() :
84 BOPAlgo_Algo(),
85 myFlag(Standard_False) {
86 }
87 //
88 virtual ~BOPAlgo_PairOfShapeBoolean() {
a0a3f6ac 89 }
90 //
91 TopoDS_Shape& Shape1() {
92 return myShape1;
93 }
94 //
95 TopoDS_Shape& Shape2() {
96 return myShape2;
97 }
98 //
99 Standard_Boolean& Flag() {
100 return myFlag;
101 }
102 //
36f4947b 103 void SetContext(const Handle(IntTools_Context)& aContext) {
104 myContext=aContext;
105 }
106 //
107 const Handle(IntTools_Context)& Context()const {
108 return myContext;
109 }
110 //
111 virtual void Perform() {
112 BOPAlgo_Algo::UserBreak();
113 //
114 const TopoDS_Face& aFj=*((TopoDS_Face*)&myShape1);
115 const TopoDS_Face& aFk=*((TopoDS_Face*)&myShape2);
0d0481c7 116 myFlag=BOPTools_AlgoTools::AreFacesSameDomain(aFj, aFk, myContext, myFuzzyValue);
36f4947b 117 }
118 //
a0a3f6ac 119 protected:
120 Standard_Boolean myFlag;
121 TopoDS_Shape myShape1;
122 TopoDS_Shape myShape2;
36f4947b 123 Handle(IntTools_Context) myContext;
a0a3f6ac 124};
125//
126typedef BOPCol_NCVector<BOPAlgo_PairOfShapeBoolean> \
127 BOPAlgo_VectorOfPairOfShapeBoolean;
128//
c7b59798 129typedef BOPCol_ContextFunctor
36f4947b 130 <BOPAlgo_PairOfShapeBoolean,
131 BOPAlgo_VectorOfPairOfShapeBoolean,
132 Handle(IntTools_Context),
133 IntTools_Context> BOPCol_BuilderSDFaceFunctor;
134//
c7b59798 135typedef BOPCol_ContextCnt
36f4947b 136 <BOPCol_BuilderSDFaceFunctor,
137 BOPAlgo_VectorOfPairOfShapeBoolean,
138 Handle(IntTools_Context)> BOPAlgo_BuilderSDFaceCnt;
a0a3f6ac 139//
a0a3f6ac 140//=======================================================================
141// BuilderFace
142//
143typedef BOPCol_NCVector<BOPAlgo_BuilderFace> BOPAlgo_VectorOfBuilderFace;
144//
c7b59798 145typedef BOPCol_Functor
a0a3f6ac 146 <BOPAlgo_BuilderFace,
147 BOPAlgo_VectorOfBuilderFace> BOPAlgo_BuilderFaceFunctor;
148//
c7b59798 149typedef BOPCol_Cnt
a0a3f6ac 150 <BOPAlgo_BuilderFaceFunctor,
151 BOPAlgo_VectorOfBuilderFace> BOPAlgo_BuilderFaceCnt;
152//
153//=======================================================================
154//class : BOPAlgo_VFI
155//purpose :
156//=======================================================================
36f4947b 157class BOPAlgo_VFI : public BOPAlgo_Algo {
158
a0a3f6ac 159 public:
36f4947b 160 DEFINE_STANDARD_ALLOC
161
162 BOPAlgo_VFI() :
163 BOPAlgo_Algo(),
164 myFlag(-1) {
a0a3f6ac 165 }
166 //
36f4947b 167 virtual ~BOPAlgo_VFI(){
a0a3f6ac 168 }
169 //
170 void SetVertex(const TopoDS_Vertex& aV) {
171 myV=aV;
172 }
173 //
174 TopoDS_Vertex& Vertex() {
175 return myV;
176 }
177 //
178 void SetFace(const TopoDS_Face& aF) {
179 myF=aF;
180 }
181 //
182 TopoDS_Face& Face() {
183 return myF;
184 }
185 //
186 Standard_Integer Flag()const {
187 return myFlag;
188 }
189 //
1e143abb 190 void SetContext(const Handle(IntTools_Context)& aContext) {
a0a3f6ac 191 myContext=aContext;
192 }
193 //
1e143abb 194 const Handle(IntTools_Context)& Context()const {
a0a3f6ac 195 return myContext;
196 }
197 //
36f4947b 198 virtual void Perform() {
3510db62 199 Standard_Real aT1, aT2, dummy;
a0a3f6ac 200 //
36f4947b 201 BOPAlgo_Algo::UserBreak();
0d0481c7 202 myFlag = myContext->ComputeVF(myV, myF, aT1, aT2, dummy, myFuzzyValue);
a0a3f6ac 203 }
204 //
205 protected:
206 Standard_Integer myFlag;
207 TopoDS_Vertex myV;
208 TopoDS_Face myF;
1e143abb 209 Handle(IntTools_Context) myContext;
a0a3f6ac 210};
211//
212typedef BOPCol_NCVector<BOPAlgo_VFI> BOPAlgo_VectorOfVFI;
213//
c7b59798 214typedef BOPCol_ContextFunctor
a0a3f6ac 215 <BOPAlgo_VFI,
216 BOPAlgo_VectorOfVFI,
1e143abb 217 Handle(IntTools_Context),
218 IntTools_Context> BOPAlgo_VFIFunctor;
a0a3f6ac 219//
c7b59798 220typedef BOPCol_ContextCnt
a0a3f6ac 221 <BOPAlgo_VFIFunctor,
222 BOPAlgo_VectorOfVFI,
1e143abb 223 Handle(IntTools_Context)> BOPAlgo_VFICnt;
a0a3f6ac 224//
4e57c75e 225//=======================================================================
226//function : FillImagesFaces
227//purpose :
228//=======================================================================
acccace3 229void BOPAlgo_Builder::FillImagesFaces()
4e57c75e 230{
231 myErrorStatus=0;
232 //
233 BuildSplitFaces();
234 FillSameDomainFaces();
235 FillImagesFaces1();
236}
237//=======================================================================
238//function : BuildSplitFaces
239//purpose :
240//=======================================================================
acccace3 241void BOPAlgo_Builder::BuildSplitFaces()
4e57c75e 242{
243 Standard_Boolean bHasFaceInfo, bIsClosed, bIsDegenerated, bToReverse;
37e640d5 244 Standard_Integer i, j, k, aNbS, aNbPBIn, aNbPBOn, aNbPBSc, aNbAV, nSp;
37e640d5 245 Standard_Size aNbBF;
4e57c75e 246 TopoDS_Face aFF, aFSD;
247 TopoDS_Edge aSp, aEE;
248 TopAbs_Orientation anOriF, anOriE;
249 TopExp_Explorer aExp;
250 BOPCol_ListIteratorOfListOfShape aIt;
251 BOPCol_ListOfInteger aLIAV;
252 BOPCol_MapOfShape aMFence;
acccace3 253 Handle(NCollection_BaseAllocator) aAllocator;
4e57c75e 254 BOPCol_ListOfShape aLFIm(myAllocator);
acccace3 255 BOPAlgo_VectorOfBuilderFace aVBF;
4e57c75e 256 //
257 myErrorStatus=0;
258 //
259 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~scope f
488e5b9d 260 aAllocator=
261 NCollection_BaseAllocator::CommonBaseAllocator();
4e57c75e 262 //
263 BOPCol_ListOfShape aLE(aAllocator);
264 BOPCol_MapOfShape aMDE(100, aAllocator);
265 //
266 aNbS=myDS->NbSourceShapes();
acccace3 267 //
4e57c75e 268 for (i=0; i<aNbS; ++i) {
269 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
270 if (aSI.ShapeType()!=TopAbs_FACE) {
271 continue;
272 }
273 //
274 const TopoDS_Face& aF=(*(TopoDS_Face*)(&aSI.Shape()));
39067947 275 Standard_Boolean isUClosed = Standard_False,
276 isVClosed = Standard_False,
277 isChecked = Standard_False;
4e57c75e 278 //
279 bHasFaceInfo=myDS->HasFaceInfo(i);
280 if(!bHasFaceInfo) {
281 continue;
282 }
283 //
4e57c75e 284 const BOPDS_FaceInfo& aFI=myDS->FaceInfo(i);
285 //
286 const BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.PaveBlocksIn();
287 const BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.PaveBlocksOn();
288 const BOPDS_IndexedMapOfPaveBlock& aMPBSc=aFI.PaveBlocksSc();
289 aLIAV.Clear();
290 myDS->AloneVertices(i, aLIAV);
291
292 aNbPBIn=aMPBIn.Extent();
293 aNbPBOn=aMPBOn.Extent();
294 aNbPBSc=aMPBSc.Extent();
295 aNbAV=aLIAV.Extent();
296 if (!aNbPBIn && !aNbPBOn && !aNbPBSc && !aNbAV) { // not compete
297 continue;
298 }
299 //
300 aMFence.Clear();
301 //
302 anOriF=aF.Orientation();
303 aFF=aF;
304 aFF.Orientation(TopAbs_FORWARD);
305 //
4e57c75e 306 // 1. Fill the egdes set for the face aFF -> LE
307 aLE.Clear();
308 //
309 //
310 // 1.1 Bounding edges
311 aExp.Init(aFF, TopAbs_EDGE);
312 for (; aExp.More(); aExp.Next()) {
313 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current()));
314 anOriE=aE.Orientation();
4e57c75e 315 //
316 if (!myImages.IsBound(aE)) {
317 if (anOriE==TopAbs_INTERNAL) {
318 aEE=aE;
319 aEE.Orientation(TopAbs_FORWARD);
320 aLE.Append(aEE);
321 aEE.Orientation(TopAbs_REVERSED);
322 aLE.Append(aEE);
323 }
324 else {
325 aLE.Append(aE);
326 }
39067947 327
328 continue;
4e57c75e 329 }
39067947 330
331 if(!isChecked)
332 {
333 const Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aF);
334 GeomLib::IsClosed(aSurf, BRep_Tool::Tolerance(aE),
335 isUClosed, isVClosed);
336
337 isChecked = Standard_True;
338 }
339
340 bIsClosed = Standard_False;
341
342 if((isUClosed || isVClosed) && BRep_Tool::IsClosed(aE, aF))
343 {
344
345 Standard_Boolean isUIso = Standard_False, isVIso = Standard_False;
346 BOPTools_AlgoTools2D::IsEdgeIsoline(aE, aF, isUIso, isVIso);
347
348 bIsClosed = ((isUClosed && isUIso) || (isVClosed && isVIso));
349 }
350
351 bIsDegenerated=BRep_Tool::Degenerated(aE);
352
353 const BOPCol_ListOfShape& aLIE=myImages.Find(aE);
354 aIt.Initialize(aLIE);
355 for (; aIt.More(); aIt.Next()) {
356 aSp=(*(TopoDS_Edge*)(&aIt.Value()));
357 if (bIsDegenerated) {
358 aSp.Orientation(anOriE);
359 aLE.Append(aSp);
360 continue;
361 }
362 //
363 if (anOriE==TopAbs_INTERNAL) {
364 aSp.Orientation(TopAbs_FORWARD);
365 aLE.Append(aSp);
366 aSp.Orientation(TopAbs_REVERSED);
367 aLE.Append(aSp);
368 continue;
369 }
4e57c75e 370 //
39067947 371 if (bIsClosed) {
372 if (aMFence.Add(aSp)) {
373 if (!BRep_Tool::IsClosed(aSp, aF)){
374 BOPTools_AlgoTools3D::DoSplitSEAMOnFace(aSp, aF);
375 }
376 //
4e57c75e 377 aSp.Orientation(TopAbs_FORWARD);
378 aLE.Append(aSp);
379 aSp.Orientation(TopAbs_REVERSED);
380 aLE.Append(aSp);
39067947 381 }// if (aMFence.Add(aSp))
382 continue;
383 }// if (bIsClosed){
384 //
385 aSp.Orientation(anOriE);
386 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aSp, aE, myContext);
387 if (bToReverse) {
388 aSp.Reverse();
389 }
390 aLE.Append(aSp);
391 }// for (; aIt.More(); aIt.Next()) {
4e57c75e 392 }// for (; aExp.More(); aExp.Next()) {
393 //
394 //
395 // 1.2 In edges
396 for (j=1; j<=aNbPBIn; ++j) {
397 const Handle(BOPDS_PaveBlock)& aPB=aMPBIn(j);
398 nSp=aPB->Edge();
399 aSp=(*(TopoDS_Edge*)(&myDS->Shape(nSp)));
400 //
401 aSp.Orientation(TopAbs_FORWARD);
402 aLE.Append(aSp);
403 aSp.Orientation(TopAbs_REVERSED);
404 aLE.Append(aSp);
405 }
406 //
407 //
408 // 1.3 Section edges
409 for (j=1; j<=aNbPBSc; ++j) {
410 const Handle(BOPDS_PaveBlock)& aPB=aMPBSc(j);
411 nSp=aPB->Edge();
412 aSp=(*(TopoDS_Edge*)(&myDS->Shape(nSp)));
413 //
414 aSp.Orientation(TopAbs_FORWARD);
415 aLE.Append(aSp);
416 aSp.Orientation(TopAbs_REVERSED);
417 aLE.Append(aSp);
418 }
419 //
3510db62 420 if (!myPaveFiller->NonDestructive()) {
421 // speed up for planar faces
422 BOPTools_AlgoTools2D::BuildPCurveForEdgesOnPlane (aLE, aFF);
423 }
acccace3 424 // 3 Build split faces
425 BOPAlgo_BuilderFace& aBF=aVBF.Append1();
426 aBF.SetFace(aF);
4e57c75e 427 aBF.SetShapes(aLE);
db8e4b9a 428 aBF.SetRunParallel(myRunParallel);
36f4947b 429 aBF.SetProgressIndicator(myProgressIndicator);
4e57c75e 430 //
acccace3 431 }// for (i=0; i<aNbS; ++i) {
432 //
433 aNbBF=aVBF.Extent();
434 //
435 //===================================================
796a784d 436 BOPAlgo_BuilderFaceCnt::Perform(myRunParallel, aVBF);
acccace3 437 //===================================================
438 //
37e640d5 439 for (k=0; k<(Standard_Integer)aNbBF; ++k) {
acccace3 440 aLFIm.Clear();
441 //
442 BOPAlgo_BuilderFace& aBF=aVBF(k);
443 TopoDS_Face aF=aBF.Face();
444 anOriF=aBF.Orientation();
445 aF.Orientation(anOriF);
4e57c75e 446 //
447 const BOPCol_ListOfShape& aLFR=aBF.Areas();
448 aIt.Initialize(aLFR);
449 for (; aIt.More(); aIt.Next()) {
450 TopoDS_Shape& aFR=aIt.ChangeValue();
451 if (anOriF==TopAbs_REVERSED) {
452 aFR.Orientation(TopAbs_REVERSED);
453 }
454 //aFR.Orientation(anOriF);
455 aLFIm.Append(aFR);
4e57c75e 456 }
457 //
458 mySplits.Bind(aF, aLFIm);
acccace3 459 }// for (k=0; k<aNbBF; ++k) {
4e57c75e 460 //
4e57c75e 461 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~scope t
462}
463//=======================================================================
464//function : FillSameDomainFaces
465//purpose :
466//=======================================================================
acccace3 467void BOPAlgo_Builder::FillSameDomainFaces()
4e57c75e 468{
469 Standard_Boolean bFlag;
edfa30de 470 Standard_Integer i, j, k, aNbFFs, nF1, nF2;
488e5b9d 471 Handle(NCollection_BaseAllocator) aAllocator;
19941687 472 BOPCol_ListIteratorOfListOfShape aItF;
473 BOPCol_MapOfShape aMFence;
474 BOPAlgo_IndexedDataMapOfSetInteger aIDMSS;
475 BOPAlgo_VectorOfVectorOfShape aVVS;
98730279 476 //
4e57c75e 477 myErrorStatus=0;
478 //
479 const BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
480 //
481 aNbFFs=aFFs.Extent();
482 if (!aNbFFs) {
483 return;
484 }
4e57c75e 485 //
486 for (i=0; i<aNbFFs; ++i) {
487 const BOPDS_InterfFF& aFF=aFFs(i);
488 aFF.Indices(nF1, nF2);
489 //
4e57c75e 490 if (!myDS->HasFaceInfo(nF1) || !myDS->HasFaceInfo(nF2) ) {
491 continue;
492 }
493 //
494 const BOPDS_FaceInfo& aFI1=myDS->FaceInfo(nF1);
495 const BOPDS_FaceInfo& aFI2=myDS->FaceInfo(nF2);
4e57c75e 496 //
19941687 497 const TopoDS_Shape& aF1=myDS->Shape(nF1);
498 const TopoDS_Shape& aF2=myDS->Shape(nF2);
499 //
500 bFlag=HasPaveBlocksOnIn(aFI1, aFI2);
c209782c 501 bFlag=bFlag && (mySplits.IsBound(aF1) && mySplits.IsBound(aF2));
502 //
19941687 503 if (bFlag) {
504 for (k=0; k<2; ++k) {
98730279 505 const TopoDS_Shape& aF=(!k) ? aF1 : aF2;
506 const BOPCol_ListOfShape& aLF=mySplits.Find(aF);
507 //
508 aItF.Initialize(aLF);
509 for (; aItF.More(); aItF.Next()) {
510 const TopoDS_Shape& aFx=aItF.Value();
511 //
512 if (aMFence.Add(aFx)) {
513 BOPTools_Set aSTx;
514 //
515 aSTx.Add(aFx, TopAbs_EDGE);
516 //
517 if (!aIDMSS.Contains(aSTx)) {
518 BOPAlgo_VectorOfShape& aVS=aVVS.Append1();
519 aVS.Append(aFx);
520 //
521 j=aVVS.Extent()-1;
522 aIDMSS.Add (aSTx, j);
523 }
524 else {
525 j=aIDMSS.ChangeFromKey(aSTx);
526 BOPAlgo_VectorOfShape& aVS=aVVS(j);
527 aVS.Append(aFx);
528 }
529 }
530 }
c209782c 531 }
19941687 532 }// if (bFlag) {
533 else {// if (!bFlag)
534 BOPTools_Set aST1, aST2;
c209782c 535 //
98730279 536 aST1.Add(aF1, TopAbs_EDGE);
537 aST2.Add(aF2, TopAbs_EDGE);
c209782c 538 //
c209782c 539 if (aST1.IsEqual(aST2)) {
98730279 540 if (!aIDMSS.Contains(aST1)) {
541 BOPAlgo_VectorOfShape& aVS=aVVS.Append1();
542 if (aMFence.Add(aF1)) {
543 aVS.Append(aF1);
544 }
545 if (aMFence.Add(aF2)) {
546 aVS.Append(aF2);
547 }
548 //
549 k=aVVS.Extent()-1;
550 aIDMSS.Add (aST1, k);
551 }
552 else {
553 k=aIDMSS.ChangeFromKey(aST1);
554 BOPAlgo_VectorOfShape& aVS=aVVS(k);
555 if (aMFence.Add(aF1)) {
556 aVS.Append(aF1);
557 }
558 if (aMFence.Add(aF2)) {
559 aVS.Append(aF2);
560 }
561 }
19941687 562 }//if (aST1.IsEqual(aST2)) {
563 }// else {// if (!bFlag)
564 //
565 }// for (i=0; i<aNbFFs; ++i) {
566 //
567 aIDMSS.Clear();
568 //
796a784d 569 Standard_Boolean bFlagSD;
19941687 570 Standard_Integer aNbVPSB, aNbVVS, aNbF, aNbF1;
571 BOPAlgo_VectorOfPairOfShapeBoolean aVPSB;
572 //
573 aNbVVS=aVVS.Extent();
574 for (i=0; i<aNbVVS; ++i) {
575 const BOPAlgo_VectorOfShape& aVS=aVVS(i);
576 aNbF=aVS.Extent();
577 if (aNbF<2) {
4e57c75e 578 continue;
579 }
580 //
19941687 581 aNbF1=aNbF-1;
582 for (j=0; j<aNbF1; ++j) {
583 const TopoDS_Shape& aFj=aVS(j);
584 for (k=j+1; k<aNbF; ++k) {
98730279 585 const TopoDS_Shape& aFk=aVS(k);
586 BOPAlgo_PairOfShapeBoolean& aPSB=aVPSB.Append1();
587 aPSB.Shape1()=aFj;
588 aPSB.Shape2()=aFk;
0d0481c7 589 aPSB.SetFuzzyValue(myFuzzyValue);
36f4947b 590 aPSB.SetProgressIndicator(myProgressIndicator);
4e57c75e 591 }
19941687 592 }
593 }
36f4947b 594 //================================================================
595 BOPAlgo_BuilderSDFaceCnt::Perform(myRunParallel, aVPSB, myContext);
596 //================================================================
488e5b9d 597 aAllocator=
598 NCollection_BaseAllocator::CommonBaseAllocator();
19941687 599 BOPCol_IndexedDataMapOfShapeListOfShape aDMSLS(100, aAllocator);
edfa30de 600 NCollection_List<BOPCol_ListOfShape> aMBlocks(aAllocator);
19941687 601 //
602 aNbVPSB=aVPSB.Extent();
603 for (i=0; i<aNbVPSB; ++i) {
604 BOPAlgo_PairOfShapeBoolean& aPSB=aVPSB(i);
605 bFlagSD=aPSB.Flag();
606 if (bFlagSD) {
607 const TopoDS_Shape& aFj=aPSB.Shape1();
608 const TopoDS_Shape& aFk=aPSB.Shape2();
edfa30de 609 BOPAlgo_Tools::FillMap<TopoDS_Shape, TopTools_ShapeMapHasher>(aFj, aFk, aDMSLS, aAllocator);
19941687 610 }
611 }
612 aVPSB.Clear();
4e57c75e 613 //
614 // 2. Make blocks
edfa30de 615 BOPAlgo_Tools::MakeBlocks<TopoDS_Shape, TopTools_ShapeMapHasher>(aDMSLS, aMBlocks, aAllocator);
4e57c75e 616 //
617 // 3. Fill same domain faces map -> aMSDF
edfa30de 618 NCollection_List<BOPCol_ListOfShape>::Iterator aItB(aMBlocks);
619 for (; aItB.More(); aItB.Next()) {
620 const BOPCol_ListOfShape& aLSD = aItB.Value();
c209782c 621 //
19941687 622 const TopoDS_Shape& aFSD1=aLSD.First();
623 aItF.Initialize(aLSD);
624 for (; aItF.More(); aItF.Next()) {
625 const TopoDS_Shape& aFSD=aItF.Value();
626 myShapesSD.Bind(aFSD, aFSD1);
627 //
628 // If the face has no splits but are SD face,
629 // it is considered as splitted face
630 if (!mySplits.IsBound(aFSD)) {
98730279 631 BOPCol_ListOfShape aLS;
632 aLS.Append(aFSD);
633 mySplits.Bind(aFSD, aLS);
19941687 634 }
635 }
c209782c 636 }
4e57c75e 637 aMBlocks.Clear();
638 aDMSLS.Clear();
4e57c75e 639}
640//=======================================================================
641// function: FillImagesFaces1
642// purpose:
643//=======================================================================
acccace3 644void BOPAlgo_Builder::FillImagesFaces1()
4e57c75e 645{
a0a3f6ac 646 Standard_Integer i, aNbS, iSense, nVx, aNbVFI, iFlag;
4e57c75e 647 TopoDS_Face aFSD;
a0a3f6ac 648 TopoDS_Vertex aVx;
649 BRep_Builder aBB;
4e57c75e 650 BOPCol_ListOfInteger aLIAV;
651 BOPCol_ListOfShape aLFIm;
a0a3f6ac 652 BOPCol_ListIteratorOfListOfInteger aItV;
653 BOPCol_ListIteratorOfListOfShape aItLS, aItF;
654 BOPAlgo_VectorOfVFI aVVFI;
4e57c75e 655 //
656 aNbS=myDS->NbSourceShapes();
657 for (i=0; i<aNbS; ++i) {
658 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
659 if (aSI.ShapeType()!=TopAbs_FACE) {
660 continue;
661 }
662 //
663 const TopoDS_Face& aF=(*(TopoDS_Face*)(&aSI.Shape()));
664 //
665 if (!mySplits.IsBound(aF)) {
666 continue;
667 }
a0a3f6ac 668 //
669 // 1.
4e57c75e 670 aLIAV.Clear();
671 myDS->AloneVertices(i, aLIAV);
672 aLFIm.Clear();
673 //
674 const BOPCol_ListOfShape& aLSp=mySplits.Find(aF);
675 aItLS.Initialize(aLSp);
676 for (; aItLS.More(); aItLS.Next()) {
677 const TopoDS_Face& aFSp=(*(TopoDS_Face*)(&aItLS.Value()));
678 if (!myShapesSD.IsBound(aFSp)) {
679 aLFIm.Append(aFSp);
680 }
681 else {
682 aFSD=(*(TopoDS_Face*)(&myShapesSD.Find(aFSp)));
51db0179 683 iSense=BOPTools_AlgoTools::Sense(aFSp, aFSD, myContext);
4e57c75e 684 if (iSense<0) {
685 aFSD.Reverse();
686 }
687 aLFIm.Append(aFSD);
688 }
689 }
690 //
a0a3f6ac 691 //FillInternalVertices(aLFIm, aLIAV);
4e57c75e 692 //
693 myImages.Bind(aF, aLFIm);
c209782c 694 //
a0a3f6ac 695 // 2. fill myOrigins
c209782c 696 aItLS.Initialize(aLFIm);
697 for (; aItLS.More(); aItLS.Next()) {
698 const TopoDS_Face& aFSp=(*(TopoDS_Face*)(&aItLS.Value()));
b18a83d4 699 //
700 BOPCol_ListOfShape* pLOr = myOrigins.ChangeSeek(aFSp);
701 if (!pLOr) {
702 pLOr = myOrigins.Bound(aFSp, BOPCol_ListOfShape());
703 }
704 pLOr->Append(aF);
c209782c 705 }
4e57c75e 706 //
a0a3f6ac 707 // 3.
708 aItV.Initialize(aLIAV);
709 for (; aItV.More(); aItV.Next()) {
710 nVx=aItV.Value();
711 aVx=(*(TopoDS_Vertex*)(&myDS->Shape(nVx)));
712 aVx.Orientation(TopAbs_INTERNAL);
713 //
714 aItF.Initialize(aLFIm);
715 for (; aItF.More(); aItF.Next()) {
716 TopoDS_Face& aFy=(*(TopoDS_Face*)(&aItF.Value()));
717 //
718 BOPAlgo_VFI& aVFI=aVVFI.Append1();
719 aVFI.SetVertex(aVx);
720 aVFI.SetFace(aFy);
0d0481c7 721 aVFI.SetFuzzyValue(myFuzzyValue);
36f4947b 722 aVFI.SetProgressIndicator(myProgressIndicator);
4e57c75e 723 }
724 }
a0a3f6ac 725 }// for (i=0; i<aNbS; ++i) {
726 //
727 // 4.
728 aNbVFI=aVVFI.Extent();
729 //================================================================
730 BOPAlgo_VFICnt::Perform(myRunParallel, aVVFI, myContext);
731 //================================================================
732 //
733 for (i=0; i < aNbVFI; ++i) {
734 BOPAlgo_VFI& aVFI=aVVFI(i);
735 //
736 iFlag=aVFI.Flag();
737 if (!iFlag) {
51740958 738 TopoDS_Vertex& aVertex=aVFI.Vertex();
a0a3f6ac 739 TopoDS_Face& aFy=aVFI.Face();
51740958 740 aBB.Add(aFy, aVertex);
a0a3f6ac 741 }
4e57c75e 742 }
743}
744//=======================================================================
4e57c75e 745//function :HasPaveBlocksOnIn
746//purpose :
747//=======================================================================
748Standard_Boolean HasPaveBlocksOnIn(const BOPDS_FaceInfo& aFI1,
749 const BOPDS_FaceInfo& aFI2)
750{
751 Standard_Boolean bRet;
319da2e4 752 Standard_Integer i, aNbPB;
4e57c75e 753 //
754 bRet=Standard_False;
319da2e4 755 const BOPDS_IndexedMapOfPaveBlock& aMPBOn1 = aFI1.PaveBlocksOn();
756 const BOPDS_IndexedMapOfPaveBlock& aMPBIn1 = aFI1.PaveBlocksIn();
757 //
758 const BOPDS_IndexedMapOfPaveBlock& aMPBOn2 = aFI2.PaveBlocksOn();
759 aNbPB = aMPBOn2.Extent();
760 for (i = 1; i <= aNbPB; ++i) {
761 const Handle(BOPDS_PaveBlock)& aPB = aMPBOn2(i);
762 bRet = aMPBOn1.Contains(aPB) || aMPBIn1.Contains(aPB);
4e57c75e 763 if (bRet) {
764 return bRet;
765 }
766 }
767 //
319da2e4 768 const BOPDS_IndexedMapOfPaveBlock& aMPBIn2 = aFI2.PaveBlocksIn();
769 aNbPB = aMPBIn2.Extent();
770 for (i = 1; i <= aNbPB; ++i) {
771 const Handle(BOPDS_PaveBlock)& aPB = aMPBIn2(i);
772 bRet = aMPBOn1.Contains(aPB) || aMPBIn1.Contains(aPB);
4e57c75e 773 if (bRet) {
774 return bRet;
775 }
776 }
777 return bRet;
778}