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 Standard_Real aTol, aTolMax(0.);
1069 BOPDS_ListOfPaveBlock aLPBxN;
1071 aItPB.Initialize(aLPBx);
1072 for(; aItPB.More(); ) {
1073 const Handle(BOPDS_PaveBlock)& aPBx=aItPB.Value();
1074 if (aLPBxN.Extent()) {
1075 const Handle(BOPDS_PaveBlock)& aPBCx = aLPBxN.First();
1076 bCoinside = CheckCoincidence(aPBx, aPBCx, theFuzz);
1078 nE = aPBx->OriginalEdge();
1079 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1080 aTol = BRep_Tool::Tolerance(aE);
1082 //pave block with the max tolerance of the original edge
1083 //must be the first in the common block
1084 if (aTolMax < aTol) {
1086 aLPBxN.Prepend(aPBx);
1088 aLPBxN.Append(aPBx);
1090 aLPBx.Remove(aItPB);
1093 }//if (aLPBxN.Extent()) {
1095 nE = aPBx->OriginalEdge();
1096 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1097 aTolMax = BRep_Tool::Tolerance(aE);
1099 aLPBxN.Append(aPBx);
1100 aLPBx.Remove(aItPB);
1104 }//for(; aItPB.More(); ) {
1106 aCBx=new BOPDS_CommonBlock;
1107 aCBx->AddPaveBlocks(aLPBxN);
1108 aCBx->SetFaces(aLF);
1110 aItPB.Initialize(aLPBxN);
1111 for (; aItPB.More(); aItPB.Next()) {
1112 aPB=aItPB.ChangeValue();
1113 SetCommonBlock(aPB, aCBx);
1119 //=======================================================================
1120 // function: RealPaveBlock
1122 //=======================================================================
1123 Handle(BOPDS_PaveBlock) BOPDS_DS::RealPaveBlock
1124 (const Handle(BOPDS_PaveBlock)& thePB) const
1126 if (IsCommonBlock(thePB)) {
1127 const Handle(BOPDS_CommonBlock)& aCB = CommonBlock(thePB);
1128 const Handle(BOPDS_PaveBlock)& aPB = aCB->PaveBlock1();
1134 //=======================================================================
1135 // function: IsCommonBlockOnEdge
1137 //=======================================================================
1138 Standard_Boolean BOPDS_DS::IsCommonBlockOnEdge
1139 (const Handle(BOPDS_PaveBlock)& thePB) const
1141 if (IsCommonBlock(thePB)) {
1142 const Handle(BOPDS_CommonBlock)& aCB = CommonBlock(thePB);
1143 return aCB->PaveBlocks().Extent()>1;
1145 return Standard_False;
1148 //=======================================================================
1149 //function : IsCommonBlock
1151 //=======================================================================
1152 Standard_Boolean BOPDS_DS::IsCommonBlock
1153 (const Handle(BOPDS_PaveBlock)& thePB) const
1155 return myMapPBCB.IsBound(thePB);
1158 //=======================================================================
1159 //function : CommonBlock
1161 //=======================================================================
1162 Handle(BOPDS_CommonBlock) BOPDS_DS::CommonBlock
1163 (const Handle(BOPDS_PaveBlock)& thePB) const
1165 return (IsCommonBlock(thePB) ? myMapPBCB.Find(thePB) : NULL);
1168 //=======================================================================
1169 //function : SetCommonBlock
1171 //=======================================================================
1172 void BOPDS_DS::SetCommonBlock(const Handle(BOPDS_PaveBlock)& thePB,
1173 const Handle(BOPDS_CommonBlock)& theCB)
1175 if (IsCommonBlock(thePB)) {
1176 Handle(BOPDS_CommonBlock)& aCB = myMapPBCB.ChangeFind(thePB);
1180 myMapPBCB.Bind(thePB, theCB);
1188 //=======================================================================
1189 //function : FaceInfoPool
1191 //=======================================================================
1192 const BOPDS_VectorOfFaceInfo& BOPDS_DS::FaceInfoPool()const
1194 return myFaceInfoPool;
1196 //=======================================================================
1197 //function : HasFaceInfo
1199 //=======================================================================
1200 Standard_Boolean BOPDS_DS::HasFaceInfo(const Standard_Integer theI)const
1202 return ShapeInfo(theI).HasReference();
1204 //=======================================================================
1205 //function : FaceInfo
1207 //=======================================================================
1208 const BOPDS_FaceInfo& BOPDS_DS::FaceInfo(const Standard_Integer theI)const
1210 static BOPDS_FaceInfo sFI;
1211 Standard_Integer aRef;
1213 if (HasFaceInfo(theI)) {
1214 aRef=ShapeInfo(theI).Reference();
1215 const BOPDS_FaceInfo& aFI=myFaceInfoPool(aRef);
1220 //=======================================================================
1221 //function : ChangeFaceInfo
1223 //=======================================================================
1224 BOPDS_FaceInfo& BOPDS_DS::ChangeFaceInfo(const Standard_Integer theI)
1226 Standard_Boolean bHasReference;
1227 Standard_Integer aRef;
1228 BOPDS_FaceInfo* pFI;
1230 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1231 bHasReference=aSI.HasReference();
1232 if (!bHasReference) {
1236 aRef=aSI.Reference();
1237 const BOPDS_FaceInfo& aFI=myFaceInfoPool(aRef);
1238 pFI=(BOPDS_FaceInfo*)&aFI;
1241 //=======================================================================
1242 //function : InitFaceInfo
1244 //=======================================================================
1245 void BOPDS_DS::InitFaceInfo(const Standard_Integer theI)
1247 Standard_Integer iRef;
1249 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1250 BOPDS_FaceInfo &aFI=myFaceInfoPool.Append1();
1251 iRef=myFaceInfoPool.Extent()-1;
1252 aSI.SetReference(iRef);
1255 UpdateFaceInfoIn(theI);
1256 UpdateFaceInfoOn(theI);
1258 //=======================================================================
1259 //function : UpdateFaceInfoIn
1261 //=======================================================================
1262 void BOPDS_DS::UpdateFaceInfoIn(const Standard_Integer theI)
1264 Standard_Integer iRef;
1266 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1267 if (aSI.HasReference()) {
1268 iRef=aSI.Reference();
1269 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1271 BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.ChangePaveBlocksIn();
1272 BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
1275 FaceInfoIn(theI, aMPBIn, aMVIn);
1278 //=======================================================================
1279 //function : UpdateFaceInfoOn
1281 //=======================================================================
1282 void BOPDS_DS::UpdateFaceInfoOn(const Standard_Integer theI)
1284 Standard_Integer iRef;
1286 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1287 if (aSI.HasReference()) {
1288 iRef=aSI.Reference();
1289 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1291 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1292 BOPCol_MapOfInteger& aMVOn=aFI.ChangeVerticesOn();
1295 FaceInfoOn(theI, aMPBOn, aMVOn);
1298 //=======================================================================
1299 //function : FaceInfoOn
1301 //=======================================================================
1302 void BOPDS_DS::FaceInfoOn(const Standard_Integer theF,
1303 BOPDS_IndexedMapOfPaveBlock& theMPB,
1304 BOPCol_MapOfInteger& theMI)
1306 Standard_Integer nS, nSD, nV1, nV2;
1307 BOPCol_ListIteratorOfListOfInteger aIt;
1308 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1310 const BOPDS_ShapeInfo& aSI=ShapeInfo(theF);
1311 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
1312 aIt.Initialize(aLI);
1313 for (; aIt.More(); aIt.Next()) {
1315 const BOPDS_ShapeInfo& aSIE=ShapeInfo(nS);
1316 if (aSIE.ShapeType()==TopAbs_EDGE) {
1317 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nS);
1318 aItPB.Initialize(aLPB);
1319 for (; aItPB.More(); aItPB.Next()) {
1320 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
1321 aPB->Indices(nV1, nV2);
1324 Handle(BOPDS_PaveBlock) aPBR=RealPaveBlock(aPB);
1327 }//if (aSIE.ShapeType()==TopAbs_EDGE)
1329 // nE is TopAbs_VERTEX
1330 if (HasShapeSD(nS, nSD)) {
1337 //=======================================================================
1338 //function : FaceInfoIn
1340 //=======================================================================
1341 void BOPDS_DS::FaceInfoIn(const Standard_Integer theF,
1342 BOPDS_IndexedMapOfPaveBlock& theMPB,
1343 BOPCol_MapOfInteger& theMI)
1345 Standard_Integer i, aNbVF, aNbEF, nV, nE, nVSD;
1346 TopoDS_Iterator aItS;
1347 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1349 // 1. Pure internal vertices on the face
1350 const TopoDS_Shape& aF=Shape(theF);
1351 aItS.Initialize(aF);
1352 for (; aItS.More(); aItS.Next()) {
1353 const TopoDS_Shape& aSx=aItS.Value();
1354 if (aSx.ShapeType()==TopAbs_VERTEX){
1356 if (HasShapeSD(nV, nVSD)) {
1364 BOPDS_VectorOfInterfVF& aVFs=InterfVF();
1365 aNbVF=aVFs.Extent();
1366 for (i=0; i<aNbVF; ++i) {
1367 BOPDS_InterfVF& aVF=aVFs(i);
1368 if(aVF.Contains(theF)) {
1369 nV=aVF.OppositeIndex(theF);
1370 if (HasShapeSD(nV, nVSD)) {
1378 BOPDS_VectorOfInterfEF& aEFs=InterfEF();
1379 aNbEF=aEFs.Extent();
1380 for (i=0; i<aNbEF; ++i) {
1381 BOPDS_InterfEF& aEF=aEFs(i);
1382 if(aEF.Contains(theF)) {
1383 if(aEF.HasIndexNew(nV)) {
1387 nE=aEF.OppositeIndex(theF);
1388 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1389 aItPB.Initialize(aLPB);
1390 for (; aItPB.More(); aItPB.Next()) {
1391 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
1392 if (IsCommonBlock(aPB)) {
1393 const Handle(BOPDS_CommonBlock)& aCB=CommonBlock(aPB);
1394 if (aCB->Contains(theF)) {
1395 const Handle(BOPDS_PaveBlock)& aPB1=aCB->PaveBlock1();
1399 }// for (; aItPB.More(); aItPB.Next()) {
1401 }// if(aEF.Contains(theF)) {
1402 }// for (i=0; i<aNbEF; ++i) {
1405 //=======================================================================
1406 //function : RefineFaceInfoOn
1408 //=======================================================================
1409 void BOPDS_DS::RefineFaceInfoOn()
1411 Standard_Integer i, aNb, nF, aNbPB, j;
1412 BOPDS_IndexedMapOfPaveBlock aMPB;
1414 aNb=myFaceInfoPool.Extent();
1415 for (i=0; i<aNb; ++i) {
1416 BOPDS_FaceInfo &aFI=myFaceInfoPool(i);
1418 UpdateFaceInfoOn(nF);
1419 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1422 aMPB.Assign(aMPBOn);
1425 aNbPB=aMPB.Extent();
1426 for (j=1; j<=aNbPB; ++j) {
1427 const Handle(BOPDS_PaveBlock)& aPB=aMPB(j);
1428 if (aPB->HasEdge()) {
1434 //=======================================================================
1435 //function : AloneVertices
1437 //=======================================================================
1438 void BOPDS_DS::AloneVertices(const Standard_Integer theI,
1439 BOPCol_ListOfInteger& theLI)const
1441 if (HasFaceInfo(theI)) {
1443 Standard_Integer i, j, nV1, nV2, nV, aNbPB;
1444 BOPCol_MapIteratorOfMapOfInteger aItMI;
1446 BOPCol_MapOfInteger aMI(100, myAllocator);
1448 const BOPDS_FaceInfo& aFI=FaceInfo(theI);
1450 for (i = 0; i < 2; ++i) {
1451 const BOPDS_IndexedMapOfPaveBlock& aMPB=
1452 (!i) ? aFI.PaveBlocksIn() : aFI.PaveBlocksSc();
1453 aNbPB = aMPB.Extent();
1454 for (j = 1; j <= aNbPB; ++j) {
1455 const Handle(BOPDS_PaveBlock)& aPB = aMPB(j);
1456 aPB->Indices(nV1, nV2);
1462 for (i=0; i<2; ++i) {
1463 const BOPCol_MapOfInteger& aMIV=
1464 (!i) ? aFI.VerticesIn() : aFI.VerticesSc();
1465 aItMI.Initialize(aMIV);
1466 for (; aItMI.More(); aItMI.Next()) {
1477 //=======================================================================
1478 //function : VerticesOnIn
1480 //=======================================================================
1481 void BOPDS_DS::SubShapesOnIn
1482 (const Standard_Integer nF1,
1483 const Standard_Integer nF2,
1484 BOPCol_MapOfInteger& theMVOnIn,
1485 BOPDS_IndexedMapOfPaveBlock& thePBOnIn,
1486 BOPDS_MapOfPaveBlock& theCommonPB)const
1488 Standard_Integer i, j, nV, nV1, nV2, aNbPB;
1489 BOPCol_MapIteratorOfMapOfInteger aIt;
1490 BOPDS_IndexedMapOfPaveBlock pMPB[4];
1492 const BOPDS_FaceInfo& aFI1=FaceInfo(nF1);
1493 const BOPDS_FaceInfo& aFI2=FaceInfo(nF2);
1495 pMPB[0]=aFI1.PaveBlocksOn();
1496 pMPB[1]=aFI1.PaveBlocksIn();
1497 pMPB[2]=aFI2.PaveBlocksOn();
1498 pMPB[3]=aFI2.PaveBlocksIn();
1500 for (i=0; i<4; ++i) {
1501 aNbPB = pMPB[i].Extent();
1502 for (j = 1; j <= aNbPB; ++j) {
1503 const Handle(BOPDS_PaveBlock)& aPB = pMPB[i](j);
1505 aPB->Indices(nV1, nV2);
1509 if (pMPB[2].Contains(aPB) || pMPB[3].Contains(aPB))
1510 theCommonPB.Add(aPB);
1515 const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
1516 const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
1517 const BOPCol_MapOfInteger& aMVOn2=aFI2.VerticesOn();
1518 const BOPCol_MapOfInteger& aMVIn2=aFI2.VerticesIn();
1520 for (i=0; i<2; ++i) {
1521 const BOPCol_MapOfInteger& aMV1=(!i) ? aMVOn1 : aMVIn1;
1522 aIt.Initialize(aMV1);
1523 for (; aIt.More(); aIt.Next()) {
1525 if (aMVOn2.Contains(nV) || aMVIn2.Contains(nV)) {
1531 //=======================================================================
1532 //function : SharedEdges
1534 //=======================================================================
1535 void BOPDS_DS::SharedEdges(const Standard_Integer nF1,
1536 const Standard_Integer nF2,
1537 BOPCol_ListOfInteger& theLI,
1538 const Handle(NCollection_BaseAllocator)& aAllocator)
1540 Standard_Integer nE, nSp;
1541 BOPCol_ListIteratorOfListOfInteger aItLI;
1542 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
1543 BOPCol_MapOfInteger aMI(100, aAllocator);
1545 const BOPDS_ShapeInfo& aSI1=ShapeInfo(nF1);
1546 const BOPCol_ListOfInteger& aLI1=aSI1.SubShapes();
1547 aItLI.Initialize(aLI1);
1548 for (; aItLI.More(); aItLI.Next()) {
1550 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1551 if(aSIE.ShapeType()==TopAbs_EDGE) {
1552 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1553 if (aLPB.IsEmpty()) {
1557 aItLPB.Initialize(aLPB);
1558 for (; aItLPB.More(); aItLPB.Next()) {
1559 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
1567 const BOPDS_ShapeInfo& aSI2=ShapeInfo(nF2);
1568 const BOPCol_ListOfInteger& aLI2=aSI2.SubShapes();
1569 aItLI.Initialize(aLI2);
1570 for (; aItLI.More(); aItLI.Next()) {
1572 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1573 if(aSIE.ShapeType()==TopAbs_EDGE) {
1574 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1575 if (aLPB.IsEmpty()) {
1576 if (aMI.Contains(nE)) {
1581 aItLPB.Initialize(aLPB);
1582 for (; aItLPB.More(); aItLPB.Next()) {
1583 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
1585 if (aMI.Contains(nSp)) {
1594 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1596 // same domain shapes
1598 //=======================================================================
1599 //function : ShapesSD
1601 //=======================================================================
1602 BOPCol_DataMapOfIntegerInteger& BOPDS_DS::ShapesSD()
1606 //=======================================================================
1607 //function : AddShapeSD
1609 //=======================================================================
1610 void BOPDS_DS::AddShapeSD(const Standard_Integer theIndex,
1611 const Standard_Integer theIndexSD)
1613 myShapesSD.Bind(theIndex, theIndexSD);
1615 //=======================================================================
1616 //function : HasShapeSD
1618 //=======================================================================
1619 Standard_Boolean BOPDS_DS::HasShapeSD
1620 (const Standard_Integer theIndex,
1621 Standard_Integer& theIndexSD)const
1623 Standard_Boolean bRet;
1625 bRet=myShapesSD.IsBound(theIndex);
1627 theIndexSD=myShapesSD.Find(theIndex);
1631 //=======================================================================
1634 //=======================================================================
1635 void BOPDS_DS::Dump()const
1637 Standard_Integer i, aNb, aNbSS;
1639 printf(" *** DS ***\n");
1641 printf(" Ranges:%d\n", aNb);
1642 for (i=0; i<aNb; ++i) {
1643 const BOPDS_IndexRange& aR=Range(i);
1648 aNbSS=NbSourceShapes();
1649 printf(" Shapes:%d\n", aNbSS);
1651 for (i=0; i<aNb; ++i) {
1652 const BOPDS_ShapeInfo& aSI=ShapeInfo(i);
1657 printf(" ****** adds\n");
1660 printf(" ******\n");
1663 //=======================================================================
1664 // function: CheckCoincidence
1666 //=======================================================================
1667 Standard_Boolean BOPDS_DS::CheckCoincidence
1668 (const Handle(BOPDS_PaveBlock)& aPB1,
1669 const Handle(BOPDS_PaveBlock)& aPB2,
1670 const Standard_Real theFuzz)
1672 Standard_Boolean bRet;
1673 Standard_Integer nE1, nE2, aNbPoints;
1674 Standard_Real aT11, aT12, aT21, aT22, aT1m, aD, aTol, aT2x;
1677 bRet=Standard_False;
1679 aPB1->Range(aT11, aT12);
1680 aT1m=IntTools_Tools::IntermediatePoint (aT11, aT12);
1681 nE1=aPB1->OriginalEdge();
1682 const TopoDS_Edge& aE1=(*(TopoDS_Edge*)(&Shape(nE1)));
1683 BOPTools_AlgoTools::PointOnEdge(aE1, aT1m, aP1m);
1685 aPB2->Range(aT21, aT22);
1686 nE2=aPB2->OriginalEdge();
1687 const TopoDS_Edge& aE2=(*(TopoDS_Edge*)(&Shape(nE2)));
1690 Handle(Geom_Curve)aC2 = BRep_Tool::Curve (aE2, f, l);
1691 GeomAPI_ProjectPointOnCurve aPPC;
1692 aPPC.Init(aC2, f, l);
1694 aNbPoints=aPPC.NbPoints();
1696 aD=aPPC.LowerDistance();
1698 aTol=BRep_Tool::Tolerance(aE1);
1699 aTol = aTol + BRep_Tool::Tolerance(aE2) + Max(theFuzz, Precision::Confusion());
1701 aT2x=aPPC.LowerDistanceParameter();
1702 if (aT2x>aT21 && aT2x<aT22) {
1709 //=======================================================================
1710 // function: SortPaveBlocks
1712 //=======================================================================
1713 void BOPDS_DS::SortPaveBlocks(const Handle(BOPDS_CommonBlock)& aCB)
1715 Standard_Integer theI;
1716 Standard_Boolean bToSort;
1717 bToSort = IsToSort(aCB, theI);
1722 Standard_Integer i(0);
1723 const BOPDS_ListOfPaveBlock& aLPB = aCB->PaveBlocks();
1724 BOPDS_ListOfPaveBlock aLPBN = aLPB;
1726 Handle(BOPDS_PaveBlock) aPB;
1727 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1729 aIt.Initialize(aLPBN);
1730 for (aIt.Next(); aIt.More(); ) {
1741 aCB->AddPaveBlocks(aLPBN);
1743 //=======================================================================
1744 // function: IsToSort
1746 //=======================================================================
1747 Standard_Boolean BOPDS_DS::IsToSort
1748 (const Handle(BOPDS_CommonBlock)& aCB,
1749 Standard_Integer& theI)
1751 Standard_Boolean bRet;
1752 bRet = Standard_False;
1753 const BOPDS_ListOfPaveBlock& aLPB = aCB->PaveBlocks();
1754 if (aLPB.Extent()==1) {
1758 Standard_Integer nE;
1759 Standard_Real aTolMax, aTol;
1760 Handle(BOPDS_PaveBlock) aPB;
1762 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1765 nE = aPB->OriginalEdge();
1766 aE = (*(TopoDS_Edge *)(&Shape(nE)));
1767 aTolMax = BRep_Tool::Tolerance(aE);
1770 aIt.Initialize(aLPB);
1771 for (aIt.Next(); aIt.More(); aIt.Next()) {
1774 nE = aPB->OriginalEdge();
1775 aE = (*(TopoDS_Edge *)(&Shape(nE)));
1776 aTol = BRep_Tool::Tolerance(aE);
1777 if (aTolMax < aTol) {
1779 bRet = Standard_True;
1785 //=======================================================================
1786 // function: IsSubShape
1788 //=======================================================================
1789 Standard_Boolean BOPDS_DS::IsSubShape
1790 (const Standard_Integer theI1,
1791 const Standard_Integer theI2)
1793 Standard_Boolean bRet;
1794 Standard_Integer nS;
1795 bRet = Standard_False;
1797 BOPCol_ListIteratorOfListOfInteger aItLI;
1799 const BOPDS_ShapeInfo& aSI = ShapeInfo(theI2);
1800 const BOPCol_ListOfInteger& aLI = aSI.SubShapes();
1801 aItLI.Initialize(aLI);
1802 for(;aItLI.More(); aItLI.Next()) {
1805 bRet = Standard_True;
1812 //=======================================================================
1815 //=======================================================================
1816 void BOPDS_DS::Paves(const Standard_Integer theEdge,
1817 BOPDS_ListOfPave& theLP)
1819 Standard_Integer aNb, i;
1820 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1821 BOPDS_MapOfPave aMP;
1823 const BOPDS_ListOfPaveBlock& aLPB = PaveBlocks(theEdge);
1824 aNb = aLPB.Extent() + 1;
1829 BOPDS_VectorOfPave pPaves(1, aNb);
1832 aIt.Initialize(aLPB);
1833 for (; aIt.More(); aIt.Next()) {
1834 const Handle(BOPDS_PaveBlock)& aPB = aIt.Value();
1835 const BOPDS_Pave& aPave1 = aPB->Pave1();
1836 const BOPDS_Pave& aPave2 = aPB->Pave2();
1838 if (aMP.Add(aPave1)){
1843 if (aMP.Add(aPave2)){
1849 Standard_ASSERT_VOID(aNb == aMP.Extent(), "Abnormal number of paves");
1851 std::sort(pPaves.begin(), pPaves.end());
1853 for (i = 1; i <= aNb; ++i) {
1854 theLP.Append(pPaves(i));
1857 //=======================================================================
1858 // function: UpdateTolerance
1860 //=======================================================================
1861 void BOPDS_DS::UpdateEdgeTolerance(const Standard_Integer nE,
1862 const Standard_Real aTol,
1863 const Standard_Real theFuzz)
1865 Standard_Integer nV;
1866 Standard_Real aTolV;
1868 BOPCol_ListIteratorOfListOfInteger aIt;
1870 Standard_Real aTolAdd = Max(theFuzz, Precision::Confusion()) * 0.5;
1872 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1873 aBB.UpdateEdge(aE, aTol);
1874 BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1875 Bnd_Box& aBoxE=aSIE.ChangeBox();
1876 BRepBndLib::Add(aE, aBoxE);
1877 aBoxE.SetGap(aBoxE.GetGap() + aTolAdd);
1879 const BOPCol_ListOfInteger& aLI = aSIE.SubShapes();
1880 aIt.Initialize(aLI);
1881 for (; aIt.More(); aIt.Next()) {
1883 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&Shape(nV);
1884 aTolV = BRep_Tool::Tolerance(aV);
1886 aBB.UpdateVertex(aV, aTol);
1887 BOPDS_ShapeInfo& aSIV = ChangeShapeInfo(nV);
1888 Bnd_Box& aBoxV = aSIV.ChangeBox();
1889 BRepBndLib::Add(aV, aBoxV);
1890 aBoxV.SetGap(aBoxV.GetGap() + aTolAdd);
1894 //=======================================================================
1895 //function : TotalShapes
1897 //=======================================================================
1898 void TotalShapes(const TopoDS_Shape& aS,
1899 Standard_Integer& aNbS,
1900 BOPCol_MapOfShape& aMS)
1903 TopoDS_Iterator aIt;
1906 for (; aIt.More(); aIt.Next()) {
1907 const TopoDS_Shape& aSx=aIt.Value();
1908 TotalShapes(aSx, aNbS, aMS);
1913 //=======================================================================
1914 //function : ComputeParameter
1916 //=======================================================================
1917 Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
1918 const TopoDS_Edge& aE)
1920 Standard_Real aT1, aT2, aTRet, aTolE2, aD2;
1922 Handle(Geom_Curve) aC3D;
1926 aEE.Orientation(TopAbs_FORWARD);
1930 aTolE2=BRep_Tool::Tolerance(aE);
1931 aTolE2=aTolE2*aTolE2;
1933 aPV=BRep_Tool::Pnt(aV);
1935 aC3D=BRep_Tool::Curve (aEE, aT1, aT2);
1938 aD2=aPC.SquareDistance(aPV);
1944 aD2=aPC.SquareDistance(aPV);
1951 //=======================================================================
1952 //function : BuildBndBoxSolid
1954 //=======================================================================
1955 void BOPDS_DS::BuildBndBoxSolid(const Standard_Integer theIndex,
1958 Standard_Boolean bIsOpenBox, bIsInverted;
1959 Standard_Integer nSh, nFc;
1960 Standard_Real aTolS, aTolFc;
1961 BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1;
1963 const BOPDS_ShapeInfo& aSI=ShapeInfo(theIndex);
1964 const TopoDS_Shape& aS=aSI.Shape();
1965 const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS));
1967 bIsOpenBox=Standard_False;
1970 const BOPCol_ListOfInteger& aLISh=aSI.SubShapes();
1971 aItLI.Initialize(aLISh);
1972 for (; aItLI.More(); aItLI.Next()) {
1974 const BOPDS_ShapeInfo& aSISh=ShapeInfo(nSh);
1975 if (aSISh.ShapeType()!=TopAbs_SHELL) {
1979 const BOPCol_ListOfInteger& aLIFc=aSISh.SubShapes();
1980 aItLI1.Initialize(aLIFc);
1981 for (; aItLI1.More(); aItLI1.Next()) {
1983 const BOPDS_ShapeInfo& aSIFc=ShapeInfo(nFc);
1984 if (aSIFc.ShapeType()!=TopAbs_FACE) {
1988 const Bnd_Box& aBFc=aSIFc.Box();
1992 bIsOpenBox=(aBFc.IsOpenXmin() || aBFc.IsOpenXmax() ||
1993 aBFc.IsOpenYmin() || aBFc.IsOpenYmax() ||
1994 aBFc.IsOpenZmin() || aBFc.IsOpenZmax());
2000 const TopoDS_Face& aFc=*((TopoDS_Face*)&aSIFc.Shape());
2001 aTolFc=BRep_Tool::Tolerance(aFc);
2005 }//for (; aItLI1.More(); aItLI1.Next()) {
2010 const TopoDS_Shell& aSh=*((TopoDS_Shell*)&aSISh.Shape());
2011 bIsOpenBox=BOPTools_AlgoTools::IsOpenShell(aSh);
2015 }//for (; aItLI.More(); aItLI.Next()) {
2021 bIsInverted=BOPTools_AlgoTools::IsInvertedSolid(aSolid);
2028 //=======================================================================
2029 //function : UpdatePaveBlocksWithSDVertices
2031 //=======================================================================
2032 void BOPDS_DS::UpdatePaveBlocksWithSDVertices()
2034 Standard_Integer i, aNbPBP;
2035 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
2037 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
2040 for (i = 0; i < aNbPBP; ++i) {
2041 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
2043 aItPB.Initialize(aLPB);
2044 for (; aItPB.More(); aItPB.Next()) {
2045 Handle(BOPDS_PaveBlock)& aPB = aItPB.ChangeValue();
2046 UpdatePaveBlockWithSDVertices(aPB);
2047 }// for (; aItPB.More(); aItPB.Next()) {
2048 }// for (i = 0; i < aNbPBP; ++i) {
2050 //=======================================================================
2051 //function : UpdatePaveBlockWithSDVertices
2053 //=======================================================================
2054 void BOPDS_DS::UpdatePaveBlockWithSDVertices
2055 (const Handle(BOPDS_PaveBlock)& thePB)
2057 Standard_Integer nV1, nV2;
2058 BOPDS_Pave aPave1, aPave2;
2060 aPave1 = thePB->Pave1();
2061 aPave2 = thePB->Pave2();
2063 nV1 = aPave1.Index();
2064 nV2 = aPave2.Index();
2066 if (HasShapeSD(nV1, nV1)) {
2067 aPave1.SetIndex(nV1);
2068 thePB->SetPave1(aPave1);
2071 if (HasShapeSD(nV2, nV2)) {
2072 aPave2.SetIndex(nV2);
2073 thePB->SetPave2(aPave2);
2076 //=======================================================================
2077 //function : UpdateCommonBlockWithSDVertices
2079 //=======================================================================
2080 void BOPDS_DS::UpdateCommonBlockWithSDVertices
2081 (const Handle(BOPDS_CommonBlock)& theCB)
2083 const BOPDS_ListOfPaveBlock& aLPB = theCB->PaveBlocks();
2084 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
2085 for (; aItPB.More(); aItPB.Next()) {
2086 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
2087 UpdatePaveBlockWithSDVertices(aPB);
2090 //=======================================================================
2091 //function : InitPaveBlocksForVertex
2093 //=======================================================================
2094 void BOPDS_DS::InitPaveBlocksForVertex(const Standard_Integer theNV)
2096 Standard_Integer nE;
2097 BOPCol_ListIteratorOfListOfInteger aItLE;
2099 if (myMapVE.IsBound(theNV)) {
2100 const BOPCol_ListOfInteger& aLE=myMapVE.Find(theNV);
2101 aItLE.Initialize(aLE);
2102 for (; aItLE.More(); aItLE.Next()) {
2104 ChangePaveBlocks(nE);
2109 //=======================================================================
2110 //function : ReleasePaveBlocks
2112 //=======================================================================
2113 void BOPDS_DS::ReleasePaveBlocks()
2115 // It is necessary to remove the reference to PaveBlocks for the untouched
2116 // edges to avoid creation of the same images for them.
2117 // Pave blocks for this reference should be cleared.
2118 // This will allow to differ the small edges, for which it is
2119 // impossible to even build a pave block from the normal edges for which the
2120 // pave block have been created, but stayed untouched.
2121 // The small edge, for which no pave blocks have been created,
2122 // should be avoided in the result, thus the reference to empty list
2123 // of pave blocks will stay to mark the edge as Deleted.
2125 BOPDS_VectorOfListOfPaveBlock& aPBP = ChangePaveBlocksPool();
2126 Standard_Integer aNbPBP = aPBP.Extent();
2131 for (Standard_Integer i = 0; i < aNbPBP; ++i) {
2132 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
2133 if (aLPB.Extent() == 1) {
2134 const Handle(BOPDS_PaveBlock)& aPB = aLPB.First();
2135 if (!IsCommonBlock(aPB)) {
2136 Standard_Integer nV1, nV2;
2137 aPB->Indices(nV1, nV2);
2138 if (!IsNewShape(nV1) && !IsNewShape(nV2)) {
2139 // Both vertices are original, thus the PB is untouched.
2140 // Remove reference for the original edge
2141 Standard_Integer nE = aPB->OriginalEdge();
2143 ChangeShapeInfo(nE).SetReference(-1);
2145 // Clear contents of the list