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,
510 bExist=IsExistingPaveBlock(aPB, aNC, aTolR3D, aLSE);
515 bExist=IsExistingPaveBlock(aPB, aNC, aTolR3D, aMPBOnIn, aPBOut);
517 if (aMPBAdd.Add(aPBOut)) {
518 Standard_Boolean bInBothFaces = Standard_True;
519 if (!myDS->IsCommonBlock(aPBOut)) {
524 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(nE);
525 aTolE = BRep_Tool::Tolerance(aE);
526 if (aTolR3D > aTolE) {
527 myDS->UpdateEdgeTolerance(nE, aTolR3D);
529 bInBothFaces = Standard_False;
531 bInBothFaces = (aFI1.PaveBlocksOn().Contains(aPBOut) ||
532 aFI1.PaveBlocksIn().Contains(aPBOut))&&
533 (aFI2.PaveBlocksOn().Contains(aPBOut) ||
534 aFI2.PaveBlocksIn().Contains(aPBOut));
537 PreparePostTreatFF(i, aPBOut, aMSCPB, aMVI, aVC);
544 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
545 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
547 BOPTools_AlgoTools::MakeEdge (aIC, aV1, aT1,
548 aV2, aT2, aTolR3D, aES);
549 BOPTools_AlgoTools::MakePCurve(aES, aF1, aF2, aIC,
550 mySectionAttribute.PCurveOnS1(),
551 mySectionAttribute.PCurveOnS2());
553 if (BOPTools_AlgoTools::IsMicroEdge(aES, myContext)) {
557 // Append the Pave Block to the Curve j
560 // Keep info for post treatment
561 BOPDS_CoupleOfPaveBlocks aCPB;
562 aCPB.SetIndexInterf(i);
564 aCPB.SetPaveBlock1(aPB);
566 aMSCPB.Add(aES, aCPB);
575 }//for (j=0; j<aNbC; ++j) {
576 //back to previous tolerance values for unused vertices
577 aItMV.Initialize(aMVTol);
578 for (; aItMV.More(); aItMV.Next()) {
580 aTol = aItMV.Value();
582 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV1);
583 const Handle(BRep_TVertex)& TV =
584 *((Handle(BRep_TVertex)*)&aV.TShape());
588 ProcessExistingPaveBlocks(i, aMPBOnIn, aMSCPB, aMVI, aMVB, aMPBAdd);
589 }//for (i=0; i<aNbFF; ++i) {
592 myErrorStatus=PostTreatFF(aMSCPB, aMVI, aDMExEdges, aDMI, aAllocator);
598 UpdateFaceInfo(aDMExEdges);
599 //Update all pave blocks
600 UpdatePaveBlocks(aDMI);
601 //-----------------------------------------------------scope t
609 aAllocator.Nullify();
612 //=======================================================================
613 //function : PostTreatFF
615 //=======================================================================
616 Standard_Integer BOPAlgo_PaveFiller::PostTreatFF
617 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMSCPB,
618 BOPCol_DataMapOfShapeInteger& aMVI,
619 BOPDS_DataMapOfPaveBlockListOfPaveBlock& aDMExEdges,
620 BOPCol_DataMapOfIntegerInteger& aDMI,
621 Handle(NCollection_BaseAllocator)& theAllocator)
623 Standard_Integer iRet, aNbS;
626 aNbS=theMSCPB.Extent();
631 Standard_Boolean bHasPaveBlocks, bOld;
632 Standard_Integer iErr, nSx, nVSD, iX, iP, iC, j, nV, iV = 0, iE, k;
633 Standard_Integer jx, aNbLPBx;
635 TopAbs_ShapeEnum aType;
637 BOPCol_ListIteratorOfListOfShape aItLS;
638 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
640 Handle(BOPDS_PaveBlock) aPB1;
641 BOPDS_Pave aPave[2], aPave1[2];
644 BOPCol_ListOfShape aLS(theAllocator);
645 BOPAlgo_PaveFiller aPF(theAllocator);
647 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
651 const TopoDS_Shape& aS=theMSCPB.FindKey(1);
652 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromIndex(1);
655 aType=aS.ShapeType();
656 if (aType==TopAbs_VERTEX) {
657 aSI.SetShapeType(aType);
659 iV=myDS->Append(aSI);
661 iX=aCPB.IndexInterf();
663 BOPDS_InterfFF& aFF=aFFs(iX);
664 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
665 BOPDS_Point& aNP=aVNP(iP);
668 else if (aType==TopAbs_EDGE) {
669 aPB1=aCPB.PaveBlock1();
671 if (aPB1->HasEdge()) {
672 BOPDS_ListOfPaveBlock aLPBx;
674 aDMExEdges.Bind(aPB1, aLPBx);
676 aSI.SetShapeType(aType);
678 iE=myDS->Append(aSI);
686 // 1 prepare arguments
687 for (k=1; k<=aNbS; ++k) {
688 const TopoDS_Shape& aS=theMSCPB.FindKey(k);
693 aPF.SetProgressIndicator(myProgressIndicator);
694 aPF.SetRunParallel(myRunParallel);
695 aPF.SetArguments(aLS);
697 iErr=aPF.ErrorStatus();
704 aItLS.Initialize(aLS);
705 for (; aItLS.More(); aItLS.Next()) {
706 const TopoDS_Shape& aSx=aItLS.Value();
707 nSx=aPDS->Index(aSx);
708 const BOPDS_ShapeInfo& aSIx=aPDS->ShapeInfo(nSx);
710 aType=aSIx.ShapeType();
712 if (aType==TopAbs_VERTEX) {
713 if (aPDS->HasShapeSD(nSx, nVSD)) {
714 aV=aPDS->Shape(nVSD);
719 // index of new vertex in theDS -> iV
720 if (!aMVI.IsBound(aV)) {
721 aSI.SetShapeType(aType);
723 iV=myDS->Append(aSI);
730 // update FF interference
731 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx);
732 iX=aCPB.IndexInterf();
734 BOPDS_InterfFF& aFF=aFFs(iX);
735 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
736 BOPDS_Point& aNP=aVNP(iP);
738 }//if (aType==TopAbs_VERTEX) {
740 else if (aType==TopAbs_EDGE) {
741 bHasPaveBlocks=aPDS->HasPaveBlocks(nSx);
742 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx);
743 iX=aCPB.IndexInterf();
745 aPB1=aCPB.PaveBlock1();
747 bOld = aPB1->HasEdge();
749 BOPDS_ListOfPaveBlock aLPBx;
750 aDMExEdges.Bind(aPB1, aLPBx);
753 if (!bHasPaveBlocks) {
755 aDMExEdges.ChangeFind(aPB1).Append(aPB1);
757 aSI.SetShapeType(aType);
759 iE=myDS->Append(aSI);
765 BOPDS_InterfFF& aFF=aFFs(iX);
766 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
767 BOPDS_Curve& aNC=aVNC(iC);
768 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
770 const BOPDS_ListOfPaveBlock& aLPBx=aPDS->PaveBlocks(nSx);
771 aNbLPBx=aLPBx.Extent();
773 if (bOld && !aNbLPBx) {
774 aDMExEdges.ChangeFind(aPB1).Append(aPB1);
779 aItLPB.Initialize(aLPBC);
780 for (; aItLPB.More(); aItLPB.Next()) {
781 const Handle(BOPDS_PaveBlock)& aPBC=aItLPB.Value();
783 aLPBC.Remove(aItLPB);
792 if (!aMVI.IsBound(aE)) {
793 aSI.SetShapeType(aType);
795 iE=myDS->Append(aSI);
801 // append new PaveBlock to aLPBC
807 aItLPB.Initialize(aLPBx);
809 aPave1[0] = aPB1->Pave1();
810 aPave1[1] = aPB1->Pave2();
812 for (; aItLPB.More(); aItLPB.Next()) {
813 const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value();
814 const Handle(BOPDS_PaveBlock) aPBRx=aPDS->RealPaveBlock(aPBx);
816 // update vertices of paves
817 aPave[0]=aPBx->Pave1();
818 aPave[1]=aPBx->Pave2();
819 for (j=0; j<2; ++j) {
822 aT = aPave[j].Parameter();
823 if (aT == aPave1[0].Parameter()) {
825 } else if (aT == aPave1[1].Parameter()) {
830 iV = aPave1[jx-1].Index();
837 if (!aMVI.IsBound(aV)) {
838 // index of new vertex in theDS -> iV
839 aSI.SetShapeType(TopAbs_VERTEX);
841 iV=myDS->Append(aSI);
848 const BOPDS_Pave& aP1 = !j ? aPB1->Pave1() : aPB1->Pave2();
849 if (aP1.Parameter() == aPave[j].Parameter() &&
851 aDMI.Bind(aP1.Index(), iV);
852 myDS->AddShapeSD(aP1.Index(), iV);
855 aPave[j].SetIndex(iV);
859 aE=aPDS->Shape(aPBRx->Edge());
861 if (!aMVI.IsBound(aE)) {
862 aSI.SetShapeType(aType);
864 iE=myDS->Append(aSI);
870 // append new PaveBlock to aLPBC
871 Handle(BOPDS_PaveBlock) aPBC=new BOPDS_PaveBlock();
873 aPBC->SetPave1(aPave[0]);
874 aPBC->SetPave2(aPave[1]);
877 aPBC->SetOriginalEdge(aPB1->OriginalEdge());
878 aDMExEdges.ChangeFind(aPB1).Append(aPBC);
886 }//else if (aType==TopAbs_EDGE)
887 }//for (; aItLS.More(); aItLS.Next()) {
891 //=======================================================================
892 //function : UpdateFaceInfo
894 //=======================================================================
895 void BOPAlgo_PaveFiller::UpdateFaceInfo
896 (BOPDS_DataMapOfPaveBlockListOfPaveBlock& theDME)
898 Standard_Integer i, j, nV1, nF1, nF2,
899 aNbFF, aNbC, aNbP, aNbS, aNbPBIn;
900 BOPDS_IndexedMapOfPaveBlock aMPBCopy;
901 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
903 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
906 //1. Sections (curves, points);
907 for (i=0; i<aNbFF; ++i) {
908 BOPDS_InterfFF& aFF=aFFs(i);
909 aFF.Indices(nF1, nF2);
911 BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
912 BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
914 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
916 for (j=0; j<aNbC; ++j) {
917 BOPDS_Curve& aNC=aVNC(j);
918 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
919 aItLPB.Initialize(aLPBC);
921 if (aItLPB.More() && theDME.IsBound(aLPBC.First())) {
922 const Handle(BOPDS_PaveBlock)& aPB=aLPBC.First();
923 BOPDS_ListOfPaveBlock& aLPB = theDME.ChangeFind(aPB);
924 UpdateExistingPaveBlocks(aPB, aLPB, nF1, nF2);
929 for(; aItLPB.More(); aItLPB.Next()) {
930 const Handle(BOPDS_PaveBlock)& aPB=aItLPB.Value();
931 aFI1.ChangePaveBlocksSc().Add(aPB);
932 aFI2.ChangePaveBlocksSc().Add(aPB);
936 const BOPDS_VectorOfPoint& aVNP=aFF.Points();
938 for (j=0; j<aNbP; ++j) {
939 const BOPDS_Point& aNP=aVNP(j);
941 aFI1.ChangeVerticesSc().Add(nV1);
942 aFI2.ChangeVerticesSc().Add(nV1);
947 if (theDME.IsEmpty()) {
951 aNbS=myDS->NbSourceShapes();
952 for (i=0; i<aNbS; ++i) {
953 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
954 if (aSI.ShapeType()!=TopAbs_FACE) {
957 if(!myDS->HasFaceInfo(i)) {
960 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(i);
962 BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.ChangePaveBlocksIn();
963 aMPBCopy.Assign(aMPBIn);
966 aNbPBIn=aMPBCopy.Extent();
967 for (j=1; j<=aNbPBIn; ++j) {
968 const Handle(BOPDS_PaveBlock)& aPB = aMPBCopy(j);
969 if (theDME.IsBound(aPB)) {
970 const BOPDS_ListOfPaveBlock& aLPB = theDME.Find(aPB);
971 aItLPB.Initialize(aLPB);
972 for (; aItLPB.More(); aItLPB.Next()) {
973 const Handle(BOPDS_PaveBlock)& aPB1 = aItLPB.Value();
979 }//for (j=1; j<=aNbPBIn; ++j) {
980 }//for (i=0; i<aNbS; ++i) {
982 //=======================================================================
983 //function : IsExistingVertex
985 //=======================================================================
986 Standard_Boolean BOPAlgo_PaveFiller::IsExistingVertex
988 const Standard_Real theTolR3D,
989 const BOPCol_MapOfInteger& aMVOnIn)const
991 Standard_Boolean bRet;
992 Standard_Integer nV, iFlag;
996 BOPCol_MapIteratorOfMapOfInteger aIt;
1001 aBoxP.Enlarge(theTolR3D);
1003 aIt.Initialize(aMVOnIn);
1004 for (; aIt.More(); aIt.Next()) {
1008 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1009 aPV=BRep_Tool::Pnt(aV);
1010 aTolV=BRep_Tool::Tolerance(aV);
1012 aBoxV.Enlarge(aTolV);
1014 if (!aBoxP.IsOut(aBoxV)) {
1015 iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP, theTolR3D);
1023 //=======================================================================
1024 //function : IsExistingPaveBlock
1026 //=======================================================================
1027 Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock
1028 (const Handle(BOPDS_PaveBlock)& thePB,
1029 const BOPDS_Curve& theNC,
1030 const Standard_Real theTolR3D,
1031 const BOPCol_ListOfInteger& theLSE)
1033 Standard_Boolean bRet=Standard_True;
1035 if (theLSE.IsEmpty()) {
1039 Standard_Real aT1, aT2, aTm, aTx, aTol;
1040 Standard_Integer nE, iFlag;
1043 BOPCol_ListIteratorOfListOfInteger aItLI;
1045 thePB->Range(aT1, aT2);
1046 aTm=IntTools_Tools::IntermediatePoint (aT1, aT2);
1047 theNC.Curve().D0(aTm, aPm);
1049 aBoxPm.Enlarge(theTolR3D);
1051 aItLI.Initialize(theLSE);
1052 for (; aItLI.More(); aItLI.Next()) {
1054 const BOPDS_ShapeInfo& aSIE=myDS->ChangeShapeInfo(nE);
1055 const Bnd_Box& aBoxE=aSIE.Box();
1056 if (!aBoxE.IsOut(aBoxPm)) {
1057 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape()));
1058 aTol = BRep_Tool::Tolerance(aE);
1059 aTol = aTol > theTolR3D ? aTol : theTolR3D;
1060 iFlag=myContext->ComputePE(aPm, aTol, aE, aTx);
1069 //=======================================================================
1070 //function : IsExistingPaveBlock
1072 //=======================================================================
1073 Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock
1074 (const Handle(BOPDS_PaveBlock)& thePB,
1075 const BOPDS_Curve& theNC,
1076 const Standard_Real theTolR3D,
1077 const BOPDS_IndexedMapOfPaveBlock& theMPBOnIn,
1078 Handle(BOPDS_PaveBlock&) aPBOut)
1080 Standard_Boolean bRet;
1081 Standard_Real aT1, aT2, aTm, aTx;
1082 Standard_Integer nSp, iFlag1, iFlag2, nV11, nV12, nV21, nV22, i, aNbPB;
1083 gp_Pnt aP1, aPm, aP2;
1084 Bnd_Box aBoxP1, aBoxPm, aBoxP2;
1086 bRet=Standard_False;
1087 const IntTools_Curve& aIC=theNC.Curve();
1089 thePB->Range(aT1, aT2);
1090 thePB->Indices(nV11, nV12);
1094 aBoxP1.Enlarge(theTolR3D);
1095 //intermediate point
1096 aTm=IntTools_Tools::IntermediatePoint (aT1, aT2);
1099 aBoxPm.Enlarge(theTolR3D);
1103 aBoxP2.Enlarge(theTolR3D);
1105 aNbPB = theMPBOnIn.Extent();
1106 for (i = 1; i <= aNbPB; ++i) {
1107 const Handle(BOPDS_PaveBlock)& aPB = theMPBOnIn(i);
1108 aPB->Indices(nV21, nV22);
1110 const BOPDS_ShapeInfo& aSISp=myDS->ChangeShapeInfo(nSp);
1111 const TopoDS_Edge& aSp=(*(TopoDS_Edge *)(&aSISp.Shape()));
1112 const Bnd_Box& aBoxSp=aSISp.Box();
1114 iFlag1 = (nV11 == nV21 || nV11 == nV22) ? 2 :
1115 (!aBoxSp.IsOut(aBoxP1) ? 1 : 0);
1116 iFlag2 = (nV12 == nV21 || nV12 == nV22) ? 2 :
1117 (!aBoxSp.IsOut(aBoxP2) ? 1 : 0);
1118 if (iFlag1 && iFlag2) {
1119 if (aBoxSp.IsOut(aBoxPm) || myContext->ComputePE(aPm,
1127 iFlag1 = !myContext->ComputePE(aP1, theTolR3D, aSp, aTx);
1131 iFlag2 = !myContext->ComputePE(aP2, theTolR3D, aSp, aTx);
1134 if (iFlag1 && iFlag2) {
1143 //=======================================================================
1144 //function : PutBoundPaveOnCurve
1146 //=======================================================================
1147 void BOPAlgo_PaveFiller::PutBoundPaveOnCurve(const TopoDS_Face& aF1,
1148 const TopoDS_Face& aF2,
1149 const Standard_Real aTolR3D,
1151 BOPCol_MapOfInteger& aMVB)
1153 Standard_Boolean bVF;
1154 Standard_Integer nV, iFlag, nVn, j, aNbEP;
1155 Standard_Real aT[2], aTmin, aTmax, aTV, aTol, aTolVnew;
1158 BOPDS_ListIteratorOfListOfPave aItLP;
1159 BOPDS_Pave aPn, aPMM[2];
1161 aTolVnew = Precision::Confusion();
1163 const IntTools_Curve& aIC=aNC.Curve();
1164 aIC.Bounds(aT[0], aT[1], aP[0], aP[1]);
1166 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1167 const BOPDS_ListOfPave& aLP=aPB->ExtPaves();
1174 aItLP.Initialize(aLP);
1175 for (; aItLP.More(); aItLP.Next()) {
1176 const BOPDS_Pave& aPv=aItLP.Value();
1177 aPv.Contents(nV, aTV);
1189 for (j=0; j<2; ++j) {
1190 //if curve is closed, process only one bound
1191 if (j && aP[1].IsEqual(aP[0], aTolVnew)) {
1201 aTol = aTolR3D+Precision::Confusion();
1202 aBoxP.Enlarge(aTol);
1203 const BOPDS_Pave& aPV=aPMM[j];
1205 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1206 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&aSIV.Shape()));
1207 const Bnd_Box& aBoxV=aSIV.Box();
1208 if (!aBoxP.IsOut(aBoxV)){
1209 iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP[j], aTol);
1214 bVF=myContext->IsValidPointForFaces (aP[j], aF1, aF2, aTolR3D);
1219 BOPDS_ShapeInfo aSIVn;
1221 BOPTools_AlgoTools::MakeNewVertex(aP[j], aTolR3D, aVn);
1222 aSIVn.SetShapeType(TopAbs_VERTEX);
1223 aSIVn.SetShape(aVn);
1225 nVn=myDS->Append(aSIVn);
1228 aPn.SetParameter(aT[j]);
1229 aPB->AppendExtPave(aPn);
1231 aVn=(*(TopoDS_Vertex *)(&myDS->Shape(nVn)));
1232 BOPTools_AlgoTools::UpdateVertex (aIC, aT[j], aVn);
1234 aTolVnew = BRep_Tool::Tolerance(aVn);
1236 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nVn);
1237 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
1238 BRepBndLib::Add(aVn, aBoxDS);
1244 //=======================================================================
1245 //function : PutPavesOnCurve
1247 //=======================================================================
1248 void BOPAlgo_PaveFiller::PutPavesOnCurve
1249 (const BOPCol_MapOfInteger& aMVOnIn,
1250 const Standard_Real aTolR3D,
1252 const Standard_Integer nF1,
1253 const Standard_Integer nF2,
1254 const BOPCol_MapOfInteger& aMI,
1255 const BOPCol_MapOfInteger& aMVEF,
1256 BOPCol_DataMapOfIntegerReal& aMVTol)
1258 Standard_Boolean bInBothFaces;
1259 Standard_Integer nV;
1260 BOPCol_MapIteratorOfMapOfInteger aIt;
1262 const Bnd_Box& aBoxC=aNC.Box();
1264 //Put EF vertices first
1265 aIt.Initialize(aMVEF);
1266 for (; aIt.More(); aIt.Next()) {
1268 PutPaveOnCurve(nV, aTolR3D, aNC, aMI, aMVTol, 2);
1270 //Put all other vertices
1271 aIt.Initialize(aMVOnIn);
1272 for (; aIt.More(); aIt.Next()) {
1274 if (aMVEF.Contains(nV)) {
1278 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1279 const Bnd_Box& aBoxV=aSIV.Box();
1281 if (aBoxC.IsOut(aBoxV)){
1284 if (!myDS->IsNewShape(nV)) {
1285 const BOPDS_FaceInfo& aFI1 = myDS->FaceInfo(nF1);
1286 const BOPDS_FaceInfo& aFI2 = myDS->FaceInfo(nF2);
1288 bInBothFaces = (aFI1.VerticesOn().Contains(nV) ||
1289 aFI1.VerticesIn().Contains(nV))&&
1290 (aFI2.VerticesOn().Contains(nV) ||
1291 aFI2.VerticesIn().Contains(nV));
1292 if (!bInBothFaces) {
1297 PutPaveOnCurve(nV, aTolR3D, aNC, aMI, aMVTol, 1);
1301 //=======================================================================
1302 //function : ExtendedTolerance
1304 //=======================================================================
1305 Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance
1306 (const Standard_Integer nV,
1307 const BOPCol_MapOfInteger& aMI,
1308 Standard_Real& aTolVExt,
1309 const Standard_Integer aType)
1311 Standard_Boolean bFound = Standard_False;
1312 if (!(myDS->IsNewShape(nV))) {
1316 Standard_Integer i, k, aNbLines, aNbInt;
1317 Standard_Real aT11, aT12, aD1, aD2, aD;
1319 gp_Pnt aPV, aP11, aP12;
1325 } else if (aType == 2) {
1329 aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1330 aPV=BRep_Tool::Pnt(aV);
1332 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
1333 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1335 for (; k<aNbInt; ++k) {
1336 aNbLines = !k ? aEEs.Extent() : aEFs.Extent();
1337 for (i = 0; i < aNbLines; ++i) {
1338 BOPDS_Interf *aInt = !k ? (BOPDS_Interf*) (&aEEs(i)) :
1339 (BOPDS_Interf*) (&aEFs(i));
1340 if (aInt->IndexNew() == nV) {
1341 if (aMI.Contains(aInt->Index1()) &&
1342 aMI.Contains(aInt->Index2())) {
1343 const IntTools_CommonPrt& aComPrt = !k ? aEEs(i).CommonPart() :
1344 aEFs(i).CommonPart();
1346 const TopoDS_Edge& aE1=aComPrt.Edge1();
1347 aComPrt.Range1(aT11, aT12);
1348 BOPTools_AlgoTools::PointOnEdge(aE1, aT11, aP11);
1349 BOPTools_AlgoTools::PointOnEdge(aE1, aT12, aP12);
1350 aD1=aPV.Distance(aP11);
1351 aD2=aPV.Distance(aP12);
1352 aD=(aD1>aD2)? aD1 : aD2;
1357 }//if (aMI.Contains(aEF.Index1()) && aMI.Contains(aEF.Index2())) {
1358 }//if (aInt->IndexNew() == nV) {
1359 }//for (i = 0; i < aNbLines; ++i) {
1360 }//for (k=0; k<2; ++k) {
1364 //=======================================================================
1365 //function : GetEFPnts
1367 //=======================================================================
1368 void BOPAlgo_PaveFiller::GetEFPnts(const Standard_Integer nF1,
1369 const Standard_Integer nF2,
1370 IntSurf_ListOfPntOn2S& aListOfPnts)
1372 Standard_Integer nE, nF, nFOpposite, aNbEFs, i;
1373 Standard_Real U1, U2, V1, V2, f, l;
1374 BOPCol_MapOfInteger aMI;
1376 //collect indexes of all shapes from nF1 and nF2.
1377 GetFullShapeMap(nF1, aMI);
1378 GetFullShapeMap(nF2, aMI);
1380 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1381 aNbEFs = aEFs.Extent();
1383 for(i = 0; i < aNbEFs; ++i) {
1384 const BOPDS_InterfEF& aEF = aEFs(i);
1385 if (aEF.HasIndexNew()) {
1386 aEF.Indices(nE, nFOpposite);
1387 if(aMI.Contains(nE) && aMI.Contains(nFOpposite)) {
1388 const IntTools_CommonPrt& aCP = aEF.CommonPart();
1389 Standard_Real aPar = aCP.VertexParameter1();
1390 const TopoDS_Edge& aE = (*(TopoDS_Edge*)(&myDS->Shape(nE)));
1391 const TopoDS_Face& aFOpposite =
1392 (*(TopoDS_Face*)(&myDS->Shape(nFOpposite)));
1394 const Handle(Geom_Curve)& aCurve = BRep_Tool::Curve(aE, f, l);
1396 nF = (nFOpposite == nF1) ? nF2 : nF1;
1397 const TopoDS_Face& aF = (*(TopoDS_Face*)(&myDS->Shape(nF)));
1398 Handle(Geom2d_Curve) aPCurve =
1399 BRep_Tool::CurveOnSurface(aE, aF, f, l);
1401 GeomAPI_ProjectPointOnSurf& aProj=myContext->ProjPS(aFOpposite);
1404 aCurve->D0(aPar, aPoint);
1405 IntSurf_PntOn2S aPnt;
1406 if(!aPCurve.IsNull()) {
1407 gp_Pnt2d aP2d = aPCurve->Value(aPar);
1408 aProj.Perform(aPoint);
1409 if(aProj.IsDone()) {
1410 aProj.LowerDistanceParameters(U1,V1);
1412 aPnt.SetValue(aP2d.X(),aP2d.Y(),U1,V1);
1414 aPnt.SetValue(U1,V1,aP2d.X(),aP2d.Y());
1416 aListOfPnts.Append(aPnt);
1420 GeomAPI_ProjectPointOnSurf& aProj1 = myContext->ProjPS(aF);
1421 aProj1.Perform(aPoint);
1422 aProj.Perform(aPoint);
1423 if(aProj1.IsDone() && aProj.IsDone()){
1424 aProj1.LowerDistanceParameters(U1,V1);
1425 aProj.LowerDistanceParameters(U2,V2);
1427 aPnt.SetValue(U1,V1,U2,V2);
1429 aPnt.SetValue(U2,V2,U1,V1);
1431 aListOfPnts.Append(aPnt);
1439 //=======================================================================
1440 //function : ProcessUnUsedVertices
1442 //=======================================================================
1443 void BOPAlgo_PaveFiller::PutEFPavesOnCurve
1445 const BOPCol_MapOfInteger& aMI,
1446 const BOPCol_MapOfInteger& aMVEF,
1447 BOPCol_DataMapOfIntegerReal& aMVTol)
1449 if (!aMVEF.Extent()) {
1453 const IntTools_Curve& aIC=aNC.Curve();
1454 GeomAbs_CurveType aTypeC;
1456 if (!(aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve)) {
1460 Standard_Integer nV;
1461 BOPCol_MapOfInteger aMV;
1464 RemoveUsedVertices(aNC, aMV);
1465 if (!aMV.Extent()) {
1469 Standard_Real aDist;
1472 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1473 GeomAPI_ProjectPointOnCurve& aProjPT = myContext->ProjPT(aC3D);
1475 BOPCol_MapIteratorOfMapOfInteger aItMI;
1476 aItMI.Initialize(aMV);
1477 for (; aItMI.More(); aItMI.Next()) {
1479 const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1480 gp_Pnt aPV = BRep_Tool::Pnt(aV);
1481 aProjPT.Perform(aPV);
1482 Standard_Integer aNbPoints = aProjPT.NbPoints();
1484 aDist = aProjPT.LowerDistance();
1485 PutPaveOnCurve(nV, aDist, aNC, aMI, aMVTol);
1490 //=======================================================================
1491 //function : ProcessUnUsedVertices
1493 //=======================================================================
1494 void BOPAlgo_PaveFiller::PutStickPavesOnCurve
1495 (const TopoDS_Face& aF1,
1496 const TopoDS_Face& aF2,
1497 const BOPCol_MapOfInteger& aMI,
1499 const BOPCol_MapOfInteger& aMVStick,
1500 BOPCol_DataMapOfIntegerReal& aMVTol)
1502 BOPCol_MapOfInteger aMV;
1503 aMV.Assign(aMVStick);
1504 RemoveUsedVertices(aNC, aMV);
1506 if (!aMV.Extent()) {
1510 GeomAbs_SurfaceType aType1, aType2;
1511 Handle(Geom_Surface) aS1=BRep_Tool::Surface(aF1);
1512 Handle(Geom_Surface) aS2=BRep_Tool::Surface(aF2);
1513 GeomAdaptor_Surface aGAS1(aS1);
1514 GeomAdaptor_Surface aGAS2(aS2);
1516 aType1=aGAS1.GetType();
1517 aType2=aGAS2.GetType();
1519 //if (aType1==GeomAbs_Torus || aType2==GeomAbs_Torus) {
1520 GeomAbs_CurveType aTypeC;
1522 const IntTools_Curve& aIC=aNC.Curve();
1524 //if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
1525 Handle(Geom2d_Curve) aC2D[2];
1527 aC2D[0]=aIC.FirstCurve2d();
1528 aC2D[1]=aIC.SecondCurve2d();
1529 if (!aC2D[0].IsNull() && !aC2D[1].IsNull()) {
1530 Standard_Integer nV, m, n;
1531 Standard_Real aTC[2], aD, aD2, u, v, aDT2, aScPr, aDScPr;
1535 BOPCol_MapIteratorOfMapOfInteger aItMI, aItMI1;
1537 aDT2=2e-7; // the rich criteria
1538 aDScPr=5.e-9; // the creasing criteria
1539 aIC.Bounds(aTC[0], aTC[1], aPC[0], aPC[1]);
1541 aItMI.Initialize(aMV);
1542 for (; aItMI.More(); aItMI.Next()) {
1544 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&myDS->Shape(nV));
1545 aPV=BRep_Tool::Pnt(aV);
1547 for (m=0; m<2; ++m) {
1548 aD2=aPC[m].SquareDistance(aPV);
1549 if (aD2>aDT2) {// no rich
1553 for (n=0; n<2; ++n) {
1554 Handle(Geom_Surface)& aS=(!n)? aS1 : aS2;
1555 aC2D[n]->D0(aTC[m], aP2D);
1557 BOPTools_AlgoTools3D::GetNormalToSurface(aS, u, v, aDN[n]);
1560 aScPr=aDN[0]*aDN[1];
1570 // The intersection curve aIC is vanishing curve (the crease)
1573 PutPaveOnCurve(nV, aD, aNC, aMI, aMVTol);
1575 }//for (jVU=1; jVU=aNbVU; ++jVU) {
1577 //}//if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
1578 //}//if(aType1==GeomAbs_Torus || aType2==GeomAbs_Torus) {
1581 //=======================================================================
1582 //function : GetStickVertices
1584 //=======================================================================
1585 void BOPAlgo_PaveFiller::GetStickVertices(const Standard_Integer nF1,
1586 const Standard_Integer nF2,
1587 BOPCol_MapOfInteger& aMVStick,
1588 BOPCol_MapOfInteger& aMVEF,
1589 BOPCol_MapOfInteger& aMI)
1591 Standard_Integer nS1, nS2, nVNew, aTypeInt, i;
1593 BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV();
1594 BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
1595 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
1596 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
1597 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1599 Standard_Integer aNbLines[5] = {
1600 aVVs.Extent(), aVEs.Extent(), aEEs.Extent(),
1601 aVFs.Extent(), aEFs.Extent()
1603 //collect indices of all shapes from nF1 and nF2.
1605 GetFullShapeMap(nF1, aMI);
1606 GetFullShapeMap(nF2, aMI);
1608 //collect VV, VE, EE, VF interferences
1609 for (aTypeInt = 0; aTypeInt < 4; ++aTypeInt) {
1610 for (i = 0; i < aNbLines[aTypeInt]; ++i) {
1611 BOPDS_Interf* aInt = (aTypeInt==0) ? (BOPDS_Interf*)(&aVVs(i)) :
1612 ((aTypeInt==1) ? (BOPDS_Interf*)(&aVEs(i)) :
1613 ((aTypeInt==2) ? (BOPDS_Interf*)(&aEEs(i)) :
1614 (BOPDS_Interf*)(&aVFs(i))));
1615 if (aInt->HasIndexNew()) {
1616 aInt->Indices(nS1, nS2);
1617 if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
1618 nVNew = aInt->IndexNew();
1619 aMVStick.Add(nVNew);
1624 //collect EF interferences
1625 for (i = 0; i < aNbLines[4]; ++i) {
1626 const BOPDS_InterfEF& aInt = aEFs(i);
1627 if (aInt.HasIndexNew()) {
1628 aInt.Indices(nS1, nS2);
1629 if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
1630 nVNew = aInt.IndexNew();
1631 aMVStick.Add(nVNew);
1638 //=======================================================================
1639 // function: GetFullShapeMap
1641 //=======================================================================
1642 void BOPAlgo_PaveFiller::GetFullShapeMap(const Standard_Integer nF,
1643 BOPCol_MapOfInteger& aMI)
1645 BOPCol_ListIteratorOfListOfInteger aIt;
1646 Standard_Integer nS;
1648 const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(nF);
1649 const BOPCol_ListOfInteger& aLI = aSI.SubShapes();
1652 aIt.Initialize(aLI);
1653 for (; aIt.More(); aIt.Next()) {
1659 //=======================================================================
1660 // function: RemoveUsedVertices
1662 //=======================================================================
1663 void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
1664 BOPCol_MapOfInteger& aMV)
1666 if (!aMV.Extent()) {
1669 Standard_Integer nV;
1671 BOPDS_ListIteratorOfListOfPave aItLP;
1673 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1674 const BOPDS_ListOfPave& aLP = aPB->ExtPaves();
1675 aItLP.Initialize(aLP);
1676 for (;aItLP.More();aItLP.Next()) {
1677 aPave = aItLP.Value();
1683 //=======================================================================
1684 //function : PutPaveOnCurve
1686 //=======================================================================
1687 void BOPAlgo_PaveFiller::PutPaveOnCurve
1688 (const Standard_Integer nV,
1689 const Standard_Real aTolR3D,
1691 const BOPCol_MapOfInteger& aMI,
1692 BOPCol_DataMapOfIntegerReal& aMVTol,
1693 const Standard_Integer iCheckExtend)
1695 Standard_Boolean bIsVertexOnLine;
1696 Standard_Real aT, aTol, aTolNew;
1699 const TopoDS_Vertex aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1700 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1701 const IntTools_Curve& aIC = aNC.Curve();
1703 bIsVertexOnLine=myContext->IsVertexOnLine(aV, aIC, aTolR3D, aT);
1704 if (!bIsVertexOnLine && iCheckExtend) {
1705 aTol = BRep_Tool::Tolerance(aV);
1707 ExtendedTolerance(nV, aMI, aTol, iCheckExtend);
1708 bIsVertexOnLine=myContext->IsVertexOnLine(aV, aTol, aIC, aTolR3D, aT);
1711 if (bIsVertexOnLine) {
1713 aPave.SetParameter(aT);
1715 aPB->AppendExtPave(aPave);
1717 aTol = BRep_Tool::Tolerance(aV);
1719 BOPTools_AlgoTools::UpdateVertex (aIC, aT, aV);
1721 if (!aMVTol.IsBound(nV)) {
1722 aTolNew = BRep_Tool::Tolerance(aV);
1723 if (aTolNew > aTol) {
1724 aMVTol.Bind(nV, aTol);
1728 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV);
1729 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
1730 BRepBndLib::Add(aV, aBoxDS);
1734 //=======================================================================
1735 //function : ProcessOldPaveBlocks
1737 //=======================================================================
1738 void BOPAlgo_PaveFiller::ProcessExistingPaveBlocks
1739 (const Standard_Integer theInt,
1740 const BOPDS_IndexedMapOfPaveBlock& aMPBOnIn,
1741 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
1742 BOPCol_DataMapOfShapeInteger& aMVI,
1743 const BOPCol_MapOfInteger& aMVB,
1744 BOPDS_MapOfPaveBlock& aMPB)
1746 Standard_Integer nV, nE, iFlag, i, aNbPB;
1748 BOPCol_MapIteratorOfMapOfInteger aItB;
1750 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
1751 BOPDS_InterfFF& aFF = aFFs(theInt);
1752 BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
1754 aItB.Initialize(aMVB);
1755 for (; aItB.More(); aItB.Next()) {
1757 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1758 const Bnd_Box& aBoxV=aSIV.Box();
1759 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&aSIV.Shape();
1760 if (!aMVI.IsBound(aV)) {
1764 aNbPB = aMPBOnIn.Extent();
1765 for (i = 1; i <= aNbPB; ++i) {
1766 const Handle(BOPDS_PaveBlock)& aPB = aMPBOnIn(i);
1767 if (aPB->Pave1().Index() == nV || aPB->Pave2().Index() == nV) {
1771 if (aMPB.Contains(aPB)) {
1775 const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
1776 const Bnd_Box& aBoxE=aSIE.Box();
1778 if (!aBoxV.IsOut(aBoxE)) {
1779 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aSIE.Shape();
1781 iFlag=myContext->ComputeVE (aV, aE, aT);
1785 PreparePostTreatFF(theInt, aPB, aMSCPB, aMVI, aVC);
1791 //=======================================================================
1792 //function : UpdateExistingPaveBlocks
1794 //=======================================================================
1795 void BOPAlgo_PaveFiller::UpdateExistingPaveBlocks
1796 (const Handle(BOPDS_PaveBlock)& aPBf,
1797 BOPDS_ListOfPaveBlock& aLPB,
1798 const Standard_Integer nF1,
1799 const Standard_Integer nF2)
1801 Standard_Integer nE;
1802 Standard_Boolean bCB;
1803 Handle(BOPDS_PaveBlock) aPB, aPB1, aPB2, aPB2n;
1804 Handle(BOPDS_CommonBlock) aCB;
1805 BOPDS_ListIteratorOfListOfPaveBlock aIt, aIt1, aIt2;
1806 BOPDS_IndexedMapOfPaveBlock aMPB;
1808 //remove micro edges from aLPB
1809 aIt.Initialize(aLPB);
1810 for (; aIt.More();) {
1812 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
1813 if (BOPTools_AlgoTools::IsMicroEdge(aE, myContext)) {
1820 if (!aLPB.Extent()) {
1824 myDS->UpdateFaceInfoOn(nF1);
1826 myDS->UpdateFaceInfoOn(nF2);
1828 BOPDS_FaceInfo& aFI1 = myDS->ChangeFaceInfo(nF1);
1829 BOPDS_FaceInfo& aFI2 = myDS->ChangeFaceInfo(nF2);
1831 BOPDS_IndexedMapOfPaveBlock& aMPBOn1 = aFI1.ChangePaveBlocksOn();
1832 BOPDS_IndexedMapOfPaveBlock& aMPBIn1 = aFI1.ChangePaveBlocksIn();
1833 BOPDS_IndexedMapOfPaveBlock& aMPBOn2 = aFI2.ChangePaveBlocksOn();
1834 BOPDS_IndexedMapOfPaveBlock& aMPBIn2 = aFI2.ChangePaveBlocksIn();
1836 // remove old pave blocks
1837 const Handle(BOPDS_CommonBlock)& aCB1 = myDS->CommonBlock(aPBf);
1838 bCB = !aCB1.IsNull();
1839 BOPDS_ListOfPaveBlock aLPB1;
1842 aLPB1.Assign(aCB1->PaveBlocks());
1846 aIt1.Initialize(aLPB1);
1847 for (; aIt1.More(); aIt1.Next()) {
1848 aPB1 = aIt1.Value();
1849 nE = aPB1->OriginalEdge();
1851 BOPDS_ListOfPaveBlock& aLPB2 = myDS->ChangePaveBlocks(nE);
1852 aIt2.Initialize(aLPB2);
1853 for (; aIt2.More(); aIt2.Next()) {
1854 aPB2 = aIt2.Value();
1863 //create new pave blocks
1864 const BOPCol_ListOfInteger& aFaces = aCB1->Faces();
1865 aIt.Initialize(aLPB);
1866 for (; aIt.More(); aIt.Next()) {
1867 Handle(BOPDS_PaveBlock)& aPB = aIt.ChangeValue();
1869 aCB = new BOPDS_CommonBlock;
1870 aIt1.Initialize(aLPB1);
1871 for (; aIt1.More(); aIt1.Next()) {
1872 aPB2 = aIt1.Value();
1873 nE = aPB2->OriginalEdge();
1875 aPB2n = new BOPDS_PaveBlock;
1876 aPB2n->SetPave1(aPB->Pave1());
1877 aPB2n->SetPave2(aPB->Pave2());
1878 aPB2n->SetEdge(aPB->Edge());
1879 aPB2n->SetOriginalEdge(nE);
1880 aCB->AddPaveBlock(aPB2n);
1881 myDS->SetCommonBlock(aPB2n, aCB);
1882 myDS->ChangePaveBlocks(nE).Append(aPB2n);
1884 aCB->AddFaces(aFaces);
1885 myDS->SortPaveBlocks(aCB);
1887 aPB=aCB->PaveBlocks().First();
1891 aIt.Initialize(aLPB);
1892 for (; aIt.More(); aIt.Next()) {
1893 Handle(BOPDS_PaveBlock)& aPB = aIt.ChangeValue();
1894 nE = aPB->OriginalEdge();
1896 Standard_Integer nF = (aMPBOn1.Contains(aPBf) ||
1897 aMPBIn1.Contains(aPBf)) ? nF2 : nF1;
1898 const TopoDS_Face& aF = *(TopoDS_Face*)&myDS->Shape(nF);
1899 IntTools_Range aShrR(aPB->Pave1().Parameter(),
1900 aPB->Pave2().Parameter());
1901 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
1903 Standard_Boolean bCom =
1904 BOPTools_AlgoTools::IsBlockInOnFace(aShrR, aF, aE, myContext);
1907 aCB = myDS->CommonBlock(aPB);
1910 aCB = new BOPDS_CommonBlock;
1911 aCB->AddPaveBlock(aPB);
1915 myDS->SetCommonBlock(aPB, aCB);
1920 myDS->ChangePaveBlocks(nE).Append(aPB);
1924 Standard_Integer i, aNbPB;
1925 Standard_Boolean bIn1, bIn2;
1927 bIn1 = aMPBOn1.Contains(aPBf) || aMPBIn1.Contains(aPBf);
1928 bIn2 = aMPBOn2.Contains(aPBf) || aMPBIn2.Contains(aPBf);
1930 aNbPB=aMPB.Extent();
1931 for (i=1; i<=aNbPB; ++i) {
1942 //=======================================================================
1943 // function: PutClosingPaveOnCurve
1945 //=======================================================================
1946 void BOPAlgo_PaveFiller::PutClosingPaveOnCurve(BOPDS_Curve& aNC)
1948 Standard_Boolean bIsClosed, bHasBounds, bAdded;
1949 Standard_Integer nVC, j;
1950 Standard_Real aT[2], aTC, dT, aTx;
1953 BOPDS_ListIteratorOfListOfPave aItLP;
1955 const IntTools_Curve& aIC=aNC.Curve();
1956 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1961 bIsClosed=IntTools_Tools::IsClosed(aC3D);
1966 bHasBounds=aIC.HasBounds ();
1971 bAdded=Standard_False;
1972 dT=Precision::PConfusion();
1973 aIC.Bounds (aT[0], aT[1], aP[0], aP[1]);
1975 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1976 BOPDS_ListOfPave& aLP=aPB->ChangeExtPaves();
1978 aItLP.Initialize(aLP);
1979 for (; aItLP.More() && !bAdded; aItLP.Next()) {
1980 const BOPDS_Pave& aPC=aItLP.Value();
1982 aTC=aPC.Parameter();
1984 for (j=0; j<2; ++j) {
1985 if (fabs(aTC-aT[j]) < dT) {
1986 aTx=(!j) ? aT[1] : aT[0];
1988 aPVx.SetParameter(aTx);
1991 bAdded=Standard_True;
1997 //=======================================================================
1998 //function : PreparePostTreatFF
2000 //=======================================================================
2001 void BOPAlgo_PaveFiller::PreparePostTreatFF
2002 (const Standard_Integer aInt,
2003 const Handle(BOPDS_PaveBlock)& aPB,
2004 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
2005 BOPCol_DataMapOfShapeInteger& aMVI,
2006 BOPDS_VectorOfCurve& aVC)
2008 Standard_Integer nV1, nV2;
2010 Standard_Integer iC=aVC.Append()-1;
2011 BOPDS_ListOfPaveBlock& aLPBC = aVC(iC).ChangePaveBlocks();
2014 aPB->Indices(nV1, nV2);
2015 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
2016 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
2017 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
2018 // Keep info for post treatment
2019 BOPDS_CoupleOfPaveBlocks aCPB;
2020 aCPB.SetIndexInterf(aInt);
2022 aCPB.SetPaveBlock1(aPB);
2024 aMSCPB.Add(aE, aCPB);
2025 aMVI.Bind(aV1, nV1);
2026 aMVI.Bind(aV2, nV2);
2029 //=======================================================================
2030 //function : CheckPlanes
2032 //=======================================================================
2033 Standard_Boolean BOPAlgo_PaveFiller::CheckPlanes
2034 (const Standard_Integer nF1,
2035 const Standard_Integer nF2)const
2037 Standard_Boolean bToIntersect;
2038 Standard_Integer i, nV2, iCnt;
2039 BOPCol_MapIteratorOfMapOfInteger aIt;
2041 bToIntersect=Standard_False;
2043 const BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
2044 const BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
2046 const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
2047 const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
2050 for (i=0; (i<2 && !bToIntersect); ++i) {
2051 const BOPCol_MapOfInteger& aMV2=(!i) ? aFI2.VerticesIn()
2052 : aFI2.VerticesOn();
2054 aIt.Initialize(aMV2);
2055 for (; aIt.More(); aIt.Next()) {
2057 if (aMVIn1.Contains(nV2) || aMVOn1.Contains(nV2)) {
2060 bToIntersect=!bToIntersect;
2067 return bToIntersect;
2069 //=======================================================================
2070 //function : UpdatePaveBlocks
2072 //=======================================================================
2073 void BOPAlgo_PaveFiller::UpdatePaveBlocks
2074 (const BOPCol_DataMapOfIntegerInteger& aDMI)
2076 if (aDMI.IsEmpty()) {
2080 Standard_Integer nSp, aNbPBP, nV[2], i, j;
2081 Standard_Real aT[2];
2082 Standard_Boolean bCB, bRebuild;
2083 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
2084 BOPDS_MapOfPaveBlock aMPB;
2086 BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->ChangePaveBlocksPool();
2087 aNbPBP = aPBP.Extent();
2088 for (i=0; i<aNbPBP; ++i) {
2089 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
2091 aItPB.Initialize(aLPB);
2092 for (; aItPB.More(); aItPB.Next()) {
2093 Handle(BOPDS_PaveBlock) aPB=aItPB.Value();
2094 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
2095 bCB = !aCB.IsNull();
2097 aPB=aCB->PaveBlock1();
2100 if (aMPB.Add(aPB)) {
2101 bRebuild = Standard_False;
2102 aPB->Indices(nV[0], nV[1]);
2103 aPB->Range(aT[0], aT[1]);
2105 for (j = 0; j < 2; ++j) {
2106 if (aDMI.IsBound(nV[j])) {
2109 nV[j] = aDMI.Find(nV[j]);
2110 aPave.SetIndex(nV[j]);
2111 aPave.SetParameter(aT[j]);
2113 bRebuild = Standard_True;
2115 aPB->SetPave1(aPave);
2117 aPB->SetPave2(aPave);
2123 nSp = SplitEdge(aPB->Edge(), nV[0], aT[0], nV[1], aT[1]);
2131 }// if (aMPB.Add(aPB)) {
2132 }// for (; aItPB.More(); aItPB.Next()) {
2133 }// for (i=0; i<aNbPBP; ++i) {
2136 //=======================================================================
2137 //function : ToleranceFF
2138 //purpose : Computes the TolFF according to the tolerance value and
2139 // types of the faces.
2140 //=======================================================================
2141 void ToleranceFF(const BRepAdaptor_Surface& aBAS1,
2142 const BRepAdaptor_Surface& aBAS2,
2143 Standard_Real& aTolFF)
2145 Standard_Real aTol1, aTol2;
2146 Standard_Boolean isAna1, isAna2;
2148 aTol1 = aBAS1.Tolerance();
2149 aTol2 = aBAS2.Tolerance();
2150 aTolFF = Max(aTol1, aTol2);
2152 isAna1 = (aBAS1.GetType() == GeomAbs_Plane ||
2153 aBAS1.GetType() == GeomAbs_Cylinder ||
2154 aBAS1.GetType() == GeomAbs_Cone ||
2155 aBAS1.GetType() == GeomAbs_Sphere ||
2156 aBAS1.GetType() == GeomAbs_Torus);
2158 isAna2 = (aBAS2.GetType() == GeomAbs_Plane ||
2159 aBAS2.GetType() == GeomAbs_Cylinder ||
2160 aBAS2.GetType() == GeomAbs_Cone ||
2161 aBAS2.GetType() == GeomAbs_Sphere ||
2162 aBAS2.GetType() == GeomAbs_Torus);
2164 if (!isAna1 || !isAna2) {
2165 aTolFF = Max(aTolFF, 5.e-6);