0024470: Wrong result done by General Fuse algorithm.
[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//
973c2be1 9// This library is free software; you can redistribute it and / or modify it
10// under the terms of the GNU Lesser General Public version 2.1 as published
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
26#include <TopoDS_Edge.hxx>
27#include <TopoDS_Vertex.hxx>
28#include <TopoDS_Compound.hxx>
29#include <BRep_Tool.hxx>
30#include <BRep_Builder.hxx>
31#include <BRepTools.hxx>
32#include <BRepBndLib.hxx>
33//
34#include <IntTools_EdgeEdge.hxx>
35#include <IntTools_Range.hxx>
36#include <IntTools_SequenceOfCommonPrts.hxx>
37#include <IntTools_CommonPrt.hxx>
38#include <IntTools_SequenceOfRanges.hxx>
39//
40#include <BOPTools_AlgoTools.hxx>
41//
42#include <BOPCol_DataMapOfShapeInteger.hxx>
43#include <BOPCol_DataMapOfIntegerShape.hxx>
44#include <BOPCol_IndexedDataMapOfShapeBox.hxx>
45//
46#include <BOPInt_Context.hxx>
47#include <BOPInt_ShrunkRange.hxx>
48#include <BOPInt_Tools.hxx>
49//
50#include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx>
51#include <BOPDS_MapOfPaveBlock.hxx>
52#include <BOPDS_CommonBlock.hxx>
53#include <BOPDS_CoupleOfPaveBlocks.hxx>
54#include <BOPDS_DataMapOfPaveBlockListOfInteger.hxx>
55#include <BOPDS_Iterator.hxx>
56#include <BOPDS_VectorOfInterfEE.hxx>
57#include <BOPDS_Interf.hxx>
58#include <BOPDS_Pave.hxx>
59#include <BOPDS_BoxBndTree.hxx>
60
61#include <BOPAlgo_Tools.hxx>
b4109929 62#include <GeomAPI_ProjectPointOnCurve.hxx>
4e57c75e 63
64//=======================================================================
65// function: PerformEE
66// purpose:
67//=======================================================================
68 void BOPAlgo_PaveFiller::PerformEE()
69{
70 Standard_Boolean bJustAdd, bOrder;
71 Standard_Integer i, iX, iSize, nE1, nE2, aDiscretize;
72 Standard_Integer aNbCPrts, nWhat, nWith;
b4109929 73 Standard_Real aTS11, aTS12, aTS21, aTS22,
74 aT11, aT12, aT21, aT22;
4e57c75e 75 Standard_Real aTolE1, aTolE2, aDeflection;
76 TopAbs_ShapeEnum aType;
77 TopoDS_Edge aEWhat, aEWith;
78 BOPDS_ListIteratorOfListOfPaveBlock aIt1, aIt2;
79 Handle(NCollection_IncAllocator) aAllocator;
b4109929 80 Handle(BOPDS_PaveBlock) aPBn1, aPBn2;
81 BOPDS_MapOfPaveBlock aMPBToUpdate;
82 BOPDS_MapIteratorOfMapOfPaveBlock aItPB;
4e57c75e 83 //
84 myErrorStatus=0;
85 //
86 myIterator->Initialize(TopAbs_EDGE, TopAbs_EDGE);
87 iSize=myIterator->ExpectedLength();
88 if (!iSize) {
89 return;
90 }
91 //
92 //-----------------------------------------------------scope f
93 aAllocator=new NCollection_IncAllocator();
94 BOPDS_IndexedDataMapOfPaveBlockListOfPaveBlock aMPBLPB(100, aAllocator);
95 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMVCPB(100, aAllocator);
96 //
97 aDiscretize=30;
98 aDeflection=0.01;
99 //
100 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
101 aEEs.SetStartSize(iSize);
102 aEEs.SetIncrement(iSize);
103 aEEs.Init();
104 //
105 for (; myIterator->More(); myIterator->Next()) {
106 myIterator->Value(nE1, nE2, bJustAdd);
107 if(bJustAdd) {
108 continue;
109 }
110 //
111 const BOPDS_ShapeInfo& aSIE1=myDS->ShapeInfo(nE1);
112 if (aSIE1.HasFlag()){
113 continue;
114 }
115 const BOPDS_ShapeInfo& aSIE2=myDS->ShapeInfo(nE2);
116 if (aSIE2.HasFlag()){
117 continue;
118 }
119 //
120 const TopoDS_Edge& aE1=(*(TopoDS_Edge *)(&aSIE1.Shape()));
121 const TopoDS_Edge& aE2=(*(TopoDS_Edge *)(&aSIE2.Shape()));
122 //
123 aTolE1=BRep_Tool::Tolerance(aE1);
124 aTolE2=BRep_Tool::Tolerance(aE2);
125 //
126 BOPDS_ListOfPaveBlock& aLPB1=myDS->ChangePaveBlocks(nE1);
127 BOPDS_ListOfPaveBlock& aLPB2=myDS->ChangePaveBlocks(nE2);
128 //
129 aIt1.Initialize(aLPB1);
130 for (; aIt1.More(); aIt1.Next()) {
131 Bnd_Box aBB1;
132 //
133 Handle(BOPDS_PaveBlock)& aPB1=aIt1.ChangeValue();
134 if (!aPB1->HasShrunkData()) {
135 FillShrunkData(aPB1);
136 if (myWarningStatus) {
137 continue;
138 }
139 }
140 aPB1->ShrunkData(aTS11, aTS12, aBB1);
141 //
142 aIt2.Initialize(aLPB2);
143 for (; aIt2.More(); aIt2.Next()) {
144 Bnd_Box aBB2;
145 //
146 Handle(BOPDS_PaveBlock)& aPB2=aIt2.ChangeValue();
147 if (!aPB2->HasShrunkData()) {
148 FillShrunkData(aPB2);
149 if (myWarningStatus) {
150 continue;
151 }
152 }
153 aPB2->ShrunkData(aTS21, aTS22, aBB2);
154 //
155 if (aBB1.IsOut(aBB2)) {
156 continue;
157 }
158 //
159 // -----------f
160 //DEBft
161 //printf(" nE1=%d nE2=%d\n", nE1, nE2);
162 //
163 IntTools_EdgeEdge aEdgeEdge;
164 //
165 aEdgeEdge.SetEdge1 (aE1);
166 aEdgeEdge.SetEdge2 (aE2);
167 aEdgeEdge.SetTolerance1 (aTolE1);
168 aEdgeEdge.SetTolerance2 (aTolE2);
169 aEdgeEdge.SetDiscretize (aDiscretize);
170 aEdgeEdge.SetDeflection (aDeflection);
171 //
172 IntTools_Range aSR1(aTS11, aTS12);
173 IntTools_Range aSR2(aTS21, aTS22);
174 IntTools_Range anewSR1 = aSR1;
175 IntTools_Range anewSR2 = aSR2;
176 //
177 BOPTools_AlgoTools::CorrectRange (aE1, aE2, aSR1, anewSR1);
178 BOPTools_AlgoTools::CorrectRange (aE2, aE1, aSR2, anewSR2);
179 //
b4109929 180 aPB1->Range(aT11, aT12);
181 aPB2->Range(aT21, aT22);
182 IntTools_Range aPBRange1(aT11, aT12), aPBRange2(aT21, aT22);
183 //
184 IntTools_Range aPBR1 = aPBRange1;
185 IntTools_Range aPBR2 = aPBRange2;
186 BOPTools_AlgoTools::CorrectRange (aE1, aE2, aPBR1, aPBRange1);
187 BOPTools_AlgoTools::CorrectRange (aE2, aE1, aPBR2, aPBRange2);
188 //
189 aEdgeEdge.SetRange1(aPBRange1);
190 aEdgeEdge.SetRange2(aPBRange2);
4e57c75e 191 //
192 aEdgeEdge.Perform();
193 if (!aEdgeEdge.IsDone()) {
194 continue;
195 }
196 //
197 bOrder=aEdgeEdge.Order();
198 if (!bOrder) {
199 aEWhat=aE1;
200 aEWith=aE2;
201 nWhat=nE1;
202 nWith=nE2;
b4109929 203 aSR1=anewSR1;
204 aSR2=anewSR2;
205 aPBR1=aPBRange1;
206 aPBR2=aPBRange2;
207 aPBn1=aPB1;
208 aPBn2=aPB2;
4e57c75e 209 }
210 else {
211 nWhat=nE2;
212 nWith=nE1;
213 aEWhat=aE2;
214 aEWith=aE1;
b4109929 215 aSR1=anewSR2;
216 aSR2=anewSR1;
217 aPBR1=aPBRange2;
218 aPBR2=aPBRange1;
219 aPBn1=aPB2;
220 aPBn2=aPB1;
4e57c75e 221 }
222 //
b4109929 223 IntTools_Range aR11(aPBR1.First(), aSR1.First()), aR12(aSR1.Last(), aPBR1.Last()),
224 aR21(aPBR2.First(), aSR2.First()), aR22(aSR2.Last(), aPBR2.Last());
225 //
4e57c75e 226 const IntTools_SequenceOfCommonPrts& aCPrts=aEdgeEdge.CommonParts();
227 //
228 aNbCPrts=aCPrts.Length();
229 for (i=1; i<=aNbCPrts; ++i) {
230 const IntTools_CommonPrt& aCPart=aCPrts(i);
231 aType=aCPart.Type();
232 switch (aType) {
233 case TopAbs_VERTEX: {
b4109929 234 Standard_Boolean bIsOnPave[4], bFlag;
235 Standard_Integer nV[4], j;
4e57c75e 236 Standard_Real aT1, aT2, aTol;
4e57c75e 237 TopoDS_Vertex aVnew;
238 //
239 BOPInt_Tools::VertexParameters(aCPart, aT1, aT2);
240 aTol=Precision::Confusion();
241 //
242 //decide to keep the pave or not
b4109929 243 bIsOnPave[0] = BOPInt_Tools::IsOnPave1(aT1, aR11, aTol);
244 bIsOnPave[1] = BOPInt_Tools::IsOnPave1(aT1, aR12, aTol);
245 bIsOnPave[2] = BOPInt_Tools::IsOnPave1(aT2, aR21, aTol);
246 bIsOnPave[3] = BOPInt_Tools::IsOnPave1(aT2, aR22, aTol);
4e57c75e 247 //
b4109929 248 aPBn1->Indices(nV[0], nV[1]);
249 aPBn2->Indices(nV[2], nV[3]);
250 //
251 if((bIsOnPave[0] && bIsOnPave[2]) || (bIsOnPave[0] && bIsOnPave[3]) ||
252 (bIsOnPave[1] && bIsOnPave[2]) || (bIsOnPave[1] && bIsOnPave[3])) {
253 continue;
254 }
4e57c75e 255 //
b4109929 256 bFlag = Standard_False;
257 for (j = 0; j < 4; ++j) {
258 if (bIsOnPave[j]) {
259 //add interf VE(nV[j], nE)
260 Handle(BOPDS_PaveBlock)& aPB = (j < 2) ? aPBn2 : aPBn1;
261 ForceInterfVE(nV[j], aPB, aMPBToUpdate);
262 bFlag = Standard_True;
263 break;
264 }
265 }
266 if (bFlag) {
4e57c75e 267 continue;
268 }
269 //
270 BOPTools_AlgoTools::MakeNewVertex(aEWhat, aT1, aEWith, aT2, aVnew);
271 // <-LXBR
272 {
b4109929 273 Standard_Integer nVS[2], iFound, k;
4e57c75e 274 Standard_Real aTolVx, aTolVnew, aD2, aDT2;
275 BOPCol_MapOfInteger aMV;
276 gp_Pnt aPnew, aPx;
277 //
278 iFound=0;
279 j=-1;
b4109929 280 aMV.Add(nV[0]);
281 aMV.Add(nV[1]);
4e57c75e 282 //
b4109929 283 if (aMV.Contains(nV[2])) {
4e57c75e 284 ++j;
b4109929 285 nVS[j]=nV[2];
4e57c75e 286 }
b4109929 287 if (aMV.Contains(nV[3])) {
4e57c75e 288 ++j;
b4109929 289 nVS[j]=nV[3];
4e57c75e 290 }
291 //
292 aTolVnew=BRep_Tool::Tolerance(aVnew);
293 aPnew=BRep_Tool::Pnt(aVnew);
294 //
295 for (k=0; k<=j; ++k) {
296 const TopoDS_Vertex& aVx= *(TopoDS_Vertex*)&(myDS->Shape(nVS[k]));
297 aTolVx=BRep_Tool::Tolerance(aVx);
298 aPx=BRep_Tool::Pnt(aVx);
299 aD2=aPnew.SquareDistance(aPx);
300 //
301 aDT2=100.*(aTolVnew+aTolVx)*(aTolVnew+aTolVx);
302 //
303 if (aD2<aDT2) {
304 iFound=1;
305 break;
306 }
307 }
308 //
309 if (iFound) {
310 continue;
311 }
312 }
313
314 // 1
315 iX=aEEs.Append()-1;
316 BOPDS_InterfEE& aEE=aEEs(iX);
317 aEE.SetIndices(nWhat, nWith);
318 aEE.SetCommonPart(aCPart);
319 // 2
320 myDS->AddInterf(nWhat, nWith);
321 //
322 BOPDS_CoupleOfPaveBlocks aCPB;
323 //
324 aCPB.SetPaveBlocks(aPB1, aPB2);
325 aCPB.SetIndexInterf(iX);
326 aMVCPB.Add(aVnew, aCPB);
327 }//case TopAbs_VERTEX:
328 break;
329 //
330 case TopAbs_EDGE: {
7eed5d29 331 if (aNbCPrts > 1) {
4e57c75e 332 break;
333 }
7eed5d29 334 //
335 Standard_Boolean bHasSameBounds;
4e57c75e 336 bHasSameBounds=aPB1->HasSameBounds(aPB2);
337 if (!bHasSameBounds) {
338 break;
339 }
340 // 1
341 iX=aEEs.Append()-1;
342 BOPDS_InterfEE& aEE=aEEs(iX);
343 aEE.SetIndices(nWhat, nWith);
344 aEE.SetCommonPart(aCPart);
345 // 2
346 myDS->AddInterf(nWhat, nWith);
347 //
348 BOPAlgo_Tools::FillMap(aPB1, aPB2, aMPBLPB, aAllocator);
349 }//case TopAbs_EDGE
350 break;
351 default:
352 break;
353 }//switch (aType) {
354 }//for (i=1; i<=aNbCPrts; i++) {
355 // -----------t
356 //
357 }// for (; aIt2.More(); aIt2.Next()) {
358 }// for (; aIt1.More(); aIt1.Next()) {
359 }
360 //
361 //=========================================
362 // post treatment
363 //=========================================
b4109929 364 aItPB.Initialize(aMPBToUpdate);
365 for (; aItPB.More(); aItPB.Next()) {
366 Handle(BOPDS_PaveBlock) aPB=aItPB.Value();
367 if (!myDS->IsCommonBlock(aPB)) {
368 myDS->UpdatePaveBlock(aPB);
369 }
370 else {
371 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
372 myDS->UpdateCommonBlock(aCB);
373 }
374 }
375 //
5a77460e 376 BOPAlgo_Tools::PerformCommonBlocks(aMPBLPB, aAllocator, myDS);
4e57c75e 377 PerformVerticesEE(aMVCPB, aAllocator);
378 //-----------------------------------------------------scope t
379 aMPBLPB.Clear();
380 aMVCPB.Clear();
b4109929 381 aMPBToUpdate.Clear();
4e57c75e 382 aAllocator.Nullify();
383}
384//=======================================================================
385//function : PerformVertices
386//purpose :
387//=======================================================================
388 Standard_Integer BOPAlgo_PaveFiller::PerformVerticesEE
389 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMVCPB,
390 Handle(NCollection_BaseAllocator)& theAllocator)
391{
392 Standard_Integer aNbV, iRet;
393 //
394 iRet=0;
395 aNbV=theMVCPB.Extent();
396 if (!aNbV) {
397 return iRet;
398 }
399 //
400 Standard_Integer nVx, iV, j, nE, iFlag, iX, i, aNb;
401 Standard_Real aT;
402 TopoDS_Shape aV;
403 BOPCol_ListIteratorOfListOfShape aItLS;
404 BOPCol_ListIteratorOfListOfInteger aItLI;
405 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
406 BOPDS_ShapeInfo aSI;
407 BOPDS_Pave aPave;
408 //
409 BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, theAllocator);
410 BOPCol_ListOfShape aLS(theAllocator);
411 BOPCol_IndexedDataMapOfShapeInteger aMVI(100, theAllocator);
412 BOPCol_IndexedDataMapOfShapeListOfShape aImages;
413 //
414 aSI.SetShapeType(TopAbs_VERTEX);
415 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
416 //
417 // 1 prepare arguments
418 //
419 // <- DEB
420 for (i=1; i<=aNbV; ++i) {
421 const TopoDS_Shape& aS=theMVCPB.FindKey(i);
422 const BOPDS_CoupleOfPaveBlocks& aCPB=theMVCPB.FindFromIndex(i);
423 iV=aCPB.IndexInterf();
424 aMVI.Add(aS, iV);
425 }
426 //
427 // 2 Fuse vertices
428 TreatNewVertices(aMVI, aImages);
429 //
430 // 3 Add new vertices to myDS;
431 // connect indices to CPB structure
432 aNb = aImages.Extent();
433 for (i=1; i<=aNb; ++i) {
434 const TopoDS_Vertex& aV=(*(TopoDS_Vertex*)(&aImages.FindKey(i)));
435 const BOPCol_ListOfShape& aLVSD=aImages.FindFromIndex(i);
436 //
437 aSI.SetShape(aV);
438 iV=myDS->Append(aSI);
439 //
440 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(iV);
441 Bnd_Box& aBox=aSIDS.ChangeBox();
442 BRepBndLib::Add(aV, aBox);
443 //
444 aItLS.Initialize(aLVSD);
445 for (; aItLS.More(); aItLS.Next()) {
446 const TopoDS_Shape& aVx = aItLS.Value();
447 BOPDS_CoupleOfPaveBlocks &aCPB=theMVCPB.ChangeFromKey(aVx);
448 aCPB.SetIndex(iV);
449 // update EE interference
450 iX=aCPB.IndexInterf();
451 BOPDS_InterfEE& aEE=aEEs(iX);
452 aEE.SetIndexNew(iV);
453 }
454 }
455 //
456 // 4 Map PaveBlock/ListOfVertices to add to this PaveBlock ->aMPBLI
457 {
458 Handle(BOPDS_PaveBlock) aPB[2];
459 //
460 for (i=1; i<=aNbV; ++i) {
461 const BOPDS_CoupleOfPaveBlocks& aCPB=theMVCPB.FindFromIndex(i);
462 iV=aCPB.Index();
463 aCPB.PaveBlocks(aPB[0], aPB[1]);
464 for (j=0; j<2; ++j) {
465 if (aMPBLI.Contains(aPB[j])) {
466 BOPCol_ListOfInteger& aLI=aMPBLI.ChangeFromKey(aPB[j]);
467 aLI.Append(iV);
468 }
469 else {
470 BOPCol_ListOfInteger aLI(theAllocator);
471 aLI.Append(iV);
472 aMPBLI.Add(aPB[j], aLI);
473 }
474 }
475 }
476 }
477 //
478 // 5
479 // 5.1 Compute Extra Paves and
480 // 5.2. Add Extra Paves to the PaveBlocks
481 aNb=aMPBLI.Extent();
482 for(i=1; i<=aNb; ++i) {
483 Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
484 nE=aPB->OriginalEdge();
485 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
486 // 1,2
487 const BOPCol_ListOfInteger& aLI=aMPBLI.FindFromIndex(i);
488 aItLI.Initialize(aLI);
489 for (; aItLI.More(); aItLI.Next()) {
490 nVx=aItLI.Value();
491 const TopoDS_Vertex& aVx=(*(TopoDS_Vertex *)(&myDS->Shape(nVx)));
492 //
493 iFlag=myContext->ComputeVE (aVx, aE, aT);
494 if (!iFlag) {
495 aPave.SetIndex(nVx);
496 aPave.SetParameter(aT);
497 aPB->AppendExtPave(aPave);
498 }
499 }
500 }
501 // 6 Split PaveBlocksa
502 aNb=aMPBLI.Extent();
503 for(i=1; i<=aNb; ++i) {
504 Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
505 nE=aPB->OriginalEdge();
506 // 3
5a77460e 507 if (!myDS->IsCommonBlock(aPB)) {
4e57c75e 508 myDS->UpdatePaveBlock(aPB);
509 }
510 else {
5a77460e 511 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
4e57c75e 512 myDS->UpdateCommonBlock(aCB);
513 }
514 }//for (; aItMPBLI.More(); aItMPBLI.Next()) {
515 //
516 return iRet;
517}
518
519//=======================================================================
520//function : TreatNewVertices
521//purpose :
522//=======================================================================
523 void BOPAlgo_PaveFiller::TreatNewVertices(
524 const BOPCol_IndexedDataMapOfShapeInteger& aMapVI,
525 BOPCol_IndexedDataMapOfShapeListOfShape& myImages)
526{
527 Standard_Integer j, i, aNbV, aNbVSD;
528 Standard_Real aTol;
529 TopoDS_Shape aVF;
530 TopoDS_Vertex aVnew;
531 BOPCol_IndexedMapOfShape aMVProcessed;
532
533 BOPCol_ListIteratorOfListOfInteger aIt;
534 BOPCol_IndexedDataMapOfShapeListOfShape aMVLV;
535 BOPCol_DataMapOfIntegerShape aMIS;
536 BOPCol_IndexedDataMapOfShapeBox aMSB;
537 //
538 BOPDS_BoxBndTreeSelector aSelector;
539 BOPDS_BoxBndTree aBBTree;
540 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
541 //
542 aNbV = aMapVI.Extent();
543 for (i=1; i<=aNbV; ++i) {
544 const TopoDS_Shape& aV=aMapVI.FindKey(i);
545 Bnd_Box aBox;
546 //
547 aTol=BRep_Tool::Tolerance(*(TopoDS_Vertex*)(&aV));
548 aBox.SetGap(aTol);
549 BRepBndLib::Add(aV, aBox);
550 //
551 aTreeFiller.Add(i, aBox);
552 //
553 aMIS.Bind(i, aV);
554 aMSB.Add(aV, aBox);
555 }
556 //
557 aTreeFiller.Fill();
558
559 // Chains
560 for (i=1; i<=aNbV; ++i) {
561 const TopoDS_Shape& aV=aMapVI.FindKey(i);
562 //
563 if (aMVProcessed.Contains(aV)) {
564 continue;
565 }
566 //
567 Standard_Integer aNbIP, aIP, aNbIP1, aIP1;
568 BOPCol_ListOfShape aLVSD;
569 BOPCol_MapOfInteger aMIP, aMIP1, aMIPC;
570 BOPCol_MapIteratorOfMapOfInteger aIt1;
571 //
572 aMIP.Add(i);
302f96fb 573 for(;;) {
4e57c75e 574 aNbIP=aMIP.Extent();
575 aIt1.Initialize(aMIP);
576 for(; aIt1.More(); aIt1.Next()) {
577 aIP=aIt1.Key();
578 if (aMIPC.Contains(aIP)) {
579 continue;
580 }
581 //
582 const TopoDS_Shape& aVP=aMIS.Find(aIP);
583 const Bnd_Box& aBoxVP=aMSB.FindFromKey(aVP);
584 //
585 aSelector.Clear();
586 aSelector.SetBox(aBoxVP);
587 //
588 aNbVSD=aBBTree.Select(aSelector);
589 if (!aNbVSD) {
590 continue; // it must not be
591 }
592 //
593 const BOPCol_ListOfInteger& aLI=aSelector.Indices();
594 aIt.Initialize(aLI);
595 for (; aIt.More(); aIt.Next()) {
596 aIP1=aIt.Value();
597 if (aMIP.Contains(aIP1)) {
598 continue;
599 }
600 aMIP1.Add(aIP1);
601 } //for (; aIt.More(); aIt.Next()) {
602 }//for(; aIt1.More(); aIt1.Next()) {
603 //
604 aNbIP1=aMIP1.Extent();
605 if (!aNbIP1) {
606 break; // from while(1)
607 }
608 //
609 aIt1.Initialize(aMIP);
610 for(; aIt1.More(); aIt1.Next()) {
611 aIP=aIt1.Key();
612 aMIPC.Add(aIP);
613 }
614 //
615 aMIP.Clear();
616 aIt1.Initialize(aMIP1);
617 for(; aIt1.More(); aIt1.Next()) {
618 aIP=aIt1.Key();
619 aMIP.Add(aIP);
620 }
621 aMIP1.Clear();
622 }// while(1)
623 //...
624 aNbIP=aMIPC.Extent();
625 if (!aNbIP) {
626 aMIPC.Add(i);
627 }
628 //
629 aIt1.Initialize(aMIPC);
630 for(j=0; aIt1.More(); aIt1.Next(), ++j) {
631 aIP=aIt1.Key();
632 const TopoDS_Shape& aVP=aMIS.Find(aIP);
633 if (!j) {
634 aVF=aVP;
635 }
636 aLVSD.Append(aVP);
637 aMVProcessed.Add(aVP);
638 }
639 aMVLV.Add(aVF, aLVSD);
640 }// for (i=1; i<=aNbV; ++i) {
641
642 // Make new vertices
643 aNbV=aMVLV.Extent();
644 for (i=1; i<=aNbV; ++i) {
645 const TopoDS_Shape& aV=aMVLV.FindKey(i);
646 BOPCol_ListOfShape& aLVSD=aMVLV.ChangeFromIndex(i);
647 aNbVSD=aLVSD.Extent();
648 if (aNbVSD>1) {
649 BOPTools_AlgoTools::MakeVertex(aLVSD, aVnew);
650 myImages.Add(aVnew, aLVSD);
651 } else {
652 myImages.Add(aV, aLVSD);
653 }
654 }
655}
656
657//=======================================================================
658//function : FillShrunkData
659//purpose :
660//=======================================================================
661 void BOPAlgo_PaveFiller::FillShrunkData(Handle(BOPDS_PaveBlock)& thePB)
662{
663 Standard_Integer nE, nV1, nV2, iErr;
664 Standard_Real aT1, aT2, aTS1, aTS2;
665 BOPInt_ShrunkRange aSR;
666 //
667 myErrorStatus=0;
668 myWarningStatus = 0;
669 //
670 const BOPDS_Pave& aPave1=thePB->Pave1();
671 nV1=aPave1.Index();
672 aT1=aPave1.Parameter();
673 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
674 //
675 const BOPDS_Pave& aPave2=thePB->Pave2();
676 nV2=aPave2.Index();
677 aT2=aPave2.Parameter();
678 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
679 //
680 nE=thePB->OriginalEdge();
681 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
682 //
683 aSR.SetData(aE, aT1, aT2, aV1, aV2, myContext);
684 //
685 aSR.Perform();
686 iErr=aSR.ErrorStatus();
687 if (iErr) {
688 myWarningStatus = 1;
689 //myErrorStatus=40;
690 return;
691 }
692 //
693 aSR.ShrunkRange(aTS1, aTS2);
694 const Bnd_Box& aBox=aSR.BndBox();
695 //
696 thePB->SetShrunkData(aTS1, aTS2, aBox);
697}
b4109929 698//=======================================================================
699//function : ForceInterfVE
700//purpose :
701//=======================================================================
702void BOPAlgo_PaveFiller::ForceInterfVE(const Standard_Integer nV,
703 Handle(BOPDS_PaveBlock)& aPB,
704 BOPDS_MapOfPaveBlock& aMPBToUpdate)
705{
706 Standard_Integer aNbPnt, nE;
707 gp_Pnt aP;
708 //
709 nE = aPB->OriginalEdge();
710 //
711 const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
712 if (aSIE.HasSubShape(nV)) {
713 return;
714 }
715 //
716 if (myDS->HasInterf(nV, nE)) {
717 return;
718 }
719 //
720 if (myDS->HasInterfShapeSubShapes(nV, nE)) {
721 return;
722 }
723 //
724 if (aPB->Pave1().Index() == nV || aPB->Pave2().Index() == nV) {
725 return;
726 }
727 //
728 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV);
729 const TopoDS_Edge& aE = *(TopoDS_Edge*) &myDS->Shape(nE);
730 aP=BRep_Tool::Pnt(aV);
731 //
732 GeomAPI_ProjectPointOnCurve& aProjector=myContext->ProjPC(aE);
733 aProjector.Perform(aP);
734 //
735 aNbPnt = aProjector.NbPoints();
736 if (aNbPnt) {
737 Standard_Real aT, aDist;
738 Standard_Integer i;
739 BRep_Builder aBB;
740 BOPDS_Pave aPave;
741 //
742 aDist=aProjector.LowerDistance();
743 aT=aProjector.LowerDistanceParameter();
744 //
745 BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
746 i=aVEs.Append()-1;
747 BOPDS_InterfVE& aVE=aVEs(i);
748 aVE.SetIndices(nV, nE);
749 aVE.SetParameter(aT);
750 //
751 myDS->AddInterf(nV, nE);
752 //
753 aBB.UpdateVertex(aV, aDist);
754 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV);
755 Bnd_Box& aBox=aSIDS.ChangeBox();
756 BRepBndLib::Add(aV, aBox);
757 //
758 aPave.SetIndex(nV);
759 aPave.SetParameter(aT);
760 aPB->AppendExtPave(aPave);
761 //
762 aMPBToUpdate.Add(aPB);
763 }
764}
765
4e57c75e 766 /*
767 // DEBf
768 {
769 TopoDS_Compound aCx;
770 BRep_Builder aBBx;
771 aBBx.MakeCompound(aCx);
772 aItMVCPB.Initialize(theMVCPB);
773 for (; aItMVCPB.More(); aItMVCPB.Next()) {
774 const TopoDS_Shape& aS=aItMVCPB.Key();
775 aBBx.Add(aCx, aS);
776 }
777 BRepTools::Write(aCx, "cx");
778 }
779 // DEBt
780 */