1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <Bnd_Box.hxx>
17 #include <BOPCol_DataMapOfIntegerMapOfInteger.hxx>
18 #include <BOPCol_DataMapOfShapeInteger.hxx>
19 #include <BOPCol_ListOfInteger.hxx>
20 #include <BOPCol_MapOfInteger.hxx>
21 #include <BOPDS_CommonBlock.hxx>
22 #include <BOPDS_DS.hxx>
23 #include <BOPDS_FaceInfo.hxx>
24 #include <BOPDS_IndexRange.hxx>
25 #include <BOPDS_MapOfPave.hxx>
26 #include <BOPDS_MapOfPaveBlock.hxx>
27 #include <BOPDS_Pair.hxx>
28 #include <BOPDS_PaveBlock.hxx>
29 #include <BOPDS_ShapeInfo.hxx>
30 #include <BOPDS_VectorOfPave.hxx>
31 #include <BOPTools_AlgoTools.hxx>
32 #include <BRep_Builder.hxx>
33 #include <BRep_TEdge.hxx>
34 #include <BRep_TFace.hxx>
35 #include <BRep_Tool.hxx>
36 #include <BRep_TVertex.hxx>
37 #include <BRepBndLib.hxx>
38 #include <Geom_Curve.hxx>
39 #include <GeomAPI_ProjectPointOnCurve.hxx>
41 #include <IntTools_Tools.hxx>
42 #include <NCollection_BaseAllocator.hxx>
43 #include <Precision.hxx>
44 #include <Standard_Assert.hxx>
45 #include <TopoDS_Edge.hxx>
46 #include <TopoDS_Face.hxx>
47 #include <TopoDS_Iterator.hxx>
48 #include <TopoDS_Shape.hxx>
49 #include <TopoDS_Vertex.hxx>
50 #include <BOPCol_MapOfShape.hxx>
51 #include <BOPCol_DataMapOfIntegerListOfInteger.hxx>
57 void TotalShapes(const TopoDS_Shape& aS,
58 Standard_Integer& aNbS,
59 BOPCol_MapOfShape& aMS);
62 Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
63 const TopoDS_Edge& aE);
65 //=======================================================================
68 //=======================================================================
71 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
72 myArguments(myAllocator),
73 myRanges(0,myAllocator),
74 myLines(0, myAllocator),
75 myMapShapeIndex(100, myAllocator),
76 myPaveBlocksPool(0,myAllocator),
77 myMapPBCB(100, myAllocator),
78 myFaceInfoPool(0, myAllocator),
79 myShapesSD(100, myAllocator),
80 myMapVE(100, myAllocator),
81 myInterfTB(100, myAllocator),
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),
91 myInterfZZ(0, myAllocator)
96 //=======================================================================
99 //=======================================================================
100 BOPDS_DS::BOPDS_DS(const Handle(NCollection_BaseAllocator)& theAllocator)
102 myAllocator(theAllocator),
103 myArguments(myAllocator),
104 myRanges(0, myAllocator),
105 myLines(0, myAllocator),
106 myMapShapeIndex(100, myAllocator),
107 myPaveBlocksPool(0, myAllocator),
108 myMapPBCB(100, myAllocator),
109 myFaceInfoPool(0, myAllocator),
110 myShapesSD(100, myAllocator),
111 myMapVE(100, myAllocator),
112 myInterfTB(100, myAllocator),
113 myInterfVV(0, myAllocator),
114 myInterfVE(0, myAllocator),
115 myInterfVF(0, myAllocator),
116 myInterfEE(0, myAllocator),
117 myInterfEF(0, myAllocator),
118 myInterfFF(0, myAllocator),
119 myInterfVZ(0, myAllocator),
120 myInterfEZ(0, myAllocator),
121 myInterfFZ(0, myAllocator),
122 myInterfZZ(0, myAllocator)
127 //=======================================================================
130 //=======================================================================
131 BOPDS_DS::~BOPDS_DS()
135 //=======================================================================
138 //=======================================================================
139 void BOPDS_DS::Clear()
147 myMapShapeIndex.Clear();
148 myPaveBlocksPool.Clear();
149 myFaceInfoPool.Clear();
165 //=======================================================================
166 //function : SetArguments
168 //=======================================================================
169 void BOPDS_DS::SetArguments(const BOPCol_ListOfShape& theLS)
173 //=======================================================================
174 //function : Arguments
176 //=======================================================================
177 const BOPCol_ListOfShape& BOPDS_DS::Arguments()const
181 //=======================================================================
182 //function : Allocator
184 //=======================================================================
185 const Handle(NCollection_BaseAllocator)& BOPDS_DS::Allocator()const
190 //=======================================================================
191 //function : NbShapes
193 //=======================================================================
194 Standard_Integer BOPDS_DS::NbShapes()const
196 return myLines.Size();
198 //=======================================================================
199 //function : NbSourceShapes
201 //=======================================================================
202 Standard_Integer BOPDS_DS::NbSourceShapes()const
204 return myNbSourceShapes;
206 //=======================================================================
207 //function : NbRanges
209 //=======================================================================
210 Standard_Integer BOPDS_DS::NbRanges()const
212 return myRanges.Size();
214 //=======================================================================
217 //=======================================================================
218 const BOPDS_IndexRange& BOPDS_DS::Range(const Standard_Integer theI)const
220 return myRanges(theI);
222 //=======================================================================
225 //=======================================================================
226 Standard_Integer BOPDS_DS::Rank(const Standard_Integer theI)const
228 Standard_Integer i, aNb, iErr;
232 for(i=0; i<aNb; ++i) {
233 const BOPDS_IndexRange& aR=Range(i);
234 if (aR.Contains(theI)) {
240 //=======================================================================
241 //function : IsNewShape
243 //=======================================================================
244 Standard_Boolean BOPDS_DS::IsNewShape(const Standard_Integer theI)const
246 return theI>=NbSourceShapes();
248 //=======================================================================
251 //=======================================================================
252 Standard_Integer BOPDS_DS::Append(const BOPDS_ShapeInfo& theSI)
256 myLines.Append1()=theSI;
257 iX=myLines.Extent()-1;
258 myMapShapeIndex.Bind(theSI.Shape(), iX);
262 //=======================================================================
265 //=======================================================================
266 Standard_Integer BOPDS_DS::Append(const TopoDS_Shape& theS)
270 myLines.Append1().SetShape(theS);
271 iX=myLines.Extent()-1;
272 myMapShapeIndex.Bind(theS, iX);
275 //=======================================================================
276 //function : ShapeInfo
278 //=======================================================================
279 const BOPDS_ShapeInfo& BOPDS_DS::ShapeInfo
280 (const Standard_Integer theI)const
282 return myLines(theI);
284 //=======================================================================
285 //function : ChangeShapeInfo
287 //=======================================================================
288 BOPDS_ShapeInfo& BOPDS_DS::ChangeShapeInfo(const Standard_Integer theI)
290 BOPDS_ShapeInfo *pSI;
292 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI);
293 pSI=(BOPDS_ShapeInfo *)&aSI;
296 //=======================================================================
299 //=======================================================================
300 const TopoDS_Shape& BOPDS_DS::Shape(const Standard_Integer theI)const
303 const TopoDS_Shape& aS=ShapeInfo(theI).Shape();
306 //=======================================================================
309 //=======================================================================
310 Standard_Integer BOPDS_DS::Index(const TopoDS_Shape& theS)const
312 Standard_Integer iRet;
315 if (myMapShapeIndex.IsBound(theS)) {
316 iRet=myMapShapeIndex.Find(theS);
320 //=======================================================================
323 //=======================================================================
324 void BOPDS_DS::Init(const Standard_Real theFuzz)
326 Standard_Integer i1, i2, j, aI, aNb, aNbS, aNbE, aNbSx;
327 Standard_Integer n1, n2, n3, nV, nW, nE, aNbF;
328 Standard_Real aTol, aTolAdd;
329 TopAbs_ShapeEnum aTS;
330 TopoDS_Iterator aItS;
331 BOPCol_ListIteratorOfListOfInteger aIt1, aIt2, aIt3;
332 BOPCol_ListIteratorOfListOfShape aIt;
334 Handle(NCollection_BaseAllocator) aAllocator;
335 BOPCol_MapOfShape aMS;
337 // 1 Append Source Shapes
338 aNb=myArguments.Extent();
343 myRanges.SetIncrement(aNb);
346 aIt.Initialize(myArguments);
347 for (; aIt.More(); aIt.Next()) {
348 const TopoDS_Shape& aSx=aIt.Value();
351 TotalShapes(aSx, aNbSx, aMS);
357 myLines.SetIncrement(2*aNbS);
358 //-----------------------------------------------------scope_1 f
360 NCollection_BaseAllocator::CommonBaseAllocator();
365 aIt.Initialize(myArguments);
366 for (; aIt.More(); aIt.Next()) {
367 const TopoDS_Shape& aS=aIt.Value();
368 if (myMapShapeIndex.IsBound(aS)) {
376 aR.SetIndices(i1, i2);
381 aTolAdd = Max(theFuzz, Precision::Confusion()) * 0.5;
382 myNbSourceShapes = NbShapes();
387 for (j=0; j<myNbSourceShapes; ++j) {
388 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
390 const TopoDS_Shape& aS=aSI.Shape();
394 if (aTS==TopAbs_VERTEX) {
395 Bnd_Box& aBox=aSI.ChangeBox();
396 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aS);
397 const gp_Pnt& aP=BRep_Tool::Pnt(aV);
398 aTol = BRep_Tool::Tolerance(aV);
399 aBox.SetGap(aTol + aTolAdd);
405 for (j=0; j<myNbSourceShapes; ++j) {
406 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
409 if (aTS==TopAbs_EDGE) {
410 const TopoDS_Shape& aS=aSI.Shape();
411 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aS);
412 aTol = BRep_Tool::Tolerance(aE);
414 if (!BRep_Tool::Degenerated(aE)) {
415 Standard_Boolean bInf1, bInf2;
416 Standard_Integer aIx;
417 Standard_Real aT1, aT2;
419 Handle(Geom_Curve) aC3D;
423 BOPDS_ShapeInfo aSIx;
425 BOPCol_ListOfInteger& aLI=aSI.ChangeSubShapes();
428 aEx.Orientation(TopAbs_FORWARD);
430 aC3D=BRep_Tool::Curve (aEx, aT1, aT2);
431 bInf1=Precision::IsNegativeInfinite(aT1);
432 bInf2=Precision::IsPositiveInfinite(aT2);
436 aBB.MakeVertex(aVx, aPx, aTol);
437 aVx.Orientation(TopAbs_FORWARD);
440 aSIx.SetShapeType(TopAbs_VERTEX);
441 aSIx.SetFlag(1); //infinite flag
448 aBB.MakeVertex(aVx, aPx, aTol);
449 aVx.Orientation(TopAbs_REVERSED);
452 aSIx.SetShapeType(TopAbs_VERTEX);
453 aSIx.SetFlag(1);//infinite flag
463 Bnd_Box& aBox=aSI.ChangeBox();
464 BRepBndLib::Add(aE, aBox);
466 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
467 aIt1.Initialize(aLV);
468 for (; aIt1.More(); aIt1.Next()) {
470 BOPDS_ShapeInfo& aSIV=ChangeShapeInfo(nV);
471 Bnd_Box& aBx=aSIV.ChangeBox();
474 aBox.SetGap(aBox.GetGap() + aTolAdd);
479 BOPCol_MapOfInteger aMI(100, aAllocator);
480 BOPCol_MapIteratorOfMapOfInteger aItMI;
483 for (j=0; j<myNbSourceShapes; ++j) {
484 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
487 if (aTS==TopAbs_FACE) {
488 const TopoDS_Shape& aS=aSI.Shape();
490 Bnd_Box& aBox=aSI.ChangeBox();
491 BRepBndLib::Add(aS, aBox);
493 BOPCol_ListOfInteger& aLW=aSI.ChangeSubShapes();
494 aIt1.Initialize(aLW);
495 for (; aIt1.More(); aIt1.Next()) {
497 BOPDS_ShapeInfo& aSIW=ChangeShapeInfo(nW);
499 const BOPCol_ListOfInteger& aLE=aSIW.SubShapes();
500 aIt2.Initialize(aLE);
501 for (; aIt2.More(); aIt2.Next()) {
503 BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
504 Bnd_Box& aBx=aSIE.ChangeBox();
508 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aSIE.Shape());
509 if (BRep_Tool::Degenerated(aE)) {
513 const BOPCol_ListOfInteger& aLV=aSIE.SubShapes();
514 aIt3.Initialize(aLV);
515 for (; aIt3.More(); aIt3.Next()) {
520 }//for (; aIt1.More(); aIt1.Next()) {
522 // pure internal vertices on the face
524 for (; aItS.More(); aItS.Next()) {
525 const TopoDS_Shape& aSx=aItS.Value();
526 if (aSx.ShapeType()==TopAbs_VERTEX){
533 // For a Face: change wires for BRep sub-shapes
535 aItMI.Initialize(aMI);
536 for (; aItMI.More(); aItMI.Next()) {
541 aBox.SetGap(aBox.GetGap() + aTolAdd);
543 }//if (aTS==TopAbs_FACE) {
544 }//for (j=0; j<myNbSourceShapes; ++j) {
547 for (j=0; j<myNbSourceShapes; ++j) {
548 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
551 if (aTS!=TopAbs_SOLID) {
554 Bnd_Box& aBox=aSI.ChangeBox();
555 BuildBndBoxSolid(j, aBox);
558 // update sub-shapes by BRep comprising ones
560 BOPCol_ListOfInteger& aLI1=aSI.ChangeSubShapes();
562 aIt1.Initialize(aLI1);
563 for (; aIt1.More(); aIt1.Next()) {
565 BOPDS_ShapeInfo& aSI1=ChangeShapeInfo(n1);
566 if (aSI1.ShapeType()!=TopAbs_SHELL) {
570 const BOPCol_ListOfInteger& aLI2=aSI1.SubShapes();
571 aIt2.Initialize(aLI2);
572 for (; aIt2.More(); aIt2.Next()) {
574 BOPDS_ShapeInfo& aSI2=ChangeShapeInfo(n2);
575 if (aSI2.ShapeType()!=TopAbs_FACE) {
581 const BOPCol_ListOfInteger& aLI3=aSI2.SubShapes();
582 aIt3.Initialize(aLI3);
583 for (; aIt3.More(); aIt3.Next()) {
591 aItMI.Initialize(aMI);
592 for (; aItMI.More(); aItMI.Next()) {
597 }//for (j=0; j<myNbSourceShapes; ++j) {
600 //-----------------------------------------------------
602 for (nE=0; nE<myNbSourceShapes; ++nE) {
603 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(nE);
604 if (aSI.ShapeType()!=TopAbs_EDGE) {
608 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
609 aIt1.Initialize(aLV);
610 for (; aIt1.More(); aIt1.Next()) {
612 if (myMapVE.IsBound(nV)) {
613 BOPCol_ListOfInteger& aLE=myMapVE.ChangeFind(nV);
617 BOPCol_ListOfInteger aLE(myAllocator);
620 myMapVE.Bind(nV, aLE);
625 BOPCol_DataMapIteratorOfDataMapOfIntegerListOfInteger aItDMILI;
626 aItDMILI.Initialize(myMapVE);
627 for(; aItDMILI.More(); aItDMILI.Next()) {
628 BOPCol_MapOfInteger aMFence;
629 BOPCol_ListOfInteger aLEx;
632 BOPCol_ListOfInteger& aLE=aItDMILI.ChangeValue();
633 aIt1.Initialize(aLE);
634 for (; aIt1.More(); aIt1.Next()) {
636 if(aMFence.Add(nE)) {
642 aIt1.Initialize(aLEx);
643 for (; aIt1.More(); aIt1.Next()) {
648 //-----------------------------------------------------scope_1 t
649 // 3 myPaveBlocksPool
651 myPaveBlocksPool.SetIncrement(aNbE);
652 myFaceInfoPool.SetIncrement(aNbF);
654 //=======================================================================
655 //function : InitShape
657 //=======================================================================
658 void BOPDS_DS::InitShape
659 (const Standard_Integer aI,
660 const TopoDS_Shape& aS)
662 Standard_Integer aIx;
664 BOPCol_ListIteratorOfListOfInteger aIt1;
666 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(aI);
667 aSI.SetShapeType(aS.ShapeType());
668 BOPCol_ListOfInteger& aLI=aSI.ChangeSubShapes();
670 BOPCol_MapOfInteger aM;
672 aIt1.Initialize(aLI);
673 for (; aIt1.More(); aIt1.Next()) {
674 aM.Add(aIt1.Value());
678 for (; aIt.More(); aIt.Next()) {
679 const TopoDS_Shape& aSx=aIt.Value();
680 const Standard_Integer* pIx = myMapShapeIndex.Seek(aSx);
681 aIx = (pIx ? *pIx : Append(aSx));
691 //=======================================================================
692 //function : HasInterf
694 //=======================================================================
695 Standard_Boolean BOPDS_DS::HasInterf(const Standard_Integer theI) const
697 Standard_Integer n1, n2;
698 Standard_Boolean bRet;
699 BOPDS_MapIteratorOfMapOfPair aIt;
701 bRet = Standard_False;
703 aIt.Initialize(myInterfTB);
704 for (; aIt.More(); aIt.Next()) {
705 const BOPDS_Pair& aPK = aIt.Value();
707 if (n1 == theI || n2 == theI) {
708 bRet = Standard_True;
715 //=======================================================================
716 //function : HasInterfShapeSubShapes
718 //=======================================================================
719 Standard_Boolean BOPDS_DS::HasInterfShapeSubShapes
720 (const Standard_Integer theI1,
721 const Standard_Integer theI2,
722 const Standard_Boolean theFlag)const
724 Standard_Boolean bRet;
726 BOPCol_ListIteratorOfListOfInteger aIt;
727 bRet = Standard_False;
729 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI2);
730 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
732 for (; aIt.More(); aIt.Next()) {
734 bRet=HasInterf(theI1, n2);
748 //=======================================================================
749 //function : HasInterfSubShapes
751 //=======================================================================
752 Standard_Boolean BOPDS_DS::HasInterfSubShapes
753 (const Standard_Integer theI1,
754 const Standard_Integer theI2)const
756 Standard_Boolean bRet;
758 BOPCol_ListIteratorOfListOfInteger aIt;
759 bRet = Standard_False;
761 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI1);
762 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
764 for (; aIt.More(); aIt.Next()) {
766 bRet=HasInterfShapeSubShapes(n1, theI2);
775 //=======================================================================
776 //function : PaveBlocksPool
778 //=======================================================================
779 const BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::PaveBlocksPool()const
781 return myPaveBlocksPool;
783 //=======================================================================
784 //function : ChangePaveBlocksPool
786 //=======================================================================
787 BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::ChangePaveBlocksPool()
789 return myPaveBlocksPool;
791 //=======================================================================
792 //function : HasPaveBlocks
794 //=======================================================================
795 Standard_Boolean BOPDS_DS::HasPaveBlocks(const Standard_Integer theI)const
797 return ShapeInfo(theI).HasReference();
799 //=======================================================================
800 //function : PaveBlocks
802 //=======================================================================
803 const BOPDS_ListOfPaveBlock& BOPDS_DS::PaveBlocks
804 (const Standard_Integer theI)const
806 static BOPDS_ListOfPaveBlock sLPB;
807 Standard_Integer aRef;
809 if (HasPaveBlocks(theI)) {
810 aRef=ShapeInfo(theI).Reference();
811 const BOPDS_ListOfPaveBlock& aLPB=myPaveBlocksPool(aRef);
817 //=======================================================================
818 //function : ChangePaveBlocks
820 //=======================================================================
821 BOPDS_ListOfPaveBlock& BOPDS_DS::ChangePaveBlocks
822 (const Standard_Integer theI)
824 Standard_Boolean bHasReference;
825 Standard_Integer aRef;
827 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
828 bHasReference=aSI.HasReference();
829 if (!bHasReference) {
830 InitPaveBlocks(theI);
833 aRef=aSI.Reference();
834 return myPaveBlocksPool(aRef);
836 //=======================================================================
837 //function : InitPaveBlocks
839 //=======================================================================
840 void BOPDS_DS::InitPaveBlocks(const Standard_Integer theI)
842 Standard_Integer nV=0, iRef, aNbV, nVSD;
844 TopAbs_Orientation aOrE;
846 BOPCol_ListIteratorOfListOfInteger aIt;
848 Handle(BOPDS_PaveBlock) aPB;
850 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
851 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aSI.Shape());
852 aOrE=aE.Orientation();
854 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
860 aPB=new BOPDS_PaveBlock;
861 aPB->SetOriginalEdge(theI);
863 if (aOrE!=TopAbs_INTERNAL) {
865 for (; aIt.More(); aIt.Next()) {
868 const BOPDS_ShapeInfo& aSIV=ShapeInfo(nV);
869 aV=*(TopoDS_Vertex*)(&aSIV.Shape());
870 if (aSIV.HasFlag()) {
871 aT=ComputeParameter(aV, aE);
874 aT=BRep_Tool::Parameter(aV, aE);
877 if (HasShapeSD(nV, nVSD)) {
881 aPave.SetParameter(aT);
883 // for a degenerated edge append pave unconditionally
884 aPB->AppendExtPave1(aPave);
886 aPB->AppendExtPave(aPave);
891 aT=BRep_Tool::Parameter(aV, aE);
893 aPave.SetParameter(aT);
894 aPB->AppendExtPave1(aPave);
899 TopoDS_Iterator aItE;
901 aItE.Initialize(aE, Standard_False, Standard_True);
902 for (; aItE.More(); aItE.Next()) {
903 aV=*((TopoDS_Vertex*)&aItE.Value());
906 const BOPDS_ShapeInfo& aSIV=ShapeInfo(nV);
907 if (aSIV.HasFlag()) {
908 aT=ComputeParameter(aV, aE);
911 aT=BRep_Tool::Parameter(aV, aE);
914 if (HasShapeSD(nV, nVSD)) {
918 aPave.SetParameter(aT);
919 aPB->AppendExtPave1(aPave);
923 BOPDS_ListOfPaveBlock &aLPB=myPaveBlocksPool.Append1();
924 iRef=myPaveBlocksPool.Extent()-1;
926 aPB->Update(aLPB, Standard_False);
927 aSI.SetReference(iRef);
929 //=======================================================================
930 //function : UpdatePaveBlocks
932 //=======================================================================
933 void BOPDS_DS::UpdatePaveBlocks()
935 Standard_Boolean bIsToUpdate;
936 Standard_Integer i, aNbPBP;
937 BOPDS_ListOfPaveBlock aLPBN(myAllocator);
938 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBN;
940 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
943 for (i=0; i<aNbPBP; ++i) {
944 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
946 aItPB.Initialize(aLPB);
947 for (; aItPB.More(); aItPB.Next()) {
948 Handle(BOPDS_PaveBlock)& aPB=aItPB.ChangeValue();
950 bIsToUpdate=aPB->IsToUpdate();
955 aItPBN.Initialize(aLPBN);
956 for (; aItPBN.More(); aItPBN.Next()) {
957 Handle(BOPDS_PaveBlock)& aPBN=aItPBN.ChangeValue();
962 }// for (; aItPB.More(); aItPB.Next()) {
963 }// for (i=0; i<aNbPBP; ++i) {
965 //=======================================================================
966 //function : UpdatePaveBlock
968 //=======================================================================
969 void BOPDS_DS::UpdatePaveBlock(const Handle(BOPDS_PaveBlock)& thePB)
971 if (!thePB->IsToUpdate()){
975 Standard_Integer nE, iRef;
976 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBN;
977 BOPDS_ListOfPaveBlock aLPBN(myAllocator);
978 Handle(BOPDS_PaveBlock) aPB;
980 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
982 nE=thePB->OriginalEdge();
983 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(nE);
984 iRef=aSI.Reference();
985 BOPDS_ListOfPaveBlock& aLPB=aPBP(iRef);
987 aItPB.Initialize(aLPB);
988 for (; aItPB.More(); aItPB.Next()) {
989 aPB=aItPB.ChangeValue();
998 //=======================================================================
999 //function : UpdateCommonBlock
1001 //=======================================================================
1002 void BOPDS_DS::UpdateCommonBlock(const Handle(BOPDS_CommonBlock)& theCB,
1003 const Standard_Real theFuzz)
1005 Standard_Integer nE, iRef, n1, n2;
1006 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBCB, aItPBN;
1007 BOPDS_ListOfPaveBlock aLPBN;
1008 NCollection_DataMap<BOPDS_Pair, BOPDS_ListOfPaveBlock, BOPDS_PairMapHasher> aMPKLPB;
1009 NCollection_DataMap<BOPDS_Pair, BOPDS_ListOfPaveBlock, BOPDS_PairMapHasher>::Iterator aItMPKLPB;
1010 Handle(BOPDS_PaveBlock) aPB;
1011 Handle(BOPDS_CommonBlock) aCBx;
1014 const BOPDS_ListOfPaveBlock& aLPBCB=theCB->PaveBlocks();
1015 if (!aLPBCB.First()->IsToUpdate()){
1019 const BOPCol_ListOfInteger& aLF=theCB->Faces();
1021 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
1023 aItPBCB.Initialize(aLPBCB);
1024 for (; aItPBCB.More(); aItPBCB.Next()) {
1025 const Handle(BOPDS_PaveBlock)& aPBCB=aItPBCB.ChangeValue();
1027 nE=aPBCB->OriginalEdge();
1028 iRef=ChangeShapeInfo(nE).Reference();
1029 BOPDS_ListOfPaveBlock& aLPB=aPBP(iRef);
1031 aItPB.Initialize(aLPB);
1032 for (; aItPB.More(); aItPB.Next()) {
1033 aPB=aItPB.ChangeValue();
1039 aItPBN.Initialize(aLPBN);
1040 for (; aItPBN.More(); aItPBN.Next()) {
1041 Handle(BOPDS_PaveBlock)& aPBN=aItPBN.ChangeValue();
1044 aPBN->Indices(n1, n2);
1045 aPK.SetIndices(n1, n2);
1046 if (aMPKLPB.IsBound(aPK)) {
1047 BOPDS_ListOfPaveBlock& aLPBx=aMPKLPB.ChangeFind(aPK);
1051 BOPDS_ListOfPaveBlock aLPBx;
1053 aMPKLPB.Bind(aPK, aLPBx);
1062 aItMPKLPB.Initialize(aMPKLPB);
1063 for (; aItMPKLPB.More(); aItMPKLPB.Next()) {
1064 BOPDS_ListOfPaveBlock& aLPBx=aItMPKLPB.ChangeValue();
1066 while (aLPBx.Extent()) {
1067 Standard_Boolean bCoinside;
1068 BOPDS_ListOfPaveBlock aLPBxN;
1070 aItPB.Initialize(aLPBx);
1071 for(; aItPB.More(); ) {
1072 const Handle(BOPDS_PaveBlock)& aPBx=aItPB.Value();
1073 if (aLPBxN.Extent()) {
1074 const Handle(BOPDS_PaveBlock)& aPBCx = aLPBxN.First();
1075 bCoinside = CheckCoincidence(aPBx, aPBCx, theFuzz);
1077 aLPBxN.Append(aPBx);
1078 aLPBx.Remove(aItPB);
1081 }//if (aLPBxN.Extent()) {
1083 aLPBxN.Append(aPBx);
1084 aLPBx.Remove(aItPB);
1088 }//for(; aItPB.More(); ) {
1090 aCBx=new BOPDS_CommonBlock;
1091 aCBx->SetPaveBlocks(aLPBxN);
1092 aCBx->SetFaces(aLF);
1094 aItPB.Initialize(aLPBxN);
1095 for (; aItPB.More(); aItPB.Next()) {
1096 aPB=aItPB.ChangeValue();
1097 SetCommonBlock(aPB, aCBx);
1103 //=======================================================================
1104 // function: RealPaveBlock
1106 //=======================================================================
1107 Handle(BOPDS_PaveBlock) BOPDS_DS::RealPaveBlock
1108 (const Handle(BOPDS_PaveBlock)& thePB) const
1110 if (IsCommonBlock(thePB)) {
1111 const Handle(BOPDS_CommonBlock)& aCB = CommonBlock(thePB);
1112 const Handle(BOPDS_PaveBlock)& aPB = aCB->PaveBlock1();
1118 //=======================================================================
1119 // function: IsCommonBlockOnEdge
1121 //=======================================================================
1122 Standard_Boolean BOPDS_DS::IsCommonBlockOnEdge
1123 (const Handle(BOPDS_PaveBlock)& thePB) const
1125 if (IsCommonBlock(thePB)) {
1126 const Handle(BOPDS_CommonBlock)& aCB = CommonBlock(thePB);
1127 return aCB->PaveBlocks().Extent()>1;
1129 return Standard_False;
1132 //=======================================================================
1133 //function : IsCommonBlock
1135 //=======================================================================
1136 Standard_Boolean BOPDS_DS::IsCommonBlock
1137 (const Handle(BOPDS_PaveBlock)& thePB) const
1139 return myMapPBCB.IsBound(thePB);
1142 //=======================================================================
1143 //function : CommonBlock
1145 //=======================================================================
1146 Handle(BOPDS_CommonBlock) BOPDS_DS::CommonBlock
1147 (const Handle(BOPDS_PaveBlock)& thePB) const
1149 return (IsCommonBlock(thePB) ? myMapPBCB.Find(thePB) : NULL);
1152 //=======================================================================
1153 //function : SetCommonBlock
1155 //=======================================================================
1156 void BOPDS_DS::SetCommonBlock(const Handle(BOPDS_PaveBlock)& thePB,
1157 const Handle(BOPDS_CommonBlock)& theCB)
1159 if (IsCommonBlock(thePB)) {
1160 Handle(BOPDS_CommonBlock)& aCB = myMapPBCB.ChangeFind(thePB);
1164 myMapPBCB.Bind(thePB, theCB);
1172 //=======================================================================
1173 //function : FaceInfoPool
1175 //=======================================================================
1176 const BOPDS_VectorOfFaceInfo& BOPDS_DS::FaceInfoPool()const
1178 return myFaceInfoPool;
1180 //=======================================================================
1181 //function : HasFaceInfo
1183 //=======================================================================
1184 Standard_Boolean BOPDS_DS::HasFaceInfo(const Standard_Integer theI)const
1186 return ShapeInfo(theI).HasReference();
1188 //=======================================================================
1189 //function : FaceInfo
1191 //=======================================================================
1192 const BOPDS_FaceInfo& BOPDS_DS::FaceInfo(const Standard_Integer theI)const
1194 static BOPDS_FaceInfo sFI;
1195 Standard_Integer aRef;
1197 if (HasFaceInfo(theI)) {
1198 aRef=ShapeInfo(theI).Reference();
1199 const BOPDS_FaceInfo& aFI=myFaceInfoPool(aRef);
1204 //=======================================================================
1205 //function : ChangeFaceInfo
1207 //=======================================================================
1208 BOPDS_FaceInfo& BOPDS_DS::ChangeFaceInfo(const Standard_Integer theI)
1210 Standard_Boolean bHasReference;
1211 Standard_Integer aRef;
1212 BOPDS_FaceInfo* pFI;
1214 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1215 bHasReference=aSI.HasReference();
1216 if (!bHasReference) {
1220 aRef=aSI.Reference();
1221 const BOPDS_FaceInfo& aFI=myFaceInfoPool(aRef);
1222 pFI=(BOPDS_FaceInfo*)&aFI;
1225 //=======================================================================
1226 //function : InitFaceInfo
1228 //=======================================================================
1229 void BOPDS_DS::InitFaceInfo(const Standard_Integer theI)
1231 Standard_Integer iRef;
1233 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1234 BOPDS_FaceInfo &aFI=myFaceInfoPool.Append1();
1235 iRef=myFaceInfoPool.Extent()-1;
1236 aSI.SetReference(iRef);
1239 UpdateFaceInfoIn(theI);
1240 UpdateFaceInfoOn(theI);
1242 //=======================================================================
1243 //function : UpdateFaceInfoIn
1245 //=======================================================================
1246 void BOPDS_DS::UpdateFaceInfoIn(const Standard_Integer theI)
1248 Standard_Integer iRef;
1250 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1251 if (aSI.HasReference()) {
1252 iRef=aSI.Reference();
1253 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1255 BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.ChangePaveBlocksIn();
1256 BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
1259 FaceInfoIn(theI, aMPBIn, aMVIn);
1262 //=======================================================================
1263 //function : UpdateFaceInfoOn
1265 //=======================================================================
1266 void BOPDS_DS::UpdateFaceInfoOn(const Standard_Integer theI)
1268 Standard_Integer iRef;
1270 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1271 if (aSI.HasReference()) {
1272 iRef=aSI.Reference();
1273 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1275 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1276 BOPCol_MapOfInteger& aMVOn=aFI.ChangeVerticesOn();
1279 FaceInfoOn(theI, aMPBOn, aMVOn);
1282 //=======================================================================
1283 //function : FaceInfoOn
1285 //=======================================================================
1286 void BOPDS_DS::FaceInfoOn(const Standard_Integer theF,
1287 BOPDS_IndexedMapOfPaveBlock& theMPB,
1288 BOPCol_MapOfInteger& theMI)
1290 Standard_Integer nS, nSD, nV1, nV2;
1291 BOPCol_ListIteratorOfListOfInteger aIt;
1292 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1294 const BOPDS_ShapeInfo& aSI=ShapeInfo(theF);
1295 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
1296 aIt.Initialize(aLI);
1297 for (; aIt.More(); aIt.Next()) {
1299 const BOPDS_ShapeInfo& aSIE=ShapeInfo(nS);
1300 if (aSIE.ShapeType()==TopAbs_EDGE) {
1301 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nS);
1302 aItPB.Initialize(aLPB);
1303 for (; aItPB.More(); aItPB.Next()) {
1304 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
1305 aPB->Indices(nV1, nV2);
1308 Handle(BOPDS_PaveBlock) aPBR=RealPaveBlock(aPB);
1311 }//if (aSIE.ShapeType()==TopAbs_EDGE)
1313 // nE is TopAbs_VERTEX
1314 if (HasShapeSD(nS, nSD)) {
1321 //=======================================================================
1322 //function : FaceInfoIn
1324 //=======================================================================
1325 void BOPDS_DS::FaceInfoIn(const Standard_Integer theF,
1326 BOPDS_IndexedMapOfPaveBlock& theMPB,
1327 BOPCol_MapOfInteger& theMI)
1329 Standard_Integer i, aNbVF, aNbEF, nV, nE, nVSD;
1330 TopoDS_Iterator aItS;
1331 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1333 // 1. Pure internal vertices on the face
1334 const TopoDS_Shape& aF=Shape(theF);
1335 aItS.Initialize(aF);
1336 for (; aItS.More(); aItS.Next()) {
1337 const TopoDS_Shape& aSx=aItS.Value();
1338 if (aSx.ShapeType()==TopAbs_VERTEX){
1340 if (HasShapeSD(nV, nVSD)) {
1348 BOPDS_VectorOfInterfVF& aVFs=InterfVF();
1349 aNbVF=aVFs.Extent();
1350 for (i=0; i<aNbVF; ++i) {
1351 BOPDS_InterfVF& aVF=aVFs(i);
1352 if(aVF.Contains(theF)) {
1353 nV=aVF.OppositeIndex(theF);
1354 if (HasShapeSD(nV, nVSD)) {
1362 BOPDS_VectorOfInterfEF& aEFs=InterfEF();
1363 aNbEF=aEFs.Extent();
1364 for (i=0; i<aNbEF; ++i) {
1365 BOPDS_InterfEF& aEF=aEFs(i);
1366 if(aEF.Contains(theF)) {
1367 if(aEF.HasIndexNew(nV)) {
1371 nE=aEF.OppositeIndex(theF);
1372 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1373 aItPB.Initialize(aLPB);
1374 for (; aItPB.More(); aItPB.Next()) {
1375 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
1376 if (IsCommonBlock(aPB)) {
1377 const Handle(BOPDS_CommonBlock)& aCB=CommonBlock(aPB);
1378 if (aCB->Contains(theF)) {
1379 const Handle(BOPDS_PaveBlock)& aPB1=aCB->PaveBlock1();
1383 }// for (; aItPB.More(); aItPB.Next()) {
1385 }// if(aEF.Contains(theF)) {
1386 }// for (i=0; i<aNbEF; ++i) {
1389 //=======================================================================
1390 //function : RefineFaceInfoOn
1392 //=======================================================================
1393 void BOPDS_DS::RefineFaceInfoOn()
1395 Standard_Integer i, aNb, nF, aNbPB, j;
1396 BOPDS_IndexedMapOfPaveBlock aMPB;
1398 aNb=myFaceInfoPool.Extent();
1399 for (i=0; i<aNb; ++i) {
1400 BOPDS_FaceInfo &aFI=myFaceInfoPool(i);
1402 UpdateFaceInfoOn(nF);
1403 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1406 aMPB.Assign(aMPBOn);
1409 aNbPB=aMPB.Extent();
1410 for (j=1; j<=aNbPB; ++j) {
1411 const Handle(BOPDS_PaveBlock)& aPB=aMPB(j);
1412 if (aPB->HasEdge()) {
1418 //=======================================================================
1419 //function : AloneVertices
1421 //=======================================================================
1422 void BOPDS_DS::AloneVertices(const Standard_Integer theI,
1423 BOPCol_ListOfInteger& theLI)const
1425 if (HasFaceInfo(theI)) {
1427 Standard_Integer i, j, nV1, nV2, nV, aNbPB;
1428 BOPCol_MapIteratorOfMapOfInteger aItMI;
1430 BOPCol_MapOfInteger aMI(100, myAllocator);
1432 const BOPDS_FaceInfo& aFI=FaceInfo(theI);
1434 for (i = 0; i < 2; ++i) {
1435 const BOPDS_IndexedMapOfPaveBlock& aMPB=
1436 (!i) ? aFI.PaveBlocksIn() : aFI.PaveBlocksSc();
1437 aNbPB = aMPB.Extent();
1438 for (j = 1; j <= aNbPB; ++j) {
1439 const Handle(BOPDS_PaveBlock)& aPB = aMPB(j);
1440 aPB->Indices(nV1, nV2);
1446 for (i=0; i<2; ++i) {
1447 const BOPCol_MapOfInteger& aMIV=
1448 (!i) ? aFI.VerticesIn() : aFI.VerticesSc();
1449 aItMI.Initialize(aMIV);
1450 for (; aItMI.More(); aItMI.Next()) {
1461 //=======================================================================
1462 //function : VerticesOnIn
1464 //=======================================================================
1465 void BOPDS_DS::SubShapesOnIn
1466 (const Standard_Integer nF1,
1467 const Standard_Integer nF2,
1468 BOPCol_MapOfInteger& theMVOnIn,
1469 BOPDS_IndexedMapOfPaveBlock& thePBOnIn,
1470 BOPDS_MapOfPaveBlock& theCommonPB)const
1472 Standard_Integer i, j, nV, nV1, nV2, aNbPB;
1473 BOPCol_MapIteratorOfMapOfInteger aIt;
1474 BOPDS_IndexedMapOfPaveBlock pMPB[4];
1476 const BOPDS_FaceInfo& aFI1=FaceInfo(nF1);
1477 const BOPDS_FaceInfo& aFI2=FaceInfo(nF2);
1479 pMPB[0]=aFI1.PaveBlocksOn();
1480 pMPB[1]=aFI1.PaveBlocksIn();
1481 pMPB[2]=aFI2.PaveBlocksOn();
1482 pMPB[3]=aFI2.PaveBlocksIn();
1484 for (i=0; i<4; ++i) {
1485 aNbPB = pMPB[i].Extent();
1486 for (j = 1; j <= aNbPB; ++j) {
1487 const Handle(BOPDS_PaveBlock)& aPB = pMPB[i](j);
1489 aPB->Indices(nV1, nV2);
1493 if (pMPB[2].Contains(aPB) || pMPB[3].Contains(aPB))
1494 theCommonPB.Add(aPB);
1499 const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
1500 const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
1501 const BOPCol_MapOfInteger& aMVOn2=aFI2.VerticesOn();
1502 const BOPCol_MapOfInteger& aMVIn2=aFI2.VerticesIn();
1504 for (i=0; i<2; ++i) {
1505 const BOPCol_MapOfInteger& aMV1=(!i) ? aMVOn1 : aMVIn1;
1506 aIt.Initialize(aMV1);
1507 for (; aIt.More(); aIt.Next()) {
1509 if (aMVOn2.Contains(nV) || aMVIn2.Contains(nV)) {
1515 //=======================================================================
1516 //function : SharedEdges
1518 //=======================================================================
1519 void BOPDS_DS::SharedEdges(const Standard_Integer nF1,
1520 const Standard_Integer nF2,
1521 BOPCol_ListOfInteger& theLI,
1522 const Handle(NCollection_BaseAllocator)& aAllocator)
1524 Standard_Integer nE, nSp;
1525 BOPCol_ListIteratorOfListOfInteger aItLI;
1526 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
1527 BOPCol_MapOfInteger aMI(100, aAllocator);
1529 const BOPDS_ShapeInfo& aSI1=ShapeInfo(nF1);
1530 const BOPCol_ListOfInteger& aLI1=aSI1.SubShapes();
1531 aItLI.Initialize(aLI1);
1532 for (; aItLI.More(); aItLI.Next()) {
1534 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1535 if(aSIE.ShapeType()==TopAbs_EDGE) {
1536 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1537 if (aLPB.IsEmpty()) {
1541 aItLPB.Initialize(aLPB);
1542 for (; aItLPB.More(); aItLPB.Next()) {
1543 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
1551 const BOPDS_ShapeInfo& aSI2=ShapeInfo(nF2);
1552 const BOPCol_ListOfInteger& aLI2=aSI2.SubShapes();
1553 aItLI.Initialize(aLI2);
1554 for (; aItLI.More(); aItLI.Next()) {
1556 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1557 if(aSIE.ShapeType()==TopAbs_EDGE) {
1558 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1559 if (aLPB.IsEmpty()) {
1560 if (aMI.Contains(nE)) {
1565 aItLPB.Initialize(aLPB);
1566 for (; aItLPB.More(); aItLPB.Next()) {
1567 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
1569 if (aMI.Contains(nSp)) {
1578 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1580 // same domain shapes
1582 //=======================================================================
1583 //function : ShapesSD
1585 //=======================================================================
1586 BOPCol_DataMapOfIntegerInteger& BOPDS_DS::ShapesSD()
1590 //=======================================================================
1591 //function : AddShapeSD
1593 //=======================================================================
1594 void BOPDS_DS::AddShapeSD(const Standard_Integer theIndex,
1595 const Standard_Integer theIndexSD)
1597 myShapesSD.Bind(theIndex, theIndexSD);
1599 //=======================================================================
1600 //function : HasShapeSD
1602 //=======================================================================
1603 Standard_Boolean BOPDS_DS::HasShapeSD
1604 (const Standard_Integer theIndex,
1605 Standard_Integer& theIndexSD)const
1607 Standard_Boolean bRet;
1609 bRet=myShapesSD.IsBound(theIndex);
1611 theIndexSD=myShapesSD.Find(theIndex);
1615 //=======================================================================
1618 //=======================================================================
1619 void BOPDS_DS::Dump()const
1621 Standard_Integer i, aNb, aNbSS;
1623 printf(" *** DS ***\n");
1625 printf(" Ranges:%d\n", aNb);
1626 for (i=0; i<aNb; ++i) {
1627 const BOPDS_IndexRange& aR=Range(i);
1632 aNbSS=NbSourceShapes();
1633 printf(" Shapes:%d\n", aNbSS);
1635 for (i=0; i<aNb; ++i) {
1636 const BOPDS_ShapeInfo& aSI=ShapeInfo(i);
1641 printf(" ****** adds\n");
1644 printf(" ******\n");
1647 //=======================================================================
1648 // function: CheckCoincidence
1650 //=======================================================================
1651 Standard_Boolean BOPDS_DS::CheckCoincidence
1652 (const Handle(BOPDS_PaveBlock)& aPB1,
1653 const Handle(BOPDS_PaveBlock)& aPB2,
1654 const Standard_Real theFuzz)
1656 Standard_Boolean bRet;
1657 Standard_Integer nE1, nE2, aNbPoints;
1658 Standard_Real aT11, aT12, aT21, aT22, aT1m, aD, aTol, aT2x;
1661 bRet=Standard_False;
1663 aPB1->Range(aT11, aT12);
1664 aT1m=IntTools_Tools::IntermediatePoint (aT11, aT12);
1665 nE1=aPB1->OriginalEdge();
1666 const TopoDS_Edge& aE1=(*(TopoDS_Edge*)(&Shape(nE1)));
1667 BOPTools_AlgoTools::PointOnEdge(aE1, aT1m, aP1m);
1669 aPB2->Range(aT21, aT22);
1670 nE2=aPB2->OriginalEdge();
1671 const TopoDS_Edge& aE2=(*(TopoDS_Edge*)(&Shape(nE2)));
1674 Handle(Geom_Curve)aC2 = BRep_Tool::Curve (aE2, f, l);
1675 GeomAPI_ProjectPointOnCurve aPPC;
1676 aPPC.Init(aC2, f, l);
1678 aNbPoints=aPPC.NbPoints();
1680 aD=aPPC.LowerDistance();
1682 aTol = BRep_Tool::MaxTolerance(aE1, TopAbs_VERTEX);
1683 aTol = aTol + BRep_Tool::MaxTolerance(aE2, TopAbs_VERTEX) + Max(theFuzz, Precision::Confusion());
1685 aT2x=aPPC.LowerDistanceParameter();
1686 if (aT2x>aT21 && aT2x<aT22) {
1693 //=======================================================================
1694 // function: IsSubShape
1696 //=======================================================================
1697 Standard_Boolean BOPDS_DS::IsSubShape
1698 (const Standard_Integer theI1,
1699 const Standard_Integer theI2)
1701 Standard_Boolean bRet;
1702 Standard_Integer nS;
1703 bRet = Standard_False;
1705 BOPCol_ListIteratorOfListOfInteger aItLI;
1707 const BOPDS_ShapeInfo& aSI = ShapeInfo(theI2);
1708 const BOPCol_ListOfInteger& aLI = aSI.SubShapes();
1709 aItLI.Initialize(aLI);
1710 for(;aItLI.More(); aItLI.Next()) {
1713 bRet = Standard_True;
1720 //=======================================================================
1723 //=======================================================================
1724 void BOPDS_DS::Paves(const Standard_Integer theEdge,
1725 BOPDS_ListOfPave& theLP)
1727 Standard_Integer aNb, i;
1728 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1729 BOPDS_MapOfPave aMP;
1731 const BOPDS_ListOfPaveBlock& aLPB = PaveBlocks(theEdge);
1732 aNb = aLPB.Extent() + 1;
1737 BOPDS_VectorOfPave pPaves(1, aNb);
1740 aIt.Initialize(aLPB);
1741 for (; aIt.More(); aIt.Next()) {
1742 const Handle(BOPDS_PaveBlock)& aPB = aIt.Value();
1743 const BOPDS_Pave& aPave1 = aPB->Pave1();
1744 const BOPDS_Pave& aPave2 = aPB->Pave2();
1746 if (aMP.Add(aPave1)){
1751 if (aMP.Add(aPave2)){
1757 Standard_ASSERT_VOID(aNb == aMP.Extent(), "Abnormal number of paves");
1759 std::sort(pPaves.begin(), pPaves.end());
1761 for (i = 1; i <= aNb; ++i) {
1762 theLP.Append(pPaves(i));
1765 //=======================================================================
1766 // function: UpdateTolerance
1768 //=======================================================================
1769 void BOPDS_DS::UpdateEdgeTolerance(const Standard_Integer nE,
1770 const Standard_Real aTol,
1771 const Standard_Real theFuzz)
1773 Standard_Integer nV;
1774 Standard_Real aTolV;
1776 BOPCol_ListIteratorOfListOfInteger aIt;
1778 Standard_Real aTolAdd = Max(theFuzz, Precision::Confusion()) * 0.5;
1780 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1781 aBB.UpdateEdge(aE, aTol);
1782 BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1783 Bnd_Box& aBoxE=aSIE.ChangeBox();
1784 BRepBndLib::Add(aE, aBoxE);
1785 aBoxE.SetGap(aBoxE.GetGap() + aTolAdd);
1787 const BOPCol_ListOfInteger& aLI = aSIE.SubShapes();
1788 aIt.Initialize(aLI);
1789 for (; aIt.More(); aIt.Next()) {
1791 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&Shape(nV);
1792 aTolV = BRep_Tool::Tolerance(aV);
1794 aBB.UpdateVertex(aV, aTol);
1795 BOPDS_ShapeInfo& aSIV = ChangeShapeInfo(nV);
1796 Bnd_Box& aBoxV = aSIV.ChangeBox();
1797 BRepBndLib::Add(aV, aBoxV);
1798 aBoxV.SetGap(aBoxV.GetGap() + aTolAdd);
1802 //=======================================================================
1803 //function : TotalShapes
1805 //=======================================================================
1806 void TotalShapes(const TopoDS_Shape& aS,
1807 Standard_Integer& aNbS,
1808 BOPCol_MapOfShape& aMS)
1811 TopoDS_Iterator aIt;
1814 for (; aIt.More(); aIt.Next()) {
1815 const TopoDS_Shape& aSx=aIt.Value();
1816 TotalShapes(aSx, aNbS, aMS);
1821 //=======================================================================
1822 //function : ComputeParameter
1824 //=======================================================================
1825 Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
1826 const TopoDS_Edge& aE)
1828 Standard_Real aT1, aT2, aTRet, aTolE2, aD2;
1830 Handle(Geom_Curve) aC3D;
1834 aEE.Orientation(TopAbs_FORWARD);
1838 aTolE2=BRep_Tool::Tolerance(aE);
1839 aTolE2=aTolE2*aTolE2;
1841 aPV=BRep_Tool::Pnt(aV);
1843 aC3D=BRep_Tool::Curve (aEE, aT1, aT2);
1846 aD2=aPC.SquareDistance(aPV);
1852 aD2=aPC.SquareDistance(aPV);
1859 //=======================================================================
1860 //function : BuildBndBoxSolid
1862 //=======================================================================
1863 void BOPDS_DS::BuildBndBoxSolid(const Standard_Integer theIndex,
1866 Standard_Boolean bIsOpenBox, bIsInverted;
1867 Standard_Integer nSh, nFc;
1868 Standard_Real aTolS, aTolFc;
1869 BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1;
1871 const BOPDS_ShapeInfo& aSI=ShapeInfo(theIndex);
1872 const TopoDS_Shape& aS=aSI.Shape();
1873 const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS));
1875 bIsOpenBox=Standard_False;
1878 const BOPCol_ListOfInteger& aLISh=aSI.SubShapes();
1879 aItLI.Initialize(aLISh);
1880 for (; aItLI.More(); aItLI.Next()) {
1882 const BOPDS_ShapeInfo& aSISh=ShapeInfo(nSh);
1883 if (aSISh.ShapeType()!=TopAbs_SHELL) {
1887 const BOPCol_ListOfInteger& aLIFc=aSISh.SubShapes();
1888 aItLI1.Initialize(aLIFc);
1889 for (; aItLI1.More(); aItLI1.Next()) {
1891 const BOPDS_ShapeInfo& aSIFc=ShapeInfo(nFc);
1892 if (aSIFc.ShapeType()!=TopAbs_FACE) {
1896 const Bnd_Box& aBFc=aSIFc.Box();
1900 bIsOpenBox=(aBFc.IsOpenXmin() || aBFc.IsOpenXmax() ||
1901 aBFc.IsOpenYmin() || aBFc.IsOpenYmax() ||
1902 aBFc.IsOpenZmin() || aBFc.IsOpenZmax());
1908 const TopoDS_Face& aFc=*((TopoDS_Face*)&aSIFc.Shape());
1909 aTolFc=BRep_Tool::Tolerance(aFc);
1913 }//for (; aItLI1.More(); aItLI1.Next()) {
1918 const TopoDS_Shell& aSh=*((TopoDS_Shell*)&aSISh.Shape());
1919 bIsOpenBox=BOPTools_AlgoTools::IsOpenShell(aSh);
1923 }//for (; aItLI.More(); aItLI.Next()) {
1929 bIsInverted=BOPTools_AlgoTools::IsInvertedSolid(aSolid);
1936 //=======================================================================
1937 //function : UpdatePaveBlocksWithSDVertices
1939 //=======================================================================
1940 void BOPDS_DS::UpdatePaveBlocksWithSDVertices()
1942 Standard_Integer i, aNbPBP;
1943 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1945 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
1948 for (i = 0; i < aNbPBP; ++i) {
1949 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
1951 aItPB.Initialize(aLPB);
1952 for (; aItPB.More(); aItPB.Next()) {
1953 Handle(BOPDS_PaveBlock)& aPB = aItPB.ChangeValue();
1954 UpdatePaveBlockWithSDVertices(aPB);
1955 }// for (; aItPB.More(); aItPB.Next()) {
1956 }// for (i = 0; i < aNbPBP; ++i) {
1958 //=======================================================================
1959 //function : UpdatePaveBlockWithSDVertices
1961 //=======================================================================
1962 void BOPDS_DS::UpdatePaveBlockWithSDVertices
1963 (const Handle(BOPDS_PaveBlock)& thePB)
1965 Standard_Integer nV1, nV2;
1966 BOPDS_Pave aPave1, aPave2;
1968 aPave1 = thePB->Pave1();
1969 aPave2 = thePB->Pave2();
1971 nV1 = aPave1.Index();
1972 nV2 = aPave2.Index();
1974 if (HasShapeSD(nV1, nV1)) {
1975 aPave1.SetIndex(nV1);
1976 thePB->SetPave1(aPave1);
1979 if (HasShapeSD(nV2, nV2)) {
1980 aPave2.SetIndex(nV2);
1981 thePB->SetPave2(aPave2);
1984 //=======================================================================
1985 //function : UpdateCommonBlockWithSDVertices
1987 //=======================================================================
1988 void BOPDS_DS::UpdateCommonBlockWithSDVertices
1989 (const Handle(BOPDS_CommonBlock)& theCB)
1991 const BOPDS_ListOfPaveBlock& aLPB = theCB->PaveBlocks();
1992 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
1993 for (; aItPB.More(); aItPB.Next()) {
1994 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
1995 UpdatePaveBlockWithSDVertices(aPB);
1998 //=======================================================================
1999 //function : InitPaveBlocksForVertex
2001 //=======================================================================
2002 void BOPDS_DS::InitPaveBlocksForVertex(const Standard_Integer theNV)
2004 Standard_Integer nE;
2005 BOPCol_ListIteratorOfListOfInteger aItLE;
2007 if (myMapVE.IsBound(theNV)) {
2008 const BOPCol_ListOfInteger& aLE=myMapVE.Find(theNV);
2009 aItLE.Initialize(aLE);
2010 for (; aItLE.More(); aItLE.Next()) {
2012 ChangePaveBlocks(nE);
2017 //=======================================================================
2018 //function : ReleasePaveBlocks
2020 //=======================================================================
2021 void BOPDS_DS::ReleasePaveBlocks()
2023 // It is necessary to remove the reference to PaveBlocks for the untouched
2024 // edges to avoid creation of the same images for them.
2025 // Pave blocks for this reference should be cleared.
2026 // This will allow to differ the small edges, for which it is
2027 // impossible to even build a pave block from the normal edges for which the
2028 // pave block have been created, but stayed untouched.
2029 // The small edge, for which no pave blocks have been created,
2030 // should be avoided in the result, thus the reference to empty list
2031 // of pave blocks will stay to mark the edge as Deleted.
2033 BOPDS_VectorOfListOfPaveBlock& aPBP = ChangePaveBlocksPool();
2034 Standard_Integer aNbPBP = aPBP.Extent();
2039 for (Standard_Integer i = 0; i < aNbPBP; ++i) {
2040 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
2041 if (aLPB.Extent() == 1) {
2042 const Handle(BOPDS_PaveBlock)& aPB = aLPB.First();
2043 if (!IsCommonBlock(aPB)) {
2044 Standard_Integer nV1, nV2;
2045 aPB->Indices(nV1, nV2);
2046 if (!IsNewShape(nV1) && !IsNewShape(nV2)) {
2047 // Both vertices are original, thus the PB is untouched.
2048 // Remove reference for the original edge
2049 Standard_Integer nE = aPB->OriginalEdge();
2051 ChangeShapeInfo(nE).SetReference(-1);
2053 // Clear contents of the list