0024826: Wrapping of parallelisation algorithms
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_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.
4e57c75e 17
18#include <BOPAlgo_PaveFiller.ixx>
19
20#include <Precision.hxx>
21#include <NCollection_IncAllocator.hxx>
22#include <NCollection_UBTreeFiller.hxx>
23
24#include <Bnd_Box.hxx>
25
db8e4b9a 26#include <GeomAPI_ProjectPointOnCurve.hxx>
27
4e57c75e 28#include <TopoDS_Edge.hxx>
29#include <TopoDS_Vertex.hxx>
30#include <TopoDS_Compound.hxx>
31#include <BRep_Tool.hxx>
32#include <BRep_Builder.hxx>
33#include <BRepTools.hxx>
34#include <BRepBndLib.hxx>
35//
36#include <IntTools_EdgeEdge.hxx>
37#include <IntTools_Range.hxx>
38#include <IntTools_SequenceOfCommonPrts.hxx>
39#include <IntTools_CommonPrt.hxx>
40#include <IntTools_SequenceOfRanges.hxx>
41//
42#include <BOPTools_AlgoTools.hxx>
43//
44#include <BOPCol_DataMapOfShapeInteger.hxx>
a2098360 45#include <BOPCol_DataMapOfShapeListOfShape.hxx>
4e57c75e 46#include <BOPCol_DataMapOfIntegerShape.hxx>
47#include <BOPCol_IndexedDataMapOfShapeBox.hxx>
db8e4b9a 48#include <BOPCol_BoxBndTree.hxx>
a942f2da 49#include <BOPCol_NCVector.hxx>
c7b59798 50#include <BOPCol_Parallel.hxx>
4e57c75e 51//
1e143abb 52#include <IntTools_Context.hxx>
53#include <IntTools_ShrunkRange.hxx>
54#include <IntTools_Tools.hxx>
4e57c75e 55//
56#include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx>
57#include <BOPDS_MapOfPaveBlock.hxx>
58#include <BOPDS_CommonBlock.hxx>
59#include <BOPDS_CoupleOfPaveBlocks.hxx>
60#include <BOPDS_DataMapOfPaveBlockListOfInteger.hxx>
61#include <BOPDS_Iterator.hxx>
62#include <BOPDS_VectorOfInterfEE.hxx>
63#include <BOPDS_Interf.hxx>
64#include <BOPDS_Pave.hxx>
db8e4b9a 65//
4e57c75e 66#include <BOPAlgo_Tools.hxx>
db8e4b9a 67
a2098360 68/////////////////////////////////////////////////////////////////////////
a942f2da 69//=======================================================================
70//class : BOPAlgo_EdgeEdge
71//purpose :
72//=======================================================================
36f4947b 73class BOPAlgo_EdgeEdge :
74 public IntTools_EdgeEdge,
75 public BOPAlgo_Algo {
76
a942f2da 77 public:
36f4947b 78
79 DEFINE_STANDARD_ALLOC
80 //
81 BOPAlgo_EdgeEdge():
82 IntTools_EdgeEdge(),
83 BOPAlgo_Algo() {
a942f2da 84 };
85 //
36f4947b 86 virtual ~BOPAlgo_EdgeEdge(){
a942f2da 87 };
88 //
89 void SetPaveBlock1(const Handle(BOPDS_PaveBlock)& aPB) {
90 myPB1=aPB;
91 }
92 //
93 Handle(BOPDS_PaveBlock)& PaveBlock1() {
94 return myPB1;
95 }
96 //
97 void SetPaveBlock2(const Handle(BOPDS_PaveBlock)& aPB) {
98 myPB2=aPB;
99 }
100 //
101 Handle(BOPDS_PaveBlock)& PaveBlock2() {
102 return myPB2;
103 }
36f4947b 104 //
105 virtual void Perform() {
106 BOPAlgo_Algo::UserBreak();
107 IntTools_EdgeEdge::Perform();
108 }
a942f2da 109 //
110 protected:
111 Handle(BOPDS_PaveBlock) myPB1;
112 Handle(BOPDS_PaveBlock) myPB2;
113};
114//
505abfb8 115//=======================================================================
116typedef BOPCol_NCVector
117 <BOPAlgo_EdgeEdge> BOPAlgo_VectorOfEdgeEdge;
a942f2da 118//
c7b59798 119typedef BOPCol_Functor
505abfb8 120 <BOPAlgo_EdgeEdge,
121 BOPAlgo_VectorOfEdgeEdge> BOPAlgo_EdgeEdgeFunctor;
122//
c7b59798 123typedef BOPCol_Cnt
505abfb8 124 <BOPAlgo_EdgeEdgeFunctor,
125 BOPAlgo_VectorOfEdgeEdge> BOPAlgo_EdgeEdgeCnt;
a942f2da 126//
a2098360 127/////////////////////////////////////////////////////////////////////////
128//=======================================================================
129//class : BOPAlgo_TNV
130//purpose :
131//=======================================================================
132class BOPAlgo_TNV : public BOPCol_BoxBndTreeSelector{
133 public:
134 BOPAlgo_TNV()
135 : BOPCol_BoxBndTreeSelector(), myTree(NULL) {
136 };
137 //
138 ~BOPAlgo_TNV(){
139 };
140 //
141 void SetVertex(const TopoDS_Vertex& aV) {
142 myV=aV;
143 }
144 //
145 const TopoDS_Vertex& Vertex()const {
146 return myV;
147 }
148 //
149 void SetTree(BOPCol_BoxBndTree& aTree) {
150 myTree=&aTree;
151 }
152 //
153 void Perform() {
154 myTree->Select(*this);
155 }
156 //
157 protected:
158 TopoDS_Vertex myV;
159 BOPCol_BoxBndTree *myTree;
160};
161//
162//=======================================================================
163typedef BOPCol_NCVector
164 <BOPAlgo_TNV> BOPAlgo_VectorOfTNV;
165//
c7b59798 166typedef BOPCol_Functor
a2098360 167 <BOPAlgo_TNV,
168 BOPAlgo_VectorOfTNV> BOPAlgo_TNVFunctor;
169//
c7b59798 170typedef BOPCol_Cnt
a2098360 171 <BOPAlgo_TNVFunctor,
172 BOPAlgo_VectorOfTNV> BOPAlgo_TNVCnt;
173/////////////////////////////////////////////////////////////////////////
174//=======================================================================
175//class : BOPAlgo_PVE
176//purpose :
177//=======================================================================
178class BOPAlgo_PVE {
179 public:
180 BOPAlgo_PVE()
181 : myIV(-1), myIE(-1), myFlag(-1), myT(-1.) {
182 };
183 //
184 ~BOPAlgo_PVE(){
185 };
186 //
187 void SetIndices(const Standard_Integer nV,
188 const Standard_Integer nE){
189 myIV=nV;
190 myIE=nE;
191 }
192 //
193 void Indices(Standard_Integer& nV,
194 Standard_Integer& nE) const {
195 nV=myIV;
196 nE=myIE;
197 }
198 //
199 void SetVertex(const TopoDS_Vertex& aV) {
200 myV=aV;
201 }
202 //
203 const TopoDS_Vertex& Vertex()const {
204 return myV;
205 }
206 //
207 void SetEdge(const TopoDS_Edge& aE) {
208 myE=aE;
209 }
210 //
211 const TopoDS_Edge& Edge()const {
212 return myE;
213 }
214 //
215 void SetPaveBlock(const Handle(BOPDS_PaveBlock)& aPB) {
216 myPB=aPB;
217 }
218 //
219 Handle(BOPDS_PaveBlock)& PaveBlock() {
220 return myPB;
221 }
222 //
223 Standard_Integer Flag()const {
224 return myFlag;
225 }
226 //
227 Standard_Real Parameter()const {
228 return myT;
229 }
230 //
1e143abb 231 void SetContext(const Handle(IntTools_Context)& aContext) {
a2098360 232 myContext=aContext;
233 }
234 //
1e143abb 235 const Handle(IntTools_Context)& Context()const {
a2098360 236 return myContext;
237 }
238 //
239 void Perform() {
240 myFlag=myContext->ComputeVE (myV, myE, myT);
241 };
242 //
243 protected:
244 Standard_Integer myIV;
245 Standard_Integer myIE;
246 Standard_Integer myFlag;
247 Standard_Real myT;
248 TopoDS_Vertex myV;
249 TopoDS_Edge myE;
250 Handle(BOPDS_PaveBlock) myPB;
1e143abb 251 Handle(IntTools_Context) myContext;
a2098360 252};
253//=======================================================================
254typedef BOPCol_NCVector
255 <BOPAlgo_PVE> BOPAlgo_VectorOfPVE;
256//
c7b59798 257typedef BOPCol_ContextFunctor
a2098360 258 <BOPAlgo_PVE,
259 BOPAlgo_VectorOfPVE,
1e143abb 260 Handle(IntTools_Context),
261 IntTools_Context> BOPAlgo_PVEFunctor;
a2098360 262//
c7b59798 263typedef BOPCol_ContextCnt
a2098360 264 <BOPAlgo_PVEFunctor,
265 BOPAlgo_VectorOfPVE,
1e143abb 266 Handle(IntTools_Context)> BOPAlgo_PVECnt;
a2098360 267/////////////////////////////////////////////////////////////////////////
4e57c75e 268//=======================================================================
269// function: PerformEE
270// purpose:
271//=======================================================================
db8e4b9a 272void BOPAlgo_PaveFiller::PerformEE()
4e57c75e 273{
a942f2da 274 Standard_Integer iSize;
4e57c75e 275 //
276 myErrorStatus=0;
277 //
505abfb8 278 FillShrunkData(TopAbs_EDGE, TopAbs_EDGE);
279 //
4e57c75e 280 myIterator->Initialize(TopAbs_EDGE, TopAbs_EDGE);
281 iSize=myIterator->ExpectedLength();
282 if (!iSize) {
283 return;
284 }
285 //
a942f2da 286 Standard_Boolean bJustAdd;
287 Standard_Integer i, iX, nE1, nE2, aNbCPrts, k, aNbFdgeEdge;
288 Standard_Real aTS11, aTS12, aTS21, aTS22, aT11, aT12, aT21, aT22;
289 TopAbs_ShapeEnum aType;
290 BOPDS_ListIteratorOfListOfPaveBlock aIt1, aIt2;
291 Handle(NCollection_IncAllocator) aAllocator;
292 BOPDS_MapOfPaveBlock aMPBToUpdate;
293 BOPAlgo_VectorOfEdgeEdge aVEdgeEdge;
294 BOPDS_MapIteratorOfMapOfPaveBlock aItPB;
295 //
4e57c75e 296 //-----------------------------------------------------scope f
4e57c75e 297 BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock aMPBLPB(100, aAllocator);
298 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMVCPB(100, aAllocator);
299 //
4e57c75e 300 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
4e57c75e 301 aEEs.SetIncrement(iSize);
4e57c75e 302 //
303 for (; myIterator->More(); myIterator->Next()) {
304 myIterator->Value(nE1, nE2, bJustAdd);
305 if(bJustAdd) {
306 continue;
307 }
308 //
309 const BOPDS_ShapeInfo& aSIE1=myDS->ShapeInfo(nE1);
310 if (aSIE1.HasFlag()){
311 continue;
312 }
313 const BOPDS_ShapeInfo& aSIE2=myDS->ShapeInfo(nE2);
314 if (aSIE2.HasFlag()){
315 continue;
316 }
317 //
318 const TopoDS_Edge& aE1=(*(TopoDS_Edge *)(&aSIE1.Shape()));
319 const TopoDS_Edge& aE2=(*(TopoDS_Edge *)(&aSIE2.Shape()));
320 //
4e57c75e 321 BOPDS_ListOfPaveBlock& aLPB1=myDS->ChangePaveBlocks(nE1);
322 BOPDS_ListOfPaveBlock& aLPB2=myDS->ChangePaveBlocks(nE2);
323 //
324 aIt1.Initialize(aLPB1);
325 for (; aIt1.More(); aIt1.Next()) {
326 Bnd_Box aBB1;
327 //
328 Handle(BOPDS_PaveBlock)& aPB1=aIt1.ChangeValue();
329 if (!aPB1->HasShrunkData()) {
505abfb8 330 continue;
4e57c75e 331 }
332 aPB1->ShrunkData(aTS11, aTS12, aBB1);
333 //
334 aIt2.Initialize(aLPB2);
335 for (; aIt2.More(); aIt2.Next()) {
336 Bnd_Box aBB2;
337 //
338 Handle(BOPDS_PaveBlock)& aPB2=aIt2.ChangeValue();
339 if (!aPB2->HasShrunkData()) {
505abfb8 340 continue;
4e57c75e 341 }
342 aPB2->ShrunkData(aTS21, aTS22, aBB2);
343 //
344 if (aBB1.IsOut(aBB2)) {
345 continue;
346 }
347 //
b4109929 348 aPB1->Range(aT11, aT12);
349 aPB2->Range(aT21, aT22);
b4109929 350 //
a942f2da 351 BOPAlgo_EdgeEdge& anEdgeEdge=aVEdgeEdge.Append1();
352 //
353 anEdgeEdge.SetPaveBlock1(aPB1);
354 anEdgeEdge.SetPaveBlock2(aPB2);
355 //
ec0cdc0e 356 anEdgeEdge.SetEdge1(aE1, aT11, aT12);
357 anEdgeEdge.SetEdge2(aE2, aT21, aT22);
36f4947b 358 anEdgeEdge.SetProgressIndicator(myProgressIndicator);
a942f2da 359 }//for (; aIt2.More(); aIt2.Next()) {
360 }//for (; aIt1.More(); aIt1.Next()) {
361 }//for (; myIterator->More(); myIterator->Next()) {
362 //
363 aNbFdgeEdge=aVEdgeEdge.Extent();
364 //======================================================
365 BOPAlgo_EdgeEdgeCnt::Perform(myRunParallel, aVEdgeEdge);
366 //======================================================
367 //
368 for (k=0; k < aNbFdgeEdge; ++k) {
369 Bnd_Box aBB1, aBB2;
370 //
371 BOPAlgo_EdgeEdge& anEdgeEdge=aVEdgeEdge(k);
372 if (!anEdgeEdge.IsDone()) {
373 continue;
374 }
375 //
376 //--------------------------------------------
377 Handle(BOPDS_PaveBlock)& aPB1=anEdgeEdge.PaveBlock1();
378 nE1=aPB1->OriginalEdge();
379 aPB1->Range(aT11, aT12);
380 aPB1->ShrunkData(aTS11, aTS12, aBB1);
381 //
382 Handle(BOPDS_PaveBlock)& aPB2=anEdgeEdge.PaveBlock2();
383 nE2=aPB2->OriginalEdge();
384 aPB2->Range(aT21, aT22);
385 aPB2->ShrunkData(aTS21, aTS22, aBB2);
386 //
387 //--------------------------------------------
388 IntTools_Range aR11(aT11, aTS11), aR12(aTS12, aT12),
389 aR21(aT21, aTS21), aR22(aTS22, aT22);
390 //
391 const IntTools_SequenceOfCommonPrts& aCPrts = anEdgeEdge.CommonParts();
392 aNbCPrts=aCPrts.Length();
393 for (i=1; i<=aNbCPrts; ++i) {
394 const IntTools_CommonPrt& aCPart=aCPrts(i);
395 //
396 const TopoDS_Edge& aE1=aCPart.Edge1();
397 const TopoDS_Edge& aE2=aCPart.Edge2();
398 //
399 aType=aCPart.Type();
400 switch (aType) {
401 case TopAbs_VERTEX: {
402 Standard_Boolean bIsOnPave[4], bFlag;
403 Standard_Integer nV[4], j;
404 Standard_Real aT1, aT2, aTol;
405 TopoDS_Vertex aVnew;
406 IntTools_Range aCR1, aCR2;
407 //
1e143abb 408 IntTools_Tools::VertexParameters(aCPart, aT1, aT2);
a942f2da 409 aTol = Precision::Confusion();
410 aCR1 = aCPart.Range1();
411 aCR2 = aCPart.Ranges2()(1);
412 //
413 //decide to keep the pave or not
1e143abb 414 bIsOnPave[0] = IntTools_Tools::IsOnPave1(aT1, aR11, aTol) ||
415 IntTools_Tools::IsOnPave1(aR11.First(), aCR1, aTol);
416 bIsOnPave[1] = IntTools_Tools::IsOnPave1(aT1, aR12, aTol) ||
417 IntTools_Tools::IsOnPave1(aR12.Last(), aCR1, aTol);
418 bIsOnPave[2] = IntTools_Tools::IsOnPave1(aT2, aR21, aTol) ||
419 IntTools_Tools::IsOnPave1(aR21.First(), aCR2, aTol);
420 bIsOnPave[3] = IntTools_Tools::IsOnPave1(aT2, aR22, aTol) ||
421 IntTools_Tools::IsOnPave1(aR22.Last(), aCR2, aTol);
a942f2da 422 //
423 aPB1->Indices(nV[0], nV[1]);
424 aPB2->Indices(nV[2], nV[3]);
425 //
426 if((bIsOnPave[0] && bIsOnPave[2]) ||
427 (bIsOnPave[0] && bIsOnPave[3]) ||
428 (bIsOnPave[1] && bIsOnPave[2]) ||
429 (bIsOnPave[1] && bIsOnPave[3])) {
430 continue;
431 }
432 //
433 bFlag = Standard_False;
434 for (j = 0; j < 4; ++j) {
435 if (bIsOnPave[j]) {
436 //add interf VE(nV[j], nE)
437 Handle(BOPDS_PaveBlock)& aPB = (j < 2) ? aPB2 : aPB1;
438 ForceInterfVE(nV[j], aPB, aMPBToUpdate);
439 bFlag = Standard_True;
440 break;
441 }
442 }
443 if (bFlag) {
444 continue;
445 }
446 //
447 BOPTools_AlgoTools::MakeNewVertex(aE1, aT1, aE2, aT2, aVnew);
448 // <-LXBR
449 {
450 Standard_Integer nVS[2], iFound, k;
451 Standard_Real aTolVx, aTolVnew, aD2, aDT2;
452 BOPCol_MapOfInteger aMV;
453 gp_Pnt aPnew, aPx;
4e57c75e 454 //
a942f2da 455 iFound=0;
456 j=-1;
457 aMV.Add(nV[0]);
458 aMV.Add(nV[1]);
459 //
460 if (aMV.Contains(nV[2])) {
461 ++j;
462 nVS[j]=nV[2];
463 }
464 if (aMV.Contains(nV[3])) {
465 ++j;
466 nVS[j]=nV[3];
467 }
468 //
469 aTolVnew=BRep_Tool::Tolerance(aVnew);
470 aPnew=BRep_Tool::Pnt(aVnew);
471 //
472 for (k=0; k<=j; ++k) {
473 const TopoDS_Vertex& aVx= *(TopoDS_Vertex*)&(myDS->Shape(nVS[k]));
474 aTolVx=BRep_Tool::Tolerance(aVx);
475 aPx=BRep_Tool::Pnt(aVx);
476 aD2=aPnew.SquareDistance(aPx);
477 //
478 aDT2=100.*(aTolVnew+aTolVx)*(aTolVnew+aTolVx);
7eed5d29 479 //
a942f2da 480 if (aD2<aDT2) {
481 iFound=1;
4e57c75e 482 break;
483 }
a942f2da 484 }
485 //
486 if (iFound) {
487 continue;
488 }
489 }
402bfe81 490 //
a942f2da 491 // 1
402bfe81 492 BOPDS_InterfEE& aEE=aEEs.Append1();
493 iX=aEEs.Extent()-1;
a942f2da 494 aEE.SetIndices(nE1, nE2);
495 aEE.SetCommonPart(aCPart);
496 // 2
497 myDS->AddInterf(nE1, nE2);
498 //
499 BOPDS_CoupleOfPaveBlocks aCPB;
500 //
501 aCPB.SetPaveBlocks(aPB1, aPB2);
502 aCPB.SetIndexInterf(iX);
503 aMVCPB.Add(aVnew, aCPB);
504 }//case TopAbs_VERTEX:
505 break;
506 //
507 case TopAbs_EDGE: {
508 if (aNbCPrts > 1) {
4e57c75e 509 break;
a942f2da 510 }
511 //
512 Standard_Boolean bHasSameBounds;
513 bHasSameBounds=aPB1->HasSameBounds(aPB2);
514 if (!bHasSameBounds) {
515 break;
516 }
517 // 1
402bfe81 518 BOPDS_InterfEE& aEE=aEEs.Append1();
519 iX=aEEs.Extent()-1;
a942f2da 520 aEE.SetIndices(nE1, nE2);
521 aEE.SetCommonPart(aCPart);
522 // 2
523 myDS->AddInterf(nE1, nE2);
524 //
525 BOPAlgo_Tools::FillMap(aPB1, aPB2, aMPBLPB, aAllocator);
526 }//case TopAbs_EDGE
527 break;
528 default:
529 break;
530 }//switch (aType) {
531 }//for (i=1; i<=aNbCPrts; i++) {
532 }//for (k=0; k < aNbFdgeEdge; ++k) {
4e57c75e 533 //
534 //=========================================
535 // post treatment
536 //=========================================
b4109929 537 aItPB.Initialize(aMPBToUpdate);
538 for (; aItPB.More(); aItPB.Next()) {
539 Handle(BOPDS_PaveBlock) aPB=aItPB.Value();
540 if (!myDS->IsCommonBlock(aPB)) {
541 myDS->UpdatePaveBlock(aPB);
542 }
543 else {
544 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
545 myDS->UpdateCommonBlock(aCB);
546 }
547 }
548 //
5a77460e 549 BOPAlgo_Tools::PerformCommonBlocks(aMPBLPB, aAllocator, myDS);
4e57c75e 550 PerformVerticesEE(aMVCPB, aAllocator);
551 //-----------------------------------------------------scope t
552 aMPBLPB.Clear();
553 aMVCPB.Clear();
b4109929 554 aMPBToUpdate.Clear();
4e57c75e 555}
556//=======================================================================
557//function : PerformVertices
558//purpose :
559//=======================================================================
db8e4b9a 560Standard_Integer BOPAlgo_PaveFiller::PerformVerticesEE
561 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMVCPB,
562 Handle(NCollection_BaseAllocator)& theAllocator)
4e57c75e 563{
564 Standard_Integer aNbV, iRet;
565 //
566 iRet=0;
567 aNbV=theMVCPB.Extent();
568 if (!aNbV) {
569 return iRet;
570 }
571 //
572 Standard_Integer nVx, iV, j, nE, iFlag, iX, i, aNb;
573 Standard_Real aT;
574 TopoDS_Shape aV;
575 BOPCol_ListIteratorOfListOfShape aItLS;
576 BOPCol_ListIteratorOfListOfInteger aItLI;
577 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
578 BOPDS_ShapeInfo aSI;
579 BOPDS_Pave aPave;
580 //
581 BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, theAllocator);
582 BOPCol_ListOfShape aLS(theAllocator);
583 BOPCol_IndexedDataMapOfShapeInteger aMVI(100, theAllocator);
584 BOPCol_IndexedDataMapOfShapeListOfShape aImages;
585 //
586 aSI.SetShapeType(TopAbs_VERTEX);
587 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
588 //
589 // 1 prepare arguments
590 //
591 // <- DEB
592 for (i=1; i<=aNbV; ++i) {
593 const TopoDS_Shape& aS=theMVCPB.FindKey(i);
594 const BOPDS_CoupleOfPaveBlocks& aCPB=theMVCPB.FindFromIndex(i);
595 iV=aCPB.IndexInterf();
596 aMVI.Add(aS, iV);
597 }
598 //
599 // 2 Fuse vertices
600 TreatNewVertices(aMVI, aImages);
601 //
602 // 3 Add new vertices to myDS;
603 // connect indices to CPB structure
604 aNb = aImages.Extent();
605 for (i=1; i<=aNb; ++i) {
606 const TopoDS_Vertex& aV=(*(TopoDS_Vertex*)(&aImages.FindKey(i)));
607 const BOPCol_ListOfShape& aLVSD=aImages.FindFromIndex(i);
608 //
609 aSI.SetShape(aV);
610 iV=myDS->Append(aSI);
611 //
612 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(iV);
613 Bnd_Box& aBox=aSIDS.ChangeBox();
614 BRepBndLib::Add(aV, aBox);
615 //
616 aItLS.Initialize(aLVSD);
617 for (; aItLS.More(); aItLS.Next()) {
618 const TopoDS_Shape& aVx = aItLS.Value();
619 BOPDS_CoupleOfPaveBlocks &aCPB=theMVCPB.ChangeFromKey(aVx);
620 aCPB.SetIndex(iV);
621 // update EE interference
622 iX=aCPB.IndexInterf();
623 BOPDS_InterfEE& aEE=aEEs(iX);
624 aEE.SetIndexNew(iV);
625 }
626 }
627 //
628 // 4 Map PaveBlock/ListOfVertices to add to this PaveBlock ->aMPBLI
629 {
630 Handle(BOPDS_PaveBlock) aPB[2];
631 //
632 for (i=1; i<=aNbV; ++i) {
633 const BOPDS_CoupleOfPaveBlocks& aCPB=theMVCPB.FindFromIndex(i);
634 iV=aCPB.Index();
635 aCPB.PaveBlocks(aPB[0], aPB[1]);
636 for (j=0; j<2; ++j) {
637 if (aMPBLI.Contains(aPB[j])) {
638 BOPCol_ListOfInteger& aLI=aMPBLI.ChangeFromKey(aPB[j]);
639 aLI.Append(iV);
640 }
641 else {
642 BOPCol_ListOfInteger aLI(theAllocator);
643 aLI.Append(iV);
644 aMPBLI.Add(aPB[j], aLI);
645 }
646 }
647 }
648 }
4e57c75e 649 // 5
650 // 5.1 Compute Extra Paves and
651 // 5.2. Add Extra Paves to the PaveBlocks
a2098360 652 //-------------------------------------------------------------
653 Standard_Integer k, aNbVPVE;
654 BOPAlgo_VectorOfPVE aVPVE;
655 //
4e57c75e 656 aNb=aMPBLI.Extent();
657 for(i=1; i<=aNb; ++i) {
658 Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
659 nE=aPB->OriginalEdge();
660 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
661 // 1,2
662 const BOPCol_ListOfInteger& aLI=aMPBLI.FindFromIndex(i);
663 aItLI.Initialize(aLI);
664 for (; aItLI.More(); aItLI.Next()) {
665 nVx=aItLI.Value();
666 const TopoDS_Vertex& aVx=(*(TopoDS_Vertex *)(&myDS->Shape(nVx)));
667 //
a2098360 668 BOPAlgo_PVE& aPVE=aVPVE.Append1();
669 aPVE.SetIndices(nVx, nE);
670 aPVE.SetVertex(aVx);
671 aPVE.SetEdge(aE);
672 aPVE.SetPaveBlock(aPB);
673 }
674 }
675 //
676 aNbVPVE=aVPVE.Extent();
677 //=============================================================
678 BOPAlgo_PVECnt::Perform(myRunParallel, aVPVE, myContext);
679 //=============================================================
680 //
681 for (k=0; k < aNbVPVE; ++k) {
682 BOPAlgo_PVE& aPVE=aVPVE(k);
683 iFlag=aPVE.Flag();
684 if (!iFlag) {
685 aPVE.Indices(nVx, nE);
686 aT=aPVE.Parameter();
687 Handle(BOPDS_PaveBlock)& aPB=aPVE.PaveBlock();
688 //
689 aPave.SetIndex(nVx);
690 aPave.SetParameter(aT);
691 aPB->AppendExtPave(aPave);
4e57c75e 692 }
693 }
694 // 6 Split PaveBlocksa
695 aNb=aMPBLI.Extent();
696 for(i=1; i<=aNb; ++i) {
697 Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
698 nE=aPB->OriginalEdge();
699 // 3
5a77460e 700 if (!myDS->IsCommonBlock(aPB)) {
4e57c75e 701 myDS->UpdatePaveBlock(aPB);
702 }
703 else {
5a77460e 704 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
4e57c75e 705 myDS->UpdateCommonBlock(aCB);
706 }
707 }//for (; aItMPBLI.More(); aItMPBLI.Next()) {
708 //
709 return iRet;
710}
4e57c75e 711//=======================================================================
712//function : TreatNewVertices
713//purpose :
714//=======================================================================
db8e4b9a 715void BOPAlgo_PaveFiller::TreatNewVertices
716 (const BOPCol_IndexedDataMapOfShapeInteger& aMapVI,
717 BOPCol_IndexedDataMapOfShapeListOfShape& myImages)
4e57c75e 718{
a2098360 719 Standard_Integer i, aNbV;//, aNbVSD;
4e57c75e 720 Standard_Real aTol;
4e57c75e 721 TopoDS_Vertex aVnew;
a2098360 722 TopoDS_Shape aVF;
4e57c75e 723 BOPCol_IndexedMapOfShape aMVProcessed;
a2098360 724 BOPCol_MapOfInteger aMFence;
4e57c75e 725 BOPCol_ListIteratorOfListOfInteger aIt;
a2098360 726 BOPCol_DataMapOfShapeListOfShape aDMVLV;
727 BOPCol_DataMapIteratorOfDataMapOfShapeListOfShape aItDMVLV;
4e57c75e 728 //
db8e4b9a 729 BOPCol_BoxBndTreeSelector aSelector;
730 BOPCol_BoxBndTree aBBTree;
a2098360 731 NCollection_UBTreeFiller <Standard_Integer,
732 Bnd_Box> aTreeFiller(aBBTree);
733 BOPAlgo_VectorOfTNV aVTNV;
4e57c75e 734 //
735 aNbV = aMapVI.Extent();
736 for (i=1; i<=aNbV; ++i) {
a2098360 737 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMapVI.FindKey(i));
4e57c75e 738 Bnd_Box aBox;
739 //
a2098360 740 aTol=BRep_Tool::Tolerance(aV);
4e57c75e 741 aBox.SetGap(aTol);
a2098360 742 aBox.Add(BRep_Tool::Pnt(aV));
743 aBox.Enlarge(aTol);
4e57c75e 744 //
745 aTreeFiller.Add(i, aBox);
746 //
a2098360 747 BOPAlgo_TNV& aTNV=aVTNV.Append1();
748 aTNV.SetTree(aBBTree);
749 aTNV.SetBox(aBox);
750 aTNV.SetVertex(aV);
4e57c75e 751 }
752 //
753 aTreeFiller.Fill();
a2098360 754 //
755 //===========================================
756 BOPAlgo_TNVCnt::Perform(myRunParallel, aVTNV);
757 //===========================================
758 //
4e57c75e 759 // Chains
760 for (i=1; i<=aNbV; ++i) {
a2098360 761 if (!aMFence.Add(i)) {
4e57c75e 762 continue;
763 }
764 //
a2098360 765 Standard_Integer aIP, aNbIP1, aIP1;
4e57c75e 766 BOPCol_ListOfShape aLVSD;
a2098360 767 BOPCol_MapIteratorOfMapOfInteger aItMI;
768 BOPCol_ListOfInteger aLIP, aLIP1, aLIPC;
769 BOPCol_ListIteratorOfListOfInteger aItLIP;
4e57c75e 770 //
a2098360 771 aLIPC.Append(i);
772 aLIP.Append(i);
302f96fb 773 for(;;) {
a2098360 774 aItLIP.Initialize(aLIP);
775 for(; aItLIP.More(); aItLIP.Next()) {
776 aIP=aItLIP.Value();
4e57c75e 777 //
a2098360 778 BOPAlgo_TNV& aTNV=aVTNV(aIP-1);
779 const BOPCol_ListOfInteger& aLI=aTNV.Indices();
4e57c75e 780 aIt.Initialize(aLI);
781 for (; aIt.More(); aIt.Next()) {
782 aIP1=aIt.Value();
a2098360 783 if (!aMFence.Add(aIP1)) {
4e57c75e 784 continue;
785 }
a2098360 786 aLIP1.Append(aIP1);
4e57c75e 787 } //for (; aIt.More(); aIt.Next()) {
788 }//for(; aIt1.More(); aIt1.Next()) {
789 //
a2098360 790 aNbIP1=aLIP1.Extent();
4e57c75e 791 if (!aNbIP1) {
a2098360 792 break; // from for(;;)
4e57c75e 793 }
794 //
a2098360 795 aLIP.Clear();
796 aItLIP.Initialize(aLIP1);
797 for(; aItLIP.More(); aItLIP.Next()) {
798 aIP=aItLIP.Value();
799 aLIP.Append(aIP);
800 aLIPC.Append(aIP);
4e57c75e 801 }
a2098360 802 aLIP1.Clear();
803 }// for(;;) {
4e57c75e 804 //
a2098360 805 aItLIP.Initialize(aLIPC);
806 for(; aItLIP.More(); aItLIP.Next()) {
807 aIP=aItLIP.Value();
808 const TopoDS_Vertex& aVP=aVTNV(aIP-1).Vertex();
4e57c75e 809 aLVSD.Append(aVP);
4e57c75e 810 }
a2098360 811 aVF=aLVSD.First();
812 aDMVLV.Bind(aVF, aLVSD);
4e57c75e 813 }// for (i=1; i<=aNbV; ++i) {
814
815 // Make new vertices
a2098360 816 aItDMVLV.Initialize(aDMVLV);
817 for(; aItDMVLV.More(); aItDMVLV.Next()) {
818 const TopoDS_Shape& aV=aItDMVLV.Key();
819 const BOPCol_ListOfShape& aLVSD=aItDMVLV.Value();
820 if (aLVSD.IsEmpty()) {
4e57c75e 821 myImages.Add(aV, aLVSD);
822 }
a2098360 823 else {
824 BOPCol_ListOfShape* pLVSD=(BOPCol_ListOfShape*)&aLVSD;
825 BOPTools_AlgoTools::MakeVertex(*pLVSD, aVnew);
826 myImages.Add(aVnew, aLVSD);
827 }
4e57c75e 828 }
829}
4e57c75e 830//=======================================================================
831//function : FillShrunkData
832//purpose :
833//=======================================================================
db8e4b9a 834void BOPAlgo_PaveFiller::FillShrunkData(Handle(BOPDS_PaveBlock)& thePB)
4e57c75e 835{
836 Standard_Integer nE, nV1, nV2, iErr;
837 Standard_Real aT1, aT2, aTS1, aTS2;
1e143abb 838 IntTools_ShrunkRange aSR;
4e57c75e 839 //
840 myErrorStatus=0;
841 myWarningStatus = 0;
842 //
843 const BOPDS_Pave& aPave1=thePB->Pave1();
844 nV1=aPave1.Index();
845 aT1=aPave1.Parameter();
846 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
847 //
848 const BOPDS_Pave& aPave2=thePB->Pave2();
849 nV2=aPave2.Index();
850 aT2=aPave2.Parameter();
851 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
852 //
853 nE=thePB->OriginalEdge();
854 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
855 //
505abfb8 856 aSR.SetContext(myContext);
857 aSR.SetData(aE, aT1, aT2, aV1, aV2);
4e57c75e 858 //
859 aSR.Perform();
860 iErr=aSR.ErrorStatus();
861 if (iErr) {
862 myWarningStatus = 1;
863 //myErrorStatus=40;
864 return;
865 }
866 //
867 aSR.ShrunkRange(aTS1, aTS2);
868 const Bnd_Box& aBox=aSR.BndBox();
869 //
870 thePB->SetShrunkData(aTS1, aTS2, aBox);
871}
b4109929 872//=======================================================================
873//function : ForceInterfVE
874//purpose :
875//=======================================================================
876void BOPAlgo_PaveFiller::ForceInterfVE(const Standard_Integer nV,
877 Handle(BOPDS_PaveBlock)& aPB,
878 BOPDS_MapOfPaveBlock& aMPBToUpdate)
879{
880 Standard_Integer aNbPnt, nE;
881 gp_Pnt aP;
882 //
883 nE = aPB->OriginalEdge();
884 //
885 const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
886 if (aSIE.HasSubShape(nV)) {
887 return;
888 }
889 //
890 if (myDS->HasInterf(nV, nE)) {
891 return;
892 }
893 //
894 if (myDS->HasInterfShapeSubShapes(nV, nE)) {
895 return;
896 }
897 //
898 if (aPB->Pave1().Index() == nV || aPB->Pave2().Index() == nV) {
899 return;
900 }
901 //
902 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV);
903 const TopoDS_Edge& aE = *(TopoDS_Edge*) &myDS->Shape(nE);
904 aP=BRep_Tool::Pnt(aV);
905 //
906 GeomAPI_ProjectPointOnCurve& aProjector=myContext->ProjPC(aE);
907 aProjector.Perform(aP);
908 //
909 aNbPnt = aProjector.NbPoints();
910 if (aNbPnt) {
911 Standard_Real aT, aDist;
402bfe81 912 //Standard_Integer i;
b4109929 913 BRep_Builder aBB;
914 BOPDS_Pave aPave;
915 //
916 aDist=aProjector.LowerDistance();
917 aT=aProjector.LowerDistanceParameter();
918 //
919 BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
402bfe81 920 BOPDS_InterfVE& aVE=aVEs.Append1();
b4109929 921 aVE.SetIndices(nV, nE);
922 aVE.SetParameter(aT);
923 //
924 myDS->AddInterf(nV, nE);
925 //
926 aBB.UpdateVertex(aV, aDist);
927 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV);
928 Bnd_Box& aBox=aSIDS.ChangeBox();
929 BRepBndLib::Add(aV, aBox);
930 //
931 aPave.SetIndex(nV);
932 aPave.SetParameter(aT);
933 aPB->AppendExtPave(aPave);
934 //
935 aMPBToUpdate.Add(aPB);
936 }
937}
938
4e57c75e 939 /*
940 // DEBf
941 {
942 TopoDS_Compound aCx;
943 BRep_Builder aBBx;
944 aBBx.MakeCompound(aCx);
945 aItMVCPB.Initialize(theMVCPB);
946 for (; aItMVCPB.More(); aItMVCPB.Next()) {
947 const TopoDS_Shape& aS=aItMVCPB.Key();
948 aBBx.Add(aCx, aS);
949 }
950 BRepTools::Write(aCx, "cx");
951 }
952 // DEBt
953 */