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 <Bnd_Box.hxx>
19 #include <BOPAlgo_PaveFiller.hxx>
20 #include <BOPAlgo_SectionAttribute.hxx>
21 #include <BOPAlgo_Tools.hxx>
22 #include <BOPCol_DataMapOfIntegerReal.hxx>
23 #include <BOPCol_DataMapOfShapeInteger.hxx>
24 #include <BOPCol_ListOfInteger.hxx>
25 #include <BOPCol_ListOfShape.hxx>
26 #include <BOPCol_MapOfInteger.hxx>
27 #include <BOPCol_NCVector.hxx>
28 #include <BOPCol_Parallel.hxx>
29 #include <BOPDS_CommonBlock.hxx>
30 #include <BOPDS_CoupleOfPaveBlocks.hxx>
31 #include <BOPDS_Curve.hxx>
32 #include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx>
33 #include <BOPDS_DS.hxx>
34 #include <BOPDS_FaceInfo.hxx>
35 #include <BOPDS_Interf.hxx>
36 #include <BOPDS_Iterator.hxx>
37 #include <BOPDS_ListOfPave.hxx>
38 #include <BOPDS_ListOfPaveBlock.hxx>
39 #include <BOPDS_MapOfPaveBlock.hxx>
40 #include <BOPDS_PaveBlock.hxx>
41 #include <BOPDS_Point.hxx>
42 #include <BOPDS_ShapeInfo.hxx>
43 #include <BOPDS_VectorOfCurve.hxx>
44 #include <BOPDS_VectorOfPoint.hxx>
45 #include <BOPTools.hxx>
46 #include <BOPTools_AlgoTools.hxx>
47 #include <BOPTools_AlgoTools3D.hxx>
48 #include <BRep_Builder.hxx>
49 #include <BRep_Tool.hxx>
50 #include <BRep_TEdge.hxx>
51 #include <BRepAdaptor_Curve.hxx>
52 #include <BRepAdaptor_Surface.hxx>
53 #include <BRepBndLib.hxx>
54 #include <BRepBuilderAPI_MakeVertex.hxx>
55 #include <BRepTools.hxx>
56 #include <Geom2d_Curve.hxx>
57 #include <Geom_Curve.hxx>
58 #include <GeomAPI_ProjectPointOnCurve.hxx>
59 #include <GeomAPI_ProjectPointOnSurf.hxx>
61 #include <IntSurf_ListOfPntOn2S.hxx>
62 #include <IntSurf_PntOn2S.hxx>
63 #include <IntTools.hxx>
64 #include <IntTools_Context.hxx>
65 #include <IntTools_Curve.hxx>
66 #include <IntTools_EdgeFace.hxx>
67 #include <IntTools_FaceFace.hxx>
68 #include <IntTools_PntOn2Faces.hxx>
69 #include <IntTools_SequenceOfCurves.hxx>
70 #include <IntTools_SequenceOfPntOn2Faces.hxx>
71 #include <IntTools_ShrunkRange.hxx>
72 #include <IntTools_Tools.hxx>
73 #include <Precision.hxx>
75 #include <TopExp_Explorer.hxx>
77 #include <TopoDS_Compound.hxx>
78 #include <TopoDS_Edge.hxx>
79 #include <TopoDS_Face.hxx>
80 #include <TopoDS_Vertex.hxx>
83 static void ToleranceFF(const BRepAdaptor_Surface& aBAS1,
84 const BRepAdaptor_Surface& aBAS2,
85 Standard_Real& aTolFF);
87 /////////////////////////////////////////////////////////////////////////
88 //=======================================================================
89 //class : BOPAlgo_FaceFace
91 //=======================================================================
92 class BOPAlgo_FaceFace :
93 public IntTools_FaceFace,
102 myIF1(-1), myIF2(-1), myTolFF(1.e-7) {
105 virtual ~BOPAlgo_FaceFace() {
108 void SetIndices(const Standard_Integer nF1,
109 const Standard_Integer nF2) {
114 void Indices(Standard_Integer& nF1,
115 Standard_Integer& nF2) const {
120 void SetFaces(const TopoDS_Face& aF1,
121 const TopoDS_Face& aF2) {
126 const TopoDS_Face& Face1()const {
130 const TopoDS_Face& Face2()const {
134 void SetTolFF(const Standard_Real aTolFF) {
138 Standard_Real TolFF() const{
142 virtual void Perform() {
143 BOPAlgo_Algo::UserBreak();
144 IntTools_FaceFace::Perform(myF1, myF2);
148 Standard_Integer myIF1;
149 Standard_Integer myIF2;
150 Standard_Real myTolFF;
155 //=======================================================================
156 typedef BOPCol_NCVector
157 <BOPAlgo_FaceFace> BOPAlgo_VectorOfFaceFace;
159 typedef BOPCol_Functor
161 BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceFunctor;
164 <BOPAlgo_FaceFaceFunctor,
165 BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceCnt;
166 /////////////////////////////////////////////////////////////////////////
167 //=======================================================================
168 //function : PerformFF
170 //=======================================================================
171 void BOPAlgo_PaveFiller::PerformFF()
173 Standard_Integer iSize;
174 Standard_Boolean bValid;
178 myIterator->Initialize(TopAbs_FACE, TopAbs_FACE);
179 iSize=myIterator->ExpectedLength();
184 Standard_Boolean bJustAdd, bApp, bCompC2D1, bCompC2D2, bIsDone;
185 Standard_Boolean bToSplit, bTangentFaces;
186 Standard_Integer nF1, nF2, aNbCurves, aNbPoints, i, aNbLP;
187 Standard_Integer aNbFaceFace, k;
188 Standard_Real aApproxTol, aTolR3D, aTolR2D, aTolFF, aTolReal;
189 BRepAdaptor_Surface aBAS1, aBAS2;
190 BOPCol_MapOfInteger aMI;
191 BOPAlgo_VectorOfFaceFace aVFaceFace;
193 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
194 aFFs.SetIncrement(iSize);
196 bApp=mySectionAttribute.Approximation();
197 bCompC2D1=mySectionAttribute.PCurveOnS1();
198 bCompC2D2=mySectionAttribute.PCurveOnS2();
200 bToSplit = Standard_False;
202 for (; myIterator->More(); myIterator->Next()) {
203 myIterator->Value(nF1, nF2, bJustAdd);
208 const TopoDS_Face& aF1=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
209 const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
212 myDS->UpdateFaceInfoOn(nF1);
213 myDS->UpdateFaceInfoIn(nF1);
216 myDS->UpdateFaceInfoOn(nF2);
217 myDS->UpdateFaceInfoIn(nF2);
220 aBAS1.Initialize(aF1, Standard_False);
221 aBAS2.Initialize(aF2, Standard_False);
222 if (aBAS1.GetType() == GeomAbs_Plane &&
223 aBAS2.GetType() == GeomAbs_Plane) {
224 Standard_Boolean bToIntersect;
226 bToIntersect = CheckPlanes(nF1, nF2);
228 myDS->AddInterf(nF1, nF2);
229 BOPDS_InterfFF& aFF=aFFs.Append1();
230 aFF.SetIndices(nF1, nF2);
236 ToleranceFF(aBAS1, aBAS2, aTolFF);
238 BOPAlgo_FaceFace& aFaceFace=aVFaceFace.Append1();
240 aFaceFace.SetIndices(nF1, nF2);
241 aFaceFace.SetFaces(aF1, aF2);
242 aFaceFace.SetTolFF(aTolFF);
244 IntSurf_ListOfPntOn2S aListOfPnts;
245 GetEFPnts(nF1, nF2, aListOfPnts);
246 aNbLP = aListOfPnts.Extent();
248 aFaceFace.SetList(aListOfPnts);
251 aFaceFace.SetParameters(bApp, bCompC2D1, bCompC2D2, aApproxTol);
252 aFaceFace.SetProgressIndicator(myProgressIndicator);
253 }//for (; myIterator->More(); myIterator->Next()) {
255 aNbFaceFace=aVFaceFace.Extent();
256 //======================================================
257 BOPAlgo_FaceFaceCnt::Perform(myRunParallel, aVFaceFace);
258 //======================================================
260 for (k=0; k < aNbFaceFace; ++k) {
261 BOPAlgo_FaceFace& aFaceFace=aVFaceFace(k);
263 aFaceFace.Indices(nF1, nF2);
264 aTolFF=aFaceFace.TolFF();
266 bIsDone=aFaceFace.IsDone();
268 aTolR3D=aFaceFace.TolReached3d();
269 aTolR2D=aFaceFace.TolReached2d();
270 aTolReal = aFaceFace.TolReal();
271 bTangentFaces=aFaceFace.TangentFaces();
273 if (aTolR3D < aTolFF){
276 if (aTolReal < aTolFF) {
279 if (aTolR2D < 1.e-7){
283 aFaceFace.PrepareLines3D(bToSplit);
285 const IntTools_SequenceOfCurves& aCvsX=aFaceFace.Lines();
286 const IntTools_SequenceOfPntOn2Faces& aPntsX=aFaceFace.Points();
288 aNbCurves=aCvsX.Length();
289 aNbPoints=aPntsX.Length();
291 if (aNbCurves || aNbPoints) {
292 myDS->AddInterf(nF1, nF2);
295 BOPDS_InterfFF& aFF=aFFs.Append1();
296 aFF.SetIndices(nF1, nF2);
298 aFF.SetTolR3D(aTolR3D);
299 aFF.SetTolR2D(aTolR2D);
300 aFF.SetTolReal(aTolReal);
301 aFF.SetTangentFaces(bTangentFaces);
304 aFF.Init(aNbCurves, aNbPoints);
308 // Fix bounding box expanding coefficient.
309 Standard_Real aBoxExpandValue = aTolR3D;
312 // Modify geometric expanding coefficient by topology value,
313 // since this bounging box used in sharing (vertex or edge).
314 Standard_Real aMaxVertexTol = Max (BRep_Tool::MaxTolerance(aFaceFace.Face1(), TopAbs_VERTEX),
315 BRep_Tool::MaxTolerance(aFaceFace.Face2(), TopAbs_VERTEX));
316 aBoxExpandValue += aMaxVertexTol;
319 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
320 for (i=1; i<=aNbCurves; ++i) {
323 const IntTools_Curve& aIC=aCvsX(i);
324 const Handle(Geom_Curve)& aC3D= aIC.Curve();
325 bValid=IntTools_Tools::CheckCurve(aC3D, aBoxExpandValue, aBox);
327 BOPDS_Curve& aNC=aVNC.Append1();
334 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
335 for (i=1; i<=aNbPoints; ++i) {
336 const IntTools_PntOn2Faces& aPi=aPntsX(i);
337 const gp_Pnt& aP=aPi.P1().Pnt();
339 BOPDS_Point& aNP=aVNP.Append1();
342 //}// if (aNbCs || aNbPs)
345 BOPDS_InterfFF& aFF=aFFs.Append1();
346 aFF.SetIndices(nF1, nF2);
349 aFF.Init(aNbCurves, aNbPoints);
351 }// for (k=0; k < aNbFaceFace; ++k) {
353 //=======================================================================
354 //function : MakeBlocks
356 //=======================================================================
357 void BOPAlgo_PaveFiller::MakeBlocks()
359 Standard_Integer aNbFF;
363 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
369 Standard_Boolean bExist, bValid2D;
370 Standard_Integer i, nF1, nF2, aNbC, aNbP, j;
371 Standard_Integer nV1, nV2;
372 Standard_Real aTolR3D, aT1, aT2, aTol;
373 Handle(NCollection_BaseAllocator) aAllocator;
374 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
376 Handle(BOPDS_PaveBlock) aPBOut;
378 //-----------------------------------------------------scope f
380 NCollection_BaseAllocator::CommonBaseAllocator();
382 BOPCol_ListOfInteger aLSE(aAllocator), aLBV(aAllocator);
383 BOPCol_MapOfInteger aMVOnIn(100, aAllocator), aMF(100, aAllocator),
384 aMVStick(100,aAllocator), aMVEF(100, aAllocator),
385 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_DataMapOfIntegerInteger aDMI(100, aAllocator);
394 BOPCol_DataMapOfIntegerListOfInteger aDMBV(100, aAllocator);
395 BOPCol_DataMapIteratorOfDataMapOfIntegerReal aItMV;
397 for (i=0; i<aNbFF; ++i) {
401 BOPDS_InterfFF& aFF=aFFs(i);
402 aFF.Indices(nF1, nF2);
404 BOPDS_VectorOfPoint& aVP=aFF.ChangePoints();
406 BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
408 if (!aNbP && !aNbC) {
412 const TopoDS_Face& aF1=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
413 const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
415 aTolR3D=aFF.TolR3D();
419 myDS->UpdateFaceInfoOn(nF1);
420 myDS->UpdateFaceInfoIn(nF1);
423 myDS->UpdateFaceInfoOn(nF2);
424 myDS->UpdateFaceInfoIn(nF2);
427 BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
428 BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
435 myDS->VerticesOnIn(nF1, nF2, aMVOnIn, aMPBOnIn);
436 myDS->SharedEdges(nF1, nF2, aLSE, aAllocator);
439 for (j=0; j<aNbP; ++j) {
441 BOPDS_CoupleOfPaveBlocks aCPB;
443 BOPDS_Point& aNP=aVP.ChangeValue(j);
444 const gp_Pnt& aP=aNP.Pnt();
446 bExist=IsExistingVertex(aP, aTolR3D, aMVOnIn);
448 BOPTools_AlgoTools::MakeNewVertex(aP, aTolR3D, aV);
450 aCPB.SetIndexInterf(i);
452 aMSCPB.Add(aV, aCPB);
459 GetStickVertices(nF1, nF2, aMVStick, aMVEF, aMI);
461 for (j=0; j<aNbC; ++j) {
462 BOPDS_Curve& aNC=aVC.ChangeValue(j);
463 const IntTools_Curve& aIC=aNC.Curve();
465 aNC.InitPaveBlock1();
467 PutPavesOnCurve(aMVOnIn, aTolR3D, aNC, nF1, nF2, aMI, aMVEF, aMVTol);
469 PutStickPavesOnCurve(aF1, aF2, aMI, aNC, aMVStick, aMVTol);
472 PutEFPavesOnCurve(aNC, aMI, aMVEF, aMVTol);
475 if (aIC.HasBounds()) {
478 PutBoundPaveOnCurve(aF1, aF2, aTolR3D, aNC, aLBV);
480 if (!aLBV.IsEmpty()) {
484 }//for (j=0; j<aNbC; ++j) {
486 // Put closing pave if needed
487 for (j=0; j<aNbC; ++j) {
488 BOPDS_Curve& aNC=aVC.ChangeValue(j);
489 PutClosingPaveOnCurve (aNC);
492 // 3. Make section edges
493 for (j=0; j<aNbC; ++j) {
494 BOPDS_Curve& aNC=aVC.ChangeValue(j);
495 const IntTools_Curve& aIC=aNC.Curve();
497 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
498 Handle(BOPDS_PaveBlock)& aPB1=aNC.ChangePaveBlock1();
501 aPB1->Update(aLPB, Standard_False);
503 aItLPB.Initialize(aLPB);
504 for (; aItLPB.More(); aItLPB.Next()) {
505 Handle(BOPDS_PaveBlock)& aPB=aItLPB.ChangeValue();
506 aPB->Indices(nV1, nV2);
507 aPB->Range (aT1, aT2);
509 if (fabs(aT1 - aT2) < Precision::PConfusion()) {
513 bValid2D=myContext->IsValidBlockForFaces(aT1, aT2, aIC,
519 bExist=IsExistingPaveBlock(aPB, aNC, aTolR3D, aLSE);
524 Standard_Real aTolNew;
525 bExist=IsExistingPaveBlock(aPB, aNC, aTolR3D, aMPBOnIn, aPBOut, aTolNew);
527 if (aMPBAdd.Add(aPBOut)) {
528 Standard_Boolean bInBothFaces = Standard_True;
529 if (!myDS->IsCommonBlock(aPBOut)) {
534 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(nE);
535 aTolE = BRep_Tool::Tolerance(aE);
536 if (aTolNew < aFF.TolReal())
537 aTolNew = aFF.TolReal(); // use real tolerance of intersection
538 if (aTolNew > aTolE) {
539 UpdateEdgeTolerance(nE, aTolNew);
541 bInBothFaces = Standard_False;
544 bInBothFaces = (aFI1.PaveBlocksOn().Contains(aPBOut) ||
545 aFI1.PaveBlocksIn().Contains(aPBOut))&&
546 (aFI2.PaveBlocksOn().Contains(aPBOut) ||
547 aFI2.PaveBlocksIn().Contains(aPBOut));
550 PreparePostTreatFF(i, j, aPBOut, aMSCPB, aMVI, aLPBC);
557 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
558 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
560 BOPTools_AlgoTools::MakeEdge (aIC, aV1, aT1,
561 aV2, aT2, aTolR3D, aES);
562 BOPTools_AlgoTools::MakePCurve(aES, aF1, aF2, aIC,
563 mySectionAttribute.PCurveOnS1(),
564 mySectionAttribute.PCurveOnS2());
566 if (BOPTools_AlgoTools::IsMicroEdge(aES, myContext)) {
570 // Append the Pave Block to the Curve j
573 // Keep info for post treatment
574 BOPDS_CoupleOfPaveBlocks aCPB;
575 aCPB.SetIndexInterf(i);
577 aCPB.SetPaveBlock1(aPB);
579 aMSCPB.Add(aES, aCPB);
588 }//for (j=0; j<aNbC; ++j) {
589 //back to previous tolerance values for unused vertices
590 aItMV.Initialize(aMVTol);
591 for (; aItMV.More(); aItMV.Next()) {
593 aTol = aItMV.Value();
595 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV1);
596 const Handle(BRep_TVertex)& TV =
597 *((Handle(BRep_TVertex)*)&aV.TShape());
601 ProcessExistingPaveBlocks(i, aMPBOnIn, aDMBV, aMSCPB, aMVI, aMPBAdd);
602 }//for (i=0; i<aNbFF; ++i) {
605 myErrorStatus=PostTreatFF(aMSCPB, aMVI, aDMExEdges, aDMI, aAllocator);
609 // reduce tolerances of section edges where it is appropriate
610 CorrectToleranceOfSE();
613 UpdateFaceInfo(aDMExEdges, aDMI);
614 //Update all pave blocks
615 UpdatePaveBlocks(aDMI);
616 //-----------------------------------------------------scope t
626 //=======================================================================
627 //function : PostTreatFF
629 //=======================================================================
630 Standard_Integer BOPAlgo_PaveFiller::PostTreatFF
631 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMSCPB,
632 BOPCol_DataMapOfShapeInteger& aMVI,
633 BOPDS_DataMapOfPaveBlockListOfPaveBlock& aDMExEdges,
634 BOPCol_DataMapOfIntegerInteger& aDMI,
635 const Handle(NCollection_BaseAllocator)& theAllocator)
637 Standard_Integer iRet, aNbS;
640 aNbS=theMSCPB.Extent();
645 Standard_Boolean bHasPaveBlocks, bOld;
646 Standard_Integer iErr, nSx, nVSD, iX, iP, iC, j, nV, iV = 0, iE, k;
647 Standard_Integer aNbLPBx;
648 TopAbs_ShapeEnum aType;
650 BOPCol_ListIteratorOfListOfShape aItLS;
651 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
653 Handle(BOPDS_PaveBlock) aPB1;
657 BOPCol_ListOfShape aLS(theAllocator);
658 BOPAlgo_PaveFiller aPF(theAllocator);
659 aPF.SetIsPrimary(Standard_False);
660 aPF.SetNonDestructive(myNonDestructive);
662 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
666 const TopoDS_Shape& aS=theMSCPB.FindKey(1);
667 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromIndex(1);
670 aType=aS.ShapeType();
671 if (aType==TopAbs_VERTEX) {
672 aSI.SetShapeType(aType);
674 iV=myDS->Append(aSI);
676 iX=aCPB.IndexInterf();
678 BOPDS_InterfFF& aFF=aFFs(iX);
679 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
680 BOPDS_Point& aNP=aVNP(iP);
683 else if (aType==TopAbs_EDGE) {
684 aPB1=aCPB.PaveBlock1();
686 if (aPB1->HasEdge()) {
687 BOPDS_ListOfPaveBlock aLPBx;
689 aDMExEdges.Bind(aPB1, aLPBx);
691 aSI.SetShapeType(aType);
693 iE=myDS->Append(aSI);
701 // 1 prepare arguments
702 for (k=1; k<=aNbS; ++k) {
703 const TopoDS_Shape& aS=theMSCPB.FindKey(k);
708 aPF.SetProgressIndicator(myProgressIndicator);
709 aPF.SetRunParallel(myRunParallel);
710 aPF.SetArguments(aLS);
712 iErr=aPF.ErrorStatus();
718 aItLS.Initialize(aLS);
719 for (; aItLS.More(); aItLS.Next()) {
720 const TopoDS_Shape& aSx=aItLS.Value();
721 nSx=aPDS->Index(aSx);
722 const BOPDS_ShapeInfo& aSIx=aPDS->ShapeInfo(nSx);
724 aType=aSIx.ShapeType();
726 if (aType==TopAbs_VERTEX) {
727 if (aPDS->HasShapeSD(nSx, nVSD)) {
728 aV=aPDS->Shape(nVSD);
733 // index of new vertex in theDS -> iV
734 if (!aMVI.IsBound(aV)) {
735 aSI.SetShapeType(aType);
737 iV=myDS->Append(aSI);
744 // update FF interference
745 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx);
746 iX=aCPB.IndexInterf();
748 BOPDS_InterfFF& aFF=aFFs(iX);
749 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
750 BOPDS_Point& aNP=aVNP(iP);
752 }//if (aType==TopAbs_VERTEX) {
754 else if (aType==TopAbs_EDGE) {
755 bHasPaveBlocks=aPDS->HasPaveBlocks(nSx);
756 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx);
757 iX=aCPB.IndexInterf();
759 aPB1=aCPB.PaveBlock1();
761 bOld = aPB1->HasEdge();
763 BOPDS_ListOfPaveBlock aLPBx;
764 aDMExEdges.Bind(aPB1, aLPBx);
767 if (!bHasPaveBlocks) {
769 aDMExEdges.ChangeFind(aPB1).Append(aPB1);
772 aSI.SetShapeType(aType);
774 iE = myDS->Append(aSI);
780 BOPDS_InterfFF& aFF=aFFs(iX);
781 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
782 BOPDS_Curve& aNC=aVNC(iC);
783 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
785 // check if edge occured to be micro edge;
786 // note we check not the edge aSx itself, but its image in aPDS
787 const BOPDS_ListOfPaveBlock& aLPBx = aPDS->PaveBlocks(nSx);
788 aNbLPBx = aLPBx.Extent();
789 if (aPDS->HasPaveBlocks(nSx) &&
790 (aNbLPBx == 0 || (aNbLPBx == 1 && !aLPBx.First()->HasShrunkData()))) {
791 BOPDS_ListIteratorOfListOfPaveBlock it(aLPBC);
792 for (; it.More(); it.Next()) {
793 if (it.Value() == aPB1) {
801 if (bOld && !aNbLPBx) {
802 aDMExEdges.ChangeFind(aPB1).Append(aPB1);
807 aItLPB.Initialize(aLPBC);
808 for (; aItLPB.More(); aItLPB.Next()) {
809 const Handle(BOPDS_PaveBlock)& aPBC=aItLPB.Value();
811 aLPBC.Remove(aItLPB);
820 if (!aMVI.IsBound(aE)) {
821 aSI.SetShapeType(aType);
823 iE=myDS->Append(aSI);
829 // append new PaveBlock to aLPBC
835 aItLPB.Initialize(aLPBx);
836 for (; aItLPB.More(); aItLPB.Next()) {
837 const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value();
838 const Handle(BOPDS_PaveBlock) aPBRx=aPDS->RealPaveBlock(aPBx);
840 // update vertices of paves
841 aPave[0]=aPBx->Pave1();
842 aPave[1]=aPBx->Pave2();
843 for (j=0; j<2; ++j) {
844 nV = aPave[j].Index();
845 aV = aPDS->Shape(nV);
847 if (!aMVI.IsBound(aV)) {
848 // index of new vertex in theDS -> iV
849 aSI.SetShapeType(TopAbs_VERTEX);
851 iV = myDS->Append(aSI);
857 const BOPDS_Pave& aP1 = !j ? aPB1->Pave1() : aPB1->Pave2();
858 if (aP1.Parameter() == aPave[j].Parameter() &&
860 aDMI.Bind(aP1.Index(), iV);
861 myDS->AddShapeSD(aP1.Index(), iV);
864 aPave[j].SetIndex(iV);
868 aE=aPDS->Shape(aPBRx->Edge());
870 if (!aMVI.IsBound(aE)) {
871 aSI.SetShapeType(aType);
873 iE=myDS->Append(aSI);
875 // update real edge tolerance according to distances in common block if any
876 if (aPDS->IsCommonBlock(aPBx)) {
877 const Handle(BOPDS_CommonBlock)& aCB = aPDS->CommonBlock(aPBx);
878 Standard_Real aTol = BOPAlgo_Tools::ComputeToleranceOfCB(aCB, aPDS, aPF.Context());
879 if (aFF.TolReal() < aTol) {
880 aFF.SetTolReal(aTol);
887 // append new PaveBlock to aLPBC
888 Handle(BOPDS_PaveBlock) aPBC=new BOPDS_PaveBlock();
890 aPBC->SetPave1(aPave[0]);
891 aPBC->SetPave2(aPave[1]);
894 aPBC->SetOriginalEdge(aPB1->OriginalEdge());
895 aDMExEdges.ChangeFind(aPB1).Append(aPBC);
903 }//else if (aType==TopAbs_EDGE)
904 }//for (; aItLS.More(); aItLS.Next()) {
908 //=======================================================================
909 //function : UpdateFaceInfo
911 //=======================================================================
912 void BOPAlgo_PaveFiller::UpdateFaceInfo
913 (BOPDS_DataMapOfPaveBlockListOfPaveBlock& theDME,
914 const BOPCol_DataMapOfIntegerInteger& theDMV)
916 Standard_Integer i, j, nV1, nF1, nF2,
918 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
919 BOPCol_MapOfInteger aMF;
921 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
924 //1. Sections (curves, points);
925 for (i=0; i<aNbFF; ++i) {
926 BOPDS_InterfFF& aFF=aFFs(i);
927 aFF.Indices(nF1, nF2);
929 BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
930 BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
932 // 1.1. Section edges
933 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
935 for (j=0; j<aNbC; ++j) {
936 BOPDS_Curve& aNC=aVNC(j);
937 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
939 // Add section edges to face info
940 aItLPB.Initialize(aLPBC);
941 for (; aItLPB.More(); ) {
942 const Handle(BOPDS_PaveBlock)& aPB=aItLPB.Value();
944 // Treat existing pave blocks
945 if (theDME.IsBound(aPB)) {
946 BOPDS_ListOfPaveBlock& aLPB=theDME.ChangeFind(aPB);
947 UpdateExistingPaveBlocks(aPB, aLPB, nF1, nF2);
948 aLPBC.Remove(aItLPB);
952 aFI1.ChangePaveBlocksSc().Add(aPB);
953 aFI2.ChangePaveBlocksSc().Add(aPB);
958 // 1.2. Section vertices
959 const BOPDS_VectorOfPoint& aVNP=aFF.Points();
961 for (j=0; j<aNbP; ++j) {
962 const BOPDS_Point& aNP=aVNP(j);
967 aFI1.ChangeVerticesSc().Add(nV1);
968 aFI2.ChangeVerticesSc().Add(nV1);
975 Standard_Boolean bVerts, bEdges;
977 bVerts = theDMV.Extent() > 0;
978 bEdges = theDME.Extent() > 0;
980 if (!bVerts && !bEdges) {
984 // 2. Update Face Info information with new vertices and new
985 // pave blocks created in PostTreatFF from existing ones
986 Standard_Integer nV2, aNbPB;
987 BOPCol_MapIteratorOfMapOfInteger aItMF;
988 BOPCol_DataMapIteratorOfDataMapOfIntegerInteger aItMV;
990 aItMF.Initialize(aMF);
991 for (; aItMF.More(); aItMF.Next()) {
994 BOPDS_FaceInfo& aFI = myDS->ChangeFaceInfo(nF1);
996 // 2.1. Update information about vertices
998 BOPCol_MapOfInteger& aMVOn = aFI.ChangeVerticesOn();
999 BOPCol_MapOfInteger& aMVIn = aFI.ChangeVerticesIn();
1001 aItMV.Initialize(theDMV);
1002 for (; aItMV.More(); aItMV.Next()) {
1004 nV2 = aItMV.Value();
1006 if (aMVOn.Remove(nV1)) {
1010 if (aMVIn.Remove(nV1)) {
1013 } // for (; aItMV.More(); aItMV.Next()) {
1016 // 2.2. Update information about pave blocks
1018 BOPDS_IndexedMapOfPaveBlock& aMPBOn = aFI.ChangePaveBlocksOn();
1019 BOPDS_IndexedMapOfPaveBlock& aMPBIn = aFI.ChangePaveBlocksIn();
1021 BOPDS_IndexedMapOfPaveBlock aMPBCopy;
1022 for (i = 0; i < 2; ++i) {
1023 BOPDS_IndexedMapOfPaveBlock& aMPBOnIn = !i ? aMPBOn : aMPBIn;
1024 aMPBCopy = aMPBOnIn;
1027 aNbPB = aMPBCopy.Extent();
1028 for (j = 1; j <= aNbPB; ++j) {
1029 const Handle(BOPDS_PaveBlock)& aPB = aMPBCopy(j);
1030 if (theDME.IsBound(aPB)) {
1031 const BOPDS_ListOfPaveBlock& aLPB = theDME.Find(aPB);
1032 if (aLPB.IsEmpty()) {
1037 aItLPB.Initialize(aLPB);
1038 for (; aItLPB.More(); aItLPB.Next()) {
1039 const Handle(BOPDS_PaveBlock)& aPB1 = aItLPB.Value();
1046 } // for (j = 1; j <= aNbPB; ++j) {
1047 } // for (i = 0; i < 2; ++i) {
1051 //=======================================================================
1052 //function : IsExistingVertex
1054 //=======================================================================
1055 Standard_Boolean BOPAlgo_PaveFiller::IsExistingVertex
1057 const Standard_Real theTolR3D,
1058 const BOPCol_MapOfInteger& aMVOnIn)const
1060 Standard_Boolean bRet;
1061 Standard_Integer nV, iFlag;
1064 BOPCol_MapIteratorOfMapOfInteger aIt;
1069 aBoxP.Enlarge(theTolR3D);
1071 aIt.Initialize(aMVOnIn);
1072 for (; aIt.More(); aIt.Next()) {
1074 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1075 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&aSIV.Shape()));
1076 const Bnd_Box& aBoxV=aSIV.Box();
1078 if (!aBoxP.IsOut(aBoxV)) {
1079 iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP, theTolR3D);
1087 //=======================================================================
1088 //function : IsExistingPaveBlock
1090 //=======================================================================
1091 Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock
1092 (const Handle(BOPDS_PaveBlock)& thePB,
1093 const BOPDS_Curve& theNC,
1094 const Standard_Real theTolR3D,
1095 const BOPCol_ListOfInteger& theLSE)
1097 Standard_Boolean bRet=Standard_True;
1099 if (theLSE.IsEmpty()) {
1103 Standard_Real aT1, aT2, aTm, aTx, aTol, aDist;
1104 Standard_Integer nE, iFlag;
1107 BOPCol_ListIteratorOfListOfInteger aItLI;
1109 thePB->Range(aT1, aT2);
1110 aTm=IntTools_Tools::IntermediatePoint (aT1, aT2);
1111 theNC.Curve().D0(aTm, aPm);
1113 aBoxPm.Enlarge(theTolR3D);
1115 aItLI.Initialize(theLSE);
1116 for (; aItLI.More(); aItLI.Next()) {
1120 const BOPDS_ShapeInfo& aSIE=myDS->ChangeShapeInfo(nE);
1121 const Bnd_Box& aBoxE=aSIE.Box();
1122 if (!aBoxE.IsOut(aBoxPm)) {
1123 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape()));
1124 aTol = BRep_Tool::Tolerance(aE);
1125 aTol = aTol > theTolR3D ? aTol : theTolR3D;
1126 iFlag=myContext->ComputePE(aPm, aTol, aE, aTx, aDist);
1135 //=======================================================================
1136 //function : IsExistingPaveBlock
1138 //=======================================================================
1139 Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock
1140 (const Handle(BOPDS_PaveBlock)& thePB,
1141 const BOPDS_Curve& theNC,
1142 const Standard_Real theTolR3D,
1143 const BOPDS_IndexedMapOfPaveBlock& theMPBOnIn,
1144 Handle(BOPDS_PaveBlock)& aPBOut,
1145 Standard_Real& theTolNew)
1147 Standard_Boolean bRet;
1148 Standard_Real aT1, aT2, aTm, aTx;
1149 Standard_Integer nSp, iFlag1, iFlag2, nV11, nV12, nV21, nV22, i, aNbPB;
1150 gp_Pnt aP1, aPm, aP2;
1151 Bnd_Box aBoxP1, aBoxPm, aBoxP2;
1153 bRet=Standard_False;
1154 const IntTools_Curve& aIC=theNC.Curve();
1156 thePB->Range(aT1, aT2);
1157 thePB->Indices(nV11, nV12);
1161 aBoxP1.Enlarge(theTolR3D);
1162 //intermediate point
1163 aTm=IntTools_Tools::IntermediatePoint (aT1, aT2);
1166 aBoxPm.Enlarge(theTolR3D);
1170 aBoxP2.Enlarge(theTolR3D);
1173 aNbPB = theMPBOnIn.Extent();
1174 for (i = 1; i <= aNbPB; ++i) {
1175 const Handle(BOPDS_PaveBlock)& aPB = theMPBOnIn(i);
1176 aPB->Indices(nV21, nV22);
1180 const BOPDS_ShapeInfo& aSISp=myDS->ChangeShapeInfo(nSp);
1181 const TopoDS_Edge& aSp=(*(TopoDS_Edge *)(&aSISp.Shape()));
1182 const Bnd_Box& aBoxSp=aSISp.Box();
1184 iFlag1 = (nV11 == nV21 || nV11 == nV22) ? 2 :
1185 (!aBoxSp.IsOut(aBoxP1) ? 1 : 0);
1186 iFlag2 = (nV12 == nV21 || nV12 == nV22) ? 2 :
1187 (!aBoxSp.IsOut(aBoxP2) ? 1 : 0);
1188 if (iFlag1 && iFlag2) {
1189 Standard_Real aDist;
1190 if (aBoxSp.IsOut(aBoxPm) || myContext->ComputePE(aPm,
1198 iFlag1 = !myContext->ComputePE(aP1, theTolR3D, aSp, aTx, aDist);
1199 if (theTolNew < aDist)
1204 iFlag2 = !myContext->ComputePE(aP2, theTolR3D, aSp, aTx, aDist);
1205 if (theTolNew < aDist)
1209 if (iFlag1 && iFlag2) {
1218 //=======================================================================
1219 //function : PutBoundPaveOnCurve
1221 //=======================================================================
1222 void BOPAlgo_PaveFiller::PutBoundPaveOnCurve(const TopoDS_Face& aF1,
1223 const TopoDS_Face& aF2,
1224 const Standard_Real aTolR3D,
1226 BOPCol_ListOfInteger& aLVB)
1228 Standard_Boolean bVF;
1229 Standard_Integer nV, iFlag, nVn, j, aNbEP;
1230 Standard_Real aT[2], aTmin, aTmax, aTV, aTol, aTolVnew;
1233 BOPDS_ListIteratorOfListOfPave aItLP;
1234 BOPDS_Pave aPn, aPMM[2];
1236 aTolVnew = Precision::Confusion();
1238 const IntTools_Curve& aIC=aNC.Curve();
1239 aIC.Bounds(aT[0], aT[1], aP[0], aP[1]);
1241 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1242 const BOPDS_ListOfPave& aLP=aPB->ExtPaves();
1249 aItLP.Initialize(aLP);
1250 for (; aItLP.More(); aItLP.Next()) {
1251 const BOPDS_Pave& aPv=aItLP.Value();
1252 aPv.Contents(nV, aTV);
1264 for (j=0; j<2; ++j) {
1265 //if curve is closed, process only one bound
1266 if (j && aP[1].IsEqual(aP[0], aTolVnew)) {
1276 aTol = aTolR3D+Precision::Confusion();
1277 aBoxP.Enlarge(aTol);
1278 const BOPDS_Pave& aPV=aPMM[j];
1280 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1281 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&aSIV.Shape()));
1282 const Bnd_Box& aBoxV=aSIV.Box();
1283 if (!aBoxP.IsOut(aBoxV)){
1284 iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP[j], aTol);
1289 bVF=myContext->IsValidPointForFaces (aP[j], aF1, aF2, aTolR3D);
1294 BOPDS_ShapeInfo aSIVn;
1296 BOPTools_AlgoTools::MakeNewVertex(aP[j], aTolR3D, aVn);
1297 aSIVn.SetShapeType(TopAbs_VERTEX);
1298 aSIVn.SetShape(aVn);
1300 nVn=myDS->Append(aSIVn);
1303 aPn.SetParameter(aT[j]);
1304 aPB->AppendExtPave(aPn);
1306 aVn=(*(TopoDS_Vertex *)(&myDS->Shape(nVn)));
1307 BOPTools_AlgoTools::UpdateVertex (aIC, aT[j], aVn);
1309 aTolVnew = BRep_Tool::Tolerance(aVn);
1311 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nVn);
1312 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
1313 BRepBndLib::Add(aVn, aBoxDS);
1314 aBoxDS.SetGap(aBoxDS.GetGap() + Precision::Confusion());
1321 //=======================================================================
1322 //function : PutPavesOnCurve
1324 //=======================================================================
1325 void BOPAlgo_PaveFiller::PutPavesOnCurve
1326 (const BOPCol_MapOfInteger& aMVOnIn,
1327 const Standard_Real aTolR3D,
1329 const Standard_Integer nF1,
1330 const Standard_Integer nF2,
1331 const BOPCol_MapOfInteger& aMI,
1332 const BOPCol_MapOfInteger& aMVEF,
1333 BOPCol_DataMapOfIntegerReal& aMVTol)
1335 Standard_Boolean bInBothFaces;
1336 Standard_Integer nV;
1337 BOPCol_MapIteratorOfMapOfInteger aIt;
1339 const Bnd_Box& aBoxC=aNC.Box();
1341 //Put EF vertices first
1342 aIt.Initialize(aMVEF);
1343 for (; aIt.More(); aIt.Next()) {
1345 PutPaveOnCurve(nV, aTolR3D, aNC, aMI, aMVTol, 2);
1347 //Put all other vertices
1348 aIt.Initialize(aMVOnIn);
1349 for (; aIt.More(); aIt.Next()) {
1351 if (aMVEF.Contains(nV)) {
1355 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1356 const Bnd_Box& aBoxV=aSIV.Box();
1358 if (aBoxC.IsOut(aBoxV)){
1361 if (!myDS->IsNewShape(nV)) {
1362 const BOPDS_FaceInfo& aFI1 = myDS->FaceInfo(nF1);
1363 const BOPDS_FaceInfo& aFI2 = myDS->FaceInfo(nF2);
1365 bInBothFaces = (aFI1.VerticesOn().Contains(nV) ||
1366 aFI1.VerticesIn().Contains(nV))&&
1367 (aFI2.VerticesOn().Contains(nV) ||
1368 aFI2.VerticesIn().Contains(nV));
1369 if (!bInBothFaces) {
1374 PutPaveOnCurve(nV, aTolR3D, aNC, aMI, aMVTol, 1);
1378 //=======================================================================
1379 //function : ExtendedTolerance
1381 //=======================================================================
1382 Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance
1383 (const Standard_Integer nV,
1384 const BOPCol_MapOfInteger& aMI,
1385 Standard_Real& aTolVExt,
1386 const Standard_Integer aType)
1388 Standard_Boolean bFound = Standard_False;
1389 if (!(myDS->IsNewShape(nV))) {
1393 Standard_Integer i, k, aNbLines, aNbInt;
1394 Standard_Real aT11, aT12, aD1, aD2, aD;
1396 gp_Pnt aPV, aP11, aP12;
1402 } else if (aType == 2) {
1406 aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1407 aPV=BRep_Tool::Pnt(aV);
1409 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
1410 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1412 for (; k<aNbInt; ++k) {
1413 aNbLines = !k ? aEEs.Extent() : aEFs.Extent();
1414 for (i = 0; i < aNbLines; ++i) {
1415 BOPDS_Interf *aInt = !k ? (BOPDS_Interf*) (&aEEs(i)) :
1416 (BOPDS_Interf*) (&aEFs(i));
1417 if (aInt->IndexNew() == nV) {
1418 if (aMI.Contains(aInt->Index1()) &&
1419 aMI.Contains(aInt->Index2())) {
1420 const IntTools_CommonPrt& aComPrt = !k ? aEEs(i).CommonPart() :
1421 aEFs(i).CommonPart();
1423 const TopoDS_Edge& aE1=aComPrt.Edge1();
1424 aComPrt.Range1(aT11, aT12);
1425 BOPTools_AlgoTools::PointOnEdge(aE1, aT11, aP11);
1426 BOPTools_AlgoTools::PointOnEdge(aE1, aT12, aP12);
1427 aD1=aPV.Distance(aP11);
1428 aD2=aPV.Distance(aP12);
1429 aD=(aD1>aD2)? aD1 : aD2;
1434 }//if (aMI.Contains(aEF.Index1()) && aMI.Contains(aEF.Index2())) {
1435 }//if (aInt->IndexNew() == nV) {
1436 }//for (i = 0; i < aNbLines; ++i) {
1437 }//for (k=0; k<2; ++k) {
1441 //=======================================================================
1442 //function : GetEFPnts
1444 //=======================================================================
1445 void BOPAlgo_PaveFiller::GetEFPnts
1446 (const Standard_Integer nF1,
1447 const Standard_Integer nF2,
1448 IntSurf_ListOfPntOn2S& aListOfPnts)
1450 Standard_Integer nE, nF, nFOpposite, aNbEFs, i;
1451 Standard_Real U1, U2, V1, V2, f, l;
1452 BOPCol_MapOfInteger aMI;
1454 //collect indexes of all shapes from nF1 and nF2.
1455 GetFullShapeMap(nF1, aMI);
1456 GetFullShapeMap(nF2, aMI);
1458 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1459 aNbEFs = aEFs.Extent();
1461 for(i = 0; i < aNbEFs; ++i) {
1462 const BOPDS_InterfEF& aEF = aEFs(i);
1463 if (aEF.HasIndexNew()) {
1464 aEF.Indices(nE, nFOpposite);
1465 if(aMI.Contains(nE) && aMI.Contains(nFOpposite)) {
1466 const IntTools_CommonPrt& aCP = aEF.CommonPart();
1467 Standard_Real aPar = aCP.VertexParameter1();
1468 const TopoDS_Edge& aE = (*(TopoDS_Edge*)(&myDS->Shape(nE)));
1469 const TopoDS_Face& aFOpposite =
1470 (*(TopoDS_Face*)(&myDS->Shape(nFOpposite)));
1472 const Handle(Geom_Curve)& aCurve = BRep_Tool::Curve(aE, f, l);
1474 nF = (nFOpposite == nF1) ? nF2 : nF1;
1475 const TopoDS_Face& aF = (*(TopoDS_Face*)(&myDS->Shape(nF)));
1476 Handle(Geom2d_Curve) aPCurve =
1477 BRep_Tool::CurveOnSurface(aE, aF, f, l);
1479 GeomAPI_ProjectPointOnSurf& aProj=myContext->ProjPS(aFOpposite);
1482 aCurve->D0(aPar, aPoint);
1483 IntSurf_PntOn2S aPnt;
1484 if(!aPCurve.IsNull()) {
1485 gp_Pnt2d aP2d = aPCurve->Value(aPar);
1486 aProj.Perform(aPoint);
1487 if(aProj.IsDone()) {
1488 aProj.LowerDistanceParameters(U1,V1);
1490 aPnt.SetValue(aP2d.X(),aP2d.Y(),U1,V1);
1492 aPnt.SetValue(U1,V1,aP2d.X(),aP2d.Y());
1494 aListOfPnts.Append(aPnt);
1498 GeomAPI_ProjectPointOnSurf& aProj1 = myContext->ProjPS(aF);
1499 aProj1.Perform(aPoint);
1500 aProj.Perform(aPoint);
1501 if(aProj1.IsDone() && aProj.IsDone()){
1502 aProj1.LowerDistanceParameters(U1,V1);
1503 aProj.LowerDistanceParameters(U2,V2);
1505 aPnt.SetValue(U1,V1,U2,V2);
1507 aPnt.SetValue(U2,V2,U1,V1);
1509 aListOfPnts.Append(aPnt);
1517 //=======================================================================
1518 //function : ProcessUnUsedVertices
1520 //=======================================================================
1521 void BOPAlgo_PaveFiller::PutEFPavesOnCurve
1523 const BOPCol_MapOfInteger& aMI,
1524 const BOPCol_MapOfInteger& aMVEF,
1525 BOPCol_DataMapOfIntegerReal& aMVTol)
1527 if (!aMVEF.Extent()) {
1531 const IntTools_Curve& aIC=aNC.Curve();
1532 GeomAbs_CurveType aTypeC;
1534 if (!(aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve)) {
1538 Standard_Integer nV;
1539 BOPCol_MapOfInteger aMV;
1542 RemoveUsedVertices(aNC, aMV);
1543 if (!aMV.Extent()) {
1547 Standard_Real aDist;
1550 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1551 GeomAPI_ProjectPointOnCurve& aProjPT = myContext->ProjPT(aC3D);
1553 BOPCol_MapIteratorOfMapOfInteger aItMI;
1554 aItMI.Initialize(aMV);
1555 for (; aItMI.More(); aItMI.Next()) {
1557 const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1558 gp_Pnt aPV = BRep_Tool::Pnt(aV);
1559 aProjPT.Perform(aPV);
1560 Standard_Integer aNbPoints = aProjPT.NbPoints();
1562 aDist = aProjPT.LowerDistance();
1563 PutPaveOnCurve(nV, aDist, aNC, aMI, aMVTol);
1568 //=======================================================================
1569 //function : ProcessUnUsedVertices
1571 //=======================================================================
1572 void BOPAlgo_PaveFiller::PutStickPavesOnCurve
1573 (const TopoDS_Face& aF1,
1574 const TopoDS_Face& aF2,
1575 const BOPCol_MapOfInteger& aMI,
1577 const BOPCol_MapOfInteger& aMVStick,
1578 BOPCol_DataMapOfIntegerReal& aMVTol)
1580 BOPCol_MapOfInteger aMV;
1581 aMV.Assign(aMVStick);
1582 RemoveUsedVertices(aNC, aMV);
1584 if (!aMV.Extent()) {
1588 Handle(Geom_Surface) aS1=BRep_Tool::Surface(aF1);
1589 Handle(Geom_Surface) aS2=BRep_Tool::Surface(aF2);
1591 const IntTools_Curve& aIC=aNC.Curve();
1592 //if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
1593 Handle(Geom2d_Curve) aC2D[2];
1595 aC2D[0]=aIC.FirstCurve2d();
1596 aC2D[1]=aIC.SecondCurve2d();
1597 if (!aC2D[0].IsNull() && !aC2D[1].IsNull()) {
1598 Standard_Integer nV, m, n;
1599 Standard_Real aTC[2], aD, aD2, u, v, aDT2, aScPr, aDScPr;
1603 BOPCol_MapIteratorOfMapOfInteger aItMI, aItMI1;
1605 aDT2=2e-7; // the rich criteria
1606 aDScPr=5.e-9; // the creasing criteria
1607 aIC.Bounds(aTC[0], aTC[1], aPC[0], aPC[1]);
1609 aItMI.Initialize(aMV);
1610 for (; aItMI.More(); aItMI.Next()) {
1612 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&myDS->Shape(nV));
1613 aPV=BRep_Tool::Pnt(aV);
1615 for (m=0; m<2; ++m) {
1616 aD2=aPC[m].SquareDistance(aPV);
1617 if (aD2>aDT2) {// no rich
1621 for (n=0; n<2; ++n) {
1622 Handle(Geom_Surface)& aS=(!n)? aS1 : aS2;
1623 aC2D[n]->D0(aTC[m], aP2D);
1625 BOPTools_AlgoTools3D::GetNormalToSurface(aS, u, v, aDN[n]);
1628 aScPr=aDN[0]*aDN[1];
1638 // The intersection curve aIC is vanishing curve (the crease)
1641 PutPaveOnCurve(nV, aD, aNC, aMI, aMVTol);
1643 }//for (jVU=1; jVU=aNbVU; ++jVU) {
1645 //}//if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
1646 //}//if(aType1==GeomAbs_Torus || aType2==GeomAbs_Torus) {
1649 //=======================================================================
1650 //function : GetStickVertices
1652 //=======================================================================
1653 void BOPAlgo_PaveFiller::GetStickVertices(const Standard_Integer nF1,
1654 const Standard_Integer nF2,
1655 BOPCol_MapOfInteger& aMVStick,
1656 BOPCol_MapOfInteger& aMVEF,
1657 BOPCol_MapOfInteger& aMI)
1659 Standard_Integer nS1, nS2, nVNew, aTypeInt, i;
1661 BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV();
1662 BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
1663 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
1664 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
1665 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1667 Standard_Integer aNbLines[5] = {
1668 aVVs.Extent(), aVEs.Extent(), aEEs.Extent(),
1669 aVFs.Extent(), aEFs.Extent()
1671 //collect indices of all shapes from nF1 and nF2.
1673 GetFullShapeMap(nF1, aMI);
1674 GetFullShapeMap(nF2, aMI);
1676 //collect VV, VE, EE, VF interferences
1677 for (aTypeInt = 0; aTypeInt < 4; ++aTypeInt) {
1678 for (i = 0; i < aNbLines[aTypeInt]; ++i) {
1679 BOPDS_Interf* aInt = (aTypeInt==0) ? (BOPDS_Interf*)(&aVVs(i)) :
1680 ((aTypeInt==1) ? (BOPDS_Interf*)(&aVEs(i)) :
1681 ((aTypeInt==2) ? (BOPDS_Interf*)(&aEEs(i)) :
1682 (BOPDS_Interf*)(&aVFs(i))));
1683 if (aInt->HasIndexNew()) {
1684 aInt->Indices(nS1, nS2);
1685 if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
1686 nVNew = aInt->IndexNew();
1687 aMVStick.Add(nVNew);
1692 //collect EF interferences
1693 for (i = 0; i < aNbLines[4]; ++i) {
1694 const BOPDS_InterfEF& aInt = aEFs(i);
1695 if (aInt.HasIndexNew()) {
1696 aInt.Indices(nS1, nS2);
1697 if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
1698 nVNew = aInt.IndexNew();
1699 aMVStick.Add(nVNew);
1706 //=======================================================================
1707 // function: GetFullShapeMap
1709 //=======================================================================
1710 void BOPAlgo_PaveFiller::GetFullShapeMap(const Standard_Integer nF,
1711 BOPCol_MapOfInteger& aMI)
1713 BOPCol_ListIteratorOfListOfInteger aIt;
1714 Standard_Integer nS;
1716 const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(nF);
1717 const BOPCol_ListOfInteger& aLI = aSI.SubShapes();
1720 aIt.Initialize(aLI);
1721 for (; aIt.More(); aIt.Next()) {
1727 //=======================================================================
1728 // function: RemoveUsedVertices
1730 //=======================================================================
1731 void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
1732 BOPCol_MapOfInteger& aMV)
1734 if (!aMV.Extent()) {
1737 Standard_Integer nV;
1739 BOPDS_ListIteratorOfListOfPave aItLP;
1741 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1742 const BOPDS_ListOfPave& aLP = aPB->ExtPaves();
1743 aItLP.Initialize(aLP);
1744 for (;aItLP.More();aItLP.Next()) {
1745 aPave = aItLP.Value();
1751 //=======================================================================
1752 //function : PutPaveOnCurve
1754 //=======================================================================
1755 void BOPAlgo_PaveFiller::PutPaveOnCurve
1756 (const Standard_Integer nV,
1757 const Standard_Real aTolR3D,
1759 const BOPCol_MapOfInteger& aMI,
1760 BOPCol_DataMapOfIntegerReal& aMVTol,
1761 const Standard_Integer iCheckExtend)
1763 Standard_Boolean bIsVertexOnLine;
1764 Standard_Real aT, aTolV;
1766 const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1767 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1768 const IntTools_Curve& aIC = aNC.Curve();
1770 bIsVertexOnLine=myContext->IsVertexOnLine(aV, aIC, aTolR3D, aT);
1771 if (!bIsVertexOnLine && iCheckExtend) {
1772 aTolV = BRep_Tool::Tolerance(aV);
1774 ExtendedTolerance(nV, aMI, aTolV, iCheckExtend);
1775 bIsVertexOnLine=myContext->IsVertexOnLine(aV, aTolV, aIC, aTolR3D, aT);
1778 if (bIsVertexOnLine) {
1779 // check if aPB contains the parameter aT
1780 Standard_Boolean bExist;
1781 Standard_Integer nVToUpdate;
1782 Standard_Real aPTol, aDist, aTolVNew, aTolV2, aDTol;
1783 TopoDS_Vertex aVToUpdate;
1789 GeomAdaptor_Curve aGAC(aIC.Curve());
1790 aPTol = aGAC.Resolution(aTolR3D);
1792 bExist = aPB->ContainsParameter(aT, aPTol, nVToUpdate);
1794 // use existing pave
1795 aP1 = BRep_Tool::Pnt(aV);
1796 aTolV2 = BRep_Tool::Tolerance(aV);
1797 aVToUpdate = (*(TopoDS_Vertex *)(&myDS->Shape(nVToUpdate)));
1803 aPave.SetParameter(aT);
1804 aPB->AppendExtPave(aPave);
1806 aP1 = aGAC.Value(aT);
1811 aTolV = BRep_Tool::Tolerance(aVToUpdate);
1812 aP2 = BRep_Tool::Pnt(aVToUpdate);
1813 aDist = aP1.Distance(aP2);
1814 aTolVNew = aDist - aTolV2;
1816 if (aTolVNew > aTolV) {
1818 aBB.UpdateVertex(aVToUpdate, aTolVNew+aDTol);
1820 if (!aMVTol.IsBound(nVToUpdate)) {
1821 aMVTol.Bind(nVToUpdate, aTolV);
1824 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nVToUpdate);
1825 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
1826 BRepBndLib::Add(aVToUpdate, aBoxDS);
1827 aBoxDS.SetGap(aBoxDS.GetGap() + Precision::Confusion());
1832 //=======================================================================
1833 //function : ProcessOldPaveBlocks
1835 //=======================================================================
1836 void BOPAlgo_PaveFiller::ProcessExistingPaveBlocks
1837 (const Standard_Integer theInt,
1838 const BOPDS_IndexedMapOfPaveBlock& aMPBOnIn,
1839 const BOPCol_DataMapOfIntegerListOfInteger& aDMBV,
1840 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
1841 BOPCol_DataMapOfShapeInteger& aMVI,
1842 BOPDS_MapOfPaveBlock& aMPB)
1844 if (aDMBV.IsEmpty()) {
1848 Standard_Real aT, dummy;
1849 Standard_Integer i, nV, nE, iC, aNbPB, iFlag;
1850 BOPCol_ListIteratorOfListOfInteger aItLI;
1851 BOPCol_DataMapIteratorOfDataMapOfIntegerListOfInteger aItBV;
1853 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
1854 BOPDS_InterfFF& aFF = aFFs(theInt);
1855 BOPDS_VectorOfCurve& aVC = aFF.ChangeCurves();
1857 aNbPB = aMPBOnIn.Extent();
1859 aItBV.Initialize(aDMBV);
1860 for (; aItBV.More(); aItBV.Next()) {
1862 const BOPCol_ListOfInteger& aLBV = aItBV.Value();
1864 BOPDS_Curve& aNC = aVC.ChangeValue(iC);
1865 BOPDS_ListOfPaveBlock& aLPBC = aNC.ChangePaveBlocks();
1867 aItLI.Initialize(aLBV);
1868 for (; aItLI.More(); aItLI.Next()) {
1870 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1871 const Bnd_Box& aBoxV=aSIV.Box();
1872 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&aSIV.Shape();
1873 if (!aMVI.IsBound(aV)) {
1877 for (i = 1; i <= aNbPB; ++i) {
1878 const Handle(BOPDS_PaveBlock)& aPB = aMPBOnIn(i);
1879 if (aPB->Pave1().Index() == nV || aPB->Pave2().Index() == nV) {
1883 if (aMPB.Contains(aPB)) {
1886 if (myDS->ShapeInfo(aPB->OriginalEdge()).HasFlag()) { // skip degenerated edges
1891 const BOPDS_ShapeInfo& aSIE = myDS->ShapeInfo(nE);
1892 const Bnd_Box& aBoxE = aSIE.Box();
1894 if (aBoxV.IsOut(aBoxE)) {
1898 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aSIE.Shape();
1900 iFlag = myContext->ComputeVE(aV, aE, aT, dummy);
1903 PreparePostTreatFF(theInt, iC, aPB, aMSCPB, aMVI, aLPBC);
1909 //=======================================================================
1910 //function : UpdateExistingPaveBlocks
1912 //=======================================================================
1913 void BOPAlgo_PaveFiller::UpdateExistingPaveBlocks
1914 (const Handle(BOPDS_PaveBlock)& aPBf,
1915 BOPDS_ListOfPaveBlock& aLPB,
1916 const Standard_Integer nF1,
1917 const Standard_Integer nF2)
1919 Standard_Integer nE;
1920 Standard_Boolean bCB;
1921 Handle(BOPDS_PaveBlock) aPB, aPB1, aPB2, aPB2n;
1922 Handle(BOPDS_CommonBlock) aCB;
1923 BOPDS_ListIteratorOfListOfPaveBlock aIt, aIt1, aIt2;
1925 // 1. Remove micro edges from aLPB
1926 aIt.Initialize(aLPB);
1927 for (; aIt.More();) {
1929 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
1930 if (BOPTools_AlgoTools::IsMicroEdge(aE, myContext)) {
1937 if (!aLPB.Extent()) {
1941 BOPDS_FaceInfo& aFI1 = myDS->ChangeFaceInfo(nF1);
1942 BOPDS_FaceInfo& aFI2 = myDS->ChangeFaceInfo(nF2);
1944 BOPDS_IndexedMapOfPaveBlock& aMPBOn1 = aFI1.ChangePaveBlocksOn();
1945 BOPDS_IndexedMapOfPaveBlock& aMPBIn1 = aFI1.ChangePaveBlocksIn();
1946 BOPDS_IndexedMapOfPaveBlock& aMPBOn2 = aFI2.ChangePaveBlocksOn();
1947 BOPDS_IndexedMapOfPaveBlock& aMPBIn2 = aFI2.ChangePaveBlocksIn();
1949 // 2. Remove old pave blocks
1950 const Handle(BOPDS_CommonBlock)& aCB1 = myDS->CommonBlock(aPBf);
1951 bCB = !aCB1.IsNull();
1952 BOPDS_ListOfPaveBlock aLPB1;
1955 aLPB1.Assign(aCB1->PaveBlocks());
1959 aIt1.Initialize(aLPB1);
1960 for (; aIt1.More(); aIt1.Next()) {
1961 aPB1 = aIt1.Value();
1962 nE = aPB1->OriginalEdge();
1964 BOPDS_ListOfPaveBlock& aLPB2 = myDS->ChangePaveBlocks(nE);
1965 aIt2.Initialize(aLPB2);
1966 for (; aIt2.More(); aIt2.Next()) {
1967 aPB2 = aIt2.Value();
1975 // 3. Update pave blocks
1977 //create new common blocks
1978 BOPDS_ListOfPaveBlock aLPBNew;
1979 const BOPCol_ListOfInteger& aFaces = aCB1->Faces();
1980 aIt.Initialize(aLPB);
1981 for (; aIt.More(); aIt.Next()) {
1982 const Handle(BOPDS_PaveBlock)& aPBValue = aIt.Value();
1984 aCB = new BOPDS_CommonBlock;
1985 aIt1.Initialize(aLPB1);
1986 for (; aIt1.More(); aIt1.Next()) {
1987 aPB2 = aIt1.Value();
1988 nE = aPB2->OriginalEdge();
1990 aPB2n = new BOPDS_PaveBlock;
1991 aPB2n->SetPave1(aPBValue->Pave1());
1992 aPB2n->SetPave2(aPBValue->Pave2());
1993 aPB2n->SetEdge(aPBValue->Edge());
1994 aPB2n->SetOriginalEdge(nE);
1995 aCB->AddPaveBlock(aPB2n);
1996 myDS->SetCommonBlock(aPB2n, aCB);
1997 myDS->ChangePaveBlocks(nE).Append(aPB2n);
1999 aCB->SetFaces(aFaces);
2000 myDS->SortPaveBlocks(aCB);
2002 const Handle(BOPDS_PaveBlock)& aPBNew = aCB->PaveBlocks().First();
2003 aLPBNew.Append(aPBNew);
2009 nE = aPBf->OriginalEdge();
2010 BOPDS_ListOfPaveBlock& aLPBE = myDS->ChangePaveBlocks(nE);
2011 aIt.Initialize(aLPB);
2012 for (; aIt.More(); aIt.Next()) {
2018 Standard_Boolean bIn1, bIn2;
2020 bIn1 = aMPBOn1.Contains(aPBf) || aMPBIn1.Contains(aPBf);
2021 bIn2 = aMPBOn2.Contains(aPBf) || aMPBIn2.Contains(aPBf);
2027 // 4. Check new pave blocks for coincidence
2028 // with the opposite face.
2029 // In case of coincidence create common blocks
2030 Standard_Integer nF;
2031 Standard_Real aTolE, aTolF;
2033 nF = bIn1 ? nF2 : nF1;
2034 const TopoDS_Face& aF = *(TopoDS_Face*)&myDS->Shape(nF);
2035 BOPDS_IndexedMapOfPaveBlock& aMPBIn = bIn1 ? aMPBIn2 : aMPBIn1;
2036 aTolF = BRep_Tool::Tolerance(aF);
2038 aIt.Initialize(aLPB);
2039 for (; aIt.More(); aIt.Next()) {
2040 Handle(BOPDS_PaveBlock)& aPBChangeValue = aIt.ChangeValue();
2041 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPBChangeValue->Edge());
2042 aTolE = BRep_Tool::Tolerance(aE);
2044 IntTools_EdgeFace anEF;
2047 anEF.SetTolE(aTolE);
2048 anEF.SetTolF(aTolF);
2049 anEF.SetRange(aPBChangeValue->Pave1().Parameter(), aPBChangeValue->Pave2().Parameter());
2050 anEF.SetContext(myContext);
2053 const IntTools_SequenceOfCommonPrts& aCPrts=anEF.CommonParts();
2054 if (aCPrts.Length() == 1) {
2055 Standard_Boolean bCoinc = (aCPrts(1).Type() == TopAbs_EDGE);
2058 aCB = myDS->CommonBlock(aPBChangeValue);
2060 aCB = new BOPDS_CommonBlock;
2061 aCB->AddPaveBlock(aPBChangeValue);
2062 myDS->SetCommonBlock(aPBChangeValue, aCB);
2066 aMPBIn.Add(aPBChangeValue);
2071 //=======================================================================
2072 // function: PutClosingPaveOnCurve
2074 //=======================================================================
2075 void BOPAlgo_PaveFiller::PutClosingPaveOnCurve(BOPDS_Curve& aNC)
2077 Standard_Boolean bIsClosed, bHasBounds, bAdded;
2078 Standard_Integer nVC, j;
2079 Standard_Real aT[2], aTC, dT, aTx;
2082 BOPDS_ListIteratorOfListOfPave aItLP;
2084 const IntTools_Curve& aIC=aNC.Curve();
2085 const Handle(Geom_Curve)& aC3D=aIC.Curve();
2090 bIsClosed=IntTools_Tools::IsClosed(aC3D);
2095 bHasBounds=aIC.HasBounds ();
2100 bAdded=Standard_False;
2101 dT=Precision::PConfusion();
2102 aIC.Bounds (aT[0], aT[1], aP[0], aP[1]);
2104 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
2105 BOPDS_ListOfPave& aLP=aPB->ChangeExtPaves();
2107 aItLP.Initialize(aLP);
2108 for (; aItLP.More() && !bAdded; aItLP.Next()) {
2109 const BOPDS_Pave& aPC=aItLP.Value();
2111 aTC=aPC.Parameter();
2113 for (j=0; j<2; ++j) {
2114 if (fabs(aTC-aT[j]) < dT) {
2115 aTx=(!j) ? aT[1] : aT[0];
2117 aPVx.SetParameter(aTx);
2120 bAdded=Standard_True;
2126 //=======================================================================
2127 //function : PreparePostTreatFF
2129 //=======================================================================
2130 void BOPAlgo_PaveFiller::PreparePostTreatFF
2131 (const Standard_Integer aInt,
2132 const Standard_Integer aCur,
2133 const Handle(BOPDS_PaveBlock)& aPB,
2134 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
2135 BOPCol_DataMapOfShapeInteger& aMVI,
2136 BOPDS_ListOfPaveBlock& aLPBC)
2138 Standard_Integer nV1, nV2;
2142 aPB->Indices(nV1, nV2);
2143 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
2144 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
2145 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
2146 // Keep info for post treatment
2147 BOPDS_CoupleOfPaveBlocks aCPB;
2148 aCPB.SetIndexInterf(aInt);
2149 aCPB.SetIndex(aCur);
2150 aCPB.SetPaveBlock1(aPB);
2152 aMSCPB.Add(aE, aCPB);
2153 aMVI.Bind(aV1, nV1);
2154 aMVI.Bind(aV2, nV2);
2157 //=======================================================================
2158 //function : CheckPlanes
2160 //=======================================================================
2161 Standard_Boolean BOPAlgo_PaveFiller::CheckPlanes
2162 (const Standard_Integer nF1,
2163 const Standard_Integer nF2)const
2165 Standard_Boolean bToIntersect;
2166 Standard_Integer i, nV2, iCnt;
2167 BOPCol_MapIteratorOfMapOfInteger aIt;
2169 bToIntersect=Standard_False;
2171 const BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
2172 const BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
2174 const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
2175 const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
2178 for (i=0; (i<2 && !bToIntersect); ++i) {
2179 const BOPCol_MapOfInteger& aMV2=(!i) ? aFI2.VerticesIn()
2180 : aFI2.VerticesOn();
2182 aIt.Initialize(aMV2);
2183 for (; aIt.More(); aIt.Next()) {
2185 if (aMVIn1.Contains(nV2) || aMVOn1.Contains(nV2)) {
2188 bToIntersect=!bToIntersect;
2195 return bToIntersect;
2197 //=======================================================================
2198 //function : UpdatePaveBlocks
2200 //=======================================================================
2201 void BOPAlgo_PaveFiller::UpdatePaveBlocks
2202 (const BOPCol_DataMapOfIntegerInteger& aDMI)
2204 if (aDMI.IsEmpty()) {
2208 Standard_Integer nSp, aNbPBP, nV[2], i, j;
2209 Standard_Real aT[2];
2210 Standard_Boolean bCB, bRebuild;
2211 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
2212 BOPDS_MapOfPaveBlock aMPB;
2213 BOPCol_MapOfInteger aMicroEdges;
2215 BOPDS_VectorOfListOfPaveBlock& aPBP = myDS->ChangePaveBlocksPool();
2216 aNbPBP = aPBP.Extent();
2217 for (i = 0; i < aNbPBP; ++i) {
2218 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
2220 aItPB.Initialize(aLPB);
2221 for (; aItPB.More(); aItPB.Next()) {
2222 Handle(BOPDS_PaveBlock) aPB = aItPB.Value();
2223 const Handle(BOPDS_CommonBlock)& aCB = myDS->CommonBlock(aPB);
2224 bCB = !aCB.IsNull();
2226 aPB = aCB->PaveBlock1();
2229 if (aMPB.Add(aPB)) {
2230 bRebuild = Standard_False;
2231 aPB->Indices(nV[0], nV[1]);
2232 aPB->Range(aT[0], aT[1]);
2233 // remember the fact if the edge had different vertices before substitution
2234 Standard_Boolean wasRegularEdge = (nV[0] != nV[1]);
2236 for (j = 0; j < 2; ++j) {
2237 if (aDMI.IsBound(nV[j])) {
2240 nV[j] = aDMI.Find(nV[j]);
2241 aPave.SetIndex(nV[j]);
2242 aPave.SetParameter(aT[j]);
2244 bRebuild = Standard_True;
2246 aPB->SetPave1(aPave);
2249 aPB->SetPave2(aPave);
2255 Standard_Boolean isDegEdge = myDS->ShapeInfo(aPB->Edge()).HasFlag();
2256 if (wasRegularEdge && !isDegEdge && nV[0] == nV[1]) {
2257 // now edge has the same vertex on both ends;
2258 // check if it is not a regular closed curve.
2259 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(aPB->Edge()));
2260 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV[0]));
2261 Standard_Real aLength = IntTools::Length(aE);
2262 Standard_Real aTolV = BRep_Tool::Tolerance(aV);
2263 if (aLength <= aTolV * 2.) {
2264 // micro edge, so mark it for removal
2265 aMicroEdges.Add(aPB->Edge());
2269 nSp = SplitEdge(aPB->OriginalEdge(), nV[0], aT[0], nV[1], aT[1]);
2277 }// if (aMPB.Add(aPB)) {
2278 }// for (; aItPB.More(); aItPB.Next()) {
2279 }// for (i=0; i<aNbPBP; ++i) {
2282 if (aMicroEdges.Extent())
2283 RemovePaveBlocks(aMicroEdges);
2285 //=======================================================================
2286 //function : RemovePaveBlocks
2288 //=======================================================================
2289 void BOPAlgo_PaveFiller::RemovePaveBlocks(const BOPCol_MapOfInteger theEdges)
2291 // Remove all pave blocks referring to input edges:
2293 // 1. from the Pave Blocks Pool
2294 BOPDS_VectorOfListOfPaveBlock& aPBP = myDS->ChangePaveBlocksPool();
2295 Standard_Integer aNbPBP = aPBP.Extent(), i;
2296 for (i = 0; i < aNbPBP; ++i) {
2297 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
2299 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
2300 while (aItPB.More()) {
2301 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
2302 if (theEdges.Contains(aPB->Edge()))
2309 // 2. from Face Info and section curves
2310 BOPCol_MapOfInteger aMPassed;
2311 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
2312 Standard_Integer aNbFF = aFFs.Extent(), j;
2313 for (i = 0; i < aNbFF; ++i) {
2314 BOPDS_InterfFF& aFF = aFFs(i);
2315 Standard_Integer nF1, nF2;
2316 aFF.Indices(nF1, nF2);
2318 // rebuild pave block maps of face info
2319 for (j = 0; j < 2; j++) {
2320 Standard_Integer nF = (j == 0 ? nF1 : nF2);
2321 if (!aMPassed.Add(nF))
2323 BOPDS_FaceInfo& aFI = myDS->ChangeFaceInfo(nF);
2324 BOPDS_IndexedMapOfPaveBlock* aIMPB[] = { &aFI.ChangePaveBlocksIn(),
2325 &aFI.ChangePaveBlocksOn(), &aFI.ChangePaveBlocksSc() };
2326 for (Standard_Integer k = 0; k < 3; k++) {
2327 Standard_Integer aNbPB = aIMPB[k]->Extent(), m;
2328 for (m = 1; m <= aNbPB; ++m) {
2329 const Handle(BOPDS_PaveBlock)& aPB = aIMPB[k]->FindKey(m);
2330 if (theEdges.Contains(aPB->Edge()))
2334 BOPDS_IndexedMapOfPaveBlock aMPBCopy = *aIMPB[k];
2336 for (m = 1; m <= aNbPB; ++m) {
2337 const Handle(BOPDS_PaveBlock)& aPB = aMPBCopy(m);
2338 if (!theEdges.Contains(aPB->Edge()))
2344 // remove from Section pave blocks
2345 BOPDS_VectorOfCurve& aVNC = aFF.ChangeCurves();
2346 Standard_Integer aNbC = aVNC.Extent();
2347 for (j = 0; j < aNbC; ++j) {
2348 BOPDS_Curve& aNC = aVNC(j);
2349 BOPDS_ListOfPaveBlock& aLPB = aNC.ChangePaveBlocks();
2350 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
2351 while (aItPB.More()) {
2352 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
2353 if (theEdges.Contains(aPB->Edge()))
2362 //=======================================================================
2363 //function : ToleranceFF
2364 //purpose : Computes the TolFF according to the tolerance value and
2365 // types of the faces.
2366 //=======================================================================
2367 void ToleranceFF(const BRepAdaptor_Surface& aBAS1,
2368 const BRepAdaptor_Surface& aBAS2,
2369 Standard_Real& aTolFF)
2371 Standard_Real aTol1, aTol2;
2372 Standard_Boolean isAna1, isAna2;
2374 aTol1 = aBAS1.Tolerance();
2375 aTol2 = aBAS2.Tolerance();
2376 aTolFF = Max(aTol1, aTol2);
2378 isAna1 = (aBAS1.GetType() == GeomAbs_Plane ||
2379 aBAS1.GetType() == GeomAbs_Cylinder ||
2380 aBAS1.GetType() == GeomAbs_Cone ||
2381 aBAS1.GetType() == GeomAbs_Sphere ||
2382 aBAS1.GetType() == GeomAbs_Torus);
2384 isAna2 = (aBAS2.GetType() == GeomAbs_Plane ||
2385 aBAS2.GetType() == GeomAbs_Cylinder ||
2386 aBAS2.GetType() == GeomAbs_Cone ||
2387 aBAS2.GetType() == GeomAbs_Sphere ||
2388 aBAS2.GetType() == GeomAbs_Torus);
2390 if (!isAna1 || !isAna2) {
2391 aTolFF = Max(aTolFF, 5.e-6);
2394 //=======================================================================
2395 //function : UpdateBlocksWithSharedVertices
2397 //=======================================================================
2398 void BOPAlgo_PaveFiller::UpdateBlocksWithSharedVertices()
2400 if (!myNonDestructive) {
2406 Standard_Integer aNbFF;
2408 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
2409 aNbFF=aFFs.Extent();
2414 Standard_Boolean bOnCurve, bHasShapeSD;
2415 Standard_Integer i, nF1, nF2, aNbC, j, nV, nVSD;
2416 Standard_Real aTolR3D, aTolV;
2417 BOPCol_MapOfInteger aMF;
2419 for (i=0; i<aNbFF; ++i) {
2420 BOPDS_InterfFF& aFF=aFFs(i);
2422 BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
2428 aFF.Indices(nF1, nF2);
2429 aTolR3D=aFF.TolR3D();
2432 myDS->UpdateFaceInfoOn(nF1);
2435 myDS->UpdateFaceInfoOn(nF2);
2438 // Collect old vertices that are shared for nF1, nF2 ->aMI;
2439 BOPCol_MapOfInteger aMI;
2440 BOPCol_MapIteratorOfMapOfInteger aItMI;
2442 BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
2443 BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
2445 const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
2446 const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
2447 const BOPCol_MapOfInteger& aMVOn2=aFI2.VerticesOn();
2448 const BOPCol_MapOfInteger& aMVIn2=aFI2.VerticesIn();
2450 for (j=0; j<2; ++j) {
2451 const BOPCol_MapOfInteger& aMV1=(!j) ? aMVOn1 : aMVIn1;
2452 aItMI.Initialize(aMV1);
2453 for (; aItMI.More(); aItMI.Next()) {
2455 if (myDS->IsNewShape(nV)) {
2458 if (aMVOn2.Contains(nV) || aMVIn2.Contains(nV)) {
2464 // Try to put vertices aMI on curves
2465 for (j=0; j<aNbC; ++j) {
2466 BOPDS_Curve& aNC=aVC.ChangeValue(j);
2467 //const IntTools_Curve& aIC=aNC.Curve();
2469 aItMI.Initialize(aMI);
2470 for (; aItMI.More(); aItMI.Next()) {
2473 bHasShapeSD=myDS->HasShapeSD(nV, nVSD);
2478 bOnCurve=EstimatePaveOnCurve(nV, aNC, aTolR3D);
2483 const TopoDS_Vertex& aV=*((TopoDS_Vertex *)&myDS->Shape(nV));
2484 aTolV=BRep_Tool::Tolerance(aV);
2486 UpdateVertex(nV, aTolV);
2488 }//for (j=0; j<aNbC; ++j) {
2489 }//for (i=0; i<aNbFF; ++i) {
2491 UpdateCommonBlocksWithSDVertices();
2493 //=======================================================================
2494 //function : EstimatePaveOnCurve
2496 //=======================================================================
2497 Standard_Boolean BOPAlgo_PaveFiller::EstimatePaveOnCurve
2498 (const Standard_Integer nV,
2499 const BOPDS_Curve& aNC,
2500 const Standard_Real aTolR3D)
2502 Standard_Boolean bIsVertexOnLine;
2505 const TopoDS_Vertex& aV=*((TopoDS_Vertex *)&myDS->Shape(nV));
2506 const IntTools_Curve& aIC=aNC.Curve();
2508 bIsVertexOnLine=myContext->IsVertexOnLine(aV, aIC, aTolR3D, aT);
2509 return bIsVertexOnLine;
2512 //=======================================================================
2513 //function : CorrectToleranceOfSE
2515 //=======================================================================
2516 void BOPAlgo_PaveFiller::CorrectToleranceOfSE()
2518 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
2519 NCollection_IndexedDataMap<Standard_Integer,BOPDS_ListOfPaveBlock> aMVIPBs;
2521 // iterate on all sections F-F
2522 Standard_Integer aNb = aFFs.Extent(), i;
2523 for (i = 0; i < aNb; ++i) {
2524 const BOPDS_InterfFF& aFF = aFFs(i);
2525 Standard_Real aTolR3D = aFF.TolR3D();
2526 Standard_Real aTolReal = aFF.TolReal();
2527 if (aTolReal < aTolR3D) {
2528 // tolerance of intersection has been increased, so process this intersection
2529 const BOPDS_VectorOfCurve& aVNC = aFF.Curves();
2530 Standard_Integer aNbC = aVNC.Extent(), k;
2531 for (k = 0; k < aNbC; ++k) {
2532 const BOPDS_Curve& aNC = aVNC(k);
2533 const BOPDS_ListOfPaveBlock& aLPB = aNC.PaveBlocks();
2534 BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPB);
2535 for (; aItLPB.More(); aItLPB.Next()) {
2536 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
2537 Standard_Integer nE;
2538 if (!aPB->HasEdge(nE) || aPB->OriginalEdge() >= 0) {
2541 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(nE));
2542 Standard_Real aTolE = BRep_Tool::Tolerance(aE);
2543 if (aTolReal < aTolE) {
2544 // reduce edge tolerance
2545 reinterpret_cast<BRep_TEdge*>(aE.TShape().operator->())->Tolerance(aTolReal);
2548 // fill in the map vertex index - pave blocks
2549 Handle(BOPDS_PaveBlock) aPBR = myDS->RealPaveBlock(aPB);
2550 for (Standard_Integer j=0; j < 2; j++) {
2551 Standard_Integer nV = (j == 0 ? aPBR->Pave1().Index() : aPBR->Pave2().Index());
2552 BOPDS_ListOfPaveBlock *pPBList = aMVIPBs.ChangeSeek(nV);
2554 pPBList = &aMVIPBs.ChangeFromIndex(aMVIPBs.Add(nV, BOPDS_ListOfPaveBlock()));
2556 pPBList->Append(aPBR);
2562 // try to reduce tolerances of connected vertices
2563 aNb = aMVIPBs.Extent();
2564 for (i = 1; i <= aNb; ++i) {
2565 Standard_Integer nV = aMVIPBs.FindKey(i);
2566 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV));
2567 gp_Pnt aP = BRep_Tool::Pnt(aV);
2569 // compute the maximal distance from the vertex to the adjacent edges
2570 Standard_Real aMaxTol = 0.;
2571 const BOPDS_ListOfPaveBlock& aLPB = aMVIPBs.FindFromIndex(i);
2572 BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPB);
2573 for (; aItLPB.More(); aItLPB.Next()) {
2574 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
2575 Standard_Integer nE = aPB->Edge();
2576 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(nE));
2577 const BOPDS_Pave& aPave = (aPB->Pave1().Index() == nV ? aPB->Pave1() : aPB->Pave2());
2578 BRepAdaptor_Curve aC(aE);
2579 gp_Pnt aPonE = aC.Value(aPave.Parameter());
2580 Standard_Real aDist = aP.Distance(aPonE);
2581 aDist += BRep_Tool::Tolerance(aE);
2582 if (aDist > aMaxTol) {
2586 Standard_Real aTolV = BRep_Tool::Tolerance(aV);
2587 if (aMaxTol < aTolV) {
2588 reinterpret_cast<BRep_TVertex*>(aV.TShape().operator->())->Tolerance(aMaxTol);