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.
15 #include <BOPDS_DS.ixx>
17 #include <Standard_Assert.hxx>
19 #include <NCollection_IncAllocator.hxx>
20 #include <NCollection_BaseAllocator.hxx>
23 #include <Bnd_Box.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopoDS_Iterator.hxx>
27 #include <TopoDS_Vertex.hxx>
28 #include <TopoDS_Edge.hxx>
29 #include <TopoDS_Face.hxx>
30 #include <BRep_Tool.hxx>
32 #include <BRepBndLib.hxx>
34 #include <BOPCol_MapOfInteger.hxx>
35 #include <BOPCol_ListOfInteger.hxx>
36 #include <BOPCol_DataMapOfShapeInteger.hxx>
38 #include <BOPDS_IndexRange.hxx>
39 #include <BOPDS_ShapeInfo.hxx>
40 #include <BOPDS_PassKey.hxx>
41 #include <BOPDS_DataMapOfPassKeyListOfPaveBlock.hxx>
42 #include <BOPDS_PassKey.hxx>
43 #include <BOPDS_MapOfPave.hxx>
44 #include <BOPDS_MapOfPaveBlock.hxx>
45 #include <BOPDS_VectorOfPave.hxx>
47 #include <Geom_Curve.hxx>
48 #include <BRep_Builder.hxx>
49 #include <Precision.hxx>
50 #include <IntTools_Tools.hxx>
51 #include <BOPTools_AlgoTools.hxx>
52 #include <GeomAPI_ProjectPointOnCurve.hxx>
58 inline void ResetShape(const TopoDS_Shape& aS);
61 inline void ResetShapes(const TopoDS_Shape& aS);
64 void TotalShapes(const TopoDS_Shape& aS,
65 Standard_Integer& aNbS);
68 Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
69 const TopoDS_Edge& aE);
71 //=======================================================================
74 //=======================================================================
77 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
78 myArguments(myAllocator),
79 myRanges(myAllocator),
81 myMapShapeIndex(100, myAllocator),
82 myPaveBlocksPool(myAllocator),
83 myMapPBCB(100, myAllocator),
84 myFaceInfoPool(myAllocator),
85 myShapesSD(100, myAllocator),
86 myInterfTB(100, myAllocator),
87 myInterfVV(myAllocator),
88 myInterfVE(myAllocator),
89 myInterfVF(myAllocator),
90 myInterfEE(myAllocator),
91 myInterfEF(myAllocator),
92 myInterfFF(myAllocator),
93 myInterfVZ(myAllocator),
94 myInterfEZ(myAllocator),
95 myInterfFZ(myAllocator),
96 myInterfZZ(myAllocator)
101 //=======================================================================
104 //=======================================================================
105 BOPDS_DS::BOPDS_DS(const Handle(NCollection_BaseAllocator)& theAllocator)
107 myAllocator(theAllocator),
108 myArguments(myAllocator),
109 myRanges(myAllocator),
110 myLines(myAllocator),
111 myMapShapeIndex(100, myAllocator),
112 myPaveBlocksPool(myAllocator),
113 myMapPBCB(100, myAllocator),
114 myFaceInfoPool(myAllocator),
115 myShapesSD(100, myAllocator),
116 myInterfTB(100, myAllocator),
117 myInterfVV(myAllocator),
118 myInterfVE(myAllocator),
119 myInterfVF(myAllocator),
120 myInterfEE(myAllocator),
121 myInterfEF(myAllocator),
122 myInterfFF(myAllocator),
123 myInterfVZ(myAllocator),
124 myInterfEZ(myAllocator),
125 myInterfFZ(myAllocator),
126 myInterfZZ(myAllocator)
131 //=======================================================================
134 //=======================================================================
135 BOPDS_DS::~BOPDS_DS()
139 //=======================================================================
142 //=======================================================================
143 void BOPDS_DS::Clear()
151 myMapShapeIndex.Clear();
152 myPaveBlocksPool.Clear();
153 myFaceInfoPool.Clear();
168 //=======================================================================
169 //function : SetArguments
171 //=======================================================================
172 void BOPDS_DS::SetArguments(const BOPCol_ListOfShape& theLS)
176 //=======================================================================
177 //function : Arguments
179 //=======================================================================
180 const BOPCol_ListOfShape& BOPDS_DS::Arguments()const
184 //=======================================================================
185 //function : Allocator
187 //=======================================================================
188 const Handle(NCollection_BaseAllocator)& BOPDS_DS::Allocator()const
193 //=======================================================================
194 //function : NbShapes
196 //=======================================================================
197 Standard_Integer BOPDS_DS::NbShapes()const
199 return myLines.Size();
201 //=======================================================================
202 //function : NbSourceShapes
204 //=======================================================================
205 Standard_Integer BOPDS_DS::NbSourceShapes()const
207 return myNbSourceShapes;
209 //=======================================================================
210 //function : NbRanges
212 //=======================================================================
213 Standard_Integer BOPDS_DS::NbRanges()const
215 return myRanges.Size();
217 //=======================================================================
220 //=======================================================================
221 const BOPDS_IndexRange& BOPDS_DS::Range(const Standard_Integer theI)const
223 return myRanges(theI);
225 //=======================================================================
228 //=======================================================================
229 Standard_Integer BOPDS_DS::Rank(const Standard_Integer theI)const
231 Standard_Integer i, aNb, iErr;
235 for(i=0; i<aNb; ++i) {
236 const BOPDS_IndexRange& aR=Range(i);
237 if (aR.Contains(theI)) {
243 //=======================================================================
244 //function : IsNewShape
246 //=======================================================================
247 Standard_Boolean BOPDS_DS::IsNewShape(const Standard_Integer theI)const
249 return theI>=NbSourceShapes();
251 //=======================================================================
254 //=======================================================================
255 Standard_Integer BOPDS_DS::Append(const BOPDS_ShapeInfo& theSI)
259 iX=myLines.Append()-1;
263 //=======================================================================
266 //=======================================================================
267 Standard_Integer BOPDS_DS::Append(const TopoDS_Shape& theS)
271 iX=myLines.Append()-1;
272 myLines(iX).SetShape(theS);
275 //=======================================================================
276 //function : ShapeInfo
278 //=======================================================================
279 const BOPDS_ShapeInfo& BOPDS_DS::ShapeInfo
280 (const Standard_Integer theI)const
282 return myLines(theI);
284 //=======================================================================
285 //function : ChangeShapeInfo
287 //=======================================================================
288 BOPDS_ShapeInfo& BOPDS_DS::ChangeShapeInfo(const Standard_Integer theI)
290 BOPDS_ShapeInfo *pSI;
292 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI);
293 pSI=(BOPDS_ShapeInfo *)&aSI;
296 //=======================================================================
299 //=======================================================================
300 const TopoDS_Shape& BOPDS_DS::Shape(const Standard_Integer theI)const
302 const TopoDS_Shape& aS=ShapeInfo(theI).Shape();
305 //=======================================================================
308 //=======================================================================
309 Standard_Integer BOPDS_DS::Index(const TopoDS_Shape& theS)const
311 Standard_Integer iRet;
314 if (myMapShapeIndex.IsBound(theS)) {
315 iRet=myMapShapeIndex.Find(theS);
320 //=======================================================================
323 //=======================================================================
324 void BOPDS_DS::Init()
326 Standard_Integer i1, i2, j, aI, aNb, aNbS, aNbE, aNbSx;
327 Standard_Integer n1, n2, n3, nV, nW, nE, aNbF;
329 TopAbs_ShapeEnum aTS;
330 TopoDS_Iterator aItS;
331 BOPCol_ListIteratorOfListOfInteger aIt1, aIt2, aIt3;
332 BOPCol_ListIteratorOfListOfShape aIt;
334 Handle(NCollection_IncAllocator) aAllocator;
336 // 1 Append Source Shapes
337 aNb=myArguments.Extent();
342 myRanges.SetStartSize(aNb);
345 aIt.Initialize(myArguments);
346 for (; aIt.More(); aIt.Next()) {
347 const TopoDS_Shape& aSx=aIt.Value();
352 aIt.Initialize(myArguments);
353 for (; aIt.More(); aIt.Next()) {
354 const TopoDS_Shape& aSx=aIt.Value();
357 TotalShapes(aSx, aNbSx);
361 myLines.SetStartSize(2*aNbS);
362 myLines.SetIncrement(aNbS);
365 //-----------------------------------------------------scope_1 f
366 aAllocator=new NCollection_IncAllocator();
368 BOPCol_DataMapOfShapeInteger& aMSI=myMapShapeIndex;
372 aIt.Initialize(myArguments);
373 for (; aIt.More(); aIt.Next()) {
374 const TopoDS_Shape& aS=aIt.Value();
375 if (aMSI.IsBound(aS)) {
381 InitShape(aI, aS, aAllocator, aMSI);
384 aR.SetIndices(i1, i2);
389 myNbSourceShapes=NbShapes();
394 for (j=0; j<myNbSourceShapes; ++j) {
395 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
397 const TopoDS_Shape& aS=aSI.Shape();
402 if (aTS==TopAbs_VERTEX) {
403 Bnd_Box& aBox=aSI.ChangeBox();
404 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aS);
405 const gp_Pnt& aP=BRep_Tool::Pnt(aV);
406 aTol=BRep_Tool::Tolerance(aV);
413 for (j=0; j<myNbSourceShapes; ++j) {
414 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
417 if (aTS==TopAbs_EDGE) {
418 const TopoDS_Shape& aS=aSI.Shape();
419 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aS);
420 aTol=BRep_Tool::Tolerance(aE);
422 if (!BRep_Tool::Degenerated(aE)) {
423 Standard_Boolean bInf1, bInf2;
424 Standard_Integer aIx;
425 Standard_Real aT1, aT2;
427 Handle(Geom_Curve) aC3D;
431 BOPDS_ShapeInfo aSIx;
433 BOPCol_ListOfInteger& aLI=aSI.ChangeSubShapes();
436 aEx.Orientation(TopAbs_FORWARD);
438 aC3D=BRep_Tool::Curve (aEx, aT1, aT2);
439 bInf1=Precision::IsNegativeInfinite(aT1);
440 bInf2=Precision::IsPositiveInfinite(aT2);
444 aBB.MakeVertex(aVx, aPx, aTol);
445 aVx.Orientation(TopAbs_FORWARD);
448 aSIx.SetShapeType(TopAbs_VERTEX);
449 aSIx.SetFlag(1); //infinite flag
456 aBB.MakeVertex(aVx, aPx, aTol);
457 aVx.Orientation(TopAbs_REVERSED);
460 aSIx.SetShapeType(TopAbs_VERTEX);
461 aSIx.SetFlag(1);//infinite flag
471 Bnd_Box& aBox=aSI.ChangeBox();
472 BRepBndLib::Add(aE, aBox);
474 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
475 aIt1.Initialize(aLV);
476 for (; aIt1.More(); aIt1.Next()) {
478 BOPDS_ShapeInfo& aSIV=ChangeShapeInfo(nV);
479 Bnd_Box& aBx=aSIV.ChangeBox();
486 BOPCol_MapOfInteger aMI(100, aAllocator);
487 BOPCol_MapIteratorOfMapOfInteger aItMI;
490 for (j=0; j<myNbSourceShapes; ++j) {
491 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
494 if (aTS==TopAbs_FACE) {
495 const TopoDS_Shape& aS=aSI.Shape();
496 const TopoDS_Face& aF=*((TopoDS_Face*)&aS);
497 aTol=BRep_Tool::Tolerance(aF);
499 Bnd_Box& aBox=aSI.ChangeBox();
500 BRepBndLib::Add(aS, aBox);
502 BOPCol_ListOfInteger& aLW=aSI.ChangeSubShapes();
503 aIt1.Initialize(aLW);
504 for (; aIt1.More(); aIt1.Next()) {
506 BOPDS_ShapeInfo& aSIW=ChangeShapeInfo(nW);
508 const BOPCol_ListOfInteger& aLE=aSIW.SubShapes();
509 aIt2.Initialize(aLE);
510 for (; aIt2.More(); aIt2.Next()) {
512 BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
513 Bnd_Box& aBx=aSIE.ChangeBox();
517 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aSIE.Shape());
518 if (BRep_Tool::Degenerated(aE)) {
522 const BOPCol_ListOfInteger& aLV=aSIE.SubShapes();
523 aIt3.Initialize(aLV);
524 for (; aIt3.More(); aIt3.Next()) {
529 }//for (; aIt1.More(); aIt1.Next()) {
531 // pure internal vertices on the face
533 for (; aItS.More(); aItS.Next()) {
534 const TopoDS_Shape& aSx=aItS.Value();
535 if (aSx.ShapeType()==TopAbs_VERTEX){
542 // For a Face: change wires for BRep sub-shapes
544 aItMI.Initialize(aMI);
545 for (; aItMI.More(); aItMI.Next()) {
551 }//if (aTS==TopAbs_FACE) {
552 }//for (j=0; j<myNbSourceShapes; ++j) {
555 for (j=0; j<myNbSourceShapes; ++j) {
556 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
559 if (aTS!=TopAbs_SOLID) {
562 Bnd_Box& aBox=aSI.ChangeBox();
563 BuildBndBoxSolid(j, aBox);
566 // update sub-shapes by BRep comprising ones
568 BOPCol_ListOfInteger& aLI1=aSI.ChangeSubShapes();
570 aIt1.Initialize(aLI1);
571 for (; aIt1.More(); aIt1.Next()) {
573 BOPDS_ShapeInfo& aSI1=ChangeShapeInfo(n1);
574 if (aSI1.ShapeType()!=TopAbs_SHELL) {
578 const BOPCol_ListOfInteger& aLI2=aSI1.SubShapes();
579 aIt2.Initialize(aLI2);
580 for (; aIt2.More(); aIt2.Next()) {
582 BOPDS_ShapeInfo& aSI2=ChangeShapeInfo(n2);
583 if (aSI2.ShapeType()!=TopAbs_FACE) {
589 const BOPCol_ListOfInteger& aLI3=aSI2.SubShapes();
590 aIt3.Initialize(aLI3);
591 for (; aIt3.More(); aIt3.Next()) {
599 aItMI.Initialize(aMI);
600 for (; aItMI.More(); aItMI.Next()) {
605 }//for (j=0; j<myNbSourceShapes; ++j) {
608 aAllocator.Nullify();
609 //-----------------------------------------------------scope_1 t
611 // 3 myPaveBlocksPool
612 myPaveBlocksPool.SetStartSize(aNbE);
613 myPaveBlocksPool.SetIncrement(aNbE);
614 myPaveBlocksPool.Init();
617 myFaceInfoPool.SetStartSize(aNbF);
618 myFaceInfoPool.SetIncrement(aNbF);
619 myFaceInfoPool.Init();
622 //=======================================================================
623 //function : InitShape
625 //=======================================================================
626 void BOPDS_DS::InitShape
627 (const Standard_Integer aI,
628 const TopoDS_Shape& aS,
629 Handle(NCollection_BaseAllocator)& theAllocator,
630 BOPCol_DataMapOfShapeInteger& aMSI)
632 Standard_Integer aIx;
634 BOPCol_ListIteratorOfListOfInteger aIt1;
636 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(aI);
637 aSI.SetShapeType(aS.ShapeType());
638 BOPCol_ListOfInteger& aLI=aSI.ChangeSubShapes();
640 BOPCol_MapOfInteger aM(100, theAllocator);
642 aIt1.Initialize(aLI);
643 for (; aIt1.More(); aIt1.Next()) {
644 aM.Add(aIt1.Value());
648 for (; aIt.More(); aIt.Next()) {
649 const TopoDS_Shape& aSx=aIt.Value();
650 if (aMSI.IsBound(aSx)) {
658 InitShape(aIx, aSx, theAllocator, aMSI);
666 //=======================================================================
667 //function : HasInterf
669 //=======================================================================
670 Standard_Boolean BOPDS_DS::HasInterf(const Standard_Integer theI) const
672 Standard_Integer n1, n2;
673 Standard_Boolean bRet;
674 BOPDS_MapIteratorMapOfPassKey aIt;
676 bRet = Standard_False;
678 aIt.Initialize(myInterfTB);
679 for (; aIt.More(); aIt.Next()) {
680 const BOPDS_PassKey& aPK = aIt.Value();
682 if (n1 == theI || n2 == theI) {
683 bRet = Standard_True;
690 //=======================================================================
691 //function : HasInterfShapeSubShapes
693 //=======================================================================
694 Standard_Boolean BOPDS_DS::HasInterfShapeSubShapes
695 (const Standard_Integer theI1,
696 const Standard_Integer theI2,
697 const Standard_Boolean theFlag)const
699 Standard_Boolean bRet;
701 BOPCol_ListIteratorOfListOfInteger aIt;
702 bRet = Standard_False;
704 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI2);
705 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
707 for (; aIt.More(); aIt.Next()) {
709 bRet=HasInterf(theI1, n2);
723 //=======================================================================
724 //function : HasInterfSubShapes
726 //=======================================================================
727 Standard_Boolean BOPDS_DS::HasInterfSubShapes
728 (const Standard_Integer theI1,
729 const Standard_Integer theI2)const
731 Standard_Boolean bRet;
733 BOPCol_ListIteratorOfListOfInteger aIt;
734 bRet = Standard_False;
736 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI1);
737 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
739 for (; aIt.More(); aIt.Next()) {
741 bRet=HasInterfShapeSubShapes(n1, theI2);
750 //=======================================================================
751 //function : PaveBlocksPool
753 //=======================================================================
754 const BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::PaveBlocksPool()const
756 return myPaveBlocksPool;
758 //=======================================================================
759 //function : ChangePaveBlocksPool
761 //=======================================================================
762 BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::ChangePaveBlocksPool()
764 return myPaveBlocksPool;
766 //=======================================================================
767 //function : HasPaveBlocks
769 //=======================================================================
770 Standard_Boolean BOPDS_DS::HasPaveBlocks(const Standard_Integer theI)const
772 return ShapeInfo(theI).HasReference();
774 //=======================================================================
775 //function : PaveBlocks
777 //=======================================================================
778 const BOPDS_ListOfPaveBlock& BOPDS_DS::PaveBlocks
779 (const Standard_Integer theI)const
781 static BOPDS_ListOfPaveBlock sLPB;
782 Standard_Integer aRef;
784 if (HasPaveBlocks(theI)) {
785 aRef=ShapeInfo(theI).Reference();
786 const BOPDS_ListOfPaveBlock& aLPB=myPaveBlocksPool(aRef);
791 //=======================================================================
792 //function : ChangePaveBlocks
794 //=======================================================================
795 BOPDS_ListOfPaveBlock& BOPDS_DS::ChangePaveBlocks
796 (const Standard_Integer theI)
798 Standard_Boolean bHasReference;
799 Standard_Integer aRef;
801 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
802 bHasReference=aSI.HasReference();
803 if (!bHasReference) {
804 InitPaveBlocks(theI);
807 aRef=aSI.Reference();
808 return myPaveBlocksPool(aRef);
810 //=======================================================================
811 //function : InitPaveBlocks
813 //=======================================================================
814 void BOPDS_DS::InitPaveBlocks(const Standard_Integer theI)
816 Standard_Integer nV=0, iRef, aNbV, nVSD;
818 TopAbs_Orientation aOrE;
820 BOPCol_ListIteratorOfListOfInteger aIt;
822 Handle(BOPDS_PaveBlock) aPB;
824 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
825 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aSI.Shape());
826 aOrE=aE.Orientation();
828 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
834 aPB=new BOPDS_PaveBlock;
835 aPB->SetOriginalEdge(theI);
837 if (aOrE!=TopAbs_INTERNAL) {
839 for (; aIt.More(); aIt.Next()) {
842 const BOPDS_ShapeInfo& aSIV=ShapeInfo(nV);
843 aV=*(TopoDS_Vertex*)(&aSIV.Shape());
844 if (aSIV.HasFlag()) {
845 aT=ComputeParameter(aV, aE);
848 aT=BRep_Tool::Parameter(aV, aE);
851 if (HasShapeSD(nV, nVSD)) {
855 aPave.SetParameter(aT);
856 aPB->AppendExtPave(aPave);
861 aT=BRep_Tool::Parameter(aV, aE);
863 aPave.SetParameter(aT);
864 aPB->AppendExtPave1(aPave);
869 TopoDS_Iterator aItE;
871 aItE.Initialize(aE, Standard_False, Standard_True);
872 for (; aItE.More(); aItE.Next()) {
873 aV=*((TopoDS_Vertex*)&aItE.Value());
876 const BOPDS_ShapeInfo& aSIV=ShapeInfo(nV);
877 if (aSIV.HasFlag()) {
878 aT=ComputeParameter(aV, aE);
881 aT=BRep_Tool::Parameter(aV, aE);
884 if (HasShapeSD(nV, nVSD)) {
888 aPave.SetParameter(aT);
889 aPB->AppendExtPave1(aPave);
893 iRef = myPaveBlocksPool.Append() - 1;
894 BOPDS_ListOfPaveBlock &aLPB=myPaveBlocksPool(iRef);
896 aPB->Update(aLPB, Standard_False);
897 aSI.SetReference(iRef);
899 //=======================================================================
900 //function : UpdatePaveBlocks
902 //=======================================================================
903 void BOPDS_DS::UpdatePaveBlocks()
905 Standard_Boolean bIsToUpdate;
906 Standard_Integer i, aNbPBP;
907 BOPDS_ListOfPaveBlock aLPBN(myAllocator);
908 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBN;
910 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
913 for (i=0; i<aNbPBP; ++i) {
914 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
916 aItPB.Initialize(aLPB);
917 for (; aItPB.More(); aItPB.Next()) {
918 Handle(BOPDS_PaveBlock)& aPB=aItPB.ChangeValue();
920 bIsToUpdate=aPB->IsToUpdate();
925 aItPBN.Initialize(aLPBN);
926 for (; aItPBN.More(); aItPBN.Next()) {
927 Handle(BOPDS_PaveBlock)& aPBN=aItPBN.ChangeValue();
932 }// for (; aItPB.More(); aItPB.Next()) {
933 }// for (i=0; i<aNbPBP; ++i) {
935 //=======================================================================
936 //function : UpdatePaveBlock
938 //=======================================================================
939 void BOPDS_DS::UpdatePaveBlock(const Handle(BOPDS_PaveBlock)& thePB)
941 if (!thePB->IsToUpdate()){
945 Standard_Integer nE, iRef;
946 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBN;
947 BOPDS_ListOfPaveBlock aLPBN(myAllocator);
948 Handle(BOPDS_PaveBlock) aPB;
950 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
952 nE=thePB->OriginalEdge();
953 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(nE);
954 iRef=aSI.Reference();
955 BOPDS_ListOfPaveBlock& aLPB=aPBP(iRef);
957 aItPB.Initialize(aLPB);
958 for (; aItPB.More(); aItPB.Next()) {
959 aPB=aItPB.ChangeValue();
963 aItPBN.Initialize(aLPBN);
964 for (; aItPBN.More(); aItPBN.Next()) {
965 Handle(BOPDS_PaveBlock)& aPBN=aItPBN.ChangeValue();
973 //=======================================================================
974 //function : UpdateCommonBlock
976 //=======================================================================
977 void BOPDS_DS::UpdateCommonBlock(const Handle(BOPDS_CommonBlock)& theCB)
979 Standard_Integer nE, iRef, n1, n2;
980 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBCB, aItPBN;
981 BOPDS_DataMapIteratorOfDataMapOfPassKeyListOfPaveBlock aItMPKLPB;
982 BOPDS_ListOfPaveBlock aLPBN;
983 BOPDS_DataMapOfPassKeyListOfPaveBlock aMPKLPB;
984 Handle(BOPDS_PaveBlock) aPB;
985 Handle(BOPDS_CommonBlock) aCBx;
988 const BOPDS_ListOfPaveBlock& aLPBCB=theCB->PaveBlocks();
989 if (!aLPBCB.First()->IsToUpdate()){
993 const BOPCol_ListOfInteger& aLF=theCB->Faces();
995 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
997 aItPBCB.Initialize(aLPBCB);
998 for (; aItPBCB.More(); aItPBCB.Next()) {
999 const Handle(BOPDS_PaveBlock)& aPBCB=aItPBCB.ChangeValue();
1001 nE=aPBCB->OriginalEdge();
1002 iRef=ChangeShapeInfo(nE).Reference();
1003 BOPDS_ListOfPaveBlock& aLPB=aPBP(iRef);
1005 aItPB.Initialize(aLPB);
1006 for (; aItPB.More(); aItPB.Next()) {
1007 aPB=aItPB.ChangeValue();
1013 aItPBN.Initialize(aLPBN);
1014 for (; aItPBN.More(); aItPBN.Next()) {
1015 Handle(BOPDS_PaveBlock)& aPBN=aItPBN.ChangeValue();
1018 aPBN->Indices(n1, n2);
1020 if (aMPKLPB.IsBound(aPK)) {
1021 BOPDS_ListOfPaveBlock& aLPBx=aMPKLPB.ChangeFind(aPK);
1025 BOPDS_ListOfPaveBlock aLPBx;
1027 aMPKLPB.Bind(aPK, aLPBx);
1036 aItMPKLPB.Initialize(aMPKLPB);
1037 for (; aItMPKLPB.More(); aItMPKLPB.Next()) {
1038 BOPDS_ListOfPaveBlock& aLPBx=aItMPKLPB.ChangeValue();
1040 while (aLPBx.Extent()) {
1041 Standard_Boolean bCoinside;
1042 Standard_Real aTol, aTolMax(0.);
1043 BOPDS_ListOfPaveBlock aLPBxN;
1045 aItPB.Initialize(aLPBx);
1046 for(; aItPB.More(); ) {
1047 const Handle(BOPDS_PaveBlock)& aPBx=aItPB.Value();
1048 if (aLPBxN.Extent()) {
1049 const Handle(BOPDS_PaveBlock)& aPBCx = aLPBxN.First();
1050 bCoinside = CheckCoincidence(aPBx, aPBCx);
1052 nE = aPBx->OriginalEdge();
1053 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1054 aTol = BRep_Tool::Tolerance(aE);
1056 //pave block with the max tolerance of the original edge
1057 //must be the first in the common block
1058 if (aTolMax < aTol) {
1060 aLPBxN.Prepend(aPBx);
1062 aLPBxN.Append(aPBx);
1064 aLPBx.Remove(aItPB);
1067 }//if (aLPBxN.Extent()) {
1069 nE = aPBx->OriginalEdge();
1070 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1071 aTolMax = BRep_Tool::Tolerance(aE);
1073 aLPBxN.Append(aPBx);
1074 aLPBx.Remove(aItPB);
1078 }//for(; aItPB.More(); ) {
1080 aCBx=new BOPDS_CommonBlock;
1081 aCBx->AddPaveBlocks(aLPBxN);
1082 aCBx->AddFaces(aLF);
1084 aItPB.Initialize(aLPBxN);
1085 for (; aItPB.More(); aItPB.Next()) {
1086 aPB=aItPB.ChangeValue();
1087 SetCommonBlock(aPB, aCBx);
1093 //=======================================================================
1094 // function: RealPaveBlock
1096 //=======================================================================
1097 Handle(BOPDS_PaveBlock) BOPDS_DS::RealPaveBlock
1098 (const Handle(BOPDS_PaveBlock)& thePB) const
1100 if (IsCommonBlock(thePB)) {
1101 const Handle(BOPDS_CommonBlock)& aCB = CommonBlock(thePB);
1102 const Handle(BOPDS_PaveBlock)& aPB = aCB->PaveBlock1();
1108 //=======================================================================
1109 // function: IsCommonBlockOnEdge
1111 //=======================================================================
1112 Standard_Boolean BOPDS_DS::IsCommonBlockOnEdge
1113 (const Handle(BOPDS_PaveBlock)& thePB) const
1115 if (IsCommonBlock(thePB)) {
1116 const Handle(BOPDS_CommonBlock)& aCB = CommonBlock(thePB);
1117 return aCB->PaveBlocks().Extent()>1;
1119 return Standard_False;
1122 //=======================================================================
1123 //function : IsCommonBlock
1125 //=======================================================================
1126 Standard_Boolean BOPDS_DS::IsCommonBlock
1127 (const Handle(BOPDS_PaveBlock)& thePB) const
1129 return myMapPBCB.IsBound(thePB);
1132 //=======================================================================
1133 //function : CommonBlock
1135 //=======================================================================
1136 Handle(BOPDS_CommonBlock) BOPDS_DS::CommonBlock
1137 (const Handle(BOPDS_PaveBlock)& thePB) const
1139 return (IsCommonBlock(thePB) ? myMapPBCB.Find(thePB) : NULL);
1142 //=======================================================================
1143 //function : SetCommonBlock
1145 //=======================================================================
1146 void BOPDS_DS::SetCommonBlock(const Handle(BOPDS_PaveBlock)& thePB,
1147 const Handle(BOPDS_CommonBlock)& theCB)
1149 if (IsCommonBlock(thePB)) {
1150 Handle(BOPDS_CommonBlock)& aCB = myMapPBCB.ChangeFind(thePB);
1154 myMapPBCB.Bind(thePB, theCB);
1162 //=======================================================================
1163 //function : FaceInfoPool
1165 //=======================================================================
1166 const BOPDS_VectorOfFaceInfo& BOPDS_DS::FaceInfoPool()const
1168 return myFaceInfoPool;
1170 //=======================================================================
1171 //function : HasFaceInfo
1173 //=======================================================================
1174 Standard_Boolean BOPDS_DS::HasFaceInfo(const Standard_Integer theI)const
1176 return ShapeInfo(theI).HasReference();
1178 //=======================================================================
1179 //function : FaceInfo
1181 //=======================================================================
1182 const BOPDS_FaceInfo& BOPDS_DS::FaceInfo(const Standard_Integer theI)const
1184 static BOPDS_FaceInfo sFI;
1185 Standard_Integer aRef;
1187 if (HasFaceInfo(theI)) {
1188 aRef=ShapeInfo(theI).Reference();
1189 const BOPDS_FaceInfo& aFI=myFaceInfoPool(aRef);
1194 //=======================================================================
1195 //function : ChangeFaceInfo
1197 //=======================================================================
1198 BOPDS_FaceInfo& BOPDS_DS::ChangeFaceInfo(const Standard_Integer theI)
1200 Standard_Boolean bHasReference;
1201 Standard_Integer aRef;
1202 BOPDS_FaceInfo* pFI;
1204 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1205 bHasReference=aSI.HasReference();
1206 if (!bHasReference) {
1210 aRef=aSI.Reference();
1211 const BOPDS_FaceInfo& aFI=myFaceInfoPool(aRef);
1212 pFI=(BOPDS_FaceInfo*)&aFI;
1215 //=======================================================================
1216 //function : InitFaceInfo
1218 //=======================================================================
1219 void BOPDS_DS::InitFaceInfo(const Standard_Integer theI)
1221 Standard_Integer iRef;
1223 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1224 iRef=myFaceInfoPool.Append()-1;
1225 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1226 aSI.SetReference(iRef);
1229 UpdateFaceInfoIn(theI);
1230 UpdateFaceInfoOn(theI);
1232 //=======================================================================
1233 //function : UpdateFaceInfoIn
1235 //=======================================================================
1236 void BOPDS_DS::UpdateFaceInfoIn(const Standard_Integer theI)
1238 Standard_Integer iRef;
1240 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1241 if (aSI.HasReference()) {
1242 iRef=aSI.Reference();
1243 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1245 BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.ChangePaveBlocksIn();
1246 BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
1249 FaceInfoIn(theI, aMPBIn, aMVIn);
1252 //=======================================================================
1253 //function : UpdateFaceInfoOn
1255 //=======================================================================
1256 void BOPDS_DS::UpdateFaceInfoOn(const Standard_Integer theI)
1258 Standard_Integer iRef;
1260 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1261 if (aSI.HasReference()) {
1262 iRef=aSI.Reference();
1263 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1265 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1266 BOPCol_MapOfInteger& aMVOn=aFI.ChangeVerticesOn();
1269 FaceInfoOn(theI, aMPBOn, aMVOn);
1272 //=======================================================================
1273 //function : FaceInfoOn
1275 //=======================================================================
1276 void BOPDS_DS::FaceInfoOn(const Standard_Integer theF,
1277 BOPDS_IndexedMapOfPaveBlock& theMPB,
1278 BOPCol_MapOfInteger& theMI)
1280 Standard_Integer nS, nSD, nV1, nV2;
1281 BOPCol_ListIteratorOfListOfInteger aIt;
1282 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1284 const BOPDS_ShapeInfo& aSI=ShapeInfo(theF);
1285 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
1286 aIt.Initialize(aLI);
1287 for (; aIt.More(); aIt.Next()) {
1289 const BOPDS_ShapeInfo& aSIE=ShapeInfo(nS);
1290 if (aSIE.ShapeType()==TopAbs_EDGE) {
1291 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nS);
1292 aItPB.Initialize(aLPB);
1293 for (; aItPB.More(); aItPB.Next()) {
1294 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
1295 aPB->Indices(nV1, nV2);
1298 Handle(BOPDS_PaveBlock) aPBR=RealPaveBlock(aPB);
1301 }//if (aSIE.ShapeType()==TopAbs_EDGE)
1303 // nE is TopAbs_VERTEX
1304 if (HasShapeSD(nS, nSD)) {
1311 //=======================================================================
1312 //function : FaceInfoIn
1314 //=======================================================================
1315 void BOPDS_DS::FaceInfoIn(const Standard_Integer theF,
1316 BOPDS_IndexedMapOfPaveBlock& theMPB,
1317 BOPCol_MapOfInteger& theMI)
1319 Standard_Integer i, aNbVF, aNbEF, nV, nE, nVSD;
1320 TopoDS_Iterator aItS;
1321 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1323 // 1. Pure internal vertices on the face
1324 const TopoDS_Shape& aF=Shape(theF);
1325 aItS.Initialize(aF);
1326 for (; aItS.More(); aItS.Next()) {
1327 const TopoDS_Shape& aSx=aItS.Value();
1328 if (aSx.ShapeType()==TopAbs_VERTEX){
1330 if (HasShapeSD(nV, nVSD)) {
1338 BOPDS_VectorOfInterfVF& aVFs=InterfVF();
1339 aNbVF=aVFs.Extent();
1340 for (i=0; i<aNbVF; ++i) {
1341 BOPDS_InterfVF& aVF=aVFs(i);
1342 if(aVF.Contains(theF)) {
1343 nV=aVF.OppositeIndex(theF);
1349 BOPDS_VectorOfInterfEF& aEFs=InterfEF();
1350 aNbEF=aEFs.Extent();
1351 for (i=0; i<aNbEF; ++i) {
1352 BOPDS_InterfEF& aEF=aEFs(i);
1353 if(aEF.Contains(theF)) {
1354 if(aEF.HasIndexNew(nV)) {
1358 nE=aEF.OppositeIndex(theF);
1359 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1360 aItPB.Initialize(aLPB);
1361 for (; aItPB.More(); aItPB.Next()) {
1362 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
1363 if (IsCommonBlock(aPB)) {
1364 const Handle(BOPDS_CommonBlock)& aCB=CommonBlock(aPB);
1365 if (aCB->Contains(theF)) {
1366 const Handle(BOPDS_PaveBlock)& aPB1=aCB->PaveBlock1();
1370 }// for (; aItPB.More(); aItPB.Next()) {
1372 }// if(aEF.Contains(theF)) {
1373 }// for (i=0; i<aNbEF; ++i) {
1376 //=======================================================================
1377 //function : RefineFaceInfoOn
1379 //=======================================================================
1380 void BOPDS_DS::RefineFaceInfoOn()
1382 Standard_Integer i, aNb, nF, aNbPB, j;
1383 BOPDS_IndexedMapOfPaveBlock aMPB;
1385 aNb=myFaceInfoPool.Extent();
1386 for (i=0; i<aNb; ++i) {
1387 BOPDS_FaceInfo &aFI=myFaceInfoPool(i);
1389 UpdateFaceInfoOn(nF);
1390 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1393 aMPB.Assign(aMPBOn);
1396 aNbPB=aMPB.Extent();
1397 for (j=1; j<=aNbPB; ++j) {
1398 const Handle(BOPDS_PaveBlock)& aPB=aMPB(j);
1399 if (aPB->HasEdge()) {
1405 //=======================================================================
1406 //function : AloneVertices
1408 //=======================================================================
1409 void BOPDS_DS::AloneVertices(const Standard_Integer theI,
1410 BOPCol_ListOfInteger& theLI)const
1412 if (HasFaceInfo(theI)) {
1414 Standard_Integer i, nV1, nV2, nV;
1415 BOPDS_MapIteratorOfMapOfPaveBlock aItMPB;
1416 BOPCol_MapIteratorOfMapOfInteger aItMI;
1418 BOPCol_MapOfInteger aMI(100, myAllocator);
1420 const BOPDS_FaceInfo& aFI=FaceInfo(theI);
1422 for (i=0; i<2; ++i) {
1423 const BOPDS_IndexedMapOfPaveBlock& aMPB=
1424 (!i) ? aFI.PaveBlocksIn() : aFI.PaveBlocksSc();
1425 aItMPB.Initialize(aMPB);
1426 for (; aItMPB.More(); aItMPB.Next()) {
1427 const Handle(BOPDS_PaveBlock)& aPB=aItMPB.Value();
1428 aPB->Indices(nV1, nV2);
1434 for (i=0; i<2; ++i) {
1435 const BOPCol_MapOfInteger& aMIV=
1436 (!i) ? aFI.VerticesIn() : aFI.VerticesSc();
1437 aItMI.Initialize(aMIV);
1438 for (; aItMI.More(); aItMI.Next()) {
1449 //=======================================================================
1450 //function : VerticesOnIn
1452 //=======================================================================
1453 void BOPDS_DS::VerticesOnIn
1454 (const Standard_Integer nF1,
1455 const Standard_Integer nF2,
1456 BOPCol_MapOfInteger& aMI,
1457 BOPDS_IndexedMapOfPaveBlock& aMPB)const
1459 Standard_Integer i, j, nV, nV1, nV2, aNbPB;
1460 BOPCol_MapIteratorOfMapOfInteger aIt;
1461 BOPDS_IndexedMapOfPaveBlock pMPB[4];
1463 const BOPDS_FaceInfo& aFI1=FaceInfo(nF1);
1464 const BOPDS_FaceInfo& aFI2=FaceInfo(nF2);
1466 pMPB[0]=aFI1.PaveBlocksOn();
1467 pMPB[1]=aFI1.PaveBlocksIn();
1468 pMPB[2]=aFI2.PaveBlocksOn();
1469 pMPB[3]=aFI2.PaveBlocksIn();
1471 for (i=0; i<4; ++i) {
1472 aNbPB = pMPB[i].Extent();
1473 for (j = 1; j <= aNbPB; ++j) {
1474 const Handle(BOPDS_PaveBlock)& aPB = pMPB[i](j);
1476 aPB->Indices(nV1, nV2);
1482 const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
1483 const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
1484 const BOPCol_MapOfInteger& aMVOn2=aFI2.VerticesOn();
1485 const BOPCol_MapOfInteger& aMVIn2=aFI2.VerticesIn();
1487 for (i=0; i<2; ++i) {
1488 const BOPCol_MapOfInteger& aMV1=(!i) ? aMVOn1 : aMVIn1;
1489 aIt.Initialize(aMV1);
1490 for (; aIt.More(); aIt.Next()) {
1492 if (aMVOn2.Contains(nV) || aMVIn2.Contains(nV)) {
1498 //=======================================================================
1499 //function : SharedEdges
1501 //=======================================================================
1502 void BOPDS_DS::SharedEdges(const Standard_Integer nF1,
1503 const Standard_Integer nF2,
1504 BOPCol_ListOfInteger& theLI,
1505 const Handle(NCollection_BaseAllocator)& aAllocator)
1507 Standard_Integer nE, nSp;
1508 BOPCol_ListIteratorOfListOfInteger aItLI;
1509 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
1510 BOPCol_MapOfInteger aMI(100, aAllocator);
1512 const BOPDS_ShapeInfo& aSI1=ShapeInfo(nF1);
1513 const BOPCol_ListOfInteger& aLI1=aSI1.SubShapes();
1514 aItLI.Initialize(aLI1);
1515 for (; aItLI.More(); aItLI.Next()) {
1517 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1518 if(aSIE.ShapeType()==TopAbs_EDGE) {
1519 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1520 if (aLPB.IsEmpty()) {
1524 aItLPB.Initialize(aLPB);
1525 for (; aItLPB.More(); aItLPB.Next()) {
1526 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
1534 const BOPDS_ShapeInfo& aSI2=ShapeInfo(nF2);
1535 const BOPCol_ListOfInteger& aLI2=aSI2.SubShapes();
1536 aItLI.Initialize(aLI2);
1537 for (; aItLI.More(); aItLI.Next()) {
1539 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1540 if(aSIE.ShapeType()==TopAbs_EDGE) {
1541 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1542 if (aLPB.IsEmpty()) {
1543 if (aMI.Contains(nE)) {
1548 aItLPB.Initialize(aLPB);
1549 for (; aItLPB.More(); aItLPB.Next()) {
1550 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
1552 if (aMI.Contains(nSp)) {
1561 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1563 // same domain shapes
1565 //=======================================================================
1566 //function : ShapesSD
1568 //=======================================================================
1569 BOPCol_DataMapOfIntegerInteger& BOPDS_DS::ShapesSD()
1573 //=======================================================================
1574 //function : AddShapeSD
1576 //=======================================================================
1577 void BOPDS_DS::AddShapeSD(const Standard_Integer theIndex,
1578 const Standard_Integer theIndexSD)
1580 myShapesSD.Bind(theIndex, theIndexSD);
1582 //=======================================================================
1583 //function : HasShapeSD
1585 //=======================================================================
1586 Standard_Boolean BOPDS_DS::HasShapeSD
1587 (const Standard_Integer theIndex,
1588 Standard_Integer& theIndexSD)const
1590 Standard_Boolean bRet;
1592 bRet=myShapesSD.IsBound(theIndex);
1594 theIndexSD=myShapesSD.Find(theIndex);
1598 //=======================================================================
1601 //=======================================================================
1602 void BOPDS_DS::Dump()const
1604 Standard_Integer i, aNb, aNbSS;
1606 printf(" *** DS ***\n");
1608 printf(" Ranges:%d\n", aNb);
1609 for (i=0; i<aNb; ++i) {
1610 const BOPDS_IndexRange& aR=Range(i);
1615 aNbSS=NbSourceShapes();
1616 printf(" Shapes:%d\n", aNbSS);
1618 for (i=0; i<aNb; ++i) {
1619 const BOPDS_ShapeInfo& aSI=ShapeInfo(i);
1624 printf(" ****** adds\n");
1627 printf(" ******\n");
1630 //=======================================================================
1631 // function: CheckCoincidence
1633 //=======================================================================
1634 Standard_Boolean BOPDS_DS::CheckCoincidence
1635 (const Handle(BOPDS_PaveBlock)& aPB1,
1636 const Handle(BOPDS_PaveBlock)& aPB2)
1638 Standard_Boolean bRet;
1639 Standard_Integer nE1, nE2, aNbPoints;
1640 Standard_Real aT11, aT12, aT21, aT22, aT1m, aD, aTol, aT2x;
1643 bRet=Standard_False;
1645 aPB1->Range(aT11, aT12);
1646 aT1m=IntTools_Tools::IntermediatePoint (aT11, aT12);
1647 nE1=aPB1->OriginalEdge();
1648 const TopoDS_Edge& aE1=(*(TopoDS_Edge*)(&Shape(nE1)));
1649 BOPTools_AlgoTools::PointOnEdge(aE1, aT1m, aP1m);
1651 aPB2->Range(aT21, aT22);
1652 nE2=aPB2->OriginalEdge();
1653 const TopoDS_Edge& aE2=(*(TopoDS_Edge*)(&Shape(nE2)));
1656 Handle(Geom_Curve)aC2 = BRep_Tool::Curve (aE2, f, l);
1657 GeomAPI_ProjectPointOnCurve aPPC;
1658 aPPC.Init(aC2, f, l);
1660 aNbPoints=aPPC.NbPoints();
1662 aD=aPPC.LowerDistance();
1664 aTol=BRep_Tool::Tolerance(aE1);
1665 aTol=aTol+BRep_Tool::Tolerance(aE2);
1667 aT2x=aPPC.LowerDistanceParameter();
1668 if (aT2x>aT21 && aT2x<aT22) {
1675 //=======================================================================
1676 // function: SortPaveBlocks
1678 //=======================================================================
1679 void BOPDS_DS::SortPaveBlocks(const Handle(BOPDS_CommonBlock)& aCB)
1681 Standard_Integer theI;
1682 Standard_Boolean bToSort;
1683 bToSort = IsToSort(aCB, theI);
1688 Standard_Integer i(0);
1689 const BOPDS_ListOfPaveBlock& aLPB = aCB->PaveBlocks();
1690 BOPDS_ListOfPaveBlock aLPBN = aLPB;
1692 Handle(BOPDS_PaveBlock) aPB;
1693 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1695 aIt.Initialize(aLPBN);
1696 for (aIt.Next(); aIt.More(); ) {
1707 aCB->AddPaveBlocks(aLPBN);
1709 //=======================================================================
1710 // function: IsToSort
1712 //=======================================================================
1713 Standard_Boolean BOPDS_DS::IsToSort
1714 (const Handle(BOPDS_CommonBlock)& aCB,
1715 Standard_Integer& theI)
1717 Standard_Boolean bRet;
1718 bRet = Standard_False;
1719 const BOPDS_ListOfPaveBlock& aLPB = aCB->PaveBlocks();
1720 if (aLPB.Extent()==1) {
1724 Standard_Integer nE;
1725 Standard_Real aTolMax, aTol;
1726 Handle(BOPDS_PaveBlock) aPB;
1728 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1731 nE = aPB->OriginalEdge();
1732 aE = (*(TopoDS_Edge *)(&Shape(nE)));
1733 aTolMax = BRep_Tool::Tolerance(aE);
1736 aIt.Initialize(aLPB);
1737 for (aIt.Next(); aIt.More(); aIt.Next()) {
1740 nE = aPB->OriginalEdge();
1741 aE = (*(TopoDS_Edge *)(&Shape(nE)));
1742 aTol = BRep_Tool::Tolerance(aE);
1743 if (aTolMax < aTol) {
1745 bRet = Standard_True;
1751 //=======================================================================
1752 // function: IsSubShape
1754 //=======================================================================
1755 Standard_Boolean BOPDS_DS::IsSubShape
1756 (const Standard_Integer theI1,
1757 const Standard_Integer theI2)
1759 Standard_Boolean bRet;
1760 Standard_Integer nS;
1761 bRet = Standard_False;
1763 BOPCol_ListIteratorOfListOfInteger aItLI;
1765 const BOPDS_ShapeInfo& aSI = ShapeInfo(theI2);
1766 const BOPCol_ListOfInteger& aLI = aSI.SubShapes();
1767 aItLI.Initialize(aLI);
1768 for(;aItLI.More(); aItLI.Next()) {
1771 bRet = Standard_True;
1779 //=======================================================================
1782 //=======================================================================
1783 void BOPDS_DS::Paves(const Standard_Integer theEdge,
1784 BOPDS_ListOfPave& theLP)
1786 Standard_Integer aNb, i;
1787 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1788 BOPDS_MapOfPave aMP;
1790 const BOPDS_ListOfPaveBlock& aLPB = PaveBlocks(theEdge);
1791 aNb = aLPB.Extent() + 1;
1796 BOPDS_VectorOfPave pPaves(1, aNb);
1799 aIt.Initialize(aLPB);
1800 for (; aIt.More(); aIt.Next()) {
1801 const Handle(BOPDS_PaveBlock)& aPB = aIt.Value();
1802 const BOPDS_Pave& aPave1 = aPB->Pave1();
1803 const BOPDS_Pave& aPave2 = aPB->Pave2();
1805 if (aMP.Add(aPave1)){
1810 if (aMP.Add(aPave2)){
1816 Standard_ASSERT_VOID(aNb == aMP.Extent(), "Abnormal number of paves");
1818 std::sort(pPaves.begin(), pPaves.end());
1820 for (i = 1; i <= aNb; ++i) {
1821 theLP.Append(pPaves(i));
1825 //=======================================================================
1826 // function: UpdateTolerance
1828 //=======================================================================
1829 void BOPDS_DS::UpdateEdgeTolerance(const Standard_Integer nE,
1830 const Standard_Real aTol)
1832 Standard_Integer nV;
1833 Standard_Real aTolV;
1835 BOPCol_ListIteratorOfListOfInteger aIt;
1837 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1838 aBB.UpdateEdge(aE, aTol);
1839 BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1840 Bnd_Box& aBoxE=aSIE.ChangeBox();
1841 BRepBndLib::Add(aE, aBoxE);
1843 const BOPCol_ListOfInteger& aLI = aSIE.SubShapes();
1844 aIt.Initialize(aLI);
1845 for (; aIt.More(); aIt.Next()) {
1847 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&Shape(nV);
1848 aTolV = BRep_Tool::Tolerance(aV);
1850 aBB.UpdateVertex(aV, aTol);
1851 BOPDS_ShapeInfo& aSIV = ChangeShapeInfo(nV);
1852 Bnd_Box& aBoxV = aSIV.ChangeBox();
1853 BRepBndLib::Add(aV, aBoxV);
1858 //=======================================================================
1859 //function : TotalShapes
1861 //=======================================================================
1862 void TotalShapes(const TopoDS_Shape& aS,
1863 Standard_Integer& aNbS)
1867 pS=(TopoDS_Shape *)&aS;
1868 if (!pS->Checked()) {
1869 TopoDS_Iterator aIt;
1874 for (; aIt.More(); aIt.Next()) {
1875 const TopoDS_Shape& aSx=aIt.Value();
1876 TotalShapes(aSx, aNbS);
1880 //=======================================================================
1881 //function : ResetShape
1883 //=======================================================================
1884 void ResetShape(const TopoDS_Shape& aS)
1888 pS=(TopoDS_Shape *)&aS;
1891 //=======================================================================
1892 //function : ResetShape
1894 //=======================================================================
1895 void ResetShapes(const TopoDS_Shape& aS)
1897 TopoDS_Iterator aIt;
1901 for (; aIt.More(); aIt.Next()) {
1902 const TopoDS_Shape& aSx=aIt.Value();
1906 //=======================================================================
1907 //function : ComputeParameter
1909 //=======================================================================
1910 Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
1911 const TopoDS_Edge& aE)
1913 Standard_Real aT1, aT2, aTRet, aTolE2, aD2;
1915 Handle(Geom_Curve) aC3D;
1919 aEE.Orientation(TopAbs_FORWARD);
1923 aTolE2=BRep_Tool::Tolerance(aE);
1924 aTolE2=aTolE2*aTolE2;
1926 aPV=BRep_Tool::Pnt(aV);
1928 aC3D=BRep_Tool::Curve (aEE, aT1, aT2);
1931 aD2=aPC.SquareDistance(aPV);
1937 aD2=aPC.SquareDistance(aPV);
1944 //=======================================================================
1945 //function : BuildBndBoxSolid
1947 //=======================================================================
1948 void BOPDS_DS::BuildBndBoxSolid(const Standard_Integer theIndex,
1951 Standard_Boolean bIsOpenBox, bIsInverted;
1952 Standard_Integer nSh, nFc;
1953 Standard_Real aTolS, aTolFc;
1954 BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1;
1956 const BOPDS_ShapeInfo& aSI=ShapeInfo(theIndex);
1957 const TopoDS_Shape& aS=aSI.Shape();
1958 const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS));
1960 bIsOpenBox=Standard_False;
1963 const BOPCol_ListOfInteger& aLISh=aSI.SubShapes();
1964 aItLI.Initialize(aLISh);
1965 for (; aItLI.More(); aItLI.Next()) {
1967 const BOPDS_ShapeInfo& aSISh=ShapeInfo(nSh);
1968 if (aSISh.ShapeType()!=TopAbs_SHELL) {
1972 const BOPCol_ListOfInteger& aLIFc=aSISh.SubShapes();
1973 aItLI1.Initialize(aLIFc);
1974 for (; aItLI1.More(); aItLI1.Next()) {
1976 const BOPDS_ShapeInfo& aSIFc=ShapeInfo(nFc);
1977 if (aSIFc.ShapeType()!=TopAbs_FACE) {
1981 const Bnd_Box& aBFc=aSIFc.Box();
1985 bIsOpenBox=(aBFc.IsOpenXmin() || aBFc.IsOpenXmax() ||
1986 aBFc.IsOpenYmin() || aBFc.IsOpenYmax() ||
1987 aBFc.IsOpenZmin() || aBFc.IsOpenZmax());
1993 const TopoDS_Face& aFc=*((TopoDS_Face*)&aSIFc.Shape());
1994 aTolFc=BRep_Tool::Tolerance(aFc);
1998 }//for (; aItLI1.More(); aItLI1.Next()) {
2003 const TopoDS_Shell& aSh=*((TopoDS_Shell*)&aSISh.Shape());
2004 bIsOpenBox=BOPTools_AlgoTools::IsOpenShell(aSh);
2008 }//for (; aItLI.More(); aItLI.Next()) {
2014 bIsInverted=BOPTools_AlgoTools::IsInvertedSolid(aSolid);