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.hxx>
19 #include <Bnd_Box.hxx>
20 #include <BOPAlgo_Alerts.hxx>
21 #include <BOPAlgo_SectionAttribute.hxx>
22 #include <BOPAlgo_Tools.hxx>
23 #include <BOPDS_CommonBlock.hxx>
24 #include <BOPDS_CoupleOfPaveBlocks.hxx>
25 #include <BOPDS_Curve.hxx>
26 #include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx>
27 #include <BOPDS_DS.hxx>
28 #include <BOPDS_FaceInfo.hxx>
29 #include <BOPDS_Interf.hxx>
30 #include <BOPDS_Iterator.hxx>
31 #include <BOPDS_ListOfPave.hxx>
32 #include <BOPDS_ListOfPaveBlock.hxx>
33 #include <BOPDS_MapOfPaveBlock.hxx>
34 #include <BOPDS_PaveBlock.hxx>
35 #include <BOPDS_Point.hxx>
36 #include <BOPDS_ShapeInfo.hxx>
37 #include <BOPDS_VectorOfCurve.hxx>
38 #include <BOPDS_VectorOfPoint.hxx>
39 #include <BOPTools_AlgoTools.hxx>
40 #include <BOPTools_AlgoTools3D.hxx>
41 #include <BOPTools_Parallel.hxx>
42 #include <BRep_Builder.hxx>
43 #include <BRep_TEdge.hxx>
44 #include <BRep_Tool.hxx>
45 #include <BRepAdaptor_Curve.hxx>
46 #include <BRepAdaptor_Surface.hxx>
47 #include <BRepBndLib.hxx>
48 #include <BRepBuilderAPI_MakeVertex.hxx>
49 #include <BRepLib.hxx>
50 #include <BRepTools.hxx>
51 #include <Geom_Curve.hxx>
52 #include <Geom2d_Curve.hxx>
53 #include <GeomAPI_ProjectPointOnCurve.hxx>
54 #include <GeomAPI_ProjectPointOnSurf.hxx>
56 #include <IntSurf_ListOfPntOn2S.hxx>
57 #include <IntSurf_PntOn2S.hxx>
58 #include <IntTools.hxx>
59 #include <IntTools_Context.hxx>
60 #include <IntTools_Curve.hxx>
61 #include <IntTools_EdgeFace.hxx>
62 #include <IntTools_FaceFace.hxx>
63 #include <IntTools_PntOn2Faces.hxx>
64 #include <IntTools_SequenceOfCurves.hxx>
65 #include <IntTools_SequenceOfPntOn2Faces.hxx>
66 #include <IntTools_ShrunkRange.hxx>
67 #include <IntTools_Tools.hxx>
68 #include <NCollection_Vector.hxx>
69 #include <Precision.hxx>
70 #include <TColStd_ListOfInteger.hxx>
71 #include <TColStd_MapOfInteger.hxx>
73 #include <TopExp_Explorer.hxx>
75 #include <TopoDS_Compound.hxx>
76 #include <TopoDS_Edge.hxx>
77 #include <TopoDS_Face.hxx>
78 #include <TopoDS_Vertex.hxx>
79 #include <TopTools_DataMapOfShapeInteger.hxx>
80 #include <TopTools_ListOfShape.hxx>
83 static Standard_Real ToleranceFF(const BRepAdaptor_Surface& aBAS1,
84 const BRepAdaptor_Surface& aBAS2);
86 /////////////////////////////////////////////////////////////////////////
87 //=======================================================================
88 //class : BOPAlgo_FaceFace
90 //=======================================================================
91 class BOPAlgo_FaceFace :
92 public IntTools_FaceFace,
101 myIF1(-1), myIF2(-1), myTolFF(1.e-7) {
104 virtual ~BOPAlgo_FaceFace() {
107 void SetIndices(const Standard_Integer nF1,
108 const Standard_Integer nF2) {
113 void Indices(Standard_Integer& nF1,
114 Standard_Integer& nF2) const {
119 void SetFaces(const TopoDS_Face& aF1,
120 const TopoDS_Face& aF2) {
125 const TopoDS_Face& Face1()const {
129 const TopoDS_Face& Face2()const {
133 void SetTolFF(const Standard_Real aTolFF) {
137 Standard_Real TolFF() const{
141 void SetFuzzyValue(const Standard_Real theFuzz) {
142 IntTools_FaceFace::SetFuzzyValue(theFuzz);
145 virtual void Perform() {
146 BOPAlgo_Algo::UserBreak();
151 IntTools_FaceFace::Perform(myF1, myF2);
153 catch (Standard_Failure)
155 AddError(new BOPAlgo_AlertIntersectionFailed);
160 Standard_Integer myIF1;
161 Standard_Integer myIF2;
162 Standard_Real myTolFF;
167 //=======================================================================
168 typedef NCollection_Vector
169 <BOPAlgo_FaceFace> BOPAlgo_VectorOfFaceFace;
171 typedef BOPTools_Functor
173 BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceFunctor;
176 <BOPAlgo_FaceFaceFunctor,
177 BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceCnt;
178 /////////////////////////////////////////////////////////////////////////
179 //=======================================================================
180 //function : PerformFF
182 //=======================================================================
183 void BOPAlgo_PaveFiller::PerformFF()
185 myIterator->Initialize(TopAbs_FACE, TopAbs_FACE);
186 Standard_Integer iSize = myIterator->ExpectedLength();
191 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
192 aFFs.SetIncrement(iSize);
194 // Options for the intersection algorithm
195 Standard_Boolean bApprox = mySectionAttribute.Approximation(),
196 bCompC2D1 = mySectionAttribute.PCurveOnS1(),
197 bCompC2D2 = mySectionAttribute.PCurveOnS2();
198 Standard_Real anApproxTol = 1.e-7;
199 // Post-processing options
200 Standard_Boolean bSplitCurve = Standard_False;
202 // Fence map to store faces with updated FaceInfo structure
203 TColStd_MapOfInteger aMIFence;
204 // Prepare the pairs of faces for intersection
205 BOPAlgo_VectorOfFaceFace aVFaceFace;
206 Standard_Integer nF1, nF2;
208 for (; myIterator->More(); myIterator->Next()) {
209 myIterator->Value(nF1, nF2);
211 // Update/Initialize FaceInfo structure for first face
212 if (myDS->HasFaceInfo(nF1))
214 if (aMIFence.Add(nF1))
216 myDS->UpdateFaceInfoOn(nF1);
217 myDS->UpdateFaceInfoIn(nF1);
220 else if (myDS->HasInterfShapeSubShapes(nF2, nF1))
222 myDS->ChangeFaceInfo(nF1);
226 // Update/Initialize FaceInfo structure for second face
227 if (myDS->HasFaceInfo(nF2))
229 if (aMIFence.Add(nF2))
231 myDS->UpdateFaceInfoOn(nF2);
232 myDS->UpdateFaceInfoIn(nF2);
235 else if (myDS->HasInterfShapeSubShapes(nF1, nF2))
237 myDS->ChangeFaceInfo(nF2);
241 if (myGlue == BOPAlgo_GlueOff)
243 const TopoDS_Face& aF1 = (*(TopoDS_Face *)(&myDS->Shape(nF1)));
244 const TopoDS_Face& aF2 = (*(TopoDS_Face *)(&myDS->Shape(nF2)));
246 const BRepAdaptor_Surface& aBAS1 = myContext->SurfaceAdaptor(aF1);
247 const BRepAdaptor_Surface& aBAS2 = myContext->SurfaceAdaptor(aF2);
248 if (aBAS1.GetType() == GeomAbs_Plane &&
249 aBAS2.GetType() == GeomAbs_Plane) {
250 // Check if the planes are really interfering
251 Standard_Boolean bToIntersect = CheckPlanes(nF1, nF2);
253 BOPDS_InterfFF& aFF = aFFs.Appended();
254 aFF.SetIndices(nF1, nF2);
260 BOPAlgo_FaceFace& aFaceFace=aVFaceFace.Appended();
262 aFaceFace.SetIndices(nF1, nF2);
263 aFaceFace.SetFaces(aF1, aF2);
264 // compute minimal tolerance for the curves
265 Standard_Real aTolFF = ToleranceFF(aBAS1, aBAS2);
266 aFaceFace.SetTolFF(aTolFF);
268 IntSurf_ListOfPntOn2S aListOfPnts;
269 GetEFPnts(nF1, nF2, aListOfPnts);
270 Standard_Integer aNbLP = aListOfPnts.Extent();
272 aFaceFace.SetList(aListOfPnts);
275 aFaceFace.SetParameters(bApprox, bCompC2D1, bCompC2D2, anApproxTol);
276 aFaceFace.SetFuzzyValue(myFuzzyValue);
277 aFaceFace.SetProgressIndicator(myProgressIndicator);
280 // for the Glue mode just add all interferences of that type
281 BOPDS_InterfFF& aFF = aFFs.Appended();
282 aFF.SetIndices(nF1, nF2);
283 aFF.SetTangentFaces(Standard_False);
286 }//for (; myIterator->More(); myIterator->Next()) {
288 //======================================================
289 // Perform intersection
290 BOPAlgo_FaceFaceCnt::Perform(myRunParallel, aVFaceFace);
291 //======================================================
292 // Treatment of the results
293 Standard_Integer k, aNbFaceFace = aVFaceFace.Length();
294 for (k = 0; k < aNbFaceFace; ++k) {
295 BOPAlgo_FaceFace& aFaceFace = aVFaceFace(k);
296 aFaceFace.Indices(nF1, nF2);
297 if (!aFaceFace.IsDone() || aFaceFace.HasErrors()) {
298 BOPDS_InterfFF& aFF = aFFs.Appended();
299 aFF.SetIndices(nF1, nF2);
301 // Warn about failed intersection of faces
302 AddIntersectionFailedWarning(aFaceFace.Face1(), aFaceFace.Face2());
306 Standard_Boolean bTangentFaces = aFaceFace.TangentFaces();
307 Standard_Real aTolFF = aFaceFace.TolFF();
309 aFaceFace.PrepareLines3D(bSplitCurve);
311 const IntTools_SequenceOfCurves& aCvsX = aFaceFace.Lines();
312 const IntTools_SequenceOfPntOn2Faces& aPntsX = aFaceFace.Points();
314 Standard_Integer aNbCurves = aCvsX.Length();
315 Standard_Integer aNbPoints = aPntsX.Length();
317 if (aNbCurves || aNbPoints) {
318 myDS->AddInterf(nF1, nF2);
321 BOPDS_InterfFF& aFF = aFFs.Appended();
322 aFF.SetIndices(nF1, nF2);
323 aFF.SetTangentFaces(bTangentFaces);
324 aFF.Init(aNbCurves, aNbPoints);
327 // Fix bounding box expanding coefficient.
328 Standard_Real aBoxExpandValue = aTolFF;
331 // Modify geometric expanding coefficient by topology value,
332 // since this bounding box used in sharing (vertex or edge).
333 Standard_Real aMaxVertexTol = Max(BRep_Tool::MaxTolerance(aFaceFace.Face1(), TopAbs_VERTEX),
334 BRep_Tool::MaxTolerance(aFaceFace.Face2(), TopAbs_VERTEX));
335 aBoxExpandValue += aMaxVertexTol;
338 BOPDS_VectorOfCurve& aVNC = aFF.ChangeCurves();
339 for (Standard_Integer i = 1; i <= aNbCurves; ++i) {
341 const IntTools_Curve& aIC = aCvsX(i);
342 Standard_Boolean bIsValid = IntTools_Tools::CheckCurve(aIC, aBox);
344 BOPDS_Curve& aNC = aVNC.Appended();
346 // make sure that the bounding box has the maximal gap
347 aBox.Enlarge(aBoxExpandValue);
349 aNC.SetTolerance(Max(aIC.Tolerance(), aTolFF));
354 BOPDS_VectorOfPoint& aVNP = aFF.ChangePoints();
355 for (Standard_Integer i = 1; i <= aNbPoints; ++i) {
356 const IntTools_PntOn2Faces& aPi = aPntsX(i);
357 const gp_Pnt& aP = aPi.P1().Pnt();
359 BOPDS_Point& aNP = aVNP.Appended();
364 //=======================================================================
365 //function : MakeBlocks
367 //=======================================================================
368 void BOPAlgo_PaveFiller::MakeBlocks()
370 if (myGlue != BOPAlgo_GlueOff) {
374 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
375 Standard_Integer aNbFF = aFFs.Length();
380 Standard_Boolean bExist, bValid2D;
381 Standard_Integer i, nF1, nF2, aNbC, aNbP, j;
382 Standard_Integer nV1, nV2;
383 Standard_Real aT1, aT2;
384 Handle(NCollection_BaseAllocator) aAllocator;
385 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
387 Handle(BOPDS_PaveBlock) aPBOut;
389 //-----------------------------------------------------scope f
391 NCollection_BaseAllocator::CommonBaseAllocator();
393 TColStd_ListOfInteger aLSE(aAllocator), aLBV(aAllocator);
394 TColStd_MapOfInteger aMVOnIn(100, aAllocator), aMVCommon(100, aAllocator),
395 aMVStick(100,aAllocator), aMVEF(100, aAllocator),
396 aMI(100, aAllocator), aMVBounds(100, aAllocator);
397 BOPDS_IndexedMapOfPaveBlock aMPBOnIn(100, aAllocator);
398 BOPDS_MapOfPaveBlock aMPBAdd(100, aAllocator), aMPBCommon;
399 BOPDS_ListOfPaveBlock aLPB(aAllocator);
400 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMSCPB(100, aAllocator);
401 TopTools_DataMapOfShapeInteger aMVI(100, aAllocator);
402 BOPDS_DataMapOfPaveBlockListOfPaveBlock aDMExEdges(100, aAllocator);
403 TColStd_DataMapOfIntegerReal aMVTol(100, aAllocator);
404 TColStd_DataMapOfIntegerInteger aDMNewSD(100, aAllocator);
405 TColStd_DataMapOfIntegerListOfInteger aDMVLV;
406 TColStd_DataMapOfIntegerListOfInteger aDMBV(100, aAllocator);
407 TColStd_DataMapIteratorOfDataMapOfIntegerReal aItMV;
408 TopTools_IndexedMapOfShape aMicroEdges(100, aAllocator);
409 TopTools_IndexedMapOfShape aVertsOnRejectedPB;
411 for (i=0; i<aNbFF; ++i) {
415 BOPDS_InterfFF& aFF=aFFs(i);
416 aFF.Indices(nF1, nF2);
418 BOPDS_VectorOfPoint& aVP=aFF.ChangePoints();
420 BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
422 if (!aNbP && !aNbC) {
426 const TopoDS_Face& aF1=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
427 const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
429 Standard_Real aTolFF = Max(BRep_Tool::Tolerance(aF1), BRep_Tool::Tolerance(aF2));
431 BOPDS_FaceInfo& aFI1 = myDS->ChangeFaceInfo(nF1);
432 BOPDS_FaceInfo& aFI2 = myDS->ChangeFaceInfo(nF2);
442 myDS->SubShapesOnIn(nF1, nF2, aMVOnIn, aMVCommon, aMPBOnIn, aMPBCommon);
443 myDS->SharedEdges(nF1, nF2, aLSE, aAllocator);
445 Standard_Boolean bHasRealSectionEdge = Standard_False;
447 for (j=0; j<aNbP; ++j) {
449 BOPDS_CoupleOfPaveBlocks aCPB;
451 BOPDS_Point& aNP=aVP.ChangeValue(j);
452 const gp_Pnt& aP=aNP.Pnt();
454 bExist=IsExistingVertex(aP, aTolFF, aMVOnIn);
456 BOPTools_AlgoTools::MakeNewVertex(aP, aTolFF, aV);
458 aCPB.SetIndexInterf(i);
460 aMSCPB.Add(aV, aCPB);
467 GetStickVertices(nF1, nF2, aMVStick, aMVEF, aMI);
469 for (j = 0; j < aNbC; ++j) {
470 BOPDS_Curve& aNC = aVC.ChangeValue(j);
472 aNC.InitPaveBlock1();
474 // In order to avoid problems connected with
475 // extending tolerance of vertex while putting
476 // (e.g. see "bugs modalg_6 bug26789_1" test case),
477 // all not-common vertices will be checked by
478 // BndBoxes before putting. For common-vertices,
479 // filtering by BndBoxes is not necessary.
480 PutPavesOnCurve(aMVOnIn, aMVCommon, aNC, aMI, aMVEF, aMVTol, aDMVLV);
483 // if some E-F vertex was put on a curve due to large E-F intersection range,
484 // and it also was put on another curve correctly then remove this vertex from
485 // the first curve. Detect such case if the distance to curve exceeds aTolR3D.
486 FilterPavesOnCurves(aVC);
488 for (j = 0; j<aNbC; ++j) {
489 BOPDS_Curve& aNC=aVC.ChangeValue(j);
490 const IntTools_Curve& aIC=aNC.Curve();
492 PutStickPavesOnCurve(aF1, aF2, aMI, aNC, aMVStick, aMVTol, aDMVLV);
495 PutEFPavesOnCurve(aNC, aMI, aMVEF, aMVTol, aDMVLV);
498 if (aIC.HasBounds()) {
501 PutBoundPaveOnCurve(aF1, aF2, aNC, aLBV);
503 if (!aLBV.IsEmpty()) {
505 TColStd_ListIteratorOfListOfInteger aItI(aLBV);
506 for (; aItI.More(); aItI.Next()) {
507 aMVBounds.Add(aItI.Value());
511 }//for (j=0; j<aNbC; ++j) {
513 // Put closing pave if needed
514 for (j=0; j<aNbC; ++j) {
515 BOPDS_Curve& aNC=aVC.ChangeValue(j);
516 PutClosingPaveOnCurve (aNC);
519 // 3. Make section edges
520 for (j=0; j<aNbC; ++j) {
521 BOPDS_Curve& aNC=aVC.ChangeValue(j);
522 const IntTools_Curve& aIC=aNC.Curve();
523 Standard_Real aTolR3D = Max(aNC.Tolerance(), aNC.TangentialTolerance());
525 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
526 Handle(BOPDS_PaveBlock)& aPB1=aNC.ChangePaveBlock1();
529 aPB1->Update(aLPB, Standard_False);
531 aItLPB.Initialize(aLPB);
532 for (; aItLPB.More(); aItLPB.Next()) {
533 Handle(BOPDS_PaveBlock)& aPB=aItLPB.ChangeValue();
534 aPB->Indices(nV1, nV2);
535 aPB->Range (aT1, aT2);
537 if (fabs(aT1 - aT2) < Precision::PConfusion()) {
541 bValid2D=myContext->IsValidBlockForFaces(aT1, aT2, aIC,
547 bExist=IsExistingPaveBlock(aPB, aNC, aLSE);
552 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
553 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
556 BOPTools_AlgoTools::MakeEdge (aIC, aV1, aT1, aV2, aT2, aTolR3D, aES);
558 // check for micro edge
559 if (BOPTools_AlgoTools::IsMicroEdge(aES, myContext, Standard_False)) {
560 // If the section edge is a micro edge, i.e. the whole edge is
561 // covered by the tolerance spheres of its vertices, it will be
562 // passed into post treatment process to fuse its vertices.
563 // The edge itself will not be kept.
564 if (!aMVBounds.Contains(nV1) && !aMVBounds.Contains(nV2)) {
565 aMicroEdges.Add(aES);
566 // keep vertices for post treatment
573 Standard_Real aTolNew;
574 bExist=IsExistingPaveBlock(aPB, aNC, aTolR3D, aMPBOnIn, aMPBCommon, aPBOut, aTolNew);
576 if (!aMPBAdd.Contains(aPBOut)) {
577 Standard_Boolean bInBothFaces = Standard_True;
578 if (!myDS->IsCommonBlock(aPBOut)) {
583 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(nE);
584 aTolE = BRep_Tool::Tolerance(aE);
585 if (aTolNew < aNC.Tolerance())
586 aTolNew = aNC.Tolerance(); // use real tolerance of intersection
587 if (aTolNew > aTolE) {
588 UpdateEdgeTolerance(nE, aTolNew);
590 bInBothFaces = Standard_False;
593 bInBothFaces = (aFI1.PaveBlocksOn().Contains(aPBOut) ||
594 aFI1.PaveBlocksIn().Contains(aPBOut))&&
595 (aFI2.PaveBlocksOn().Contains(aPBOut) ||
596 aFI2.PaveBlocksIn().Contains(aPBOut));
600 PreparePostTreatFF(i, j, aPBOut, aMSCPB, aMVI, aLPBC);
601 // Try fusing the vertices of the existing pave block
602 // with the vertices put on the real section curve (except
603 // for technological vertices, which will be removed)
604 Standard_Integer nVOut1, nVOut2;
605 aPBOut->Indices(nVOut1, nVOut2);
606 if (nV1 != nVOut1 && nV1 != nVOut2 && !aMVBounds.Contains(nV1))
608 aVertsOnRejectedPB.Add(aV1);
610 if (nV2 != nVOut1 && nV2 != nVOut2 && !aMVBounds.Contains(nV2))
612 aVertsOnRejectedPB.Add(aV2);
620 BOPTools_AlgoTools::MakePCurve(aES, aF1, aF2, aIC,
621 mySectionAttribute.PCurveOnS1(),
622 mySectionAttribute.PCurveOnS2(),
625 // Append the Pave Block to the Curve j
628 // Keep info for post treatment
629 BOPDS_CoupleOfPaveBlocks aCPB;
630 aCPB.SetIndexInterf(i);
632 aCPB.SetPaveBlock1(aPB);
634 aMSCPB.Add(aES, aCPB);
641 bHasRealSectionEdge = Standard_True;
645 }//for (j=0; j<aNbC; ++j) {
647 //back to previous tolerance values for unused vertices
648 //and forget about SD groups of such vertices
649 aItMV.Initialize(aMVTol);
650 for (; aItMV.More(); aItMV.Next()) {
652 Standard_Real aTol = aItMV.Value();
654 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV1);
655 const Handle(BRep_TVertex)& TV =
656 *((Handle(BRep_TVertex)*)&aV.TShape());
659 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV1);
660 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
662 BRepBndLib::Add(aV, aBoxDS);
663 aBoxDS.SetGap(aBoxDS.GetGap() + Precision::Confusion());
665 if (aDMVLV.IsBound(nV1))
669 ProcessExistingPaveBlocks(i, aMPBOnIn, aDMBV, aMSCPB, aMVI, aMPBAdd);
671 // If the pair of faces has produced any real section edges
672 // it is necessary to check if these edges do not intersect
673 // any common IN edges of the faces. For that, all such edges
674 // are added for Post Treatment along with sections edges.
675 if (bHasRealSectionEdge) {
676 const BOPDS_IndexedMapOfPaveBlock& aMPBIn1 = aFI1.PaveBlocksIn();
677 const BOPDS_IndexedMapOfPaveBlock& aMPBIn2 = aFI2.PaveBlocksIn();
679 // For simplicity add all IN edges into the first set of section curves.
680 // These existing edges will be removed from the set on the post treatment
681 // stage in the UpdateFaceInfo function.
682 BOPDS_ListOfPaveBlock& aLPBC = aVC.ChangeValue(0).ChangePaveBlocks();
684 Standard_Integer aNbIn1 = aMPBIn1.Extent();
685 for (j = 1; j <= aNbIn1; ++j) {
686 const Handle(BOPDS_PaveBlock)& aPB = aMPBIn1(j);
687 if (aMPBIn2.Contains(aPB) && aMPBAdd.Add(aPB)) {
688 PreparePostTreatFF(i, 0, aPB, aMSCPB, aMVI, aLPBC);
692 }//for (i=0; i<aNbFF; ++i) {
695 MakeSDVerticesFF(aDMVLV, aDMNewSD);
696 PostTreatFF(aMSCPB, aDMExEdges, aDMNewSD, aMicroEdges, aVertsOnRejectedPB, aAllocator);
700 // reduce tolerances of section edges where it is appropriate
701 CorrectToleranceOfSE();
704 UpdateFaceInfo(aDMExEdges, aDMNewSD);
705 //Update all pave blocks
706 UpdatePaveBlocks(aDMNewSD);
708 // Treat possible common zones by trying to put each section edge
709 // into all faces, not participated in creation of that edge, as IN edge
712 //-----------------------------------------------------scope t
722 //=======================================================================
723 //function : MakeSDVerticesFF
725 //=======================================================================
726 void BOPAlgo_PaveFiller::MakeSDVerticesFF
727 (const TColStd_DataMapOfIntegerListOfInteger& theDMVLV,
728 TColStd_DataMapOfIntegerInteger& theDMNewSD)
730 // Create a new SD vertex for each group of coinciding vertices
731 // and put new substitutions to theDMNewSD.
732 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItG(theDMVLV);
733 for (; aItG.More(); aItG.Next()) {
734 const TColStd_ListOfInteger& aList = aItG.Value();
735 // make SD vertices w/o creation of interfs
736 Standard_Integer nSD = MakeSDVertices(aList, Standard_False);
738 TColStd_ListIteratorOfListOfInteger aItL(aList);
739 for (; aItL.More(); aItL.Next()) {
740 Standard_Integer nV = aItL.Value();
741 theDMNewSD.Bind(nV, nSD);
746 //=======================================================================
747 //function : PostTreatFF
749 //=======================================================================
750 void BOPAlgo_PaveFiller::PostTreatFF
751 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMSCPB,
752 BOPDS_DataMapOfPaveBlockListOfPaveBlock& aDMExEdges,
753 TColStd_DataMapOfIntegerInteger& aDMNewSD,
754 const TopTools_IndexedMapOfShape& theMicroEdges,
755 const TopTools_IndexedMapOfShape& theVertsOnRejectedPB,
756 const Handle(NCollection_BaseAllocator)& theAllocator)
758 Standard_Integer aNbS = theMSCPB.Extent();
763 Standard_Boolean bHasPaveBlocks, bOld;
764 Standard_Integer nSx, nVSD, iX, iP, iC, j, nV, iV = 0, iE, k;
765 Standard_Integer aNbLPBx;
766 TopAbs_ShapeEnum aType;
768 TopTools_ListIteratorOfListOfShape aItLS;
769 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
771 Handle(BOPDS_PaveBlock) aPB1;
775 TopTools_ListOfShape aLS(theAllocator);
776 BOPAlgo_PaveFiller aPF(theAllocator);
777 aPF.SetIsPrimary(Standard_False);
778 aPF.SetNonDestructive(myNonDestructive);
780 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
782 Standard_Integer aNbME = theMicroEdges.Extent();
783 Standard_Integer aNbVOnRPB = theVertsOnRejectedPB.Extent();
785 if (aNbS==1 && (aNbME == 0) && (aNbVOnRPB == 0)) {
786 const TopoDS_Shape& aS=theMSCPB.FindKey(1);
787 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromIndex(1);
789 aType=aS.ShapeType();
790 if (aType==TopAbs_VERTEX) {
791 aSI.SetShapeType(aType);
793 iV=myDS->Append(aSI);
795 iX=aCPB.IndexInterf();
797 BOPDS_InterfFF& aFF=aFFs(iX);
798 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
799 BOPDS_Point& aNP=aVNP(iP);
802 else if (aType==TopAbs_EDGE) {
803 aPB1=aCPB.PaveBlock1();
805 if (aPB1->HasEdge()) {
806 BOPDS_ListOfPaveBlock aLPBx;
808 aDMExEdges.Bind(aPB1, aLPBx);
810 aSI.SetShapeType(aType);
812 iE=myDS->Append(aSI);
820 // 1 prepare arguments
821 TopTools_MapOfShape anAddedSD;
822 for (k=1; k<=aNbS; ++k) {
823 const TopoDS_Shape& aS=theMSCPB.FindKey(k);
825 // add vertices-candidates for SD from the map aDMNewSD,
826 // so that they took part in fuse operation.
827 TopoDS_Iterator itV(aS);
828 for (; itV.More(); itV.Next())
830 const TopoDS_Shape& aVer = itV.Value();
831 Standard_Integer iVer = myDS->Index(aVer);
832 const Standard_Integer* pSD = aDMNewSD.Seek(iVer);
835 const TopoDS_Shape& aVSD = myDS->Shape(*pSD);
836 if (anAddedSD.Add(aVSD))
842 // The section edges considered as a micro should be
843 // specially treated - their vertices should be united and
844 // the edge itself should be removed. Thus, we add only
845 // its vertices into operation.
848 for (k = 1; k <= aNbME; ++k) {
849 const TopoDS_Edge& aEM = TopoDS::Edge(theMicroEdges(k));
851 TopoDS_Vertex aVerts[2];
852 TopExp::Vertices(aEM, aVerts[0], aVerts[1]);
853 for (Standard_Integer i = 0; i < 2; ++i) {
854 nV = myDS->Index(aVerts[i]);
855 const Standard_Integer* pSD = aDMNewSD.Seek(nV);
857 aVerts[i] = TopoDS::Vertex(myDS->Shape(*pSD));
860 if (anAddedSD.Add(aVerts[i])) {
861 aLS.Append(aVerts[i]);
865 if (aVerts[0].IsSame(aVerts[1])) {
869 // make sure these vertices will be united
870 const gp_Pnt& aP1 = BRep_Tool::Pnt(aVerts[0]);
871 const gp_Pnt& aP2 = BRep_Tool::Pnt(aVerts[1]);
873 Standard_Real aDist = aP1.Distance(aP2);
874 Standard_Real aTolV1 = BRep_Tool::Tolerance(aVerts[0]);
875 Standard_Real aTolV2 = BRep_Tool::Tolerance(aVerts[1]);
877 aDist -= (aTolV1 + aTolV2);
880 aBB.UpdateVertex(aVerts[0], aTolV1 + aDist);
881 aBB.UpdateVertex(aVerts[1], aTolV2 + aDist);
885 // Add vertices put on the real section curves to unify them with the
886 // vertices of the edges, by which these sections curves have been rejected
887 for (Standard_Integer i = 1; i <= aNbVOnRPB; ++i)
889 TopoDS_Shape aVer = theVertsOnRejectedPB(i);
890 Standard_Integer iVer = myDS->Index(aVer);
891 const Standard_Integer* pSD = aDMNewSD.Seek(iVer);
893 aVer = myDS->Shape(*pSD);
895 if (anAddedSD.Add(aVer))
900 aPF.SetProgressIndicator(myProgressIndicator);
901 aPF.SetRunParallel(myRunParallel);
902 aPF.SetArguments(aLS);
904 if (aPF.HasErrors()) {
905 AddError (new BOPAlgo_AlertPostTreatFF);
910 // Map to store the real tolerance of the common block
911 // and avoid repeated computation of it
912 NCollection_DataMap<Handle(BOPDS_CommonBlock),
914 TColStd_MapTransientHasher> aMCBTol;
915 // Map to avoid creation of different pave blocks for
916 // the same intersection edge
917 NCollection_DataMap<Standard_Integer, Handle(BOPDS_PaveBlock)> aMEPB;
919 aItLS.Initialize(aLS);
920 for (; aItLS.More(); aItLS.Next()) {
921 const TopoDS_Shape& aSx=aItLS.Value();
922 nSx=aPDS->Index(aSx);
923 const BOPDS_ShapeInfo& aSIx=aPDS->ShapeInfo(nSx);
925 aType=aSIx.ShapeType();
927 if (aType==TopAbs_VERTEX) {
928 Standard_Boolean bIntersectionPoint = theMSCPB.Contains(aSx);
930 if (aPDS->HasShapeSD(nSx, nVSD)) {
931 aV=aPDS->Shape(nVSD);
936 // index of new vertex in theDS -> iV
937 iV = myDS->Index(aV);
939 aSI.SetShapeType(aType);
941 iV=myDS->Append(aSI);
944 if (!bIntersectionPoint) {
945 // save SD connection
946 nSx = myDS->Index(aSx);
947 aDMNewSD.Bind(nSx, iV);
948 myDS->AddShapeSD(nSx, iV);
951 // update FF interference
952 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx);
953 iX=aCPB.IndexInterf();
955 BOPDS_InterfFF& aFF=aFFs(iX);
956 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
957 BOPDS_Point& aNP=aVNP(iP);
960 }//if (aType==TopAbs_VERTEX) {
962 else if (aType==TopAbs_EDGE) {
963 bHasPaveBlocks=aPDS->HasPaveBlocks(nSx);
964 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx);
965 iX=aCPB.IndexInterf();
967 aPB1=aCPB.PaveBlock1();
969 bOld = aPB1->HasEdge();
971 BOPDS_ListOfPaveBlock aLPBx;
972 aDMExEdges.Bind(aPB1, aLPBx);
975 if (!bHasPaveBlocks) {
977 aDMExEdges.ChangeFind(aPB1).Append(aPB1);
980 aSI.SetShapeType(aType);
982 iE = myDS->Append(aSI);
988 BOPDS_InterfFF& aFF=aFFs(iX);
989 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
990 BOPDS_Curve& aNC=aVNC(iC);
991 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
993 // check if edge occured to be micro edge;
994 // note we check not the edge aSx itself, but its image in aPDS
995 const BOPDS_ListOfPaveBlock& aLPBx = aPDS->PaveBlocks(nSx);
996 aNbLPBx = aLPBx.Extent();
997 if (aPDS->HasPaveBlocks(nSx) &&
998 (aNbLPBx == 0 || (aNbLPBx == 1 && !aLPBx.First()->HasShrunkData()))) {
999 BOPDS_ListIteratorOfListOfPaveBlock it(aLPBC);
1000 for (; it.More(); it.Next()) {
1001 if (it.Value() == aPB1) {
1009 if (bOld && !aNbLPBx) {
1010 aDMExEdges.ChangeFind(aPB1).Append(aPB1);
1015 aItLPB.Initialize(aLPBC);
1016 for (; aItLPB.More(); aItLPB.Next()) {
1017 const Handle(BOPDS_PaveBlock)& aPBC=aItLPB.Value();
1019 aLPBC.Remove(aItLPB);
1026 aItLPB.Initialize(aLPBx);
1027 for (; aItLPB.More(); aItLPB.Next()) {
1028 const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value();
1029 const Handle(BOPDS_PaveBlock) aPBRx=aPDS->RealPaveBlock(aPBx);
1031 // update vertices of paves
1032 aPave[0] = aPBx->Pave1();
1033 aPave[1] = aPBx->Pave2();
1034 for (j=0; j<2; ++j) {
1035 nV = aPave[j].Index();
1036 aV = aPDS->Shape(nV);
1037 // index of new vertex in myDS -> iV
1038 iV = myDS->Index(aV);
1040 aSI.SetShapeType(TopAbs_VERTEX);
1042 iV = myDS->Append(aSI);
1044 const BOPDS_Pave& aP1 = !j ? aPB1->Pave1() : aPB1->Pave2();
1045 if (aP1.Index() != iV) {
1046 if (aP1.Parameter() == aPave[j].Parameter()) {
1047 aDMNewSD.Bind(aP1.Index(), iV);
1048 myDS->AddShapeSD(aP1.Index(), iV);
1051 // check aPDS to have the SD connection between these vertices
1052 const TopoDS_Shape& aVPave = myDS->Shape(aP1.Index());
1053 Standard_Integer nVnewSD, nVnew = aPDS->Index(aVPave);
1054 if (aPDS->HasShapeSD(nVnew, nVnewSD)) {
1055 if (nVnewSD == nV) {
1056 aDMNewSD.Bind(aP1.Index(), iV);
1057 myDS->AddShapeSD(aP1.Index(), iV);
1063 aPave[j].SetIndex(iV);
1067 aE=aPDS->Shape(aPBRx->Edge());
1068 iE = myDS->Index(aE);
1070 aSI.SetShapeType(aType);
1072 iE=myDS->Append(aSI);
1075 // update real edge tolerance according to distances in common block if any
1076 if (aPDS->IsCommonBlock(aPBRx)) {
1077 const Handle(BOPDS_CommonBlock)& aCB = aPDS->CommonBlock(aPBRx);
1078 Standard_Real *pTol = aMCBTol.ChangeSeek(aCB);
1080 Standard_Real aTol = BOPAlgo_Tools::ComputeToleranceOfCB(aCB, aPDS, aPF.Context());
1081 pTol = aMCBTol.Bound(aCB, aTol);
1084 if (aNC.Tolerance() < *pTol) {
1085 aNC.SetTolerance(*pTol);
1088 // append new PaveBlock to aLPBC
1089 Handle(BOPDS_PaveBlock) *pPBC = aMEPB.ChangeSeek(iE);
1091 pPBC = aMEPB.Bound(iE, new BOPDS_PaveBlock());
1092 BOPDS_Pave aPaveR1, aPaveR2;
1093 aPaveR1 = aPBRx->Pave1();
1094 aPaveR2 = aPBRx->Pave2();
1095 aPaveR1.SetIndex(myDS->Index(aPDS->Shape(aPaveR1.Index())));
1096 aPaveR2.SetIndex(myDS->Index(aPDS->Shape(aPaveR2.Index())));
1098 (*pPBC)->SetPave1(aPaveR1);
1099 (*pPBC)->SetPave2(aPaveR2);
1100 (*pPBC)->SetEdge(iE);
1104 (*pPBC)->SetOriginalEdge(aPB1->OriginalEdge());
1105 aDMExEdges.ChangeFind(aPB1).Append(*pPBC);
1108 aLPBC.Append(*pPBC);
1113 }//else if (aType==TopAbs_EDGE)
1114 }//for (; aItLS.More(); aItLS.Next()) {
1116 // Update SD for vertices that did not participate in operation
1117 TColStd_DataMapOfIntegerInteger::Iterator itDM(aDMNewSD);
1118 for (; itDM.More(); itDM.Next())
1120 const Standard_Integer* pSD = aDMNewSD.Seek(itDM.Value());
1123 itDM.ChangeValue() = *pSD;
1124 myDS->AddShapeSD(itDM.Key(), *pSD);
1130 //=======================================================================
1131 //function : UpdateFaceInfo
1133 //=======================================================================
1134 void BOPAlgo_PaveFiller::UpdateFaceInfo
1135 (BOPDS_DataMapOfPaveBlockListOfPaveBlock& theDME,
1136 const TColStd_DataMapOfIntegerInteger& theDMV)
1138 Standard_Integer i, j, nV1, nF1, nF2,
1140 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
1141 TColStd_MapOfInteger aMF;
1143 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
1144 aNbFF=aFFs.Length();
1146 //1. Sections (curves, points);
1147 for (i=0; i<aNbFF; ++i) {
1148 BOPDS_InterfFF& aFF=aFFs(i);
1149 aFF.Indices(nF1, nF2);
1151 BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
1152 BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
1154 // 1.1. Section edges
1155 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
1157 for (j=0; j<aNbC; ++j) {
1158 BOPDS_Curve& aNC=aVNC(j);
1159 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
1161 // Add section edges to face info
1162 aItLPB.Initialize(aLPBC);
1163 for (; aItLPB.More(); ) {
1164 const Handle(BOPDS_PaveBlock)& aPB=aItLPB.Value();
1166 // Treat existing pave blocks
1167 if (theDME.IsBound(aPB)) {
1168 BOPDS_ListOfPaveBlock& aLPB=theDME.ChangeFind(aPB);
1169 UpdateExistingPaveBlocks(aPB, aLPB, nF1, nF2);
1170 aLPBC.Remove(aItLPB);
1174 aFI1.ChangePaveBlocksSc().Add(aPB);
1175 aFI2.ChangePaveBlocksSc().Add(aPB);
1180 // 1.2. Section vertices
1181 const BOPDS_VectorOfPoint& aVNP=aFF.Points();
1183 for (j=0; j<aNbP; ++j) {
1184 const BOPDS_Point& aNP=aVNP(j);
1189 aFI1.ChangeVerticesSc().Add(nV1);
1190 aFI2.ChangeVerticesSc().Add(nV1);
1197 Standard_Boolean bVerts, bEdges;
1199 bVerts = theDMV.Extent() > 0;
1200 bEdges = theDME.Extent() > 0;
1202 if (!bVerts && !bEdges) {
1206 // 2. Update Face Info information with new vertices and new
1207 // pave blocks created in PostTreatFF from existing ones
1208 Standard_Integer nV2, aNbPB;
1209 TColStd_MapIteratorOfMapOfInteger aItMF;
1210 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aItMV;
1212 aItMF.Initialize(aMF);
1213 for (; aItMF.More(); aItMF.Next()) {
1214 nF1 = aItMF.Value();
1216 BOPDS_FaceInfo& aFI = myDS->ChangeFaceInfo(nF1);
1218 // 2.1. Update information about vertices
1220 TColStd_MapOfInteger& aMVOn = aFI.ChangeVerticesOn();
1221 TColStd_MapOfInteger& aMVIn = aFI.ChangeVerticesIn();
1223 aItMV.Initialize(theDMV);
1224 for (; aItMV.More(); aItMV.Next()) {
1226 nV2 = aItMV.Value();
1228 if (aMVOn.Remove(nV1)) {
1232 if (aMVIn.Remove(nV1)) {
1235 } // for (; aItMV.More(); aItMV.Next()) {
1238 // 2.2. Update information about pave blocks
1240 BOPDS_IndexedMapOfPaveBlock& aMPBOn = aFI.ChangePaveBlocksOn();
1241 BOPDS_IndexedMapOfPaveBlock& aMPBIn = aFI.ChangePaveBlocksIn();
1243 BOPDS_IndexedMapOfPaveBlock aMPBCopy;
1244 for (i = 0; i < 2; ++i) {
1245 BOPDS_IndexedMapOfPaveBlock& aMPBOnIn = !i ? aMPBOn : aMPBIn;
1246 aMPBCopy = aMPBOnIn;
1249 aNbPB = aMPBCopy.Extent();
1250 for (j = 1; j <= aNbPB; ++j) {
1251 const Handle(BOPDS_PaveBlock)& aPB = aMPBCopy(j);
1252 if (theDME.IsBound(aPB)) {
1253 const BOPDS_ListOfPaveBlock& aLPB = theDME.Find(aPB);
1254 if (aLPB.IsEmpty()) {
1259 aItLPB.Initialize(aLPB);
1260 for (; aItLPB.More(); aItLPB.Next()) {
1261 const Handle(BOPDS_PaveBlock)& aPB1 = aItLPB.Value();
1268 } // for (j = 1; j <= aNbPB; ++j) {
1269 } // for (i = 0; i < 2; ++i) {
1273 //=======================================================================
1274 //function : IsExistingVertex
1276 //=======================================================================
1277 Standard_Boolean BOPAlgo_PaveFiller::IsExistingVertex
1279 const Standard_Real theTolR3D,
1280 const TColStd_MapOfInteger& aMVOnIn)const
1282 Standard_Boolean bRet;
1283 Standard_Integer nV, iFlag;
1284 Standard_Real aTolCheck;
1287 TColStd_MapIteratorOfMapOfInteger aIt;
1289 aTolCheck = theTolR3D + myFuzzyValue;
1293 aBoxP.Enlarge(theTolR3D);
1295 aIt.Initialize(aMVOnIn);
1296 for (; aIt.More(); aIt.Next()) {
1298 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1299 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&aSIV.Shape()));
1300 const Bnd_Box& aBoxV=aSIV.Box();
1302 if (!aBoxP.IsOut(aBoxV)) {
1303 iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP, aTolCheck);
1311 //=======================================================================
1312 //function : IsExistingPaveBlock
1314 //=======================================================================
1315 Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock
1316 (const Handle(BOPDS_PaveBlock)& thePB,
1317 const BOPDS_Curve& theNC,
1318 const TColStd_ListOfInteger& theLSE)
1320 Standard_Boolean bRet=Standard_True;
1322 if (theLSE.IsEmpty()) {
1326 Standard_Real aT1, aT2, aTm, aTx, aTolE, aTolCheck, aTol, aDist;
1327 Standard_Integer nE, iFlag, nV1, nV2;
1330 TColStd_ListIteratorOfListOfInteger aItLI;
1332 thePB->Range(aT1, aT2);
1333 thePB->Indices(nV1, nV2);
1334 const TopoDS_Vertex &aV1 = TopoDS::Vertex(myDS->Shape(nV1)),
1335 &aV2 = TopoDS::Vertex(myDS->Shape(nV2));
1336 const Standard_Real aTolV1 = BRep_Tool::Tolerance(aV1),
1337 aTolV2 = BRep_Tool::Tolerance(aV2);
1339 aTol = Max(aTolV1, aTolV2);
1341 aTm=IntTools_Tools::IntermediatePoint (aT1, aT2);
1342 theNC.Curve().D0(aTm, aPm);
1344 aBoxPm.Enlarge(aTol);
1346 aItLI.Initialize(theLSE);
1347 for (; aItLI.More(); aItLI.Next()) {
1351 const BOPDS_ShapeInfo& aSIE=myDS->ChangeShapeInfo(nE);
1352 const Bnd_Box& aBoxE=aSIE.Box();
1353 if (!aBoxE.IsOut(aBoxPm)) {
1354 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape()));
1355 aTolE = BRep_Tool::Tolerance(aE);
1356 aTolCheck = Max(aTolE, aTol) + myFuzzyValue;
1357 iFlag = myContext->ComputePE(aPm, aTolCheck, aE, aTx, aDist);
1360 // Update tolerance of the edge
1361 UpdateEdgeTolerance(nE, aDist);
1369 //=======================================================================
1370 //function : IsExistingPaveBlock
1372 //=======================================================================
1373 Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock
1374 (const Handle(BOPDS_PaveBlock)& thePB,
1375 const BOPDS_Curve& theNC,
1376 const Standard_Real theTolR3D,
1377 const BOPDS_IndexedMapOfPaveBlock& theMPBOnIn,
1378 const BOPDS_MapOfPaveBlock& theMPBCommon,
1379 Handle(BOPDS_PaveBlock)& aPBOut,
1380 Standard_Real& theTolNew)
1382 Standard_Boolean bRet;
1383 Standard_Real aT1, aT2, aTm, aTx, aTolCheck;
1384 Standard_Integer nSp, iFlag1, iFlag2, nV11, nV12, nV21, nV22, i, aNbPB;
1385 gp_Pnt aP1, aPm, aP2;
1386 Bnd_Box aBoxP1, aBoxPm, aBoxP2, aBoxTmp;
1388 bRet=Standard_False;
1389 aTolCheck = theTolR3D + myFuzzyValue;
1390 const IntTools_Curve& aIC=theNC.Curve();
1392 thePB->Range(aT1, aT2);
1393 thePB->Indices(nV11, nV12);
1394 const Standard_Real aTolV11 = BRep_Tool::Tolerance(TopoDS::Vertex(myDS->Shape(nV11)));
1395 const Standard_Real aTolV12 = BRep_Tool::Tolerance(TopoDS::Vertex(myDS->Shape(nV12)));
1396 const Standard_Real aTolV1 = Max(aTolV11, aTolV12) + myFuzzyValue;
1401 aBoxP1.Enlarge(aTolV11);
1402 //intermediate point
1403 aTm=IntTools_Tools::IntermediatePoint (aT1, aT2);
1409 aBoxP2.Enlarge(aTolV12);
1412 aNbPB = theMPBOnIn.Extent();
1413 for (i = 1; i <= aNbPB; ++i) {
1414 const Handle(BOPDS_PaveBlock)& aPB = theMPBOnIn(i);
1415 aPB->Indices(nV21, nV22);
1416 const Standard_Real aTolV21 = BRep_Tool::Tolerance(TopoDS::Vertex(myDS->Shape(nV21)));
1417 const Standard_Real aTolV22 = BRep_Tool::Tolerance(TopoDS::Vertex(myDS->Shape(nV22)));
1418 const Standard_Real aTolV2 = Max(aTolV21, aTolV22) + myFuzzyValue;
1422 const BOPDS_ShapeInfo& aSISp=myDS->ChangeShapeInfo(nSp);
1423 const TopoDS_Edge& aSp=(*(TopoDS_Edge *)(&aSISp.Shape()));
1424 const Bnd_Box& aBoxSp=aSISp.Box();
1426 iFlag1 = (nV11 == nV21 || nV11 == nV22) ? 2 :
1427 (!aBoxSp.IsOut(aBoxP1) ? 1 : 0);
1428 iFlag2 = (nV12 == nV21 || nV12 == nV22) ? 2 :
1429 (!aBoxSp.IsOut(aBoxP2) ? 1 : 0);
1430 if (iFlag1 && iFlag2) {
1431 Standard_Real aDist = 0.;
1433 Standard_Real aRealTol = aTolCheck;
1434 if (myDS->IsCommonBlock(aPB))
1436 aRealTol = Max(aRealTol, Max(aTolV1, aTolV2));
1437 if (theMPBCommon.Contains(aPB))
1438 // for an edge, which is a common block with a face,
1439 // increase the chance to coincide with section curve
1444 aBoxTmp.Enlarge(aRealTol);
1446 if (aBoxSp.IsOut(aBoxTmp) || myContext->ComputePE(aPm,
1454 iFlag1 = !myContext->ComputePE(aP1, aRealTol, aSp, aTx, aDist);
1455 if (iFlag1 && theTolNew < aDist)
1460 iFlag2 = !myContext->ComputePE(aP2, aRealTol, aSp, aTx, aDist);
1461 if (iFlag2 && theTolNew < aDist)
1465 if (iFlag1 && iFlag2) {
1474 //=======================================================================
1475 //function : PutBoundPaveOnCurve
1477 //=======================================================================
1478 void BOPAlgo_PaveFiller::PutBoundPaveOnCurve(const TopoDS_Face& aF1,
1479 const TopoDS_Face& aF2,
1481 TColStd_ListOfInteger& aLVB)
1483 Standard_Boolean bVF;
1484 Standard_Integer nV, iFlag, nVn, j, aNbEP;
1485 Standard_Real aT[2], aTmin, aTmax, aTV, aTol, aTolVnew;
1488 BOPDS_ListIteratorOfListOfPave aItLP;
1489 BOPDS_Pave aPn, aPMM[2];
1491 aTolVnew = Precision::Confusion();
1493 const IntTools_Curve& aIC=aNC.Curve();
1494 aIC.Bounds(aT[0], aT[1], aP[0], aP[1]);
1495 Standard_Real aTolR3D = Max(aNC.Tolerance(), aNC.TangentialTolerance());
1497 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1498 const BOPDS_ListOfPave& aLP=aPB->ExtPaves();
1505 aItLP.Initialize(aLP);
1506 for (; aItLP.More(); aItLP.Next()) {
1507 const BOPDS_Pave& aPv=aItLP.Value();
1508 aPv.Contents(nV, aTV);
1520 for (j=0; j<2; ++j) {
1521 //if curve is closed, process only one bound
1522 if (j && aP[1].IsEqual(aP[0], aTolVnew)) {
1532 aTol = aTolR3D+Precision::Confusion();
1533 aBoxP.Enlarge(aTol);
1534 const BOPDS_Pave& aPV=aPMM[j];
1536 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1537 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&aSIV.Shape()));
1538 const Bnd_Box& aBoxV=aSIV.Box();
1539 if (!aBoxP.IsOut(aBoxV)){
1540 iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP[j], aTol);
1545 bVF=myContext->IsValidPointForFaces (aP[j], aF1, aF2, aTolR3D);
1550 BOPDS_ShapeInfo aSIVn;
1552 BOPTools_AlgoTools::MakeNewVertex(aP[j], aTolR3D, aVn);
1553 aSIVn.SetShapeType(TopAbs_VERTEX);
1554 aSIVn.SetShape(aVn);
1556 nVn=myDS->Append(aSIVn);
1559 aPn.SetParameter(aT[j]);
1560 aPB->AppendExtPave(aPn);
1562 aVn=(*(TopoDS_Vertex *)(&myDS->Shape(nVn)));
1563 BOPTools_AlgoTools::UpdateVertex (aIC, aT[j], aVn);
1565 aTolVnew = BRep_Tool::Tolerance(aVn);
1567 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nVn);
1568 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
1569 BRepBndLib::Add(aVn, aBoxDS);
1570 aBoxDS.SetGap(aBoxDS.GetGap() + Precision::Confusion());
1577 //=======================================================================
1578 //function : PutPavesOnCurve
1580 //=======================================================================
1581 void BOPAlgo_PaveFiller::PutPavesOnCurve(const TColStd_MapOfInteger& theMVOnIn,
1582 const TColStd_MapOfInteger& theMVCommon,
1584 const TColStd_MapOfInteger& theMI,
1585 const TColStd_MapOfInteger& theMVEF,
1586 TColStd_DataMapOfIntegerReal& theMVTol,
1587 TColStd_DataMapOfIntegerListOfInteger& theDMVLV)
1589 Standard_Integer nV;
1590 TColStd_MapIteratorOfMapOfInteger aIt;
1592 const Bnd_Box& aBoxC = theNC.Box();
1593 const Standard_Real aTolR3D = Max(theNC.Tolerance(), theNC.TangentialTolerance());
1595 //Put EF vertices first
1596 aIt.Initialize(theMVEF);
1597 for (; aIt.More(); aIt.Next())
1600 PutPaveOnCurve(nV, aTolR3D, theNC, theMI, theMVTol, theDMVLV, 2);
1603 //Put all other vertices
1604 aIt.Initialize(theMVOnIn);
1605 for (; aIt.More(); aIt.Next())
1608 if (theMVEF.Contains(nV))
1613 if (!theMVCommon.Contains(nV))
1615 const BOPDS_ShapeInfo& aSIV = myDS->ShapeInfo(nV);
1616 const Bnd_Box& aBoxV = aSIV.Box();
1618 if (aBoxC.IsOut(aBoxV))
1622 if (!myDS->IsNewShape(nV))
1628 PutPaveOnCurve(nV, aTolR3D, theNC, theMI, theMVTol, theDMVLV, 1);
1632 //=======================================================================
1633 //function : FilterPavesOnCurves
1635 //=======================================================================
1637 struct PaveBlockDist {
1638 Handle(BOPDS_PaveBlock) PB;
1639 Standard_Real Dist; // square distance from vertex to the paveblock
1640 Standard_Real SinAngle; // sinus of angle between projection vector
1641 // and tangent at projection point
1642 Standard_Real Tolerance; // tolerance of the section curve
1645 void BOPAlgo_PaveFiller::FilterPavesOnCurves(const BOPDS_VectorOfCurve& theVNC)
1647 // For each vertex found in ExtPaves of pave blocks of section curves
1648 // collect list of pave blocks with distance to the curve
1649 NCollection_IndexedDataMap<Standard_Integer,NCollection_List<PaveBlockDist> > aIDMVertPBs;
1651 const Standard_Real anEps = gp::Resolution();
1652 for (i = 0; i < theVNC.Length(); ++i)
1654 const BOPDS_Curve& aNC = theVNC(i);
1655 const IntTools_Curve& aIC = aNC.Curve();
1656 const Standard_Real aTolR3D = Max(aNC.Tolerance(), aNC.TangentialTolerance());
1657 GeomAdaptor_Curve aGAC(aIC.Curve());
1658 const Handle(BOPDS_PaveBlock)& aPB = aNC.PaveBlocks().First();
1659 const BOPDS_ListOfPave& aPaves = aPB->ExtPaves();
1660 BOPDS_ListOfPave::Iterator itPaves(aPaves);
1661 for (; itPaves.More(); itPaves.Next())
1663 const BOPDS_Pave& aPave = itPaves.Value();
1664 Standard_Integer nV = aPave.Index();
1665 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV));
1666 // compute distance from vertex to the point on curve with vertex parameter
1667 gp_Pnt aPV = BRep_Tool::Pnt(aV);
1668 Standard_Real aPar = aPave.Parameter();
1671 aGAC.D1(aPar, aPonC, aD1);
1672 gp_Vec aProjVec(aPV, aPonC);
1673 Standard_Real aSqDist = aProjVec.SquareMagnitude();
1674 Standard_Real aSqD1Mod = aD1.SquareMagnitude();
1675 Standard_Real aSin = aProjVec.CrossSquareMagnitude(aD1);
1676 if (aSqDist > anEps && aSqD1Mod > anEps)
1677 aSin = sqrt(aSin / aSqDist / aSqD1Mod);
1678 NCollection_List<PaveBlockDist>* pList = aIDMVertPBs.ChangeSeek(nV);
1680 pList = &aIDMVertPBs.ChangeFromIndex(aIDMVertPBs.Add(nV, NCollection_List<PaveBlockDist>()));
1681 PaveBlockDist aPBD = { aPB, aSqDist, aSin, aTolR3D };
1682 pList->Append(aPBD);
1686 // Process each vertex
1687 const Standard_Real aSinAngleMin = 0.5; // angle below which projection is suspicious
1688 for (i = 1; i <= aIDMVertPBs.Extent(); i++)
1690 Standard_Integer nV = aIDMVertPBs.FindKey(i);
1691 const NCollection_List<PaveBlockDist>& aList = aIDMVertPBs(i);
1692 // Find a pave with minimal distance
1693 Standard_Real aMinDist = RealLast();
1694 Handle(BOPDS_PaveBlock) aPBMinDist;
1695 NCollection_List<PaveBlockDist>::Iterator itL(aList);
1696 for (; itL.More(); itL.Next())
1698 const PaveBlockDist& aPBD = itL.Value();
1699 if (aPBD.Dist < aMinDist)
1701 aMinDist = aPBD.Dist;
1702 aPBMinDist = aPBD.PB;
1705 // Remove a vertex from a pave block if the distance is greater than the tolerance
1706 // and there are other pave blocks for which the distance is less than the current.
1707 // Do not remove a vertex if it is projected on the curve with quite large angle
1708 // (see test bugs modalg_6 bug27761).
1709 for (itL.Init(aList); itL.More(); itL.Next())
1711 const PaveBlockDist& aPBD = itL.Value();
1712 Standard_Real aCheckDist = 100. * Max(aPBD.Tolerance*aPBD.Tolerance, aMinDist);
1713 if (aPBD.Dist > aCheckDist && aPBD.SinAngle < aSinAngleMin)
1715 aPBD.PB->RemoveExtPave(nV);
1721 //=======================================================================
1722 //function : ExtendedTolerance
1724 //=======================================================================
1725 Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance
1726 (const Standard_Integer nV,
1727 const TColStd_MapOfInteger& aMI,
1728 Standard_Real& aTolVExt,
1729 const Standard_Integer aType)
1731 Standard_Boolean bFound = Standard_False;
1732 if (!(myDS->IsNewShape(nV))) {
1736 Standard_Integer i, k, aNbLines, aNbInt;
1737 Standard_Real aT11, aT12, aD1, aD2, aD;
1739 gp_Pnt aPV, aP11, aP12;
1745 } else if (aType == 2) {
1749 aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1750 aPV=BRep_Tool::Pnt(aV);
1752 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
1753 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1755 for (; k<aNbInt; ++k) {
1756 aNbLines = !k ? aEEs.Length() : aEFs.Length();
1757 for (i = 0; i < aNbLines; ++i) {
1758 BOPDS_Interf *aInt = !k ? (BOPDS_Interf*) (&aEEs(i)) :
1759 (BOPDS_Interf*) (&aEFs(i));
1760 if (aInt->IndexNew() == nV) {
1761 if (aMI.Contains(aInt->Index1()) &&
1762 aMI.Contains(aInt->Index2())) {
1763 const IntTools_CommonPrt& aComPrt = !k ? aEEs(i).CommonPart() :
1764 aEFs(i).CommonPart();
1766 const TopoDS_Edge& aE1=aComPrt.Edge1();
1767 aComPrt.Range1(aT11, aT12);
1768 BOPTools_AlgoTools::PointOnEdge(aE1, aT11, aP11);
1769 BOPTools_AlgoTools::PointOnEdge(aE1, aT12, aP12);
1770 aD1=aPV.Distance(aP11);
1771 aD2=aPV.Distance(aP12);
1772 aD=(aD1>aD2)? aD1 : aD2;
1777 }//if (aMI.Contains(aEF.Index1()) && aMI.Contains(aEF.Index2())) {
1778 }//if (aInt->IndexNew() == nV) {
1779 }//for (i = 0; i < aNbLines; ++i) {
1780 }//for (k=0; k<2; ++k) {
1784 //=======================================================================
1785 //function : GetEFPnts
1787 //=======================================================================
1788 void BOPAlgo_PaveFiller::GetEFPnts
1789 (const Standard_Integer nF1,
1790 const Standard_Integer nF2,
1791 IntSurf_ListOfPntOn2S& aListOfPnts)
1793 Standard_Integer nE, nF, nFOpposite, aNbEFs, i;
1794 Standard_Real U1, U2, V1, V2, f, l;
1795 TColStd_MapOfInteger aMI;
1797 //collect indexes of all shapes from nF1 and nF2.
1798 GetFullShapeMap(nF1, aMI);
1799 GetFullShapeMap(nF2, aMI);
1801 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1802 aNbEFs = aEFs.Length();
1804 for(i = 0; i < aNbEFs; ++i) {
1805 const BOPDS_InterfEF& aEF = aEFs(i);
1806 if (aEF.HasIndexNew()) {
1807 aEF.Indices(nE, nFOpposite);
1808 if(aMI.Contains(nE) && aMI.Contains(nFOpposite)) {
1809 const IntTools_CommonPrt& aCP = aEF.CommonPart();
1810 Standard_Real aPar = aCP.VertexParameter1();
1811 const TopoDS_Edge& aE = (*(TopoDS_Edge*)(&myDS->Shape(nE)));
1812 const TopoDS_Face& aFOpposite =
1813 (*(TopoDS_Face*)(&myDS->Shape(nFOpposite)));
1815 const Handle(Geom_Curve)& aCurve = BRep_Tool::Curve(aE, f, l);
1817 nF = (nFOpposite == nF1) ? nF2 : nF1;
1818 const TopoDS_Face& aF = (*(TopoDS_Face*)(&myDS->Shape(nF)));
1819 Handle(Geom2d_Curve) aPCurve =
1820 BRep_Tool::CurveOnSurface(aE, aF, f, l);
1822 GeomAPI_ProjectPointOnSurf& aProj=myContext->ProjPS(aFOpposite);
1825 aCurve->D0(aPar, aPoint);
1826 IntSurf_PntOn2S aPnt;
1827 if(!aPCurve.IsNull()) {
1828 gp_Pnt2d aP2d = aPCurve->Value(aPar);
1829 aProj.Perform(aPoint);
1830 if(aProj.IsDone()) {
1831 aProj.LowerDistanceParameters(U1,V1);
1833 aPnt.SetValue(aP2d.X(),aP2d.Y(),U1,V1);
1835 aPnt.SetValue(U1,V1,aP2d.X(),aP2d.Y());
1837 aListOfPnts.Append(aPnt);
1841 GeomAPI_ProjectPointOnSurf& aProj1 = myContext->ProjPS(aF);
1842 aProj1.Perform(aPoint);
1843 aProj.Perform(aPoint);
1844 if(aProj1.IsDone() && aProj.IsDone()){
1845 aProj1.LowerDistanceParameters(U1,V1);
1846 aProj.LowerDistanceParameters(U2,V2);
1848 aPnt.SetValue(U1,V1,U2,V2);
1850 aPnt.SetValue(U2,V2,U1,V1);
1852 aListOfPnts.Append(aPnt);
1860 //=======================================================================
1861 //function : PutEFPavesOnCurve
1863 //=======================================================================
1864 void BOPAlgo_PaveFiller::PutEFPavesOnCurve
1866 const TColStd_MapOfInteger& aMI,
1867 const TColStd_MapOfInteger& aMVEF,
1868 TColStd_DataMapOfIntegerReal& aMVTol,
1869 TColStd_DataMapOfIntegerListOfInteger& aDMVLV)
1871 if (!aMVEF.Extent()) {
1875 const IntTools_Curve& aIC=aNC.Curve();
1876 GeomAbs_CurveType aTypeC;
1878 if (!(aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve)) {
1882 Standard_Integer nV;
1883 TColStd_MapOfInteger aMV;
1886 RemoveUsedVertices(aNC, aMV);
1887 if (!aMV.Extent()) {
1891 Standard_Real aDist;
1894 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1895 GeomAPI_ProjectPointOnCurve& aProjPT = myContext->ProjPT(aC3D);
1897 TColStd_MapIteratorOfMapOfInteger aItMI;
1898 aItMI.Initialize(aMV);
1899 for (; aItMI.More(); aItMI.Next()) {
1901 const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1902 gp_Pnt aPV = BRep_Tool::Pnt(aV);
1903 aProjPT.Perform(aPV);
1904 Standard_Integer aNbPoints = aProjPT.NbPoints();
1906 aDist = aProjPT.LowerDistance();
1907 PutPaveOnCurve(nV, aDist, aNC, aMI, aMVTol, aDMVLV);
1912 //=======================================================================
1913 //function : ProcessUnUsedVertices
1915 //=======================================================================
1916 void BOPAlgo_PaveFiller::PutStickPavesOnCurve
1917 (const TopoDS_Face& aF1,
1918 const TopoDS_Face& aF2,
1919 const TColStd_MapOfInteger& aMI,
1921 const TColStd_MapOfInteger& aMVStick,
1922 TColStd_DataMapOfIntegerReal& aMVTol,
1923 TColStd_DataMapOfIntegerListOfInteger& aDMVLV)
1925 TColStd_MapOfInteger aMV;
1926 aMV.Assign(aMVStick);
1927 RemoveUsedVertices(aNC, aMV);
1929 if (!aMV.Extent()) {
1933 Handle(Geom_Surface) aS1=BRep_Tool::Surface(aF1);
1934 Handle(Geom_Surface) aS2=BRep_Tool::Surface(aF2);
1936 const IntTools_Curve& aIC=aNC.Curve();
1937 //if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
1938 Handle(Geom2d_Curve) aC2D[2];
1940 aC2D[0]=aIC.FirstCurve2d();
1941 aC2D[1]=aIC.SecondCurve2d();
1942 if (!aC2D[0].IsNull() && !aC2D[1].IsNull()) {
1943 Standard_Integer nV, m, n;
1944 Standard_Real aTC[2], aD, aD2, u, v, aDT2, aScPr, aDScPr;
1948 TColStd_MapIteratorOfMapOfInteger aItMI, aItMI1;
1950 aDT2=2e-7; // the rich criteria
1951 aDScPr=5.e-9; // the creasing criteria
1952 aIC.Bounds(aTC[0], aTC[1], aPC[0], aPC[1]);
1954 aItMI.Initialize(aMV);
1955 for (; aItMI.More(); aItMI.Next()) {
1957 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&myDS->Shape(nV));
1958 aPV=BRep_Tool::Pnt(aV);
1960 for (m=0; m<2; ++m) {
1961 aD2=aPC[m].SquareDistance(aPV);
1962 if (aD2>aDT2) {// no rich
1966 for (n=0; n<2; ++n) {
1967 Handle(Geom_Surface)& aS=(!n)? aS1 : aS2;
1968 aC2D[n]->D0(aTC[m], aP2D);
1970 BOPTools_AlgoTools3D::GetNormalToSurface(aS, u, v, aDN[n]);
1973 aScPr=aDN[0]*aDN[1];
1983 // The intersection curve aIC is vanishing curve (the crease)
1986 PutPaveOnCurve(nV, aD, aNC, aMI, aMVTol, aDMVLV);
1988 }//for (jVU=1; jVU=aNbVU; ++jVU) {
1990 //}//if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
1991 //}//if(aType1==GeomAbs_Torus || aType2==GeomAbs_Torus) {
1994 //=======================================================================
1995 //function : GetStickVertices
1997 //=======================================================================
1998 void BOPAlgo_PaveFiller::GetStickVertices(const Standard_Integer nF1,
1999 const Standard_Integer nF2,
2000 TColStd_MapOfInteger& aMVStick,
2001 TColStd_MapOfInteger& aMVEF,
2002 TColStd_MapOfInteger& aMI)
2004 Standard_Integer nS1, nS2, nVNew, aTypeInt, i;
2006 BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV();
2007 BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
2008 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
2009 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
2010 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
2012 Standard_Integer aNbLines[5] = {
2013 aVVs.Length(), aVEs.Length(), aEEs.Length(),
2014 aVFs.Length(), aEFs.Length()
2016 //collect indices of all shapes from nF1 and nF2.
2018 GetFullShapeMap(nF1, aMI);
2019 GetFullShapeMap(nF2, aMI);
2021 //collect VV, VE, EE, VF interferences
2022 for (aTypeInt = 0; aTypeInt < 4; ++aTypeInt) {
2023 for (i = 0; i < aNbLines[aTypeInt]; ++i) {
2024 BOPDS_Interf* aInt = (aTypeInt==0) ? (BOPDS_Interf*)(&aVVs(i)) :
2025 ((aTypeInt==1) ? (BOPDS_Interf*)(&aVEs(i)) :
2026 ((aTypeInt==2) ? (BOPDS_Interf*)(&aEEs(i)) :
2027 (BOPDS_Interf*)(&aVFs(i))));
2028 if (aInt->HasIndexNew()) {
2029 aInt->Indices(nS1, nS2);
2030 if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
2031 nVNew = aInt->IndexNew();
2032 aMVStick.Add(nVNew);
2037 //collect EF interferences
2038 for (i = 0; i < aNbLines[4]; ++i) {
2039 const BOPDS_InterfEF& aInt = aEFs(i);
2040 if (aInt.HasIndexNew()) {
2041 aInt.Indices(nS1, nS2);
2042 if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
2043 nVNew = aInt.IndexNew();
2044 aMVStick.Add(nVNew);
2051 //=======================================================================
2052 // function: GetFullShapeMap
2054 //=======================================================================
2055 void BOPAlgo_PaveFiller::GetFullShapeMap(const Standard_Integer nF,
2056 TColStd_MapOfInteger& aMI)
2058 TColStd_ListIteratorOfListOfInteger aIt;
2059 Standard_Integer nS;
2061 const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(nF);
2062 const TColStd_ListOfInteger& aLI = aSI.SubShapes();
2065 aIt.Initialize(aLI);
2066 for (; aIt.More(); aIt.Next()) {
2072 //=======================================================================
2073 // function: RemoveUsedVertices
2075 //=======================================================================
2076 void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
2077 TColStd_MapOfInteger& aMV)
2079 if (!aMV.Extent()) {
2082 Standard_Integer nV;
2084 BOPDS_ListIteratorOfListOfPave aItLP;
2086 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
2087 const BOPDS_ListOfPave& aLP = aPB->ExtPaves();
2088 aItLP.Initialize(aLP);
2089 for (;aItLP.More();aItLP.Next()) {
2090 aPave = aItLP.Value();
2096 //=======================================================================
2097 //function : PutPaveOnCurve
2099 //=======================================================================
2100 void BOPAlgo_PaveFiller::PutPaveOnCurve
2101 (const Standard_Integer nV,
2102 const Standard_Real aTolR3D,
2103 const BOPDS_Curve& aNC,
2104 const TColStd_MapOfInteger& aMI,
2105 TColStd_DataMapOfIntegerReal& aMVTol,
2106 TColStd_DataMapOfIntegerListOfInteger& aDMVLV,
2107 const Standard_Integer iCheckExtend)
2109 Standard_Boolean bIsVertexOnLine;
2112 const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
2113 const Handle(BOPDS_PaveBlock)& aPB = aNC.PaveBlocks().First();
2114 const IntTools_Curve& aIC = aNC.Curve();
2116 Standard_Real aTolV = (aMVTol.IsBound(nV) ? aMVTol(nV) : BRep_Tool::Tolerance(aV));
2118 bIsVertexOnLine = myContext->IsVertexOnLine(aV, aTolV, aIC, aTolR3D + myFuzzyValue, aT);
2119 if (!bIsVertexOnLine && iCheckExtend) {
2120 ExtendedTolerance(nV, aMI, aTolV, iCheckExtend);
2121 bIsVertexOnLine = myContext->IsVertexOnLine(aV, aTolV, aIC, aTolR3D + myFuzzyValue, aT);
2124 if (bIsVertexOnLine) {
2125 // check if aPB contains the parameter aT
2126 Standard_Boolean bExist;
2127 Standard_Integer nVUsed;
2128 Standard_Real aPTol, aDTol;
2132 GeomAdaptor_Curve aGAC(aIC.Curve());
2133 aPTol = aGAC.Resolution(Max(aTolR3D, aTolV));
2135 bExist = aPB->ContainsParameter(aT, aPTol, nVUsed);
2137 // use existing pave
2138 TColStd_ListOfInteger* pList = aDMVLV.ChangeSeek(nVUsed);
2140 pList = aDMVLV.Bound(nVUsed, TColStd_ListOfInteger());
2141 pList->Append(nVUsed);
2142 if (!aMVTol.IsBound(nVUsed)) {
2143 const TopoDS_Vertex& aVUsed = (*(TopoDS_Vertex *)(&myDS->Shape(nVUsed)));
2144 aTolV = BRep_Tool::Tolerance(aVUsed);
2145 aMVTol.Bind(nVUsed, aTolV);
2148 // avoid repeated elements in the list
2149 TColStd_ListIteratorOfListOfInteger aItLI(*pList);
2150 for (; aItLI.More(); aItLI.Next()) {
2151 if (aItLI.Value() == nV) {
2155 if (!aItLI.More()) {
2158 // save initial tolerance for the vertex
2159 if (!aMVTol.IsBound(nV)) {
2160 aTolV = BRep_Tool::Tolerance(aV);
2161 aMVTol.Bind(nV, aTolV);
2168 aPave.SetParameter(aT);
2169 aPB->AppendExtPave(aPave);
2171 gp_Pnt aP1 = aGAC.Value(aT);
2172 aTolV = BRep_Tool::Tolerance(aV);
2173 gp_Pnt aP2 = BRep_Tool::Pnt(aV);
2174 Standard_Real aDist = aP1.Distance(aP2);
2175 if (aDist > aTolV) {
2176 BRep_Builder().UpdateVertex(aV, aDist + aDTol);
2178 if (!aMVTol.IsBound(nV)) {
2179 aMVTol.Bind(nV, aTolV);
2182 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV);
2183 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
2184 BRepBndLib::Add(aV, aBoxDS);
2185 aBoxDS.SetGap(aBoxDS.GetGap() + Precision::Confusion());
2191 //=======================================================================
2192 //function : ProcessExistingPaveBlocks
2194 //=======================================================================
2195 void BOPAlgo_PaveFiller::ProcessExistingPaveBlocks
2196 (const Standard_Integer theInt,
2197 const BOPDS_IndexedMapOfPaveBlock& aMPBOnIn,
2198 const TColStd_DataMapOfIntegerListOfInteger& aDMBV,
2199 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
2200 TopTools_DataMapOfShapeInteger& aMVI,
2201 BOPDS_MapOfPaveBlock& aMPB)
2203 if (aDMBV.IsEmpty()) {
2207 Standard_Real aT, dummy;
2208 Standard_Integer i, nV, nE, iC, aNbPB, iFlag;
2209 TColStd_ListIteratorOfListOfInteger aItLI;
2210 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItBV;
2212 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
2213 BOPDS_InterfFF& aFF = aFFs(theInt);
2214 BOPDS_VectorOfCurve& aVC = aFF.ChangeCurves();
2216 aNbPB = aMPBOnIn.Extent();
2218 aItBV.Initialize(aDMBV);
2219 for (; aItBV.More(); aItBV.Next()) {
2221 const TColStd_ListOfInteger& aLBV = aItBV.Value();
2223 BOPDS_Curve& aNC = aVC.ChangeValue(iC);
2224 BOPDS_ListOfPaveBlock& aLPBC = aNC.ChangePaveBlocks();
2226 aItLI.Initialize(aLBV);
2227 for (; aItLI.More(); aItLI.Next()) {
2229 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
2230 const Bnd_Box& aBoxV=aSIV.Box();
2231 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&aSIV.Shape();
2232 if (!aMVI.IsBound(aV)) {
2236 for (i = 1; i <= aNbPB; ++i) {
2237 const Handle(BOPDS_PaveBlock)& aPB = aMPBOnIn(i);
2238 if (aPB->Pave1().Index() == nV || aPB->Pave2().Index() == nV) {
2242 if (aMPB.Contains(aPB)) {
2245 if (myDS->ShapeInfo(aPB->OriginalEdge()).HasFlag()) { // skip degenerated edges
2250 const BOPDS_ShapeInfo& aSIE = myDS->ShapeInfo(nE);
2251 const Bnd_Box& aBoxE = aSIE.Box();
2253 if (aBoxV.IsOut(aBoxE)) {
2257 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aSIE.Shape();
2259 iFlag = myContext->ComputeVE(aV, aE, aT, dummy, myFuzzyValue);
2262 PreparePostTreatFF(theInt, iC, aPB, aMSCPB, aMVI, aLPBC);
2268 //=======================================================================
2269 //function : UpdateExistingPaveBlocks
2271 //=======================================================================
2272 void BOPAlgo_PaveFiller::UpdateExistingPaveBlocks
2273 (const Handle(BOPDS_PaveBlock)& aPBf,
2274 BOPDS_ListOfPaveBlock& aLPB,
2275 const Standard_Integer nF1,
2276 const Standard_Integer nF2)
2278 if (!aLPB.Extent()) {
2282 Standard_Integer nE;
2283 Standard_Boolean bCB;
2284 Handle(BOPDS_PaveBlock) aPB, aPB1, aPB2, aPB2n;
2285 Handle(BOPDS_CommonBlock) aCB;
2286 BOPDS_ListIteratorOfListOfPaveBlock aIt, aIt1, aIt2;
2288 BOPDS_FaceInfo& aFI1 = myDS->ChangeFaceInfo(nF1);
2289 BOPDS_FaceInfo& aFI2 = myDS->ChangeFaceInfo(nF2);
2291 BOPDS_IndexedMapOfPaveBlock& aMPBOn1 = aFI1.ChangePaveBlocksOn();
2292 BOPDS_IndexedMapOfPaveBlock& aMPBIn1 = aFI1.ChangePaveBlocksIn();
2293 BOPDS_IndexedMapOfPaveBlock& aMPBOn2 = aFI2.ChangePaveBlocksOn();
2294 BOPDS_IndexedMapOfPaveBlock& aMPBIn2 = aFI2.ChangePaveBlocksIn();
2296 // 1. Remove old pave blocks
2297 const Handle(BOPDS_CommonBlock)& aCB1 = myDS->CommonBlock(aPBf);
2298 bCB = !aCB1.IsNull();
2299 BOPDS_ListOfPaveBlock aLPB1;
2302 aLPB1.Assign(aCB1->PaveBlocks());
2306 aIt1.Initialize(aLPB1);
2307 for (; aIt1.More(); aIt1.Next()) {
2308 aPB1 = aIt1.Value();
2309 nE = aPB1->OriginalEdge();
2311 BOPDS_ListOfPaveBlock& aLPB2 = myDS->ChangePaveBlocks(nE);
2312 aIt2.Initialize(aLPB2);
2313 for (; aIt2.More(); aIt2.Next()) {
2314 aPB2 = aIt2.Value();
2322 // 2. Update pave blocks
2324 // Create new common blocks
2325 BOPDS_ListOfPaveBlock aLPBNew;
2326 const TColStd_ListOfInteger& aFaces = aCB1->Faces();
2327 aIt.Initialize(aLPB);
2328 for (; aIt.More(); aIt.Next()) {
2329 const Handle(BOPDS_PaveBlock)& aPBValue = aIt.Value();
2330 BOPDS_Pave aPBValuePaves[2] = {aPBValue->Pave1(), aPBValue->Pave2()};
2332 aCB = new BOPDS_CommonBlock;
2333 aIt1.Initialize(aLPB1);
2334 for (; aIt1.More(); aIt1.Next()) {
2335 aPB2 = aIt1.Value();
2336 nE = aPB2->OriginalEdge();
2338 // Create new pave block
2339 aPB2n = new BOPDS_PaveBlock;
2340 if (aPBValue->OriginalEdge() == nE) {
2341 aPB2n->SetPave1(aPBValuePaves[0]);
2342 aPB2n->SetPave2(aPBValuePaves[1]);
2345 // For the different original edge compute the parameters of paves
2346 BOPDS_Pave aPave[2];
2347 for (Standard_Integer i = 0; i < 2; ++i) {
2348 Standard_Integer nV = aPBValuePaves[i].Index();
2349 aPave[i].SetIndex(nV);
2350 if (nV == aPB2->Pave1().Index()) {
2351 aPave[i].SetParameter(aPB2->Pave1().Parameter());
2353 else if (nV == aPB2->Pave2().Index()) {
2354 aPave[i].SetParameter(aPB2->Pave2().Parameter());
2357 // Compute the parameter by projecting the point
2358 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV));
2359 const TopoDS_Edge& aEOr = TopoDS::Edge(myDS->Shape(nE));
2360 Standard_Real aTOut, aDist;
2361 Standard_Integer iErr = myContext->ComputeVE(aV, aEOr, aTOut, aDist, myFuzzyValue);
2363 aPave[i].SetParameter(aTOut);
2366 // Unable to project - set the parameter of the closest boundary
2367 const TopoDS_Vertex& aV1 = TopoDS::Vertex(myDS->Shape(aPB2->Pave1().Index()));
2368 const TopoDS_Vertex& aV2 = TopoDS::Vertex(myDS->Shape(aPB2->Pave2().Index()));
2370 gp_Pnt aP = BRep_Tool::Pnt(aV);
2371 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
2372 gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
2374 Standard_Real aDist1 = aP.SquareDistance(aP1);
2375 Standard_Real aDist2 = aP.SquareDistance(aP2);
2377 aPave[i].SetParameter(aDist1 < aDist2 ? aPB2->Pave1().Parameter() : aPB2->Pave2().Parameter());
2382 if (aPave[1].Parameter() < aPave[0].Parameter()) {
2383 BOPDS_Pave aPaveTmp = aPave[0];
2384 aPave[0] = aPave[1];
2385 aPave[1] = aPaveTmp;
2388 aPB2n->SetPave1(aPave[0]);
2389 aPB2n->SetPave2(aPave[1]);
2392 aPB2n->SetEdge(aPBValue->Edge());
2393 aPB2n->SetOriginalEdge(nE);
2394 aCB->AddPaveBlock(aPB2n);
2395 myDS->SetCommonBlock(aPB2n, aCB);
2396 myDS->ChangePaveBlocks(nE).Append(aPB2n);
2398 aCB->SetFaces(aFaces);
2400 const Handle(BOPDS_PaveBlock)& aPBNew = aCB->PaveBlocks().First();
2401 aLPBNew.Append(aPBNew);
2407 nE = aPBf->OriginalEdge();
2408 BOPDS_ListOfPaveBlock& aLPBE = myDS->ChangePaveBlocks(nE);
2409 aIt.Initialize(aLPB);
2410 for (; aIt.More(); aIt.Next()) {
2416 Standard_Boolean bIn1, bIn2;
2418 bIn1 = aMPBOn1.Contains(aPBf) || aMPBIn1.Contains(aPBf);
2419 bIn2 = aMPBOn2.Contains(aPBf) || aMPBIn2.Contains(aPBf);
2425 // 3. Check new pave blocks for coincidence
2426 // with the opposite face.
2427 // In case of coincidence create common blocks
2428 Standard_Integer nF;
2430 nF = bIn1 ? nF2 : nF1;
2431 const TopoDS_Face& aF = *(TopoDS_Face*)&myDS->Shape(nF);
2432 BOPDS_IndexedMapOfPaveBlock& aMPBIn = bIn1 ? aMPBIn2 : aMPBIn1;
2434 aIt.Initialize(aLPB);
2435 for (; aIt.More(); aIt.Next()) {
2436 Handle(BOPDS_PaveBlock)& aPBChangeValue = aIt.ChangeValue();
2437 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPBChangeValue->Edge());
2439 IntTools_EdgeFace anEF;
2442 anEF.SetFuzzyValue(myFuzzyValue);
2443 anEF.SetRange(aPBChangeValue->Pave1().Parameter(), aPBChangeValue->Pave2().Parameter());
2444 anEF.SetContext(myContext);
2447 const IntTools_SequenceOfCommonPrts& aCPrts=anEF.CommonParts();
2448 if (aCPrts.Length() == 1) {
2449 Standard_Boolean bCoinc = (aCPrts(1).Type() == TopAbs_EDGE);
2452 aCB = myDS->CommonBlock(aPBChangeValue);
2454 aCB = new BOPDS_CommonBlock;
2455 aCB->AddPaveBlock(aPBChangeValue);
2456 myDS->SetCommonBlock(aPBChangeValue, aCB);
2460 aMPBIn.Add(aPBChangeValue);
2465 //=======================================================================
2466 // function: PutClosingPaveOnCurve
2468 //=======================================================================
2469 void BOPAlgo_PaveFiller::PutClosingPaveOnCurve(BOPDS_Curve& aNC)
2471 const IntTools_Curve& aIC = aNC.Curve();
2472 const Handle(Geom_Curve)& aC3D = aIC.Curve();
2478 if (!aIC.HasBounds())
2482 Standard_Real aT[2];
2484 aIC.Bounds(aT[0], aT[1], aP[0], aP[1]);
2486 // Find the pave which has been put at one of the ends
2487 Standard_Integer nV = -1;
2488 // Keep the opposite parameter
2489 Standard_Real aTOp = 0.;
2491 Standard_Boolean bFound = Standard_False;
2493 Handle(BOPDS_PaveBlock)& aPB = aNC.ChangePaveBlock1();
2494 BOPDS_ListOfPave& aLP = aPB->ChangeExtPaves();
2495 BOPDS_ListIteratorOfListOfPave aItLP(aLP);
2496 for (; aItLP.More() && !bFound; aItLP.Next())
2498 const BOPDS_Pave& aPC = aItLP.Value();
2499 Standard_Real aTC = aPC.Parameter();
2500 for (Standard_Integer j = 0; j < 2; ++j)
2502 if (Abs(aTC - aT[j]) < Precision::PConfusion())
2505 aTOp = (!j) ? aT[1] : aT[0];
2506 bFound = Standard_True;
2515 // Check if the curve is closed using the tolerance
2517 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV));
2518 const Standard_Real aTolV = BRep_Tool::Tolerance(aV);
2520 Standard_Real aDist = aP[0].Distance(aP[1]);
2524 // Check if there will be valid range on the curve
2525 Standard_Real aFirst, aLast;
2526 if (!BRepLib::FindValidRange(GeomAdaptor_Curve(aIC.Curve()), aIC.Tolerance(),
2527 aT[0], aP[0], aTolV,
2528 aT[1], aP[1], aTolV,
2534 // Add closing pave to the curve
2537 aPave.SetParameter(aTOp);
2540 //=======================================================================
2541 //function : PreparePostTreatFF
2543 //=======================================================================
2544 void BOPAlgo_PaveFiller::PreparePostTreatFF
2545 (const Standard_Integer aInt,
2546 const Standard_Integer aCur,
2547 const Handle(BOPDS_PaveBlock)& aPB,
2548 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
2549 TopTools_DataMapOfShapeInteger& aMVI,
2550 BOPDS_ListOfPaveBlock& aLPBC)
2552 Standard_Integer nV1, nV2;
2556 aPB->Indices(nV1, nV2);
2557 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
2558 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
2559 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
2560 // Keep info for post treatment
2561 BOPDS_CoupleOfPaveBlocks aCPB;
2562 aCPB.SetIndexInterf(aInt);
2563 aCPB.SetIndex(aCur);
2564 aCPB.SetPaveBlock1(aPB);
2566 aMSCPB.Add(aE, aCPB);
2567 aMVI.Bind(aV1, nV1);
2568 aMVI.Bind(aV2, nV2);
2571 //=======================================================================
2572 //function : CheckPlanes
2574 //=======================================================================
2575 Standard_Boolean BOPAlgo_PaveFiller::CheckPlanes
2576 (const Standard_Integer nF1,
2577 const Standard_Integer nF2)const
2579 Standard_Boolean bToIntersect;
2580 Standard_Integer i, nV2, iCnt;
2581 TColStd_MapIteratorOfMapOfInteger aIt;
2583 bToIntersect=Standard_False;
2585 const BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
2586 const BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
2588 const TColStd_MapOfInteger& aMVIn1=aFI1.VerticesIn();
2589 const TColStd_MapOfInteger& aMVOn1=aFI1.VerticesOn();
2592 for (i=0; (i<2 && !bToIntersect); ++i) {
2593 const TColStd_MapOfInteger& aMV2=(!i) ? aFI2.VerticesIn()
2594 : aFI2.VerticesOn();
2596 aIt.Initialize(aMV2);
2597 for (; aIt.More(); aIt.Next()) {
2599 if (aMVIn1.Contains(nV2) || aMVOn1.Contains(nV2)) {
2602 bToIntersect=!bToIntersect;
2609 return bToIntersect;
2611 //=======================================================================
2612 //function : UpdatePaveBlocks
2614 //=======================================================================
2615 void BOPAlgo_PaveFiller::UpdatePaveBlocks
2616 (const TColStd_DataMapOfIntegerInteger& aDMNewSD)
2618 if (aDMNewSD.IsEmpty()) {
2622 Standard_Integer nSp, aNbPBP, nV[2], i, j;
2623 Standard_Real aT[2];
2624 Standard_Boolean bCB, bRebuild;
2625 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
2626 BOPDS_MapOfPaveBlock aMPB;
2627 TColStd_MapOfInteger aMicroEdges;
2629 BOPDS_ListOfPaveBlock anAllPBs;
2631 // Get pave blocks of section edges
2632 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
2633 Standard_Integer aNbFF = aFFs.Length();
2634 for (i = 0; i < aNbFF; ++i)
2636 const BOPDS_InterfFF& aFF = aFFs(i);
2637 const BOPDS_VectorOfCurve& aVNC = aFF.Curves();
2638 Standard_Integer aNbC = aVNC.Length();
2639 for (j = 0; j < aNbC; ++j)
2641 const BOPDS_Curve& aNC = aVNC(j);
2642 const BOPDS_ListOfPaveBlock& aLPBC = aNC.PaveBlocks();
2643 aItPB.Initialize(aLPBC);
2644 for (; aItPB.More(); aItPB.Next())
2645 anAllPBs.Append(aItPB.Value());
2649 // Get pave blocks from the pool
2650 BOPDS_VectorOfListOfPaveBlock& aPBP = myDS->ChangePaveBlocksPool();
2651 aNbPBP = aPBP.Length();
2652 for (i = 0; i < aNbPBP; ++i) {
2653 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
2654 aItPB.Initialize(aLPB);
2655 for (; aItPB.More(); aItPB.Next())
2656 anAllPBs.Append(aItPB.Value());
2659 // Process all pave blocks
2660 aItPB.Initialize(anAllPBs);
2661 for (; aItPB.More(); aItPB.Next())
2663 Handle(BOPDS_PaveBlock) aPB = aItPB.Value();
2664 const Handle(BOPDS_CommonBlock)& aCB = myDS->CommonBlock(aPB);
2665 bCB = !aCB.IsNull();
2667 aPB = aCB->PaveBlock1();
2670 if (aMPB.Add(aPB)) {
2671 bRebuild = Standard_False;
2672 aPB->Indices(nV[0], nV[1]);
2673 aPB->Range(aT[0], aT[1]);
2674 // remember the fact if the edge had different vertices before substitution
2675 Standard_Boolean wasRegularEdge = (nV[0] != nV[1]);
2677 for (j = 0; j < 2; ++j) {
2678 if (aDMNewSD.IsBound(nV[j])) {
2681 nV[j] = aDMNewSD.Find(nV[j]);
2682 aPave.SetIndex(nV[j]);
2683 aPave.SetParameter(aT[j]);
2685 bRebuild = Standard_True;
2687 aPB->SetPave1(aPave);
2690 aPB->SetPave2(aPave);
2696 Standard_Integer nE = aPB->Edge();
2697 // Check if the Pave Block has the edge set
2700 nE = aPB->OriginalEdge();
2702 Standard_Boolean isDegEdge = myDS->ShapeInfo(nE).HasFlag();
2703 if (wasRegularEdge && !isDegEdge && nV[0] == nV[1]) {
2704 // now edge has the same vertex on both ends;
2705 // check if it is not a regular closed curve.
2706 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(nE));
2707 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV[0]));
2708 Standard_Real aLength = IntTools::Length(aE);
2709 Standard_Real aTolV = BRep_Tool::Tolerance(aV);
2710 if (aLength <= aTolV * 2.) {
2711 // micro edge, so mark it for removal
2712 aMicroEdges.Add(nE);
2716 nSp = SplitEdge(nE, nV[0], aT[0], nV[1], aT[1]);
2722 }// if (aMPB.Add(aPB)) {
2723 }// for (; aItPB.More(); aItPB.Next()) {
2726 if (aMicroEdges.Extent())
2727 RemovePaveBlocks(aMicroEdges);
2729 //=======================================================================
2730 //function : RemovePaveBlocks
2732 //=======================================================================
2733 void BOPAlgo_PaveFiller::RemovePaveBlocks(const TColStd_MapOfInteger theEdges)
2735 // Remove all pave blocks referring to input edges:
2737 // 1. from the Pave Blocks Pool
2738 BOPDS_VectorOfListOfPaveBlock& aPBP = myDS->ChangePaveBlocksPool();
2739 Standard_Integer aNbPBP = aPBP.Length(), i;
2740 for (i = 0; i < aNbPBP; ++i) {
2741 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
2743 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
2744 while (aItPB.More()) {
2745 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
2746 if (theEdges.Contains(aPB->Edge()))
2753 // 2. from Face Info and section curves
2754 TColStd_MapOfInteger aMPassed;
2755 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
2756 Standard_Integer aNbFF = aFFs.Length(), j;
2757 for (i = 0; i < aNbFF; ++i) {
2758 BOPDS_InterfFF& aFF = aFFs(i);
2759 Standard_Integer nF1, nF2;
2760 aFF.Indices(nF1, nF2);
2762 // rebuild pave block maps of face info
2763 for (j = 0; j < 2; j++) {
2764 Standard_Integer nF = (j == 0 ? nF1 : nF2);
2765 if (!aMPassed.Add(nF))
2767 BOPDS_FaceInfo& aFI = myDS->ChangeFaceInfo(nF);
2768 BOPDS_IndexedMapOfPaveBlock* aIMPB[] = { &aFI.ChangePaveBlocksIn(),
2769 &aFI.ChangePaveBlocksOn(), &aFI.ChangePaveBlocksSc() };
2770 for (Standard_Integer k = 0; k < 3; k++) {
2771 Standard_Integer aNbPB = aIMPB[k]->Extent(), m;
2772 for (m = 1; m <= aNbPB; ++m) {
2773 const Handle(BOPDS_PaveBlock)& aPB = aIMPB[k]->FindKey(m);
2774 if (theEdges.Contains(aPB->Edge()))
2778 BOPDS_IndexedMapOfPaveBlock aMPBCopy = *aIMPB[k];
2780 for (m = 1; m <= aNbPB; ++m) {
2781 const Handle(BOPDS_PaveBlock)& aPB = aMPBCopy(m);
2782 if (!theEdges.Contains(aPB->Edge()))
2788 // remove from Section pave blocks
2789 BOPDS_VectorOfCurve& aVNC = aFF.ChangeCurves();
2790 Standard_Integer aNbC = aVNC.Length();
2791 for (j = 0; j < aNbC; ++j) {
2792 BOPDS_Curve& aNC = aVNC(j);
2793 BOPDS_ListOfPaveBlock& aLPB = aNC.ChangePaveBlocks();
2794 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
2795 while (aItPB.More()) {
2796 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
2797 if (theEdges.Contains(aPB->Edge()))
2805 //=======================================================================
2806 //function : ToleranceFF
2807 //purpose : Computes the TolFF according to the tolerance value and
2808 // types of the faces.
2809 //=======================================================================
2810 Standard_Real ToleranceFF(const BRepAdaptor_Surface& aBAS1,
2811 const BRepAdaptor_Surface& aBAS2)
2813 Standard_Real aTol1 = aBAS1.Tolerance();
2814 Standard_Real aTol2 = aBAS2.Tolerance();
2815 Standard_Real aTolFF = Max(aTol1, aTol2);
2817 Standard_Boolean isAna1, isAna2;
2818 isAna1 = (aBAS1.GetType() == GeomAbs_Plane ||
2819 aBAS1.GetType() == GeomAbs_Cylinder ||
2820 aBAS1.GetType() == GeomAbs_Cone ||
2821 aBAS1.GetType() == GeomAbs_Sphere ||
2822 aBAS1.GetType() == GeomAbs_Torus);
2824 isAna2 = (aBAS2.GetType() == GeomAbs_Plane ||
2825 aBAS2.GetType() == GeomAbs_Cylinder ||
2826 aBAS2.GetType() == GeomAbs_Cone ||
2827 aBAS2.GetType() == GeomAbs_Sphere ||
2828 aBAS2.GetType() == GeomAbs_Torus);
2830 if (!isAna1 || !isAna2) {
2831 aTolFF = Max(aTolFF, 5.e-6);
2835 //=======================================================================
2836 //function : UpdateBlocksWithSharedVertices
2838 //=======================================================================
2839 void BOPAlgo_PaveFiller::UpdateBlocksWithSharedVertices()
2841 if (!myNonDestructive) {
2845 Standard_Integer aNbFF;
2847 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
2848 aNbFF=aFFs.Length();
2853 Standard_Boolean bOnCurve, bHasShapeSD;
2854 Standard_Integer i, nF1, nF2, aNbC, j, nV, nVSD;
2855 Standard_Real aTolV;
2856 TColStd_MapOfInteger aMF;
2858 for (i=0; i<aNbFF; ++i) {
2859 BOPDS_InterfFF& aFF=aFFs(i);
2861 BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
2867 aFF.Indices(nF1, nF2);
2870 myDS->UpdateFaceInfoOn(nF1);
2873 myDS->UpdateFaceInfoOn(nF2);
2876 // Collect old vertices that are shared for nF1, nF2 ->aMI;
2877 TColStd_MapOfInteger aMI;
2878 TColStd_MapIteratorOfMapOfInteger aItMI;
2880 BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
2881 BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
2883 const TColStd_MapOfInteger& aMVOn1=aFI1.VerticesOn();
2884 const TColStd_MapOfInteger& aMVIn1=aFI1.VerticesIn();
2885 const TColStd_MapOfInteger& aMVOn2=aFI2.VerticesOn();
2886 const TColStd_MapOfInteger& aMVIn2=aFI2.VerticesIn();
2888 for (j=0; j<2; ++j) {
2889 const TColStd_MapOfInteger& aMV1=(!j) ? aMVOn1 : aMVIn1;
2890 aItMI.Initialize(aMV1);
2891 for (; aItMI.More(); aItMI.Next()) {
2893 if (myDS->IsNewShape(nV)) {
2896 if (aMVOn2.Contains(nV) || aMVIn2.Contains(nV)) {
2902 // Try to put vertices aMI on curves
2903 for (j=0; j<aNbC; ++j) {
2904 BOPDS_Curve& aNC=aVC.ChangeValue(j);
2905 Standard_Real aTolR3D = Max(aNC.Tolerance(), aNC.TangentialTolerance());
2907 aItMI.Initialize(aMI);
2908 for (; aItMI.More(); aItMI.Next()) {
2911 bHasShapeSD=myDS->HasShapeSD(nV, nVSD);
2916 bOnCurve=EstimatePaveOnCurve(nV, aNC, aTolR3D);
2921 const TopoDS_Vertex& aV=*((TopoDS_Vertex *)&myDS->Shape(nV));
2922 aTolV=BRep_Tool::Tolerance(aV);
2924 UpdateVertex(nV, aTolV);
2926 }//for (j=0; j<aNbC; ++j) {
2927 }//for (i=0; i<aNbFF; ++i) {
2929 UpdateCommonBlocksWithSDVertices();
2931 //=======================================================================
2932 //function : EstimatePaveOnCurve
2934 //=======================================================================
2935 Standard_Boolean BOPAlgo_PaveFiller::EstimatePaveOnCurve
2936 (const Standard_Integer nV,
2937 const BOPDS_Curve& aNC,
2938 const Standard_Real aTolR3D)
2940 Standard_Boolean bIsVertexOnLine;
2943 const TopoDS_Vertex& aV=*((TopoDS_Vertex *)&myDS->Shape(nV));
2944 const IntTools_Curve& aIC=aNC.Curve();
2946 bIsVertexOnLine=myContext->IsVertexOnLine(aV, aIC, aTolR3D, aT);
2947 return bIsVertexOnLine;
2950 //=======================================================================
2951 //function : CorrectToleranceOfSE
2953 //=======================================================================
2954 void BOPAlgo_PaveFiller::CorrectToleranceOfSE()
2956 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
2957 NCollection_IndexedDataMap<Standard_Integer,BOPDS_ListOfPaveBlock> aMVIPBs;
2958 TColStd_MapOfInteger aMVIToReduce;
2959 // Fence map to avoid repeated checking of the same edge
2960 BOPDS_MapOfPaveBlock aMPB;
2962 // 1. iterate on all sections F-F
2963 Standard_Integer aNb = aFFs.Length(), i;
2964 for (i = 0; i < aNb; ++i) {
2965 BOPDS_InterfFF& aFF = aFFs(i);
2967 BOPDS_VectorOfCurve& aVNC = aFF.ChangeCurves();
2968 Standard_Integer aNbC = aVNC.Length(), k;
2969 for (k = 0; k < aNbC; ++k) {
2970 BOPDS_Curve& aNC = aVNC(k);
2971 BOPDS_ListOfPaveBlock& aLPB = aNC.ChangePaveBlocks();
2972 BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPB);
2973 for (; aItLPB.More(); ) {
2974 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
2975 Standard_Integer nE;
2976 if (!aPB->HasEdge(nE)) {
2977 aLPB.Remove(aItLPB);
2981 if (!aMPB.Add(aPB)) {
2986 Standard_Boolean bIsReduced = Standard_False;
2987 if (aPB->OriginalEdge() < 0) {
2988 // It is possible that due to small angle between faces the
2989 // common zone between faces can be large and the tangential
2990 // tolerance of the curve will be large as well.
2991 // Here we're trying to reduce the tolerance of the section
2992 // edge using the valid tolerance of the edge.
2993 // Note, that if the pave block has created common block with
2994 // other edges its valid tolerance could have been changed to
2995 // cover all edges in common block (see PostTreatFF() method).
2996 Standard_Real aTolC = aNC.Tolerance();
2997 Standard_Real aTolTang = aNC.TangentialTolerance();
2998 if (aTolC < aTolTang) {
2999 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(nE));
3000 Standard_Real aTolE = BRep_Tool::Tolerance(aE);
3001 if (aTolC < aTolE) {
3002 // reduce edge tolerance
3003 reinterpret_cast<BRep_TEdge*>(aE.TShape().operator->())->Tolerance(aTolC);
3004 bIsReduced = Standard_True;
3009 // fill in the map vertex index - pave blocks
3010 for (Standard_Integer j=0; j < 2; j++) {
3011 Standard_Integer nV = (j == 0 ? aPB->Pave1().Index() : aPB->Pave2().Index());
3012 myDS->HasShapeSD(nV, nV);
3013 BOPDS_ListOfPaveBlock *pPBList = aMVIPBs.ChangeSeek(nV);
3015 pPBList = &aMVIPBs.ChangeFromIndex(aMVIPBs.Add(nV, BOPDS_ListOfPaveBlock()));
3017 pPBList->Append(aPB);
3019 aMVIToReduce.Add(nV);
3027 if (aMVIToReduce.IsEmpty()) {
3031 // 2. try to reduce tolerances of connected vertices
3032 // 2.1 find all other edges containing these connected vertices to avoid
3033 // reducing the tolerance to the value less than the tolerances of edges,
3034 // i.e. minimal tolerance for the vertex is the max tolerance of the
3035 // edges containing this vertex
3036 TColStd_DataMapOfIntegerReal aMVITol;
3037 BOPDS_VectorOfListOfPaveBlock& aPBP = myDS->ChangePaveBlocksPool();
3038 aNb = aPBP.Length();
3039 for (i = 0; i < aNb; ++i) {
3040 const BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
3041 BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPB);
3042 for (; aItLPB.More(); aItLPB.Next()) {
3043 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
3044 Standard_Integer nE;
3045 if (!aPB->HasEdge(nE)) {
3048 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(nE));
3049 Standard_Real aTolE = BRep_Tool::Tolerance(aE);
3051 Standard_Integer nV[2];
3052 aPB->Indices(nV[0], nV[1]);
3054 for (Standard_Integer j = 0; j < 2; j++) {
3055 if (aMVIToReduce.Contains(nV[j])) {
3056 Standard_Real *aMaxTol = aMVITol.ChangeSeek(nV[j]);
3058 aMVITol.Bind(nV[j], aTolE);
3060 else if (aTolE > *aMaxTol) {
3068 // 2.2 reduce tolerances if possible
3069 aNb = aMVIPBs.Extent();
3070 for (i = 1; i <= aNb; ++i) {
3071 Standard_Integer nV = aMVIPBs.FindKey(i);
3072 if (!aMVIToReduce.Contains(nV)) {
3076 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV));
3077 Standard_Real aTolV = BRep_Tool::Tolerance(aV);
3078 Standard_Real aMaxTol = aMVITol.IsBound(nV) ? aMVITol.Find(nV) : 0.;
3079 // it makes no sense to compute the real tolerance if it is
3080 // impossible to reduce the tolerance at least 0.1% of the current value
3081 if (aTolV - aMaxTol < 0.001 * aTolV) {
3085 // compute the maximal distance from the vertex to the adjacent edges
3086 gp_Pnt aP = BRep_Tool::Pnt(aV);
3088 // Avoid repeated checks
3089 BOPDS_MapOfPaveBlock aMPBFence;
3091 const BOPDS_ListOfPaveBlock& aLPB = aMVIPBs.FindFromIndex(i);
3092 BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPB);
3093 for (; aItLPB.More(); aItLPB.Next()) {
3094 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
3095 if (!aMPBFence.Add(aPB)) {
3098 Standard_Integer nE = aPB->Edge();
3099 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(nE));
3100 BRepAdaptor_Curve aC(aE);
3101 for (Standard_Integer iPave = 0; iPave < 2; ++iPave) {
3102 const BOPDS_Pave& aPave = !iPave ? aPB->Pave1() : aPB->Pave2();
3103 Standard_Integer nVSD = aPave.Index();
3104 myDS->HasShapeSD(nVSD, nVSD);
3109 gp_Pnt aPonE = aC.Value(aPave.Parameter());
3110 Standard_Real aDist = aP.Distance(aPonE);
3111 aDist += BRep_Tool::Tolerance(aE);
3112 if (aDist > aMaxTol) {
3118 if (aMaxTol < aTolV) {
3119 reinterpret_cast<BRep_TVertex*>(aV.TShape().operator->())->Tolerance(aMaxTol);
3124 //=======================================================================
3125 //function : PutSEInOtherFaces
3127 //=======================================================================
3128 void BOPAlgo_PaveFiller::PutSEInOtherFaces()
3130 // Try to intersect each section edge with the faces
3131 // not participated in its creation
3133 // 1. Get all section edges
3134 BOPDS_IndexedMapOfPaveBlock aMPBScAll;
3136 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
3137 Standard_Integer i, j, aNbFF = aFFs.Length();
3139 for (i = 0; i < aNbFF; ++i) {
3140 const BOPDS_VectorOfCurve& aVNC = aFFs(i).Curves();
3141 Standard_Integer aNbC = aVNC.Length();
3142 for (j = 0; j < aNbC; ++j) {
3143 const BOPDS_ListOfPaveBlock& aLPBC = aVNC(j).PaveBlocks();
3144 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPBC);
3145 for (; aItPB.More(); aItPB.Next()) {
3146 aMPBScAll.Add(aItPB.Value());
3151 Standard_Integer aNbPBSc = aMPBScAll.Extent();
3153 // 2. Loop for all faces and check each section curve
3154 Standard_Integer aNbS = myDS->NbSourceShapes();
3155 for (i = 0; i < aNbS; ++i) {
3156 const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(i);
3157 if (aSI.ShapeType() != TopAbs_FACE) {
3161 const TopoDS_Face& aF = (*(TopoDS_Face*)(&aSI.Shape()));
3162 BOPDS_FaceInfo& aFI = myDS->ChangeFaceInfo(i);
3164 // IN edges to add new ones
3165 BOPDS_IndexedMapOfPaveBlock& aMFPBIn = aFI.ChangePaveBlocksIn();
3166 // Section edges to check the participation of the face
3167 const BOPDS_IndexedMapOfPaveBlock& aMFPBSc = aFI.PaveBlocksSc();
3169 // Get vertices of the face to check that vertices of the
3170 // processed section edge belong to the face
3171 TColStd_MapOfInteger aMFVerts;
3172 // Get vertices from ON, IN and Sc pave blocks of the face
3173 for (j = 0; j < 3; ++j) {
3174 const BOPDS_IndexedMapOfPaveBlock& aMPB =
3175 !j ? aFI.PaveBlocksOn() : (j == 1 ? aMFPBIn : aMFPBSc);
3176 Standard_Integer aNbPB = aMPB.Extent();
3177 for (Standard_Integer k = 1; k <= aNbPB; ++k) {
3178 const Handle(BOPDS_PaveBlock)& aPB = aMPB(k);
3179 aMFVerts.Add(aPB->Pave1().Index());
3180 aMFVerts.Add(aPB->Pave2().Index());
3183 // Add ON, IN and Sc vertices of the face
3184 for (j = 0; j < 3; ++j) {
3185 const TColStd_MapOfInteger& aMFV = !j ? aFI.VerticesOn() :
3186 (j == 1 ? aFI.VerticesIn() : aFI.VerticesSc());
3187 TColStd_MapIteratorOfMapOfInteger aItMI(aMFV);
3188 for (; aItMI.More(); aItMI.Next()) {
3189 aMFVerts.Add(aItMI.Value());
3193 // Check each section edge for possible belonging to the face
3194 for (j = 1; j <= aNbPBSc; ++j) {
3195 const Handle(BOPDS_PaveBlock)& aPB = aMPBScAll(j);
3196 if (aMFPBSc.Contains(aPB)) {
3200 // Both vertices of the section edge should belong to the face
3201 if (!aMFVerts.Contains(aPB->Pave1().Index()) ||
3202 !aMFVerts.Contains(aPB->Pave2().Index())) {
3206 // Perform intersection
3207 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(aPB->Edge()));
3209 IntTools_EdgeFace anEFInt;
3210 anEFInt.SetEdge(aE);
3211 anEFInt.SetFace(aF);
3212 anEFInt.SetFuzzyValue(myFuzzyValue);
3213 anEFInt.SetRange(aPB->Pave1().Parameter(), aPB->Pave2().Parameter());
3214 anEFInt.SetContext(myContext);
3215 anEFInt.UseQuickCoincidenceCheck(Standard_True);
3218 const IntTools_SequenceOfCommonPrts& aCPrts = anEFInt.CommonParts();
3219 if ((aCPrts.Length() == 1) && (aCPrts(1).Type() == TopAbs_EDGE)) {
3220 Handle(BOPDS_CommonBlock) aCB;
3221 if (myDS->IsCommonBlock(aPB)) {
3222 aCB = myDS->CommonBlock(aPB);
3225 aCB = new BOPDS_CommonBlock;
3226 aCB->AddPaveBlock(aPB);