0028259: Method MakeBlocksCnx is duplicated in two different places in BOPAlgo
[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
4e57c75e 18
19#include <Bnd_Box.hxx>
42cf5bc1 20#include <BOPAlgo_PaveFiller.hxx>
21#include <BOPAlgo_SectionAttribute.hxx>
22#include <BOPAlgo_Tools.hxx>
23#include <BOPCol_BoxBndTree.hxx>
24#include <BOPCol_DataMapOfIntegerShape.hxx>
4e57c75e 25#include <BOPCol_DataMapOfShapeInteger.hxx>
a2098360 26#include <BOPCol_DataMapOfShapeListOfShape.hxx>
4e57c75e 27#include <BOPCol_IndexedDataMapOfShapeBox.hxx>
a942f2da 28#include <BOPCol_NCVector.hxx>
c7b59798 29#include <BOPCol_Parallel.hxx>
4e57c75e 30#include <BOPDS_CommonBlock.hxx>
31#include <BOPDS_CoupleOfPaveBlocks.hxx>
42cf5bc1 32#include <BOPDS_Curve.hxx>
4e57c75e 33#include <BOPDS_DataMapOfPaveBlockListOfInteger.hxx>
42cf5bc1 34#include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx>
35#include <BOPDS_DS.hxx>
4e57c75e 36#include <BOPDS_Interf.hxx>
42cf5bc1 37#include <BOPDS_Iterator.hxx>
38#include <BOPDS_MapOfPaveBlock.hxx>
4e57c75e 39#include <BOPDS_Pave.hxx>
42cf5bc1 40#include <BOPDS_PaveBlock.hxx>
41#include <BOPDS_VectorOfInterfEE.hxx>
42#include <BOPTools_AlgoTools.hxx>
01b5b3df 43#include <BndLib_Add3dCurve.hxx>
42cf5bc1 44#include <BRep_Tool.hxx>
45#include <BRepBndLib.hxx>
46#include <BRepTools.hxx>
3510db62 47#include <BRepAdaptor_Curve.hxx>
42cf5bc1 48#include <gp_Pnt.hxx>
49#include <IntTools_CommonPrt.hxx>
50#include <IntTools_Context.hxx>
51#include <IntTools_EdgeEdge.hxx>
52#include <IntTools_Range.hxx>
53#include <IntTools_SequenceOfCommonPrts.hxx>
54#include <IntTools_SequenceOfRanges.hxx>
55#include <IntTools_ShrunkRange.hxx>
56#include <IntTools_Tools.hxx>
42cf5bc1 57#include <NCollection_UBTreeFiller.hxx>
58#include <Precision.hxx>
59#include <TopoDS_Compound.hxx>
60#include <TopoDS_Edge.hxx>
61#include <TopoDS_Face.hxx>
62#include <TopoDS_Vertex.hxx>
db8e4b9a 63
a2098360 64/////////////////////////////////////////////////////////////////////////
a942f2da 65//=======================================================================
66//class : BOPAlgo_EdgeEdge
67//purpose :
68//=======================================================================
36f4947b 69class BOPAlgo_EdgeEdge :
70 public IntTools_EdgeEdge,
71 public BOPAlgo_Algo {
72
a942f2da 73 public:
36f4947b 74
75 DEFINE_STANDARD_ALLOC
76 //
77 BOPAlgo_EdgeEdge():
78 IntTools_EdgeEdge(),
79 BOPAlgo_Algo() {
a942f2da 80 };
81 //
36f4947b 82 virtual ~BOPAlgo_EdgeEdge(){
a942f2da 83 };
84 //
85 void SetPaveBlock1(const Handle(BOPDS_PaveBlock)& aPB) {
86 myPB1=aPB;
87 }
88 //
89 Handle(BOPDS_PaveBlock)& PaveBlock1() {
90 return myPB1;
91 }
92 //
93 void SetPaveBlock2(const Handle(BOPDS_PaveBlock)& aPB) {
94 myPB2=aPB;
95 }
96 //
97 Handle(BOPDS_PaveBlock)& PaveBlock2() {
98 return myPB2;
99 }
36f4947b 100 //
0d0481c7 101 void SetFuzzyValue(const Standard_Real theFuzz) {
102 IntTools_EdgeEdge::SetFuzzyValue(theFuzz);
103 }
104 //
36f4947b 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//=======================================================================
0d0481c7 132class BOPAlgo_TNV;
133typedef BOPCol_NCVector
134 <BOPAlgo_TNV> BOPAlgo_VectorOfTNV;
135//
136typedef BOPCol_Functor
137 <BOPAlgo_TNV,
138 BOPAlgo_VectorOfTNV> BOPAlgo_TNVFunctor;
139//
140typedef BOPCol_Cnt
141 <BOPAlgo_TNVFunctor,
142 BOPAlgo_VectorOfTNV> BOPAlgo_TNVCnt;
143//=======================================================================
a2098360 144class BOPAlgo_TNV : public BOPCol_BoxBndTreeSelector{
145 public:
146 BOPAlgo_TNV()
0d0481c7 147 : BOPCol_BoxBndTreeSelector(),
148 myTol (0.), myFuzzyValue(0.), myTree(NULL), myVecTNV(NULL) {
a2098360 149 };
150 //
151 ~BOPAlgo_TNV(){
152 };
153 //
154 void SetVertex(const TopoDS_Vertex& aV) {
155 myV=aV;
0d0481c7 156 myPnt = BRep_Tool::Pnt(myV);
a2098360 157 }
158 //
159 const TopoDS_Vertex& Vertex()const {
160 return myV;
161 }
162 //
163 void SetTree(BOPCol_BoxBndTree& aTree) {
164 myTree=&aTree;
165 }
166 //
0d0481c7 167 void SetTolerance(const Standard_Real theTol) {
168 myTol = theTol;
169 }
170 //
171 Standard_Real Tolerance() const {
172 return myTol;
173 }
174 //
175 const gp_Pnt& Pnt() const {
176 return myPnt;
177 }
178 //
179 void SetFuzzyValue(const Standard_Real theFuzzyValue) {
180 myFuzzyValue = theFuzzyValue;
181 }
182 //
183 void SetVectorOfTNV(const BOPAlgo_VectorOfTNV& theVec) {
184 myVecTNV = &theVec;
185 }
186 //
187 virtual Standard_Boolean Accept(const Standard_Integer& theIndex)
188 {
189 const BOPAlgo_TNV& aTNV = myVecTNV->Value(theIndex - 1);
190 Standard_Real aTolSum2 = myTol + aTNV.Tolerance() + myFuzzyValue;
191 aTolSum2 *= aTolSum2;
192 Standard_Real aD2 = myPnt.SquareDistance(aTNV.Pnt());
193 if (aD2 < aTolSum2)
194 return BOPCol_BoxBndTreeSelector::Accept(theIndex);
195 return Standard_False;
196 }
197 //
a2098360 198 void Perform() {
199 myTree->Select(*this);
200 }
201 //
202 protected:
0d0481c7 203 Standard_Real myTol;
204 Standard_Real myFuzzyValue;
205 gp_Pnt myPnt;
a2098360 206 TopoDS_Vertex myV;
207 BOPCol_BoxBndTree *myTree;
0d0481c7 208 const BOPAlgo_VectorOfTNV *myVecTNV;
a2098360 209};
210//
a2098360 211/////////////////////////////////////////////////////////////////////////
212//=======================================================================
213//class : BOPAlgo_PVE
214//purpose :
215//=======================================================================
216class BOPAlgo_PVE {
217 public:
218 BOPAlgo_PVE()
219 : myIV(-1), myIE(-1), myFlag(-1), myT(-1.) {
220 };
221 //
222 ~BOPAlgo_PVE(){
223 };
224 //
225 void SetIndices(const Standard_Integer nV,
226 const Standard_Integer nE){
227 myIV=nV;
228 myIE=nE;
229 }
230 //
231 void Indices(Standard_Integer& nV,
232 Standard_Integer& nE) const {
233 nV=myIV;
234 nE=myIE;
235 }
236 //
237 void SetVertex(const TopoDS_Vertex& aV) {
238 myV=aV;
239 }
240 //
241 const TopoDS_Vertex& Vertex()const {
242 return myV;
243 }
244 //
245 void SetEdge(const TopoDS_Edge& aE) {
246 myE=aE;
247 }
248 //
249 const TopoDS_Edge& Edge()const {
250 return myE;
251 }
252 //
253 void SetPaveBlock(const Handle(BOPDS_PaveBlock)& aPB) {
254 myPB=aPB;
255 }
256 //
257 Handle(BOPDS_PaveBlock)& PaveBlock() {
258 return myPB;
259 }
260 //
261 Standard_Integer Flag()const {
262 return myFlag;
263 }
264 //
265 Standard_Real Parameter()const {
266 return myT;
267 }
268 //
1e143abb 269 void SetContext(const Handle(IntTools_Context)& aContext) {
a2098360 270 myContext=aContext;
271 }
272 //
1e143abb 273 const Handle(IntTools_Context)& Context()const {
a2098360 274 return myContext;
275 }
276 //
0d0481c7 277 void SetFuzzyValue(const Standard_Real theValue) {
278 myFuzzyValue = theValue;
279 }
280 //
a2098360 281 void Perform() {
3510db62 282 Standard_Real dummy;
0d0481c7 283 myFlag = myContext->ComputeVE(myV, myE, myT, dummy, myFuzzyValue);
a2098360 284 };
285 //
286 protected:
287 Standard_Integer myIV;
288 Standard_Integer myIE;
289 Standard_Integer myFlag;
290 Standard_Real myT;
0d0481c7 291 Standard_Real myFuzzyValue;
a2098360 292 TopoDS_Vertex myV;
293 TopoDS_Edge myE;
294 Handle(BOPDS_PaveBlock) myPB;
1e143abb 295 Handle(IntTools_Context) myContext;
a2098360 296};
297//=======================================================================
298typedef BOPCol_NCVector
299 <BOPAlgo_PVE> BOPAlgo_VectorOfPVE;
300//
c7b59798 301typedef BOPCol_ContextFunctor
a2098360 302 <BOPAlgo_PVE,
303 BOPAlgo_VectorOfPVE,
1e143abb 304 Handle(IntTools_Context),
305 IntTools_Context> BOPAlgo_PVEFunctor;
a2098360 306//
c7b59798 307typedef BOPCol_ContextCnt
a2098360 308 <BOPAlgo_PVEFunctor,
309 BOPAlgo_VectorOfPVE,
1e143abb 310 Handle(IntTools_Context)> BOPAlgo_PVECnt;
a2098360 311/////////////////////////////////////////////////////////////////////////
4e57c75e 312//=======================================================================
313// function: PerformEE
314// purpose:
315//=======================================================================
db8e4b9a 316void BOPAlgo_PaveFiller::PerformEE()
4e57c75e 317{
a942f2da 318 Standard_Integer iSize;
4e57c75e 319 //
320 myErrorStatus=0;
321 //
505abfb8 322 FillShrunkData(TopAbs_EDGE, TopAbs_EDGE);
323 //
4e57c75e 324 myIterator->Initialize(TopAbs_EDGE, TopAbs_EDGE);
325 iSize=myIterator->ExpectedLength();
326 if (!iSize) {
327 return;
328 }
329 //
25dfc507 330 Standard_Boolean bExpressCompute, bIsPBSplittable1, bIsPBSplittable2;
01b5b3df 331 Standard_Integer i, iX, nE1, nE2, aNbCPrts, k, aNbEdgeEdge;
6dc83e21 332 Standard_Integer nV11, nV12, nV21, nV22;
a942f2da 333 Standard_Real aTS11, aTS12, aTS21, aTS22, aT11, aT12, aT21, aT22;
334 TopAbs_ShapeEnum aType;
335 BOPDS_ListIteratorOfListOfPaveBlock aIt1, aIt2;
488e5b9d 336 Handle(NCollection_BaseAllocator) aAllocator;
a942f2da 337 BOPDS_MapOfPaveBlock aMPBToUpdate;
338 BOPAlgo_VectorOfEdgeEdge aVEdgeEdge;
339 BOPDS_MapIteratorOfMapOfPaveBlock aItPB;
340 //
488e5b9d 341 aAllocator=NCollection_BaseAllocator::CommonBaseAllocator();
4e57c75e 342 //-----------------------------------------------------scope f
4e57c75e 343 BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock aMPBLPB(100, aAllocator);
344 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMVCPB(100, aAllocator);
01b5b3df 345 BOPAlgo_DataMapOfPaveBlockBndBox aDMPBBox(100, aAllocator);
4e57c75e 346 //
4e57c75e 347 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
4e57c75e 348 aEEs.SetIncrement(iSize);
4e57c75e 349 //
350 for (; myIterator->More(); myIterator->Next()) {
25dfc507 351 myIterator->Value(nE1, nE2);
4e57c75e 352 //
353 const BOPDS_ShapeInfo& aSIE1=myDS->ShapeInfo(nE1);
354 if (aSIE1.HasFlag()){
355 continue;
356 }
357 const BOPDS_ShapeInfo& aSIE2=myDS->ShapeInfo(nE2);
358 if (aSIE2.HasFlag()){
359 continue;
360 }
361 //
752f9d72 362 BOPDS_ListOfPaveBlock& aLPB1 = myDS->ChangePaveBlocks(nE1);
363 if (aLPB1.IsEmpty()) {
364 continue;
365 }
366 //
367 BOPDS_ListOfPaveBlock& aLPB2 = myDS->ChangePaveBlocks(nE2);
368 if (aLPB2.IsEmpty()) {
369 continue;
370 }
371 //
4e57c75e 372 const TopoDS_Edge& aE1=(*(TopoDS_Edge *)(&aSIE1.Shape()));
01b5b3df 373 const TopoDS_Edge& aE2=(*(TopoDS_Edge *)(&aSIE2.Shape()));
4e57c75e 374 //
4e57c75e 375 aIt1.Initialize(aLPB1);
376 for (; aIt1.More(); aIt1.Next()) {
377 Bnd_Box aBB1;
378 //
379 Handle(BOPDS_PaveBlock)& aPB1=aIt1.ChangeValue();
01b5b3df 380 //
381 if (!GetPBBox(aE1, aPB1, aDMPBBox, aT11, aT12, aTS11, aTS12, aBB1)) {
505abfb8 382 continue;
4e57c75e 383 }
4e57c75e 384 //
6dc83e21 385 aPB1->Indices(nV11, nV12);
386 //
4e57c75e 387 aIt2.Initialize(aLPB2);
388 for (; aIt2.More(); aIt2.Next()) {
389 Bnd_Box aBB2;
390 //
391 Handle(BOPDS_PaveBlock)& aPB2=aIt2.ChangeValue();
01b5b3df 392 //
393 if (!GetPBBox(aE2, aPB2, aDMPBBox, aT21, aT22, aTS21, aTS22, aBB2)) {
505abfb8 394 continue;
4e57c75e 395 }
4e57c75e 396 //
397 if (aBB1.IsOut(aBB2)) {
398 continue;
399 }
400 //
6dc83e21 401 aPB2->Indices(nV21, nV22);
402 //
403 bExpressCompute=((nV11==nV21 && nV12==nV22) ||
404 (nV12==nV21 && nV11==nV22));
405 //
a942f2da 406 BOPAlgo_EdgeEdge& anEdgeEdge=aVEdgeEdge.Append1();
6dc83e21 407 //
408 anEdgeEdge.UseQuickCoincidenceCheck(bExpressCompute);
409 //
a942f2da 410 anEdgeEdge.SetPaveBlock1(aPB1);
411 anEdgeEdge.SetPaveBlock2(aPB2);
412 //
ec0cdc0e 413 anEdgeEdge.SetEdge1(aE1, aT11, aT12);
414 anEdgeEdge.SetEdge2(aE2, aT21, aT22);
0d0481c7 415 anEdgeEdge.SetFuzzyValue(myFuzzyValue);
36f4947b 416 anEdgeEdge.SetProgressIndicator(myProgressIndicator);
a942f2da 417 }//for (; aIt2.More(); aIt2.Next()) {
418 }//for (; aIt1.More(); aIt1.Next()) {
419 }//for (; myIterator->More(); myIterator->Next()) {
420 //
01b5b3df 421 aNbEdgeEdge=aVEdgeEdge.Extent();
a942f2da 422 //======================================================
423 BOPAlgo_EdgeEdgeCnt::Perform(myRunParallel, aVEdgeEdge);
424 //======================================================
425 //
01b5b3df 426 for (k = 0; k < aNbEdgeEdge; ++k) {
a942f2da 427 Bnd_Box aBB1, aBB2;
428 //
429 BOPAlgo_EdgeEdge& anEdgeEdge=aVEdgeEdge(k);
430 if (!anEdgeEdge.IsDone()) {
431 continue;
432 }
433 //
51db0179 434 const IntTools_SequenceOfCommonPrts& aCPrts = anEdgeEdge.CommonParts();
435 aNbCPrts = aCPrts.Length();
436 if (!aNbCPrts) {
437 continue;
438 }
a942f2da 439 //--------------------------------------------
440 Handle(BOPDS_PaveBlock)& aPB1=anEdgeEdge.PaveBlock1();
441 nE1=aPB1->OriginalEdge();
442 aPB1->Range(aT11, aT12);
01b5b3df 443 if (!aPB1->HasShrunkData()) {
444 aTS11 = aT11;
445 aTS12 = aT12;
446 bIsPBSplittable1 = Standard_False;
447 }
448 else {
449 aPB1->ShrunkData(aTS11, aTS12, aBB1, bIsPBSplittable1);
450 }
a942f2da 451 //
452 Handle(BOPDS_PaveBlock)& aPB2=anEdgeEdge.PaveBlock2();
453 nE2=aPB2->OriginalEdge();
454 aPB2->Range(aT21, aT22);
01b5b3df 455 if (!aPB2->HasShrunkData()) {
456 aTS21 = aT21;
457 aTS22 = aT22;
458 bIsPBSplittable2 = Standard_False;
459 }
460 else {
461 aPB2->ShrunkData(aTS21, aTS22, aBB2, bIsPBSplittable2);
462 }
a942f2da 463 //
464 //--------------------------------------------
465 IntTools_Range aR11(aT11, aTS11), aR12(aTS12, aT12),
466 aR21(aT21, aTS21), aR22(aTS22, aT22);
467 //
3065019c 468 Standard_Boolean bAnalytical = Standard_False;
51db0179 469 {
3510db62 470 const TopoDS_Edge& aOE1 = *(TopoDS_Edge*)&myDS->Shape(nE1);
471 const TopoDS_Edge& aOE2 = *(TopoDS_Edge*)&myDS->Shape(nE2);
472 //
473 BRepAdaptor_Curve aBAC1(aOE1), aBAC2(aOE2);
474 //
3065019c 475 GeomAbs_CurveType aType1 = aBAC1.GetType();
476 GeomAbs_CurveType aType2 = aBAC2.GetType();
477 //
478 bAnalytical = (((aType1 == GeomAbs_Line) &&
479 (aType2 == GeomAbs_Line ||
480 aType2 == GeomAbs_Circle)) ||
481 ((aType2 == GeomAbs_Line) &&
482 (aType1 == GeomAbs_Line ||
483 aType1 == GeomAbs_Circle)));
3510db62 484 }
485 //
a942f2da 486 for (i=1; i<=aNbCPrts; ++i) {
487 const IntTools_CommonPrt& aCPart=aCPrts(i);
488 //
489 const TopoDS_Edge& aE1=aCPart.Edge1();
490 const TopoDS_Edge& aE2=aCPart.Edge2();
491 //
492 aType=aCPart.Type();
493 switch (aType) {
494 case TopAbs_VERTEX: {
01b5b3df 495 if (!bIsPBSplittable1 || !bIsPBSplittable2) {
496 continue;
497 }
498 //
a942f2da 499 Standard_Boolean bIsOnPave[4], bFlag;
500 Standard_Integer nV[4], j;
501 Standard_Real aT1, aT2, aTol;
502 TopoDS_Vertex aVnew;
503 IntTools_Range aCR1, aCR2;
504 //
1e143abb 505 IntTools_Tools::VertexParameters(aCPart, aT1, aT2);
a942f2da 506 aTol = Precision::Confusion();
507 aCR1 = aCPart.Range1();
508 aCR2 = aCPart.Ranges2()(1);
509 //
510 //decide to keep the pave or not
1e143abb 511 bIsOnPave[0] = IntTools_Tools::IsOnPave1(aT1, aR11, aTol) ||
512 IntTools_Tools::IsOnPave1(aR11.First(), aCR1, aTol);
513 bIsOnPave[1] = IntTools_Tools::IsOnPave1(aT1, aR12, aTol) ||
514 IntTools_Tools::IsOnPave1(aR12.Last(), aCR1, aTol);
515 bIsOnPave[2] = IntTools_Tools::IsOnPave1(aT2, aR21, aTol) ||
516 IntTools_Tools::IsOnPave1(aR21.First(), aCR2, aTol);
517 bIsOnPave[3] = IntTools_Tools::IsOnPave1(aT2, aR22, aTol) ||
518 IntTools_Tools::IsOnPave1(aR22.Last(), aCR2, aTol);
a942f2da 519 //
520 aPB1->Indices(nV[0], nV[1]);
521 aPB2->Indices(nV[2], nV[3]);
522 //
523 if((bIsOnPave[0] && bIsOnPave[2]) ||
524 (bIsOnPave[0] && bIsOnPave[3]) ||
525 (bIsOnPave[1] && bIsOnPave[2]) ||
526 (bIsOnPave[1] && bIsOnPave[3])) {
527 continue;
528 }
529 //
530 bFlag = Standard_False;
531 for (j = 0; j < 4; ++j) {
532 if (bIsOnPave[j]) {
533 //add interf VE(nV[j], nE)
534 Handle(BOPDS_PaveBlock)& aPB = (j < 2) ? aPB2 : aPB1;
535 ForceInterfVE(nV[j], aPB, aMPBToUpdate);
536 bFlag = Standard_True;
537 break;
538 }
539 }
540 if (bFlag) {
24542bc0 541 BOPDS_InterfEE& aEE = aEEs.Append1();
542 aEE.SetIndices(nE1, nE2);
543 aEE.SetCommonPart(aCPart);
a942f2da 544 continue;
545 }
546 //
547 BOPTools_AlgoTools::MakeNewVertex(aE1, aT1, aE2, aT2, aVnew);
3510db62 548 Standard_Real aTolVnew = BRep_Tool::Tolerance(aVnew);
3065019c 549 if (bAnalytical) {
3510db62 550 // increase tolerance for Line/Line intersection, but do not update
551 // the vertex till its intersection with some other shape
3065019c 552 Standard_Real aTolMin = (BRepAdaptor_Curve(aE1).GetType() == GeomAbs_Line) ?
553 (aCR1.Last() - aCR1.First()) / 2. : (aCR2.Last() - aCR2.First()) / 2.;
8bb8064e 554 if (aTolMin > aTolVnew) {
555 aTolVnew = aTolMin;
3510db62 556 }
557 }
a942f2da 558 // <-LXBR
559 {
51740958 560 Standard_Integer nVS[2], iFound;
3510db62 561 Standard_Real aTolVx, aD2, aDT2;
a942f2da 562 BOPCol_MapOfInteger aMV;
563 gp_Pnt aPnew, aPx;
4e57c75e 564 //
a942f2da 565 iFound=0;
566 j=-1;
567 aMV.Add(nV[0]);
568 aMV.Add(nV[1]);
569 //
570 if (aMV.Contains(nV[2])) {
571 ++j;
572 nVS[j]=nV[2];
573 }
574 if (aMV.Contains(nV[3])) {
575 ++j;
576 nVS[j]=nV[3];
577 }
578 //
a942f2da 579 aPnew=BRep_Tool::Pnt(aVnew);
580 //
51740958 581 for (Standard_Integer k1=0; k1<=j; ++k1) {
582 const TopoDS_Vertex& aVx= *(TopoDS_Vertex*)&(myDS->Shape(nVS[k1]));
a942f2da 583 aTolVx=BRep_Tool::Tolerance(aVx);
584 aPx=BRep_Tool::Pnt(aVx);
585 aD2=aPnew.SquareDistance(aPx);
586 //
587 aDT2=100.*(aTolVnew+aTolVx)*(aTolVnew+aTolVx);
7eed5d29 588 //
a942f2da 589 if (aD2<aDT2) {
590 iFound=1;
4e57c75e 591 break;
592 }
a942f2da 593 }
594 //
595 if (iFound) {
596 continue;
597 }
598 }
402bfe81 599 //
a942f2da 600 // 1
402bfe81 601 BOPDS_InterfEE& aEE=aEEs.Append1();
602 iX=aEEs.Extent()-1;
a942f2da 603 aEE.SetIndices(nE1, nE2);
604 aEE.SetCommonPart(aCPart);
605 // 2
606 myDS->AddInterf(nE1, nE2);
607 //
608 BOPDS_CoupleOfPaveBlocks aCPB;
609 //
610 aCPB.SetPaveBlocks(aPB1, aPB2);
611 aCPB.SetIndexInterf(iX);
3510db62 612 aCPB.SetTolerance(aTolVnew);
a942f2da 613 aMVCPB.Add(aVnew, aCPB);
614 }//case TopAbs_VERTEX:
615 break;
616 //
617 case TopAbs_EDGE: {
618 if (aNbCPrts > 1) {
4e57c75e 619 break;
a942f2da 620 }
621 //
622 Standard_Boolean bHasSameBounds;
623 bHasSameBounds=aPB1->HasSameBounds(aPB2);
624 if (!bHasSameBounds) {
625 break;
626 }
627 // 1
402bfe81 628 BOPDS_InterfEE& aEE=aEEs.Append1();
629 iX=aEEs.Extent()-1;
a942f2da 630 aEE.SetIndices(nE1, nE2);
631 aEE.SetCommonPart(aCPart);
632 // 2
633 myDS->AddInterf(nE1, nE2);
634 //
edfa30de 635 BOPAlgo_Tools::FillMap<Handle(BOPDS_PaveBlock), TColStd_MapTransientHasher>(aPB1, aPB2, aMPBLPB, aAllocator);
a942f2da 636 }//case TopAbs_EDGE
637 break;
638 default:
639 break;
640 }//switch (aType) {
641 }//for (i=1; i<=aNbCPrts; i++) {
642 }//for (k=0; k < aNbFdgeEdge; ++k) {
4e57c75e 643 //
644 //=========================================
645 // post treatment
646 //=========================================
a3476a9f 647 {
648 Standard_Integer aNbV;
649 Handle(BOPDS_PaveBlock) aPB1, aPB2;
650 //
651 aNbV=aMVCPB.Extent();
652 for (i=1; i<=aNbV; ++i) {
653 const BOPDS_CoupleOfPaveBlocks& aCPB=aMVCPB.FindFromIndex(i);
654 aCPB.PaveBlocks(aPB1, aPB2);
655 //
656 aMPBToUpdate.Remove(aPB1);
657 aMPBToUpdate.Remove(aPB2);
658 }
659 }
660 //
b4109929 661 aItPB.Initialize(aMPBToUpdate);
662 for (; aItPB.More(); aItPB.Next()) {
663 Handle(BOPDS_PaveBlock) aPB=aItPB.Value();
664 if (!myDS->IsCommonBlock(aPB)) {
665 myDS->UpdatePaveBlock(aPB);
666 }
667 else {
668 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
0d0481c7 669 myDS->UpdateCommonBlock(aCB, myFuzzyValue);
b4109929 670 }
671 }
672 //
5a77460e 673 BOPAlgo_Tools::PerformCommonBlocks(aMPBLPB, aAllocator, myDS);
4e57c75e 674 PerformVerticesEE(aMVCPB, aAllocator);
675 //-----------------------------------------------------scope t
676 aMPBLPB.Clear();
677 aMVCPB.Clear();
b4109929 678 aMPBToUpdate.Clear();
4e57c75e 679}
680//=======================================================================
3510db62 681//function : PerformVerticesEE
4e57c75e 682//purpose :
683//=======================================================================
db8e4b9a 684Standard_Integer BOPAlgo_PaveFiller::PerformVerticesEE
685 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMVCPB,
7f22979e 686 const Handle(NCollection_BaseAllocator)& theAllocator)
4e57c75e 687{
688 Standard_Integer aNbV, iRet;
689 //
690 iRet=0;
691 aNbV=theMVCPB.Extent();
692 if (!aNbV) {
693 return iRet;
694 }
695 //
696 Standard_Integer nVx, iV, j, nE, iFlag, iX, i, aNb;
697 Standard_Real aT;
4e57c75e 698 BOPCol_ListIteratorOfListOfShape aItLS;
699 BOPCol_ListIteratorOfListOfInteger aItLI;
700 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
701 BOPDS_ShapeInfo aSI;
702 BOPDS_Pave aPave;
703 //
704 BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, theAllocator);
705 BOPCol_ListOfShape aLS(theAllocator);
706 BOPCol_IndexedDataMapOfShapeInteger aMVI(100, theAllocator);
707 BOPCol_IndexedDataMapOfShapeListOfShape aImages;
708 //
709 aSI.SetShapeType(TopAbs_VERTEX);
710 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
711 //
712 // 1 prepare arguments
4e57c75e 713 // 2 Fuse vertices
3510db62 714 TreatNewVertices(theMVCPB, aImages);
4e57c75e 715 //
716 // 3 Add new vertices to myDS;
717 // connect indices to CPB structure
718 aNb = aImages.Extent();
719 for (i=1; i<=aNb; ++i) {
720 const TopoDS_Vertex& aV=(*(TopoDS_Vertex*)(&aImages.FindKey(i)));
721 const BOPCol_ListOfShape& aLVSD=aImages.FindFromIndex(i);
722 //
723 aSI.SetShape(aV);
724 iV=myDS->Append(aSI);
725 //
726 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(iV);
727 Bnd_Box& aBox=aSIDS.ChangeBox();
728 BRepBndLib::Add(aV, aBox);
3510db62 729 aBox.SetGap(aBox.GetGap() + Precision::Confusion());
4e57c75e 730 //
731 aItLS.Initialize(aLVSD);
732 for (; aItLS.More(); aItLS.Next()) {
733 const TopoDS_Shape& aVx = aItLS.Value();
734 BOPDS_CoupleOfPaveBlocks &aCPB=theMVCPB.ChangeFromKey(aVx);
735 aCPB.SetIndex(iV);
736 // update EE interference
737 iX=aCPB.IndexInterf();
738 BOPDS_InterfEE& aEE=aEEs(iX);
739 aEE.SetIndexNew(iV);
740 }
741 }
742 //
743 // 4 Map PaveBlock/ListOfVertices to add to this PaveBlock ->aMPBLI
744 {
745 Handle(BOPDS_PaveBlock) aPB[2];
746 //
747 for (i=1; i<=aNbV; ++i) {
748 const BOPDS_CoupleOfPaveBlocks& aCPB=theMVCPB.FindFromIndex(i);
749 iV=aCPB.Index();
750 aCPB.PaveBlocks(aPB[0], aPB[1]);
751 for (j=0; j<2; ++j) {
752 if (aMPBLI.Contains(aPB[j])) {
753 BOPCol_ListOfInteger& aLI=aMPBLI.ChangeFromKey(aPB[j]);
754 aLI.Append(iV);
755 }
756 else {
757 BOPCol_ListOfInteger aLI(theAllocator);
758 aLI.Append(iV);
759 aMPBLI.Add(aPB[j], aLI);
760 }
761 }
762 }
763 }
4e57c75e 764 // 5
765 // 5.1 Compute Extra Paves and
766 // 5.2. Add Extra Paves to the PaveBlocks
a2098360 767 //-------------------------------------------------------------
768 Standard_Integer k, aNbVPVE;
769 BOPAlgo_VectorOfPVE aVPVE;
770 //
4e57c75e 771 aNb=aMPBLI.Extent();
772 for(i=1; i<=aNb; ++i) {
773 Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
774 nE=aPB->OriginalEdge();
775 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
776 // 1,2
777 const BOPCol_ListOfInteger& aLI=aMPBLI.FindFromIndex(i);
778 aItLI.Initialize(aLI);
779 for (; aItLI.More(); aItLI.Next()) {
780 nVx=aItLI.Value();
781 const TopoDS_Vertex& aVx=(*(TopoDS_Vertex *)(&myDS->Shape(nVx)));
782 //
a2098360 783 BOPAlgo_PVE& aPVE=aVPVE.Append1();
784 aPVE.SetIndices(nVx, nE);
785 aPVE.SetVertex(aVx);
786 aPVE.SetEdge(aE);
0d0481c7 787 aPVE.SetFuzzyValue(myFuzzyValue);
a2098360 788 aPVE.SetPaveBlock(aPB);
789 }
790 }
791 //
792 aNbVPVE=aVPVE.Extent();
793 //=============================================================
794 BOPAlgo_PVECnt::Perform(myRunParallel, aVPVE, myContext);
795 //=============================================================
796 //
797 for (k=0; k < aNbVPVE; ++k) {
798 BOPAlgo_PVE& aPVE=aVPVE(k);
799 iFlag=aPVE.Flag();
800 if (!iFlag) {
801 aPVE.Indices(nVx, nE);
802 aT=aPVE.Parameter();
803 Handle(BOPDS_PaveBlock)& aPB=aPVE.PaveBlock();
804 //
805 aPave.SetIndex(nVx);
806 aPave.SetParameter(aT);
807 aPB->AppendExtPave(aPave);
4e57c75e 808 }
809 }
810 // 6 Split PaveBlocksa
811 aNb=aMPBLI.Extent();
812 for(i=1; i<=aNb; ++i) {
813 Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
814 nE=aPB->OriginalEdge();
815 // 3
5a77460e 816 if (!myDS->IsCommonBlock(aPB)) {
4e57c75e 817 myDS->UpdatePaveBlock(aPB);
818 }
819 else {
5a77460e 820 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
0d0481c7 821 myDS->UpdateCommonBlock(aCB, myFuzzyValue);
4e57c75e 822 }
823 }//for (; aItMPBLI.More(); aItMPBLI.Next()) {
824 //
825 return iRet;
826}
4e57c75e 827//=======================================================================
828//function : TreatNewVertices
829//purpose :
830//=======================================================================
db8e4b9a 831void BOPAlgo_PaveFiller::TreatNewVertices
3510db62 832(const BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMVCPB,
db8e4b9a 833 BOPCol_IndexedDataMapOfShapeListOfShape& myImages)
4e57c75e 834{
a2098360 835 Standard_Integer i, aNbV;//, aNbVSD;
4e57c75e 836 Standard_Real aTol;
4e57c75e 837 TopoDS_Vertex aVnew;
838 BOPCol_IndexedMapOfShape aMVProcessed;
a2098360 839 BOPCol_MapOfInteger aMFence;
4e57c75e 840 BOPCol_ListIteratorOfListOfInteger aIt;
3510db62 841 NCollection_Vector<BOPCol_ListOfShape> aVecOfLVSD;
4e57c75e 842 //
db8e4b9a 843 BOPCol_BoxBndTree aBBTree;
a2098360 844 NCollection_UBTreeFiller <Standard_Integer,
845 Bnd_Box> aTreeFiller(aBBTree);
846 BOPAlgo_VectorOfTNV aVTNV;
4e57c75e 847 //
0d0481c7 848 Standard_Real aTolAdd = myFuzzyValue / 2.;
3510db62 849 aNbV = theMVCPB.Extent();
4e57c75e 850 for (i=1; i<=aNbV; ++i) {
3510db62 851 const TopoDS_Vertex& aV = *((TopoDS_Vertex*)&theMVCPB.FindKey(i));
4e57c75e 852 Bnd_Box aBox;
853 //
3510db62 854 aTol = theMVCPB.FindFromIndex(i).Tolerance();
a2098360 855 aBox.Add(BRep_Tool::Pnt(aV));
3065019c 856 aBox.SetGap(aTol + aTolAdd);
4e57c75e 857 //
858 aTreeFiller.Add(i, aBox);
859 //
a2098360 860 BOPAlgo_TNV& aTNV=aVTNV.Append1();
861 aTNV.SetTree(aBBTree);
862 aTNV.SetBox(aBox);
863 aTNV.SetVertex(aV);
0d0481c7 864 aTNV.SetTolerance(aTol);
865 aTNV.SetFuzzyValue(myFuzzyValue);
866 aTNV.SetVectorOfTNV(aVTNV);
4e57c75e 867 }
868 //
869 aTreeFiller.Fill();
a2098360 870 //
871 //===========================================
872 BOPAlgo_TNVCnt::Perform(myRunParallel, aVTNV);
873 //===========================================
874 //
4e57c75e 875 // Chains
876 for (i=1; i<=aNbV; ++i) {
a2098360 877 if (!aMFence.Add(i)) {
4e57c75e 878 continue;
879 }
880 //
a2098360 881 Standard_Integer aIP, aNbIP1, aIP1;
4e57c75e 882 BOPCol_ListOfShape aLVSD;
a2098360 883 BOPCol_ListOfInteger aLIP, aLIP1, aLIPC;
884 BOPCol_ListIteratorOfListOfInteger aItLIP;
4e57c75e 885 //
a2098360 886 aLIPC.Append(i);
887 aLIP.Append(i);
302f96fb 888 for(;;) {
a2098360 889 aItLIP.Initialize(aLIP);
890 for(; aItLIP.More(); aItLIP.Next()) {
891 aIP=aItLIP.Value();
4e57c75e 892 //
a2098360 893 BOPAlgo_TNV& aTNV=aVTNV(aIP-1);
894 const BOPCol_ListOfInteger& aLI=aTNV.Indices();
4e57c75e 895 aIt.Initialize(aLI);
896 for (; aIt.More(); aIt.Next()) {
897 aIP1=aIt.Value();
a2098360 898 if (!aMFence.Add(aIP1)) {
4e57c75e 899 continue;
900 }
a2098360 901 aLIP1.Append(aIP1);
4e57c75e 902 } //for (; aIt.More(); aIt.Next()) {
903 }//for(; aIt1.More(); aIt1.Next()) {
904 //
a2098360 905 aNbIP1=aLIP1.Extent();
4e57c75e 906 if (!aNbIP1) {
a2098360 907 break; // from for(;;)
4e57c75e 908 }
909 //
3510db62 910 aLIP = aLIP1;
911 aLIPC.Append(aLIP1); // items of aLIP1 are moved to aLIPC
a2098360 912 }// for(;;) {
4e57c75e 913 //
a2098360 914 aItLIP.Initialize(aLIPC);
915 for(; aItLIP.More(); aItLIP.Next()) {
916 aIP=aItLIP.Value();
917 const TopoDS_Vertex& aVP=aVTNV(aIP-1).Vertex();
4e57c75e 918 aLVSD.Append(aVP);
4e57c75e 919 }
3510db62 920 aVecOfLVSD.Append(aLVSD);
4e57c75e 921 }// for (i=1; i<=aNbV; ++i) {
922
923 // Make new vertices
3510db62 924 aNbV = aVecOfLVSD.Size();
925 for (i = 0; i < aNbV; ++i) {
926 const BOPCol_ListOfShape& aLVSD = aVecOfLVSD(i);
927 BOPTools_AlgoTools::MakeVertex(aLVSD, aVnew);
928 myImages.Add(aVnew, aLVSD);
4e57c75e 929 }
930}
4e57c75e 931//=======================================================================
932//function : FillShrunkData
933//purpose :
934//=======================================================================
db8e4b9a 935void BOPAlgo_PaveFiller::FillShrunkData(Handle(BOPDS_PaveBlock)& thePB)
4e57c75e 936{
01b5b3df 937 Standard_Integer nE, nV1, nV2;
4e57c75e 938 Standard_Real aT1, aT2, aTS1, aTS2;
1e143abb 939 IntTools_ShrunkRange aSR;
4e57c75e 940 //
941 myErrorStatus=0;
942 myWarningStatus = 0;
943 //
944 const BOPDS_Pave& aPave1=thePB->Pave1();
945 nV1=aPave1.Index();
946 aT1=aPave1.Parameter();
947 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
948 //
949 const BOPDS_Pave& aPave2=thePB->Pave2();
950 nV2=aPave2.Index();
951 aT2=aPave2.Parameter();
952 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
953 //
954 nE=thePB->OriginalEdge();
955 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
956 //
505abfb8 957 aSR.SetContext(myContext);
958 aSR.SetData(aE, aT1, aT2, aV1, aV2);
4e57c75e 959 //
960 aSR.Perform();
01b5b3df 961 if (!aSR.IsDone()) {
4e57c75e 962 myWarningStatus = 1;
4e57c75e 963 return;
964 }
965 //
966 aSR.ShrunkRange(aTS1, aTS2);
967 const Bnd_Box& aBox=aSR.BndBox();
01b5b3df 968 Standard_Boolean bIsSplittable = aSR.IsSplittable();
4e57c75e 969 //
01b5b3df 970 thePB->SetShrunkData(aTS1, aTS2, aBox, bIsSplittable);
4e57c75e 971}
b4109929 972//=======================================================================
973//function : ForceInterfVE
974//purpose :
975//=======================================================================
976void BOPAlgo_PaveFiller::ForceInterfVE(const Standard_Integer nV,
977 Handle(BOPDS_PaveBlock)& aPB,
978 BOPDS_MapOfPaveBlock& aMPBToUpdate)
979{
3510db62 980 Standard_Integer nE, nVx, nVSD, iFlag;
981 Standard_Real aT, aTolVNew;
b4109929 982 //
983 nE = aPB->OriginalEdge();
984 //
985 const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
986 if (aSIE.HasSubShape(nV)) {
987 return;
988 }
989 //
990 if (myDS->HasInterf(nV, nE)) {
991 return;
992 }
993 //
994 if (myDS->HasInterfShapeSubShapes(nV, nE)) {
995 return;
996 }
997 //
3510db62 998 if (aPB->Pave1().Index() == nV ||
999 aPB->Pave2().Index() == nV) {
b4109929 1000 return;
1001 }
1002 //
3510db62 1003 nVx = nV;
1004 if (myDS->HasShapeSD(nV, nVSD)) {
1005 nVx = nVSD;
1006 }
b4109929 1007 //
3510db62 1008 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nVx);
1009 const TopoDS_Edge& aE = *(TopoDS_Edge*) &myDS->Shape(nE);
b4109929 1010 //
0d0481c7 1011 iFlag = myContext->ComputeVE(aV, aE, aT, aTolVNew, myFuzzyValue);
3510db62 1012 if (iFlag == 0 || iFlag == -4) {
b4109929 1013 BOPDS_Pave aPave;
1014 //
b4109929 1015 //
1016 BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
a3476a9f 1017 aVEs.SetIncrement(10);
3510db62 1018 // 1
402bfe81 1019 BOPDS_InterfVE& aVE=aVEs.Append1();
b4109929 1020 aVE.SetIndices(nV, nE);
1021 aVE.SetParameter(aT);
3510db62 1022 // 2
b4109929 1023 myDS->AddInterf(nV, nE);
1024 //
3510db62 1025 // 3 update vertex V/E if necessary
1026 nVx=UpdateVertex(nV, aTolVNew);
1027 // 4
1028 if (myDS->IsNewShape(nVx)) {
1029 aVE.SetIndexNew(nVx);
1030 }
1031 // 5 append ext pave to pave block
1032 aPave.SetIndex(nVx);
b4109929 1033 aPave.SetParameter(aT);
1034 aPB->AppendExtPave(aPave);
1035 //
1036 aMPBToUpdate.Add(aPB);
1037 }
1038}
01b5b3df 1039
1040//=======================================================================
1041//function : GetPBBox
1042//purpose :
1043//=======================================================================
1044Standard_Boolean BOPAlgo_PaveFiller::GetPBBox(const TopoDS_Edge& theE,
1045 const Handle(BOPDS_PaveBlock)& thePB,
1046 BOPAlgo_DataMapOfPaveBlockBndBox& thePBBox,
1047 Standard_Real& theFirst,
1048 Standard_Real& theLast,
1049 Standard_Real& theSFirst,
1050 Standard_Real& theSLast,
1051 Bnd_Box& theBox)
1052{
1053 thePB->Range(theFirst, theLast);
1054 // check the validity of PB's range
1055 Standard_Boolean bValid = theLast - theFirst > Precision::PConfusion();
1056 if (!bValid) {
1057 return bValid;
1058 }
1059 //
1060 // check shrunk data
1061 if (thePB->HasShrunkData()) {
1062 Standard_Boolean bIsSplittable;
1063 thePB->ShrunkData(theSFirst, theSLast, theBox, bIsSplittable);
1064 return bValid;
1065 }
1066 //
1067 theSFirst = theFirst;
1068 theSLast = theLast;
1069 // check the map
1070 if (thePBBox.IsBound(thePB)) {
1071 theBox = thePBBox.Find(thePB);
1072 }
1073 else {
1074 // build bounding box
1075 BRepAdaptor_Curve aBAC(theE);
1076 Standard_Real aTol = BRep_Tool::Tolerance(theE) + Precision::Confusion();
1077 BndLib_Add3dCurve::Add(aBAC, theSFirst, theSLast, aTol, theBox);
1078 thePBBox.Bind(thePB, theBox);
1079 }
1080 return bValid;
1081}