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>
62 inline void ResetShape(const TopoDS_Shape& aS);
65 inline void ResetShapes(const TopoDS_Shape& aS);
68 void TotalShapes(const TopoDS_Shape& aS,
69 Standard_Integer& aNbS);
72 Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
73 const TopoDS_Edge& aE);
76 void AddShapeAndSubShapes(const Standard_Integer nS,
77 const BOPDS_ShapeInfo& theSI,
78 BOPCol_MapOfInteger& theMI);
81 void CollectEdges(const BOPDS_DS& theDS,
82 const Standard_Integer nF,
83 BOPCol_MapOfInteger& theMI);
85 //=======================================================================
88 //=======================================================================
91 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
92 myArguments(myAllocator),
93 myRanges(0,myAllocator),
94 myLines(0, myAllocator),
95 myMapShapeIndex(100, myAllocator),
96 myPaveBlocksPool(0,myAllocator),
97 myMapPBCB(100, myAllocator),
98 myFaceInfoPool(0, myAllocator),
99 myShapesSD(100, myAllocator),
100 myInterfTB(100, myAllocator),
101 myInterfVV(0, myAllocator),
102 myInterfVE(0, myAllocator),
103 myInterfVF(0, myAllocator),
104 myInterfEE(0, myAllocator),
105 myInterfEF(0, myAllocator),
106 myInterfFF(0, myAllocator),
107 myInterfVZ(0, myAllocator),
108 myInterfEZ(0, myAllocator),
109 myInterfFZ(0, myAllocator),
110 myInterfZZ(0, myAllocator),
112 myToleranceMap(100, myAllocator)
117 //=======================================================================
120 //=======================================================================
121 BOPDS_DS::BOPDS_DS(const Handle(NCollection_BaseAllocator)& theAllocator)
123 myAllocator(theAllocator),
124 myArguments(myAllocator),
125 myRanges(0, myAllocator),
126 myLines(0, myAllocator),
127 myMapShapeIndex(100, myAllocator),
128 myPaveBlocksPool(0, myAllocator),
129 myMapPBCB(100, myAllocator),
130 myFaceInfoPool(0, myAllocator),
131 myShapesSD(100, myAllocator),
132 myInterfTB(100, myAllocator),
133 myInterfVV(0, myAllocator),
134 myInterfVE(0, myAllocator),
135 myInterfVF(0, myAllocator),
136 myInterfEE(0, myAllocator),
137 myInterfEF(0, myAllocator),
138 myInterfFF(0, myAllocator),
139 myInterfVZ(0, myAllocator),
140 myInterfEZ(0, myAllocator),
141 myInterfFZ(0, myAllocator),
142 myInterfZZ(0, myAllocator),
144 myToleranceMap(100, myAllocator)
149 //=======================================================================
152 //=======================================================================
153 BOPDS_DS::~BOPDS_DS()
157 //=======================================================================
160 //=======================================================================
161 void BOPDS_DS::Clear()
170 myMapShapeIndex.Clear();
171 myPaveBlocksPool.Clear();
172 myFaceInfoPool.Clear();
186 myToleranceMap.Clear();
188 //=======================================================================
189 //function : SetArguments
191 //=======================================================================
192 void BOPDS_DS::SetArguments(const BOPCol_ListOfShape& theLS)
196 //=======================================================================
197 //function : Arguments
199 //=======================================================================
200 const BOPCol_ListOfShape& BOPDS_DS::Arguments()const
204 //=======================================================================
205 //function : Allocator
207 //=======================================================================
208 const Handle(NCollection_BaseAllocator)& BOPDS_DS::Allocator()const
213 //=======================================================================
214 //function : NbShapes
216 //=======================================================================
217 Standard_Integer BOPDS_DS::NbShapes()const
219 return myLines.Size();
221 //=======================================================================
222 //function : NbSourceShapes
224 //=======================================================================
225 Standard_Integer BOPDS_DS::NbSourceShapes()const
227 return myNbSourceShapes;
229 //=======================================================================
230 //function : NbRanges
232 //=======================================================================
233 Standard_Integer BOPDS_DS::NbRanges()const
235 return myRanges.Size();
237 //=======================================================================
240 //=======================================================================
241 const BOPDS_IndexRange& BOPDS_DS::Range(const Standard_Integer theI)const
243 return myRanges(theI);
245 //=======================================================================
248 //=======================================================================
249 Standard_Integer BOPDS_DS::Rank(const Standard_Integer theI)const
251 Standard_Integer i, aNb, iErr;
255 for(i=0; i<aNb; ++i) {
256 const BOPDS_IndexRange& aR=Range(i);
257 if (aR.Contains(theI)) {
263 //=======================================================================
264 //function : IsNewShape
266 //=======================================================================
267 Standard_Boolean BOPDS_DS::IsNewShape(const Standard_Integer theI)const
269 return theI>=NbSourceShapes();
271 //=======================================================================
274 //=======================================================================
275 Standard_Integer BOPDS_DS::Append(const BOPDS_ShapeInfo& theSI)
279 myLines.Append1()=theSI;
280 iX=myLines.Extent()-1;
284 //=======================================================================
287 //=======================================================================
288 Standard_Integer BOPDS_DS::Append(const TopoDS_Shape& theS)
292 myLines.Append1().SetShape(theS);
293 iX=myLines.Extent()-1;
296 //=======================================================================
297 //function : ShapeInfo
299 //=======================================================================
300 const BOPDS_ShapeInfo& BOPDS_DS::ShapeInfo
301 (const Standard_Integer theI)const
303 return myLines(theI);
305 //=======================================================================
306 //function : ChangeShapeInfo
308 //=======================================================================
309 BOPDS_ShapeInfo& BOPDS_DS::ChangeShapeInfo(const Standard_Integer theI)
311 BOPDS_ShapeInfo *pSI;
313 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI);
314 pSI=(BOPDS_ShapeInfo *)&aSI;
317 //=======================================================================
320 //=======================================================================
321 const TopoDS_Shape& BOPDS_DS::Shape(const Standard_Integer theI)const
324 const TopoDS_Shape& aS=ShapeInfo(theI).Shape();
327 //=======================================================================
330 //=======================================================================
331 Standard_Integer BOPDS_DS::Index(const TopoDS_Shape& theS)const
333 Standard_Integer iRet;
336 if (myMapShapeIndex.IsBound(theS)) {
337 iRet=myMapShapeIndex.Find(theS);
342 //=======================================================================
345 //=======================================================================
346 void BOPDS_DS::Init()
348 Standard_Integer i1, i2, j, aI, aNb, aNbS, aNbE, aNbSx;
349 Standard_Integer n1, n2, n3, nV, nW, nE, aNbF;
350 Standard_Real aTol, aFuzz;
351 TopAbs_ShapeEnum aTS;
352 TopoDS_Iterator aItS;
353 BOPCol_ListIteratorOfListOfInteger aIt1, aIt2, aIt3;
354 BOPCol_ListIteratorOfListOfShape aIt;
356 Handle(NCollection_BaseAllocator) aAllocator;
358 // 1 Append Source Shapes
359 aNb=myArguments.Extent();
364 myRanges.SetIncrement(aNb);
366 aIt.Initialize(myArguments);
367 for (; aIt.More(); aIt.Next()) {
368 const TopoDS_Shape& aSx=aIt.Value();
373 aIt.Initialize(myArguments);
374 for (; aIt.More(); aIt.Next()) {
375 const TopoDS_Shape& aSx=aIt.Value();
378 TotalShapes(aSx, aNbSx);
382 myLines.SetIncrement(2*aNbS);
383 //-----------------------------------------------------scope_1 f
385 NCollection_BaseAllocator::CommonBaseAllocator();
387 BOPCol_DataMapOfShapeInteger& aMSI=myMapShapeIndex;
391 aIt.Initialize(myArguments);
392 for (; aIt.More(); aIt.Next()) {
393 const TopoDS_Shape& aS=aIt.Value();
394 if (aMSI.IsBound(aS)) {
400 InitShape(aI, aS, aAllocator, aMSI);
403 aR.SetIndices(i1, i2);
408 aFuzz = myFuzzyValue / 2.;
409 myNbSourceShapes=NbShapes();
414 for (j=0; j<myNbSourceShapes; ++j) {
415 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
417 const TopoDS_Shape& aS=aSI.Shape();
422 if (aTS==TopAbs_VERTEX) {
423 Bnd_Box& aBox=aSI.ChangeBox();
424 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aS);
425 const gp_Pnt& aP=BRep_Tool::Pnt(aV);
427 const Handle(BRep_TVertex)& TV =
428 *((Handle(BRep_TVertex)*)&aV.TShape());
429 aTol = TV->Tolerance();
431 myToleranceMap.Bind(j, aTol);
441 for (j=0; j<myNbSourceShapes; ++j) {
442 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
445 if (aTS==TopAbs_EDGE) {
446 const TopoDS_Shape& aS=aSI.Shape();
447 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aS);
449 const Handle(BRep_TEdge)& TE =
450 *((Handle(BRep_TEdge)*)&aE.TShape());
451 aTol = TE->Tolerance();
453 myToleranceMap.Bind(j, aTol);
457 if (!BRep_Tool::Degenerated(aE)) {
458 Standard_Boolean bInf1, bInf2;
459 Standard_Integer aIx;
460 Standard_Real aT1, aT2;
462 Handle(Geom_Curve) aC3D;
466 BOPDS_ShapeInfo aSIx;
468 BOPCol_ListOfInteger& aLI=aSI.ChangeSubShapes();
471 aEx.Orientation(TopAbs_FORWARD);
473 aC3D=BRep_Tool::Curve (aEx, aT1, aT2);
474 bInf1=Precision::IsNegativeInfinite(aT1);
475 bInf2=Precision::IsPositiveInfinite(aT2);
479 aBB.MakeVertex(aVx, aPx, aTol);
480 aVx.Orientation(TopAbs_FORWARD);
483 aSIx.SetShapeType(TopAbs_VERTEX);
484 aSIx.SetFlag(1); //infinite flag
491 aBB.MakeVertex(aVx, aPx, aTol);
492 aVx.Orientation(TopAbs_REVERSED);
495 aSIx.SetShapeType(TopAbs_VERTEX);
496 aSIx.SetFlag(1);//infinite flag
506 Bnd_Box& aBox=aSI.ChangeBox();
507 BRepBndLib::Add(aE, aBox);
509 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
510 aIt1.Initialize(aLV);
511 for (; aIt1.More(); aIt1.Next()) {
513 BOPDS_ShapeInfo& aSIV=ChangeShapeInfo(nV);
514 Bnd_Box& aBx=aSIV.ChangeBox();
521 BOPCol_MapOfInteger aMI(100, aAllocator);
522 BOPCol_MapIteratorOfMapOfInteger aItMI;
525 for (j=0; j<myNbSourceShapes; ++j) {
526 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
529 if (aTS==TopAbs_FACE) {
530 const TopoDS_Shape& aS=aSI.Shape();
531 const TopoDS_Face& aF=*((TopoDS_Face*)&aS);
533 const Handle(BRep_TFace)& TF =
534 *((Handle(BRep_TFace)*)&aF.TShape());
535 aTol = TF->Tolerance();
537 myToleranceMap.Bind(j, aTol);
541 Bnd_Box& aBox=aSI.ChangeBox();
542 BRepBndLib::Add(aS, aBox);
544 BOPCol_ListOfInteger& aLW=aSI.ChangeSubShapes();
545 aIt1.Initialize(aLW);
546 for (; aIt1.More(); aIt1.Next()) {
548 BOPDS_ShapeInfo& aSIW=ChangeShapeInfo(nW);
550 const BOPCol_ListOfInteger& aLE=aSIW.SubShapes();
551 aIt2.Initialize(aLE);
552 for (; aIt2.More(); aIt2.Next()) {
554 BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
555 Bnd_Box& aBx=aSIE.ChangeBox();
559 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aSIE.Shape());
560 if (BRep_Tool::Degenerated(aE)) {
564 const BOPCol_ListOfInteger& aLV=aSIE.SubShapes();
565 aIt3.Initialize(aLV);
566 for (; aIt3.More(); aIt3.Next()) {
571 }//for (; aIt1.More(); aIt1.Next()) {
573 // pure internal vertices on the face
575 for (; aItS.More(); aItS.Next()) {
576 const TopoDS_Shape& aSx=aItS.Value();
577 if (aSx.ShapeType()==TopAbs_VERTEX){
584 // For a Face: change wires for BRep sub-shapes
586 aItMI.Initialize(aMI);
587 for (; aItMI.More(); aItMI.Next()) {
593 }//if (aTS==TopAbs_FACE) {
594 }//for (j=0; j<myNbSourceShapes; ++j) {
597 for (j=0; j<myNbSourceShapes; ++j) {
598 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
601 if (aTS!=TopAbs_SOLID) {
604 Bnd_Box& aBox=aSI.ChangeBox();
605 BuildBndBoxSolid(j, aBox);
608 // update sub-shapes by BRep comprising ones
610 BOPCol_ListOfInteger& aLI1=aSI.ChangeSubShapes();
612 aIt1.Initialize(aLI1);
613 for (; aIt1.More(); aIt1.Next()) {
615 BOPDS_ShapeInfo& aSI1=ChangeShapeInfo(n1);
616 if (aSI1.ShapeType()!=TopAbs_SHELL) {
620 const BOPCol_ListOfInteger& aLI2=aSI1.SubShapes();
621 aIt2.Initialize(aLI2);
622 for (; aIt2.More(); aIt2.Next()) {
624 BOPDS_ShapeInfo& aSI2=ChangeShapeInfo(n2);
625 if (aSI2.ShapeType()!=TopAbs_FACE) {
631 const BOPCol_ListOfInteger& aLI3=aSI2.SubShapes();
632 aIt3.Initialize(aLI3);
633 for (; aIt3.More(); aIt3.Next()) {
641 aItMI.Initialize(aMI);
642 for (; aItMI.More(); aItMI.Next()) {
647 }//for (j=0; j<myNbSourceShapes; ++j) {
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,
663 const Handle(NCollection_BaseAllocator)& theAllocator,
664 BOPCol_DataMapOfShapeInteger& aMSI)
666 Standard_Integer aIx;
668 BOPCol_ListIteratorOfListOfInteger aIt1;
670 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(aI);
671 aSI.SetShapeType(aS.ShapeType());
672 BOPCol_ListOfInteger& aLI=aSI.ChangeSubShapes();
674 BOPCol_MapOfInteger aM(100, theAllocator);
676 aIt1.Initialize(aLI);
677 for (; aIt1.More(); aIt1.Next()) {
678 aM.Add(aIt1.Value());
682 for (; aIt.More(); aIt.Next()) {
683 const TopoDS_Shape& aSx=aIt.Value();
684 if (aMSI.IsBound(aSx)) {
692 InitShape(aIx, aSx, theAllocator, aMSI);
700 //=======================================================================
701 //function : HasInterf
703 //=======================================================================
704 Standard_Boolean BOPDS_DS::HasInterf(const Standard_Integer theI) const
706 Standard_Integer n1, n2;
707 Standard_Boolean bRet;
708 BOPDS_MapIteratorMapOfPassKey aIt;
710 bRet = Standard_False;
712 aIt.Initialize(myInterfTB);
713 for (; aIt.More(); aIt.Next()) {
714 const BOPDS_PassKey& aPK = aIt.Value();
716 if (n1 == theI || n2 == theI) {
717 bRet = Standard_True;
724 //=======================================================================
725 //function : HasInterfShapeSubShapes
727 //=======================================================================
728 Standard_Boolean BOPDS_DS::HasInterfShapeSubShapes
729 (const Standard_Integer theI1,
730 const Standard_Integer theI2,
731 const Standard_Boolean theFlag)const
733 Standard_Boolean bRet;
735 BOPCol_ListIteratorOfListOfInteger aIt;
736 bRet = Standard_False;
738 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI2);
739 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
741 for (; aIt.More(); aIt.Next()) {
743 bRet=HasInterf(theI1, n2);
757 //=======================================================================
758 //function : HasInterfSubShapes
760 //=======================================================================
761 Standard_Boolean BOPDS_DS::HasInterfSubShapes
762 (const Standard_Integer theI1,
763 const Standard_Integer theI2)const
765 Standard_Boolean bRet;
767 BOPCol_ListIteratorOfListOfInteger aIt;
768 bRet = Standard_False;
770 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI1);
771 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
773 for (; aIt.More(); aIt.Next()) {
775 bRet=HasInterfShapeSubShapes(n1, theI2);
784 //=======================================================================
785 //function : PaveBlocksPool
787 //=======================================================================
788 const BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::PaveBlocksPool()const
790 return myPaveBlocksPool;
792 //=======================================================================
793 //function : ChangePaveBlocksPool
795 //=======================================================================
796 BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::ChangePaveBlocksPool()
798 return myPaveBlocksPool;
800 //=======================================================================
801 //function : HasPaveBlocks
803 //=======================================================================
804 Standard_Boolean BOPDS_DS::HasPaveBlocks(const Standard_Integer theI)const
806 return ShapeInfo(theI).HasReference();
808 //=======================================================================
809 //function : PaveBlocks
811 //=======================================================================
812 const BOPDS_ListOfPaveBlock& BOPDS_DS::PaveBlocks
813 (const Standard_Integer theI)const
815 static BOPDS_ListOfPaveBlock sLPB;
816 Standard_Integer aRef;
818 if (HasPaveBlocks(theI)) {
819 aRef=ShapeInfo(theI).Reference();
820 const BOPDS_ListOfPaveBlock& aLPB=myPaveBlocksPool(aRef);
825 //=======================================================================
826 //function : ChangePaveBlocks
828 //=======================================================================
829 BOPDS_ListOfPaveBlock& BOPDS_DS::ChangePaveBlocks
830 (const Standard_Integer theI)
832 Standard_Boolean bHasReference;
833 Standard_Integer aRef;
835 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
836 bHasReference=aSI.HasReference();
837 if (!bHasReference) {
838 InitPaveBlocks(theI);
841 aRef=aSI.Reference();
842 return myPaveBlocksPool(aRef);
844 //=======================================================================
845 //function : InitPaveBlocks
847 //=======================================================================
848 void BOPDS_DS::InitPaveBlocks(const Standard_Integer theI)
850 Standard_Integer nV=0, iRef, aNbV, nVSD;
852 TopAbs_Orientation aOrE;
854 BOPCol_ListIteratorOfListOfInteger aIt;
856 Handle(BOPDS_PaveBlock) aPB;
858 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
859 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aSI.Shape());
860 aOrE=aE.Orientation();
862 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
868 aPB=new BOPDS_PaveBlock;
869 aPB->SetOriginalEdge(theI);
871 if (aOrE!=TopAbs_INTERNAL) {
873 for (; aIt.More(); aIt.Next()) {
876 const BOPDS_ShapeInfo& aSIV=ShapeInfo(nV);
877 aV=*(TopoDS_Vertex*)(&aSIV.Shape());
878 if (aSIV.HasFlag()) {
879 aT=ComputeParameter(aV, aE);
882 aT=BRep_Tool::Parameter(aV, aE);
885 if (HasShapeSD(nV, nVSD)) {
889 aPave.SetParameter(aT);
890 aPB->AppendExtPave(aPave);
895 aT=BRep_Tool::Parameter(aV, aE);
897 aPave.SetParameter(aT);
898 aPB->AppendExtPave1(aPave);
903 TopoDS_Iterator aItE;
905 aItE.Initialize(aE, Standard_False, Standard_True);
906 for (; aItE.More(); aItE.Next()) {
907 aV=*((TopoDS_Vertex*)&aItE.Value());
910 const BOPDS_ShapeInfo& aSIV=ShapeInfo(nV);
911 if (aSIV.HasFlag()) {
912 aT=ComputeParameter(aV, aE);
915 aT=BRep_Tool::Parameter(aV, aE);
918 if (HasShapeSD(nV, nVSD)) {
922 aPave.SetParameter(aT);
923 aPB->AppendExtPave1(aPave);
927 BOPDS_ListOfPaveBlock &aLPB=myPaveBlocksPool.Append1();
928 iRef=myPaveBlocksPool.Extent()-1;
930 aPB->Update(aLPB, Standard_False);
931 aSI.SetReference(iRef);
933 //=======================================================================
934 //function : UpdatePaveBlocks
936 //=======================================================================
937 void BOPDS_DS::UpdatePaveBlocks()
939 Standard_Boolean bIsToUpdate;
940 Standard_Integer i, aNbPBP;
941 BOPDS_ListOfPaveBlock aLPBN(myAllocator);
942 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBN;
944 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
947 for (i=0; i<aNbPBP; ++i) {
948 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
950 aItPB.Initialize(aLPB);
951 for (; aItPB.More(); aItPB.Next()) {
952 Handle(BOPDS_PaveBlock)& aPB=aItPB.ChangeValue();
954 bIsToUpdate=aPB->IsToUpdate();
959 aItPBN.Initialize(aLPBN);
960 for (; aItPBN.More(); aItPBN.Next()) {
961 Handle(BOPDS_PaveBlock)& aPBN=aItPBN.ChangeValue();
966 }// for (; aItPB.More(); aItPB.Next()) {
967 }// for (i=0; i<aNbPBP; ++i) {
969 //=======================================================================
970 //function : UpdatePaveBlock
972 //=======================================================================
973 void BOPDS_DS::UpdatePaveBlock(const Handle(BOPDS_PaveBlock)& thePB)
975 if (!thePB->IsToUpdate()){
979 Standard_Integer nE, iRef;
980 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBN;
981 BOPDS_ListOfPaveBlock aLPBN(myAllocator);
982 Handle(BOPDS_PaveBlock) aPB;
984 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
986 nE=thePB->OriginalEdge();
987 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(nE);
988 iRef=aSI.Reference();
989 BOPDS_ListOfPaveBlock& aLPB=aPBP(iRef);
991 aItPB.Initialize(aLPB);
992 for (; aItPB.More(); aItPB.Next()) {
993 aPB=aItPB.ChangeValue();
997 aItPBN.Initialize(aLPBN);
998 for (; aItPBN.More(); aItPBN.Next()) {
999 Handle(BOPDS_PaveBlock)& aPBN=aItPBN.ChangeValue();
1007 //=======================================================================
1008 //function : UpdateCommonBlock
1010 //=======================================================================
1011 void BOPDS_DS::UpdateCommonBlock(const Handle(BOPDS_CommonBlock)& theCB)
1013 Standard_Integer nE, iRef, n1, n2;
1014 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBCB, aItPBN;
1015 BOPDS_DataMapIteratorOfDataMapOfPassKeyListOfPaveBlock aItMPKLPB;
1016 BOPDS_ListOfPaveBlock aLPBN;
1017 BOPDS_DataMapOfPassKeyListOfPaveBlock aMPKLPB;
1018 Handle(BOPDS_PaveBlock) aPB;
1019 Handle(BOPDS_CommonBlock) aCBx;
1022 const BOPDS_ListOfPaveBlock& aLPBCB=theCB->PaveBlocks();
1023 if (!aLPBCB.First()->IsToUpdate()){
1027 const BOPCol_ListOfInteger& aLF=theCB->Faces();
1029 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
1031 aItPBCB.Initialize(aLPBCB);
1032 for (; aItPBCB.More(); aItPBCB.Next()) {
1033 const Handle(BOPDS_PaveBlock)& aPBCB=aItPBCB.ChangeValue();
1035 nE=aPBCB->OriginalEdge();
1036 iRef=ChangeShapeInfo(nE).Reference();
1037 BOPDS_ListOfPaveBlock& aLPB=aPBP(iRef);
1039 aItPB.Initialize(aLPB);
1040 for (; aItPB.More(); aItPB.Next()) {
1041 aPB=aItPB.ChangeValue();
1047 aItPBN.Initialize(aLPBN);
1048 for (; aItPBN.More(); aItPBN.Next()) {
1049 Handle(BOPDS_PaveBlock)& aPBN=aItPBN.ChangeValue();
1052 aPBN->Indices(n1, n2);
1054 if (aMPKLPB.IsBound(aPK)) {
1055 BOPDS_ListOfPaveBlock& aLPBx=aMPKLPB.ChangeFind(aPK);
1059 BOPDS_ListOfPaveBlock aLPBx;
1061 aMPKLPB.Bind(aPK, aLPBx);
1070 aItMPKLPB.Initialize(aMPKLPB);
1071 for (; aItMPKLPB.More(); aItMPKLPB.Next()) {
1072 BOPDS_ListOfPaveBlock& aLPBx=aItMPKLPB.ChangeValue();
1074 while (aLPBx.Extent()) {
1075 Standard_Boolean bCoinside;
1076 Standard_Real aTol, aTolMax(0.);
1077 BOPDS_ListOfPaveBlock aLPBxN;
1079 aItPB.Initialize(aLPBx);
1080 for(; aItPB.More(); ) {
1081 const Handle(BOPDS_PaveBlock)& aPBx=aItPB.Value();
1082 if (aLPBxN.Extent()) {
1083 const Handle(BOPDS_PaveBlock)& aPBCx = aLPBxN.First();
1084 bCoinside = CheckCoincidence(aPBx, aPBCx);
1086 nE = aPBx->OriginalEdge();
1087 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1088 aTol = BRep_Tool::Tolerance(aE);
1090 //pave block with the max tolerance of the original edge
1091 //must be the first in the common block
1092 if (aTolMax < aTol) {
1094 aLPBxN.Prepend(aPBx);
1096 aLPBxN.Append(aPBx);
1098 aLPBx.Remove(aItPB);
1101 }//if (aLPBxN.Extent()) {
1103 nE = aPBx->OriginalEdge();
1104 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1105 aTolMax = BRep_Tool::Tolerance(aE);
1107 aLPBxN.Append(aPBx);
1108 aLPBx.Remove(aItPB);
1112 }//for(; aItPB.More(); ) {
1114 aCBx=new BOPDS_CommonBlock;
1115 aCBx->AddPaveBlocks(aLPBxN);
1116 aCBx->AddFaces(aLF);
1118 aItPB.Initialize(aLPBxN);
1119 for (; aItPB.More(); aItPB.Next()) {
1120 aPB=aItPB.ChangeValue();
1121 SetCommonBlock(aPB, aCBx);
1127 //=======================================================================
1128 // function: RealPaveBlock
1130 //=======================================================================
1131 Handle(BOPDS_PaveBlock) BOPDS_DS::RealPaveBlock
1132 (const Handle(BOPDS_PaveBlock)& thePB) const
1134 if (IsCommonBlock(thePB)) {
1135 const Handle(BOPDS_CommonBlock)& aCB = CommonBlock(thePB);
1136 const Handle(BOPDS_PaveBlock)& aPB = aCB->PaveBlock1();
1142 //=======================================================================
1143 // function: IsCommonBlockOnEdge
1145 //=======================================================================
1146 Standard_Boolean BOPDS_DS::IsCommonBlockOnEdge
1147 (const Handle(BOPDS_PaveBlock)& thePB) const
1149 if (IsCommonBlock(thePB)) {
1150 const Handle(BOPDS_CommonBlock)& aCB = CommonBlock(thePB);
1151 return aCB->PaveBlocks().Extent()>1;
1153 return Standard_False;
1156 //=======================================================================
1157 //function : IsCommonBlock
1159 //=======================================================================
1160 Standard_Boolean BOPDS_DS::IsCommonBlock
1161 (const Handle(BOPDS_PaveBlock)& thePB) const
1163 return myMapPBCB.IsBound(thePB);
1166 //=======================================================================
1167 //function : CommonBlock
1169 //=======================================================================
1170 Handle(BOPDS_CommonBlock) BOPDS_DS::CommonBlock
1171 (const Handle(BOPDS_PaveBlock)& thePB) const
1173 return (IsCommonBlock(thePB) ? myMapPBCB.Find(thePB) : NULL);
1176 //=======================================================================
1177 //function : SetCommonBlock
1179 //=======================================================================
1180 void BOPDS_DS::SetCommonBlock(const Handle(BOPDS_PaveBlock)& thePB,
1181 const Handle(BOPDS_CommonBlock)& theCB)
1183 if (IsCommonBlock(thePB)) {
1184 Handle(BOPDS_CommonBlock)& aCB = myMapPBCB.ChangeFind(thePB);
1188 myMapPBCB.Bind(thePB, theCB);
1196 //=======================================================================
1197 //function : FaceInfoPool
1199 //=======================================================================
1200 const BOPDS_VectorOfFaceInfo& BOPDS_DS::FaceInfoPool()const
1202 return myFaceInfoPool;
1204 //=======================================================================
1205 //function : HasFaceInfo
1207 //=======================================================================
1208 Standard_Boolean BOPDS_DS::HasFaceInfo(const Standard_Integer theI)const
1210 return ShapeInfo(theI).HasReference();
1212 //=======================================================================
1213 //function : FaceInfo
1215 //=======================================================================
1216 const BOPDS_FaceInfo& BOPDS_DS::FaceInfo(const Standard_Integer theI)const
1218 static BOPDS_FaceInfo sFI;
1219 Standard_Integer aRef;
1221 if (HasFaceInfo(theI)) {
1222 aRef=ShapeInfo(theI).Reference();
1223 const BOPDS_FaceInfo& aFI=myFaceInfoPool(aRef);
1228 //=======================================================================
1229 //function : ChangeFaceInfo
1231 //=======================================================================
1232 BOPDS_FaceInfo& BOPDS_DS::ChangeFaceInfo(const Standard_Integer theI)
1234 Standard_Boolean bHasReference;
1235 Standard_Integer aRef;
1236 BOPDS_FaceInfo* pFI;
1238 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1239 bHasReference=aSI.HasReference();
1240 if (!bHasReference) {
1244 aRef=aSI.Reference();
1245 const BOPDS_FaceInfo& aFI=myFaceInfoPool(aRef);
1246 pFI=(BOPDS_FaceInfo*)&aFI;
1249 //=======================================================================
1250 //function : InitFaceInfo
1252 //=======================================================================
1253 void BOPDS_DS::InitFaceInfo(const Standard_Integer theI)
1255 Standard_Integer iRef;
1257 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1258 BOPDS_FaceInfo &aFI=myFaceInfoPool.Append1();
1259 iRef=myFaceInfoPool.Extent()-1;
1260 aSI.SetReference(iRef);
1263 UpdateFaceInfoIn(theI);
1264 UpdateFaceInfoOn(theI);
1266 //=======================================================================
1267 //function : UpdateFaceInfoIn
1269 //=======================================================================
1270 void BOPDS_DS::UpdateFaceInfoIn(const Standard_Integer theI)
1272 Standard_Integer iRef;
1274 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1275 if (aSI.HasReference()) {
1276 iRef=aSI.Reference();
1277 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1279 BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.ChangePaveBlocksIn();
1280 BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
1283 FaceInfoIn(theI, aMPBIn, aMVIn);
1286 //=======================================================================
1287 //function : UpdateFaceInfoOn
1289 //=======================================================================
1290 void BOPDS_DS::UpdateFaceInfoOn(const Standard_Integer theI)
1292 Standard_Integer iRef;
1294 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1295 if (aSI.HasReference()) {
1296 iRef=aSI.Reference();
1297 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1299 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1300 BOPCol_MapOfInteger& aMVOn=aFI.ChangeVerticesOn();
1303 FaceInfoOn(theI, aMPBOn, aMVOn);
1306 //=======================================================================
1307 //function : FaceInfoOn
1309 //=======================================================================
1310 void BOPDS_DS::FaceInfoOn(const Standard_Integer theF,
1311 BOPDS_IndexedMapOfPaveBlock& theMPB,
1312 BOPCol_MapOfInteger& theMI)
1314 Standard_Integer nS, nSD, nV1, nV2;
1315 BOPCol_ListIteratorOfListOfInteger aIt;
1316 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1318 const BOPDS_ShapeInfo& aSI=ShapeInfo(theF);
1319 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
1320 aIt.Initialize(aLI);
1321 for (; aIt.More(); aIt.Next()) {
1323 const BOPDS_ShapeInfo& aSIE=ShapeInfo(nS);
1324 if (aSIE.ShapeType()==TopAbs_EDGE) {
1325 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nS);
1326 aItPB.Initialize(aLPB);
1327 for (; aItPB.More(); aItPB.Next()) {
1328 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
1329 aPB->Indices(nV1, nV2);
1332 Handle(BOPDS_PaveBlock) aPBR=RealPaveBlock(aPB);
1335 }//if (aSIE.ShapeType()==TopAbs_EDGE)
1337 // nE is TopAbs_VERTEX
1338 if (HasShapeSD(nS, nSD)) {
1345 //=======================================================================
1346 //function : FaceInfoIn
1348 //=======================================================================
1349 void BOPDS_DS::FaceInfoIn(const Standard_Integer theF,
1350 BOPDS_IndexedMapOfPaveBlock& theMPB,
1351 BOPCol_MapOfInteger& theMI)
1353 Standard_Integer i, aNbVF, aNbEF, nV, nE, nVSD;
1354 TopoDS_Iterator aItS;
1355 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1357 // 1. Pure internal vertices on the face
1358 const TopoDS_Shape& aF=Shape(theF);
1359 aItS.Initialize(aF);
1360 for (; aItS.More(); aItS.Next()) {
1361 const TopoDS_Shape& aSx=aItS.Value();
1362 if (aSx.ShapeType()==TopAbs_VERTEX){
1364 if (HasShapeSD(nV, nVSD)) {
1372 BOPDS_VectorOfInterfVF& aVFs=InterfVF();
1373 aNbVF=aVFs.Extent();
1374 for (i=0; i<aNbVF; ++i) {
1375 BOPDS_InterfVF& aVF=aVFs(i);
1376 if(aVF.Contains(theF)) {
1377 nV=aVF.OppositeIndex(theF);
1383 BOPDS_VectorOfInterfEF& aEFs=InterfEF();
1384 aNbEF=aEFs.Extent();
1385 for (i=0; i<aNbEF; ++i) {
1386 BOPDS_InterfEF& aEF=aEFs(i);
1387 if(aEF.Contains(theF)) {
1388 if(aEF.HasIndexNew(nV)) {
1392 nE=aEF.OppositeIndex(theF);
1393 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1394 aItPB.Initialize(aLPB);
1395 for (; aItPB.More(); aItPB.Next()) {
1396 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
1397 if (IsCommonBlock(aPB)) {
1398 const Handle(BOPDS_CommonBlock)& aCB=CommonBlock(aPB);
1399 if (aCB->Contains(theF)) {
1400 const Handle(BOPDS_PaveBlock)& aPB1=aCB->PaveBlock1();
1404 }// for (; aItPB.More(); aItPB.Next()) {
1406 }// if(aEF.Contains(theF)) {
1407 }// for (i=0; i<aNbEF; ++i) {
1410 //=======================================================================
1411 //function : RefineFaceInfoOn
1413 //=======================================================================
1414 void BOPDS_DS::RefineFaceInfoOn()
1416 Standard_Integer i, aNb, nF, aNbPB, j;
1417 BOPDS_IndexedMapOfPaveBlock aMPB;
1419 aNb=myFaceInfoPool.Extent();
1420 for (i=0; i<aNb; ++i) {
1421 BOPDS_FaceInfo &aFI=myFaceInfoPool(i);
1423 UpdateFaceInfoOn(nF);
1424 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1427 aMPB.Assign(aMPBOn);
1430 aNbPB=aMPB.Extent();
1431 for (j=1; j<=aNbPB; ++j) {
1432 const Handle(BOPDS_PaveBlock)& aPB=aMPB(j);
1433 if (aPB->HasEdge()) {
1439 //=======================================================================
1440 //function : AloneVertices
1442 //=======================================================================
1443 void BOPDS_DS::AloneVertices(const Standard_Integer theI,
1444 BOPCol_ListOfInteger& theLI)const
1446 if (HasFaceInfo(theI)) {
1448 Standard_Integer i, j, nV1, nV2, nV, aNbPB;
1449 BOPCol_MapIteratorOfMapOfInteger aItMI;
1451 BOPCol_MapOfInteger aMI(100, myAllocator);
1453 const BOPDS_FaceInfo& aFI=FaceInfo(theI);
1455 for (i = 0; i < 2; ++i) {
1456 const BOPDS_IndexedMapOfPaveBlock& aMPB=
1457 (!i) ? aFI.PaveBlocksIn() : aFI.PaveBlocksSc();
1458 aNbPB = aMPB.Extent();
1459 for (j = 1; j <= aNbPB; ++j) {
1460 const Handle(BOPDS_PaveBlock)& aPB = aMPB(j);
1461 aPB->Indices(nV1, nV2);
1467 for (i=0; i<2; ++i) {
1468 const BOPCol_MapOfInteger& aMIV=
1469 (!i) ? aFI.VerticesIn() : aFI.VerticesSc();
1470 aItMI.Initialize(aMIV);
1471 for (; aItMI.More(); aItMI.Next()) {
1482 //=======================================================================
1483 //function : VerticesOnIn
1485 //=======================================================================
1486 void BOPDS_DS::VerticesOnIn
1487 (const Standard_Integer nF1,
1488 const Standard_Integer nF2,
1489 BOPCol_MapOfInteger& aMI,
1490 BOPDS_IndexedMapOfPaveBlock& aMPB)const
1492 Standard_Integer i, j, nV, nV1, nV2, aNbPB;
1493 BOPCol_MapIteratorOfMapOfInteger aIt;
1494 BOPDS_IndexedMapOfPaveBlock pMPB[4];
1496 const BOPDS_FaceInfo& aFI1=FaceInfo(nF1);
1497 const BOPDS_FaceInfo& aFI2=FaceInfo(nF2);
1499 pMPB[0]=aFI1.PaveBlocksOn();
1500 pMPB[1]=aFI1.PaveBlocksIn();
1501 pMPB[2]=aFI2.PaveBlocksOn();
1502 pMPB[3]=aFI2.PaveBlocksIn();
1504 for (i=0; i<4; ++i) {
1505 aNbPB = pMPB[i].Extent();
1506 for (j = 1; j <= aNbPB; ++j) {
1507 const Handle(BOPDS_PaveBlock)& aPB = pMPB[i](j);
1509 aPB->Indices(nV1, nV2);
1515 const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
1516 const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
1517 const BOPCol_MapOfInteger& aMVOn2=aFI2.VerticesOn();
1518 const BOPCol_MapOfInteger& aMVIn2=aFI2.VerticesIn();
1520 for (i=0; i<2; ++i) {
1521 const BOPCol_MapOfInteger& aMV1=(!i) ? aMVOn1 : aMVIn1;
1522 aIt.Initialize(aMV1);
1523 for (; aIt.More(); aIt.Next()) {
1525 if (aMVOn2.Contains(nV) || aMVIn2.Contains(nV)) {
1531 //=======================================================================
1532 //function : SharedEdges
1534 //=======================================================================
1535 void BOPDS_DS::SharedEdges(const Standard_Integer nF1,
1536 const Standard_Integer nF2,
1537 BOPCol_ListOfInteger& theLI,
1538 const Handle(NCollection_BaseAllocator)& aAllocator)
1540 Standard_Integer nE, nSp;
1541 BOPCol_ListIteratorOfListOfInteger aItLI;
1542 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
1543 BOPCol_MapOfInteger aMI(100, aAllocator);
1545 const BOPDS_ShapeInfo& aSI1=ShapeInfo(nF1);
1546 const BOPCol_ListOfInteger& aLI1=aSI1.SubShapes();
1547 aItLI.Initialize(aLI1);
1548 for (; aItLI.More(); aItLI.Next()) {
1550 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1551 if(aSIE.ShapeType()==TopAbs_EDGE) {
1552 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1553 if (aLPB.IsEmpty()) {
1557 aItLPB.Initialize(aLPB);
1558 for (; aItLPB.More(); aItLPB.Next()) {
1559 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
1567 const BOPDS_ShapeInfo& aSI2=ShapeInfo(nF2);
1568 const BOPCol_ListOfInteger& aLI2=aSI2.SubShapes();
1569 aItLI.Initialize(aLI2);
1570 for (; aItLI.More(); aItLI.Next()) {
1572 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1573 if(aSIE.ShapeType()==TopAbs_EDGE) {
1574 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1575 if (aLPB.IsEmpty()) {
1576 if (aMI.Contains(nE)) {
1581 aItLPB.Initialize(aLPB);
1582 for (; aItLPB.More(); aItLPB.Next()) {
1583 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
1585 if (aMI.Contains(nSp)) {
1594 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1596 // same domain shapes
1598 //=======================================================================
1599 //function : ShapesSD
1601 //=======================================================================
1602 BOPCol_DataMapOfIntegerInteger& BOPDS_DS::ShapesSD()
1606 //=======================================================================
1607 //function : AddShapeSD
1609 //=======================================================================
1610 void BOPDS_DS::AddShapeSD(const Standard_Integer theIndex,
1611 const Standard_Integer theIndexSD)
1613 myShapesSD.Bind(theIndex, theIndexSD);
1615 //=======================================================================
1616 //function : HasShapeSD
1618 //=======================================================================
1619 Standard_Boolean BOPDS_DS::HasShapeSD
1620 (const Standard_Integer theIndex,
1621 Standard_Integer& theIndexSD)const
1623 Standard_Boolean bRet;
1625 bRet=myShapesSD.IsBound(theIndex);
1627 theIndexSD=myShapesSD.Find(theIndex);
1631 //=======================================================================
1634 //=======================================================================
1635 void BOPDS_DS::Dump()const
1637 Standard_Integer i, aNb, aNbSS;
1639 printf(" *** DS ***\n");
1641 printf(" Ranges:%d\n", aNb);
1642 for (i=0; i<aNb; ++i) {
1643 const BOPDS_IndexRange& aR=Range(i);
1648 aNbSS=NbSourceShapes();
1649 printf(" Shapes:%d\n", aNbSS);
1651 for (i=0; i<aNb; ++i) {
1652 const BOPDS_ShapeInfo& aSI=ShapeInfo(i);
1657 printf(" ****** adds\n");
1660 printf(" ******\n");
1663 //=======================================================================
1664 // function: CheckCoincidence
1666 //=======================================================================
1667 Standard_Boolean BOPDS_DS::CheckCoincidence
1668 (const Handle(BOPDS_PaveBlock)& aPB1,
1669 const Handle(BOPDS_PaveBlock)& aPB2)
1671 Standard_Boolean bRet;
1672 Standard_Integer nE1, nE2, aNbPoints;
1673 Standard_Real aT11, aT12, aT21, aT22, aT1m, aD, aTol, aT2x;
1676 bRet=Standard_False;
1678 aPB1->Range(aT11, aT12);
1679 aT1m=IntTools_Tools::IntermediatePoint (aT11, aT12);
1680 nE1=aPB1->OriginalEdge();
1681 const TopoDS_Edge& aE1=(*(TopoDS_Edge*)(&Shape(nE1)));
1682 BOPTools_AlgoTools::PointOnEdge(aE1, aT1m, aP1m);
1684 aPB2->Range(aT21, aT22);
1685 nE2=aPB2->OriginalEdge();
1686 const TopoDS_Edge& aE2=(*(TopoDS_Edge*)(&Shape(nE2)));
1689 Handle(Geom_Curve)aC2 = BRep_Tool::Curve (aE2, f, l);
1690 GeomAPI_ProjectPointOnCurve aPPC;
1691 aPPC.Init(aC2, f, l);
1693 aNbPoints=aPPC.NbPoints();
1695 aD=aPPC.LowerDistance();
1697 aTol=BRep_Tool::Tolerance(aE1);
1698 aTol=aTol+BRep_Tool::Tolerance(aE2);
1700 aT2x=aPPC.LowerDistanceParameter();
1701 if (aT2x>aT21 && aT2x<aT22) {
1708 //=======================================================================
1709 // function: SortPaveBlocks
1711 //=======================================================================
1712 void BOPDS_DS::SortPaveBlocks(const Handle(BOPDS_CommonBlock)& aCB)
1714 Standard_Integer theI;
1715 Standard_Boolean bToSort;
1716 bToSort = IsToSort(aCB, theI);
1721 Standard_Integer i(0);
1722 const BOPDS_ListOfPaveBlock& aLPB = aCB->PaveBlocks();
1723 BOPDS_ListOfPaveBlock aLPBN = aLPB;
1725 Handle(BOPDS_PaveBlock) aPB;
1726 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1728 aIt.Initialize(aLPBN);
1729 for (aIt.Next(); aIt.More(); ) {
1740 aCB->AddPaveBlocks(aLPBN);
1742 //=======================================================================
1743 // function: IsToSort
1745 //=======================================================================
1746 Standard_Boolean BOPDS_DS::IsToSort
1747 (const Handle(BOPDS_CommonBlock)& aCB,
1748 Standard_Integer& theI)
1750 Standard_Boolean bRet;
1751 bRet = Standard_False;
1752 const BOPDS_ListOfPaveBlock& aLPB = aCB->PaveBlocks();
1753 if (aLPB.Extent()==1) {
1757 Standard_Integer nE;
1758 Standard_Real aTolMax, aTol;
1759 Handle(BOPDS_PaveBlock) aPB;
1761 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1764 nE = aPB->OriginalEdge();
1765 aE = (*(TopoDS_Edge *)(&Shape(nE)));
1766 aTolMax = BRep_Tool::Tolerance(aE);
1769 aIt.Initialize(aLPB);
1770 for (aIt.Next(); aIt.More(); aIt.Next()) {
1773 nE = aPB->OriginalEdge();
1774 aE = (*(TopoDS_Edge *)(&Shape(nE)));
1775 aTol = BRep_Tool::Tolerance(aE);
1776 if (aTolMax < aTol) {
1778 bRet = Standard_True;
1784 //=======================================================================
1785 // function: IsSubShape
1787 //=======================================================================
1788 Standard_Boolean BOPDS_DS::IsSubShape
1789 (const Standard_Integer theI1,
1790 const Standard_Integer theI2)
1792 Standard_Boolean bRet;
1793 Standard_Integer nS;
1794 bRet = Standard_False;
1796 BOPCol_ListIteratorOfListOfInteger aItLI;
1798 const BOPDS_ShapeInfo& aSI = ShapeInfo(theI2);
1799 const BOPCol_ListOfInteger& aLI = aSI.SubShapes();
1800 aItLI.Initialize(aLI);
1801 for(;aItLI.More(); aItLI.Next()) {
1804 bRet = Standard_True;
1812 //=======================================================================
1815 //=======================================================================
1816 void BOPDS_DS::Paves(const Standard_Integer theEdge,
1817 BOPDS_ListOfPave& theLP)
1819 Standard_Integer aNb, i;
1820 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1821 BOPDS_MapOfPave aMP;
1823 const BOPDS_ListOfPaveBlock& aLPB = PaveBlocks(theEdge);
1824 aNb = aLPB.Extent() + 1;
1829 BOPDS_VectorOfPave pPaves(1, aNb);
1832 aIt.Initialize(aLPB);
1833 for (; aIt.More(); aIt.Next()) {
1834 const Handle(BOPDS_PaveBlock)& aPB = aIt.Value();
1835 const BOPDS_Pave& aPave1 = aPB->Pave1();
1836 const BOPDS_Pave& aPave2 = aPB->Pave2();
1838 if (aMP.Add(aPave1)){
1843 if (aMP.Add(aPave2)){
1849 Standard_ASSERT_VOID(aNb == aMP.Extent(), "Abnormal number of paves");
1851 std::sort(pPaves.begin(), pPaves.end());
1853 for (i = 1; i <= aNb; ++i) {
1854 theLP.Append(pPaves(i));
1858 //=======================================================================
1859 // function: UpdateTolerance
1861 //=======================================================================
1862 void BOPDS_DS::UpdateEdgeTolerance(const Standard_Integer nE,
1863 const Standard_Real aTol)
1865 Standard_Integer nV;
1866 Standard_Real aTolV;
1868 BOPCol_ListIteratorOfListOfInteger aIt;
1870 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1871 aBB.UpdateEdge(aE, aTol);
1872 BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1873 Bnd_Box& aBoxE=aSIE.ChangeBox();
1874 BRepBndLib::Add(aE, aBoxE);
1876 const BOPCol_ListOfInteger& aLI = aSIE.SubShapes();
1877 aIt.Initialize(aLI);
1878 for (; aIt.More(); aIt.Next()) {
1880 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&Shape(nV);
1881 aTolV = BRep_Tool::Tolerance(aV);
1883 aBB.UpdateVertex(aV, aTol);
1884 BOPDS_ShapeInfo& aSIV = ChangeShapeInfo(nV);
1885 Bnd_Box& aBoxV = aSIV.ChangeBox();
1886 BRepBndLib::Add(aV, aBoxV);
1891 //=======================================================================
1892 //function : TotalShapes
1894 //=======================================================================
1895 void TotalShapes(const TopoDS_Shape& aS,
1896 Standard_Integer& aNbS)
1900 pS=(TopoDS_Shape *)&aS;
1901 if (!pS->Checked()) {
1902 TopoDS_Iterator aIt;
1907 for (; aIt.More(); aIt.Next()) {
1908 const TopoDS_Shape& aSx=aIt.Value();
1909 TotalShapes(aSx, aNbS);
1913 //=======================================================================
1914 //function : ResetShape
1916 //=======================================================================
1917 void ResetShape(const TopoDS_Shape& aS)
1921 pS=(TopoDS_Shape *)&aS;
1924 //=======================================================================
1925 //function : ResetShape
1927 //=======================================================================
1928 void ResetShapes(const TopoDS_Shape& aS)
1930 TopoDS_Iterator aIt;
1934 for (; aIt.More(); aIt.Next()) {
1935 const TopoDS_Shape& aSx=aIt.Value();
1939 //=======================================================================
1940 //function : ComputeParameter
1942 //=======================================================================
1943 Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
1944 const TopoDS_Edge& aE)
1946 Standard_Real aT1, aT2, aTRet, aTolE2, aD2;
1948 Handle(Geom_Curve) aC3D;
1952 aEE.Orientation(TopAbs_FORWARD);
1956 aTolE2=BRep_Tool::Tolerance(aE);
1957 aTolE2=aTolE2*aTolE2;
1959 aPV=BRep_Tool::Pnt(aV);
1961 aC3D=BRep_Tool::Curve (aEE, aT1, aT2);
1964 aD2=aPC.SquareDistance(aPV);
1970 aD2=aPC.SquareDistance(aPV);
1977 //=======================================================================
1978 //function : BuildBndBoxSolid
1980 //=======================================================================
1981 void BOPDS_DS::BuildBndBoxSolid(const Standard_Integer theIndex,
1984 Standard_Boolean bIsOpenBox, bIsInverted;
1985 Standard_Integer nSh, nFc;
1986 Standard_Real aTolS, aTolFc;
1987 BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1;
1989 const BOPDS_ShapeInfo& aSI=ShapeInfo(theIndex);
1990 const TopoDS_Shape& aS=aSI.Shape();
1991 const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS));
1993 bIsOpenBox=Standard_False;
1996 const BOPCol_ListOfInteger& aLISh=aSI.SubShapes();
1997 aItLI.Initialize(aLISh);
1998 for (; aItLI.More(); aItLI.Next()) {
2000 const BOPDS_ShapeInfo& aSISh=ShapeInfo(nSh);
2001 if (aSISh.ShapeType()!=TopAbs_SHELL) {
2005 const BOPCol_ListOfInteger& aLIFc=aSISh.SubShapes();
2006 aItLI1.Initialize(aLIFc);
2007 for (; aItLI1.More(); aItLI1.Next()) {
2009 const BOPDS_ShapeInfo& aSIFc=ShapeInfo(nFc);
2010 if (aSIFc.ShapeType()!=TopAbs_FACE) {
2014 const Bnd_Box& aBFc=aSIFc.Box();
2018 bIsOpenBox=(aBFc.IsOpenXmin() || aBFc.IsOpenXmax() ||
2019 aBFc.IsOpenYmin() || aBFc.IsOpenYmax() ||
2020 aBFc.IsOpenZmin() || aBFc.IsOpenZmax());
2026 const TopoDS_Face& aFc=*((TopoDS_Face*)&aSIFc.Shape());
2027 aTolFc=BRep_Tool::Tolerance(aFc);
2031 }//for (; aItLI1.More(); aItLI1.Next()) {
2036 const TopoDS_Shell& aSh=*((TopoDS_Shell*)&aSISh.Shape());
2037 bIsOpenBox=BOPTools_AlgoTools::IsOpenShell(aSh);
2041 }//for (; aItLI.More(); aItLI.Next()) {
2047 bIsInverted=BOPTools_AlgoTools::IsInvertedSolid(aSolid);
2054 //=======================================================================
2055 //function : DefaultTolerances
2057 //=======================================================================
2058 void BOPDS_DS::SetDefaultTolerances()
2060 if (myFuzzyValue == 0.) {
2064 Standard_Boolean bAdd;
2065 Standard_Integer i, j, n1, n2, nS, nSOp, nSs;
2066 Standard_Integer anIntType, aNbFF, aNbFIn;
2067 Standard_Real aTolDef;
2068 TopAbs_ShapeEnum aTS1, aTS2;
2069 BOPCol_MapOfInteger aMICh;
2070 BOPCol_DataMapOfIntegerMapOfInteger aDMI;
2071 BOPCol_ListIteratorOfListOfInteger aItLI;
2072 BOPDS_MapIteratorMapOfPassKey aItPK;
2073 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
2074 BOPCol_MapIteratorOfMapOfInteger aItMI;
2075 BOPCol_DataMapIteratorOfDataMapOfIntegerReal aItDMIR;
2077 // 1. Collect interfered shapes
2078 // 1.1. Interferences V/V, V/E, V/F, E/E and E/F
2079 aItPK.Initialize(myInterfTB);
2080 for (; aItPK.More(); aItPK.Next()) {
2081 const BOPDS_PassKey& aPK = aItPK.Value();
2084 const BOPDS_ShapeInfo& aSI1 = ShapeInfo(n1);
2085 const BOPDS_ShapeInfo& aSI2 = ShapeInfo(n2);
2087 aTS1 = aSI1.ShapeType();
2088 aTS2 = aSI2.ShapeType();
2090 anIntType = BOPDS_Tools::TypeToInteger(aTS1, aTS2);
2091 if (anIntType < 5) {
2092 AddShapeAndSubShapes(n1, aSI1, aMICh);
2093 AddShapeAndSubShapes(n2, aSI2, aMICh);
2094 } // if (anIntType < 5) {
2095 } // for (; aIt.More(); aIt.Next()) {
2097 // 1.2 FaceInfo information
2098 aNbFF = myFaceInfoPool.Extent();
2099 for (i = 0; i < aNbFF; ++i) {
2100 const BOPDS_FaceInfo& aFI = myFaceInfoPool(i);
2102 if (aMICh.Contains(nS)) {
2106 aNbFIn = (aFI.PaveBlocksIn().Extent() +
2107 aFI.VerticesIn().Extent() +
2108 aFI.PaveBlocksSc().Extent() +
2109 aFI.VerticesSc().Extent());
2111 AddShapeAndSubShapes(nS, ShapeInfo(nS), aMICh);
2112 } // if (aNbFIn > 0) {
2113 } // for (i = 0; i < aNbFF; ++i) {
2115 // 1.3. Empty F/F interferences
2116 aNbFF = myInterfFF.Extent();
2117 for (i = 0; i < aNbFF; ++i) {
2118 BOPDS_InterfFF& aFF = myInterfFF(i);
2119 if ((aFF.Curves().Extent() == 0) &&
2120 (aFF.Points().Extent() == 0)) {
2121 aFF.Indices(n1, n2);
2122 for (j = 0; j < 2; ++j) {
2124 if (aMICh.Contains(nS)) {
2127 nSOp = !j ? n2 : n1;
2129 BOPCol_MapOfInteger aME, aMEOp;
2131 if (aDMI.IsBound(nS)) {
2132 aME = aDMI.Find(nS);
2134 CollectEdges(*this, nS, aME);
2138 if (aDMI.IsBound(nSOp)) {
2139 aMEOp = aDMI.Find(nSOp);
2141 CollectEdges(*this, nSOp, aMEOp);
2142 aDMI.Bind(nSOp, aMEOp);
2145 bAdd = Standard_True;
2146 aItMI.Initialize(aME);
2147 for (; aItMI.More(); aItMI.Next()) {
2148 nSs = aItMI.Value();
2149 if (!aMEOp.Contains(nSs)) {
2150 bAdd = Standard_False;
2156 AddShapeAndSubShapes(nS, ShapeInfo(nS), aMICh);
2158 AddShapeAndSubShapes(nSOp, ShapeInfo(nSOp), aMICh);
2161 } // for (j = 0; j < 2; ++j) {
2162 } //if ((aFF.Curves().Extent() == 0) &&
2163 } // for (i = 0; i < aNbFF; ++i) {
2165 // 2. Back to default tolerance values
2166 aItDMIR.Initialize(myToleranceMap);
2167 for (; aItDMIR.More(); aItDMIR.Next()) {
2170 if (aMICh.Contains(i)) {
2174 const BOPDS_ShapeInfo& aSI = ShapeInfo(i);
2175 aTolDef = aItDMIR.Value();
2176 aTS1 = aSI.ShapeType();
2178 case TopAbs_VERTEX: {
2179 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&aSI.Shape();
2180 const Handle(BRep_TVertex)& aTV =
2181 *((Handle(BRep_TVertex)*)&aV.TShape());
2182 aTV->Tolerance(aTolDef);
2186 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aSI.Shape();
2187 const Handle(BRep_TEdge)& aTE =
2188 *((Handle(BRep_TEdge)*)&aE.TShape());
2189 aTE->Tolerance(aTolDef);
2191 const BOPDS_ListOfPaveBlock& aLPB = PaveBlocks(i);
2192 aItPB.Initialize(aLPB);
2193 for (; aItPB.More(); aItPB.Next()) {
2194 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
2196 const TopoDS_Edge& aEIm = *(TopoDS_Edge*)&Shape(nS);
2197 const Handle(BRep_TEdge)& aTEIm =
2198 *((Handle(BRep_TEdge)*)&aEIm.TShape());
2199 aTEIm->Tolerance(aTolDef);
2204 const TopoDS_Face& aF = *(TopoDS_Face*)&aSI.Shape();
2205 const Handle(BRep_TFace)& aTF =
2206 *((Handle(BRep_TFace)*)&aF.TShape());
2207 aTF->Tolerance(aTolDef);
2212 } // switch (aTS1) {
2213 } // for (; aItDMIR.More(); aItDMIR.Next()) {
2216 //=======================================================================
2217 //function : AddShapeAndSubShapes
2219 //=======================================================================
2220 void AddShapeAndSubShapes(const Standard_Integer nS,
2221 const BOPDS_ShapeInfo& theSI,
2222 BOPCol_MapOfInteger& theMI)
2224 Standard_Integer nSs;
2225 if (theMI.Add(nS)) {
2226 const BOPCol_ListOfInteger& aLI = theSI.SubShapes();
2227 BOPCol_ListIteratorOfListOfInteger aItLI(aLI);
2228 for (; aItLI.More(); aItLI.Next()) {
2229 nSs = aItLI.Value();
2235 //=======================================================================
2236 //function : CollectEdges
2238 //=======================================================================
2239 void CollectEdges(const BOPDS_DS& theDS,
2240 const Standard_Integer nF,
2241 BOPCol_MapOfInteger& theMI)
2243 Standard_Integer i, j, aNbPB, nE, nEIm;
2244 BOPCol_ListIteratorOfListOfInteger aItLI;
2245 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
2248 const BOPDS_ShapeInfo& aSI = theDS.ShapeInfo(nF);
2249 const BOPCol_ListOfInteger& aLI = aSI.SubShapes();
2250 aItLI.Initialize(aLI);
2251 for (; aItLI.More(); aItLI.Next()) {
2253 const BOPDS_ShapeInfo& aSIE = theDS.ShapeInfo(nE);
2254 if (aSIE.ShapeType() != TopAbs_EDGE) {
2258 if (!aSIE.HasReference()) {
2263 const BOPDS_ListOfPaveBlock& aLPB = theDS.PaveBlocks(nE);
2264 aItLPB.Initialize(aLPB);
2265 for (; aItLPB.More(); aItLPB.Next()) {
2266 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
2272 const BOPDS_FaceInfo& aFI = theDS.FaceInfo(nF);
2273 const BOPDS_IndexedMapOfPaveBlock& aMPBIn = aFI.PaveBlocksIn();
2274 const BOPDS_IndexedMapOfPaveBlock& aMPBSc = aFI.PaveBlocksSc();
2276 for (i = 0; i < 2; ++i) {
2277 const BOPDS_IndexedMapOfPaveBlock& aMPB = !i ? aMPBIn : aMPBSc;
2278 aNbPB = aMPB.Extent();
2279 for (j = 1; j <= aNbPB; ++j) {
2280 const Handle(BOPDS_PaveBlock)& aPB = aMPB(j);