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 <BRepAdaptor_Curve.hxx>
33 #include <BRep_Builder.hxx>
34 #include <BRep_TEdge.hxx>
35 #include <BRep_TFace.hxx>
36 #include <BRep_Tool.hxx>
37 #include <BRep_TVertex.hxx>
38 #include <BRepBndLib.hxx>
39 #include <Geom_Curve.hxx>
40 #include <GeomAPI_ProjectPointOnCurve.hxx>
42 #include <IntTools_Tools.hxx>
43 #include <NCollection_BaseAllocator.hxx>
44 #include <Precision.hxx>
45 #include <Standard_Assert.hxx>
47 #include <TopoDS_Edge.hxx>
48 #include <TopoDS_Face.hxx>
49 #include <TopoDS_Iterator.hxx>
50 #include <TopoDS_Shape.hxx>
51 #include <TopoDS_Vertex.hxx>
52 #include <BOPCol_MapOfShape.hxx>
53 #include <BOPCol_DataMapOfIntegerListOfInteger.hxx>
59 void TotalShapes(const TopoDS_Shape& aS,
60 Standard_Integer& aNbS,
61 BOPCol_MapOfShape& aMS);
64 Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
65 const TopoDS_Edge& aE);
67 //=======================================================================
70 //=======================================================================
73 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
74 myArguments(myAllocator),
75 myRanges(0,myAllocator),
76 myLines(0, myAllocator),
77 myMapShapeIndex(100, myAllocator),
78 myPaveBlocksPool(0,myAllocator),
79 myMapPBCB(100, myAllocator),
80 myFaceInfoPool(0, myAllocator),
81 myShapesSD(100, myAllocator),
82 myMapVE(100, myAllocator),
83 myInterfTB(100, myAllocator),
84 myInterfVV(0, myAllocator),
85 myInterfVE(0, myAllocator),
86 myInterfVF(0, myAllocator),
87 myInterfEE(0, myAllocator),
88 myInterfEF(0, myAllocator),
89 myInterfFF(0, myAllocator),
90 myInterfVZ(0, myAllocator),
91 myInterfEZ(0, myAllocator),
92 myInterfFZ(0, myAllocator),
93 myInterfZZ(0, myAllocator)
98 //=======================================================================
101 //=======================================================================
102 BOPDS_DS::BOPDS_DS(const Handle(NCollection_BaseAllocator)& theAllocator)
104 myAllocator(theAllocator),
105 myArguments(myAllocator),
106 myRanges(0, myAllocator),
107 myLines(0, myAllocator),
108 myMapShapeIndex(100, myAllocator),
109 myPaveBlocksPool(0, myAllocator),
110 myMapPBCB(100, myAllocator),
111 myFaceInfoPool(0, myAllocator),
112 myShapesSD(100, myAllocator),
113 myMapVE(100, myAllocator),
114 myInterfTB(100, myAllocator),
115 myInterfVV(0, myAllocator),
116 myInterfVE(0, myAllocator),
117 myInterfVF(0, myAllocator),
118 myInterfEE(0, myAllocator),
119 myInterfEF(0, myAllocator),
120 myInterfFF(0, myAllocator),
121 myInterfVZ(0, myAllocator),
122 myInterfEZ(0, myAllocator),
123 myInterfFZ(0, myAllocator),
124 myInterfZZ(0, myAllocator)
129 //=======================================================================
132 //=======================================================================
133 BOPDS_DS::~BOPDS_DS()
137 //=======================================================================
140 //=======================================================================
141 void BOPDS_DS::Clear()
149 myMapShapeIndex.Clear();
150 myPaveBlocksPool.Clear();
151 myFaceInfoPool.Clear();
167 //=======================================================================
168 //function : SetArguments
170 //=======================================================================
171 void BOPDS_DS::SetArguments(const BOPCol_ListOfShape& theLS)
175 //=======================================================================
176 //function : Arguments
178 //=======================================================================
179 const BOPCol_ListOfShape& BOPDS_DS::Arguments()const
183 //=======================================================================
184 //function : Allocator
186 //=======================================================================
187 const Handle(NCollection_BaseAllocator)& BOPDS_DS::Allocator()const
192 //=======================================================================
193 //function : NbShapes
195 //=======================================================================
196 Standard_Integer BOPDS_DS::NbShapes()const
198 return myLines.Size();
200 //=======================================================================
201 //function : NbSourceShapes
203 //=======================================================================
204 Standard_Integer BOPDS_DS::NbSourceShapes()const
206 return myNbSourceShapes;
208 //=======================================================================
209 //function : NbRanges
211 //=======================================================================
212 Standard_Integer BOPDS_DS::NbRanges()const
214 return myRanges.Size();
216 //=======================================================================
219 //=======================================================================
220 const BOPDS_IndexRange& BOPDS_DS::Range(const Standard_Integer theI)const
222 return myRanges(theI);
224 //=======================================================================
227 //=======================================================================
228 Standard_Integer BOPDS_DS::Rank(const Standard_Integer theI)const
230 Standard_Integer i, aNb, iErr;
234 for(i=0; i<aNb; ++i) {
235 const BOPDS_IndexRange& aR=Range(i);
236 if (aR.Contains(theI)) {
242 //=======================================================================
243 //function : IsNewShape
245 //=======================================================================
246 Standard_Boolean BOPDS_DS::IsNewShape(const Standard_Integer theI)const
248 return theI>=NbSourceShapes();
250 //=======================================================================
253 //=======================================================================
254 Standard_Integer BOPDS_DS::Append(const BOPDS_ShapeInfo& theSI)
258 myLines.Append1()=theSI;
259 iX=myLines.Extent()-1;
260 myMapShapeIndex.Bind(theSI.Shape(), iX);
264 //=======================================================================
267 //=======================================================================
268 Standard_Integer BOPDS_DS::Append(const TopoDS_Shape& theS)
272 myLines.Append1().SetShape(theS);
273 iX=myLines.Extent()-1;
274 myMapShapeIndex.Bind(theS, iX);
277 //=======================================================================
278 //function : ShapeInfo
280 //=======================================================================
281 const BOPDS_ShapeInfo& BOPDS_DS::ShapeInfo
282 (const Standard_Integer theI)const
284 return myLines(theI);
286 //=======================================================================
287 //function : ChangeShapeInfo
289 //=======================================================================
290 BOPDS_ShapeInfo& BOPDS_DS::ChangeShapeInfo(const Standard_Integer theI)
292 BOPDS_ShapeInfo *pSI;
294 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI);
295 pSI=(BOPDS_ShapeInfo *)&aSI;
298 //=======================================================================
301 //=======================================================================
302 const TopoDS_Shape& BOPDS_DS::Shape(const Standard_Integer theI)const
305 const TopoDS_Shape& aS=ShapeInfo(theI).Shape();
308 //=======================================================================
311 //=======================================================================
312 Standard_Integer BOPDS_DS::Index(const TopoDS_Shape& theS)const
314 Standard_Integer iRet;
317 if (myMapShapeIndex.IsBound(theS)) {
318 iRet=myMapShapeIndex.Find(theS);
322 //=======================================================================
325 //=======================================================================
326 void BOPDS_DS::Init(const Standard_Real theFuzz)
328 Standard_Integer i1, i2, j, aI, aNb, aNbS, aNbE, aNbSx;
329 Standard_Integer n1, n2, n3, nV, nW, nE, aNbF;
330 Standard_Real aTol, aTolAdd;
331 TopAbs_ShapeEnum aTS;
332 TopoDS_Iterator aItS;
333 BOPCol_ListIteratorOfListOfInteger aIt1, aIt2, aIt3;
334 BOPCol_ListIteratorOfListOfShape aIt;
336 Handle(NCollection_BaseAllocator) aAllocator;
337 BOPCol_MapOfShape aMS;
339 // 1 Append Source Shapes
340 aNb=myArguments.Extent();
345 myRanges.SetIncrement(aNb);
348 aIt.Initialize(myArguments);
349 for (; aIt.More(); aIt.Next()) {
350 const TopoDS_Shape& aSx=aIt.Value();
353 TotalShapes(aSx, aNbSx, aMS);
359 myLines.SetIncrement(2*aNbS);
360 //-----------------------------------------------------scope_1 f
362 NCollection_BaseAllocator::CommonBaseAllocator();
367 aIt.Initialize(myArguments);
368 for (; aIt.More(); aIt.Next()) {
369 const TopoDS_Shape& aS=aIt.Value();
370 if (myMapShapeIndex.IsBound(aS)) {
378 aR.SetIndices(i1, i2);
383 aTolAdd = Max(theFuzz, Precision::Confusion()) * 0.5;
384 myNbSourceShapes = NbShapes();
389 for (j=0; j<myNbSourceShapes; ++j) {
390 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
392 const TopoDS_Shape& aS=aSI.Shape();
396 if (aTS==TopAbs_VERTEX) {
397 Bnd_Box& aBox=aSI.ChangeBox();
398 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aS);
399 const gp_Pnt& aP=BRep_Tool::Pnt(aV);
400 aTol = BRep_Tool::Tolerance(aV);
401 aBox.SetGap(aTol + aTolAdd);
407 for (j=0; j<myNbSourceShapes; ++j) {
408 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
411 if (aTS==TopAbs_EDGE) {
412 const TopoDS_Shape& aS=aSI.Shape();
413 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aS);
414 aTol = BRep_Tool::Tolerance(aE);
416 if (!BRep_Tool::Degenerated(aE)) {
417 Standard_Boolean bInf1, bInf2;
418 Standard_Integer aIx;
419 Standard_Real aT1, aT2;
421 Handle(Geom_Curve) aC3D;
425 BOPDS_ShapeInfo aSIx;
427 BOPCol_ListOfInteger& aLI=aSI.ChangeSubShapes();
430 aEx.Orientation(TopAbs_FORWARD);
432 aC3D=BRep_Tool::Curve (aEx, aT1, aT2);
433 bInf1=Precision::IsNegativeInfinite(aT1);
434 bInf2=Precision::IsPositiveInfinite(aT2);
438 aBB.MakeVertex(aVx, aPx, aTol);
439 aVx.Orientation(TopAbs_FORWARD);
442 aSIx.SetShapeType(TopAbs_VERTEX);
443 aSIx.SetFlag(1); //infinite flag
450 aBB.MakeVertex(aVx, aPx, aTol);
451 aVx.Orientation(TopAbs_REVERSED);
454 aSIx.SetShapeType(TopAbs_VERTEX);
455 aSIx.SetFlag(1);//infinite flag
465 Bnd_Box& aBox=aSI.ChangeBox();
466 BRepBndLib::Add(aE, aBox);
468 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
469 aIt1.Initialize(aLV);
470 for (; aIt1.More(); aIt1.Next()) {
472 BOPDS_ShapeInfo& aSIV=ChangeShapeInfo(nV);
473 Bnd_Box& aBx=aSIV.ChangeBox();
476 aBox.SetGap(aBox.GetGap() + aTolAdd);
481 BOPCol_MapOfInteger aMI(100, aAllocator);
482 BOPCol_MapIteratorOfMapOfInteger aItMI;
485 for (j=0; j<myNbSourceShapes; ++j) {
486 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
489 if (aTS==TopAbs_FACE) {
490 const TopoDS_Shape& aS=aSI.Shape();
492 Bnd_Box& aBox=aSI.ChangeBox();
493 BRepBndLib::Add(aS, aBox);
495 BOPCol_ListOfInteger& aLW=aSI.ChangeSubShapes();
496 aIt1.Initialize(aLW);
497 for (; aIt1.More(); aIt1.Next()) {
499 BOPDS_ShapeInfo& aSIW=ChangeShapeInfo(nW);
501 const BOPCol_ListOfInteger& aLE=aSIW.SubShapes();
502 aIt2.Initialize(aLE);
503 for (; aIt2.More(); aIt2.Next()) {
505 BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
506 Bnd_Box& aBx=aSIE.ChangeBox();
510 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aSIE.Shape());
511 if (BRep_Tool::Degenerated(aE)) {
515 const BOPCol_ListOfInteger& aLV=aSIE.SubShapes();
516 aIt3.Initialize(aLV);
517 for (; aIt3.More(); aIt3.Next()) {
522 }//for (; aIt1.More(); aIt1.Next()) {
524 // pure internal vertices on the face
526 for (; aItS.More(); aItS.Next()) {
527 const TopoDS_Shape& aSx=aItS.Value();
528 if (aSx.ShapeType()==TopAbs_VERTEX){
535 // For a Face: change wires for BRep sub-shapes
537 aItMI.Initialize(aMI);
538 for (; aItMI.More(); aItMI.Next()) {
543 aBox.SetGap(aBox.GetGap() + aTolAdd);
545 }//if (aTS==TopAbs_FACE) {
546 }//for (j=0; j<myNbSourceShapes; ++j) {
549 for (j=0; j<myNbSourceShapes; ++j) {
550 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
553 if (aTS!=TopAbs_SOLID) {
556 Bnd_Box& aBox=aSI.ChangeBox();
557 BuildBndBoxSolid(j, aBox);
560 // update sub-shapes by BRep comprising ones
562 BOPCol_ListOfInteger& aLI1=aSI.ChangeSubShapes();
564 aIt1.Initialize(aLI1);
565 for (; aIt1.More(); aIt1.Next()) {
567 BOPDS_ShapeInfo& aSI1=ChangeShapeInfo(n1);
568 if (aSI1.ShapeType()!=TopAbs_SHELL) {
572 const BOPCol_ListOfInteger& aLI2=aSI1.SubShapes();
573 aIt2.Initialize(aLI2);
574 for (; aIt2.More(); aIt2.Next()) {
576 BOPDS_ShapeInfo& aSI2=ChangeShapeInfo(n2);
577 if (aSI2.ShapeType()!=TopAbs_FACE) {
583 const BOPCol_ListOfInteger& aLI3=aSI2.SubShapes();
584 aIt3.Initialize(aLI3);
585 for (; aIt3.More(); aIt3.Next()) {
593 aItMI.Initialize(aMI);
594 for (; aItMI.More(); aItMI.Next()) {
599 }//for (j=0; j<myNbSourceShapes; ++j) {
602 //-----------------------------------------------------
604 for (nE=0; nE<myNbSourceShapes; ++nE) {
605 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(nE);
606 if (aSI.ShapeType()!=TopAbs_EDGE) {
610 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
611 aIt1.Initialize(aLV);
612 for (; aIt1.More(); aIt1.Next()) {
614 if (myMapVE.IsBound(nV)) {
615 BOPCol_ListOfInteger& aLE=myMapVE.ChangeFind(nV);
619 BOPCol_ListOfInteger aLE(myAllocator);
622 myMapVE.Bind(nV, aLE);
627 BOPCol_DataMapIteratorOfDataMapOfIntegerListOfInteger aItDMILI;
628 aItDMILI.Initialize(myMapVE);
629 for(; aItDMILI.More(); aItDMILI.Next()) {
630 BOPCol_MapOfInteger aMFence;
631 BOPCol_ListOfInteger aLEx;
634 BOPCol_ListOfInteger& aLE=aItDMILI.ChangeValue();
635 aIt1.Initialize(aLE);
636 for (; aIt1.More(); aIt1.Next()) {
638 if(aMFence.Add(nE)) {
644 aIt1.Initialize(aLEx);
645 for (; aIt1.More(); aIt1.Next()) {
650 //-----------------------------------------------------scope_1 t
651 // 3 myPaveBlocksPool
653 myPaveBlocksPool.SetIncrement(aNbE);
654 myFaceInfoPool.SetIncrement(aNbF);
656 //=======================================================================
657 //function : InitShape
659 //=======================================================================
660 void BOPDS_DS::InitShape
661 (const Standard_Integer aI,
662 const TopoDS_Shape& aS)
664 Standard_Integer aIx;
666 BOPCol_ListIteratorOfListOfInteger aIt1;
668 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(aI);
669 aSI.SetShapeType(aS.ShapeType());
670 BOPCol_ListOfInteger& aLI=aSI.ChangeSubShapes();
672 BOPCol_MapOfInteger aM;
674 aIt1.Initialize(aLI);
675 for (; aIt1.More(); aIt1.Next()) {
676 aM.Add(aIt1.Value());
680 for (; aIt.More(); aIt.Next()) {
681 const TopoDS_Shape& aSx=aIt.Value();
682 const Standard_Integer* pIx = myMapShapeIndex.Seek(aSx);
683 aIx = (pIx ? *pIx : Append(aSx));
693 //=======================================================================
694 //function : HasInterf
696 //=======================================================================
697 Standard_Boolean BOPDS_DS::HasInterf(const Standard_Integer theI) const
699 Standard_Integer n1, n2;
700 Standard_Boolean bRet;
701 BOPDS_MapIteratorOfMapOfPair aIt;
703 bRet = Standard_False;
705 aIt.Initialize(myInterfTB);
706 for (; aIt.More(); aIt.Next()) {
707 const BOPDS_Pair& aPK = aIt.Value();
709 if (n1 == theI || n2 == theI) {
710 bRet = Standard_True;
717 //=======================================================================
718 //function : HasInterfShapeSubShapes
720 //=======================================================================
721 Standard_Boolean BOPDS_DS::HasInterfShapeSubShapes
722 (const Standard_Integer theI1,
723 const Standard_Integer theI2,
724 const Standard_Boolean theFlag)const
726 Standard_Boolean bRet;
728 BOPCol_ListIteratorOfListOfInteger aIt;
729 bRet = Standard_False;
731 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI2);
732 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
734 for (; aIt.More(); aIt.Next()) {
736 bRet=HasInterf(theI1, n2);
750 //=======================================================================
751 //function : HasInterfSubShapes
753 //=======================================================================
754 Standard_Boolean BOPDS_DS::HasInterfSubShapes
755 (const Standard_Integer theI1,
756 const Standard_Integer theI2)const
758 Standard_Boolean bRet;
760 BOPCol_ListIteratorOfListOfInteger aIt;
761 bRet = Standard_False;
763 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI1);
764 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
766 for (; aIt.More(); aIt.Next()) {
768 bRet=HasInterfShapeSubShapes(n1, theI2);
777 //=======================================================================
778 //function : PaveBlocksPool
780 //=======================================================================
781 const BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::PaveBlocksPool()const
783 return myPaveBlocksPool;
785 //=======================================================================
786 //function : ChangePaveBlocksPool
788 //=======================================================================
789 BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::ChangePaveBlocksPool()
791 return myPaveBlocksPool;
793 //=======================================================================
794 //function : HasPaveBlocks
796 //=======================================================================
797 Standard_Boolean BOPDS_DS::HasPaveBlocks(const Standard_Integer theI)const
799 return ShapeInfo(theI).HasReference();
801 //=======================================================================
802 //function : PaveBlocks
804 //=======================================================================
805 const BOPDS_ListOfPaveBlock& BOPDS_DS::PaveBlocks
806 (const Standard_Integer theI)const
808 static BOPDS_ListOfPaveBlock sLPB;
809 Standard_Integer aRef;
811 if (HasPaveBlocks(theI)) {
812 aRef=ShapeInfo(theI).Reference();
813 const BOPDS_ListOfPaveBlock& aLPB=myPaveBlocksPool(aRef);
819 //=======================================================================
820 //function : ChangePaveBlocks
822 //=======================================================================
823 BOPDS_ListOfPaveBlock& BOPDS_DS::ChangePaveBlocks
824 (const Standard_Integer theI)
826 Standard_Boolean bHasReference;
827 Standard_Integer aRef;
829 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
830 bHasReference=aSI.HasReference();
831 if (!bHasReference) {
832 InitPaveBlocks(theI);
835 aRef=aSI.Reference();
836 return myPaveBlocksPool(aRef);
838 //=======================================================================
839 //function : InitPaveBlocks
841 //=======================================================================
842 void BOPDS_DS::InitPaveBlocks(const Standard_Integer theI)
844 Standard_Integer nV=0, iRef, aNbV, nVSD;
846 TopAbs_Orientation aOrE;
848 BOPCol_ListIteratorOfListOfInteger aIt;
850 Handle(BOPDS_PaveBlock) aPB;
852 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
853 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aSI.Shape());
854 aOrE=aE.Orientation();
856 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
862 aPB=new BOPDS_PaveBlock;
863 aPB->SetOriginalEdge(theI);
865 if (aOrE!=TopAbs_INTERNAL) {
867 for (; aIt.More(); aIt.Next()) {
870 const BOPDS_ShapeInfo& aSIV=ShapeInfo(nV);
871 aV=*(TopoDS_Vertex*)(&aSIV.Shape());
872 if (aSIV.HasFlag()) {
873 aT=ComputeParameter(aV, aE);
876 aT=BRep_Tool::Parameter(aV, aE);
879 if (HasShapeSD(nV, nVSD)) {
883 aPave.SetParameter(aT);
885 // for a degenerated edge append pave unconditionally
886 aPB->AppendExtPave1(aPave);
888 aPB->AppendExtPave(aPave);
893 aT=BRep_Tool::Parameter(aV, aE);
895 aPave.SetParameter(aT);
896 aPB->AppendExtPave1(aPave);
901 TopoDS_Iterator aItE;
903 aItE.Initialize(aE, Standard_False, Standard_True);
904 for (; aItE.More(); aItE.Next()) {
905 aV=*((TopoDS_Vertex*)&aItE.Value());
908 const BOPDS_ShapeInfo& aSIV=ShapeInfo(nV);
909 if (aSIV.HasFlag()) {
910 aT=ComputeParameter(aV, aE);
913 aT=BRep_Tool::Parameter(aV, aE);
916 if (HasShapeSD(nV, nVSD)) {
920 aPave.SetParameter(aT);
921 aPB->AppendExtPave1(aPave);
925 BOPDS_ListOfPaveBlock &aLPB=myPaveBlocksPool.Append1();
926 iRef=myPaveBlocksPool.Extent()-1;
928 aPB->Update(aLPB, Standard_False);
929 aSI.SetReference(iRef);
931 //=======================================================================
932 //function : UpdatePaveBlocks
934 //=======================================================================
935 void BOPDS_DS::UpdatePaveBlocks()
937 Standard_Integer i, aNbPBP;
938 BOPDS_ListOfPaveBlock aLPBN(myAllocator);
939 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
941 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
944 for (i=0; i<aNbPBP; ++i) {
945 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
947 aItPB.Initialize(aLPB);
948 for (; aItPB.More();) {
949 Handle(BOPDS_PaveBlock)& aPB=aItPB.ChangeValue();
951 if (!aPB->IsToUpdate()) {
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)) {
1368 if (HasShapeSD(nV, nVSD)) {
1374 nE=aEF.OppositeIndex(theF);
1375 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1376 aItPB.Initialize(aLPB);
1377 for (; aItPB.More(); aItPB.Next()) {
1378 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
1379 if (IsCommonBlock(aPB)) {
1380 const Handle(BOPDS_CommonBlock)& aCB=CommonBlock(aPB);
1381 if (aCB->Contains(theF)) {
1382 const Handle(BOPDS_PaveBlock)& aPB1=aCB->PaveBlock1();
1386 }// for (; aItPB.More(); aItPB.Next()) {
1388 }// if(aEF.Contains(theF)) {
1389 }// for (i=0; i<aNbEF; ++i) {
1392 //=======================================================================
1393 //function : RefineFaceInfoOn
1395 //=======================================================================
1396 void BOPDS_DS::RefineFaceInfoOn()
1398 Standard_Integer i, aNb, nF, aNbPB, j;
1399 BOPDS_IndexedMapOfPaveBlock aMPB;
1401 aNb=myFaceInfoPool.Extent();
1402 for (i=0; i<aNb; ++i) {
1403 BOPDS_FaceInfo &aFI=myFaceInfoPool(i);
1405 UpdateFaceInfoOn(nF);
1406 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1409 aMPB.Assign(aMPBOn);
1412 aNbPB=aMPB.Extent();
1413 for (j=1; j<=aNbPB; ++j) {
1414 const Handle(BOPDS_PaveBlock)& aPB=aMPB(j);
1415 if (aPB->HasEdge()) {
1421 //=======================================================================
1422 //function : AloneVertices
1424 //=======================================================================
1425 void BOPDS_DS::AloneVertices(const Standard_Integer theI,
1426 BOPCol_ListOfInteger& theLI)const
1428 if (HasFaceInfo(theI)) {
1430 Standard_Integer i, j, nV1, nV2, nV, aNbPB;
1431 BOPCol_MapIteratorOfMapOfInteger aItMI;
1433 BOPCol_MapOfInteger aMI(100, myAllocator);
1435 const BOPDS_FaceInfo& aFI=FaceInfo(theI);
1437 for (i = 0; i < 2; ++i) {
1438 const BOPDS_IndexedMapOfPaveBlock& aMPB=
1439 (!i) ? aFI.PaveBlocksIn() : aFI.PaveBlocksSc();
1440 aNbPB = aMPB.Extent();
1441 for (j = 1; j <= aNbPB; ++j) {
1442 const Handle(BOPDS_PaveBlock)& aPB = aMPB(j);
1443 aPB->Indices(nV1, nV2);
1449 for (i=0; i<2; ++i) {
1450 const BOPCol_MapOfInteger& aMIV=
1451 (!i) ? aFI.VerticesIn() : aFI.VerticesSc();
1452 aItMI.Initialize(aMIV);
1453 for (; aItMI.More(); aItMI.Next()) {
1464 //=======================================================================
1465 //function : VerticesOnIn
1467 //=======================================================================
1468 void BOPDS_DS::SubShapesOnIn
1469 (const Standard_Integer nF1,
1470 const Standard_Integer nF2,
1471 BOPCol_MapOfInteger& theMVOnIn,
1472 BOPDS_IndexedMapOfPaveBlock& thePBOnIn,
1473 BOPDS_MapOfPaveBlock& theCommonPB)const
1475 Standard_Integer i, j, nV, nV1, nV2, aNbPB;
1476 BOPCol_MapIteratorOfMapOfInteger aIt;
1477 BOPDS_IndexedMapOfPaveBlock pMPB[4];
1479 const BOPDS_FaceInfo& aFI1=FaceInfo(nF1);
1480 const BOPDS_FaceInfo& aFI2=FaceInfo(nF2);
1482 pMPB[0]=aFI1.PaveBlocksOn();
1483 pMPB[1]=aFI1.PaveBlocksIn();
1484 pMPB[2]=aFI2.PaveBlocksOn();
1485 pMPB[3]=aFI2.PaveBlocksIn();
1487 for (i=0; i<4; ++i) {
1488 aNbPB = pMPB[i].Extent();
1489 for (j = 1; j <= aNbPB; ++j) {
1490 const Handle(BOPDS_PaveBlock)& aPB = pMPB[i](j);
1492 aPB->Indices(nV1, nV2);
1496 if (pMPB[2].Contains(aPB) || pMPB[3].Contains(aPB))
1497 theCommonPB.Add(aPB);
1502 const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
1503 const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
1504 const BOPCol_MapOfInteger& aMVOn2=aFI2.VerticesOn();
1505 const BOPCol_MapOfInteger& aMVIn2=aFI2.VerticesIn();
1507 for (i=0; i<2; ++i) {
1508 const BOPCol_MapOfInteger& aMV1=(!i) ? aMVOn1 : aMVIn1;
1509 aIt.Initialize(aMV1);
1510 for (; aIt.More(); aIt.Next()) {
1512 if (aMVOn2.Contains(nV) || aMVIn2.Contains(nV)) {
1518 //=======================================================================
1519 //function : SharedEdges
1521 //=======================================================================
1522 void BOPDS_DS::SharedEdges(const Standard_Integer nF1,
1523 const Standard_Integer nF2,
1524 BOPCol_ListOfInteger& theLI,
1525 const Handle(NCollection_BaseAllocator)& aAllocator)
1527 Standard_Integer nE, nSp;
1528 BOPCol_ListIteratorOfListOfInteger aItLI;
1529 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
1530 BOPCol_MapOfInteger aMI(100, aAllocator);
1532 const BOPDS_ShapeInfo& aSI1=ShapeInfo(nF1);
1533 const BOPCol_ListOfInteger& aLI1=aSI1.SubShapes();
1534 aItLI.Initialize(aLI1);
1535 for (; aItLI.More(); aItLI.Next()) {
1537 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1538 if(aSIE.ShapeType()==TopAbs_EDGE) {
1539 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1540 if (aLPB.IsEmpty()) {
1544 aItLPB.Initialize(aLPB);
1545 for (; aItLPB.More(); aItLPB.Next()) {
1546 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
1554 const BOPDS_ShapeInfo& aSI2=ShapeInfo(nF2);
1555 const BOPCol_ListOfInteger& aLI2=aSI2.SubShapes();
1556 aItLI.Initialize(aLI2);
1557 for (; aItLI.More(); aItLI.Next()) {
1559 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1560 if(aSIE.ShapeType()==TopAbs_EDGE) {
1561 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1562 if (aLPB.IsEmpty()) {
1563 if (aMI.Contains(nE)) {
1568 aItLPB.Initialize(aLPB);
1569 for (; aItLPB.More(); aItLPB.Next()) {
1570 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
1572 if (aMI.Contains(nSp)) {
1581 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1583 // same domain shapes
1585 //=======================================================================
1586 //function : ShapesSD
1588 //=======================================================================
1589 BOPCol_DataMapOfIntegerInteger& BOPDS_DS::ShapesSD()
1593 //=======================================================================
1594 //function : AddShapeSD
1596 //=======================================================================
1597 void BOPDS_DS::AddShapeSD(const Standard_Integer theIndex,
1598 const Standard_Integer theIndexSD)
1600 if (theIndex != theIndexSD)
1601 myShapesSD.Bind(theIndex, theIndexSD);
1603 //=======================================================================
1604 //function : HasShapeSD
1606 //=======================================================================
1607 Standard_Boolean BOPDS_DS::HasShapeSD
1608 (const Standard_Integer theIndex,
1609 Standard_Integer& theIndexSD)const
1611 Standard_Boolean bHasSD = Standard_False;
1612 const Standard_Integer *pSD = myShapesSD.Seek(theIndex);
1615 bHasSD = Standard_True;
1616 pSD = myShapesSD.Seek(theIndexSD);
1620 //=======================================================================
1623 //=======================================================================
1624 void BOPDS_DS::Dump()const
1626 Standard_Integer i, aNb, aNbSS;
1628 printf(" *** DS ***\n");
1630 printf(" Ranges:%d\n", aNb);
1631 for (i=0; i<aNb; ++i) {
1632 const BOPDS_IndexRange& aR=Range(i);
1637 aNbSS=NbSourceShapes();
1638 printf(" Shapes:%d\n", aNbSS);
1640 for (i=0; i<aNb; ++i) {
1641 const BOPDS_ShapeInfo& aSI=ShapeInfo(i);
1646 printf(" ****** adds\n");
1649 printf(" ******\n");
1652 //=======================================================================
1653 // function: CheckCoincidence
1655 //=======================================================================
1656 Standard_Boolean BOPDS_DS::CheckCoincidence
1657 (const Handle(BOPDS_PaveBlock)& aPB1,
1658 const Handle(BOPDS_PaveBlock)& aPB2,
1659 const Standard_Real theFuzz)
1661 Standard_Boolean bRet;
1662 Standard_Integer nE1, nE2, aNbPoints;
1663 Standard_Real aT11, aT12, aT21, aT22, aT1m, aD, aTol, aT2x;
1666 bRet=Standard_False;
1668 aPB1->Range(aT11, aT12);
1669 aT1m=IntTools_Tools::IntermediatePoint (aT11, aT12);
1670 nE1=aPB1->OriginalEdge();
1671 const TopoDS_Edge& aE1=(*(TopoDS_Edge*)(&Shape(nE1)));
1672 BOPTools_AlgoTools::PointOnEdge(aE1, aT1m, aP1m);
1674 aPB2->Range(aT21, aT22);
1675 nE2=aPB2->OriginalEdge();
1676 const TopoDS_Edge& aE2=(*(TopoDS_Edge*)(&Shape(nE2)));
1679 Handle(Geom_Curve)aC2 = BRep_Tool::Curve (aE2, f, l);
1680 GeomAPI_ProjectPointOnCurve aPPC;
1681 aPPC.Init(aC2, f, l);
1683 aNbPoints=aPPC.NbPoints();
1685 aD=aPPC.LowerDistance();
1687 aTol = BRep_Tool::MaxTolerance(aE1, TopAbs_VERTEX);
1688 aTol = aTol + BRep_Tool::MaxTolerance(aE2, TopAbs_VERTEX) + Max(theFuzz, Precision::Confusion());
1690 aT2x=aPPC.LowerDistanceParameter();
1691 if (aT2x>aT21 && aT2x<aT22) {
1698 //=======================================================================
1699 // function: IsSubShape
1701 //=======================================================================
1702 Standard_Boolean BOPDS_DS::IsSubShape
1703 (const Standard_Integer theI1,
1704 const Standard_Integer theI2)
1706 Standard_Boolean bRet;
1707 Standard_Integer nS;
1708 bRet = Standard_False;
1710 BOPCol_ListIteratorOfListOfInteger aItLI;
1712 const BOPDS_ShapeInfo& aSI = ShapeInfo(theI2);
1713 const BOPCol_ListOfInteger& aLI = aSI.SubShapes();
1714 aItLI.Initialize(aLI);
1715 for(;aItLI.More(); aItLI.Next()) {
1718 bRet = Standard_True;
1725 //=======================================================================
1728 //=======================================================================
1729 void BOPDS_DS::Paves(const Standard_Integer theEdge,
1730 BOPDS_ListOfPave& theLP)
1732 Standard_Integer aNb, i;
1733 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1734 BOPDS_MapOfPave aMP;
1736 const BOPDS_ListOfPaveBlock& aLPB = PaveBlocks(theEdge);
1737 aNb = aLPB.Extent() + 1;
1742 BOPDS_VectorOfPave pPaves(1, aNb);
1745 aIt.Initialize(aLPB);
1746 for (; aIt.More(); aIt.Next()) {
1747 const Handle(BOPDS_PaveBlock)& aPB = aIt.Value();
1748 const BOPDS_Pave& aPave1 = aPB->Pave1();
1749 const BOPDS_Pave& aPave2 = aPB->Pave2();
1751 if (aMP.Add(aPave1)){
1756 if (aMP.Add(aPave2)){
1762 Standard_ASSERT_VOID(aNb == aMP.Extent(), "Abnormal number of paves");
1764 std::sort(pPaves.begin(), pPaves.end());
1766 for (i = 1; i <= aNb; ++i) {
1767 theLP.Append(pPaves(i));
1770 //=======================================================================
1771 // function: UpdateTolerance
1773 //=======================================================================
1774 void BOPDS_DS::UpdateEdgeTolerance(const Standard_Integer nE,
1775 const Standard_Real aTol,
1776 const Standard_Real theFuzz)
1778 Standard_Integer nV;
1779 Standard_Real aTolV;
1781 BOPCol_ListIteratorOfListOfInteger aIt;
1783 Standard_Real aTolAdd = Max(theFuzz, Precision::Confusion()) * 0.5;
1785 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1786 aBB.UpdateEdge(aE, aTol);
1787 BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1788 Bnd_Box& aBoxE=aSIE.ChangeBox();
1789 BRepBndLib::Add(aE, aBoxE);
1790 aBoxE.SetGap(aBoxE.GetGap() + aTolAdd);
1792 const BOPCol_ListOfInteger& aLI = aSIE.SubShapes();
1793 aIt.Initialize(aLI);
1794 for (; aIt.More(); aIt.Next()) {
1796 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&Shape(nV);
1797 aTolV = BRep_Tool::Tolerance(aV);
1799 aBB.UpdateVertex(aV, aTol);
1800 BOPDS_ShapeInfo& aSIV = ChangeShapeInfo(nV);
1801 Bnd_Box& aBoxV = aSIV.ChangeBox();
1802 BRepBndLib::Add(aV, aBoxV);
1803 aBoxV.SetGap(aBoxV.GetGap() + aTolAdd);
1807 //=======================================================================
1808 //function : TotalShapes
1810 //=======================================================================
1811 void TotalShapes(const TopoDS_Shape& aS,
1812 Standard_Integer& aNbS,
1813 BOPCol_MapOfShape& aMS)
1816 TopoDS_Iterator aIt;
1819 for (; aIt.More(); aIt.Next()) {
1820 const TopoDS_Shape& aSx=aIt.Value();
1821 TotalShapes(aSx, aNbS, aMS);
1826 //=======================================================================
1827 //function : ComputeParameter
1829 //=======================================================================
1830 Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
1831 const TopoDS_Edge& aE)
1833 Standard_Real aT1, aT2, aTRet, aTolE2, aD2;
1835 Handle(Geom_Curve) aC3D;
1839 aEE.Orientation(TopAbs_FORWARD);
1843 aTolE2=BRep_Tool::Tolerance(aE);
1844 aTolE2=aTolE2*aTolE2;
1846 aPV=BRep_Tool::Pnt(aV);
1848 aC3D=BRep_Tool::Curve (aEE, aT1, aT2);
1851 aD2=aPC.SquareDistance(aPV);
1857 aD2=aPC.SquareDistance(aPV);
1864 //=======================================================================
1865 //function : BuildBndBoxSolid
1867 //=======================================================================
1868 void BOPDS_DS::BuildBndBoxSolid(const Standard_Integer theIndex,
1871 Standard_Boolean bIsOpenBox, bIsInverted;
1872 Standard_Integer nSh, nFc;
1873 Standard_Real aTolS, aTolFc;
1874 BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1;
1876 const BOPDS_ShapeInfo& aSI=ShapeInfo(theIndex);
1877 const TopoDS_Shape& aS=aSI.Shape();
1878 const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS));
1880 bIsOpenBox=Standard_False;
1883 const BOPCol_ListOfInteger& aLISh=aSI.SubShapes();
1884 aItLI.Initialize(aLISh);
1885 for (; aItLI.More(); aItLI.Next()) {
1887 const BOPDS_ShapeInfo& aSISh=ShapeInfo(nSh);
1888 if (aSISh.ShapeType()!=TopAbs_SHELL) {
1892 const BOPCol_ListOfInteger& aLIFc=aSISh.SubShapes();
1893 aItLI1.Initialize(aLIFc);
1894 for (; aItLI1.More(); aItLI1.Next()) {
1896 const BOPDS_ShapeInfo& aSIFc=ShapeInfo(nFc);
1897 if (aSIFc.ShapeType()!=TopAbs_FACE) {
1901 const Bnd_Box& aBFc=aSIFc.Box();
1905 bIsOpenBox=(aBFc.IsOpenXmin() || aBFc.IsOpenXmax() ||
1906 aBFc.IsOpenYmin() || aBFc.IsOpenYmax() ||
1907 aBFc.IsOpenZmin() || aBFc.IsOpenZmax());
1913 const TopoDS_Face& aFc=*((TopoDS_Face*)&aSIFc.Shape());
1914 aTolFc=BRep_Tool::Tolerance(aFc);
1918 }//for (; aItLI1.More(); aItLI1.Next()) {
1923 const TopoDS_Shell& aSh=*((TopoDS_Shell*)&aSISh.Shape());
1924 bIsOpenBox=BOPTools_AlgoTools::IsOpenShell(aSh);
1928 }//for (; aItLI.More(); aItLI.Next()) {
1934 bIsInverted=BOPTools_AlgoTools::IsInvertedSolid(aSolid);
1941 //=======================================================================
1942 //function : UpdatePaveBlocksWithSDVertices
1944 //=======================================================================
1945 void BOPDS_DS::UpdatePaveBlocksWithSDVertices()
1947 Standard_Integer i, aNbPBP;
1948 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1950 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
1953 for (i = 0; i < aNbPBP; ++i) {
1954 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
1956 aItPB.Initialize(aLPB);
1957 for (; aItPB.More(); aItPB.Next()) {
1958 Handle(BOPDS_PaveBlock)& aPB = aItPB.ChangeValue();
1959 UpdatePaveBlockWithSDVertices(aPB);
1960 }// for (; aItPB.More(); aItPB.Next()) {
1961 }// for (i = 0; i < aNbPBP; ++i) {
1963 //=======================================================================
1964 //function : UpdatePaveBlockWithSDVertices
1966 //=======================================================================
1967 void BOPDS_DS::UpdatePaveBlockWithSDVertices
1968 (const Handle(BOPDS_PaveBlock)& thePB)
1970 Standard_Integer nV1, nV2;
1971 BOPDS_Pave aPave1, aPave2;
1973 aPave1 = thePB->Pave1();
1974 aPave2 = thePB->Pave2();
1976 nV1 = aPave1.Index();
1977 nV2 = aPave2.Index();
1979 if (HasShapeSD(nV1, nV1)) {
1980 aPave1.SetIndex(nV1);
1981 thePB->SetPave1(aPave1);
1984 if (HasShapeSD(nV2, nV2)) {
1985 aPave2.SetIndex(nV2);
1986 thePB->SetPave2(aPave2);
1989 //=======================================================================
1990 //function : UpdateCommonBlockWithSDVertices
1992 //=======================================================================
1993 void BOPDS_DS::UpdateCommonBlockWithSDVertices
1994 (const Handle(BOPDS_CommonBlock)& theCB)
1996 const BOPDS_ListOfPaveBlock& aLPB = theCB->PaveBlocks();
1997 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
1998 for (; aItPB.More(); aItPB.Next()) {
1999 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
2000 UpdatePaveBlockWithSDVertices(aPB);
2003 //=======================================================================
2004 //function : InitPaveBlocksForVertex
2006 //=======================================================================
2007 void BOPDS_DS::InitPaveBlocksForVertex(const Standard_Integer theNV)
2009 Standard_Integer nE;
2010 BOPCol_ListIteratorOfListOfInteger aItLE;
2012 if (myMapVE.IsBound(theNV)) {
2013 const BOPCol_ListOfInteger& aLE=myMapVE.Find(theNV);
2014 aItLE.Initialize(aLE);
2015 for (; aItLE.More(); aItLE.Next()) {
2017 ChangePaveBlocks(nE);
2022 //=======================================================================
2023 //function : ReleasePaveBlocks
2025 //=======================================================================
2026 void BOPDS_DS::ReleasePaveBlocks()
2028 // It is necessary to remove the reference to PaveBlocks for the untouched
2029 // edges to avoid creation of the same images for them.
2030 // Pave blocks for this reference should be cleared.
2031 // This will allow to differ the small edges, for which it is
2032 // impossible to even build a pave block from the normal edges for which the
2033 // pave block have been created, but stayed untouched.
2034 // The small edge, for which no pave blocks have been created,
2035 // should be avoided in the result, thus the reference to empty list
2036 // of pave blocks will stay to mark the edge as Deleted.
2038 BOPDS_VectorOfListOfPaveBlock& aPBP = ChangePaveBlocksPool();
2039 Standard_Integer aNbPBP = aPBP.Extent();
2044 for (Standard_Integer i = 0; i < aNbPBP; ++i) {
2045 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
2046 if (aLPB.Extent() == 1) {
2047 const Handle(BOPDS_PaveBlock)& aPB = aLPB.First();
2048 if (!IsCommonBlock(aPB)) {
2049 Standard_Integer nV1, nV2;
2050 aPB->Indices(nV1, nV2);
2051 if (!IsNewShape(nV1) && !IsNewShape(nV2)) {
2052 // Both vertices are original, thus the PB is untouched.
2053 // Remove reference for the original edge
2054 Standard_Integer nE = aPB->OriginalEdge();
2056 ChangeShapeInfo(nE).SetReference(-1);
2058 // Clear contents of the list
2066 //=======================================================================
2067 //function : IsValidShrunkData
2069 //=======================================================================
2070 Standard_Boolean BOPDS_DS::IsValidShrunkData(const Handle(BOPDS_PaveBlock)& thePB)
2072 if (!thePB->HasShrunkData())
2073 return Standard_False;
2075 // Compare the distances from the bounds of the shrunk range to the vertices
2076 // with the tolerance values of vertices
2079 Standard_Real aTS[2];
2081 Standard_Boolean bIsSplit;
2083 thePB->ShrunkData(aTS[0], aTS[1], aBox, bIsSplit);
2086 Standard_Integer nV[2];
2087 thePB->Indices(nV[0], nV[1]);
2089 const TopoDS_Edge& aE = TopoDS::Edge(Shape(thePB->OriginalEdge()));
2090 BRepAdaptor_Curve aBAC(aE);
2092 Standard_Real anEps = BRep_Tool::Tolerance(aE) * 0.01;
2094 for (Standard_Integer i = 0; i < 2; ++i) {
2095 const TopoDS_Vertex& aV = TopoDS::Vertex(Shape(nV[i]));
2096 Standard_Real aTol = BRep_Tool::Tolerance(aV) + Precision::Confusion();
2098 gp_Pnt aP = BRep_Tool::Pnt(aV);
2100 // Point on the end of shrunk range
2101 gp_Pnt aPS = aBAC.Value(aTS[i]);
2103 Standard_Real aDist = aP.Distance(aPS);
2104 if (aTol - aDist > anEps) {
2105 return Standard_False;
2108 return Standard_True;