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