1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 // This file is part of Open CASCADE Technology software library.
9 // This library is free software; you can redistribute it and/or modify it under
10 // the terms of the GNU Lesser General Public License version 2.1 as published
11 // by the Free Software Foundation, with special exception defined in the file
12 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 // distribution for complete text of the license and disclaimer of any warranty.
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
18 #include <BOPAlgo_PaveFiller.ixx>
20 #include <Precision.hxx>
21 #include <NCollection_IncAllocator.hxx>
22 #include <Bnd_Box.hxx>
24 #include <Geom_Curve.hxx>
25 #include <Geom2d_Curve.hxx>
27 #include <GeomAPI_ProjectPointOnCurve.hxx>
28 #include <GeomAPI_ProjectPointOnSurf.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Vertex.hxx>
33 #include <TopoDS_Compound.hxx>
35 #include <TopExp_Explorer.hxx>
37 #include <BRep_Builder.hxx>
38 #include <BRep_Tool.hxx>
40 #include <BRepBndLib.hxx>
41 #include <BRepTools.hxx>
43 #include <BRepAdaptor_Curve.hxx>
44 #include <BRepAdaptor_Surface.hxx>
46 #include <IntTools_FaceFace.hxx>
47 #include <IntTools_SequenceOfCurves.hxx>
48 #include <IntTools_SequenceOfPntOn2Faces.hxx>
49 #include <IntTools_Curve.hxx>
50 #include <IntTools_PntOn2Faces.hxx>
51 #include <IntTools_Tools.hxx>
53 #include <IntSurf_ListOfPntOn2S.hxx>
54 #include <IntSurf_PntOn2S.hxx>
56 #include <BOPTools_AlgoTools.hxx>
57 #include <BOPTools_AlgoTools3D.hxx>
59 #include <BOPCol_MapOfInteger.hxx>
60 #include <BOPCol_ListOfShape.hxx>
61 #include <BOPCol_DataMapOfShapeInteger.hxx>
62 #include <BOPCol_ListOfInteger.hxx>
63 #include <BOPCol_IndexedMapOfInteger.hxx>
64 #include <BOPCol_DataMapOfIntegerReal.hxx>
65 #include <BOPCol_NCVector.hxx>
66 #include <BOPCol_TBB.hxx>
68 #include <IntTools_Context.hxx>
69 #include <IntTools_Tools.hxx>
71 #include <BOPDS_Interf.hxx>
72 #include <BOPDS_Iterator.hxx>
73 #include <BOPDS_Curve.hxx>
74 #include <BOPDS_Point.hxx>
75 #include <BOPDS_FaceInfo.hxx>
76 #include <BOPDS_Curve.hxx>
77 #include <BOPDS_MapOfPaveBlock.hxx>
78 #include <BOPDS_PaveBlock.hxx>
79 #include <BOPDS_VectorOfCurve.hxx>
80 #include <BOPDS_VectorOfPoint.hxx>
81 #include <BOPDS_ShapeInfo.hxx>
82 #include <BOPDS_PaveBlock.hxx>
83 #include <BOPDS_ListOfPave.hxx>
84 #include <BOPDS_ListOfPaveBlock.hxx>
85 #include <BOPDS_CoupleOfPaveBlocks.hxx>
86 #include <BOPDS_FaceInfo.hxx>
87 #include <BOPDS_CommonBlock.hxx>
89 #include <BOPAlgo_Tools.hxx>
90 #include <BRepBuilderAPI_MakeVertex.hxx>
92 #include <IntTools_ShrunkRange.hxx>
93 #include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx>
95 static void ToleranceFF(const BRepAdaptor_Surface& aBAS1,
96 const BRepAdaptor_Surface& aBAS2,
97 Standard_Real& aTolFF);
99 /////////////////////////////////////////////////////////////////////////
100 //=======================================================================
101 //class : BOPAlgo_FaceFace
103 //=======================================================================
104 class BOPAlgo_FaceFace :
105 public IntTools_FaceFace,
106 public BOPAlgo_Algo {
109 DEFINE_STANDARD_ALLOC
114 myIF1(-1), myIF2(-1), myTolFF(1.e-7) {
117 virtual ~BOPAlgo_FaceFace() {
120 void SetIndices(const Standard_Integer nF1,
121 const Standard_Integer nF2) {
126 void Indices(Standard_Integer& nF1,
127 Standard_Integer& nF2) const {
132 void SetFaces(const TopoDS_Face& aF1,
133 const TopoDS_Face& aF2) {
138 const TopoDS_Face& Face1()const {
142 const TopoDS_Face& Face2()const {
146 void SetTolFF(const Standard_Real aTolFF) {
150 Standard_Real TolFF() const{
154 virtual void Perform() {
155 BOPAlgo_Algo::UserBreak();
156 IntTools_FaceFace::Perform(myF1, myF2);
160 Standard_Integer myIF1;
161 Standard_Integer myIF2;
162 Standard_Real myTolFF;
167 //=======================================================================
168 typedef BOPCol_NCVector
169 <BOPAlgo_FaceFace> BOPAlgo_VectorOfFaceFace;
171 typedef BOPCol_TBBFunctor
173 BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceFunctor;
175 typedef BOPCol_TBBCnt
176 <BOPAlgo_FaceFaceFunctor,
177 BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceCnt;
178 /////////////////////////////////////////////////////////////////////////
179 //=======================================================================
180 //function : PerformFF
182 //=======================================================================
183 void BOPAlgo_PaveFiller::PerformFF()
185 Standard_Integer iSize;
186 Standard_Boolean bValid;
190 myIterator->Initialize(TopAbs_FACE, TopAbs_FACE);
191 iSize=myIterator->ExpectedLength();
196 Standard_Boolean bJustAdd, bApp, bCompC2D1, bCompC2D2, bIsDone;
197 Standard_Boolean bToSplit, bTangentFaces;
198 Standard_Integer nF1, nF2, aNbCurves, aNbPoints, iX, i, iP, iC, aNbLP;
199 Standard_Integer aNbFaceFace, k;
200 Standard_Real aApproxTol, aTolR3D, aTolR2D, aTolFF;
201 BRepAdaptor_Surface aBAS1, aBAS2;
202 BOPCol_MapOfInteger aMI;
203 BOPAlgo_VectorOfFaceFace aVFaceFace;
205 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
206 aFFs.SetStartSize(iSize);
207 aFFs.SetIncrement(iSize);
210 bApp=mySectionAttribute.Approximation();
211 bCompC2D1=mySectionAttribute.PCurveOnS1();
212 bCompC2D2=mySectionAttribute.PCurveOnS2();
214 bToSplit = Standard_False;
216 for (; myIterator->More(); myIterator->Next()) {
217 myIterator->Value(nF1, nF2, bJustAdd);
222 const TopoDS_Face& aF1=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
223 const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
225 aBAS1.Initialize(aF1, Standard_False);
226 aBAS2.Initialize(aF2, Standard_False);
228 if (aBAS1.GetType() == GeomAbs_Plane &&
229 aBAS2.GetType() == GeomAbs_Plane) {
230 Standard_Boolean bToIntersect;
233 myDS->UpdateFaceInfoOn(nF1);
234 myDS->UpdateFaceInfoIn(nF1);
237 myDS->UpdateFaceInfoOn(nF2);
238 myDS->UpdateFaceInfoIn(nF2);
241 bToIntersect = CheckPlanes(nF1, nF2);
243 myDS->AddInterf(nF1, nF2);
245 BOPDS_InterfFF& aFF=aFFs(iX);
246 aFF.SetIndices(nF1, nF2);
252 ToleranceFF(aBAS1, aBAS2, aTolFF);
254 BOPAlgo_FaceFace& aFaceFace=aVFaceFace.Append1();
256 aFaceFace.SetIndices(nF1, nF2);
257 aFaceFace.SetFaces(aF1, aF2);
258 aFaceFace.SetTolFF(aTolFF);
260 IntSurf_ListOfPntOn2S aListOfPnts;
261 GetEFPnts(nF1, nF2, aListOfPnts);
262 aNbLP = aListOfPnts.Extent();
264 aFaceFace.SetList(aListOfPnts);
267 aFaceFace.SetParameters(bApp, bCompC2D1, bCompC2D2, aApproxTol);
268 aFaceFace.SetProgressIndicator(myProgressIndicator);
269 }//for (; myIterator->More(); myIterator->Next()) {
271 aNbFaceFace=aVFaceFace.Extent();
272 //======================================================
273 BOPAlgo_FaceFaceCnt::Perform(myRunParallel, aVFaceFace);
274 //======================================================
276 for (k=0; k < aNbFaceFace; ++k) {
277 BOPAlgo_FaceFace& aFaceFace=aVFaceFace(k);
279 aFaceFace.Indices(nF1, nF2);
280 aTolFF=aFaceFace.TolFF();
282 bIsDone=aFaceFace.IsDone();
284 aTolR3D=aFaceFace.TolReached3d();
285 aTolR2D=aFaceFace.TolReached2d();
286 bTangentFaces=aFaceFace.TangentFaces();
288 if (aTolR3D < aTolFF){
291 if (aTolR2D < 1.e-7){
295 aFaceFace.PrepareLines3D(bToSplit);
297 const IntTools_SequenceOfCurves& aCvsX=aFaceFace.Lines();
298 const IntTools_SequenceOfPntOn2Faces& aPntsX=aFaceFace.Points();
300 aNbCurves=aCvsX.Length();
301 aNbPoints=aPntsX.Length();
303 myDS->AddInterf(nF1, nF2);
306 BOPDS_InterfFF& aFF=aFFs(iX);
307 aFF.SetIndices(nF1, nF2);
309 aFF.SetTolR3D(aTolR3D);
310 aFF.SetTolR2D(aTolR2D);
311 aFF.SetTangentFaces(bTangentFaces);
314 aFF.Init(aNbCurves, aNbPoints);
317 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
318 for (i=1; i<=aNbCurves; ++i) {
321 const IntTools_Curve& aIC=aCvsX(i);
322 const Handle(Geom_Curve)& aC3D= aIC.Curve();
323 bValid=IntTools_Tools::CheckCurve(aC3D, aTolR3D, aBox);
326 BOPDS_Curve& aNC=aVNC(iC);
333 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
334 for (i=1; i<=aNbPoints; ++i) {
335 const IntTools_PntOn2Faces& aPi=aPntsX(i);
336 const gp_Pnt& aP=aPi.P1().Pnt();
339 BOPDS_Point& aNP=aVNP(iP);
342 //}// if (aNbCs || aNbPs)
346 BOPDS_InterfFF& aFF=aFFs(iX);
347 aFF.SetIndices(nF1, nF2);
350 aFF.Init(aNbCurves, aNbPoints);
352 }// for (k=0; k < aNbFaceFace; ++k) {
354 //=======================================================================
355 //function : MakeBlocks
357 //=======================================================================
358 void BOPAlgo_PaveFiller::MakeBlocks()
360 Standard_Integer aNbFF;
364 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
370 Standard_Boolean bExist, bValid2D;
371 Standard_Integer i, nF1, nF2, aNbC, aNbP, j;
372 Standard_Integer nV1, nV2;
373 Standard_Real aTolR3D, aT1, aT2, aTol;
374 Handle(NCollection_IncAllocator) aAllocator;
375 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
377 Handle(BOPDS_PaveBlock) aPBOut;
379 //-----------------------------------------------------scope f
380 aAllocator=new NCollection_IncAllocator();
382 BOPCol_ListOfInteger aLSE(aAllocator);
383 BOPCol_MapOfInteger aMVOnIn(100, aAllocator), aMF(100, aAllocator),
384 aMVStick(100,aAllocator), aMVEF(100, aAllocator),
385 aMVB(100, aAllocator), aMI(100, aAllocator);
386 BOPDS_IndexedMapOfPaveBlock aMPBOnIn(100, aAllocator);
387 BOPDS_MapOfPaveBlock aMPBAdd(100, aAllocator);
388 BOPDS_ListOfPaveBlock aLPB(aAllocator);
389 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMSCPB(100, aAllocator);
390 BOPCol_DataMapOfShapeInteger aMVI(100, aAllocator);
391 BOPDS_DataMapOfPaveBlockListOfPaveBlock aDMExEdges(100, aAllocator);
392 BOPCol_DataMapOfIntegerReal aMVTol(100, aAllocator);
393 BOPCol_DataMapIteratorOfDataMapOfIntegerReal aItMV;
394 BOPCol_DataMapOfIntegerInteger aDMI(100, aAllocator);
396 for (i=0; i<aNbFF; ++i) {
400 BOPDS_InterfFF& aFF=aFFs(i);
401 aFF.Indices(nF1, nF2);
403 BOPDS_VectorOfPoint& aVP=aFF.ChangePoints();
405 BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
407 if (!aNbP && !aNbC) {
411 const TopoDS_Face& aF1=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
412 const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
414 aTolR3D=aFF.TolR3D();
418 myDS->UpdateFaceInfoOn(nF1);
421 myDS->UpdateFaceInfoOn(nF2);
424 BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
425 BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
432 myDS->VerticesOnIn(nF1, nF2, aMVOnIn, aMPBOnIn);
433 myDS->SharedEdges(nF1, nF2, aLSE, aAllocator);
436 for (j=0; j<aNbP; ++j) {
438 BOPDS_CoupleOfPaveBlocks aCPB;
440 BOPDS_Point& aNP=aVP.ChangeValue(j);
441 const gp_Pnt& aP=aNP.Pnt();
443 bExist=IsExistingVertex(aP, aTolR3D, aMVOnIn);
445 BOPTools_AlgoTools::MakeNewVertex(aP, aTolR3D, aV);
447 aCPB.SetIndexInterf(i);
449 aMSCPB.Add(aV, aCPB);
456 GetStickVertices(nF1, nF2, aMVStick, aMVEF, aMI);
458 for (j=0; j<aNbC; ++j) {
459 BOPDS_Curve& aNC=aVC.ChangeValue(j);
460 const IntTools_Curve& aIC=aNC.Curve();
462 aNC.InitPaveBlock1();
464 PutPavesOnCurve(aMVOnIn, aTolR3D, aNC, nF1, nF2, aMI, aMVEF, aMVTol);
466 PutStickPavesOnCurve(aF1, aF2, aMI, aNC, aMVStick, aMVTol);
469 PutEFPavesOnCurve(aNC, aMI, aMVEF, aMVTol);
472 if (aIC.HasBounds()) {
473 PutBoundPaveOnCurve(aF1, aF2, aTolR3D, aNC, aMVB);
475 }//for (j=0; j<aNbC; ++j) {
477 // Put closing pave if needed
478 for (j=0; j<aNbC; ++j) {
479 BOPDS_Curve& aNC=aVC.ChangeValue(j);
480 PutClosingPaveOnCurve (aNC);
483 // 3. Make section edges
484 for (j=0; j<aNbC; ++j) {
485 BOPDS_Curve& aNC=aVC.ChangeValue(j);
486 const IntTools_Curve& aIC=aNC.Curve();
488 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
489 Handle(BOPDS_PaveBlock)& aPB1=aNC.ChangePaveBlock1();
492 aPB1->Update(aLPB, Standard_False);
494 aItLPB.Initialize(aLPB);
495 for (; aItLPB.More(); aItLPB.Next()) {
496 Handle(BOPDS_PaveBlock)& aPB=aItLPB.ChangeValue();
497 aPB->Indices(nV1, nV2);
498 aPB->Range (aT1, aT2);
500 if (fabs(aT1 - aT2) < Precision::PConfusion()) {
504 bValid2D=myContext->IsValidBlockForFaces(aT1, aT2, aIC, aF1, aF2, aTolR3D);
509 bExist=IsExistingPaveBlock(aPB, aNC, aTolR3D, aLSE);
514 bExist=IsExistingPaveBlock(aPB, aNC, aTolR3D, aMPBOnIn, aPBOut);
516 if (aMPBAdd.Add(aPBOut)) {
517 Standard_Boolean bInBothFaces = Standard_True;
518 if (!myDS->IsCommonBlock(aPBOut)) {
523 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(nE);
524 aTolE = BRep_Tool::Tolerance(aE);
525 if (aTolR3D > aTolE) {
526 myDS->UpdateEdgeTolerance(nE, aTolR3D);
528 bInBothFaces = Standard_False;
530 bInBothFaces = (aFI1.PaveBlocksOn().Contains(aPBOut) ||
531 aFI1.PaveBlocksIn().Contains(aPBOut))&&
532 (aFI2.PaveBlocksOn().Contains(aPBOut) ||
533 aFI2.PaveBlocksIn().Contains(aPBOut));
536 PreparePostTreatFF(i, aPBOut, aMSCPB, aMVI, aVC);
543 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
544 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
546 BOPTools_AlgoTools::MakeEdge (aIC, aV1, aT1, aV2, aT2, aTolR3D, aES);
547 BOPTools_AlgoTools::MakePCurve(aES, aF1, aF2, aIC,
548 mySectionAttribute.PCurveOnS1(),
549 mySectionAttribute.PCurveOnS2());
551 if (BOPTools_AlgoTools::IsMicroEdge(aES, myContext)) {
555 // Append the Pave Block to the Curve j
558 // Keep info for post treatment
559 BOPDS_CoupleOfPaveBlocks aCPB;
560 aCPB.SetIndexInterf(i);
562 aCPB.SetPaveBlock1(aPB);
564 aMSCPB.Add(aES, aCPB);
573 }//for (j=0; j<aNbC; ++j) {
574 //back to previous tolerance values for unused vertices
575 aItMV.Initialize(aMVTol);
576 for (; aItMV.More(); aItMV.Next()) {
578 aTol = aItMV.Value();
580 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV1);
581 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*)&aV.TShape());
585 ProcessExistingPaveBlocks(i, aMPBOnIn, aMSCPB, aMVI, aMVB, aMPBAdd);
586 }//for (i=0; i<aNbFF; ++i) {
589 myErrorStatus=PostTreatFF(aMSCPB, aMVI, aDMExEdges, aDMI, aAllocator);
595 UpdateFaceInfo(aDMExEdges);
596 //Update all pave blocks
597 UpdatePaveBlocks(aDMI);
598 //-----------------------------------------------------scope t
606 aAllocator.Nullify();
609 //=======================================================================
610 //function : PostTreatFF
612 //=======================================================================
613 Standard_Integer BOPAlgo_PaveFiller::PostTreatFF
614 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMSCPB,
615 BOPCol_DataMapOfShapeInteger& aMVI,
616 BOPDS_DataMapOfPaveBlockListOfPaveBlock& aDMExEdges,
617 BOPCol_DataMapOfIntegerInteger& aDMI,
618 Handle(NCollection_BaseAllocator)& theAllocator)
620 Standard_Integer iRet, aNbS;
623 aNbS=theMSCPB.Extent();
628 Standard_Boolean bHasPaveBlocks, bOld;
629 Standard_Integer iErr, nSx, nVSD, iX, iP, iC, j, nV, iV = 0, iE, k;
630 Standard_Integer jx, aNbLPBx;
632 TopAbs_ShapeEnum aType;
634 BOPCol_ListIteratorOfListOfShape aItLS;
635 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
637 Handle(BOPDS_PaveBlock) aPB1;
638 BOPDS_Pave aPave[2], aPave1[2];
641 BOPCol_ListOfShape aLS(theAllocator);
642 BOPAlgo_PaveFiller aPF(theAllocator);
644 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
650 const TopoDS_Shape& aS=theMSCPB.FindKey(1);
651 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromIndex(1);
654 aType=aS.ShapeType();
655 if (aType==TopAbs_VERTEX) {
656 aSI.SetShapeType(aType);
658 iV=myDS->Append(aSI);
660 iX=aCPB.IndexInterf();
662 BOPDS_InterfFF& aFF=aFFs(iX);
663 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
664 BOPDS_Point& aNP=aVNP(iP);
667 else if (aType==TopAbs_EDGE) {
668 aPB1=aCPB.PaveBlock1();
670 if (aPB1->HasEdge()) {
671 BOPDS_ListOfPaveBlock aLPBx;
673 aDMExEdges.Bind(aPB1, aLPBx);
675 aSI.SetShapeType(aType);
677 iE=myDS->Append(aSI);
685 // 1 prepare arguments
686 for (k=1; k<=aNbS; ++k) {
687 const TopoDS_Shape& aS=theMSCPB.FindKey(k);
692 aPF.SetProgressIndicator(myProgressIndicator);
693 aPF.SetRunParallel(myRunParallel);
694 aPF.SetArguments(aLS);
696 iErr=aPF.ErrorStatus();
703 aItLS.Initialize(aLS);
704 for (; aItLS.More(); aItLS.Next()) {
705 const TopoDS_Shape& aSx=aItLS.Value();
706 nSx=aPDS->Index(aSx);
707 const BOPDS_ShapeInfo& aSIx=aPDS->ShapeInfo(nSx);
709 aType=aSIx.ShapeType();
711 if (aType==TopAbs_VERTEX) {
712 if (aPDS->HasShapeSD(nSx, nVSD)) {
713 aV=aPDS->Shape(nVSD);
718 // index of new vertex in theDS -> iV
719 if (!aMVI.IsBound(aV)) {
720 aSI.SetShapeType(aType);
722 iV=myDS->Append(aSI);
729 // update FF interference
730 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx);
731 iX=aCPB.IndexInterf();
733 BOPDS_InterfFF& aFF=aFFs(iX);
734 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
735 BOPDS_Point& aNP=aVNP(iP);
737 }//if (aType==TopAbs_VERTEX) {
739 else if (aType==TopAbs_EDGE) {
740 bHasPaveBlocks=aPDS->HasPaveBlocks(nSx);
741 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx);
742 iX=aCPB.IndexInterf();
744 aPB1=aCPB.PaveBlock1();
746 bOld = aPB1->HasEdge();
748 BOPDS_ListOfPaveBlock aLPBx;
749 aDMExEdges.Bind(aPB1, aLPBx);
752 if (!bHasPaveBlocks) {
754 aDMExEdges.ChangeFind(aPB1).Append(aPB1);
756 aSI.SetShapeType(aType);
758 iE=myDS->Append(aSI);
764 BOPDS_InterfFF& aFF=aFFs(iX);
765 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
766 BOPDS_Curve& aNC=aVNC(iC);
767 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
769 const BOPDS_ListOfPaveBlock& aLPBx=aPDS->PaveBlocks(nSx);
770 aNbLPBx=aLPBx.Extent();
772 if (bOld && !aNbLPBx) {
773 aDMExEdges.ChangeFind(aPB1).Append(aPB1);
778 aItLPB.Initialize(aLPBC);
779 for (; aItLPB.More(); aItLPB.Next()) {
780 const Handle(BOPDS_PaveBlock)& aPBC=aItLPB.Value();
782 aLPBC.Remove(aItLPB);
791 if (!aMVI.IsBound(aE)) {
792 aSI.SetShapeType(aType);
794 iE=myDS->Append(aSI);
800 // append new PaveBlock to aLPBC
806 aItLPB.Initialize(aLPBx);
808 aPave1[0] = aPB1->Pave1();
809 aPave1[1] = aPB1->Pave2();
811 for (; aItLPB.More(); aItLPB.Next()) {
812 const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value();
813 const Handle(BOPDS_PaveBlock) aPBRx=aPDS->RealPaveBlock(aPBx);
815 // update vertices of paves
816 aPave[0]=aPBx->Pave1();
817 aPave[1]=aPBx->Pave2();
818 for (j=0; j<2; ++j) {
821 aT = aPave[j].Parameter();
822 if (aT == aPave1[0].Parameter()) {
824 } else if (aT == aPave1[1].Parameter()) {
829 iV = aPave1[jx-1].Index();
836 if (!aMVI.IsBound(aV)) {// index of new vertex in theDS -> iV
837 aSI.SetShapeType(TopAbs_VERTEX);
839 iV=myDS->Append(aSI);
846 const BOPDS_Pave& aP1 = !j ? aPB1->Pave1() : aPB1->Pave2();
847 if (aP1.Parameter() == aPave[j].Parameter() && aP1.Index() != iV) {
848 aDMI.Bind(aP1.Index(), iV);
849 myDS->AddShapeSD(aP1.Index(), iV);
852 aPave[j].SetIndex(iV);
856 aE=aPDS->Shape(aPBRx->Edge());
858 if (!aMVI.IsBound(aE)) {
859 aSI.SetShapeType(aType);
861 iE=myDS->Append(aSI);
867 // append new PaveBlock to aLPBC
868 Handle(BOPDS_PaveBlock) aPBC=new BOPDS_PaveBlock();
870 aPBC->SetPave1(aPave[0]);
871 aPBC->SetPave2(aPave[1]);
874 aPBC->SetOriginalEdge(aPB1->OriginalEdge());
875 aDMExEdges.ChangeFind(aPB1).Append(aPBC);
883 }//else if (aType==TopAbs_EDGE)
884 }//for (; aItLS.More(); aItLS.Next()) {
888 //=======================================================================
889 //function : UpdateFaceInfo
891 //=======================================================================
892 void BOPAlgo_PaveFiller::UpdateFaceInfo(BOPDS_DataMapOfPaveBlockListOfPaveBlock& theDME)
894 Standard_Integer i, j, nV1, nF1, nF2,
895 aNbFF, aNbC, aNbP, aNbS, aNbPBIn;
896 BOPDS_IndexedMapOfPaveBlock aMPBCopy;
897 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
899 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
902 //1. Sections (curves, points);
903 for (i=0; i<aNbFF; ++i) {
904 BOPDS_InterfFF& aFF=aFFs(i);
905 aFF.Indices(nF1, nF2);
907 BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
908 BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
910 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
912 for (j=0; j<aNbC; ++j) {
913 BOPDS_Curve& aNC=aVNC(j);
914 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
915 aItLPB.Initialize(aLPBC);
917 if (aItLPB.More() && theDME.IsBound(aLPBC.First())) {
918 const Handle(BOPDS_PaveBlock)& aPB=aLPBC.First();
919 BOPDS_ListOfPaveBlock& aLPB = theDME.ChangeFind(aPB);
920 UpdateExistingPaveBlocks(aPB, aLPB, nF1, nF2);
925 for(; aItLPB.More(); aItLPB.Next()) {
926 const Handle(BOPDS_PaveBlock)& aPB=aItLPB.Value();
927 aFI1.ChangePaveBlocksSc().Add(aPB);
928 aFI2.ChangePaveBlocksSc().Add(aPB);
932 const BOPDS_VectorOfPoint& aVNP=aFF.Points();
934 for (j=0; j<aNbP; ++j) {
935 const BOPDS_Point& aNP=aVNP(j);
937 aFI1.ChangeVerticesSc().Add(nV1);
938 aFI2.ChangeVerticesSc().Add(nV1);
943 if (theDME.IsEmpty()) {
947 aNbS=myDS->NbSourceShapes();
948 for (i=0; i<aNbS; ++i) {
949 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
950 if (aSI.ShapeType()!=TopAbs_FACE) {
953 if(!myDS->HasFaceInfo(i)) {
956 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(i);
958 BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.ChangePaveBlocksIn();
959 aMPBCopy.Assign(aMPBIn);
962 aNbPBIn=aMPBCopy.Extent();
963 for (j=1; j<=aNbPBIn; ++j) {
964 const Handle(BOPDS_PaveBlock)& aPB = aMPBCopy(j);
965 if (theDME.IsBound(aPB)) {
966 const BOPDS_ListOfPaveBlock& aLPB = theDME.Find(aPB);
967 aItLPB.Initialize(aLPB);
968 for (; aItLPB.More(); aItLPB.Next()) {
969 const Handle(BOPDS_PaveBlock)& aPB1 = aItLPB.Value();
975 }//for (j=1; j<=aNbPBIn; ++j) {
976 }//for (i=0; i<aNbS; ++i) {
978 //=======================================================================
979 //function : IsExistingVertex
981 //=======================================================================
982 Standard_Boolean BOPAlgo_PaveFiller::IsExistingVertex
984 const Standard_Real theTolR3D,
985 const BOPCol_MapOfInteger& aMVOnIn)const
987 Standard_Boolean bRet;
988 Standard_Integer nV, iFlag;
992 BOPCol_MapIteratorOfMapOfInteger aIt;
997 aBoxP.Enlarge(theTolR3D);
999 aIt.Initialize(aMVOnIn);
1000 for (; aIt.More(); aIt.Next()) {
1004 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1005 aPV=BRep_Tool::Pnt(aV);
1006 aTolV=BRep_Tool::Tolerance(aV);
1008 aBoxV.Enlarge(aTolV);
1010 if (!aBoxP.IsOut(aBoxV)) {
1011 iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP, theTolR3D);
1019 //=======================================================================
1020 //function : IsExistingPaveBlock
1022 //=======================================================================
1023 Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock
1024 (const Handle(BOPDS_PaveBlock)& thePB,
1025 const BOPDS_Curve& theNC,
1026 const Standard_Real theTolR3D,
1027 const BOPCol_ListOfInteger& theLSE)
1029 Standard_Boolean bRet=Standard_True;
1031 if (theLSE.IsEmpty()) {
1035 Standard_Real aT1, aT2, aTm, aTx, aTol;
1036 Standard_Integer nE, iFlag;
1039 BOPCol_ListIteratorOfListOfInteger aItLI;
1041 thePB->Range(aT1, aT2);
1042 aTm=IntTools_Tools::IntermediatePoint (aT1, aT2);
1043 theNC.Curve().D0(aTm, aPm);
1045 aBoxPm.Enlarge(theTolR3D);
1047 aItLI.Initialize(theLSE);
1048 for (; aItLI.More(); aItLI.Next()) {
1050 const BOPDS_ShapeInfo& aSIE=myDS->ChangeShapeInfo(nE);
1051 const Bnd_Box& aBoxE=aSIE.Box();
1052 if (!aBoxE.IsOut(aBoxPm)) {
1053 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape()));
1054 aTol = BRep_Tool::Tolerance(aE);
1055 aTol = aTol > theTolR3D ? aTol : theTolR3D;
1056 iFlag=myContext->ComputePE(aPm, aTol, aE, aTx);
1065 //=======================================================================
1066 //function : IsExistingPaveBlock
1068 //=======================================================================
1069 Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock
1070 (const Handle(BOPDS_PaveBlock)& thePB,
1071 const BOPDS_Curve& theNC,
1072 const Standard_Real theTolR3D,
1073 const BOPDS_IndexedMapOfPaveBlock& theMPBOnIn,
1074 Handle(BOPDS_PaveBlock&) aPBOut)
1076 Standard_Boolean bRet;
1077 Standard_Real aT1, aT2, aTm, aTx;
1078 Standard_Integer nSp, iFlag1, iFlag2, nV11, nV12, nV21, nV22, i, aNbPB;
1079 gp_Pnt aP1, aPm, aP2;
1080 Bnd_Box aBoxP1, aBoxPm, aBoxP2;
1082 bRet=Standard_False;
1083 const IntTools_Curve& aIC=theNC.Curve();
1085 thePB->Range(aT1, aT2);
1086 thePB->Indices(nV11, nV12);
1090 aBoxP1.Enlarge(theTolR3D);
1091 //intermediate point
1092 aTm=IntTools_Tools::IntermediatePoint (aT1, aT2);
1095 aBoxPm.Enlarge(theTolR3D);
1099 aBoxP2.Enlarge(theTolR3D);
1101 aNbPB = theMPBOnIn.Extent();
1102 for (i = 1; i <= aNbPB; ++i) {
1103 const Handle(BOPDS_PaveBlock)& aPB = theMPBOnIn(i);
1104 aPB->Indices(nV21, nV22);
1106 const BOPDS_ShapeInfo& aSISp=myDS->ChangeShapeInfo(nSp);
1107 const TopoDS_Edge& aSp=(*(TopoDS_Edge *)(&aSISp.Shape()));
1108 const Bnd_Box& aBoxSp=aSISp.Box();
1110 iFlag1 = (nV11 == nV21 || nV11 == nV22) ? 2 : (!aBoxSp.IsOut(aBoxP1) ? 1 : 0);
1111 iFlag2 = (nV12 == nV21 || nV12 == nV22) ? 2 : (!aBoxSp.IsOut(aBoxP2) ? 1 : 0);
1112 if (iFlag1 && iFlag2) {
1113 if (aBoxSp.IsOut(aBoxPm) || myContext->ComputePE(aPm, theTolR3D, aSp, aTx)) {
1118 iFlag1 = !myContext->ComputePE(aP1, theTolR3D, aSp, aTx);
1122 iFlag2 = !myContext->ComputePE(aP2, theTolR3D, aSp, aTx);
1125 if (iFlag1 && iFlag2) {
1135 //=======================================================================
1136 //function : PutBoundPaveOnCurve
1138 //=======================================================================
1139 void BOPAlgo_PaveFiller::PutBoundPaveOnCurve(const TopoDS_Face& aF1,
1140 const TopoDS_Face& aF2,
1141 const Standard_Real aTolR3D,
1143 BOPCol_MapOfInteger& aMVB)
1145 Standard_Boolean bVF;
1146 Standard_Integer nV, iFlag, nVn, j, aNbEP;
1147 Standard_Real aT[2], aTmin, aTmax, aTV, aTol, aTolVnew;
1150 BOPDS_ListIteratorOfListOfPave aItLP;
1151 BOPDS_Pave aPn, aPMM[2];
1153 aTolVnew = Precision::Confusion();
1155 const IntTools_Curve& aIC=aNC.Curve();
1156 aIC.Bounds(aT[0], aT[1], aP[0], aP[1]);
1158 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1159 const BOPDS_ListOfPave& aLP=aPB->ExtPaves();
1166 aItLP.Initialize(aLP);
1167 for (; aItLP.More(); aItLP.Next()) {
1168 const BOPDS_Pave& aPv=aItLP.Value();
1169 aPv.Contents(nV, aTV);
1181 for (j=0; j<2; ++j) {
1182 //if curve is closed, process only one bound
1183 if (j && aP[1].IsEqual(aP[0], aTolVnew)) {
1193 aTol = aTolR3D+Precision::Confusion();
1194 aBoxP.Enlarge(aTol);
1195 const BOPDS_Pave& aPV=aPMM[j];
1197 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1198 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&aSIV.Shape()));
1199 const Bnd_Box& aBoxV=aSIV.Box();
1200 if (!aBoxP.IsOut(aBoxV)){
1201 iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP[j], aTol);
1206 bVF=myContext->IsValidPointForFaces (aP[j], aF1, aF2, aTolR3D);
1211 BOPDS_ShapeInfo aSIVn;
1213 BOPTools_AlgoTools::MakeNewVertex(aP[j], aTolR3D, aVn);
1214 aSIVn.SetShapeType(TopAbs_VERTEX);
1215 aSIVn.SetShape(aVn);
1217 nVn=myDS->Append(aSIVn);
1220 aPn.SetParameter(aT[j]);
1221 aPB->AppendExtPave(aPn);
1223 aVn=(*(TopoDS_Vertex *)(&myDS->Shape(nVn)));
1224 BOPTools_AlgoTools::UpdateVertex (aIC, aT[j], aVn);
1226 aTolVnew = BRep_Tool::Tolerance(aVn);
1228 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nVn);
1229 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
1230 BRepBndLib::Add(aVn, aBoxDS);
1236 //=======================================================================
1237 //function : PutPavesOnCurve
1239 //=======================================================================
1240 void BOPAlgo_PaveFiller::PutPavesOnCurve(const BOPCol_MapOfInteger& aMVOnIn,
1241 const Standard_Real aTolR3D,
1243 const Standard_Integer nF1,
1244 const Standard_Integer nF2,
1245 const BOPCol_MapOfInteger& aMI,
1246 const BOPCol_MapOfInteger& aMVEF,
1247 BOPCol_DataMapOfIntegerReal& aMVTol)
1249 Standard_Boolean bInBothFaces;
1250 Standard_Integer nV;
1251 BOPCol_MapIteratorOfMapOfInteger aIt;
1253 const Bnd_Box& aBoxC=aNC.Box();
1255 //Put EF vertices first
1256 aIt.Initialize(aMVEF);
1257 for (; aIt.More(); aIt.Next()) {
1259 PutPaveOnCurve(nV, aTolR3D, aNC, aMI, aMVTol, 2);
1261 //Put all other vertices
1262 aIt.Initialize(aMVOnIn);
1263 for (; aIt.More(); aIt.Next()) {
1265 if (aMVEF.Contains(nV)) {
1269 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1270 const Bnd_Box& aBoxV=aSIV.Box();
1272 if (aBoxC.IsOut(aBoxV)){
1275 if (!myDS->IsNewShape(nV)) {
1276 const BOPDS_FaceInfo& aFI1 = myDS->FaceInfo(nF1);
1277 const BOPDS_FaceInfo& aFI2 = myDS->FaceInfo(nF2);
1279 bInBothFaces = (aFI1.VerticesOn().Contains(nV) ||
1280 aFI1.VerticesIn().Contains(nV))&&
1281 (aFI2.VerticesOn().Contains(nV) ||
1282 aFI2.VerticesIn().Contains(nV));
1283 if (!bInBothFaces) {
1288 PutPaveOnCurve(nV, aTolR3D, aNC, aMI, aMVTol, 1);
1292 //=======================================================================
1293 //function : ExtendedTolerance
1295 //=======================================================================
1296 Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance(const Standard_Integer nV,
1297 const BOPCol_MapOfInteger& aMI,
1298 Standard_Real& aTolVExt,
1299 const Standard_Integer aType)
1301 Standard_Boolean bFound = Standard_False;
1302 if (!(myDS->IsNewShape(nV))) {
1306 Standard_Integer i, k, aNbLines, aNbInt;
1307 Standard_Real aT11, aT12, aD1, aD2, aD;
1309 gp_Pnt aPV, aP11, aP12;
1315 } else if (aType == 2) {
1319 aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1320 aPV=BRep_Tool::Pnt(aV);
1322 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
1323 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1325 for (; k<aNbInt; ++k) {
1326 aNbLines = !k ? aEEs.Extent() : aEFs.Extent();
1327 for (i = 0; i < aNbLines; ++i) {
1328 BOPDS_Interf *aInt = !k ? (BOPDS_Interf*) (&aEEs(i)) :
1329 (BOPDS_Interf*) (&aEFs(i));
1330 if (aInt->IndexNew() == nV) {
1331 if (aMI.Contains(aInt->Index1()) && aMI.Contains(aInt->Index2())) {
1332 const IntTools_CommonPrt& aComPrt = !k ? aEEs(i).CommonPart() :
1333 aEFs(i).CommonPart();
1335 const TopoDS_Edge& aE1=aComPrt.Edge1();
1336 aComPrt.Range1(aT11, aT12);
1337 BOPTools_AlgoTools::PointOnEdge(aE1, aT11, aP11);
1338 BOPTools_AlgoTools::PointOnEdge(aE1, aT12, aP12);
1339 aD1=aPV.Distance(aP11);
1340 aD2=aPV.Distance(aP12);
1341 aD=(aD1>aD2)? aD1 : aD2;
1346 }//if (aMI.Contains(aEF.Index1()) && aMI.Contains(aEF.Index2())) {
1347 }//if (aInt->IndexNew() == nV) {
1348 }//for (i = 0; i < aNbLines; ++i) {
1349 }//for (k=0; k<2; ++k) {
1353 //=======================================================================
1354 //function : GetEFPnts
1356 //=======================================================================
1357 void BOPAlgo_PaveFiller::GetEFPnts(const Standard_Integer nF1,
1358 const Standard_Integer nF2,
1359 IntSurf_ListOfPntOn2S& aListOfPnts)
1361 Standard_Integer nE, nF, nFOpposite, aNbEFs, i;
1362 Standard_Real U1, U2, V1, V2, f, l;
1363 BOPCol_MapOfInteger aMI;
1365 //collect indexes of all shapes from nF1 and nF2.
1366 GetFullShapeMap(nF1, aMI);
1367 GetFullShapeMap(nF2, aMI);
1369 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1370 aNbEFs = aEFs.Extent();
1372 for(i = 0; i < aNbEFs; ++i) {
1373 const BOPDS_InterfEF& aEF = aEFs(i);
1374 if (aEF.HasIndexNew()) {
1375 aEF.Indices(nE, nFOpposite);
1376 if(aMI.Contains(nE) && aMI.Contains(nFOpposite)) {
1377 const IntTools_CommonPrt& aCP = aEF.CommonPart();
1378 Standard_Real aPar = aCP.VertexParameter1();
1379 const TopoDS_Edge& aE = (*(TopoDS_Edge*)(&myDS->Shape(nE)));
1380 const TopoDS_Face& aFOpposite = (*(TopoDS_Face*)(&myDS->Shape(nFOpposite)));
1382 const Handle(Geom_Curve)& aCurve = BRep_Tool::Curve(aE, f, l);
1384 nF = (nFOpposite == nF1) ? nF2 : nF1;
1385 const TopoDS_Face& aF = (*(TopoDS_Face*)(&myDS->Shape(nF)));
1386 Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface(aE, aF, f, l);
1388 GeomAPI_ProjectPointOnSurf& aProj = myContext->ProjPS(aFOpposite);
1391 aCurve->D0(aPar, aPoint);
1392 IntSurf_PntOn2S aPnt;
1393 if(!aPCurve.IsNull()) {
1394 gp_Pnt2d aP2d = aPCurve->Value(aPar);
1395 aProj.Perform(aPoint);
1396 if(aProj.IsDone()) {
1397 aProj.LowerDistanceParameters(U1,V1);
1399 aPnt.SetValue(aP2d.X(),aP2d.Y(),U1,V1);
1401 aPnt.SetValue(U1,V1,aP2d.X(),aP2d.Y());
1403 aListOfPnts.Append(aPnt);
1407 GeomAPI_ProjectPointOnSurf& aProj1 = myContext->ProjPS(aF);
1408 aProj1.Perform(aPoint);
1409 aProj.Perform(aPoint);
1410 if(aProj1.IsDone() && aProj.IsDone()){
1411 aProj1.LowerDistanceParameters(U1,V1);
1412 aProj.LowerDistanceParameters(U2,V2);
1414 aPnt.SetValue(U1,V1,U2,V2);
1416 aPnt.SetValue(U2,V2,U1,V1);
1418 aListOfPnts.Append(aPnt);
1426 //=======================================================================
1427 //function : ProcessUnUsedVertices
1429 //=======================================================================
1430 void BOPAlgo_PaveFiller::PutEFPavesOnCurve(BOPDS_Curve& aNC,
1431 const BOPCol_MapOfInteger& aMI,
1432 const BOPCol_MapOfInteger& aMVEF,
1433 BOPCol_DataMapOfIntegerReal& aMVTol)
1435 if (!aMVEF.Extent()) {
1439 const IntTools_Curve& aIC=aNC.Curve();
1440 GeomAbs_CurveType aTypeC;
1442 if (!(aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve)) {
1446 Standard_Integer nV;
1447 BOPCol_MapOfInteger aMV;
1450 RemoveUsedVertices(aNC, aMV);
1451 if (!aMV.Extent()) {
1455 Standard_Real aDist;
1458 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1459 GeomAPI_ProjectPointOnCurve& aProjPT = myContext->ProjPT(aC3D);
1461 BOPCol_MapIteratorOfMapOfInteger aItMI;
1462 aItMI.Initialize(aMV);
1463 for (; aItMI.More(); aItMI.Next()) {
1465 const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1466 gp_Pnt aPV = BRep_Tool::Pnt(aV);
1467 aProjPT.Perform(aPV);
1468 Standard_Integer aNbPoints = aProjPT.NbPoints();
1470 aDist = aProjPT.LowerDistance();
1471 PutPaveOnCurve(nV, aDist, aNC, aMI, aMVTol);
1476 //=======================================================================
1477 //function : ProcessUnUsedVertices
1479 //=======================================================================
1480 void BOPAlgo_PaveFiller::PutStickPavesOnCurve(const TopoDS_Face& aF1,
1481 const TopoDS_Face& aF2,
1482 const BOPCol_MapOfInteger& aMI,
1484 const BOPCol_MapOfInteger& aMVStick,
1485 BOPCol_DataMapOfIntegerReal& aMVTol)
1487 BOPCol_MapOfInteger aMV;
1488 aMV.Assign(aMVStick);
1489 RemoveUsedVertices(aNC, aMV);
1491 if (!aMV.Extent()) {
1495 GeomAbs_SurfaceType aType1, aType2;
1496 Handle(Geom_Surface) aS1=BRep_Tool::Surface(aF1);
1497 Handle(Geom_Surface) aS2=BRep_Tool::Surface(aF2);
1498 GeomAdaptor_Surface aGAS1(aS1);
1499 GeomAdaptor_Surface aGAS2(aS2);
1501 aType1=aGAS1.GetType();
1502 aType2=aGAS2.GetType();
1504 //if (aType1==GeomAbs_Torus || aType2==GeomAbs_Torus) {
1505 GeomAbs_CurveType aTypeC;
1507 const IntTools_Curve& aIC=aNC.Curve();
1509 //if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
1510 Handle(Geom2d_Curve) aC2D[2];
1512 aC2D[0]=aIC.FirstCurve2d();
1513 aC2D[1]=aIC.SecondCurve2d();
1514 if (!aC2D[0].IsNull() && !aC2D[1].IsNull()) {
1515 Standard_Integer nV, m, n;
1516 Standard_Real aTC[2], aD, aD2, u, v, aDT2, aScPr, aDScPr;
1520 BOPCol_MapIteratorOfMapOfInteger aItMI, aItMI1;
1522 aDT2=2e-7; // the rich criteria
1523 aDScPr=5.e-9; // the creasing criteria
1524 aIC.Bounds(aTC[0], aTC[1], aPC[0], aPC[1]);
1526 aItMI.Initialize(aMV);
1527 for (; aItMI.More(); aItMI.Next()) {
1529 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&myDS->Shape(nV));
1530 aPV=BRep_Tool::Pnt(aV);
1532 for (m=0; m<2; ++m) {
1533 aD2=aPC[m].SquareDistance(aPV);
1534 if (aD2>aDT2) {// no rich
1538 for (n=0; n<2; ++n) {
1539 Handle(Geom_Surface)& aS=(!n)? aS1 : aS2;
1540 aC2D[n]->D0(aTC[m], aP2D);
1542 BOPTools_AlgoTools3D::GetNormalToSurface(aS, u, v, aDN[n]);
1545 aScPr=aDN[0]*aDN[1];
1555 // The intersection curve aIC is vanishing curve (the crease)
1558 PutPaveOnCurve(nV, aD, aNC, aMI, aMVTol);
1560 }//for (jVU=1; jVU=aNbVU; ++jVU) {
1562 //}//if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
1563 //}//if(aType1==GeomAbs_Torus || aType2==GeomAbs_Torus) {
1566 //=======================================================================
1567 //function : GetStickVertices
1569 //=======================================================================
1570 void BOPAlgo_PaveFiller::GetStickVertices(const Standard_Integer nF1,
1571 const Standard_Integer nF2,
1572 BOPCol_MapOfInteger& aMVStick,
1573 BOPCol_MapOfInteger& aMVEF,
1574 BOPCol_MapOfInteger& aMI)
1576 Standard_Integer nS1, nS2, nVNew, aTypeInt, i;
1578 BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV();
1579 BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
1580 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
1581 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
1582 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1584 Standard_Integer aNbLines[5] = {aVVs.Extent(), aVEs.Extent(), aEEs.Extent(),
1585 aVFs.Extent(), aEFs.Extent()};
1586 //collect indices of all shapes from nF1 and nF2.
1588 GetFullShapeMap(nF1, aMI);
1589 GetFullShapeMap(nF2, aMI);
1591 //collect VV, VE, EE, VF interferences
1592 for (aTypeInt = 0; aTypeInt < 4; ++aTypeInt) {
1593 for (i = 0; i < aNbLines[aTypeInt]; ++i) {
1594 BOPDS_Interf* aInt = (aTypeInt==0) ? (BOPDS_Interf*)(&aVVs(i)) :
1595 ((aTypeInt==1) ? (BOPDS_Interf*)(&aVEs(i)) :
1596 ((aTypeInt==2) ? (BOPDS_Interf*)(&aEEs(i)) : (BOPDS_Interf*)(&aVFs(i))));
1597 if (aInt->HasIndexNew()) {
1598 aInt->Indices(nS1, nS2);
1599 if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
1600 nVNew = aInt->IndexNew();
1601 aMVStick.Add(nVNew);
1606 //collect EF interferences
1607 for (i = 0; i < aNbLines[4]; ++i) {
1608 const BOPDS_InterfEF& aInt = aEFs(i);
1609 if (aInt.HasIndexNew()) {
1610 aInt.Indices(nS1, nS2);
1611 if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
1612 nVNew = aInt.IndexNew();
1613 aMVStick.Add(nVNew);
1620 //=======================================================================
1621 // function: GetFullShapeMap
1623 //=======================================================================
1624 void BOPAlgo_PaveFiller::GetFullShapeMap(const Standard_Integer nF,
1625 BOPCol_MapOfInteger& aMI)
1627 BOPCol_ListIteratorOfListOfInteger aIt;
1628 Standard_Integer nS;
1630 const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(nF);
1631 const BOPCol_ListOfInteger& aLI = aSI.SubShapes();
1634 aIt.Initialize(aLI);
1635 for (; aIt.More(); aIt.Next()) {
1641 //=======================================================================
1642 // function: RemoveUsedVertices
1644 //=======================================================================
1645 void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
1646 BOPCol_MapOfInteger& aMV)
1648 if (!aMV.Extent()) {
1651 Standard_Integer nV;
1653 BOPDS_ListIteratorOfListOfPave aItLP;
1655 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1656 const BOPDS_ListOfPave& aLP = aPB->ExtPaves();
1657 aItLP.Initialize(aLP);
1658 for (;aItLP.More();aItLP.Next()) {
1659 aPave = aItLP.Value();
1665 //=======================================================================
1666 //function : PutPaveOnCurve
1668 //=======================================================================
1669 void BOPAlgo_PaveFiller::PutPaveOnCurve(const Standard_Integer nV,
1670 const Standard_Real aTolR3D,
1672 const BOPCol_MapOfInteger& aMI,
1673 BOPCol_DataMapOfIntegerReal& aMVTol,
1674 const Standard_Integer iCheckExtend)
1676 Standard_Boolean bIsVertexOnLine;
1677 Standard_Real aT, aTol, aTolNew;
1680 const TopoDS_Vertex aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1681 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1682 const IntTools_Curve& aIC = aNC.Curve();
1684 bIsVertexOnLine=myContext->IsVertexOnLine(aV, aIC, aTolR3D, aT);
1685 if (!bIsVertexOnLine && iCheckExtend) {
1686 aTol = BRep_Tool::Tolerance(aV);
1688 ExtendedTolerance(nV, aMI, aTol, iCheckExtend);
1689 bIsVertexOnLine=myContext->IsVertexOnLine(aV, aTol, aIC, aTolR3D, aT);
1692 if (bIsVertexOnLine) {
1694 aPave.SetParameter(aT);
1696 aPB->AppendExtPave(aPave);
1698 aTol = BRep_Tool::Tolerance(aV);
1700 BOPTools_AlgoTools::UpdateVertex (aIC, aT, aV);
1702 if (!aMVTol.IsBound(nV)) {
1703 aTolNew = BRep_Tool::Tolerance(aV);
1704 if (aTolNew > aTol) {
1705 aMVTol.Bind(nV, aTol);
1709 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV);
1710 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
1711 BRepBndLib::Add(aV, aBoxDS);
1715 //=======================================================================
1716 //function : ProcessOldPaveBlocks
1718 //=======================================================================
1719 void BOPAlgo_PaveFiller::ProcessExistingPaveBlocks
1720 (const Standard_Integer theInt,
1721 const BOPDS_IndexedMapOfPaveBlock& aMPBOnIn,
1722 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
1723 BOPCol_DataMapOfShapeInteger& aMVI,
1724 const BOPCol_MapOfInteger& aMVB,
1725 BOPDS_MapOfPaveBlock& aMPB)
1727 Standard_Integer nV, nE, iFlag, i, aNbPB;
1729 BOPCol_MapIteratorOfMapOfInteger aItB;
1731 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
1732 BOPDS_InterfFF& aFF = aFFs(theInt);
1733 BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
1735 aItB.Initialize(aMVB);
1736 for (; aItB.More(); aItB.Next()) {
1738 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1739 const Bnd_Box& aBoxV=aSIV.Box();
1740 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&aSIV.Shape();
1741 if (!aMVI.IsBound(aV)) {
1745 aNbPB = aMPBOnIn.Extent();
1746 for (i = 1; i <= aNbPB; ++i) {
1747 const Handle(BOPDS_PaveBlock)& aPB = aMPBOnIn(i);
1748 if (aPB->Pave1().Index() == nV || aPB->Pave2().Index() == nV) {
1752 if (aMPB.Contains(aPB)) {
1756 const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
1757 const Bnd_Box& aBoxE=aSIE.Box();
1759 if (!aBoxV.IsOut(aBoxE)) {
1760 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aSIE.Shape();
1762 iFlag=myContext->ComputeVE (aV, aE, aT);
1766 PreparePostTreatFF(theInt, aPB, aMSCPB, aMVI, aVC);
1773 //=======================================================================
1774 //function : UpdateExistingPaveBlocks
1776 //=======================================================================
1777 void BOPAlgo_PaveFiller::UpdateExistingPaveBlocks
1778 (const Handle(BOPDS_PaveBlock)& aPBf,
1779 BOPDS_ListOfPaveBlock& aLPB,
1780 const Standard_Integer nF1,
1781 const Standard_Integer nF2)
1783 Standard_Integer nE;
1784 Standard_Boolean bCB;
1785 Handle(BOPDS_PaveBlock) aPB, aPB1, aPB2, aPB2n;
1786 Handle(BOPDS_CommonBlock) aCB;
1787 BOPDS_ListIteratorOfListOfPaveBlock aIt, aIt1, aIt2;
1788 BOPDS_IndexedMapOfPaveBlock aMPB;
1790 //remove micro edges from aLPB
1791 aIt.Initialize(aLPB);
1792 for (; aIt.More();) {
1794 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
1795 if (BOPTools_AlgoTools::IsMicroEdge(aE, myContext)) {
1802 if (!aLPB.Extent()) {
1806 myDS->UpdateFaceInfoOn(nF1);
1808 myDS->UpdateFaceInfoOn(nF2);
1810 BOPDS_FaceInfo& aFI1 = myDS->ChangeFaceInfo(nF1);
1811 BOPDS_FaceInfo& aFI2 = myDS->ChangeFaceInfo(nF2);
1813 BOPDS_IndexedMapOfPaveBlock& aMPBOn1 = aFI1.ChangePaveBlocksOn();
1814 BOPDS_IndexedMapOfPaveBlock& aMPBIn1 = aFI1.ChangePaveBlocksIn();
1815 BOPDS_IndexedMapOfPaveBlock& aMPBOn2 = aFI2.ChangePaveBlocksOn();
1816 BOPDS_IndexedMapOfPaveBlock& aMPBIn2 = aFI2.ChangePaveBlocksIn();
1818 // remove old pave blocks
1819 const Handle(BOPDS_CommonBlock)& aCB1 = myDS->CommonBlock(aPBf);
1820 bCB = !aCB1.IsNull();
1821 BOPDS_ListOfPaveBlock aLPB1;
1824 aLPB1.Assign(aCB1->PaveBlocks());
1828 aIt1.Initialize(aLPB1);
1829 for (; aIt1.More(); aIt1.Next()) {
1830 aPB1 = aIt1.Value();
1831 nE = aPB1->OriginalEdge();
1833 BOPDS_ListOfPaveBlock& aLPB2 = myDS->ChangePaveBlocks(nE);
1834 aIt2.Initialize(aLPB2);
1835 for (; aIt2.More(); aIt2.Next()) {
1836 aPB2 = aIt2.Value();
1845 //create new pave blocks
1846 const BOPCol_ListOfInteger& aFaces = aCB1->Faces();
1847 aIt.Initialize(aLPB);
1848 for (; aIt.More(); aIt.Next()) {
1849 Handle(BOPDS_PaveBlock)& aPB = aIt.ChangeValue();
1851 aCB = new BOPDS_CommonBlock;
1852 aIt1.Initialize(aLPB1);
1853 for (; aIt1.More(); aIt1.Next()) {
1854 aPB2 = aIt1.Value();
1855 nE = aPB2->OriginalEdge();
1857 aPB2n = new BOPDS_PaveBlock;
1858 aPB2n->SetPave1(aPB->Pave1());
1859 aPB2n->SetPave2(aPB->Pave2());
1860 aPB2n->SetEdge(aPB->Edge());
1861 aPB2n->SetOriginalEdge(nE);
1862 aCB->AddPaveBlock(aPB2n);
1863 myDS->SetCommonBlock(aPB2n, aCB);
1864 myDS->ChangePaveBlocks(nE).Append(aPB2n);
1866 aCB->AddFaces(aFaces);
1867 myDS->SortPaveBlocks(aCB);
1869 aPB=aCB->PaveBlocks().First();
1873 aIt.Initialize(aLPB);
1874 for (; aIt.More(); aIt.Next()) {
1875 Handle(BOPDS_PaveBlock)& aPB = aIt.ChangeValue();
1876 nE = aPB->OriginalEdge();
1878 Standard_Integer nF = (aMPBOn1.Contains(aPBf) ||
1879 aMPBIn1.Contains(aPBf)) ? nF2 : nF1;
1880 const TopoDS_Face& aF = *(TopoDS_Face*)&myDS->Shape(nF);
1881 IntTools_Range aShrR(aPB->Pave1().Parameter(), aPB->Pave2().Parameter());
1882 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
1884 Standard_Boolean bCom = BOPTools_AlgoTools::IsBlockInOnFace(aShrR, aF, aE, myContext);
1887 aCB = myDS->CommonBlock(aPB);
1890 aCB = new BOPDS_CommonBlock;
1891 aCB->AddPaveBlock(aPB);
1895 myDS->SetCommonBlock(aPB, aCB);
1900 myDS->ChangePaveBlocks(nE).Append(aPB);
1904 Standard_Integer i, aNbPB;
1905 Standard_Boolean bIn1, bIn2;
1907 bIn1 = aMPBOn1.Contains(aPBf) || aMPBIn1.Contains(aPBf);
1908 bIn2 = aMPBOn2.Contains(aPBf) || aMPBIn2.Contains(aPBf);
1910 aNbPB=aMPB.Extent();
1911 for (i=1; i<=aNbPB; ++i) {
1923 //=======================================================================
1924 // function: PutClosingPaveOnCurve
1926 //=======================================================================
1927 void BOPAlgo_PaveFiller::PutClosingPaveOnCurve(BOPDS_Curve& aNC)
1929 Standard_Boolean bIsClosed, bHasBounds, bAdded;
1930 Standard_Integer nVC, j;
1931 Standard_Real aT[2], aTC, dT, aTx;
1934 BOPDS_ListIteratorOfListOfPave aItLP;
1936 const IntTools_Curve& aIC=aNC.Curve();
1937 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1942 bIsClosed=IntTools_Tools::IsClosed(aC3D);
1947 bHasBounds=aIC.HasBounds ();
1952 bAdded=Standard_False;
1953 dT=Precision::PConfusion();
1954 aIC.Bounds (aT[0], aT[1], aP[0], aP[1]);
1956 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1957 BOPDS_ListOfPave& aLP=aPB->ChangeExtPaves();
1959 aItLP.Initialize(aLP);
1960 for (; aItLP.More() && !bAdded; aItLP.Next()) {
1961 const BOPDS_Pave& aPC=aItLP.Value();
1963 aTC=aPC.Parameter();
1965 for (j=0; j<2; ++j) {
1966 if (fabs(aTC-aT[j]) < dT) {
1967 aTx=(!j) ? aT[1] : aT[0];
1969 aPVx.SetParameter(aTx);
1972 bAdded=Standard_True;
1979 //=======================================================================
1980 //function : PreparePostTreatFF
1982 //=======================================================================
1983 void BOPAlgo_PaveFiller::PreparePostTreatFF
1984 (const Standard_Integer aInt,
1985 const Handle(BOPDS_PaveBlock)& aPB,
1986 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
1987 BOPCol_DataMapOfShapeInteger& aMVI,
1988 BOPDS_VectorOfCurve& aVC)
1990 Standard_Integer nV1, nV2;
1992 Standard_Integer iC=aVC.Append()-1;
1993 BOPDS_ListOfPaveBlock& aLPBC = aVC(iC).ChangePaveBlocks();
1996 aPB->Indices(nV1, nV2);
1997 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
1998 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
1999 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
2000 // Keep info for post treatment
2001 BOPDS_CoupleOfPaveBlocks aCPB;
2002 aCPB.SetIndexInterf(aInt);
2004 aCPB.SetPaveBlock1(aPB);
2006 aMSCPB.Add(aE, aCPB);
2007 aMVI.Bind(aV1, nV1);
2008 aMVI.Bind(aV2, nV2);
2011 //=======================================================================
2012 //function : CheckPlanes
2014 //=======================================================================
2016 BOPAlgo_PaveFiller::CheckPlanes(const Standard_Integer nF1,
2017 const Standard_Integer nF2)const
2019 Standard_Boolean bToIntersect;
2020 Standard_Integer i, nV2, iCnt;
2021 BOPCol_MapIteratorOfMapOfInteger aIt;
2023 bToIntersect=Standard_False;
2025 const BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
2026 const BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
2028 const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
2029 const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
2032 for (i=0; (i<2 && !bToIntersect); ++i) {
2033 const BOPCol_MapOfInteger& aMV2=(!i) ? aFI2.VerticesIn()
2034 : aFI2.VerticesOn();
2036 aIt.Initialize(aMV2);
2037 for (; aIt.More(); aIt.Next()) {
2039 if (aMVIn1.Contains(nV2) || aMVOn1.Contains(nV2)) {
2042 bToIntersect=!bToIntersect;
2049 return bToIntersect;
2051 //=======================================================================
2052 //function : UpdatePaveBlocks
2054 //=======================================================================
2055 void BOPAlgo_PaveFiller::UpdatePaveBlocks(const BOPCol_DataMapOfIntegerInteger& aDMI)
2057 if (aDMI.IsEmpty()) {
2061 Standard_Integer nSp, aNbPBP, nV[2], i, j;
2062 Standard_Real aT[2];
2063 Standard_Boolean bCB, bRebuild;
2064 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
2065 BOPDS_MapOfPaveBlock aMPB;
2067 BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->ChangePaveBlocksPool();
2068 aNbPBP = aPBP.Extent();
2069 for (i=0; i<aNbPBP; ++i) {
2070 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
2072 aItPB.Initialize(aLPB);
2073 for (; aItPB.More(); aItPB.Next()) {
2074 Handle(BOPDS_PaveBlock) aPB=aItPB.Value();
2075 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
2076 bCB = !aCB.IsNull();
2078 aPB=aCB->PaveBlock1();
2081 if (aMPB.Add(aPB)) {
2082 bRebuild = Standard_False;
2083 aPB->Indices(nV[0], nV[1]);
2084 aPB->Range(aT[0], aT[1]);
2086 for (j = 0; j < 2; ++j) {
2087 if (aDMI.IsBound(nV[j])) {
2090 nV[j] = aDMI.Find(nV[j]);
2091 aPave.SetIndex(nV[j]);
2092 aPave.SetParameter(aT[j]);
2094 bRebuild = Standard_True;
2096 aPB->SetPave1(aPave);
2098 aPB->SetPave2(aPave);
2104 nSp = SplitEdge(aPB->Edge(), nV[0], aT[0], nV[1], aT[1]);
2112 }// if (aMPB.Add(aPB)) {
2113 }// for (; aItPB.More(); aItPB.Next()) {
2114 }// for (i=0; i<aNbPBP; ++i) {
2117 //=======================================================================
2118 //function : ToleranceFF
2119 //purpose : Computes the TolFF according to the tolerance value and
2120 // types of the faces.
2121 //=======================================================================
2122 void ToleranceFF(const BRepAdaptor_Surface& aBAS1,
2123 const BRepAdaptor_Surface& aBAS2,
2124 Standard_Real& aTolFF)
2126 Standard_Real aTol1, aTol2;
2127 Standard_Boolean isAna1, isAna2;
2129 aTol1 = aBAS1.Tolerance();
2130 aTol2 = aBAS2.Tolerance();
2131 aTolFF = Max(aTol1, aTol2);
2133 isAna1 = (aBAS1.GetType() == GeomAbs_Plane ||
2134 aBAS1.GetType() == GeomAbs_Cylinder ||
2135 aBAS1.GetType() == GeomAbs_Cone ||
2136 aBAS1.GetType() == GeomAbs_Sphere ||
2137 aBAS1.GetType() == GeomAbs_Torus);
2139 isAna2 = (aBAS2.GetType() == GeomAbs_Plane ||
2140 aBAS2.GetType() == GeomAbs_Cylinder ||
2141 aBAS2.GetType() == GeomAbs_Cone ||
2142 aBAS2.GetType() == GeomAbs_Sphere ||
2143 aBAS2.GetType() == GeomAbs_Torus);
2145 if (!isAna1 || !isAna2) {
2146 aTolFF = Max(aTolFF, 5.e-6);