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_DataMapOfPassKeyListOfPaveBlock.hxx>
23 #include <BOPDS_DS.hxx>
24 #include <BOPDS_FaceInfo.hxx>
25 #include <BOPDS_IndexRange.hxx>
26 #include <BOPDS_MapOfPave.hxx>
27 #include <BOPDS_MapOfPaveBlock.hxx>
28 #include <BOPDS_PassKey.hxx>
29 #include <BOPDS_PaveBlock.hxx>
30 #include <BOPDS_ShapeInfo.hxx>
31 #include <BOPDS_VectorOfPave.hxx>
32 #include <BOPTools_AlgoTools.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>
46 #include <TopoDS_Edge.hxx>
47 #include <TopoDS_Face.hxx>
48 #include <TopoDS_Iterator.hxx>
49 #include <TopoDS_Shape.hxx>
50 #include <TopoDS_Vertex.hxx>
51 #include <BOPCol_MapOfShape.hxx>
52 #include <BOPCol_DataMapOfIntegerListOfInteger.hxx>
58 void TotalShapes(const TopoDS_Shape& aS,
59 Standard_Integer& aNbS,
60 BOPCol_MapOfShape& aMS);
63 Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
64 const TopoDS_Edge& aE);
67 void AddShapeAndSubShapes(const Standard_Integer nS,
68 const BOPDS_ShapeInfo& theSI,
69 BOPCol_MapOfInteger& theMI);
72 void CollectEdges(const BOPDS_DS& theDS,
73 const Standard_Integer nF,
74 BOPCol_MapOfInteger& theMI);
76 //=======================================================================
79 //=======================================================================
82 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
83 myArguments(myAllocator),
84 myRanges(0,myAllocator),
85 myLines(0, myAllocator),
86 myMapShapeIndex(100, myAllocator),
87 myPaveBlocksPool(0,myAllocator),
88 myMapPBCB(100, myAllocator),
89 myFaceInfoPool(0, myAllocator),
90 myShapesSD(100, myAllocator),
91 myMapVE(100, myAllocator),
92 myInterfTB(100, myAllocator),
93 myInterfVV(0, myAllocator),
94 myInterfVE(0, myAllocator),
95 myInterfVF(0, myAllocator),
96 myInterfEE(0, myAllocator),
97 myInterfEF(0, myAllocator),
98 myInterfFF(0, myAllocator),
99 myInterfVZ(0, myAllocator),
100 myInterfEZ(0, myAllocator),
101 myInterfFZ(0, myAllocator),
102 myInterfZZ(0, myAllocator),
104 myToleranceMap(100, myAllocator)
109 //=======================================================================
112 //=======================================================================
113 BOPDS_DS::BOPDS_DS(const Handle(NCollection_BaseAllocator)& theAllocator)
115 myAllocator(theAllocator),
116 myArguments(myAllocator),
117 myRanges(0, myAllocator),
118 myLines(0, myAllocator),
119 myMapShapeIndex(100, myAllocator),
120 myPaveBlocksPool(0, myAllocator),
121 myMapPBCB(100, myAllocator),
122 myFaceInfoPool(0, myAllocator),
123 myShapesSD(100, myAllocator),
124 myMapVE(100, myAllocator),
125 myInterfTB(100, myAllocator),
126 myInterfVV(0, myAllocator),
127 myInterfVE(0, myAllocator),
128 myInterfVF(0, myAllocator),
129 myInterfEE(0, myAllocator),
130 myInterfEF(0, myAllocator),
131 myInterfFF(0, myAllocator),
132 myInterfVZ(0, myAllocator),
133 myInterfEZ(0, myAllocator),
134 myInterfFZ(0, myAllocator),
135 myInterfZZ(0, myAllocator),
137 myToleranceMap(100, myAllocator)
142 //=======================================================================
145 //=======================================================================
146 BOPDS_DS::~BOPDS_DS()
150 //=======================================================================
153 //=======================================================================
154 void BOPDS_DS::Clear()
163 myMapShapeIndex.Clear();
164 myPaveBlocksPool.Clear();
165 myFaceInfoPool.Clear();
180 myToleranceMap.Clear();
182 //=======================================================================
183 //function : SetArguments
185 //=======================================================================
186 void BOPDS_DS::SetArguments(const BOPCol_ListOfShape& theLS)
190 //=======================================================================
191 //function : Arguments
193 //=======================================================================
194 const BOPCol_ListOfShape& BOPDS_DS::Arguments()const
198 //=======================================================================
199 //function : Allocator
201 //=======================================================================
202 const Handle(NCollection_BaseAllocator)& BOPDS_DS::Allocator()const
207 //=======================================================================
208 //function : NbShapes
210 //=======================================================================
211 Standard_Integer BOPDS_DS::NbShapes()const
213 return myLines.Size();
215 //=======================================================================
216 //function : NbSourceShapes
218 //=======================================================================
219 Standard_Integer BOPDS_DS::NbSourceShapes()const
221 return myNbSourceShapes;
223 //=======================================================================
224 //function : NbRanges
226 //=======================================================================
227 Standard_Integer BOPDS_DS::NbRanges()const
229 return myRanges.Size();
231 //=======================================================================
234 //=======================================================================
235 const BOPDS_IndexRange& BOPDS_DS::Range(const Standard_Integer theI)const
237 return myRanges(theI);
239 //=======================================================================
242 //=======================================================================
243 Standard_Integer BOPDS_DS::Rank(const Standard_Integer theI)const
245 Standard_Integer i, aNb, iErr;
249 for(i=0; i<aNb; ++i) {
250 const BOPDS_IndexRange& aR=Range(i);
251 if (aR.Contains(theI)) {
257 //=======================================================================
258 //function : IsNewShape
260 //=======================================================================
261 Standard_Boolean BOPDS_DS::IsNewShape(const Standard_Integer theI)const
263 return theI>=NbSourceShapes();
265 //=======================================================================
268 //=======================================================================
269 Standard_Integer BOPDS_DS::Append(const BOPDS_ShapeInfo& theSI)
273 myLines.Append1()=theSI;
274 iX=myLines.Extent()-1;
278 //=======================================================================
281 //=======================================================================
282 Standard_Integer BOPDS_DS::Append(const TopoDS_Shape& theS)
286 myLines.Append1().SetShape(theS);
287 iX=myLines.Extent()-1;
290 //=======================================================================
291 //function : ShapeInfo
293 //=======================================================================
294 const BOPDS_ShapeInfo& BOPDS_DS::ShapeInfo
295 (const Standard_Integer theI)const
297 return myLines(theI);
299 //=======================================================================
300 //function : ChangeShapeInfo
302 //=======================================================================
303 BOPDS_ShapeInfo& BOPDS_DS::ChangeShapeInfo(const Standard_Integer theI)
305 BOPDS_ShapeInfo *pSI;
307 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI);
308 pSI=(BOPDS_ShapeInfo *)&aSI;
311 //=======================================================================
314 //=======================================================================
315 const TopoDS_Shape& BOPDS_DS::Shape(const Standard_Integer theI)const
318 const TopoDS_Shape& aS=ShapeInfo(theI).Shape();
321 //=======================================================================
324 //=======================================================================
325 Standard_Integer BOPDS_DS::Index(const TopoDS_Shape& theS)const
327 Standard_Integer iRet;
330 if (myMapShapeIndex.IsBound(theS)) {
331 iRet=myMapShapeIndex.Find(theS);
335 //=======================================================================
338 //=======================================================================
339 void BOPDS_DS::Init()
341 Standard_Integer i1, i2, j, aI, aNb, aNbS, aNbE, aNbSx;
342 Standard_Integer n1, n2, n3, nV, nW, nE, aNbF;
343 Standard_Real aTol, aFuzz, aTolAdd;
344 TopAbs_ShapeEnum aTS;
345 TopoDS_Iterator aItS;
346 BOPCol_ListIteratorOfListOfInteger aIt1, aIt2, aIt3;
347 BOPCol_ListIteratorOfListOfShape aIt;
349 Handle(NCollection_BaseAllocator) aAllocator;
350 BOPCol_MapOfShape aMS;
352 // 1 Append Source Shapes
353 aNb=myArguments.Extent();
358 myRanges.SetIncrement(aNb);
361 aIt.Initialize(myArguments);
362 for (; aIt.More(); aIt.Next()) {
363 const TopoDS_Shape& aSx=aIt.Value();
366 TotalShapes(aSx, aNbSx, aMS);
372 myLines.SetIncrement(2*aNbS);
373 //-----------------------------------------------------scope_1 f
375 NCollection_BaseAllocator::CommonBaseAllocator();
377 BOPCol_DataMapOfShapeInteger& aMSI=myMapShapeIndex;
381 aIt.Initialize(myArguments);
382 for (; aIt.More(); aIt.Next()) {
383 const TopoDS_Shape& aS=aIt.Value();
384 if (aMSI.IsBound(aS)) {
390 InitShape(aI, aS, aAllocator, aMSI);
393 aR.SetIndices(i1, i2);
398 aFuzz = myFuzzyValue / 2.;
399 aTolAdd = Precision::Confusion();
400 myNbSourceShapes = NbShapes();
405 for (j=0; j<myNbSourceShapes; ++j) {
406 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
408 const TopoDS_Shape& aS=aSI.Shape();
412 if (aTS==TopAbs_VERTEX) {
413 Bnd_Box& aBox=aSI.ChangeBox();
414 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aS);
415 const gp_Pnt& aP=BRep_Tool::Pnt(aV);
417 const Handle(BRep_TVertex)& TV =
418 *((Handle(BRep_TVertex)*)&aV.TShape());
419 aTol = TV->Tolerance();
420 // TODO: non-destructive
421 myToleranceMap.Bind(j, aTol);
425 aBox.SetGap(aTol + aTolAdd);
431 for (j=0; j<myNbSourceShapes; ++j) {
432 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
435 if (aTS==TopAbs_EDGE) {
436 const TopoDS_Shape& aS=aSI.Shape();
437 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aS);
439 const Handle(BRep_TEdge)& TE =
440 *((Handle(BRep_TEdge)*)&aE.TShape());
441 aTol = TE->Tolerance();
442 // TODO: non-destructive
443 myToleranceMap.Bind(j, aTol);
447 if (!BRep_Tool::Degenerated(aE)) {
448 Standard_Boolean bInf1, bInf2;
449 Standard_Integer aIx;
450 Standard_Real aT1, aT2;
452 Handle(Geom_Curve) aC3D;
456 BOPDS_ShapeInfo aSIx;
458 BOPCol_ListOfInteger& aLI=aSI.ChangeSubShapes();
461 aEx.Orientation(TopAbs_FORWARD);
463 aC3D=BRep_Tool::Curve (aEx, aT1, aT2);
464 bInf1=Precision::IsNegativeInfinite(aT1);
465 bInf2=Precision::IsPositiveInfinite(aT2);
469 aBB.MakeVertex(aVx, aPx, aTol);
470 aVx.Orientation(TopAbs_FORWARD);
473 aSIx.SetShapeType(TopAbs_VERTEX);
474 aSIx.SetFlag(1); //infinite flag
481 aBB.MakeVertex(aVx, aPx, aTol);
482 aVx.Orientation(TopAbs_REVERSED);
485 aSIx.SetShapeType(TopAbs_VERTEX);
486 aSIx.SetFlag(1);//infinite flag
496 Bnd_Box& aBox=aSI.ChangeBox();
497 BRepBndLib::Add(aE, aBox);
499 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
500 aIt1.Initialize(aLV);
501 for (; aIt1.More(); aIt1.Next()) {
503 BOPDS_ShapeInfo& aSIV=ChangeShapeInfo(nV);
504 Bnd_Box& aBx=aSIV.ChangeBox();
507 aBox.SetGap(aBox.GetGap() + aTolAdd);
512 BOPCol_MapOfInteger aMI(100, aAllocator);
513 BOPCol_MapIteratorOfMapOfInteger aItMI;
516 for (j=0; j<myNbSourceShapes; ++j) {
517 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
520 if (aTS==TopAbs_FACE) {
521 const TopoDS_Shape& aS=aSI.Shape();
522 const TopoDS_Face& aF=*((TopoDS_Face*)&aS);
524 const Handle(BRep_TFace)& TF =
525 *((Handle(BRep_TFace)*)&aF.TShape());
526 aTol = TF->Tolerance();
527 // TODO: non-destructive
528 myToleranceMap.Bind(j, aTol);
532 Bnd_Box& aBox=aSI.ChangeBox();
533 BRepBndLib::Add(aS, aBox);
535 BOPCol_ListOfInteger& aLW=aSI.ChangeSubShapes();
536 aIt1.Initialize(aLW);
537 for (; aIt1.More(); aIt1.Next()) {
539 BOPDS_ShapeInfo& aSIW=ChangeShapeInfo(nW);
541 const BOPCol_ListOfInteger& aLE=aSIW.SubShapes();
542 aIt2.Initialize(aLE);
543 for (; aIt2.More(); aIt2.Next()) {
545 BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
546 Bnd_Box& aBx=aSIE.ChangeBox();
550 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aSIE.Shape());
551 if (BRep_Tool::Degenerated(aE)) {
555 const BOPCol_ListOfInteger& aLV=aSIE.SubShapes();
556 aIt3.Initialize(aLV);
557 for (; aIt3.More(); aIt3.Next()) {
562 }//for (; aIt1.More(); aIt1.Next()) {
564 // pure internal vertices on the face
566 for (; aItS.More(); aItS.Next()) {
567 const TopoDS_Shape& aSx=aItS.Value();
568 if (aSx.ShapeType()==TopAbs_VERTEX){
575 // For a Face: change wires for BRep sub-shapes
577 aItMI.Initialize(aMI);
578 for (; aItMI.More(); aItMI.Next()) {
583 aBox.SetGap(aBox.GetGap() + aTolAdd);
585 }//if (aTS==TopAbs_FACE) {
586 }//for (j=0; j<myNbSourceShapes; ++j) {
589 for (j=0; j<myNbSourceShapes; ++j) {
590 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
593 if (aTS!=TopAbs_SOLID) {
596 Bnd_Box& aBox=aSI.ChangeBox();
597 BuildBndBoxSolid(j, aBox);
600 // update sub-shapes by BRep comprising ones
602 BOPCol_ListOfInteger& aLI1=aSI.ChangeSubShapes();
604 aIt1.Initialize(aLI1);
605 for (; aIt1.More(); aIt1.Next()) {
607 BOPDS_ShapeInfo& aSI1=ChangeShapeInfo(n1);
608 if (aSI1.ShapeType()!=TopAbs_SHELL) {
612 const BOPCol_ListOfInteger& aLI2=aSI1.SubShapes();
613 aIt2.Initialize(aLI2);
614 for (; aIt2.More(); aIt2.Next()) {
616 BOPDS_ShapeInfo& aSI2=ChangeShapeInfo(n2);
617 if (aSI2.ShapeType()!=TopAbs_FACE) {
623 const BOPCol_ListOfInteger& aLI3=aSI2.SubShapes();
624 aIt3.Initialize(aLI3);
625 for (; aIt3.More(); aIt3.Next()) {
633 aItMI.Initialize(aMI);
634 for (; aItMI.More(); aItMI.Next()) {
639 }//for (j=0; j<myNbSourceShapes; ++j) {
642 //-----------------------------------------------------
644 for (nE=0; nE<myNbSourceShapes; ++nE) {
645 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(nE);
646 if (aSI.ShapeType()!=TopAbs_EDGE) {
650 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
651 aIt1.Initialize(aLV);
652 for (; aIt1.More(); aIt1.Next()) {
654 if (myMapVE.IsBound(nV)) {
655 BOPCol_ListOfInteger& aLE=myMapVE.ChangeFind(nV);
659 BOPCol_ListOfInteger aLE(myAllocator);
662 myMapVE.Bind(nV, aLE);
667 BOPCol_DataMapIteratorOfDataMapOfIntegerListOfInteger aItDMILI;
668 aItDMILI.Initialize(myMapVE);
669 for(; aItDMILI.More(); aItDMILI.Next()) {
670 BOPCol_MapOfInteger aMFence;
671 BOPCol_ListOfInteger aLEx;
674 BOPCol_ListOfInteger& aLE=aItDMILI.ChangeValue();
675 aIt1.Initialize(aLE);
676 for (; aIt1.More(); aIt1.Next()) {
678 if(aMFence.Add(nE)) {
684 aIt1.Initialize(aLEx);
685 for (; aIt1.More(); aIt1.Next()) {
690 //-----------------------------------------------------scope_1 t
691 // 3 myPaveBlocksPool
693 myPaveBlocksPool.SetIncrement(aNbE);
694 myFaceInfoPool.SetIncrement(aNbF);
696 //=======================================================================
697 //function : InitShape
699 //=======================================================================
700 void BOPDS_DS::InitShape
701 (const Standard_Integer aI,
702 const TopoDS_Shape& aS,
703 const Handle(NCollection_BaseAllocator)& theAllocator,
704 BOPCol_DataMapOfShapeInteger& aMSI)
706 Standard_Integer aIx;
708 BOPCol_ListIteratorOfListOfInteger aIt1;
710 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(aI);
711 aSI.SetShapeType(aS.ShapeType());
712 BOPCol_ListOfInteger& aLI=aSI.ChangeSubShapes();
714 BOPCol_MapOfInteger aM(100, theAllocator);
716 aIt1.Initialize(aLI);
717 for (; aIt1.More(); aIt1.Next()) {
718 aM.Add(aIt1.Value());
722 for (; aIt.More(); aIt.Next()) {
723 const TopoDS_Shape& aSx=aIt.Value();
724 if (aMSI.IsBound(aSx)) {
732 InitShape(aIx, aSx, theAllocator, aMSI);
740 //=======================================================================
741 //function : HasInterf
743 //=======================================================================
744 Standard_Boolean BOPDS_DS::HasInterf(const Standard_Integer theI) const
746 Standard_Integer n1, n2;
747 Standard_Boolean bRet;
748 BOPDS_MapIteratorMapOfPassKey aIt;
750 bRet = Standard_False;
752 aIt.Initialize(myInterfTB);
753 for (; aIt.More(); aIt.Next()) {
754 const BOPDS_PassKey& aPK = aIt.Value();
756 if (n1 == theI || n2 == theI) {
757 bRet = Standard_True;
764 //=======================================================================
765 //function : HasInterfShapeSubShapes
767 //=======================================================================
768 Standard_Boolean BOPDS_DS::HasInterfShapeSubShapes
769 (const Standard_Integer theI1,
770 const Standard_Integer theI2,
771 const Standard_Boolean theFlag)const
773 Standard_Boolean bRet;
775 BOPCol_ListIteratorOfListOfInteger aIt;
776 bRet = Standard_False;
778 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI2);
779 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
781 for (; aIt.More(); aIt.Next()) {
783 bRet=HasInterf(theI1, n2);
797 //=======================================================================
798 //function : HasInterfSubShapes
800 //=======================================================================
801 Standard_Boolean BOPDS_DS::HasInterfSubShapes
802 (const Standard_Integer theI1,
803 const Standard_Integer theI2)const
805 Standard_Boolean bRet;
807 BOPCol_ListIteratorOfListOfInteger aIt;
808 bRet = Standard_False;
810 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI1);
811 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
813 for (; aIt.More(); aIt.Next()) {
815 bRet=HasInterfShapeSubShapes(n1, theI2);
824 //=======================================================================
825 //function : PaveBlocksPool
827 //=======================================================================
828 const BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::PaveBlocksPool()const
830 return myPaveBlocksPool;
832 //=======================================================================
833 //function : ChangePaveBlocksPool
835 //=======================================================================
836 BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::ChangePaveBlocksPool()
838 return myPaveBlocksPool;
840 //=======================================================================
841 //function : HasPaveBlocks
843 //=======================================================================
844 Standard_Boolean BOPDS_DS::HasPaveBlocks(const Standard_Integer theI)const
846 return ShapeInfo(theI).HasReference();
848 //=======================================================================
849 //function : PaveBlocks
851 //=======================================================================
852 const BOPDS_ListOfPaveBlock& BOPDS_DS::PaveBlocks
853 (const Standard_Integer theI)const
855 static BOPDS_ListOfPaveBlock sLPB;
856 Standard_Integer aRef;
858 if (HasPaveBlocks(theI)) {
859 aRef=ShapeInfo(theI).Reference();
860 const BOPDS_ListOfPaveBlock& aLPB=myPaveBlocksPool(aRef);
866 //=======================================================================
867 //function : ChangePaveBlocks
869 //=======================================================================
870 BOPDS_ListOfPaveBlock& BOPDS_DS::ChangePaveBlocks
871 (const Standard_Integer theI)
873 Standard_Boolean bHasReference;
874 Standard_Integer aRef;
876 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
877 bHasReference=aSI.HasReference();
878 if (!bHasReference) {
879 InitPaveBlocks(theI);
882 aRef=aSI.Reference();
883 return myPaveBlocksPool(aRef);
885 //=======================================================================
886 //function : InitPaveBlocks
888 //=======================================================================
889 void BOPDS_DS::InitPaveBlocks(const Standard_Integer theI)
891 Standard_Integer nV=0, iRef, aNbV, nVSD;
893 TopAbs_Orientation aOrE;
895 BOPCol_ListIteratorOfListOfInteger aIt;
897 Handle(BOPDS_PaveBlock) aPB;
899 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
900 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aSI.Shape());
901 aOrE=aE.Orientation();
903 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
909 aPB=new BOPDS_PaveBlock;
910 aPB->SetOriginalEdge(theI);
912 if (aOrE!=TopAbs_INTERNAL) {
914 for (; aIt.More(); aIt.Next()) {
917 const BOPDS_ShapeInfo& aSIV=ShapeInfo(nV);
918 aV=*(TopoDS_Vertex*)(&aSIV.Shape());
919 if (aSIV.HasFlag()) {
920 aT=ComputeParameter(aV, aE);
923 aT=BRep_Tool::Parameter(aV, aE);
926 if (HasShapeSD(nV, nVSD)) {
930 aPave.SetParameter(aT);
931 aPB->AppendExtPave(aPave);
936 aT=BRep_Tool::Parameter(aV, aE);
938 aPave.SetParameter(aT);
939 aPB->AppendExtPave1(aPave);
944 TopoDS_Iterator aItE;
946 aItE.Initialize(aE, Standard_False, Standard_True);
947 for (; aItE.More(); aItE.Next()) {
948 aV=*((TopoDS_Vertex*)&aItE.Value());
951 const BOPDS_ShapeInfo& aSIV=ShapeInfo(nV);
952 if (aSIV.HasFlag()) {
953 aT=ComputeParameter(aV, aE);
956 aT=BRep_Tool::Parameter(aV, aE);
959 if (HasShapeSD(nV, nVSD)) {
963 aPave.SetParameter(aT);
964 aPB->AppendExtPave1(aPave);
968 BOPDS_ListOfPaveBlock &aLPB=myPaveBlocksPool.Append1();
969 iRef=myPaveBlocksPool.Extent()-1;
971 aPB->Update(aLPB, Standard_False);
972 aSI.SetReference(iRef);
974 //=======================================================================
975 //function : UpdatePaveBlocks
977 //=======================================================================
978 void BOPDS_DS::UpdatePaveBlocks()
980 Standard_Boolean bIsToUpdate;
981 Standard_Integer i, aNbPBP;
982 BOPDS_ListOfPaveBlock aLPBN(myAllocator);
983 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBN;
985 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
988 for (i=0; i<aNbPBP; ++i) {
989 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
991 aItPB.Initialize(aLPB);
992 for (; aItPB.More(); aItPB.Next()) {
993 Handle(BOPDS_PaveBlock)& aPB=aItPB.ChangeValue();
995 bIsToUpdate=aPB->IsToUpdate();
1000 aItPBN.Initialize(aLPBN);
1001 for (; aItPBN.More(); aItPBN.Next()) {
1002 Handle(BOPDS_PaveBlock)& aPBN=aItPBN.ChangeValue();
1007 }// for (; aItPB.More(); aItPB.Next()) {
1008 }// for (i=0; i<aNbPBP; ++i) {
1010 //=======================================================================
1011 //function : UpdatePaveBlock
1013 //=======================================================================
1014 void BOPDS_DS::UpdatePaveBlock(const Handle(BOPDS_PaveBlock)& thePB)
1016 if (!thePB->IsToUpdate()){
1020 Standard_Integer nE, iRef;
1021 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBN;
1022 BOPDS_ListOfPaveBlock aLPBN(myAllocator);
1023 Handle(BOPDS_PaveBlock) aPB;
1025 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
1027 nE=thePB->OriginalEdge();
1028 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(nE);
1029 iRef=aSI.Reference();
1030 BOPDS_ListOfPaveBlock& aLPB=aPBP(iRef);
1032 aItPB.Initialize(aLPB);
1033 for (; aItPB.More(); aItPB.Next()) {
1034 aPB=aItPB.ChangeValue();
1043 //=======================================================================
1044 //function : UpdateCommonBlock
1046 //=======================================================================
1047 void BOPDS_DS::UpdateCommonBlock(const Handle(BOPDS_CommonBlock)& theCB)
1049 Standard_Integer nE, iRef, n1, n2;
1050 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBCB, aItPBN;
1051 BOPDS_DataMapIteratorOfDataMapOfPassKeyListOfPaveBlock aItMPKLPB;
1052 BOPDS_ListOfPaveBlock aLPBN;
1053 BOPDS_DataMapOfPassKeyListOfPaveBlock aMPKLPB;
1054 Handle(BOPDS_PaveBlock) aPB;
1055 Handle(BOPDS_CommonBlock) aCBx;
1058 const BOPDS_ListOfPaveBlock& aLPBCB=theCB->PaveBlocks();
1059 if (!aLPBCB.First()->IsToUpdate()){
1063 const BOPCol_ListOfInteger& aLF=theCB->Faces();
1065 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
1067 aItPBCB.Initialize(aLPBCB);
1068 for (; aItPBCB.More(); aItPBCB.Next()) {
1069 const Handle(BOPDS_PaveBlock)& aPBCB=aItPBCB.ChangeValue();
1071 nE=aPBCB->OriginalEdge();
1072 iRef=ChangeShapeInfo(nE).Reference();
1073 BOPDS_ListOfPaveBlock& aLPB=aPBP(iRef);
1075 aItPB.Initialize(aLPB);
1076 for (; aItPB.More(); aItPB.Next()) {
1077 aPB=aItPB.ChangeValue();
1083 aItPBN.Initialize(aLPBN);
1084 for (; aItPBN.More(); aItPBN.Next()) {
1085 Handle(BOPDS_PaveBlock)& aPBN=aItPBN.ChangeValue();
1088 aPBN->Indices(n1, n2);
1090 if (aMPKLPB.IsBound(aPK)) {
1091 BOPDS_ListOfPaveBlock& aLPBx=aMPKLPB.ChangeFind(aPK);
1095 BOPDS_ListOfPaveBlock aLPBx;
1097 aMPKLPB.Bind(aPK, aLPBx);
1106 aItMPKLPB.Initialize(aMPKLPB);
1107 for (; aItMPKLPB.More(); aItMPKLPB.Next()) {
1108 BOPDS_ListOfPaveBlock& aLPBx=aItMPKLPB.ChangeValue();
1110 while (aLPBx.Extent()) {
1111 Standard_Boolean bCoinside;
1112 Standard_Real aTol, aTolMax(0.);
1113 BOPDS_ListOfPaveBlock aLPBxN;
1115 aItPB.Initialize(aLPBx);
1116 for(; aItPB.More(); ) {
1117 const Handle(BOPDS_PaveBlock)& aPBx=aItPB.Value();
1118 if (aLPBxN.Extent()) {
1119 const Handle(BOPDS_PaveBlock)& aPBCx = aLPBxN.First();
1120 bCoinside = CheckCoincidence(aPBx, aPBCx);
1122 nE = aPBx->OriginalEdge();
1123 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1124 aTol = BRep_Tool::Tolerance(aE);
1126 //pave block with the max tolerance of the original edge
1127 //must be the first in the common block
1128 if (aTolMax < aTol) {
1130 aLPBxN.Prepend(aPBx);
1132 aLPBxN.Append(aPBx);
1134 aLPBx.Remove(aItPB);
1137 }//if (aLPBxN.Extent()) {
1139 nE = aPBx->OriginalEdge();
1140 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1141 aTolMax = BRep_Tool::Tolerance(aE);
1143 aLPBxN.Append(aPBx);
1144 aLPBx.Remove(aItPB);
1148 }//for(; aItPB.More(); ) {
1150 aCBx=new BOPDS_CommonBlock;
1151 aCBx->AddPaveBlocks(aLPBxN);
1152 aCBx->SetFaces(aLF);
1154 aItPB.Initialize(aLPBxN);
1155 for (; aItPB.More(); aItPB.Next()) {
1156 aPB=aItPB.ChangeValue();
1157 SetCommonBlock(aPB, aCBx);
1163 //=======================================================================
1164 // function: RealPaveBlock
1166 //=======================================================================
1167 Handle(BOPDS_PaveBlock) BOPDS_DS::RealPaveBlock
1168 (const Handle(BOPDS_PaveBlock)& thePB) const
1170 if (IsCommonBlock(thePB)) {
1171 const Handle(BOPDS_CommonBlock)& aCB = CommonBlock(thePB);
1172 const Handle(BOPDS_PaveBlock)& aPB = aCB->PaveBlock1();
1178 //=======================================================================
1179 // function: IsCommonBlockOnEdge
1181 //=======================================================================
1182 Standard_Boolean BOPDS_DS::IsCommonBlockOnEdge
1183 (const Handle(BOPDS_PaveBlock)& thePB) const
1185 if (IsCommonBlock(thePB)) {
1186 const Handle(BOPDS_CommonBlock)& aCB = CommonBlock(thePB);
1187 return aCB->PaveBlocks().Extent()>1;
1189 return Standard_False;
1192 //=======================================================================
1193 //function : IsCommonBlock
1195 //=======================================================================
1196 Standard_Boolean BOPDS_DS::IsCommonBlock
1197 (const Handle(BOPDS_PaveBlock)& thePB) const
1199 return myMapPBCB.IsBound(thePB);
1202 //=======================================================================
1203 //function : CommonBlock
1205 //=======================================================================
1206 Handle(BOPDS_CommonBlock) BOPDS_DS::CommonBlock
1207 (const Handle(BOPDS_PaveBlock)& thePB) const
1209 return (IsCommonBlock(thePB) ? myMapPBCB.Find(thePB) : NULL);
1212 //=======================================================================
1213 //function : SetCommonBlock
1215 //=======================================================================
1216 void BOPDS_DS::SetCommonBlock(const Handle(BOPDS_PaveBlock)& thePB,
1217 const Handle(BOPDS_CommonBlock)& theCB)
1219 if (IsCommonBlock(thePB)) {
1220 Handle(BOPDS_CommonBlock)& aCB = myMapPBCB.ChangeFind(thePB);
1224 myMapPBCB.Bind(thePB, theCB);
1232 //=======================================================================
1233 //function : FaceInfoPool
1235 //=======================================================================
1236 const BOPDS_VectorOfFaceInfo& BOPDS_DS::FaceInfoPool()const
1238 return myFaceInfoPool;
1240 //=======================================================================
1241 //function : HasFaceInfo
1243 //=======================================================================
1244 Standard_Boolean BOPDS_DS::HasFaceInfo(const Standard_Integer theI)const
1246 return ShapeInfo(theI).HasReference();
1248 //=======================================================================
1249 //function : FaceInfo
1251 //=======================================================================
1252 const BOPDS_FaceInfo& BOPDS_DS::FaceInfo(const Standard_Integer theI)const
1254 static BOPDS_FaceInfo sFI;
1255 Standard_Integer aRef;
1257 if (HasFaceInfo(theI)) {
1258 aRef=ShapeInfo(theI).Reference();
1259 const BOPDS_FaceInfo& aFI=myFaceInfoPool(aRef);
1264 //=======================================================================
1265 //function : ChangeFaceInfo
1267 //=======================================================================
1268 BOPDS_FaceInfo& BOPDS_DS::ChangeFaceInfo(const Standard_Integer theI)
1270 Standard_Boolean bHasReference;
1271 Standard_Integer aRef;
1272 BOPDS_FaceInfo* pFI;
1274 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1275 bHasReference=aSI.HasReference();
1276 if (!bHasReference) {
1280 aRef=aSI.Reference();
1281 const BOPDS_FaceInfo& aFI=myFaceInfoPool(aRef);
1282 pFI=(BOPDS_FaceInfo*)&aFI;
1285 //=======================================================================
1286 //function : InitFaceInfo
1288 //=======================================================================
1289 void BOPDS_DS::InitFaceInfo(const Standard_Integer theI)
1291 Standard_Integer iRef;
1293 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1294 BOPDS_FaceInfo &aFI=myFaceInfoPool.Append1();
1295 iRef=myFaceInfoPool.Extent()-1;
1296 aSI.SetReference(iRef);
1299 UpdateFaceInfoIn(theI);
1300 UpdateFaceInfoOn(theI);
1302 //=======================================================================
1303 //function : UpdateFaceInfoIn
1305 //=======================================================================
1306 void BOPDS_DS::UpdateFaceInfoIn(const Standard_Integer theI)
1308 Standard_Integer iRef;
1310 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1311 if (aSI.HasReference()) {
1312 iRef=aSI.Reference();
1313 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1315 BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.ChangePaveBlocksIn();
1316 BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
1319 FaceInfoIn(theI, aMPBIn, aMVIn);
1322 //=======================================================================
1323 //function : UpdateFaceInfoOn
1325 //=======================================================================
1326 void BOPDS_DS::UpdateFaceInfoOn(const Standard_Integer theI)
1328 Standard_Integer iRef;
1330 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1331 if (aSI.HasReference()) {
1332 iRef=aSI.Reference();
1333 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1335 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1336 BOPCol_MapOfInteger& aMVOn=aFI.ChangeVerticesOn();
1339 FaceInfoOn(theI, aMPBOn, aMVOn);
1342 //=======================================================================
1343 //function : FaceInfoOn
1345 //=======================================================================
1346 void BOPDS_DS::FaceInfoOn(const Standard_Integer theF,
1347 BOPDS_IndexedMapOfPaveBlock& theMPB,
1348 BOPCol_MapOfInteger& theMI)
1350 Standard_Integer nS, nSD, nV1, nV2;
1351 BOPCol_ListIteratorOfListOfInteger aIt;
1352 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1354 const BOPDS_ShapeInfo& aSI=ShapeInfo(theF);
1355 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
1356 aIt.Initialize(aLI);
1357 for (; aIt.More(); aIt.Next()) {
1359 const BOPDS_ShapeInfo& aSIE=ShapeInfo(nS);
1360 if (aSIE.ShapeType()==TopAbs_EDGE) {
1361 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nS);
1362 aItPB.Initialize(aLPB);
1363 for (; aItPB.More(); aItPB.Next()) {
1364 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
1365 aPB->Indices(nV1, nV2);
1368 Handle(BOPDS_PaveBlock) aPBR=RealPaveBlock(aPB);
1371 }//if (aSIE.ShapeType()==TopAbs_EDGE)
1373 // nE is TopAbs_VERTEX
1374 if (HasShapeSD(nS, nSD)) {
1381 //=======================================================================
1382 //function : FaceInfoIn
1384 //=======================================================================
1385 void BOPDS_DS::FaceInfoIn(const Standard_Integer theF,
1386 BOPDS_IndexedMapOfPaveBlock& theMPB,
1387 BOPCol_MapOfInteger& theMI)
1389 Standard_Integer i, aNbVF, aNbEF, nV, nE, nVSD;
1390 TopoDS_Iterator aItS;
1391 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1393 // 1. Pure internal vertices on the face
1394 const TopoDS_Shape& aF=Shape(theF);
1395 aItS.Initialize(aF);
1396 for (; aItS.More(); aItS.Next()) {
1397 const TopoDS_Shape& aSx=aItS.Value();
1398 if (aSx.ShapeType()==TopAbs_VERTEX){
1400 if (HasShapeSD(nV, nVSD)) {
1408 BOPDS_VectorOfInterfVF& aVFs=InterfVF();
1409 aNbVF=aVFs.Extent();
1410 for (i=0; i<aNbVF; ++i) {
1411 BOPDS_InterfVF& aVF=aVFs(i);
1412 if(aVF.Contains(theF)) {
1413 nV=aVF.OppositeIndex(theF);
1414 if (HasShapeSD(nV, nVSD)) {
1422 BOPDS_VectorOfInterfEF& aEFs=InterfEF();
1423 aNbEF=aEFs.Extent();
1424 for (i=0; i<aNbEF; ++i) {
1425 BOPDS_InterfEF& aEF=aEFs(i);
1426 if(aEF.Contains(theF)) {
1427 if(aEF.HasIndexNew(nV)) {
1431 nE=aEF.OppositeIndex(theF);
1432 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1433 aItPB.Initialize(aLPB);
1434 for (; aItPB.More(); aItPB.Next()) {
1435 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
1436 if (IsCommonBlock(aPB)) {
1437 const Handle(BOPDS_CommonBlock)& aCB=CommonBlock(aPB);
1438 if (aCB->Contains(theF)) {
1439 const Handle(BOPDS_PaveBlock)& aPB1=aCB->PaveBlock1();
1443 }// for (; aItPB.More(); aItPB.Next()) {
1445 }// if(aEF.Contains(theF)) {
1446 }// for (i=0; i<aNbEF; ++i) {
1449 //=======================================================================
1450 //function : RefineFaceInfoOn
1452 //=======================================================================
1453 void BOPDS_DS::RefineFaceInfoOn()
1455 Standard_Integer i, aNb, nF, aNbPB, j;
1456 BOPDS_IndexedMapOfPaveBlock aMPB;
1458 aNb=myFaceInfoPool.Extent();
1459 for (i=0; i<aNb; ++i) {
1460 BOPDS_FaceInfo &aFI=myFaceInfoPool(i);
1462 UpdateFaceInfoOn(nF);
1463 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1466 aMPB.Assign(aMPBOn);
1469 aNbPB=aMPB.Extent();
1470 for (j=1; j<=aNbPB; ++j) {
1471 const Handle(BOPDS_PaveBlock)& aPB=aMPB(j);
1472 if (aPB->HasEdge()) {
1478 //=======================================================================
1479 //function : AloneVertices
1481 //=======================================================================
1482 void BOPDS_DS::AloneVertices(const Standard_Integer theI,
1483 BOPCol_ListOfInteger& theLI)const
1485 if (HasFaceInfo(theI)) {
1487 Standard_Integer i, j, nV1, nV2, nV, aNbPB;
1488 BOPCol_MapIteratorOfMapOfInteger aItMI;
1490 BOPCol_MapOfInteger aMI(100, myAllocator);
1492 const BOPDS_FaceInfo& aFI=FaceInfo(theI);
1494 for (i = 0; i < 2; ++i) {
1495 const BOPDS_IndexedMapOfPaveBlock& aMPB=
1496 (!i) ? aFI.PaveBlocksIn() : aFI.PaveBlocksSc();
1497 aNbPB = aMPB.Extent();
1498 for (j = 1; j <= aNbPB; ++j) {
1499 const Handle(BOPDS_PaveBlock)& aPB = aMPB(j);
1500 aPB->Indices(nV1, nV2);
1506 for (i=0; i<2; ++i) {
1507 const BOPCol_MapOfInteger& aMIV=
1508 (!i) ? aFI.VerticesIn() : aFI.VerticesSc();
1509 aItMI.Initialize(aMIV);
1510 for (; aItMI.More(); aItMI.Next()) {
1521 //=======================================================================
1522 //function : VerticesOnIn
1524 //=======================================================================
1525 void BOPDS_DS::VerticesOnIn
1526 (const Standard_Integer nF1,
1527 const Standard_Integer nF2,
1528 BOPCol_MapOfInteger& aMI,
1529 BOPDS_IndexedMapOfPaveBlock& aMPB)const
1531 Standard_Integer i, j, nV, nV1, nV2, aNbPB;
1532 BOPCol_MapIteratorOfMapOfInteger aIt;
1533 BOPDS_IndexedMapOfPaveBlock pMPB[4];
1535 const BOPDS_FaceInfo& aFI1=FaceInfo(nF1);
1536 const BOPDS_FaceInfo& aFI2=FaceInfo(nF2);
1538 pMPB[0]=aFI1.PaveBlocksOn();
1539 pMPB[1]=aFI1.PaveBlocksIn();
1540 pMPB[2]=aFI2.PaveBlocksOn();
1541 pMPB[3]=aFI2.PaveBlocksIn();
1543 for (i=0; i<4; ++i) {
1544 aNbPB = pMPB[i].Extent();
1545 for (j = 1; j <= aNbPB; ++j) {
1546 const Handle(BOPDS_PaveBlock)& aPB = pMPB[i](j);
1548 aPB->Indices(nV1, nV2);
1554 const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
1555 const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
1556 const BOPCol_MapOfInteger& aMVOn2=aFI2.VerticesOn();
1557 const BOPCol_MapOfInteger& aMVIn2=aFI2.VerticesIn();
1559 for (i=0; i<2; ++i) {
1560 const BOPCol_MapOfInteger& aMV1=(!i) ? aMVOn1 : aMVIn1;
1561 aIt.Initialize(aMV1);
1562 for (; aIt.More(); aIt.Next()) {
1564 if (aMVOn2.Contains(nV) || aMVIn2.Contains(nV)) {
1570 //=======================================================================
1571 //function : SharedEdges
1573 //=======================================================================
1574 void BOPDS_DS::SharedEdges(const Standard_Integer nF1,
1575 const Standard_Integer nF2,
1576 BOPCol_ListOfInteger& theLI,
1577 const Handle(NCollection_BaseAllocator)& aAllocator)
1579 Standard_Integer nE, nSp;
1580 BOPCol_ListIteratorOfListOfInteger aItLI;
1581 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
1582 BOPCol_MapOfInteger aMI(100, aAllocator);
1584 const BOPDS_ShapeInfo& aSI1=ShapeInfo(nF1);
1585 const BOPCol_ListOfInteger& aLI1=aSI1.SubShapes();
1586 aItLI.Initialize(aLI1);
1587 for (; aItLI.More(); aItLI.Next()) {
1589 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1590 if(aSIE.ShapeType()==TopAbs_EDGE) {
1591 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1592 if (aLPB.IsEmpty()) {
1596 aItLPB.Initialize(aLPB);
1597 for (; aItLPB.More(); aItLPB.Next()) {
1598 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
1606 const BOPDS_ShapeInfo& aSI2=ShapeInfo(nF2);
1607 const BOPCol_ListOfInteger& aLI2=aSI2.SubShapes();
1608 aItLI.Initialize(aLI2);
1609 for (; aItLI.More(); aItLI.Next()) {
1611 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1612 if(aSIE.ShapeType()==TopAbs_EDGE) {
1613 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1614 if (aLPB.IsEmpty()) {
1615 if (aMI.Contains(nE)) {
1620 aItLPB.Initialize(aLPB);
1621 for (; aItLPB.More(); aItLPB.Next()) {
1622 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
1624 if (aMI.Contains(nSp)) {
1633 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1635 // same domain shapes
1637 //=======================================================================
1638 //function : ShapesSD
1640 //=======================================================================
1641 BOPCol_DataMapOfIntegerInteger& BOPDS_DS::ShapesSD()
1645 //=======================================================================
1646 //function : AddShapeSD
1648 //=======================================================================
1649 void BOPDS_DS::AddShapeSD(const Standard_Integer theIndex,
1650 const Standard_Integer theIndexSD)
1652 myShapesSD.Bind(theIndex, theIndexSD);
1654 //=======================================================================
1655 //function : HasShapeSD
1657 //=======================================================================
1658 Standard_Boolean BOPDS_DS::HasShapeSD
1659 (const Standard_Integer theIndex,
1660 Standard_Integer& theIndexSD)const
1662 Standard_Boolean bRet;
1664 bRet=myShapesSD.IsBound(theIndex);
1666 theIndexSD=myShapesSD.Find(theIndex);
1670 //=======================================================================
1673 //=======================================================================
1674 void BOPDS_DS::Dump()const
1676 Standard_Integer i, aNb, aNbSS;
1678 printf(" *** DS ***\n");
1680 printf(" Ranges:%d\n", aNb);
1681 for (i=0; i<aNb; ++i) {
1682 const BOPDS_IndexRange& aR=Range(i);
1687 aNbSS=NbSourceShapes();
1688 printf(" Shapes:%d\n", aNbSS);
1690 for (i=0; i<aNb; ++i) {
1691 const BOPDS_ShapeInfo& aSI=ShapeInfo(i);
1696 printf(" ****** adds\n");
1699 printf(" ******\n");
1702 //=======================================================================
1703 // function: CheckCoincidence
1705 //=======================================================================
1706 Standard_Boolean BOPDS_DS::CheckCoincidence
1707 (const Handle(BOPDS_PaveBlock)& aPB1,
1708 const Handle(BOPDS_PaveBlock)& aPB2)
1710 Standard_Boolean bRet;
1711 Standard_Integer nE1, nE2, aNbPoints;
1712 Standard_Real aT11, aT12, aT21, aT22, aT1m, aD, aTol, aT2x;
1715 bRet=Standard_False;
1717 aPB1->Range(aT11, aT12);
1718 aT1m=IntTools_Tools::IntermediatePoint (aT11, aT12);
1719 nE1=aPB1->OriginalEdge();
1720 const TopoDS_Edge& aE1=(*(TopoDS_Edge*)(&Shape(nE1)));
1721 BOPTools_AlgoTools::PointOnEdge(aE1, aT1m, aP1m);
1723 aPB2->Range(aT21, aT22);
1724 nE2=aPB2->OriginalEdge();
1725 const TopoDS_Edge& aE2=(*(TopoDS_Edge*)(&Shape(nE2)));
1728 Handle(Geom_Curve)aC2 = BRep_Tool::Curve (aE2, f, l);
1729 GeomAPI_ProjectPointOnCurve aPPC;
1730 aPPC.Init(aC2, f, l);
1732 aNbPoints=aPPC.NbPoints();
1734 aD=aPPC.LowerDistance();
1736 aTol=BRep_Tool::Tolerance(aE1);
1737 aTol=aTol+BRep_Tool::Tolerance(aE2) + Precision::Confusion();
1739 aT2x=aPPC.LowerDistanceParameter();
1740 if (aT2x>aT21 && aT2x<aT22) {
1747 //=======================================================================
1748 // function: SortPaveBlocks
1750 //=======================================================================
1751 void BOPDS_DS::SortPaveBlocks(const Handle(BOPDS_CommonBlock)& aCB)
1753 Standard_Integer theI;
1754 Standard_Boolean bToSort;
1755 bToSort = IsToSort(aCB, theI);
1760 Standard_Integer i(0);
1761 const BOPDS_ListOfPaveBlock& aLPB = aCB->PaveBlocks();
1762 BOPDS_ListOfPaveBlock aLPBN = aLPB;
1764 Handle(BOPDS_PaveBlock) aPB;
1765 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1767 aIt.Initialize(aLPBN);
1768 for (aIt.Next(); aIt.More(); ) {
1779 aCB->AddPaveBlocks(aLPBN);
1781 //=======================================================================
1782 // function: IsToSort
1784 //=======================================================================
1785 Standard_Boolean BOPDS_DS::IsToSort
1786 (const Handle(BOPDS_CommonBlock)& aCB,
1787 Standard_Integer& theI)
1789 Standard_Boolean bRet;
1790 bRet = Standard_False;
1791 const BOPDS_ListOfPaveBlock& aLPB = aCB->PaveBlocks();
1792 if (aLPB.Extent()==1) {
1796 Standard_Integer nE;
1797 Standard_Real aTolMax, aTol;
1798 Handle(BOPDS_PaveBlock) aPB;
1800 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1803 nE = aPB->OriginalEdge();
1804 aE = (*(TopoDS_Edge *)(&Shape(nE)));
1805 aTolMax = BRep_Tool::Tolerance(aE);
1808 aIt.Initialize(aLPB);
1809 for (aIt.Next(); aIt.More(); aIt.Next()) {
1812 nE = aPB->OriginalEdge();
1813 aE = (*(TopoDS_Edge *)(&Shape(nE)));
1814 aTol = BRep_Tool::Tolerance(aE);
1815 if (aTolMax < aTol) {
1817 bRet = Standard_True;
1823 //=======================================================================
1824 // function: IsSubShape
1826 //=======================================================================
1827 Standard_Boolean BOPDS_DS::IsSubShape
1828 (const Standard_Integer theI1,
1829 const Standard_Integer theI2)
1831 Standard_Boolean bRet;
1832 Standard_Integer nS;
1833 bRet = Standard_False;
1835 BOPCol_ListIteratorOfListOfInteger aItLI;
1837 const BOPDS_ShapeInfo& aSI = ShapeInfo(theI2);
1838 const BOPCol_ListOfInteger& aLI = aSI.SubShapes();
1839 aItLI.Initialize(aLI);
1840 for(;aItLI.More(); aItLI.Next()) {
1843 bRet = Standard_True;
1850 //=======================================================================
1853 //=======================================================================
1854 void BOPDS_DS::Paves(const Standard_Integer theEdge,
1855 BOPDS_ListOfPave& theLP)
1857 Standard_Integer aNb, i;
1858 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1859 BOPDS_MapOfPave aMP;
1861 const BOPDS_ListOfPaveBlock& aLPB = PaveBlocks(theEdge);
1862 aNb = aLPB.Extent() + 1;
1867 BOPDS_VectorOfPave pPaves(1, aNb);
1870 aIt.Initialize(aLPB);
1871 for (; aIt.More(); aIt.Next()) {
1872 const Handle(BOPDS_PaveBlock)& aPB = aIt.Value();
1873 const BOPDS_Pave& aPave1 = aPB->Pave1();
1874 const BOPDS_Pave& aPave2 = aPB->Pave2();
1876 if (aMP.Add(aPave1)){
1881 if (aMP.Add(aPave2)){
1887 Standard_ASSERT_VOID(aNb == aMP.Extent(), "Abnormal number of paves");
1889 std::sort(pPaves.begin(), pPaves.end());
1891 for (i = 1; i <= aNb; ++i) {
1892 theLP.Append(pPaves(i));
1895 //=======================================================================
1896 // function: UpdateTolerance
1898 //=======================================================================
1899 void BOPDS_DS::UpdateEdgeTolerance(const Standard_Integer nE,
1900 const Standard_Real aTol)
1902 Standard_Integer nV;
1903 Standard_Real aTolV;
1905 BOPCol_ListIteratorOfListOfInteger aIt;
1907 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1908 aBB.UpdateEdge(aE, aTol);
1909 BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1910 Bnd_Box& aBoxE=aSIE.ChangeBox();
1911 BRepBndLib::Add(aE, aBoxE);
1912 aBoxE.SetGap(aBoxE.GetGap() + Precision::Confusion());
1914 const BOPCol_ListOfInteger& aLI = aSIE.SubShapes();
1915 aIt.Initialize(aLI);
1916 for (; aIt.More(); aIt.Next()) {
1918 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&Shape(nV);
1919 aTolV = BRep_Tool::Tolerance(aV);
1921 aBB.UpdateVertex(aV, aTol);
1922 BOPDS_ShapeInfo& aSIV = ChangeShapeInfo(nV);
1923 Bnd_Box& aBoxV = aSIV.ChangeBox();
1924 BRepBndLib::Add(aV, aBoxV);
1925 aBoxV.SetGap(aBoxV.GetGap() + Precision::Confusion());
1929 //=======================================================================
1930 //function : TotalShapes
1932 //=======================================================================
1933 void TotalShapes(const TopoDS_Shape& aS,
1934 Standard_Integer& aNbS,
1935 BOPCol_MapOfShape& aMS)
1938 TopoDS_Iterator aIt;
1941 for (; aIt.More(); aIt.Next()) {
1942 const TopoDS_Shape& aSx=aIt.Value();
1943 TotalShapes(aSx, aNbS, aMS);
1948 //=======================================================================
1949 //function : ComputeParameter
1951 //=======================================================================
1952 Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
1953 const TopoDS_Edge& aE)
1955 Standard_Real aT1, aT2, aTRet, aTolE2, aD2;
1957 Handle(Geom_Curve) aC3D;
1961 aEE.Orientation(TopAbs_FORWARD);
1965 aTolE2=BRep_Tool::Tolerance(aE);
1966 aTolE2=aTolE2*aTolE2;
1968 aPV=BRep_Tool::Pnt(aV);
1970 aC3D=BRep_Tool::Curve (aEE, aT1, aT2);
1973 aD2=aPC.SquareDistance(aPV);
1979 aD2=aPC.SquareDistance(aPV);
1986 //=======================================================================
1987 //function : BuildBndBoxSolid
1989 //=======================================================================
1990 void BOPDS_DS::BuildBndBoxSolid(const Standard_Integer theIndex,
1993 Standard_Boolean bIsOpenBox, bIsInverted;
1994 Standard_Integer nSh, nFc;
1995 Standard_Real aTolS, aTolFc;
1996 BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1;
1998 const BOPDS_ShapeInfo& aSI=ShapeInfo(theIndex);
1999 const TopoDS_Shape& aS=aSI.Shape();
2000 const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS));
2002 bIsOpenBox=Standard_False;
2005 const BOPCol_ListOfInteger& aLISh=aSI.SubShapes();
2006 aItLI.Initialize(aLISh);
2007 for (; aItLI.More(); aItLI.Next()) {
2009 const BOPDS_ShapeInfo& aSISh=ShapeInfo(nSh);
2010 if (aSISh.ShapeType()!=TopAbs_SHELL) {
2014 const BOPCol_ListOfInteger& aLIFc=aSISh.SubShapes();
2015 aItLI1.Initialize(aLIFc);
2016 for (; aItLI1.More(); aItLI1.Next()) {
2018 const BOPDS_ShapeInfo& aSIFc=ShapeInfo(nFc);
2019 if (aSIFc.ShapeType()!=TopAbs_FACE) {
2023 const Bnd_Box& aBFc=aSIFc.Box();
2027 bIsOpenBox=(aBFc.IsOpenXmin() || aBFc.IsOpenXmax() ||
2028 aBFc.IsOpenYmin() || aBFc.IsOpenYmax() ||
2029 aBFc.IsOpenZmin() || aBFc.IsOpenZmax());
2035 const TopoDS_Face& aFc=*((TopoDS_Face*)&aSIFc.Shape());
2036 aTolFc=BRep_Tool::Tolerance(aFc);
2040 }//for (; aItLI1.More(); aItLI1.Next()) {
2045 const TopoDS_Shell& aSh=*((TopoDS_Shell*)&aSISh.Shape());
2046 bIsOpenBox=BOPTools_AlgoTools::IsOpenShell(aSh);
2050 }//for (; aItLI.More(); aItLI.Next()) {
2056 bIsInverted=BOPTools_AlgoTools::IsInvertedSolid(aSolid);
2063 //=======================================================================
2064 //function : DefaultTolerances
2066 //=======================================================================
2067 void BOPDS_DS::SetDefaultTolerances()
2069 if (myFuzzyValue == 0.) {
2073 Standard_Boolean bAdd;
2074 Standard_Integer i, j, n1, n2, nS, nSOp, nSs;
2075 Standard_Integer anIntType, aNbFF, aNbFIn;
2076 Standard_Real aTolDef;
2077 TopAbs_ShapeEnum aTS1, aTS2;
2078 BOPCol_MapOfInteger aMICh;
2079 BOPCol_DataMapOfIntegerMapOfInteger aDMI;
2080 BOPCol_ListIteratorOfListOfInteger aItLI;
2081 BOPDS_MapIteratorMapOfPassKey aItPK;
2082 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
2083 BOPCol_MapIteratorOfMapOfInteger aItMI;
2084 BOPCol_DataMapIteratorOfDataMapOfIntegerReal aItDMIR;
2086 // 1. Collect interfered shapes
2087 // 1.1. Interferences V/V, V/E, V/F, E/E and E/F
2088 aItPK.Initialize(myInterfTB);
2089 for (; aItPK.More(); aItPK.Next()) {
2090 const BOPDS_PassKey& aPK = aItPK.Value();
2093 const BOPDS_ShapeInfo& aSI1 = ShapeInfo(n1);
2094 const BOPDS_ShapeInfo& aSI2 = ShapeInfo(n2);
2096 aTS1 = aSI1.ShapeType();
2097 aTS2 = aSI2.ShapeType();
2099 anIntType = BOPDS_Tools::TypeToInteger(aTS1, aTS2);
2100 if (anIntType < 5) {
2101 AddShapeAndSubShapes(n1, aSI1, aMICh);
2102 AddShapeAndSubShapes(n2, aSI2, aMICh);
2103 } // if (anIntType < 5) {
2104 } // for (; aIt.More(); aIt.Next()) {
2106 // 1.2 FaceInfo information
2107 aNbFF = myFaceInfoPool.Extent();
2108 for (i = 0; i < aNbFF; ++i) {
2109 const BOPDS_FaceInfo& aFI = myFaceInfoPool(i);
2111 if (aMICh.Contains(nS)) {
2115 aNbFIn = (aFI.PaveBlocksIn().Extent() +
2116 aFI.VerticesIn().Extent() +
2117 aFI.PaveBlocksSc().Extent() +
2118 aFI.VerticesSc().Extent());
2120 AddShapeAndSubShapes(nS, ShapeInfo(nS), aMICh);
2121 } // if (aNbFIn > 0) {
2122 } // for (i = 0; i < aNbFF; ++i) {
2124 // 1.3. Empty F/F interferences
2125 aNbFF = myInterfFF.Extent();
2126 for (i = 0; i < aNbFF; ++i) {
2127 BOPDS_InterfFF& aFF = myInterfFF(i);
2128 if ((aFF.Curves().Extent() == 0) &&
2129 (aFF.Points().Extent() == 0)) {
2130 aFF.Indices(n1, n2);
2131 for (j = 0; j < 2; ++j) {
2133 if (aMICh.Contains(nS)) {
2136 nSOp = !j ? n2 : n1;
2138 BOPCol_MapOfInteger aME, aMEOp;
2140 if (aDMI.IsBound(nS)) {
2141 aME = aDMI.Find(nS);
2143 CollectEdges(*this, nS, aME);
2147 if (aDMI.IsBound(nSOp)) {
2148 aMEOp = aDMI.Find(nSOp);
2150 CollectEdges(*this, nSOp, aMEOp);
2151 aDMI.Bind(nSOp, aMEOp);
2154 bAdd = Standard_True;
2155 aItMI.Initialize(aME);
2156 for (; aItMI.More(); aItMI.Next()) {
2157 nSs = aItMI.Value();
2158 if (!aMEOp.Contains(nSs)) {
2159 bAdd = Standard_False;
2165 AddShapeAndSubShapes(nS, ShapeInfo(nS), aMICh);
2167 AddShapeAndSubShapes(nSOp, ShapeInfo(nSOp), aMICh);
2170 } // for (j = 0; j < 2; ++j) {
2171 } //if ((aFF.Curves().Extent() == 0) &&
2172 } // for (i = 0; i < aNbFF; ++i) {
2174 // 2. Back to default tolerance values
2175 aItDMIR.Initialize(myToleranceMap);
2176 for (; aItDMIR.More(); aItDMIR.Next()) {
2179 if (aMICh.Contains(i)) {
2183 const BOPDS_ShapeInfo& aSI = ShapeInfo(i);
2184 aTolDef = aItDMIR.Value();
2185 aTS1 = aSI.ShapeType();
2187 case TopAbs_VERTEX: {
2188 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&aSI.Shape();
2189 const Handle(BRep_TVertex)& aTV =
2190 *((Handle(BRep_TVertex)*)&aV.TShape());
2191 aTV->Tolerance(aTolDef);
2195 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aSI.Shape();
2196 const Handle(BRep_TEdge)& aTE =
2197 *((Handle(BRep_TEdge)*)&aE.TShape());
2198 aTE->Tolerance(aTolDef);
2200 const BOPDS_ListOfPaveBlock& aLPB = PaveBlocks(i);
2201 aItPB.Initialize(aLPB);
2202 for (; aItPB.More(); aItPB.Next()) {
2203 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
2205 const TopoDS_Edge& aEIm = *(TopoDS_Edge*)&Shape(nS);
2206 const Handle(BRep_TEdge)& aTEIm =
2207 *((Handle(BRep_TEdge)*)&aEIm.TShape());
2208 aTEIm->Tolerance(aTolDef);
2213 const TopoDS_Face& aF = *(TopoDS_Face*)&aSI.Shape();
2214 const Handle(BRep_TFace)& aTF =
2215 *((Handle(BRep_TFace)*)&aF.TShape());
2216 aTF->Tolerance(aTolDef);
2221 } // switch (aTS1) {
2222 } // for (; aItDMIR.More(); aItDMIR.Next()) {
2225 //=======================================================================
2226 //function : AddShapeAndSubShapes
2228 //=======================================================================
2229 void AddShapeAndSubShapes(const Standard_Integer nS,
2230 const BOPDS_ShapeInfo& theSI,
2231 BOPCol_MapOfInteger& theMI)
2233 Standard_Integer nSs;
2234 if (theMI.Add(nS)) {
2235 const BOPCol_ListOfInteger& aLI = theSI.SubShapes();
2236 BOPCol_ListIteratorOfListOfInteger aItLI(aLI);
2237 for (; aItLI.More(); aItLI.Next()) {
2238 nSs = aItLI.Value();
2244 //=======================================================================
2245 //function : CollectEdges
2247 //=======================================================================
2248 void CollectEdges(const BOPDS_DS& theDS,
2249 const Standard_Integer nF,
2250 BOPCol_MapOfInteger& theMI)
2252 Standard_Integer i, j, aNbPB, nE, nEIm;
2253 BOPCol_ListIteratorOfListOfInteger aItLI;
2254 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
2257 const BOPDS_ShapeInfo& aSI = theDS.ShapeInfo(nF);
2258 const BOPCol_ListOfInteger& aLI = aSI.SubShapes();
2259 aItLI.Initialize(aLI);
2260 for (; aItLI.More(); aItLI.Next()) {
2262 const BOPDS_ShapeInfo& aSIE = theDS.ShapeInfo(nE);
2263 if (aSIE.ShapeType() != TopAbs_EDGE) {
2267 if (!aSIE.HasReference()) {
2272 const BOPDS_ListOfPaveBlock& aLPB = theDS.PaveBlocks(nE);
2273 aItLPB.Initialize(aLPB);
2274 for (; aItLPB.More(); aItLPB.Next()) {
2275 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
2281 const BOPDS_FaceInfo& aFI = theDS.FaceInfo(nF);
2282 const BOPDS_IndexedMapOfPaveBlock& aMPBIn = aFI.PaveBlocksIn();
2283 const BOPDS_IndexedMapOfPaveBlock& aMPBSc = aFI.PaveBlocksSc();
2285 for (i = 0; i < 2; ++i) {
2286 const BOPDS_IndexedMapOfPaveBlock& aMPB = !i ? aMPBIn : aMPBSc;
2287 aNbPB = aMPB.Extent();
2288 for (j = 1; j <= aNbPB; ++j) {
2289 const Handle(BOPDS_PaveBlock)& aPB = aMPB(j);
2296 //=======================================================================
2297 //function : UpdatePaveBlocksWithSDVertices
2299 //=======================================================================
2300 void BOPDS_DS::UpdatePaveBlocksWithSDVertices()
2302 Standard_Integer i, aNbPBP;
2303 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
2305 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
2308 for (i = 0; i < aNbPBP; ++i) {
2309 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
2311 aItPB.Initialize(aLPB);
2312 for (; aItPB.More(); aItPB.Next()) {
2313 Handle(BOPDS_PaveBlock)& aPB = aItPB.ChangeValue();
2314 UpdatePaveBlockWithSDVertices(aPB);
2315 }// for (; aItPB.More(); aItPB.Next()) {
2316 }// for (i = 0; i < aNbPBP; ++i) {
2318 //=======================================================================
2319 //function : UpdatePaveBlockWithSDVertices
2321 //=======================================================================
2322 void BOPDS_DS::UpdatePaveBlockWithSDVertices
2323 (const Handle(BOPDS_PaveBlock)& thePB)
2325 Standard_Integer nV1, nV2;
2326 BOPDS_Pave aPave1, aPave2;
2328 aPave1 = thePB->Pave1();
2329 aPave2 = thePB->Pave2();
2331 nV1 = aPave1.Index();
2332 nV2 = aPave2.Index();
2334 if (HasShapeSD(nV1, nV1)) {
2335 aPave1.SetIndex(nV1);
2336 thePB->SetPave1(aPave1);
2339 if (HasShapeSD(nV2, nV2)) {
2340 aPave2.SetIndex(nV2);
2341 thePB->SetPave2(aPave2);
2344 //=======================================================================
2345 //function : UpdateCommonBlockWithSDVertices
2347 //=======================================================================
2348 void BOPDS_DS::UpdateCommonBlockWithSDVertices
2349 (const Handle(BOPDS_CommonBlock)& theCB)
2351 const BOPDS_ListOfPaveBlock& aLPB = theCB->PaveBlocks();
2352 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
2353 for (; aItPB.More(); aItPB.Next()) {
2354 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
2355 UpdatePaveBlockWithSDVertices(aPB);
2358 //=======================================================================
2359 //function : InitPaveBlocksForVertex
2361 //=======================================================================
2362 void BOPDS_DS::InitPaveBlocksForVertex(const Standard_Integer theNV)
2364 Standard_Integer nE;
2365 BOPCol_ListIteratorOfListOfInteger aItLE;
2367 if (myMapVE.IsBound(theNV)) {
2368 const BOPCol_ListOfInteger& aLE=myMapVE.Find(theNV);
2369 aItLE.Initialize(aLE);
2370 for (; aItLE.More(); aItLE.Next()) {
2372 ChangePaveBlocks(nE);