0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / BOPDS / BOPDS_DS.cxx
CommitLineData
4e57c75e 1// Created by: Peter KURNEV
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
4e57c75e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
4e57c75e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
4e57c75e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
4e57c75e 14
4e57c75e 15
4e57c75e 16#include <Bnd_Box.hxx>
42cf5bc1 17#include <BOPDS_CommonBlock.hxx>
42cf5bc1 18#include <BOPDS_DS.hxx>
19#include <BOPDS_FaceInfo.hxx>
20#include <BOPDS_IndexRange.hxx>
decdfc94 21#include <BOPDS_MapOfPave.hxx>
22#include <BOPDS_MapOfPaveBlock.hxx>
25dfc507 23#include <BOPDS_Pair.hxx>
42cf5bc1 24#include <BOPDS_PaveBlock.hxx>
25#include <BOPDS_ShapeInfo.hxx>
7a76337e 26#include <BOPDS_VectorOfPave.hxx>
4e57c75e 27#include <BOPTools_AlgoTools.hxx>
8ae442a8 28#include <BRepAdaptor_Curve.hxx>
42cf5bc1 29#include <BRep_Builder.hxx>
30#include <BRep_TEdge.hxx>
31#include <BRep_TFace.hxx>
32#include <BRep_Tool.hxx>
33#include <BRep_TVertex.hxx>
34#include <BRepBndLib.hxx>
35#include <Geom_Curve.hxx>
4e57c75e 36#include <GeomAPI_ProjectPointOnCurve.hxx>
42cf5bc1 37#include <gp_Pnt.hxx>
38#include <IntTools_Tools.hxx>
39#include <NCollection_BaseAllocator.hxx>
42cf5bc1 40#include <Precision.hxx>
41#include <Standard_Assert.hxx>
8ae442a8 42#include <TopoDS.hxx>
42cf5bc1 43#include <TopoDS_Edge.hxx>
44#include <TopoDS_Face.hxx>
45#include <TopoDS_Iterator.hxx>
46#include <TopoDS_Shape.hxx>
47#include <TopoDS_Vertex.hxx>
1155d05a 48#include <TColStd_DataMapOfIntegerListOfInteger.hxx>
49#include <TColStd_ListOfInteger.hxx>
50#include <TColStd_MapOfInteger.hxx>
51#include <TopTools_DataMapOfShapeInteger.hxx>
52#include <TopTools_MapOfShape.hxx>
7a76337e 53#include <algorithm>
42cf5bc1 54//
4e57c75e 55
56static
57 void TotalShapes(const TopoDS_Shape& aS,
3510db62 58 Standard_Integer& aNbS,
1155d05a 59 TopTools_MapOfShape& aMS);
4e57c75e 60
61static
62 Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
63 const TopoDS_Edge& aE);
4e57c75e 64
65//=======================================================================
66//function :
67//purpose :
68//=======================================================================
72e88cf7 69BOPDS_DS::BOPDS_DS()
4e57c75e 70:
71 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
72 myArguments(myAllocator),
402bfe81 73 myRanges(0,myAllocator),
74 myLines(0, myAllocator),
4e57c75e 75 myMapShapeIndex(100, myAllocator),
402bfe81 76 myPaveBlocksPool(0,myAllocator),
5a77460e 77 myMapPBCB(100, myAllocator),
402bfe81 78 myFaceInfoPool(0, myAllocator),
eafb234b 79 myShapesSD(100, myAllocator),
3510db62 80 myMapVE(100, myAllocator),
4e57c75e 81 myInterfTB(100, myAllocator),
402bfe81 82 myInterfVV(0, myAllocator),
83 myInterfVE(0, myAllocator),
84 myInterfVF(0, myAllocator),
85 myInterfEE(0, myAllocator),
86 myInterfEF(0, myAllocator),
87 myInterfFF(0, myAllocator),
88 myInterfVZ(0, myAllocator),
89 myInterfEZ(0, myAllocator),
90 myInterfFZ(0, myAllocator),
d3578357 91 myInterfZZ(0, myAllocator),
92 myInterfered(100, myAllocator)
4e57c75e 93{
94 myNbShapes=0;
95 myNbSourceShapes=0;
96}
97//=======================================================================
98//function :
99//purpose :
100//=======================================================================
72e88cf7 101BOPDS_DS::BOPDS_DS(const Handle(NCollection_BaseAllocator)& theAllocator)
4e57c75e 102:
103 myAllocator(theAllocator),
104 myArguments(myAllocator),
402bfe81 105 myRanges(0, myAllocator),
106 myLines(0, myAllocator),
4e57c75e 107 myMapShapeIndex(100, myAllocator),
402bfe81 108 myPaveBlocksPool(0, myAllocator),
5a77460e 109 myMapPBCB(100, myAllocator),
402bfe81 110 myFaceInfoPool(0, myAllocator),
eafb234b 111 myShapesSD(100, myAllocator),
3510db62 112 myMapVE(100, myAllocator),
4e57c75e 113 myInterfTB(100, myAllocator),
402bfe81 114 myInterfVV(0, myAllocator),
115 myInterfVE(0, myAllocator),
116 myInterfVF(0, myAllocator),
117 myInterfEE(0, myAllocator),
118 myInterfEF(0, myAllocator),
119 myInterfFF(0, myAllocator),
120 myInterfVZ(0, myAllocator),
121 myInterfEZ(0, myAllocator),
122 myInterfFZ(0, myAllocator),
d3578357 123 myInterfZZ(0, myAllocator),
124 myInterfered(100, myAllocator)
4e57c75e 125{
126 myNbShapes=0;
127 myNbSourceShapes=0;
128}
129//=======================================================================
130//function : ~
131//purpose :
132//=======================================================================
72e88cf7 133BOPDS_DS::~BOPDS_DS()
4e57c75e 134{
135 Clear();
136}
137//=======================================================================
138//function : Clear
139//purpose :
140//=======================================================================
72e88cf7 141void BOPDS_DS::Clear()
4e57c75e 142{
143 myNbShapes=0;
144 myNbSourceShapes=0;
145 //
146 myArguments.Clear();
147 myRanges.Clear();
148 myLines.Clear();
149 myMapShapeIndex.Clear();
150 myPaveBlocksPool.Clear();
151 myFaceInfoPool.Clear();
152 myShapesSD.Clear();
3510db62 153 myMapVE.Clear();
5a77460e 154 myMapPBCB.Clear();
4e57c75e 155 myInterfTB.Clear();
156 myInterfVV.Clear();
157 myInterfVE.Clear();
158 myInterfVF.Clear();
159 myInterfEE.Clear();
160 myInterfEF.Clear();
161 myInterfFF.Clear();
ceaa5e27 162 myInterfVZ.Clear();
163 myInterfEZ.Clear();
164 myInterfFZ.Clear();
165 myInterfZZ.Clear();
d3578357 166 myInterfered.Clear();
4e57c75e 167}
168//=======================================================================
169//function : SetArguments
170//purpose :
171//=======================================================================
1155d05a 172void BOPDS_DS::SetArguments(const TopTools_ListOfShape& theLS)
4e57c75e 173{
174 myArguments=theLS;
175}
176//=======================================================================
177//function : Arguments
178//purpose :
179//=======================================================================
1155d05a 180const TopTools_ListOfShape& BOPDS_DS::Arguments()const
4e57c75e 181{
182 return myArguments;
183}
184//=======================================================================
185//function : Allocator
186//purpose :
187//=======================================================================
72e88cf7 188const Handle(NCollection_BaseAllocator)& BOPDS_DS::Allocator()const
4e57c75e 189{
190 return myAllocator;
191}
192
193//=======================================================================
194//function : NbShapes
195//purpose :
196//=======================================================================
72e88cf7 197Standard_Integer BOPDS_DS::NbShapes()const
4e57c75e 198{
199 return myLines.Size();
200}
201//=======================================================================
202//function : NbSourceShapes
203//purpose :
204//=======================================================================
72e88cf7 205Standard_Integer BOPDS_DS::NbSourceShapes()const
4e57c75e 206{
207 return myNbSourceShapes;
208}
209//=======================================================================
210//function : NbRanges
211//purpose :
212//=======================================================================
72e88cf7 213Standard_Integer BOPDS_DS::NbRanges()const
4e57c75e 214{
215 return myRanges.Size();
216}
217//=======================================================================
218//function : Range
219//purpose :
220//=======================================================================
72e88cf7 221const BOPDS_IndexRange& BOPDS_DS::Range(const Standard_Integer theI)const
4e57c75e 222{
223 return myRanges(theI);
224}
225//=======================================================================
226//function : Rank
227//purpose :
228//=======================================================================
72e88cf7 229Standard_Integer BOPDS_DS::Rank(const Standard_Integer theI)const
4e57c75e 230{
231 Standard_Integer i, aNb, iErr;
232 //
233 iErr=-1;
234 aNb=NbRanges();
235 for(i=0; i<aNb; ++i) {
236 const BOPDS_IndexRange& aR=Range(i);
237 if (aR.Contains(theI)) {
238 return i;
239 }
240 }
241 return iErr;
242}
243//=======================================================================
244//function : IsNewShape
245//purpose :
246//=======================================================================
72e88cf7 247Standard_Boolean BOPDS_DS::IsNewShape(const Standard_Integer theI)const
4e57c75e 248{
249 return theI>=NbSourceShapes();
250}
251//=======================================================================
252//function : Append
253//purpose :
254//=======================================================================
72e88cf7 255Standard_Integer BOPDS_DS::Append(const BOPDS_ShapeInfo& theSI)
4e57c75e 256{
257 Standard_Integer iX;
258 //
1155d05a 259 myLines.Appended()=theSI;
260 iX=myLines.Length()-1;
24542bc0 261 myMapShapeIndex.Bind(theSI.Shape(), iX);
402bfe81 262 //
4e57c75e 263 return iX;
264}
265//=======================================================================
266//function : Append
267//purpose :
268//=======================================================================
72e88cf7 269Standard_Integer BOPDS_DS::Append(const TopoDS_Shape& theS)
4e57c75e 270{
271 Standard_Integer iX;
272 //
1155d05a 273 myLines.Appended().SetShape(theS);
274 iX=myLines.Length()-1;
24542bc0 275 myMapShapeIndex.Bind(theS, iX);
4e57c75e 276 return iX;
277}
278//=======================================================================
279//function : ShapeInfo
280//purpose :
281//=======================================================================
362dec17 282const BOPDS_ShapeInfo& BOPDS_DS::ShapeInfo
283 (const Standard_Integer theI)const
4e57c75e 284{
285 return myLines(theI);
286}
287//=======================================================================
288//function : ChangeShapeInfo
289//purpose :
290//=======================================================================
72e88cf7 291BOPDS_ShapeInfo& BOPDS_DS::ChangeShapeInfo(const Standard_Integer theI)
4e57c75e 292{
293 BOPDS_ShapeInfo *pSI;
294 //
295 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI);
296 pSI=(BOPDS_ShapeInfo *)&aSI;
297 return *pSI;
298}
299//=======================================================================
300//function : Shape
301//purpose :
302//=======================================================================
72e88cf7 303const TopoDS_Shape& BOPDS_DS::Shape(const Standard_Integer theI)const
4e57c75e 304{
402bfe81 305
4e57c75e 306 const TopoDS_Shape& aS=ShapeInfo(theI).Shape();
307 return aS;
308}
309//=======================================================================
310//function : Index
311//purpose :
312//=======================================================================
72e88cf7 313Standard_Integer BOPDS_DS::Index(const TopoDS_Shape& theS)const
4e57c75e 314{
315 Standard_Integer iRet;
316 //
317 iRet=-1;
318 if (myMapShapeIndex.IsBound(theS)) {
319 iRet=myMapShapeIndex.Find(theS);
320 }
321 return iRet;
322}
4e57c75e 323//=======================================================================
324//function : Init
325//purpose :
326//=======================================================================
0d0481c7 327void BOPDS_DS::Init(const Standard_Real theFuzz)
4e57c75e 328{
362dec17 329 Standard_Integer i1, i2, j, aI, aNb, aNbS, aNbE, aNbSx;
330 Standard_Integer n1, n2, n3, nV, nW, nE, aNbF;
0d0481c7 331 Standard_Real aTol, aTolAdd;
4e57c75e 332 TopAbs_ShapeEnum aTS;
50ba108c 333 TopoDS_Iterator aItS;
1155d05a 334 TColStd_ListIteratorOfListOfInteger aIt1, aIt2, aIt3;
335 TopTools_ListIteratorOfListOfShape aIt;
4e57c75e 336 BOPDS_IndexRange aR;
488e5b9d 337 Handle(NCollection_BaseAllocator) aAllocator;
1155d05a 338 TopTools_MapOfShape aMS;
4e57c75e 339 //
340 // 1 Append Source Shapes
341 aNb=myArguments.Extent();
342 if (!aNb) {
343 return;
344 }
345 //
402bfe81 346 myRanges.SetIncrement(aNb);
4e57c75e 347 //
4e57c75e 348 aNbS=0;
349 aIt.Initialize(myArguments);
350 for (; aIt.More(); aIt.Next()) {
351 const TopoDS_Shape& aSx=aIt.Value();
352 //
353 aNbSx=0;
3510db62 354 TotalShapes(aSx, aNbSx, aMS);
355 //
4e57c75e 356 aNbS=aNbS+aNbSx;
357 }
3510db62 358 aMS.Clear();
4e57c75e 359 //
402bfe81 360 myLines.SetIncrement(2*aNbS);
4e57c75e 361 //-----------------------------------------------------scope_1 f
488e5b9d 362 aAllocator=
363 NCollection_BaseAllocator::CommonBaseAllocator();
4e57c75e 364 //
4e57c75e 365 //
366 i1=0;
367 i2=0;
368 aIt.Initialize(myArguments);
369 for (; aIt.More(); aIt.Next()) {
370 const TopoDS_Shape& aS=aIt.Value();
24542bc0 371 if (myMapShapeIndex.IsBound(aS)) {
72e88cf7 372 continue;
373 }
4e57c75e 374 aI=Append(aS);
4e57c75e 375 //
24542bc0 376 InitShape(aI, aS);
4e57c75e 377 //
378 i2=NbShapes()-1;
379 aR.SetIndices(i1, i2);
380 myRanges.Append(aR);
381 i1=i2+1;
382 }
383 //
0d0481c7 384 aTolAdd = Max(theFuzz, Precision::Confusion()) * 0.5;
3510db62 385 myNbSourceShapes = NbShapes();
4e57c75e 386 //
387 // 2 Bounding Boxes
388 //
389 // 2.1 Vertex
390 for (j=0; j<myNbSourceShapes; ++j) {
391 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
392 //
393 const TopoDS_Shape& aS=aSI.Shape();
4e57c75e 394 //
395 aTS=aSI.ShapeType();
396 //
397 if (aTS==TopAbs_VERTEX) {
398 Bnd_Box& aBox=aSI.ChangeBox();
399 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aS);
400 const gp_Pnt& aP=BRep_Tool::Pnt(aV);
0d0481c7 401 aTol = BRep_Tool::Tolerance(aV);
3510db62 402 aBox.SetGap(aTol + aTolAdd);
4e57c75e 403 aBox.Add(aP);
404 }
405 }
406 // 2.2 Edge
407 aNbE=0;
408 for (j=0; j<myNbSourceShapes; ++j) {
409 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
410 //
411 aTS=aSI.ShapeType();
412 if (aTS==TopAbs_EDGE) {
413 const TopoDS_Shape& aS=aSI.Shape();
414 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aS);
0d0481c7 415 aTol = BRep_Tool::Tolerance(aE);
4e57c75e 416 //
417 if (!BRep_Tool::Degenerated(aE)) {
418 Standard_Boolean bInf1, bInf2;
419 Standard_Integer aIx;
420 Standard_Real aT1, aT2;
421 gp_Pnt aPx;
422 Handle(Geom_Curve) aC3D;
423 TopoDS_Vertex aVx;
424 TopoDS_Edge aEx;
425 BRep_Builder aBB;
426 BOPDS_ShapeInfo aSIx;
427 //
1155d05a 428 TColStd_ListOfInteger& aLI=aSI.ChangeSubShapes();
4e57c75e 429 //
430 aEx=aE;
431 aEx.Orientation(TopAbs_FORWARD);
432 //
433 aC3D=BRep_Tool::Curve (aEx, aT1, aT2);
434 bInf1=Precision::IsNegativeInfinite(aT1);
435 bInf2=Precision::IsPositiveInfinite(aT2);
436 //
437 if (bInf1) {
438 aC3D->D0(aT1, aPx);
439 aBB.MakeVertex(aVx, aPx, aTol);
440 aVx.Orientation(TopAbs_FORWARD);
441 //
442 aSIx.SetShape(aVx);
443 aSIx.SetShapeType(TopAbs_VERTEX);
444 aSIx.SetFlag(1); //infinite flag
445 //
446 aIx=Append(aSIx);
447 aLI.Append(aIx);
448 }
449 if (bInf2) {
450 aC3D->D0(aT2, aPx);
451 aBB.MakeVertex(aVx, aPx, aTol);
452 aVx.Orientation(TopAbs_REVERSED);
453 //
454 aSIx.SetShape(aVx);
455 aSIx.SetShapeType(TopAbs_VERTEX);
456 aSIx.SetFlag(1);//infinite flag
457 //
458 aIx=Append(aSIx);
459 aLI.Append(aIx);
460 }
461 }
462 else {
463 aSI.SetFlag(j);
464 }
465 //
466 Bnd_Box& aBox=aSI.ChangeBox();
467 BRepBndLib::Add(aE, aBox);
468 //
1155d05a 469 const TColStd_ListOfInteger& aLV=aSI.SubShapes();
4e57c75e 470 aIt1.Initialize(aLV);
471 for (; aIt1.More(); aIt1.Next()) {
472 nV=aIt1.Value();
473 BOPDS_ShapeInfo& aSIV=ChangeShapeInfo(nV);
474 Bnd_Box& aBx=aSIV.ChangeBox();
475 aBox.Add(aBx);
476 }
3510db62 477 aBox.SetGap(aBox.GetGap() + aTolAdd);
4e57c75e 478 ++aNbE;
479 }
480 }
481 // 2.3 Face
1155d05a 482 TColStd_MapOfInteger aMI(100, aAllocator);
483 TColStd_MapIteratorOfMapOfInteger aItMI;
4e57c75e 484 //
485 aNbF=0;
486 for (j=0; j<myNbSourceShapes; ++j) {
487 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
488 //
489 aTS=aSI.ShapeType();
490 if (aTS==TopAbs_FACE) {
491 const TopoDS_Shape& aS=aSI.Shape();
4e57c75e 492 //
493 Bnd_Box& aBox=aSI.ChangeBox();
494 BRepBndLib::Add(aS, aBox);
495 //
1155d05a 496 TColStd_ListOfInteger& aLW=aSI.ChangeSubShapes();
4e57c75e 497 aIt1.Initialize(aLW);
498 for (; aIt1.More(); aIt1.Next()) {
499 nW=aIt1.Value();
500 BOPDS_ShapeInfo& aSIW=ChangeShapeInfo(nW);
501 //
1155d05a 502 const TColStd_ListOfInteger& aLE=aSIW.SubShapes();
4e57c75e 503 aIt2.Initialize(aLE);
504 for (; aIt2.More(); aIt2.Next()) {
505 nE=aIt2.Value();
506 BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
507 Bnd_Box& aBx=aSIE.ChangeBox();
508 aBox.Add(aBx);
509 aMI.Add(nE);
510 //
511 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aSIE.Shape());
512 if (BRep_Tool::Degenerated(aE)) {
513 aSIE.SetFlag(j);
514 }
515 //
1155d05a 516 const TColStd_ListOfInteger& aLV=aSIE.SubShapes();
4e57c75e 517 aIt3.Initialize(aLV);
518 for (; aIt3.More(); aIt3.Next()) {
519 nV=aIt3.Value();
520 aMI.Add(nV);
521 }
522 }
523 }//for (; aIt1.More(); aIt1.Next()) {
524 //
50ba108c 525 // pure internal vertices on the face
526 aItS.Initialize(aS);
527 for (; aItS.More(); aItS.Next()) {
362dec17 528 const TopoDS_Shape& aSx=aItS.Value();
529 if (aSx.ShapeType()==TopAbs_VERTEX){
530 nV=Index(aSx);
531 aMI.Add(nV);
532 }
50ba108c 533 }
534 //
4e57c75e 535 //
536 // For a Face: change wires for BRep sub-shapes
537 aLW.Clear();
538 aItMI.Initialize(aMI);
539 for (; aItMI.More(); aItMI.Next()) {
540 nV=aItMI.Value();
541 aLW.Append(nV);
542 }
543 aMI.Clear();
3510db62 544 aBox.SetGap(aBox.GetGap() + aTolAdd);
4e57c75e 545 ++aNbF;
546 }//if (aTS==TopAbs_FACE) {
547 }//for (j=0; j<myNbSourceShapes; ++j) {
548 //
98b37659 549 // For the check mode we need to compute the bounding box for solid.
550 // Otherwise, it will be computed on the building stage
551 Standard_Boolean bCheckMode = (myArguments.Extent() == 1);
552 if (bCheckMode)
553 {
554 // 2.4 Solids
555 for (j=0; j<myNbSourceShapes; ++j) {
556 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
557 //
558 aTS=aSI.ShapeType();
559 if (aTS!=TopAbs_SOLID) {
362dec17 560 continue;
ceaa5e27 561 }
98b37659 562 Bnd_Box& aBox=aSI.ChangeBox();
563 BuildBndBoxSolid(j, aBox);
ceaa5e27 564 //
98b37659 565 //
566 // update sub-shapes by BRep comprising ones
567 aMI.Clear();
1155d05a 568 TColStd_ListOfInteger& aLI1=aSI.ChangeSubShapes();
98b37659 569 //
570 aIt1.Initialize(aLI1);
571 for (; aIt1.More(); aIt1.Next()) {
572 n1=aIt1.Value();
573 BOPDS_ShapeInfo& aSI1=ChangeShapeInfo(n1);
574 if (aSI1.ShapeType()!=TopAbs_SHELL) {
362dec17 575 continue;
576 }
577 //
1155d05a 578 const TColStd_ListOfInteger& aLI2=aSI1.SubShapes();
98b37659 579 aIt2.Initialize(aLI2);
580 for (; aIt2.More(); aIt2.Next()) {
581 n2=aIt2.Value();
582 BOPDS_ShapeInfo& aSI2=ChangeShapeInfo(n2);
583 if (aSI2.ShapeType()!=TopAbs_FACE) {
584 continue;
585 }
586 //
587 aMI.Add(n2);
588 //
1155d05a 589 const TColStd_ListOfInteger& aLI3=aSI2.SubShapes();
98b37659 590 aIt3.Initialize(aLI3);
591 for (; aIt3.More(); aIt3.Next()) {
592 n3=aIt3.Value();
593 aMI.Add(n3);
594 }
362dec17 595 }
ceaa5e27 596 }
98b37659 597 //
598 aLI1.Clear();
599 aItMI.Initialize(aMI);
600 for (; aItMI.More(); aItMI.Next()) {
601 n1=aItMI.Value();
602 aLI1.Append(n1);
603 }
604 aMI.Clear();
605 }//for (j=0; j<myNbSourceShapes; ++j) {
606 }
30ecd5f8 607 //
4e57c75e 608 aMI.Clear();
3510db62 609 //-----------------------------------------------------
610 //
b7cd7c2b 611 // Prepare Vertex-Edge connection map
612 for (nE = 0; nE < myNbSourceShapes; ++nE)
613 {
614 BOPDS_ShapeInfo& aSI = ChangeShapeInfo(nE);
615 if (aSI.ShapeType() != TopAbs_EDGE)
3510db62 616 continue;
b7cd7c2b 617
1155d05a 618 const TColStd_ListOfInteger& aLV = aSI.SubShapes();
3510db62 619 aIt1.Initialize(aLV);
b7cd7c2b 620 for (; aIt1.More(); aIt1.Next())
621 {
622 nV = aIt1.Value();
1155d05a 623 TColStd_ListOfInteger* pLE = myMapVE.ChangeSeek(nV);
b7cd7c2b 624 if (!pLE) {
1155d05a 625 pLE = myMapVE.Bound(nV, TColStd_ListOfInteger(myAllocator));
b7cd7c2b 626 pLE->Append(nE);
3510db62 627 }
b7cd7c2b 628 else
629 {
630 // provide uniqueness of the edges in the list
631 for (aIt2.Initialize(*pLE); aIt2.More(); aIt2.Next())
632 {
633 if (aIt2.Value() == nE)
634 break;
635 }
636 if (!aIt2.More())
637 pLE->Append(nE);
3510db62 638 }
639 }
3510db62 640 }
4e57c75e 641 //-----------------------------------------------------scope_1 t
4e57c75e 642 // 3 myPaveBlocksPool
4e57c75e 643 // 4. myFaceInfoPool
402bfe81 644 myPaveBlocksPool.SetIncrement(aNbE);
4e57c75e 645 myFaceInfoPool.SetIncrement(aNbF);
4e57c75e 646}
647//=======================================================================
648//function : InitShape
649//purpose :
650//=======================================================================
362dec17 651void BOPDS_DS::InitShape
652 (const Standard_Integer aI,
24542bc0 653 const TopoDS_Shape& aS)
4e57c75e 654{
655 Standard_Integer aIx;
656 TopoDS_Iterator aIt;
1155d05a 657 TColStd_ListIteratorOfListOfInteger aIt1;
4e57c75e 658 //
659 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(aI);
660 aSI.SetShapeType(aS.ShapeType());
1155d05a 661 TColStd_ListOfInteger& aLI=aSI.ChangeSubShapes();
4e57c75e 662 //
1155d05a 663 TColStd_MapOfInteger aM;
4e57c75e 664 //
665 aIt1.Initialize(aLI);
666 for (; aIt1.More(); aIt1.Next()) {
667 aM.Add(aIt1.Value());
668 }
669 //
670 aIt.Initialize(aS);
671 for (; aIt.More(); aIt.Next()) {
672 const TopoDS_Shape& aSx=aIt.Value();
24542bc0 673 const Standard_Integer* pIx = myMapShapeIndex.Seek(aSx);
674 aIx = (pIx ? *pIx : Append(aSx));
4e57c75e 675 //
24542bc0 676 InitShape(aIx, aSx);
4e57c75e 677 //
678 if (aM.Add(aIx)) {
679 aLI.Append(aIx);
680 }
681 }
682}
683
4e57c75e 684//=======================================================================
685//function : HasInterfShapeSubShapes
686//purpose :
687//=======================================================================
ceaa5e27 688Standard_Boolean BOPDS_DS::HasInterfShapeSubShapes
689 (const Standard_Integer theI1,
690 const Standard_Integer theI2,
691 const Standard_Boolean theFlag)const
4e57c75e 692{
693 Standard_Boolean bRet;
694 Standard_Integer n2;
1155d05a 695 TColStd_ListIteratorOfListOfInteger aIt;
4e57c75e 696 bRet = Standard_False;
697 //
698 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI2);
1155d05a 699 const TColStd_ListOfInteger& aLI=aSI.SubShapes();
4e57c75e 700 aIt.Initialize(aLI);
701 for (; aIt.More(); aIt.Next()) {
702 n2=aIt.Value();
703 bRet=HasInterf(theI1, n2);
ceaa5e27 704 if (theFlag) {
705 if(bRet) {
b1d15f53 706 break;
ceaa5e27 707 }
708 }
709 else {
710 if(!bRet) {
b1d15f53 711 break;
ceaa5e27 712 }
4e57c75e 713 }
714 }
715 return bRet;
716}
4e57c75e 717//=======================================================================
718//function : HasInterfSubShapes
719//purpose :
720//=======================================================================
362dec17 721Standard_Boolean BOPDS_DS::HasInterfSubShapes
722 (const Standard_Integer theI1,
723 const Standard_Integer theI2)const
4e57c75e 724{
725 Standard_Boolean bRet;
726 Standard_Integer n1;
1155d05a 727 TColStd_ListIteratorOfListOfInteger aIt;
4e57c75e 728 bRet = Standard_False;
729 //
730 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI1);
1155d05a 731 const TColStd_ListOfInteger& aLI=aSI.SubShapes();
4e57c75e 732 aIt.Initialize(aLI);
733 for (; aIt.More(); aIt.Next()) {
734 n1=aIt.Value();
735 bRet=HasInterfShapeSubShapes(n1, theI2);
736 if(bRet) {
737 break;
738 }
739 }
740 return bRet;
741}
742//
743// PaveBlocks
744//=======================================================================
745//function : PaveBlocksPool
746//purpose :
747//=======================================================================
72e88cf7 748const BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::PaveBlocksPool()const
4e57c75e 749{
750 return myPaveBlocksPool;
751}
752//=======================================================================
753//function : ChangePaveBlocksPool
754//purpose :
755//=======================================================================
72e88cf7 756BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::ChangePaveBlocksPool()
4e57c75e 757{
758 return myPaveBlocksPool;
759}
760//=======================================================================
761//function : HasPaveBlocks
762//purpose :
763//=======================================================================
72e88cf7 764Standard_Boolean BOPDS_DS::HasPaveBlocks(const Standard_Integer theI)const
4e57c75e 765{
766 return ShapeInfo(theI).HasReference();
767}
768//=======================================================================
769//function : PaveBlocks
770//purpose :
771//=======================================================================
362dec17 772const BOPDS_ListOfPaveBlock& BOPDS_DS::PaveBlocks
773 (const Standard_Integer theI)const
4e57c75e 774{
775 static BOPDS_ListOfPaveBlock sLPB;
776 Standard_Integer aRef;
777 //
778 if (HasPaveBlocks(theI)) {
779 aRef=ShapeInfo(theI).Reference();
780 const BOPDS_ListOfPaveBlock& aLPB=myPaveBlocksPool(aRef);
781 return aLPB;
782 }
783 return sLPB;
784}
3510db62 785
4e57c75e 786//=======================================================================
787//function : ChangePaveBlocks
788//purpose :
789//=======================================================================
362dec17 790BOPDS_ListOfPaveBlock& BOPDS_DS::ChangePaveBlocks
791 (const Standard_Integer theI)
4e57c75e 792{
793 Standard_Boolean bHasReference;
794 Standard_Integer aRef;
4e57c75e 795 //
796 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
797 bHasReference=aSI.HasReference();
798 if (!bHasReference) {
799 InitPaveBlocks(theI);
800 }
801 //
802 aRef=aSI.Reference();
323c04de 803 return myPaveBlocksPool(aRef);
4e57c75e 804}
805//=======================================================================
806//function : InitPaveBlocks
807//purpose :
808//=======================================================================
72e88cf7 809void BOPDS_DS::InitPaveBlocks(const Standard_Integer theI)
4e57c75e 810{
59427cbc 811 Standard_Integer nV=0, iRef, aNbV, nVSD;
4e57c75e 812 Standard_Real aT;
59427cbc 813 TopAbs_Orientation aOrE;
4e57c75e 814 TopoDS_Vertex aV;
1155d05a 815 TColStd_ListIteratorOfListOfInteger aIt;
4e57c75e 816 BOPDS_Pave aPave;
817 Handle(BOPDS_PaveBlock) aPB;
818 //
819 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
820 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aSI.Shape());
59427cbc 821 aOrE=aE.Orientation();
4e57c75e 822 //
1155d05a 823 const TColStd_ListOfInteger& aLV=aSI.SubShapes();
4e57c75e 824 aNbV=aLV.Extent();
825 if (!aNbV) {
826 return;
827 }
828 //
829 aPB=new BOPDS_PaveBlock;
830 aPB->SetOriginalEdge(theI);
831 //
59427cbc 832 if (aOrE!=TopAbs_INTERNAL) {
833 aIt.Initialize(aLV);
834 for (; aIt.More(); aIt.Next()) {
835 nV=aIt.Value();
836 //
837 const BOPDS_ShapeInfo& aSIV=ShapeInfo(nV);
838 aV=*(TopoDS_Vertex*)(&aSIV.Shape());
839 if (aSIV.HasFlag()) {
840 aT=ComputeParameter(aV, aE);
841 }
842 else {
843 aT=BRep_Tool::Parameter(aV, aE);
844 }
845 //
846 if (HasShapeSD(nV, nVSD)) {
847 nV=nVSD;
848 }
849 aPave.SetIndex(nV);
850 aPave.SetParameter(aT);
0d0481c7 851 if (aSI.HasFlag())
852 // for a degenerated edge append pave unconditionally
853 aPB->AppendExtPave1(aPave);
854 else
855 aPB->AppendExtPave(aPave);
4e57c75e 856 }
4e57c75e 857 //
59427cbc 858 if (aNbV==1) {
859 aV.Reverse();
860 aT=BRep_Tool::Parameter(aV, aE);
861 aPave.SetIndex(nV);
862 aPave.SetParameter(aT);
863 aPB->AppendExtPave1(aPave);
4e57c75e 864 }
4e57c75e 865 }
866 //
59427cbc 867 else {
868 TopoDS_Iterator aItE;
869 //
870 aItE.Initialize(aE, Standard_False, Standard_True);
871 for (; aItE.More(); aItE.Next()) {
872 aV=*((TopoDS_Vertex*)&aItE.Value());
873 nV=Index(aV);
2a2e3ecd 874 //
875 const BOPDS_ShapeInfo& aSIV=ShapeInfo(nV);
876 if (aSIV.HasFlag()) {
877 aT=ComputeParameter(aV, aE);
878 }
879 else {
880 aT=BRep_Tool::Parameter(aV, aE);
881 }
882 //
883 if (HasShapeSD(nV, nVSD)) {
884 nV=nVSD;
885 }
59427cbc 886 aPave.SetIndex(nV);
887 aPave.SetParameter(aT);
888 aPB->AppendExtPave1(aPave);
889 }
4e57c75e 890 }
891 //
1155d05a 892 BOPDS_ListOfPaveBlock &aLPB=myPaveBlocksPool.Appended();
893 iRef=myPaveBlocksPool.Length()-1;
4e57c75e 894 //
895 aPB->Update(aLPB, Standard_False);
4e57c75e 896 aSI.SetReference(iRef);
897}
898//=======================================================================
899//function : UpdatePaveBlocks
900//purpose :
901//=======================================================================
72e88cf7 902void BOPDS_DS::UpdatePaveBlocks()
4e57c75e 903{
4e57c75e 904 Standard_Integer i, aNbPBP;
905 BOPDS_ListOfPaveBlock aLPBN(myAllocator);
8ae442a8 906 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
4e57c75e 907 //
908 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
909 //
910 aNbPBP=aPBP.Size();
911 for (i=0; i<aNbPBP; ++i) {
912 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
913 //
914 aItPB.Initialize(aLPB);
8ae442a8 915 for (; aItPB.More();) {
4e57c75e 916 Handle(BOPDS_PaveBlock)& aPB=aItPB.ChangeValue();
917 //
8ae442a8 918 if (!aPB->IsToUpdate()) {
919 aItPB.Next();
920 continue;
4e57c75e 921 }
8ae442a8 922 //
923 aLPBN.Clear();
924 aPB->Update(aLPBN);
925 //
926 aLPB.Remove(aItPB);
927 //
928 aLPB.Append(aLPBN);
4e57c75e 929 }// for (; aItPB.More(); aItPB.Next()) {
930 }// for (i=0; i<aNbPBP; ++i) {
931}
932//=======================================================================
933//function : UpdatePaveBlock
934//purpose :
935//=======================================================================
72e88cf7 936void BOPDS_DS::UpdatePaveBlock(const Handle(BOPDS_PaveBlock)& thePB)
4e57c75e 937{
938 if (!thePB->IsToUpdate()){
939 return;
940 }
941 //
942 Standard_Integer nE, iRef;
943 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBN;
944 BOPDS_ListOfPaveBlock aLPBN(myAllocator);
945 Handle(BOPDS_PaveBlock) aPB;
946 //
947 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
948 //
949 nE=thePB->OriginalEdge();
950 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(nE);
951 iRef=aSI.Reference();
952 BOPDS_ListOfPaveBlock& aLPB=aPBP(iRef);
953 //
954 aItPB.Initialize(aLPB);
955 for (; aItPB.More(); aItPB.Next()) {
956 aPB=aItPB.ChangeValue();
957 if (aPB==thePB) {
958 aPB->Update(aLPBN);
3510db62 959 aLPB.Append(aLPBN);
4e57c75e 960 aLPB.Remove(aItPB);
961 break;
962 }
963 }
964}
965//=======================================================================
966//function : UpdateCommonBlock
967//purpose :
968//=======================================================================
0d0481c7 969void BOPDS_DS::UpdateCommonBlock(const Handle(BOPDS_CommonBlock)& theCB,
970 const Standard_Real theFuzz)
4e57c75e 971{
972 Standard_Integer nE, iRef, n1, n2;
973 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBCB, aItPBN;
4e57c75e 974 BOPDS_ListOfPaveBlock aLPBN;
25dfc507 975 NCollection_DataMap<BOPDS_Pair, BOPDS_ListOfPaveBlock, BOPDS_PairMapHasher> aMPKLPB;
976 NCollection_DataMap<BOPDS_Pair, BOPDS_ListOfPaveBlock, BOPDS_PairMapHasher>::Iterator aItMPKLPB;
4e57c75e 977 Handle(BOPDS_PaveBlock) aPB;
978 Handle(BOPDS_CommonBlock) aCBx;
25dfc507 979 BOPDS_Pair aPK;
4e57c75e 980 //
981 const BOPDS_ListOfPaveBlock& aLPBCB=theCB->PaveBlocks();
982 if (!aLPBCB.First()->IsToUpdate()){
983 return;
984 }
985 //
1155d05a 986 const TColStd_ListOfInteger& aLF=theCB->Faces();
4e57c75e 987 //
988 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
989 //
990 aItPBCB.Initialize(aLPBCB);
991 for (; aItPBCB.More(); aItPBCB.Next()) {
992 const Handle(BOPDS_PaveBlock)& aPBCB=aItPBCB.ChangeValue();
993 //
994 nE=aPBCB->OriginalEdge();
995 iRef=ChangeShapeInfo(nE).Reference();
996 BOPDS_ListOfPaveBlock& aLPB=aPBP(iRef);
997 //
998 aItPB.Initialize(aLPB);
999 for (; aItPB.More(); aItPB.Next()) {
1000 aPB=aItPB.ChangeValue();
1001 if (aPB==aPBCB) {
1002 //
1003 aLPBN.Clear();
1004 aPB->Update(aLPBN);
1005 //
1006 aItPBN.Initialize(aLPBN);
1007 for (; aItPBN.More(); aItPBN.Next()) {
1008 Handle(BOPDS_PaveBlock)& aPBN=aItPBN.ChangeValue();
1009 aLPB.Append(aPBN);
1010 //
1011 aPBN->Indices(n1, n2);
25dfc507 1012 aPK.SetIndices(n1, n2);
4e57c75e 1013 if (aMPKLPB.IsBound(aPK)) {
1014 BOPDS_ListOfPaveBlock& aLPBx=aMPKLPB.ChangeFind(aPK);
1015 aLPBx.Append(aPBN);
1016 }
1017 else {
1018 BOPDS_ListOfPaveBlock aLPBx;
1019 aLPBx.Append(aPBN);
1020 aMPKLPB.Bind(aPK, aLPBx);
1021 }
1022 }
25dfc507 1023 aLPB.Remove(aItPB);
4e57c75e 1024 break;
1025 }
1026 }
1027 }
1028 //
1029 aItMPKLPB.Initialize(aMPKLPB);
1030 for (; aItMPKLPB.More(); aItMPKLPB.Next()) {
1031 BOPDS_ListOfPaveBlock& aLPBx=aItMPKLPB.ChangeValue();
1032 //
1033 while (aLPBx.Extent()) {
1034 Standard_Boolean bCoinside;
4e57c75e 1035 BOPDS_ListOfPaveBlock aLPBxN;
1036 //
1037 aItPB.Initialize(aLPBx);
1038 for(; aItPB.More(); ) {
1039 const Handle(BOPDS_PaveBlock)& aPBx=aItPB.Value();
1040 if (aLPBxN.Extent()) {
1041 const Handle(BOPDS_PaveBlock)& aPBCx = aLPBxN.First();
0d0481c7 1042 bCoinside = CheckCoincidence(aPBx, aPBCx, theFuzz);
4e57c75e 1043 if (bCoinside) {
edfa30de 1044 aLPBxN.Append(aPBx);
4e57c75e 1045 aLPBx.Remove(aItPB);
1046 continue;
1047 }//if (bCoinside) {
1048 }//if (aLPBxN.Extent()) {
1049 else {
4e57c75e 1050 aLPBxN.Append(aPBx);
1051 aLPBx.Remove(aItPB);
1052 continue;
1053 }
1054 aItPB.Next();
1055 }//for(; aItPB.More(); ) {
1056 //
1057 aCBx=new BOPDS_CommonBlock;
edfa30de 1058 aCBx->SetPaveBlocks(aLPBxN);
3510db62 1059 aCBx->SetFaces(aLF);
4e57c75e 1060 //
1061 aItPB.Initialize(aLPBxN);
1062 for (; aItPB.More(); aItPB.Next()) {
1063 aPB=aItPB.ChangeValue();
5a77460e 1064 SetCommonBlock(aPB, aCBx);
4e57c75e 1065 }
1066 }
1067 }
1068}
5a77460e 1069
1070//=======================================================================
1071// function: RealPaveBlock
1072// purpose:
1073//=======================================================================
72e88cf7 1074Handle(BOPDS_PaveBlock) BOPDS_DS::RealPaveBlock
5a77460e 1075 (const Handle(BOPDS_PaveBlock)& thePB) const
1076{
1077 if (IsCommonBlock(thePB)) {
1078 const Handle(BOPDS_CommonBlock)& aCB = CommonBlock(thePB);
1079 const Handle(BOPDS_PaveBlock)& aPB = aCB->PaveBlock1();
1080 return aPB;
1081 }
1082 return thePB;
1083}
1084
1085//=======================================================================
1086// function: IsCommonBlockOnEdge
1087// purpose:
1088//=======================================================================
72e88cf7 1089Standard_Boolean BOPDS_DS::IsCommonBlockOnEdge
5a77460e 1090 (const Handle(BOPDS_PaveBlock)& thePB) const
1091{
1092 if (IsCommonBlock(thePB)) {
1093 const Handle(BOPDS_CommonBlock)& aCB = CommonBlock(thePB);
1094 return aCB->PaveBlocks().Extent()>1;
1095 }
1096 return Standard_False;
1097}
1098
1099//=======================================================================
1100//function : IsCommonBlock
1101//purpose :
1102//=======================================================================
72e88cf7 1103Standard_Boolean BOPDS_DS::IsCommonBlock
5a77460e 1104 (const Handle(BOPDS_PaveBlock)& thePB) const
1105{
1106 return myMapPBCB.IsBound(thePB);
1107}
1108
1109//=======================================================================
1110//function : CommonBlock
1111//purpose :
1112//=======================================================================
819f58c7 1113Handle(BOPDS_CommonBlock) BOPDS_DS::CommonBlock
5a77460e 1114 (const Handle(BOPDS_PaveBlock)& thePB) const
1115{
819f58c7 1116 return (IsCommonBlock(thePB) ? myMapPBCB.Find(thePB) : NULL);
5a77460e 1117}
1118
1119//=======================================================================
1120//function : SetCommonBlock
1121//purpose :
1122//=======================================================================
72e88cf7 1123void BOPDS_DS::SetCommonBlock(const Handle(BOPDS_PaveBlock)& thePB,
362dec17 1124 const Handle(BOPDS_CommonBlock)& theCB)
5a77460e 1125{
1126 if (IsCommonBlock(thePB)) {
1127 Handle(BOPDS_CommonBlock)& aCB = myMapPBCB.ChangeFind(thePB);
1128 aCB=theCB;
1129 }
1130 else {
1131 myMapPBCB.Bind(thePB, theCB);
1132 }
1133}
1134
4e57c75e 1135//
1136// FaceInfo
1137//
1138
1139//=======================================================================
1140//function : FaceInfoPool
1141//purpose :
1142//=======================================================================
72e88cf7 1143const BOPDS_VectorOfFaceInfo& BOPDS_DS::FaceInfoPool()const
4e57c75e 1144{
1145 return myFaceInfoPool;
1146}
1147//=======================================================================
1148//function : HasFaceInfo
1149//purpose :
1150//=======================================================================
72e88cf7 1151Standard_Boolean BOPDS_DS::HasFaceInfo(const Standard_Integer theI)const
4e57c75e 1152{
1153 return ShapeInfo(theI).HasReference();
1154}
1155//=======================================================================
1156//function : FaceInfo
1157//purpose :
1158//=======================================================================
72e88cf7 1159const BOPDS_FaceInfo& BOPDS_DS::FaceInfo(const Standard_Integer theI)const
4e57c75e 1160{
1161 static BOPDS_FaceInfo sFI;
1162 Standard_Integer aRef;
1163 //
1164 if (HasFaceInfo(theI)) {
1165 aRef=ShapeInfo(theI).Reference();
1166 const BOPDS_FaceInfo& aFI=myFaceInfoPool(aRef);
1167 return aFI;
1168 }
1169 return sFI;
1170}
1171//=======================================================================
1172//function : ChangeFaceInfo
1173//purpose :
1174//=======================================================================
72e88cf7 1175BOPDS_FaceInfo& BOPDS_DS::ChangeFaceInfo(const Standard_Integer theI)
4e57c75e 1176{
1177 Standard_Boolean bHasReference;
1178 Standard_Integer aRef;
1179 BOPDS_FaceInfo* pFI;
1180 //
1181 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1182 bHasReference=aSI.HasReference();
1183 if (!bHasReference) {
1184 InitFaceInfo(theI);
1185 }
1186 //
1187 aRef=aSI.Reference();
1188 const BOPDS_FaceInfo& aFI=myFaceInfoPool(aRef);
1189 pFI=(BOPDS_FaceInfo*)&aFI;
1190 return *pFI;
1191}
1192//=======================================================================
1193//function : InitFaceInfo
1194//purpose :
1195//=======================================================================
72e88cf7 1196void BOPDS_DS::InitFaceInfo(const Standard_Integer theI)
4e57c75e 1197{
1198 Standard_Integer iRef;
1199 //
1200 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1155d05a 1201 BOPDS_FaceInfo &aFI=myFaceInfoPool.Appended();
1202 iRef=myFaceInfoPool.Length()-1;
4e57c75e 1203 aSI.SetReference(iRef);
1204 //
1205 aFI.SetIndex(theI);
1206 UpdateFaceInfoIn(theI);
1207 UpdateFaceInfoOn(theI);
1208}
1209//=======================================================================
1210//function : UpdateFaceInfoIn
1211//purpose :
1212//=======================================================================
72e88cf7 1213void BOPDS_DS::UpdateFaceInfoIn(const Standard_Integer theI)
4e57c75e 1214{
1215 Standard_Integer iRef;
1216 //
1217 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1218 if (aSI.HasReference()) {
1219 iRef=aSI.Reference();
1220 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1221 //
1222 BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.ChangePaveBlocksIn();
1155d05a 1223 TColStd_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
4e57c75e 1224 aMPBIn.Clear();
1225 aMVIn.Clear();
1226 FaceInfoIn(theI, aMPBIn, aMVIn);
1227 }
1228}
1229//=======================================================================
1230//function : UpdateFaceInfoOn
1231//purpose :
1232//=======================================================================
72e88cf7 1233void BOPDS_DS::UpdateFaceInfoOn(const Standard_Integer theI)
4e57c75e 1234{
1235 Standard_Integer iRef;
1236 //
1237 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1238 if (aSI.HasReference()) {
1239 iRef=aSI.Reference();
1240 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1241 //
1242 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1155d05a 1243 TColStd_MapOfInteger& aMVOn=aFI.ChangeVerticesOn();
4e57c75e 1244 aMPBOn.Clear();
1245 aMVOn.Clear();
1246 FaceInfoOn(theI, aMPBOn, aMVOn);
1247 }
1248}
1249//=======================================================================
1250//function : FaceInfoOn
1251//purpose :
1252//=======================================================================
72e88cf7 1253void BOPDS_DS::FaceInfoOn(const Standard_Integer theF,
362dec17 1254 BOPDS_IndexedMapOfPaveBlock& theMPB,
1155d05a 1255 TColStd_MapOfInteger& theMI)
4e57c75e 1256{
1257 Standard_Integer nS, nSD, nV1, nV2;
1155d05a 1258 TColStd_ListIteratorOfListOfInteger aIt;
4e57c75e 1259 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1260 //
1261 const BOPDS_ShapeInfo& aSI=ShapeInfo(theF);
1155d05a 1262 const TColStd_ListOfInteger& aLI=aSI.SubShapes();
4e57c75e 1263 aIt.Initialize(aLI);
1264 for (; aIt.More(); aIt.Next()) {
1265 nS=aIt.Value();
1266 const BOPDS_ShapeInfo& aSIE=ShapeInfo(nS);
1267 if (aSIE.ShapeType()==TopAbs_EDGE) {
1268 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nS);
1269 aItPB.Initialize(aLPB);
1270 for (; aItPB.More(); aItPB.Next()) {
1271 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
1272 aPB->Indices(nV1, nV2);
1273 theMI.Add(nV1);
1274 theMI.Add(nV2);
5a77460e 1275 Handle(BOPDS_PaveBlock) aPBR=RealPaveBlock(aPB);
1276 theMPB.Add(aPBR);
4e57c75e 1277 }
1278 }//if (aSIE.ShapeType()==TopAbs_EDGE)
1279 else {
1280 // nE is TopAbs_VERTEX
1281 if (HasShapeSD(nS, nSD)) {
1282 nS=nSD;
1283 }
1284 theMI.Add(nS);
1285 }
1286 }
1287}
1288//=======================================================================
1289//function : FaceInfoIn
1290//purpose :
1291//=======================================================================
72e88cf7 1292void BOPDS_DS::FaceInfoIn(const Standard_Integer theF,
362dec17 1293 BOPDS_IndexedMapOfPaveBlock& theMPB,
1155d05a 1294 TColStd_MapOfInteger& theMI)
4e57c75e 1295{
50ba108c 1296 Standard_Integer i, aNbVF, aNbEF, nV, nE, nVSD;
1297 TopoDS_Iterator aItS;
4e57c75e 1298 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1299 //
50ba108c 1300 // 1. Pure internal vertices on the face
1301 const TopoDS_Shape& aF=Shape(theF);
1302 aItS.Initialize(aF);
1303 for (; aItS.More(); aItS.Next()) {
1304 const TopoDS_Shape& aSx=aItS.Value();
1305 if (aSx.ShapeType()==TopAbs_VERTEX){
1306 nV=Index(aSx);
1307 if (HasShapeSD(nV, nVSD)) {
319da2e4 1308 nV=nVSD;
50ba108c 1309 }
1310 theMI.Add(nV);
1311 }
1312 }
1313 //
1314 // 2. aVFs
4e57c75e 1315 BOPDS_VectorOfInterfVF& aVFs=InterfVF();
1155d05a 1316 aNbVF=aVFs.Length();
4e57c75e 1317 for (i=0; i<aNbVF; ++i) {
1318 BOPDS_InterfVF& aVF=aVFs(i);
1319 if(aVF.Contains(theF)) {
1320 nV=aVF.OppositeIndex(theF);
3510db62 1321 if (HasShapeSD(nV, nVSD)) {
1322 nV=nVSD;
1323 }
4e57c75e 1324 theMI.Add(nV);
1325 }
1326 }
1327 //
50ba108c 1328 // 3. aEFs
4e57c75e 1329 BOPDS_VectorOfInterfEF& aEFs=InterfEF();
1155d05a 1330 aNbEF=aEFs.Length();
4e57c75e 1331 for (i=0; i<aNbEF; ++i) {
1332 BOPDS_InterfEF& aEF=aEFs(i);
1333 if(aEF.Contains(theF)) {
1334 if(aEF.HasIndexNew(nV)) {
8ae442a8 1335 if (HasShapeSD(nV, nVSD)) {
1336 nV=nVSD;
1337 }
4e57c75e 1338 theMI.Add(nV);
1339 }
1340 else {
1341 nE=aEF.OppositeIndex(theF);
1342 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1343 aItPB.Initialize(aLPB);
1344 for (; aItPB.More(); aItPB.Next()) {
1345 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
5a77460e 1346 if (IsCommonBlock(aPB)) {
1347 const Handle(BOPDS_CommonBlock)& aCB=CommonBlock(aPB);
4e57c75e 1348 if (aCB->Contains(theF)) {
1349 const Handle(BOPDS_PaveBlock)& aPB1=aCB->PaveBlock1();
1350 theMPB.Add(aPB1);
1351 }
1352 }
1353 }// for (; aItPB.More(); aItPB.Next()) {
1354 }// else {
1355 }// if(aEF.Contains(theF)) {
1356 }// for (i=0; i<aNbEF; ++i) {
1357}
1358
1359//=======================================================================
1360//function : RefineFaceInfoOn
1361//purpose :
1362//=======================================================================
72e88cf7 1363void BOPDS_DS::RefineFaceInfoOn()
4e57c75e 1364{
1365 Standard_Integer i, aNb, nF, aNbPB, j;
1366 BOPDS_IndexedMapOfPaveBlock aMPB;
1367 //
1155d05a 1368 aNb=myFaceInfoPool.Length();
4e57c75e 1369 for (i=0; i<aNb; ++i) {
1370 BOPDS_FaceInfo &aFI=myFaceInfoPool(i);
1371 nF=aFI.Index();
1372 UpdateFaceInfoOn(nF);
1373 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1374 //
1375 aMPB.Clear();
1376 aMPB.Assign(aMPBOn);
1377 aMPBOn.Clear();
1378 //
1379 aNbPB=aMPB.Extent();
1380 for (j=1; j<=aNbPB; ++j) {
1381 const Handle(BOPDS_PaveBlock)& aPB=aMPB(j);
1382 if (aPB->HasEdge()) {
1383 aMPBOn.Add(aPB);
1384 }
1385 }
1386 }
1387}
1388//=======================================================================
1389//function : AloneVertices
1390//purpose :
1391//=======================================================================
72e88cf7 1392void BOPDS_DS::AloneVertices(const Standard_Integer theI,
1155d05a 1393 TColStd_ListOfInteger& theLI)const
4e57c75e 1394{
1395 if (HasFaceInfo(theI)) {
1396 //
319da2e4 1397 Standard_Integer i, j, nV1, nV2, nV, aNbPB;
1155d05a 1398 TColStd_MapIteratorOfMapOfInteger aItMI;
4e57c75e 1399 //
1155d05a 1400 TColStd_MapOfInteger aMI(100, myAllocator);
4e57c75e 1401 //
1402 const BOPDS_FaceInfo& aFI=FaceInfo(theI);
1403 //
319da2e4 1404 for (i = 0; i < 2; ++i) {
362dec17 1405 const BOPDS_IndexedMapOfPaveBlock& aMPB=
1406 (!i) ? aFI.PaveBlocksIn() : aFI.PaveBlocksSc();
319da2e4 1407 aNbPB = aMPB.Extent();
1408 for (j = 1; j <= aNbPB; ++j) {
1409 const Handle(BOPDS_PaveBlock)& aPB = aMPB(j);
4e57c75e 1410 aPB->Indices(nV1, nV2);
1411 aMI.Add(nV1);
1412 aMI.Add(nV2);
1413 }
1414 }
1415 //
1416 for (i=0; i<2; ++i) {
1155d05a 1417 const TColStd_MapOfInteger& aMIV=
362dec17 1418 (!i) ? aFI.VerticesIn() : aFI.VerticesSc();
4e57c75e 1419 aItMI.Initialize(aMIV);
1420 for (; aItMI.More(); aItMI.Next()) {
1421 nV=aItMI.Value();
362dec17 1422 if (nV>=0) {
4e57c75e 1423 if (aMI.Add(nV)) {
1424 theLI.Append(nV);
1425 }
1426 }
1427 }
1428 }
1429 }
1430}
4e57c75e 1431//=======================================================================
1432//function : VerticesOnIn
1433//purpose :
1434//=======================================================================
6f1ea0f4 1435void BOPDS_DS::SubShapesOnIn(const Standard_Integer theNF1,
1436 const Standard_Integer theNF2,
1437 TColStd_MapOfInteger& theMVOnIn,
1438 TColStd_MapOfInteger& theMVCommon,
1439 BOPDS_IndexedMapOfPaveBlock& thePBOnIn,
1440 BOPDS_MapOfPaveBlock& theCommonPB)const
4e57c75e 1441{
decdfc94 1442 Standard_Integer i, j, nV, nV1, nV2, aNbPB;
1155d05a 1443 TColStd_MapIteratorOfMapOfInteger aIt;
decdfc94 1444 BOPDS_IndexedMapOfPaveBlock pMPB[4];
4e57c75e 1445 //
6f1ea0f4 1446 const BOPDS_FaceInfo& aFI1 = FaceInfo(theNF1);
1447 const BOPDS_FaceInfo& aFI2 = FaceInfo(theNF2);
4e57c75e 1448 //
6f1ea0f4 1449 pMPB[0] = aFI1.PaveBlocksOn();
1450 pMPB[1] = aFI1.PaveBlocksIn();
1451 pMPB[2] = aFI2.PaveBlocksOn();
1452 pMPB[3] = aFI2.PaveBlocksIn();
1da6ad32 1453 //
6f1ea0f4 1454 for (i = 0; i < 4; ++i)
1455 {
decdfc94 1456 aNbPB = pMPB[i].Extent();
6f1ea0f4 1457 for (j = 1; j <= aNbPB; ++j)
1458 {
decdfc94 1459 const Handle(BOPDS_PaveBlock)& aPB = pMPB[i](j);
0d0481c7 1460 thePBOnIn.Add(aPB);
1da6ad32 1461 aPB->Indices(nV1, nV2);
6f1ea0f4 1462
0d0481c7 1463 theMVOnIn.Add(nV1);
1464 theMVOnIn.Add(nV2);
6f1ea0f4 1465
1466 if (i < 2)
1467 {
0d0481c7 1468 if (pMPB[2].Contains(aPB) || pMPB[3].Contains(aPB))
6f1ea0f4 1469 {
0d0481c7 1470 theCommonPB.Add(aPB);
6f1ea0f4 1471 theMVCommon.Add(nV1);
1472 theMVCommon.Add(nV2);
1473 }
0d0481c7 1474 }
1da6ad32 1475 }
4e57c75e 1476 }
1477 //
6f1ea0f4 1478 const TColStd_MapOfInteger& aMVOn1 = aFI1.VerticesOn();
1479 const TColStd_MapOfInteger& aMVIn1 = aFI1.VerticesIn();
1480 const TColStd_MapOfInteger& aMVOn2 = aFI2.VerticesOn();
1481 const TColStd_MapOfInteger& aMVIn2 = aFI2.VerticesIn();
1da6ad32 1482 //
6f1ea0f4 1483 for (i = 0; i < 2; ++i)
1484 {
1485 const TColStd_MapOfInteger& aMV1 = (!i) ? aMVOn1 : aMVIn1;
1da6ad32 1486 aIt.Initialize(aMV1);
6f1ea0f4 1487 for (; aIt.More(); aIt.Next())
1488 {
1489 nV = aIt.Value();
1490 if (aMVOn2.Contains(nV) || aMVIn2.Contains(nV))
1491 {
0d0481c7 1492 theMVOnIn.Add(nV);
6f1ea0f4 1493
1494 // Vertex taken from the 1st face is in the 2nd one.
1495 theMVCommon.Add(nV);
1da6ad32 1496 }
1497 }
4e57c75e 1498 }
6f1ea0f4 1499}
4e57c75e 1500//=======================================================================
1501//function : SharedEdges
1502//purpose :
1503//=======================================================================
72e88cf7 1504void BOPDS_DS::SharedEdges(const Standard_Integer nF1,
362dec17 1505 const Standard_Integer nF2,
1155d05a 1506 TColStd_ListOfInteger& theLI,
362dec17 1507 const Handle(NCollection_BaseAllocator)& aAllocator)
4e57c75e 1508{
1509 Standard_Integer nE, nSp;
1155d05a 1510 TColStd_ListIteratorOfListOfInteger aItLI;
4e57c75e 1511 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
1155d05a 1512 TColStd_MapOfInteger aMI(100, aAllocator);
4e57c75e 1513 //
1514 const BOPDS_ShapeInfo& aSI1=ShapeInfo(nF1);
1155d05a 1515 const TColStd_ListOfInteger& aLI1=aSI1.SubShapes();
4e57c75e 1516 aItLI.Initialize(aLI1);
1517 for (; aItLI.More(); aItLI.Next()) {
1518 nE=aItLI.Value();
1519 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1520 if(aSIE.ShapeType()==TopAbs_EDGE) {
1521 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1522 if (aLPB.IsEmpty()) {
1523 aMI.Add(nE);
1524 }
1525 else {
1526 aItLPB.Initialize(aLPB);
1527 for (; aItLPB.More(); aItLPB.Next()) {
5a77460e 1528 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
4e57c75e 1529 nSp=aPB->Edge();
1530 aMI.Add(nSp);
1531 }
1532 }
1533 }
1534 }
1535 //
1536 const BOPDS_ShapeInfo& aSI2=ShapeInfo(nF2);
1155d05a 1537 const TColStd_ListOfInteger& aLI2=aSI2.SubShapes();
4e57c75e 1538 aItLI.Initialize(aLI2);
1539 for (; aItLI.More(); aItLI.Next()) {
1540 nE=aItLI.Value();
1541 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1542 if(aSIE.ShapeType()==TopAbs_EDGE) {
1543 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1544 if (aLPB.IsEmpty()) {
1545 if (aMI.Contains(nE)) {
1546 theLI.Append(nE);
1547 }
1548 }
1549 else {
1550 aItLPB.Initialize(aLPB);
1551 for (; aItLPB.More(); aItLPB.Next()) {
5a77460e 1552 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
4e57c75e 1553 nSp=aPB->Edge();
1554 if (aMI.Contains(nSp)) {
1555 theLI.Append(nSp);
1556 }
1557 }
1558 }
1559 }
1560 }
1561}
1562
1563//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1564//
1565// same domain shapes
1566//
1567//=======================================================================
1568//function : ShapesSD
1569//purpose :
1570//=======================================================================
1155d05a 1571TColStd_DataMapOfIntegerInteger& BOPDS_DS::ShapesSD()
4e57c75e 1572{
1573 return myShapesSD;
1574}
1575//=======================================================================
1576//function : AddShapeSD
1577//purpose :
1578//=======================================================================
72e88cf7 1579void BOPDS_DS::AddShapeSD(const Standard_Integer theIndex,
362dec17 1580 const Standard_Integer theIndexSD)
4e57c75e 1581{
8ae442a8 1582 if (theIndex != theIndexSD)
1583 myShapesSD.Bind(theIndex, theIndexSD);
4e57c75e 1584}
1585//=======================================================================
1586//function : HasShapeSD
1587//purpose :
1588//=======================================================================
362dec17 1589Standard_Boolean BOPDS_DS::HasShapeSD
1590 (const Standard_Integer theIndex,
1591 Standard_Integer& theIndexSD)const
4e57c75e 1592{
8ae442a8 1593 Standard_Boolean bHasSD = Standard_False;
1594 const Standard_Integer *pSD = myShapesSD.Seek(theIndex);
1595 while (pSD) {
1596 theIndexSD = *pSD;
1597 bHasSD = Standard_True;
1598 pSD = myShapesSD.Seek(theIndexSD);
4e57c75e 1599 }
8ae442a8 1600 return bHasSD;
4e57c75e 1601}
1602//=======================================================================
1603//function : Dump
1604//purpose :
1605//=======================================================================
72e88cf7 1606void BOPDS_DS::Dump()const
4e57c75e 1607{
1608 Standard_Integer i, aNb, aNbSS;
1609 //
1610 printf(" *** DS ***\n");
1611 aNb=NbRanges();
1612 printf(" Ranges:%d\n", aNb);
1613 for (i=0; i<aNb; ++i) {
1614 const BOPDS_IndexRange& aR=Range(i);
1615 aR.Dump();
1616 printf("\n");
1617 }
1618 //
1619 aNbSS=NbSourceShapes();
1620 printf(" Shapes:%d\n", aNbSS);
1621 aNb=NbShapes();
1622 for (i=0; i<aNb; ++i) {
1623 const BOPDS_ShapeInfo& aSI=ShapeInfo(i);
1624 printf(" %d :", i);
1625 aSI.Dump();
1626 printf("\n");
1627 if (i==aNbSS-1) {
1628 printf(" ****** adds\n");
1629 }
1630 }
1631 printf(" ******\n");
1632}
1633
1634//=======================================================================
1635// function: CheckCoincidence
1636// purpose:
1637//=======================================================================
362dec17 1638Standard_Boolean BOPDS_DS::CheckCoincidence
1639 (const Handle(BOPDS_PaveBlock)& aPB1,
0d0481c7 1640 const Handle(BOPDS_PaveBlock)& aPB2,
1641 const Standard_Real theFuzz)
4e57c75e 1642{
1643 Standard_Boolean bRet;
1644 Standard_Integer nE1, nE2, aNbPoints;
1645 Standard_Real aT11, aT12, aT21, aT22, aT1m, aD, aTol, aT2x;
1646 gp_Pnt aP1m;
1647 //
1648 bRet=Standard_False;
1649 //
1650 aPB1->Range(aT11, aT12);
1651 aT1m=IntTools_Tools::IntermediatePoint (aT11, aT12);
1652 nE1=aPB1->OriginalEdge();
1653 const TopoDS_Edge& aE1=(*(TopoDS_Edge*)(&Shape(nE1)));
1654 BOPTools_AlgoTools::PointOnEdge(aE1, aT1m, aP1m);
1655 //
1656 aPB2->Range(aT21, aT22);
1657 nE2=aPB2->OriginalEdge();
1658 const TopoDS_Edge& aE2=(*(TopoDS_Edge*)(&Shape(nE2)));
1659 //
1660 Standard_Real f, l;
1661 Handle(Geom_Curve)aC2 = BRep_Tool::Curve (aE2, f, l);
1662 GeomAPI_ProjectPointOnCurve aPPC;
1663 aPPC.Init(aC2, f, l);
1664 aPPC.Perform(aP1m);
1665 aNbPoints=aPPC.NbPoints();
1666 if (aNbPoints) {
1667 aD=aPPC.LowerDistance();
1668 //
edfa30de 1669 aTol = BRep_Tool::MaxTolerance(aE1, TopAbs_VERTEX);
1670 aTol = aTol + BRep_Tool::MaxTolerance(aE2, TopAbs_VERTEX) + Max(theFuzz, Precision::Confusion());
4e57c75e 1671 if (aD<aTol) {
1672 aT2x=aPPC.LowerDistanceParameter();
1673 if (aT2x>aT21 && aT2x<aT22) {
1674 return !bRet;
1675 }
1676 }
1677 }
1678 return bRet;
1679}
4e57c75e 1680//=======================================================================
4e57c75e 1681// function: IsSubShape
1682// purpose:
1683//=======================================================================
362dec17 1684Standard_Boolean BOPDS_DS::IsSubShape
1685 (const Standard_Integer theI1,
1686 const Standard_Integer theI2)
4e57c75e 1687{
1688 Standard_Boolean bRet;
1689 Standard_Integer nS;
1690 bRet = Standard_False;
1691 //
1155d05a 1692 TColStd_ListIteratorOfListOfInteger aItLI;
4e57c75e 1693 //
1694 const BOPDS_ShapeInfo& aSI = ShapeInfo(theI2);
1155d05a 1695 const TColStd_ListOfInteger& aLI = aSI.SubShapes();
4e57c75e 1696 aItLI.Initialize(aLI);
1697 for(;aItLI.More(); aItLI.Next()) {
1698 nS = aItLI.Value();
1699 if (nS == theI1) {
1700 bRet = Standard_True;
1701 break;
1702 }
1703 }
1704
1705 return bRet;
1706}
4e57c75e 1707//=======================================================================
1708// function: Paves
1709// purpose:
1710//=======================================================================
72e88cf7 1711void BOPDS_DS::Paves(const Standard_Integer theEdge,
362dec17 1712 BOPDS_ListOfPave& theLP)
4e57c75e 1713{
1714 Standard_Integer aNb, i;
4e57c75e 1715 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1716 BOPDS_MapOfPave aMP;
1717 //
1718 const BOPDS_ListOfPaveBlock& aLPB = PaveBlocks(theEdge);
7a76337e 1719 aNb = aLPB.Extent() + 1;
1720 if (aNb == 1) {
1721 return;
4e57c75e 1722 }
1723 //
7a76337e 1724 BOPDS_VectorOfPave pPaves(1, aNb);
1725 //
1726 i = 1;
1727 aIt.Initialize(aLPB);
1728 for (; aIt.More(); aIt.Next()) {
4e57c75e 1729 const Handle(BOPDS_PaveBlock)& aPB = aIt.Value();
7a76337e 1730 const BOPDS_Pave& aPave1 = aPB->Pave1();
1731 const BOPDS_Pave& aPave2 = aPB->Pave2();
1732 //
1733 if (aMP.Add(aPave1)){
1734 pPaves(i) = aPave1;
4e57c75e 1735 ++i;
1736 }
7a76337e 1737 //
1738 if (aMP.Add(aPave2)){
1739 pPaves(i) = aPave2;
4e57c75e 1740 ++i;
1741 }
1742 }
1743 //
7a76337e 1744 Standard_ASSERT_VOID(aNb == aMP.Extent(), "Abnormal number of paves");
1745 //
1746 std::sort(pPaves.begin(), pPaves.end());
4e57c75e 1747 //
7a76337e 1748 for (i = 1; i <= aNb; ++i) {
1749 theLP.Append(pPaves(i));
4e57c75e 1750 }
1751}
4e57c75e 1752//=======================================================================
4e57c75e 1753//function : TotalShapes
1754//purpose :
1755//=======================================================================
1756void TotalShapes(const TopoDS_Shape& aS,
3510db62 1757 Standard_Integer& aNbS,
1155d05a 1758 TopTools_MapOfShape& aMS)
4e57c75e 1759{
3510db62 1760 if (aMS.Add(aS)) {
4e57c75e 1761 TopoDS_Iterator aIt;
4e57c75e 1762 ++aNbS;
1763 aIt.Initialize(aS);
1764 for (; aIt.More(); aIt.Next()) {
1765 const TopoDS_Shape& aSx=aIt.Value();
3510db62 1766 TotalShapes(aSx, aNbS, aMS);
4e57c75e 1767 }
1768 }
1769}
3510db62 1770
4e57c75e 1771//=======================================================================
1772//function : ComputeParameter
1773//purpose :
1774//=======================================================================
1775Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
1776 const TopoDS_Edge& aE)
1777{
1778 Standard_Real aT1, aT2, aTRet, aTolE2, aD2;
1779 gp_Pnt aPC, aPV;
1780 Handle(Geom_Curve) aC3D;
1781 TopoDS_Edge aEE;
1782 //
1783 aEE=aE;
1784 aEE.Orientation(TopAbs_FORWARD);
1785 //
1786 aTRet=0.;
1787 //
1788 aTolE2=BRep_Tool::Tolerance(aE);
1789 aTolE2=aTolE2*aTolE2;
1790 //
1791 aPV=BRep_Tool::Pnt(aV);
1792 //
1793 aC3D=BRep_Tool::Curve (aEE, aT1, aT2);
1794 //
1795 aC3D->D0(aT1, aPC);
1796 aD2=aPC.SquareDistance(aPV);
1797 if (aD2<aTolE2) {
1798 aTRet=aT1;
1799 }
1800 //
1801 aC3D->D0(aT2, aPC);
1802 aD2=aPC.SquareDistance(aPV);
1803 if (aD2<aTolE2) {
1804 aTRet=aT2;
1805 }
1806 //
1807 return aTRet;
1808}
1809//=======================================================================
30ecd5f8 1810//function : BuildBndBoxSolid
1811//purpose :
1812//=======================================================================
1813void BOPDS_DS::BuildBndBoxSolid(const Standard_Integer theIndex,
98b37659 1814 Bnd_Box& aBoxS,
1815 const Standard_Boolean theCheckInverted)
30ecd5f8 1816{
1817 Standard_Boolean bIsOpenBox, bIsInverted;
1818 Standard_Integer nSh, nFc;
1819 Standard_Real aTolS, aTolFc;
1155d05a 1820 TColStd_ListIteratorOfListOfInteger aItLI, aItLI1;
30ecd5f8 1821 //
1822 const BOPDS_ShapeInfo& aSI=ShapeInfo(theIndex);
1823 const TopoDS_Shape& aS=aSI.Shape();
1824 const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS));
1825 //
1826 bIsOpenBox=Standard_False;
1827 //
1828 aTolS=0.;
1155d05a 1829 const TColStd_ListOfInteger& aLISh=aSI.SubShapes();
30ecd5f8 1830 aItLI.Initialize(aLISh);
1831 for (; aItLI.More(); aItLI.Next()) {
1832 nSh=aItLI.Value();
1833 const BOPDS_ShapeInfo& aSISh=ShapeInfo(nSh);
1834 if (aSISh.ShapeType()!=TopAbs_SHELL) {
1835 continue;
1836 }
1837 //
1155d05a 1838 const TColStd_ListOfInteger& aLIFc=aSISh.SubShapes();
30ecd5f8 1839 aItLI1.Initialize(aLIFc);
1840 for (; aItLI1.More(); aItLI1.Next()) {
1841 nFc=aItLI1.Value();
1842 const BOPDS_ShapeInfo& aSIFc=ShapeInfo(nFc);
1843 if (aSIFc.ShapeType()!=TopAbs_FACE) {
362dec17 1844 continue;
30ecd5f8 1845 }
1846 //
1847 const Bnd_Box& aBFc=aSIFc.Box();
1848 aBoxS.Add(aBFc);
1849 //
1850 if (!bIsOpenBox) {
362dec17 1851 bIsOpenBox=(aBFc.IsOpenXmin() || aBFc.IsOpenXmax() ||
1852 aBFc.IsOpenYmin() || aBFc.IsOpenYmax() ||
1853 aBFc.IsOpenZmin() || aBFc.IsOpenZmax());
1854 if (bIsOpenBox) {
1855 break;
1856 }
30ecd5f8 1857 }
1858 //
1859 const TopoDS_Face& aFc=*((TopoDS_Face*)&aSIFc.Shape());
1860 aTolFc=BRep_Tool::Tolerance(aFc);
1861 if (aTolFc>aTolS) {
362dec17 1862 aTolS=aTolFc;
30ecd5f8 1863 }
1864 }//for (; aItLI1.More(); aItLI1.Next()) {
1865 if (bIsOpenBox) {
1866 break;
1867 }
1868 //
1869 const TopoDS_Shell& aSh=*((TopoDS_Shell*)&aSISh.Shape());
1870 bIsOpenBox=BOPTools_AlgoTools::IsOpenShell(aSh);
1871 if (bIsOpenBox) {
1872 break;
1873 }
1874 }//for (; aItLI.More(); aItLI.Next()) {
1875 //
1876 if (bIsOpenBox) {
1877 aBoxS.SetWhole();
1878 }
98b37659 1879 else if (theCheckInverted) {
30ecd5f8 1880 bIsInverted=BOPTools_AlgoTools::IsInvertedSolid(aSolid);
1881 if (bIsInverted) {
1882 aBoxS.SetWhole();
1883 }
1884 }
1885}
b1d15f53 1886
3510db62 1887//=======================================================================
1888//function : UpdatePaveBlocksWithSDVertices
1889//purpose :
1890//=======================================================================
1891void BOPDS_DS::UpdatePaveBlocksWithSDVertices()
1892{
1893 Standard_Integer i, aNbPBP;
1894 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1895 //
1896 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
1897 //
1898 aNbPBP=aPBP.Size();
1899 for (i = 0; i < aNbPBP; ++i) {
1900 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
1901 //
1902 aItPB.Initialize(aLPB);
1903 for (; aItPB.More(); aItPB.Next()) {
1904 Handle(BOPDS_PaveBlock)& aPB = aItPB.ChangeValue();
1905 UpdatePaveBlockWithSDVertices(aPB);
1906 }// for (; aItPB.More(); aItPB.Next()) {
1907 }// for (i = 0; i < aNbPBP; ++i) {
1908}
1909//=======================================================================
1910//function : UpdatePaveBlockWithSDVertices
1911//purpose :
1912//=======================================================================
1913void BOPDS_DS::UpdatePaveBlockWithSDVertices
1914 (const Handle(BOPDS_PaveBlock)& thePB)
1915{
1916 Standard_Integer nV1, nV2;
1917 BOPDS_Pave aPave1, aPave2;
1918 //
1919 aPave1 = thePB->Pave1();
1920 aPave2 = thePB->Pave2();
1921 //
1922 nV1 = aPave1.Index();
1923 nV2 = aPave2.Index();
1924 //
1925 if (HasShapeSD(nV1, nV1)) {
1926 aPave1.SetIndex(nV1);
1927 thePB->SetPave1(aPave1);
1928 }
1929 //
1930 if (HasShapeSD(nV2, nV2)) {
1931 aPave2.SetIndex(nV2);
1932 thePB->SetPave2(aPave2);
1933 }
1934}
1935//=======================================================================
1936//function : UpdateCommonBlockWithSDVertices
1937//purpose :
1938//=======================================================================
1939void BOPDS_DS::UpdateCommonBlockWithSDVertices
1940 (const Handle(BOPDS_CommonBlock)& theCB)
1941{
1942 const BOPDS_ListOfPaveBlock& aLPB = theCB->PaveBlocks();
1943 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
1944 for (; aItPB.More(); aItPB.Next()) {
1945 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
1946 UpdatePaveBlockWithSDVertices(aPB);
1947 }
1948}
1949//=======================================================================
1950//function : InitPaveBlocksForVertex
1951//purpose :
1952//=======================================================================
1953void BOPDS_DS::InitPaveBlocksForVertex(const Standard_Integer theNV)
1954{
1155d05a 1955 const TColStd_ListOfInteger* pLE = myMapVE.Seek(theNV);
b7cd7c2b 1956 if (!pLE)
1957 return;
1958
1155d05a 1959 TColStd_ListIteratorOfListOfInteger aItLE(*pLE);
b7cd7c2b 1960 for (; aItLE.More(); aItLE.Next())
1961 ChangePaveBlocks(aItLE.Value());
3510db62 1962}
6769ec6b 1963
1964//=======================================================================
1965//function : ReleasePaveBlocks
1966//purpose :
1967//=======================================================================
1968void BOPDS_DS::ReleasePaveBlocks()
1969{
1970 // It is necessary to remove the reference to PaveBlocks for the untouched
1971 // edges to avoid creation of the same images for them.
1972 // Pave blocks for this reference should be cleared.
1973 // This will allow to differ the small edges, for which it is
1974 // impossible to even build a pave block from the normal edges for which the
1975 // pave block have been created, but stayed untouched.
1976 // The small edge, for which no pave blocks have been created,
1977 // should be avoided in the result, thus the reference to empty list
1978 // of pave blocks will stay to mark the edge as Deleted.
1979
1980 BOPDS_VectorOfListOfPaveBlock& aPBP = ChangePaveBlocksPool();
1155d05a 1981 Standard_Integer aNbPBP = aPBP.Length();
6769ec6b 1982 if (!aNbPBP) {
1983 return;
1984 }
1985 //
1986 for (Standard_Integer i = 0; i < aNbPBP; ++i) {
1987 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
1988 if (aLPB.Extent() == 1) {
1989 const Handle(BOPDS_PaveBlock)& aPB = aLPB.First();
1990 if (!IsCommonBlock(aPB)) {
1991 Standard_Integer nV1, nV2;
1992 aPB->Indices(nV1, nV2);
1993 if (!IsNewShape(nV1) && !IsNewShape(nV2)) {
1994 // Both vertices are original, thus the PB is untouched.
1995 // Remove reference for the original edge
1996 Standard_Integer nE = aPB->OriginalEdge();
1997 if (nE >= 0) {
1998 ChangeShapeInfo(nE).SetReference(-1);
1999 }
2000 // Clear contents of the list
2001 aLPB.Clear();
2002 }
2003 }
2004 }
2005 }
2006}
8ae442a8 2007
2008//=======================================================================
2009//function : IsValidShrunkData
2010//purpose :
2011//=======================================================================
2012Standard_Boolean BOPDS_DS::IsValidShrunkData(const Handle(BOPDS_PaveBlock)& thePB)
2013{
2014 if (!thePB->HasShrunkData())
2015 return Standard_False;
2016
2017 // Compare the distances from the bounds of the shrunk range to the vertices
2018 // with the tolerance values of vertices
2019
2020 // Shrunk range
2021 Standard_Real aTS[2];
2022 Bnd_Box aBox;
2023 Standard_Boolean bIsSplit;
2024 //
2025 thePB->ShrunkData(aTS[0], aTS[1], aBox, bIsSplit);
2026 //
2027 // Vertices
2028 Standard_Integer nV[2];
2029 thePB->Indices(nV[0], nV[1]);
2030 //
2031 const TopoDS_Edge& aE = TopoDS::Edge(Shape(thePB->OriginalEdge()));
2032 BRepAdaptor_Curve aBAC(aE);
2033 //
2034 Standard_Real anEps = BRep_Tool::Tolerance(aE) * 0.01;
2035 //
2036 for (Standard_Integer i = 0; i < 2; ++i) {
2037 const TopoDS_Vertex& aV = TopoDS::Vertex(Shape(nV[i]));
2038 Standard_Real aTol = BRep_Tool::Tolerance(aV) + Precision::Confusion();
2039 // Bounding point
2040 gp_Pnt aP = BRep_Tool::Pnt(aV);
2041 //
2042 // Point on the end of shrunk range
2043 gp_Pnt aPS = aBAC.Value(aTS[i]);
2044 //
2045 Standard_Real aDist = aP.Distance(aPS);
2046 if (aTol - aDist > anEps) {
2047 return Standard_False;
2048 }
2049 }
2050 return Standard_True;
2051}