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();
365 //=======================================================================
366 //function : UpdateSavedTolerance
367 //purpose : Updates the saved tolerance of the vertices of the edge
368 // with new tolerance of edge
369 //=======================================================================
370 static void UpdateSavedTolerance(const BOPDS_PDS& theDS,
371 const Standard_Integer theNE,
372 const Standard_Real theTolNew,
373 TColStd_DataMapOfIntegerReal& theMVTol)
375 const TColStd_ListOfInteger& aSubShapes = theDS->ShapeInfo(theNE).SubShapes();
376 TColStd_ListIteratorOfListOfInteger itSS(aSubShapes);
377 for (; itSS.More(); itSS.Next())
379 const Standard_Integer nV = itSS.Value();
380 Standard_Real *pTolSaved = theMVTol.ChangeSeek(nV);
381 if (pTolSaved && *pTolSaved < theTolNew)
382 *pTolSaved = theTolNew;
386 //=======================================================================
387 //function : MakeBlocks
389 //=======================================================================
390 void BOPAlgo_PaveFiller::MakeBlocks()
392 if (myGlue != BOPAlgo_GlueOff) {
396 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
397 Standard_Integer aNbFF = aFFs.Length();
402 Standard_Boolean bExist, bValid2D;
403 Standard_Integer i, nF1, nF2, aNbC, aNbP, j;
404 Standard_Integer nV1, nV2;
405 Standard_Real aT1, aT2;
406 Handle(NCollection_BaseAllocator) aAllocator;
407 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
409 Handle(BOPDS_PaveBlock) aPBOut;
411 //-----------------------------------------------------scope f
413 NCollection_BaseAllocator::CommonBaseAllocator();
415 TColStd_ListOfInteger aLSE(aAllocator), aLBV(aAllocator);
416 TColStd_MapOfInteger aMVOnIn(100, aAllocator), aMVCommon(100, aAllocator),
417 aMVStick(100,aAllocator), aMVEF(100, aAllocator),
418 aMI(100, aAllocator), aMVBounds(100, aAllocator);
419 BOPDS_IndexedMapOfPaveBlock aMPBOnIn(100, aAllocator);
420 BOPDS_MapOfPaveBlock aMPBAdd(100, aAllocator), aMPBCommon;
421 BOPDS_ListOfPaveBlock aLPB(aAllocator);
422 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMSCPB(100, aAllocator);
423 TopTools_DataMapOfShapeInteger aMVI(100, aAllocator);
424 BOPDS_DataMapOfPaveBlockListOfPaveBlock aDMExEdges(100, aAllocator);
425 TColStd_DataMapOfIntegerReal aMVTol(100, aAllocator);
426 TColStd_DataMapOfIntegerInteger aDMNewSD(100, aAllocator);
427 TColStd_DataMapOfIntegerListOfInteger aDMVLV;
428 TColStd_DataMapOfIntegerListOfInteger aDMBV(100, aAllocator);
429 TColStd_DataMapIteratorOfDataMapOfIntegerReal aItMV;
430 BOPDS_IndexedMapOfPaveBlock aMicroPB(100, aAllocator);
431 TopTools_IndexedMapOfShape aVertsOnRejectedPB;
432 // Map of PaveBlocks with the faces to which it has to be added
433 BOPAlgo_DataMapOfPaveBlockListOfInteger aPBFacesMap;
435 for (i=0; i<aNbFF; ++i) {
439 BOPDS_InterfFF& aFF=aFFs(i);
440 aFF.Indices(nF1, nF2);
442 BOPDS_VectorOfPoint& aVP=aFF.ChangePoints();
444 BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
446 if (!aNbP && !aNbC) {
450 const TopoDS_Face& aF1=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
451 const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
453 Standard_Real aTolFF = Max(BRep_Tool::Tolerance(aF1), BRep_Tool::Tolerance(aF2));
455 BOPDS_FaceInfo& aFI1 = myDS->ChangeFaceInfo(nF1);
456 BOPDS_FaceInfo& aFI2 = myDS->ChangeFaceInfo(nF2);
466 myDS->SubShapesOnIn(nF1, nF2, aMVOnIn, aMVCommon, aMPBOnIn, aMPBCommon);
467 myDS->SharedEdges(nF1, nF2, aLSE, aAllocator);
469 Standard_Boolean bHasRealSectionEdge = Standard_False;
471 for (j=0; j<aNbP; ++j) {
473 BOPDS_CoupleOfPaveBlocks aCPB;
475 BOPDS_Point& aNP=aVP.ChangeValue(j);
476 const gp_Pnt& aP=aNP.Pnt();
478 bExist=IsExistingVertex(aP, aTolFF, aMVOnIn);
480 BOPTools_AlgoTools::MakeNewVertex(aP, aTolFF, aV);
482 aCPB.SetIndexInterf(i);
484 aMSCPB.Add(aV, aCPB);
491 GetStickVertices(nF1, nF2, aMVStick, aMVEF, aMI);
493 for (j = 0; j < aNbC; ++j) {
494 BOPDS_Curve& aNC = aVC.ChangeValue(j);
496 aNC.InitPaveBlock1();
498 // In order to avoid problems connected with
499 // extending tolerance of vertex while putting
500 // (e.g. see "bugs modalg_6 bug26789_1" test case),
501 // all not-common vertices will be checked by
502 // BndBoxes before putting. For common-vertices,
503 // filtering by BndBoxes is not necessary.
504 PutPavesOnCurve(aMVOnIn, aMVCommon, aNC, aMI, aMVEF, aMVTol, aDMVLV);
507 // if some E-F vertex was put on a curve due to large E-F intersection range,
508 // and it also was put on another curve correctly then remove this vertex from
509 // the first curve. Detect such case if the distance to curve exceeds aTolR3D.
510 FilterPavesOnCurves(aVC, aMVTol);
512 for (j = 0; j<aNbC; ++j) {
513 BOPDS_Curve& aNC=aVC.ChangeValue(j);
514 const IntTools_Curve& aIC=aNC.Curve();
516 PutStickPavesOnCurve(aF1, aF2, aMI, aNC, aMVStick, aMVTol, aDMVLV);
519 PutEFPavesOnCurve(aNC, aMI, aMVEF, aMVTol, aDMVLV);
522 if (aIC.HasBounds()) {
525 PutBoundPaveOnCurve(aF1, aF2, aNC, aLBV);
527 if (!aLBV.IsEmpty()) {
529 TColStd_ListIteratorOfListOfInteger aItI(aLBV);
530 for (; aItI.More(); aItI.Next()) {
531 aMVBounds.Add(aItI.Value());
535 }//for (j=0; j<aNbC; ++j) {
537 // Put closing pave if needed
538 for (j=0; j<aNbC; ++j) {
539 BOPDS_Curve& aNC=aVC.ChangeValue(j);
540 PutClosingPaveOnCurve (aNC);
543 // 3. Make section edges
544 for (j=0; j<aNbC; ++j) {
545 BOPDS_Curve& aNC=aVC.ChangeValue(j);
546 const IntTools_Curve& aIC=aNC.Curve();
547 Standard_Real aTolR3D = Max(aNC.Tolerance(), aNC.TangentialTolerance());
549 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
550 Handle(BOPDS_PaveBlock)& aPB1=aNC.ChangePaveBlock1();
553 aPB1->Update(aLPB, Standard_False);
555 aItLPB.Initialize(aLPB);
556 for (; aItLPB.More(); aItLPB.Next()) {
557 Handle(BOPDS_PaveBlock)& aPB=aItLPB.ChangeValue();
558 aPB->Indices(nV1, nV2);
559 aPB->Range (aT1, aT2);
561 if (fabs(aT1 - aT2) < Precision::PConfusion()) {
565 // Check validity of the block for the faces:
566 // classify bounding and middle points on the curve
567 // relatively both faces
568 bValid2D=myContext->IsValidBlockForFaces(aT1, aT2, aIC,
574 Standard_Integer nEOut;
575 Standard_Real aTolNew;
576 bExist = IsExistingPaveBlock(aPB, aNC, aLSE, nEOut, aTolNew);
579 // Update edge with new tolerance
580 UpdateEdgeTolerance(nEOut, aTolNew);
581 // Update aMVTol map with new tolerances of vertices
582 UpdateSavedTolerance(myDS, nEOut, aTolNew, aMVTol);
586 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
587 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
589 // check if the pave block has a valid range
590 Standard_Real aFirst, aLast;
591 if (!BRepLib::FindValidRange(GeomAdaptor_Curve(aIC.Curve()), aTolR3D,
592 aT1, BRep_Tool::Pnt(aV1), BRep_Tool::Tolerance(aV1),
593 aT2, BRep_Tool::Pnt(aV2), BRep_Tool::Tolerance(aV2),
596 // If the pave block does not have valid range, i.e. it is completely
597 // covered by the tolerance spheres of its vertices, it will be
598 // passed into post treatment process to fuse its vertices.
599 // The pave block itself will not be kept.
600 if (!aMVBounds.Contains(nV1) && !aMVBounds.Contains(nV2)) {
602 // keep vertices for post treatment
609 bExist = IsExistingPaveBlock(aPB, aNC, aTolR3D, aMPBOnIn, aMPBCommon, aPBOut, aTolNew);
612 Standard_Boolean bInF1 = (aFI1.PaveBlocksOn().Contains(aPBOut) ||
613 aFI1.PaveBlocksIn().Contains(aPBOut));
614 Standard_Boolean bInF2 = (aFI2.PaveBlocksOn().Contains(aPBOut) ||
615 aFI2.PaveBlocksIn().Contains(aPBOut));
616 if (!bInF1 || !bInF2)
618 // Update edge to touch both faces
619 Standard_Integer nE = aPBOut->Edge();
620 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(nE);
621 Standard_Real aTolE = BRep_Tool::Tolerance(aE);
622 if (aTolNew < aNC.Tolerance())
623 aTolNew = aNC.Tolerance(); // use real tolerance of intersection
624 if (aTolNew > aTolE) {
625 UpdateEdgeTolerance(nE, aTolNew);
626 // Update aMVTol map with new tolerances of vertices
627 UpdateSavedTolerance(myDS, nE, aTolNew, aMVTol);
630 // Face without pave block
631 const Standard_Integer nF = bInF1 ? nF2 : nF1;
632 TColStd_ListOfInteger* pFaces = aPBFacesMap.ChangeSeek(aPBOut);
634 pFaces = aPBFacesMap.Bound(aPBOut, TColStd_ListOfInteger());
635 // List is expected to be short, so we allow the check here
636 if (pFaces->IsEmpty() || !pFaces->Contains(nF))
639 if (aMPBAdd.Add(aPBOut))
641 // Add edge for processing as the section edge
642 PreparePostTreatFF(i, j, aPBOut, aMSCPB, aMVI, aLPBC);
643 // Try fusing the vertices of the existing pave block
644 // with the vertices put on the real section curve (except
645 // for technological vertices, which will be removed)
646 Standard_Integer nVOut1, nVOut2;
647 aPBOut->Indices(nVOut1, nVOut2);
648 if (nV1 != nVOut1 && nV1 != nVOut2 && !aMVBounds.Contains(nV1))
650 aVertsOnRejectedPB.Add(aV1);
652 if (nV2 != nVOut1 && nV2 != nVOut2 && !aMVBounds.Contains(nV2))
654 aVertsOnRejectedPB.Add(aV2);
662 BOPTools_AlgoTools::MakeEdge (aIC, aV1, aT1, aV2, aT2, aTolR3D, aES);
664 BOPTools_AlgoTools::MakePCurve(aES, aF1, aF2, aIC,
665 mySectionAttribute.PCurveOnS1(),
666 mySectionAttribute.PCurveOnS2(),
669 // Append the Pave Block to the Curve j
672 // Keep info for post treatment
673 BOPDS_CoupleOfPaveBlocks aCPB;
674 aCPB.SetIndexInterf(i);
676 aCPB.SetPaveBlock1(aPB);
678 aMSCPB.Add(aES, aCPB);
685 bHasRealSectionEdge = Standard_True;
689 }//for (j=0; j<aNbC; ++j) {
691 //back to previous tolerance values for unused vertices
692 //and forget about SD groups of such vertices
693 aItMV.Initialize(aMVTol);
694 for (; aItMV.More(); aItMV.Next()) {
696 Standard_Real aTol = aItMV.Value();
698 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV1);
699 const Handle(BRep_TVertex)& TV =
700 *((Handle(BRep_TVertex)*)&aV.TShape());
703 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV1);
704 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
706 BRepBndLib::Add(aV, aBoxDS);
707 aBoxDS.SetGap(aBoxDS.GetGap() + Precision::Confusion());
709 if (aDMVLV.IsBound(nV1))
713 ProcessExistingPaveBlocks(i, nF1, nF2, aMPBOnIn, aDMBV, aMSCPB, aMVI, aPBFacesMap, aMPBAdd);
715 // If the pair of faces has produced any real section edges
716 // it is necessary to check if these edges do not intersect
717 // any common IN edges of the faces. For that, all such edges
718 // are added for Post Treatment along with sections edges.
719 if (bHasRealSectionEdge) {
720 const BOPDS_IndexedMapOfPaveBlock& aMPBIn1 = aFI1.PaveBlocksIn();
721 const BOPDS_IndexedMapOfPaveBlock& aMPBIn2 = aFI2.PaveBlocksIn();
723 // For simplicity add all IN edges into the first set of section curves.
724 // These existing edges will be removed from the set on the post treatment
725 // stage in the UpdateFaceInfo function.
726 BOPDS_ListOfPaveBlock& aLPBC = aVC.ChangeValue(0).ChangePaveBlocks();
728 Standard_Integer aNbIn1 = aMPBIn1.Extent();
729 for (j = 1; j <= aNbIn1; ++j) {
730 const Handle(BOPDS_PaveBlock)& aPB = aMPBIn1(j);
731 if (aMPBIn2.Contains(aPB) && aMPBAdd.Add(aPB)) {
732 PreparePostTreatFF(i, 0, aPB, aMSCPB, aMVI, aLPBC);
736 }//for (i=0; i<aNbFF; ++i) {
738 // Remove "micro" section edges
739 RemoveMicroSectionEdges(aMSCPB, aMicroPB);
742 MakeSDVerticesFF(aDMVLV, aDMNewSD);
743 PostTreatFF(aMSCPB, aDMExEdges, aDMNewSD, aMicroPB, aVertsOnRejectedPB, aAllocator);
747 // reduce tolerances of section edges where it is appropriate
748 CorrectToleranceOfSE();
751 UpdateFaceInfo(aDMExEdges, aDMNewSD, aPBFacesMap);
752 //Update all pave blocks
753 UpdatePaveBlocks(aDMNewSD);
755 // Treat possible common zones by trying to put each section edge
756 // into all faces, not participated in creation of that edge, as IN edge
759 //-----------------------------------------------------scope t
769 //=======================================================================
770 //function : MakeSDVerticesFF
772 //=======================================================================
773 void BOPAlgo_PaveFiller::MakeSDVerticesFF
774 (const TColStd_DataMapOfIntegerListOfInteger& theDMVLV,
775 TColStd_DataMapOfIntegerInteger& theDMNewSD)
777 // Create a new SD vertex for each group of coinciding vertices
778 // and put new substitutions to theDMNewSD.
779 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItG(theDMVLV);
780 for (; aItG.More(); aItG.Next()) {
781 const TColStd_ListOfInteger& aList = aItG.Value();
782 // make SD vertices w/o creation of interfs
783 Standard_Integer nSD = MakeSDVertices(aList, Standard_False);
785 TColStd_ListIteratorOfListOfInteger aItL(aList);
786 for (; aItL.More(); aItL.Next()) {
787 Standard_Integer nV = aItL.Value();
788 theDMNewSD.Bind(nV, nSD);
793 //=======================================================================
794 //function : PostTreatFF
796 //=======================================================================
797 void BOPAlgo_PaveFiller::PostTreatFF
798 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMSCPB,
799 BOPDS_DataMapOfPaveBlockListOfPaveBlock& aDMExEdges,
800 TColStd_DataMapOfIntegerInteger& aDMNewSD,
801 const BOPDS_IndexedMapOfPaveBlock& theMicroPB,
802 const TopTools_IndexedMapOfShape& theVertsOnRejectedPB,
803 const Handle(NCollection_BaseAllocator)& theAllocator)
805 Standard_Integer aNbS = theMSCPB.Extent();
810 Standard_Boolean bHasPaveBlocks, bOld;
811 Standard_Integer nSx, nVSD, iX, iP, iC, j, nV, iV = 0, iE, k;
812 Standard_Integer aNbLPBx;
813 TopAbs_ShapeEnum aType;
815 TopTools_ListIteratorOfListOfShape aItLS;
816 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
818 Handle(BOPDS_PaveBlock) aPB1;
822 TopTools_ListOfShape aLS(theAllocator);
823 BOPAlgo_PaveFiller aPF(theAllocator);
824 aPF.SetIsPrimary(Standard_False);
825 aPF.SetNonDestructive(myNonDestructive);
827 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
828 Standard_Integer aNbFF = aFFs.Length();
831 //Find unused vertices
832 TopTools_IndexedMapOfShape VertsUnused;
833 TColStd_MapOfInteger IndMap;
834 for (Standard_Integer i = 0; i < aNbFF; i++)
836 BOPDS_InterfFF& aFF = aFFs(i);
837 Standard_Integer nF1, nF2;
838 aFF.Indices(nF1, nF2);
840 TColStd_MapOfInteger aMV, aMVEF, aMI;
841 GetStickVertices(nF1, nF2, aMV, aMVEF, aMI);
842 BOPDS_VectorOfCurve& aVC = aFF.ChangeCurves();
843 Standard_Integer aNbC = aVC.Length();
844 for (j = 0; j < aNbC; j++)
846 BOPDS_Curve& aNC = aVC.ChangeValue(j);
847 RemoveUsedVertices(aNC, aMV);
850 TColStd_MapIteratorOfMapOfInteger itmap(aMV);
851 for(; itmap.More(); itmap.Next())
853 Standard_Integer indV = itmap.Value();
854 const TopoDS_Shape& aVertex = myDS->Shape(indV);
855 if (IndMap.Add(indV))
856 VertsUnused.Add(aVertex);
858 VertsUnused.RemoveKey(aVertex);
861 /////////////////////
863 Standard_Integer aNbME = theMicroPB.Extent();
864 Standard_Integer aNbVOnRPB = theVertsOnRejectedPB.Extent();
866 if (aNbS==1 && (aNbME == 0) && (aNbVOnRPB == 0) && VertsUnused.IsEmpty()) {
867 const TopoDS_Shape& aS=theMSCPB.FindKey(1);
868 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromIndex(1);
870 aType=aS.ShapeType();
871 if (aType==TopAbs_VERTEX) {
872 aSI.SetShapeType(aType);
874 iV=myDS->Append(aSI);
876 iX=aCPB.IndexInterf();
878 BOPDS_InterfFF& aFF=aFFs(iX);
879 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
880 BOPDS_Point& aNP=aVNP(iP);
883 else if (aType==TopAbs_EDGE) {
884 aPB1=aCPB.PaveBlock1();
886 if (aPB1->HasEdge()) {
887 BOPDS_ListOfPaveBlock aLPBx;
889 aDMExEdges.Bind(aPB1, aLPBx);
891 aSI.SetShapeType(aType);
893 iE=myDS->Append(aSI);
901 // 1 prepare arguments
902 TopTools_MapOfShape anAddedSD;
903 for (k=1; k<=aNbS; ++k) {
904 const TopoDS_Shape& aS=theMSCPB.FindKey(k);
906 // add vertices-candidates for SD from the map aDMNewSD,
907 // so that they took part in fuse operation.
908 TopoDS_Iterator itV(aS);
909 for (; itV.More(); itV.Next())
911 const TopoDS_Shape& aVer = itV.Value();
912 Standard_Integer iVer = myDS->Index(aVer);
913 const Standard_Integer* pSD = aDMNewSD.Seek(iVer);
916 const TopoDS_Shape& aVSD = myDS->Shape(*pSD);
917 if (anAddedSD.Add(aVSD))
923 // The section edges considered as a micro should be
924 // specially treated - their vertices should be united and
925 // the edge itself should be removed. Thus, we add only
926 // its vertices into operation.
929 for (k = 1; k <= aNbME; ++k) {
930 Standard_Integer nVerts[2];
931 theMicroPB(k)->Indices(nVerts[0], nVerts[1]);
932 TopoDS_Vertex aVerts[2];
933 for (Standard_Integer i = 0; i < 2; ++i) {
934 const Standard_Integer* pSD = aDMNewSD.Seek(nVerts[i]);
935 aVerts[i] = TopoDS::Vertex(myDS->Shape(pSD ? *pSD : nVerts[i]));
936 if (anAddedSD.Add(aVerts[i]))
937 aLS.Append(aVerts[i]);
940 if (aVerts[0].IsSame(aVerts[1])) {
944 // make sure these vertices will be united
945 const gp_Pnt& aP1 = BRep_Tool::Pnt(aVerts[0]);
946 const gp_Pnt& aP2 = BRep_Tool::Pnt(aVerts[1]);
948 Standard_Real aDist = aP1.Distance(aP2);
949 Standard_Real aTolV1 = BRep_Tool::Tolerance(aVerts[0]);
950 Standard_Real aTolV2 = BRep_Tool::Tolerance(aVerts[1]);
952 aDist -= (aTolV1 + aTolV2);
955 aBB.UpdateVertex(aVerts[0], aTolV1 + aDist);
956 aBB.UpdateVertex(aVerts[1], aTolV2 + aDist);
960 // Add vertices put on the real section curves to unify them with the
961 // vertices of the edges, by which these sections curves have been rejected
962 // and with unused vertices
963 const TopTools_IndexedMapOfShape* VerMap [2] = {&theVertsOnRejectedPB, &VertsUnused};
964 for (Standard_Integer imap = 0; imap < 2; imap++)
966 Standard_Integer NbVer = VerMap[imap]->Extent();
967 for (Standard_Integer i = 1; i <= NbVer; ++i)
969 TopoDS_Shape aVer = VerMap[imap]->FindKey(i);
970 Standard_Integer iVer = myDS->Index(aVer);
971 const Standard_Integer* pSD = aDMNewSD.Seek(iVer);
973 aVer = myDS->Shape(*pSD);
975 if (anAddedSD.Add(aVer))
981 aPF.SetProgressIndicator(myProgressIndicator);
982 aPF.SetRunParallel(myRunParallel);
983 aPF.SetArguments(aLS);
985 if (aPF.HasErrors()) {
986 AddError (new BOPAlgo_AlertPostTreatFF);
991 // Map to store the real tolerance of the common block
992 // and avoid repeated computation of it
993 NCollection_DataMap<Handle(BOPDS_CommonBlock),
995 TColStd_MapTransientHasher> aMCBTol;
996 // Map to avoid creation of different pave blocks for
997 // the same intersection edge
998 NCollection_DataMap<Standard_Integer, Handle(BOPDS_PaveBlock)> aMEPB;
1000 aItLS.Initialize(aLS);
1001 for (; aItLS.More(); aItLS.Next()) {
1002 const TopoDS_Shape& aSx=aItLS.Value();
1003 nSx=aPDS->Index(aSx);
1004 const BOPDS_ShapeInfo& aSIx=aPDS->ShapeInfo(nSx);
1006 aType=aSIx.ShapeType();
1008 if (aType==TopAbs_VERTEX) {
1009 Standard_Boolean bIntersectionPoint = theMSCPB.Contains(aSx);
1011 if (aPDS->HasShapeSD(nSx, nVSD)) {
1012 aV=aPDS->Shape(nVSD);
1017 // index of new vertex in theDS -> iV
1018 iV = myDS->Index(aV);
1020 aSI.SetShapeType(aType);
1022 iV=myDS->Append(aSI);
1025 if (!bIntersectionPoint) {
1026 // save SD connection
1027 nSx = myDS->Index(aSx);
1028 aDMNewSD.Bind(nSx, iV);
1029 myDS->AddShapeSD(nSx, iV);
1032 // update FF interference
1033 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx);
1034 iX=aCPB.IndexInterf();
1036 BOPDS_InterfFF& aFF=aFFs(iX);
1037 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
1038 BOPDS_Point& aNP=aVNP(iP);
1041 }//if (aType==TopAbs_VERTEX) {
1043 else if (aType==TopAbs_EDGE) {
1044 bHasPaveBlocks=aPDS->HasPaveBlocks(nSx);
1045 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx);
1046 iX=aCPB.IndexInterf();
1048 aPB1=aCPB.PaveBlock1();
1050 bOld = aPB1->HasEdge();
1052 BOPDS_ListOfPaveBlock aLPBx;
1053 aDMExEdges.Bind(aPB1, aLPBx);
1056 if (!bHasPaveBlocks) {
1058 aDMExEdges.ChangeFind(aPB1).Append(aPB1);
1061 aSI.SetShapeType(aType);
1063 iE = myDS->Append(aSI);
1069 BOPDS_InterfFF& aFF=aFFs(iX);
1070 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
1071 BOPDS_Curve& aNC=aVNC(iC);
1072 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
1074 // check if edge occurred to be micro edge;
1075 // note we check not the edge aSx itself, but its image in aPDS
1076 const BOPDS_ListOfPaveBlock& aLPBx = aPDS->PaveBlocks(nSx);
1077 aNbLPBx = aLPBx.Extent();
1078 if (aPDS->HasPaveBlocks(nSx) &&
1079 (aNbLPBx == 0 || (aNbLPBx == 1 && !aLPBx.First()->HasShrunkData()))) {
1080 BOPDS_ListIteratorOfListOfPaveBlock it(aLPBC);
1081 for (; it.More(); it.Next()) {
1082 if (it.Value() == aPB1) {
1090 if (bOld && !aNbLPBx) {
1091 aDMExEdges.ChangeFind(aPB1).Append(aPB1);
1096 aItLPB.Initialize(aLPBC);
1097 for (; aItLPB.More(); aItLPB.Next()) {
1098 const Handle(BOPDS_PaveBlock)& aPBC=aItLPB.Value();
1100 aLPBC.Remove(aItLPB);
1107 aItLPB.Initialize(aLPBx);
1108 for (; aItLPB.More(); aItLPB.Next()) {
1109 const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value();
1110 const Handle(BOPDS_PaveBlock) aPBRx=aPDS->RealPaveBlock(aPBx);
1112 // update vertices of paves
1113 aPave[0] = aPBx->Pave1();
1114 aPave[1] = aPBx->Pave2();
1115 for (j=0; j<2; ++j) {
1116 nV = aPave[j].Index();
1117 aV = aPDS->Shape(nV);
1118 // index of new vertex in myDS -> iV
1119 iV = myDS->Index(aV);
1121 aSI.SetShapeType(TopAbs_VERTEX);
1123 iV = myDS->Append(aSI);
1125 const BOPDS_Pave& aP1 = !j ? aPB1->Pave1() : aPB1->Pave2();
1126 if (aP1.Index() != iV) {
1127 if (aP1.Parameter() == aPave[j].Parameter()) {
1128 aDMNewSD.Bind(aP1.Index(), iV);
1129 myDS->AddShapeSD(aP1.Index(), iV);
1132 // check aPDS to have the SD connection between these vertices
1133 const TopoDS_Shape& aVPave = myDS->Shape(aP1.Index());
1134 Standard_Integer nVnewSD, nVnew = aPDS->Index(aVPave);
1135 if (aPDS->HasShapeSD(nVnew, nVnewSD)) {
1136 if (nVnewSD == nV) {
1137 aDMNewSD.Bind(aP1.Index(), iV);
1138 myDS->AddShapeSD(aP1.Index(), iV);
1144 aPave[j].SetIndex(iV);
1148 aE=aPDS->Shape(aPBRx->Edge());
1149 iE = myDS->Index(aE);
1151 aSI.SetShapeType(aType);
1153 iE=myDS->Append(aSI);
1156 // update real edge tolerance according to distances in common block if any
1157 if (aPDS->IsCommonBlock(aPBRx)) {
1158 const Handle(BOPDS_CommonBlock)& aCB = aPDS->CommonBlock(aPBRx);
1159 Standard_Real *pTol = aMCBTol.ChangeSeek(aCB);
1161 Standard_Real aTol = BOPAlgo_Tools::ComputeToleranceOfCB(aCB, aPDS, aPF.Context());
1162 pTol = aMCBTol.Bound(aCB, aTol);
1165 if (aNC.Tolerance() < *pTol) {
1166 aNC.SetTolerance(*pTol);
1169 // append new PaveBlock to aLPBC
1170 Handle(BOPDS_PaveBlock) *pPBC = aMEPB.ChangeSeek(iE);
1172 pPBC = aMEPB.Bound(iE, new BOPDS_PaveBlock());
1173 BOPDS_Pave aPaveR1, aPaveR2;
1174 aPaveR1 = aPBRx->Pave1();
1175 aPaveR2 = aPBRx->Pave2();
1176 aPaveR1.SetIndex(myDS->Index(aPDS->Shape(aPaveR1.Index())));
1177 aPaveR2.SetIndex(myDS->Index(aPDS->Shape(aPaveR2.Index())));
1179 (*pPBC)->SetPave1(aPaveR1);
1180 (*pPBC)->SetPave2(aPaveR2);
1181 (*pPBC)->SetEdge(iE);
1185 (*pPBC)->SetOriginalEdge(aPB1->OriginalEdge());
1186 aDMExEdges.ChangeFind(aPB1).Append(*pPBC);
1189 aLPBC.Append(*pPBC);
1194 }//else if (aType==TopAbs_EDGE)
1195 }//for (; aItLS.More(); aItLS.Next()) {
1197 // Update SD for vertices that did not participate in operation
1198 TColStd_DataMapOfIntegerInteger::Iterator itDM(aDMNewSD);
1199 for (; itDM.More(); itDM.Next())
1201 const Standard_Integer* pSD = aDMNewSD.Seek(itDM.Value());
1204 itDM.ChangeValue() = *pSD;
1205 myDS->AddShapeSD(itDM.Key(), *pSD);
1211 //=======================================================================
1212 //function : UpdateFaceInfo
1214 //=======================================================================
1215 void BOPAlgo_PaveFiller::UpdateFaceInfo
1216 (BOPDS_DataMapOfPaveBlockListOfPaveBlock& theDME,
1217 const TColStd_DataMapOfIntegerInteger& theDMV,
1218 const BOPAlgo_DataMapOfPaveBlockListOfInteger& thePBFacesMap)
1220 Standard_Integer i, j, nV1, nF1, nF2,
1222 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
1223 TColStd_MapOfInteger aMF;
1225 // Unify pave blocks of the existing edges united on the post-treat stage
1226 NCollection_DataMap<Standard_Integer, BOPDS_ListOfPaveBlock> anEdgeLPB;
1228 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
1229 aNbFF=aFFs.Length();
1230 //1. Sections (curves, points);
1231 for (i=0; i<aNbFF; ++i) {
1232 BOPDS_InterfFF& aFF=aFFs(i);
1233 aFF.Indices(nF1, nF2);
1235 BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
1236 BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
1238 // 1.1. Section edges
1239 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
1241 for (j=0; j<aNbC; ++j) {
1242 BOPDS_Curve& aNC=aVNC(j);
1243 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
1245 // Add section edges to face info
1246 aItLPB.Initialize(aLPBC);
1247 for (; aItLPB.More(); ) {
1248 const Handle(BOPDS_PaveBlock)& aPB=aItLPB.Value();
1250 // Treat existing pave blocks
1251 if (theDME.IsBound(aPB)) {
1252 BOPDS_ListOfPaveBlock& aLPB=theDME.ChangeFind(aPB);
1253 UpdateExistingPaveBlocks(aPB, aLPB, thePBFacesMap);
1255 BOPDS_ListIteratorOfListOfPaveBlock itLPB(aLPB);
1256 for (; itLPB.More(); itLPB.Next())
1258 const Standard_Integer nE = itLPB.Value()->Edge();
1259 BOPDS_ListOfPaveBlock* pLPBOnE = anEdgeLPB.ChangeSeek(nE);
1261 pLPBOnE = anEdgeLPB.Bound(nE, BOPDS_ListOfPaveBlock());
1262 pLPBOnE->Append(itLPB.Value());
1265 aLPBC.Remove(aItLPB);
1269 aFI1.ChangePaveBlocksSc().Add(aPB);
1270 aFI2.ChangePaveBlocksSc().Add(aPB);
1271 // Add edge-PB connection
1272 const Standard_Integer nE = aPB->Edge();
1273 BOPDS_ListOfPaveBlock* pLPBOnE = anEdgeLPB.ChangeSeek(nE);
1275 pLPBOnE = anEdgeLPB.Bound(nE, BOPDS_ListOfPaveBlock());
1276 pLPBOnE->Append(aPB);
1282 // 1.2. Section vertices
1283 const BOPDS_VectorOfPoint& aVNP=aFF.Points();
1285 for (j=0; j<aNbP; ++j) {
1286 const BOPDS_Point& aNP=aVNP(j);
1291 aFI1.ChangeVerticesSc().Add(nV1);
1292 aFI2.ChangeVerticesSc().Add(nV1);
1299 Standard_Boolean bNewCB = Standard_False;
1301 // Unify pave blocks of the existing edges united on the post-treat stage
1302 // by making new Common blocks from them
1303 NCollection_DataMap<Standard_Integer,
1304 BOPDS_ListOfPaveBlock>::Iterator itDM(anEdgeLPB);
1305 for (; itDM.More(); itDM.Next())
1307 const BOPDS_ListOfPaveBlock& aLPB = itDM.Value();
1308 if (aLPB.Extent() == 1)
1311 bNewCB = Standard_True;
1313 // Find or create common block
1314 Handle(BOPDS_CommonBlock) aCB;
1315 // Collect all faces attached to common blocks
1316 TColStd_MapOfInteger aMFaces;
1317 // Collect all pave blocks attached to common blocks
1318 BOPDS_IndexedMapOfPaveBlock aMPaveBlocks;
1320 BOPDS_ListIteratorOfListOfPaveBlock itLPB(aLPB);
1321 for (; itLPB.More(); itLPB.Next())
1323 const Handle(BOPDS_PaveBlock)& aPB = itLPB.Value();
1324 aMPaveBlocks.Add(aPB);
1326 if (myDS->IsCommonBlock(aPB))
1328 Handle(BOPDS_CommonBlock) aPBCB = myDS->CommonBlock(aPB);
1330 const BOPDS_ListOfPaveBlock& aLPBOnCB = aPBCB->PaveBlocks();
1331 for (BOPDS_ListOfPaveBlock::Iterator it(aLPBOnCB); it.More(); it.Next())
1332 aMPaveBlocks.Add(it.Value());
1335 const TColStd_ListOfInteger& aLFacesOnCB = aPBCB->Faces();
1336 for (TColStd_ListOfInteger::Iterator it(aLFacesOnCB); it.More(); it.Next())
1337 aMFaces.Add(it.Value());
1346 // None of the pave blocks in the list is a common block,
1347 // so create the new one.
1348 aCB = new BOPDS_CommonBlock;
1349 aCB->SetPaveBlocks(aLPB);
1350 itLPB.Initialize(aLPB);
1351 for (; itLPB.More(); itLPB.Next())
1353 const Handle(BOPDS_PaveBlock)& aPB = itLPB.Value();
1354 myDS->SetCommonBlock(aPB, aCB);
1359 // Update common block with new pave blocks
1360 BOPDS_ListOfPaveBlock aLPBNew;
1362 const Standard_Integer aNbPB = aMPaveBlocks.Extent();
1363 for (Standard_Integer iPB = 1; iPB <= aNbPB; ++iPB)
1365 const Handle(BOPDS_PaveBlock)& aPB = aMPaveBlocks(iPB);
1366 myDS->SetCommonBlock(aPB, aCB);
1367 aLPBNew.Append(aPB);
1370 aCB->SetPaveBlocks(aLPBNew);
1372 // Update faces of the common block
1373 TColStd_ListOfInteger aLFaces;
1374 for (TColStd_MapOfInteger::Iterator it(aMFaces); it.More(); it.Next())
1375 aLFaces.Append(it.Value());
1376 aCB->SetFaces(aLFaces);
1381 Standard_Boolean bVerts = theDMV.Extent() > 0;
1382 Standard_Boolean bEdges = theDME.Extent() > 0 || bNewCB;
1384 if (!bVerts && !bEdges) {
1388 // 2. Update Face Info information with new vertices and new
1389 // pave blocks created in PostTreatFF from existing ones
1390 Standard_Integer nV2;
1391 TColStd_MapIteratorOfMapOfInteger aItMF;
1392 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aItMV;
1394 aItMF.Initialize(aMF);
1395 for (; aItMF.More(); aItMF.Next()) {
1396 nF1 = aItMF.Value();
1398 BOPDS_FaceInfo& aFI = myDS->ChangeFaceInfo(nF1);
1400 // 2.1. Update information about vertices
1403 TColStd_MapOfInteger& aMVOn = aFI.ChangeVerticesOn();
1404 TColStd_MapOfInteger& aMVIn = aFI.ChangeVerticesIn();
1406 aItMV.Initialize(theDMV);
1407 for (; aItMV.More(); aItMV.Next())
1410 nV2 = aItMV.Value();
1412 if (aMVOn.Remove(nV1))
1415 if (aMVIn.Remove(nV1))
1417 } // for (; aItMV.More(); aItMV.Next()) {
1420 // 2.2. Update information about pave blocks
1423 BOPDS_MapOfPaveBlock aMPBFence;
1424 BOPDS_IndexedMapOfPaveBlock* pMPB[] = { &aFI.ChangePaveBlocksOn(),
1425 &aFI.ChangePaveBlocksIn(),
1426 &aFI.ChangePaveBlocksSc() };
1427 for (i = 0; i < 3; ++i)
1429 BOPDS_IndexedMapOfPaveBlock aMPBCopy = *pMPB[i];
1431 const Standard_Integer aNbPB = aMPBCopy.Extent();
1432 for (j = 1; j <= aNbPB; ++j)
1434 const Handle(BOPDS_PaveBlock)& aPB = aMPBCopy(j);
1435 const BOPDS_ListOfPaveBlock* pLPB = theDME.Seek(aPB);
1436 if (pLPB && !pLPB->IsEmpty())
1438 aItLPB.Initialize(*pLPB);
1439 for (; aItLPB.More(); aItLPB.Next())
1441 const Handle(BOPDS_PaveBlock)& aPB1 = aItLPB.Value();
1442 const Handle(BOPDS_PaveBlock)& aPBR = myDS->RealPaveBlock(aPB1);
1443 if (aMPBFence.Add(aPBR))
1449 const Handle(BOPDS_PaveBlock)& aPBR = myDS->RealPaveBlock(aPB);
1450 if (aMPBFence.Add(aPBR))
1453 } // for (j = 1; j <= aNbPB; ++j) {
1454 } // for (i = 0; i < 2; ++i) {
1458 //=======================================================================
1459 //function : IsExistingVertex
1461 //=======================================================================
1462 Standard_Boolean BOPAlgo_PaveFiller::IsExistingVertex
1464 const Standard_Real theTolR3D,
1465 const TColStd_MapOfInteger& aMVOnIn)const
1467 Standard_Boolean bRet;
1468 Standard_Integer nV, iFlag;
1469 Standard_Real aTolCheck;
1472 TColStd_MapIteratorOfMapOfInteger aIt;
1474 aTolCheck = theTolR3D + myFuzzyValue;
1478 aBoxP.Enlarge(theTolR3D);
1480 aIt.Initialize(aMVOnIn);
1481 for (; aIt.More(); aIt.Next()) {
1483 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1484 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&aSIV.Shape()));
1485 const Bnd_Box& aBoxV=aSIV.Box();
1487 if (!aBoxP.IsOut(aBoxV)) {
1488 iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP, aTolCheck);
1496 //=======================================================================
1497 //function : IsExistingPaveBlock
1499 //=======================================================================
1500 Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock
1501 (const Handle(BOPDS_PaveBlock)& thePB,
1502 const BOPDS_Curve& theNC,
1503 const TColStd_ListOfInteger& theLSE,
1504 Standard_Integer& theNEOut,
1505 Standard_Real& theTolNew)
1507 if (theLSE.IsEmpty())
1508 return Standard_False;
1510 Standard_Real aT1, aT2, aTm, aTx, aTolE, aTolCheck, aTol, aDist;
1511 Standard_Integer nE, iFlag, nV1, nV2;
1514 TColStd_ListIteratorOfListOfInteger aItLI;
1516 thePB->Range(aT1, aT2);
1517 thePB->Indices(nV1, nV2);
1518 const TopoDS_Vertex &aV1 = TopoDS::Vertex(myDS->Shape(nV1)),
1519 &aV2 = TopoDS::Vertex(myDS->Shape(nV2));
1520 const Standard_Real aTolV1 = BRep_Tool::Tolerance(aV1),
1521 aTolV2 = BRep_Tool::Tolerance(aV2);
1523 aTol = Max(aTolV1, aTolV2);
1525 aTm=IntTools_Tools::IntermediatePoint (aT1, aT2);
1526 theNC.Curve().D0(aTm, aPm);
1528 aBoxPm.Enlarge(aTol);
1530 aItLI.Initialize(theLSE);
1531 for (; aItLI.More(); aItLI.Next()) {
1535 const BOPDS_ShapeInfo& aSIE=myDS->ChangeShapeInfo(nE);
1536 const Bnd_Box& aBoxE=aSIE.Box();
1537 if (!aBoxE.IsOut(aBoxPm)) {
1538 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape()));
1539 aTolE = BRep_Tool::Tolerance(aE);
1540 aTolCheck = Max(aTolE, aTol) + myFuzzyValue;
1541 iFlag = myContext->ComputePE(aPm, aTolCheck, aE, aTx, aDist);
1546 return Standard_True;
1550 return Standard_False;
1553 //=======================================================================
1554 //function : IsExistingPaveBlock
1556 //=======================================================================
1557 Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock
1558 (const Handle(BOPDS_PaveBlock)& thePB,
1559 const BOPDS_Curve& theNC,
1560 const Standard_Real theTolR3D,
1561 const BOPDS_IndexedMapOfPaveBlock& theMPBOnIn,
1562 const BOPDS_MapOfPaveBlock& theMPBCommon,
1563 Handle(BOPDS_PaveBlock)& aPBOut,
1564 Standard_Real& theTolNew)
1566 Standard_Boolean bRet;
1567 Standard_Real aT1, aT2, aTm, aTx, aTolCheck;
1568 Standard_Integer nSp, iFlag1, iFlag2, nV11, nV12, nV21, nV22, i, aNbPB;
1569 gp_Pnt aP1, aPm, aP2;
1570 Bnd_Box aBoxP1, aBoxPm, aBoxP2, aBoxTmp;
1572 bRet=Standard_False;
1573 aTolCheck = theTolR3D + myFuzzyValue;
1574 const IntTools_Curve& aIC=theNC.Curve();
1576 thePB->Range(aT1, aT2);
1577 thePB->Indices(nV11, nV12);
1578 const Standard_Real aTolV11 = BRep_Tool::Tolerance(TopoDS::Vertex(myDS->Shape(nV11)));
1579 const Standard_Real aTolV12 = BRep_Tool::Tolerance(TopoDS::Vertex(myDS->Shape(nV12)));
1580 const Standard_Real aTolV1 = Max(aTolV11, aTolV12) + myFuzzyValue;
1585 aBoxP1.Enlarge(aTolV11);
1586 //intermediate point
1587 aTm=IntTools_Tools::IntermediatePoint (aT1, aT2);
1593 aBoxP2.Enlarge(aTolV12);
1595 // Look for the existing pave block closest to the section curve
1596 theTolNew = ::RealLast();
1598 aNbPB = theMPBOnIn.Extent();
1599 for (i = 1; i <= aNbPB; ++i) {
1600 const Handle(BOPDS_PaveBlock)& aPB = theMPBOnIn(i);
1601 aPB->Indices(nV21, nV22);
1602 const Standard_Real aTolV21 = BRep_Tool::Tolerance(TopoDS::Vertex(myDS->Shape(nV21)));
1603 const Standard_Real aTolV22 = BRep_Tool::Tolerance(TopoDS::Vertex(myDS->Shape(nV22)));
1604 const Standard_Real aTolV2 = Max(aTolV21, aTolV22) + myFuzzyValue;
1608 const BOPDS_ShapeInfo& aSISp=myDS->ChangeShapeInfo(nSp);
1609 const TopoDS_Edge& aSp=(*(TopoDS_Edge *)(&aSISp.Shape()));
1610 const Bnd_Box& aBoxSp=aSISp.Box();
1612 iFlag1 = (nV11 == nV21 || nV11 == nV22) ? 2 :
1613 (!aBoxSp.IsOut(aBoxP1) ? 1 : 0);
1614 iFlag2 = (nV12 == nV21 || nV12 == nV22) ? 2 :
1615 (!aBoxSp.IsOut(aBoxP2) ? 1 : 0);
1616 if (iFlag1 && iFlag2) {
1617 Standard_Real aDist = 0.;
1619 Standard_Real aRealTol = aTolCheck;
1620 if (myDS->IsCommonBlock(aPB))
1622 aRealTol = Max(aRealTol, Max(aTolV1, aTolV2));
1623 if (theMPBCommon.Contains(aPB))
1624 // for an edge, which is a common block with a face,
1625 // increase the chance to coincide with section curve
1630 aBoxTmp.Enlarge(aRealTol);
1632 Standard_Real aDistToSp = 0.;
1633 if (aBoxSp.IsOut(aBoxTmp) || myContext->ComputePE(aPm,
1641 iFlag1 = !myContext->ComputePE(aP1, aRealTol, aSp, aTx, aDist);
1642 if (iFlag1 && aDistToSp < aDist)
1647 iFlag2 = !myContext->ComputePE(aP2, aRealTol, aSp, aTx, aDist);
1648 if (iFlag2 && aDistToSp < aDist)
1652 if (iFlag1 && iFlag2)
1654 if (aDistToSp < theTolNew)
1657 theTolNew = aDistToSp;
1658 bRet = Standard_True;
1666 //=======================================================================
1669 //=======================================================================
1670 static void getBoundPaves(const BOPDS_DS* theDS,
1672 Standard_Integer theNV[2])
1674 theNV[0] = theNV[1] = -1;
1676 // get extreme paves
1677 Handle(BOPDS_PaveBlock)& aPB = theNC.ChangePaveBlock1();
1678 const BOPDS_ListOfPave& aLP = aPB->ExtPaves();
1679 Standard_Integer aNbEP = aLP.Extent();
1682 Standard_Real aTmin = RealLast();
1683 Standard_Real aTmax = -aTmin;
1684 for (BOPDS_ListIteratorOfListOfPave aItLP(aLP); aItLP.More(); aItLP.Next())
1686 const BOPDS_Pave& aPv = aItLP.Value();
1687 Standard_Integer nV;
1689 aPv.Contents(nV, aTV);
1691 theNV[0] = aPv.Index();
1695 theNV[1] = aPv.Index();
1700 // compare extreme vertices with ends of the curve
1701 const IntTools_Curve& aIC = theNC.Curve();
1702 Standard_Real aT[2];
1704 aIC.Bounds(aT[0], aT[1], aP[0], aP[1]);
1705 Standard_Real aTol = Max(theNC.Tolerance(), theNC.TangentialTolerance());
1706 aTol += Precision::Confusion();
1707 for (Standard_Integer j = 0; j < 2; ++j)
1709 const BOPDS_ShapeInfo& aSIV = theDS->ShapeInfo(theNV[j]);
1710 const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&aSIV.Shape()));
1711 Standard_Integer iFlag = BOPTools_AlgoTools::ComputeVV(aV, aP[j], aTol);
1717 //=======================================================================
1718 //function : PutBoundPaveOnCurve
1720 //=======================================================================
1721 void BOPAlgo_PaveFiller::PutBoundPaveOnCurve(const TopoDS_Face& aF1,
1722 const TopoDS_Face& aF2,
1724 TColStd_ListOfInteger& aLVB)
1726 const IntTools_Curve& aIC=aNC.Curve();
1727 Standard_Real aT[2];
1729 aIC.Bounds(aT[0], aT[1], aP[0], aP[1]);
1730 Standard_Real aTolR3D = Max(aNC.Tolerance(), aNC.TangentialTolerance());
1731 Handle(BOPDS_PaveBlock)& aPB = aNC.ChangePaveBlock1();
1732 // Get numbers of vertices assigned to the ends of the curve
1733 Standard_Integer aBndNV[2];
1734 getBoundPaves(myDS, aNC, aBndNV);
1736 Standard_Real aTolVnew = Precision::Confusion();
1737 for (Standard_Integer j = 0; j<2; ++j)
1741 // no vertex on this end
1742 if (j && aP[1].IsEqual(aP[0], aTolVnew)) {
1743 //if curve is closed, process only one bound
1746 Standard_Boolean bVF = myContext->IsValidPointForFaces(aP[j], aF1, aF2, aTolR3D);
1751 BOPTools_AlgoTools::MakeNewVertex(aP[j], aTolR3D, aVn);
1752 BOPTools_AlgoTools::UpdateVertex(aIC, aT[j], aVn);
1753 aTolVnew = BRep_Tool::Tolerance(aVn);
1755 BOPDS_ShapeInfo aSIVn;
1756 aSIVn.SetShapeType(TopAbs_VERTEX);
1757 aSIVn.SetShape(aVn);
1759 Bnd_Box& aBox = aSIVn.ChangeBox();
1760 BRepBndLib::Add(aVn, aBox);
1761 aBox.SetGap(aBox.GetGap() + Precision::Confusion());
1763 Standard_Integer nVn = myDS->Append(aSIVn);
1767 aPn.SetParameter(aT[j]);
1768 aPB->AppendExtPave(aPn);
1775 //=======================================================================
1776 //function : PutPavesOnCurve
1778 //=======================================================================
1779 void BOPAlgo_PaveFiller::PutPavesOnCurve(const TColStd_MapOfInteger& theMVOnIn,
1780 const TColStd_MapOfInteger& theMVCommon,
1782 const TColStd_MapOfInteger& theMI,
1783 const TColStd_MapOfInteger& theMVEF,
1784 TColStd_DataMapOfIntegerReal& theMVTol,
1785 TColStd_DataMapOfIntegerListOfInteger& theDMVLV)
1787 Standard_Integer nV;
1788 TColStd_MapIteratorOfMapOfInteger aIt;
1790 const Bnd_Box& aBoxC = theNC.Box();
1791 const Standard_Real aTolR3D = Max(theNC.Tolerance(), theNC.TangentialTolerance());
1793 //Put EF vertices first
1794 aIt.Initialize(theMVEF);
1795 for (; aIt.More(); aIt.Next())
1798 PutPaveOnCurve(nV, aTolR3D, theNC, theMI, theMVTol, theDMVLV, 2);
1801 //Put all other vertices
1802 aIt.Initialize(theMVOnIn);
1803 for (; aIt.More(); aIt.Next())
1806 if (theMVEF.Contains(nV))
1811 if (!theMVCommon.Contains(nV))
1813 const BOPDS_ShapeInfo& aSIV = myDS->ShapeInfo(nV);
1814 const Bnd_Box& aBoxV = aSIV.Box();
1816 if (aBoxC.IsOut(aBoxV))
1820 if (!myDS->IsNewShape(nV))
1826 PutPaveOnCurve(nV, aTolR3D, theNC, theMI, theMVTol, theDMVLV, 1);
1830 //=======================================================================
1831 //function : FilterPavesOnCurves
1833 //=======================================================================
1835 struct PaveBlockDist {
1836 Handle(BOPDS_PaveBlock) PB;
1837 Standard_Real SquareDist; // square distance from vertex to the paveblock
1838 Standard_Real SinAngle; // sinus of angle between projection vector
1839 // and tangent at projection point
1840 Standard_Real Tolerance; // tolerance of the section curve
1843 void BOPAlgo_PaveFiller::FilterPavesOnCurves(const BOPDS_VectorOfCurve& theVNC,
1844 TColStd_DataMapOfIntegerReal& theMVTol)
1846 // For each vertex found in ExtPaves of pave blocks of section curves
1847 // collect list of pave blocks with distance to the curve
1848 NCollection_IndexedDataMap<Standard_Integer,NCollection_List<PaveBlockDist> > aIDMVertPBs;
1850 const Standard_Real anEps = gp::Resolution();
1851 for (i = 0; i < theVNC.Length(); ++i)
1853 const BOPDS_Curve& aNC = theVNC(i);
1854 const IntTools_Curve& aIC = aNC.Curve();
1855 const Standard_Real aTolR3D = Max(aNC.Tolerance(), aNC.TangentialTolerance());
1856 GeomAdaptor_Curve aGAC(aIC.Curve());
1857 const Handle(BOPDS_PaveBlock)& aPB = aNC.PaveBlocks().First();
1858 const BOPDS_ListOfPave& aPaves = aPB->ExtPaves();
1859 BOPDS_ListOfPave::Iterator itPaves(aPaves);
1860 for (; itPaves.More(); itPaves.Next())
1862 const BOPDS_Pave& aPave = itPaves.Value();
1863 Standard_Integer nV = aPave.Index();
1864 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV));
1865 // compute distance from vertex to the point on curve with vertex parameter
1866 gp_Pnt aPV = BRep_Tool::Pnt(aV);
1867 Standard_Real aPar = aPave.Parameter();
1870 aGAC.D1(aPar, aPonC, aD1);
1871 gp_Vec aProjVec(aPV, aPonC);
1872 Standard_Real aSqDist = aProjVec.SquareMagnitude();
1873 Standard_Real aSqD1Mod = aD1.SquareMagnitude();
1874 Standard_Real aSin = aProjVec.CrossSquareMagnitude(aD1);
1875 if (aSqDist > anEps && aSqD1Mod > anEps)
1876 aSin = sqrt(aSin / aSqDist / aSqD1Mod);
1877 NCollection_List<PaveBlockDist>* pList = aIDMVertPBs.ChangeSeek(nV);
1879 pList = &aIDMVertPBs.ChangeFromIndex(aIDMVertPBs.Add(nV, NCollection_List<PaveBlockDist>()));
1880 PaveBlockDist aPBD = { aPB, aSqDist, aSin, aTolR3D };
1881 pList->Append(aPBD);
1885 // Process each vertex
1886 const Standard_Real aSinAngleMin = 0.5; // angle below which projection is suspicious
1887 for (i = 1; i <= aIDMVertPBs.Extent(); i++)
1889 Standard_Integer nV = aIDMVertPBs.FindKey(i);
1890 const NCollection_List<PaveBlockDist>& aList = aIDMVertPBs(i);
1891 // Find a pave with minimal distance
1892 Standard_Real aMinDist = RealLast();
1893 Handle(BOPDS_PaveBlock) aPBMinDist;
1894 NCollection_List<PaveBlockDist>::Iterator itL(aList);
1895 for (; itL.More(); itL.Next())
1897 const PaveBlockDist& aPBD = itL.Value();
1898 if (aPBD.SquareDist < aMinDist)
1900 aMinDist = aPBD.SquareDist;
1901 aPBMinDist = aPBD.PB;
1904 // Remove a vertex from a pave block if the distance is greater than the tolerance
1905 // and there are other pave blocks for which the distance is less than the current.
1906 // Do not remove a vertex if it is projected on the curve with quite large angle
1907 // (see test bugs modalg_6 bug27761).
1909 // Reduce tolerance for the vertex to the value of maximal distance to
1910 // to section curve on which it will be kept.
1911 Standard_Real aMaxDistKept = -1;
1912 Standard_Boolean isRemoved = Standard_False;
1913 for (itL.Init(aList); itL.More(); itL.Next())
1915 const PaveBlockDist& aPBD = itL.Value();
1916 Standard_Real aCheckDist = 100. * Max(aPBD.Tolerance*aPBD.Tolerance, aMinDist);
1917 if (aPBD.SquareDist > aCheckDist && aPBD.SinAngle < aSinAngleMin)
1919 aPBD.PB->RemoveExtPave(nV);
1920 isRemoved = Standard_True;
1922 else if (aPBD.SquareDist > aMaxDistKept)
1923 aMaxDistKept = aPBD.SquareDist;
1926 if (isRemoved && aMaxDistKept > 0)
1928 const Standard_Real* pTol = theMVTol.Seek(nV);
1931 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV);
1932 const Standard_Real aRealTol = Max(*pTol, sqrt(aMaxDistKept) + Precision::Confusion());
1933 (*(Handle(BRep_TVertex)*)&aV.TShape())->Tolerance(aRealTol);
1939 //=======================================================================
1940 //function : ExtendedTolerance
1942 //=======================================================================
1943 Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance
1944 (const Standard_Integer nV,
1945 const TColStd_MapOfInteger& aMI,
1946 Standard_Real& aTolVExt,
1947 const Standard_Integer aType)
1949 Standard_Boolean bFound = Standard_False;
1950 if (!(myDS->IsNewShape(nV))) {
1954 Standard_Integer i, k, aNbLines, aNbInt;
1955 Standard_Real aT11, aT12, aD1, aD2, aD;
1957 gp_Pnt aPV, aP11, aP12;
1963 } else if (aType == 2) {
1967 aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1968 aPV=BRep_Tool::Pnt(aV);
1970 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
1971 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1973 for (; k<aNbInt; ++k) {
1974 aNbLines = !k ? aEEs.Length() : aEFs.Length();
1975 for (i = 0; i < aNbLines; ++i) {
1976 BOPDS_Interf *aInt = !k ? (BOPDS_Interf*) (&aEEs(i)) :
1977 (BOPDS_Interf*) (&aEFs(i));
1978 if (aInt->IndexNew() == nV) {
1979 if (aMI.Contains(aInt->Index1()) &&
1980 aMI.Contains(aInt->Index2())) {
1981 const IntTools_CommonPrt& aComPrt = !k ? aEEs(i).CommonPart() :
1982 aEFs(i).CommonPart();
1984 const TopoDS_Edge& aE1=aComPrt.Edge1();
1985 aComPrt.Range1(aT11, aT12);
1986 BOPTools_AlgoTools::PointOnEdge(aE1, aT11, aP11);
1987 BOPTools_AlgoTools::PointOnEdge(aE1, aT12, aP12);
1988 aD1=aPV.Distance(aP11);
1989 aD2=aPV.Distance(aP12);
1990 aD=(aD1>aD2)? aD1 : aD2;
1995 }//if (aMI.Contains(aEF.Index1()) && aMI.Contains(aEF.Index2())) {
1996 }//if (aInt->IndexNew() == nV) {
1997 }//for (i = 0; i < aNbLines; ++i) {
1998 }//for (k=0; k<2; ++k) {
2002 //=======================================================================
2003 //function : GetEFPnts
2005 //=======================================================================
2006 void BOPAlgo_PaveFiller::GetEFPnts
2007 (const Standard_Integer nF1,
2008 const Standard_Integer nF2,
2009 IntSurf_ListOfPntOn2S& aListOfPnts)
2011 Standard_Integer nE, nF, nFOpposite, aNbEFs, i;
2012 Standard_Real U1, U2, V1, V2, f, l;
2013 TColStd_MapOfInteger aMI;
2015 //collect indexes of all shapes from nF1 and nF2.
2016 GetFullShapeMap(nF1, aMI);
2017 GetFullShapeMap(nF2, aMI);
2019 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
2020 aNbEFs = aEFs.Length();
2022 for(i = 0; i < aNbEFs; ++i) {
2023 const BOPDS_InterfEF& aEF = aEFs(i);
2024 if (aEF.HasIndexNew()) {
2025 aEF.Indices(nE, nFOpposite);
2026 if(aMI.Contains(nE) && aMI.Contains(nFOpposite)) {
2027 const IntTools_CommonPrt& aCP = aEF.CommonPart();
2028 Standard_Real aPar = aCP.VertexParameter1();
2029 const TopoDS_Edge& aE = (*(TopoDS_Edge*)(&myDS->Shape(nE)));
2030 const TopoDS_Face& aFOpposite =
2031 (*(TopoDS_Face*)(&myDS->Shape(nFOpposite)));
2033 const Handle(Geom_Curve)& aCurve = BRep_Tool::Curve(aE, f, l);
2035 nF = (nFOpposite == nF1) ? nF2 : nF1;
2036 const TopoDS_Face& aF = (*(TopoDS_Face*)(&myDS->Shape(nF)));
2037 Handle(Geom2d_Curve) aPCurve =
2038 BRep_Tool::CurveOnSurface(aE, aF, f, l);
2040 GeomAPI_ProjectPointOnSurf& aProj=myContext->ProjPS(aFOpposite);
2043 aCurve->D0(aPar, aPoint);
2044 IntSurf_PntOn2S aPnt;
2045 if(!aPCurve.IsNull()) {
2046 gp_Pnt2d aP2d = aPCurve->Value(aPar);
2047 aProj.Perform(aPoint);
2048 if(aProj.IsDone()) {
2049 aProj.LowerDistanceParameters(U1,V1);
2051 aPnt.SetValue(aP2d.X(),aP2d.Y(),U1,V1);
2053 aPnt.SetValue(U1,V1,aP2d.X(),aP2d.Y());
2055 aListOfPnts.Append(aPnt);
2059 GeomAPI_ProjectPointOnSurf& aProj1 = myContext->ProjPS(aF);
2060 aProj1.Perform(aPoint);
2061 aProj.Perform(aPoint);
2062 if(aProj1.IsDone() && aProj.IsDone()){
2063 aProj1.LowerDistanceParameters(U1,V1);
2064 aProj.LowerDistanceParameters(U2,V2);
2066 aPnt.SetValue(U1,V1,U2,V2);
2068 aPnt.SetValue(U2,V2,U1,V1);
2070 aListOfPnts.Append(aPnt);
2078 //=======================================================================
2079 //function : PutEFPavesOnCurve
2081 //=======================================================================
2082 void BOPAlgo_PaveFiller::PutEFPavesOnCurve
2084 const TColStd_MapOfInteger& aMI,
2085 const TColStd_MapOfInteger& aMVEF,
2086 TColStd_DataMapOfIntegerReal& aMVTol,
2087 TColStd_DataMapOfIntegerListOfInteger& aDMVLV)
2089 if (!aMVEF.Extent()) {
2093 const IntTools_Curve& aIC=aNC.Curve();
2094 GeomAbs_CurveType aTypeC;
2096 if (!(aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve)) {
2100 Standard_Integer nV;
2101 TColStd_MapOfInteger aMV;
2104 RemoveUsedVertices(aNC, aMV);
2105 if (!aMV.Extent()) {
2109 Standard_Real aDist;
2112 const Handle(Geom_Curve)& aC3D=aIC.Curve();
2113 GeomAPI_ProjectPointOnCurve& aProjPT = myContext->ProjPT(aC3D);
2115 TColStd_MapIteratorOfMapOfInteger aItMI;
2116 aItMI.Initialize(aMV);
2117 for (; aItMI.More(); aItMI.Next()) {
2119 const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
2120 gp_Pnt aPV = BRep_Tool::Pnt(aV);
2121 aProjPT.Perform(aPV);
2122 Standard_Integer aNbPoints = aProjPT.NbPoints();
2124 aDist = aProjPT.LowerDistance();
2125 PutPaveOnCurve(nV, aDist, aNC, aMI, aMVTol, aDMVLV);
2130 //=======================================================================
2131 //function : PutStickPavesOnCurve
2133 //=======================================================================
2134 void BOPAlgo_PaveFiller::PutStickPavesOnCurve
2135 (const TopoDS_Face& aF1,
2136 const TopoDS_Face& aF2,
2137 const TColStd_MapOfInteger& aMI,
2139 const TColStd_MapOfInteger& aMVStick,
2140 TColStd_DataMapOfIntegerReal& aMVTol,
2141 TColStd_DataMapOfIntegerListOfInteger& aDMVLV)
2143 // Get numbers of vertices assigned to the ends of the curve
2144 Standard_Integer aBndNV[2];
2145 getBoundPaves(myDS, aNC, aBndNV);
2146 if (aBndNV[0] >= 0 && aBndNV[1] >= 0)
2148 // both curve ends already have assigned vertices
2151 TColStd_MapOfInteger aMV;
2152 aMV.Assign(aMVStick);
2153 RemoveUsedVertices(aNC, aMV);
2155 if (!aMV.Extent()) {
2159 Handle(Geom_Surface) aS1=BRep_Tool::Surface(aF1);
2160 Handle(Geom_Surface) aS2=BRep_Tool::Surface(aF2);
2162 const IntTools_Curve& aIC=aNC.Curve();
2163 //if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
2164 Handle(Geom2d_Curve) aC2D[2];
2166 aC2D[0]=aIC.FirstCurve2d();
2167 aC2D[1]=aIC.SecondCurve2d();
2168 if (!aC2D[0].IsNull() && !aC2D[1].IsNull()) {
2169 Standard_Integer nV, m, n;
2170 Standard_Real aTC[2], aD, aD2, u, v, aDT2, aScPr, aDScPr;
2174 TColStd_MapIteratorOfMapOfInteger aItMI, aItMI1;
2176 aDT2=2e-7; // the rich criteria
2177 aDScPr=5.e-9; // the creasing criteria
2178 aIC.Bounds(aTC[0], aTC[1], aPC[0], aPC[1]);
2180 aItMI.Initialize(aMV);
2181 for (; aItMI.More(); aItMI.Next()) {
2183 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&myDS->Shape(nV));
2184 aPV=BRep_Tool::Pnt(aV);
2186 for (m=0; m<2; ++m) {
2189 aD2=aPC[m].SquareDistance(aPV);
2190 if (aD2>aDT2) {// no rich
2194 for (n=0; n<2; ++n) {
2195 Handle(Geom_Surface)& aS=(!n)? aS1 : aS2;
2196 aC2D[n]->D0(aTC[m], aP2D);
2198 BOPTools_AlgoTools3D::GetNormalToSurface(aS, u, v, aDN[n]);
2201 aScPr=aDN[0]*aDN[1];
2211 // The intersection curve aIC is vanishing curve (the crease)
2214 PutPaveOnCurve(nV, aD, aNC, aMI, aMVTol, aDMVLV);
2216 }//for (jVU=1; jVU=aNbVU; ++jVU) {
2220 //=======================================================================
2221 //function : GetStickVertices
2223 //=======================================================================
2224 void BOPAlgo_PaveFiller::GetStickVertices(const Standard_Integer nF1,
2225 const Standard_Integer nF2,
2226 TColStd_MapOfInteger& aMVStick,
2227 TColStd_MapOfInteger& aMVEF,
2228 TColStd_MapOfInteger& aMI)
2230 Standard_Integer nS1, nS2, nVNew, aTypeInt, i;
2232 BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV();
2233 BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
2234 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
2235 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
2236 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
2238 Standard_Integer aNbLines[5] = {
2239 aVVs.Length(), aVEs.Length(), aEEs.Length(),
2240 aVFs.Length(), aEFs.Length()
2242 //collect indices of all shapes from nF1 and nF2.
2244 GetFullShapeMap(nF1, aMI);
2245 GetFullShapeMap(nF2, aMI);
2247 //collect VV, VE, EE, VF interferences
2248 for (aTypeInt = 0; aTypeInt < 4; ++aTypeInt) {
2249 for (i = 0; i < aNbLines[aTypeInt]; ++i) {
2250 BOPDS_Interf* aInt = (aTypeInt==0) ? (BOPDS_Interf*)(&aVVs(i)) :
2251 ((aTypeInt==1) ? (BOPDS_Interf*)(&aVEs(i)) :
2252 ((aTypeInt==2) ? (BOPDS_Interf*)(&aEEs(i)) :
2253 (BOPDS_Interf*)(&aVFs(i))));
2254 if (aInt->HasIndexNew()) {
2255 aInt->Indices(nS1, nS2);
2256 if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
2257 nVNew = aInt->IndexNew();
2258 aMVStick.Add(nVNew);
2263 //collect EF interferences
2264 for (i = 0; i < aNbLines[4]; ++i) {
2265 const BOPDS_InterfEF& aInt = aEFs(i);
2266 if (aInt.HasIndexNew()) {
2267 aInt.Indices(nS1, nS2);
2268 if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
2269 nVNew = aInt.IndexNew();
2270 aMVStick.Add(nVNew);
2277 //=======================================================================
2278 // function: GetFullShapeMap
2280 //=======================================================================
2281 void BOPAlgo_PaveFiller::GetFullShapeMap(const Standard_Integer nF,
2282 TColStd_MapOfInteger& aMI)
2284 TColStd_ListIteratorOfListOfInteger aIt;
2285 Standard_Integer nS;
2287 const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(nF);
2288 const TColStd_ListOfInteger& aLI = aSI.SubShapes();
2291 aIt.Initialize(aLI);
2292 for (; aIt.More(); aIt.Next()) {
2298 //=======================================================================
2299 // function: RemoveUsedVertices
2301 //=======================================================================
2302 void BOPAlgo_PaveFiller::RemoveUsedVertices(const BOPDS_Curve& aNC,
2303 TColStd_MapOfInteger& aMV)
2305 if (!aMV.Extent()) {
2309 const BOPDS_ListOfPaveBlock& aLPBC = aNC.PaveBlocks();
2310 BOPDS_ListIteratorOfListOfPaveBlock itPB(aLPBC);
2311 for (; itPB.More(); itPB.Next())
2313 const BOPDS_ListOfPave& aLP = itPB.Value()->ExtPaves();
2314 BOPDS_ListIteratorOfListOfPave aItLP(aLP);
2315 for (;aItLP.More();aItLP.Next()) {
2316 BOPDS_Pave aPave = aItLP.Value();
2317 Standard_Integer nV = aPave.Index();
2323 //=======================================================================
2324 //function : PutPaveOnCurve
2326 //=======================================================================
2327 void BOPAlgo_PaveFiller::PutPaveOnCurve
2328 (const Standard_Integer nV,
2329 const Standard_Real aTolR3D,
2330 const BOPDS_Curve& aNC,
2331 const TColStd_MapOfInteger& aMI,
2332 TColStd_DataMapOfIntegerReal& aMVTol,
2333 TColStd_DataMapOfIntegerListOfInteger& aDMVLV,
2334 const Standard_Integer iCheckExtend)
2336 Standard_Boolean bIsVertexOnLine;
2339 const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
2340 const Handle(BOPDS_PaveBlock)& aPB = aNC.PaveBlocks().First();
2341 const IntTools_Curve& aIC = aNC.Curve();
2343 Standard_Real aTolV = (aMVTol.IsBound(nV) ? aMVTol(nV) : BRep_Tool::Tolerance(aV));
2345 bIsVertexOnLine = myContext->IsVertexOnLine(aV, aTolV, aIC, aTolR3D + myFuzzyValue, aT);
2346 if (!bIsVertexOnLine && iCheckExtend && !myVertsToAvoidExtension.Contains(nV))
2348 Standard_Real anExtraTol = aTolV;
2349 if (ExtendedTolerance(nV, aMI, anExtraTol, iCheckExtend))
2351 bIsVertexOnLine = myContext->IsVertexOnLine(aV, anExtraTol, aIC, aTolR3D + myFuzzyValue, aT);
2352 if (bIsVertexOnLine)
2356 aTolV = aPOnC.Distance(BRep_Tool::Pnt(aV));
2361 if (bIsVertexOnLine) {
2362 // check if aPB contains the parameter aT
2363 Standard_Boolean bExist;
2364 Standard_Integer nVUsed;
2365 Standard_Real aPTol, aDTol;
2369 GeomAdaptor_Curve aGAC(aIC.Curve());
2370 aPTol = aGAC.Resolution(Max(aTolR3D, aTolV));
2372 bExist = aPB->ContainsParameter(aT, aPTol, nVUsed);
2374 // use existing pave
2375 TColStd_ListOfInteger* pList = aDMVLV.ChangeSeek(nVUsed);
2377 pList = aDMVLV.Bound(nVUsed, TColStd_ListOfInteger());
2378 pList->Append(nVUsed);
2379 if (!aMVTol.IsBound(nVUsed)) {
2380 const TopoDS_Vertex& aVUsed = (*(TopoDS_Vertex *)(&myDS->Shape(nVUsed)));
2381 aTolV = BRep_Tool::Tolerance(aVUsed);
2382 aMVTol.Bind(nVUsed, aTolV);
2385 // avoid repeated elements in the list
2386 TColStd_ListIteratorOfListOfInteger aItLI(*pList);
2387 for (; aItLI.More(); aItLI.Next()) {
2388 if (aItLI.Value() == nV) {
2392 if (!aItLI.More()) {
2395 // save initial tolerance for the vertex
2396 if (!aMVTol.IsBound(nV)) {
2397 aTolV = BRep_Tool::Tolerance(aV);
2398 aMVTol.Bind(nV, aTolV);
2405 aPave.SetParameter(aT);
2406 aPB->AppendExtPave(aPave);
2408 gp_Pnt aP1 = aGAC.Value(aT);
2409 aTolV = BRep_Tool::Tolerance(aV);
2410 gp_Pnt aP2 = BRep_Tool::Pnt(aV);
2411 Standard_Real aDist = aP1.Distance(aP2);
2412 if (aDist > aTolV) {
2413 BRep_Builder().UpdateVertex(aV, aDist + aDTol);
2415 if (!aMVTol.IsBound(nV)) {
2416 aMVTol.Bind(nV, aTolV);
2419 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV);
2420 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
2421 BRepBndLib::Add(aV, aBoxDS);
2422 aBoxDS.SetGap(aBoxDS.GetGap() + Precision::Confusion());
2428 //=======================================================================
2429 //function : ProcessExistingPaveBlocks
2431 //=======================================================================
2432 void BOPAlgo_PaveFiller::ProcessExistingPaveBlocks
2433 (const Standard_Integer theInt,
2434 const Standard_Integer nF1,
2435 const Standard_Integer nF2,
2436 const BOPDS_IndexedMapOfPaveBlock& aMPBOnIn,
2437 const TColStd_DataMapOfIntegerListOfInteger& aDMBV,
2438 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
2439 TopTools_DataMapOfShapeInteger& aMVI,
2440 BOPAlgo_DataMapOfPaveBlockListOfInteger& thePBFacesMap,
2441 BOPDS_MapOfPaveBlock& aMPB)
2443 if (aDMBV.IsEmpty()) {
2447 Standard_Real aT, dummy;
2448 Standard_Integer i, nV, nE, iC, aNbPB, iFlag;
2449 TColStd_ListIteratorOfListOfInteger aItLI;
2450 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItBV;
2452 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
2453 BOPDS_InterfFF& aFF = aFFs(theInt);
2454 BOPDS_VectorOfCurve& aVC = aFF.ChangeCurves();
2456 const BOPDS_FaceInfo& aFI1 = myDS->FaceInfo(nF1);
2457 const BOPDS_FaceInfo& aFI2 = myDS->FaceInfo(nF2);
2459 aNbPB = aMPBOnIn.Extent();
2461 aItBV.Initialize(aDMBV);
2462 for (; aItBV.More(); aItBV.Next()) {
2464 const TColStd_ListOfInteger& aLBV = aItBV.Value();
2466 BOPDS_Curve& aNC = aVC.ChangeValue(iC);
2467 BOPDS_ListOfPaveBlock& aLPBC = aNC.ChangePaveBlocks();
2469 aItLI.Initialize(aLBV);
2470 for (; aItLI.More(); aItLI.Next()) {
2472 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
2473 const Bnd_Box& aBoxV=aSIV.Box();
2474 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&aSIV.Shape();
2475 if (!aMVI.IsBound(aV)) {
2479 for (i = 1; i <= aNbPB; ++i) {
2480 const Handle(BOPDS_PaveBlock)& aPB = aMPBOnIn(i);
2481 if (aPB->Pave1().Index() == nV || aPB->Pave2().Index() == nV) {
2485 if (aMPB.Contains(aPB)) {
2488 if (myDS->ShapeInfo(aPB->OriginalEdge()).HasFlag()) { // skip degenerated edges
2493 const BOPDS_ShapeInfo& aSIE = myDS->ShapeInfo(nE);
2494 const Bnd_Box& aBoxE = aSIE.Box();
2496 if (aBoxV.IsOut(aBoxE)) {
2500 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aSIE.Shape();
2502 iFlag = myContext->ComputeVE(aV, aE, aT, dummy, myFuzzyValue);
2505 PreparePostTreatFF(theInt, iC, aPB, aMSCPB, aMVI, aLPBC);
2508 Standard_Boolean bInF1 = (aFI1.PaveBlocksOn().Contains(aPB) ||
2509 aFI1.PaveBlocksIn().Contains(aPB));
2510 Standard_Boolean bInF2 = (aFI2.PaveBlocksOn().Contains(aPB) ||
2511 aFI2.PaveBlocksIn().Contains(aPB));
2512 if (!bInF1 || !bInF2)
2514 // Face without pave block
2515 const Standard_Integer nF = bInF1 ? nF2 : nF1;
2516 TColStd_ListOfInteger* pFaces = thePBFacesMap.ChangeSeek(aPB);
2518 pFaces = thePBFacesMap.Bound(aPB, TColStd_ListOfInteger());
2519 // List is expected to be short, so we allow the check here
2520 if (pFaces->IsEmpty() || !pFaces->Contains(nF))
2528 //=======================================================================
2529 //function : UpdateExistingPaveBlocks
2531 //=======================================================================
2532 void BOPAlgo_PaveFiller::UpdateExistingPaveBlocks
2533 (const Handle(BOPDS_PaveBlock)& aPBf,
2534 BOPDS_ListOfPaveBlock& aLPB,
2535 const BOPAlgo_DataMapOfPaveBlockListOfInteger& thePBFacesMap)
2537 if (!aLPB.Extent()) {
2541 Standard_Integer nE;
2542 Standard_Boolean bCB;
2543 Handle(BOPDS_PaveBlock) aPB, aPB1, aPB2, aPB2n;
2544 Handle(BOPDS_CommonBlock) aCB;
2545 BOPDS_ListIteratorOfListOfPaveBlock aIt, aIt1, aIt2;
2547 // 1. Remove old pave blocks
2548 const Handle(BOPDS_CommonBlock)& aCB1 = myDS->CommonBlock(aPBf);
2549 bCB = !aCB1.IsNull();
2550 BOPDS_ListOfPaveBlock aLPB1;
2553 aLPB1.Assign(aCB1->PaveBlocks());
2557 aIt1.Initialize(aLPB1);
2558 for (; aIt1.More(); aIt1.Next()) {
2559 aPB1 = aIt1.Value();
2560 nE = aPB1->OriginalEdge();
2562 BOPDS_ListOfPaveBlock& aLPB2 = myDS->ChangePaveBlocks(nE);
2563 aIt2.Initialize(aLPB2);
2564 for (; aIt2.More(); aIt2.Next()) {
2565 aPB2 = aIt2.Value();
2573 // 2. Update pave blocks
2575 // Create new common blocks
2576 BOPDS_ListOfPaveBlock aLPBNew;
2577 const TColStd_ListOfInteger& aFaces = aCB1->Faces();
2578 aIt.Initialize(aLPB);
2579 for (; aIt.More(); aIt.Next()) {
2580 const Handle(BOPDS_PaveBlock)& aPBValue = aIt.Value();
2581 BOPDS_Pave aPBValuePaves[2] = {aPBValue->Pave1(), aPBValue->Pave2()};
2583 aCB = new BOPDS_CommonBlock;
2584 aIt1.Initialize(aLPB1);
2585 for (; aIt1.More(); aIt1.Next()) {
2586 aPB2 = aIt1.Value();
2587 nE = aPB2->OriginalEdge();
2589 // Create new pave block
2590 aPB2n = new BOPDS_PaveBlock;
2591 if (aPBValue->OriginalEdge() == nE) {
2592 aPB2n->SetPave1(aPBValuePaves[0]);
2593 aPB2n->SetPave2(aPBValuePaves[1]);
2596 // For the different original edge compute the parameters of paves
2597 BOPDS_Pave aPave[2];
2598 for (Standard_Integer i = 0; i < 2; ++i) {
2599 Standard_Integer nV = aPBValuePaves[i].Index();
2600 aPave[i].SetIndex(nV);
2601 if (nV == aPB2->Pave1().Index()) {
2602 aPave[i].SetParameter(aPB2->Pave1().Parameter());
2604 else if (nV == aPB2->Pave2().Index()) {
2605 aPave[i].SetParameter(aPB2->Pave2().Parameter());
2608 // Compute the parameter by projecting the point
2609 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV));
2610 const TopoDS_Edge& aEOr = TopoDS::Edge(myDS->Shape(nE));
2611 Standard_Real aTOut, aDist;
2612 Standard_Integer iErr = myContext->ComputeVE(aV, aEOr, aTOut, aDist, myFuzzyValue);
2614 aPave[i].SetParameter(aTOut);
2617 // Unable to project - set the parameter of the closest boundary
2618 const TopoDS_Vertex& aV1 = TopoDS::Vertex(myDS->Shape(aPB2->Pave1().Index()));
2619 const TopoDS_Vertex& aV2 = TopoDS::Vertex(myDS->Shape(aPB2->Pave2().Index()));
2621 gp_Pnt aP = BRep_Tool::Pnt(aV);
2622 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
2623 gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
2625 Standard_Real aDist1 = aP.SquareDistance(aP1);
2626 Standard_Real aDist2 = aP.SquareDistance(aP2);
2628 aPave[i].SetParameter(aDist1 < aDist2 ? aPB2->Pave1().Parameter() : aPB2->Pave2().Parameter());
2633 if (aPave[1].Parameter() < aPave[0].Parameter()) {
2634 BOPDS_Pave aPaveTmp = aPave[0];
2635 aPave[0] = aPave[1];
2636 aPave[1] = aPaveTmp;
2639 aPB2n->SetPave1(aPave[0]);
2640 aPB2n->SetPave2(aPave[1]);
2643 aPB2n->SetEdge(aPBValue->Edge());
2644 aPB2n->SetOriginalEdge(nE);
2645 aCB->AddPaveBlock(aPB2n);
2646 myDS->SetCommonBlock(aPB2n, aCB);
2647 myDS->ChangePaveBlocks(nE).Append(aPB2n);
2649 aCB->SetFaces(aFaces);
2651 const Handle(BOPDS_PaveBlock)& aPBNew = aCB->PaveBlocks().First();
2652 aLPBNew.Append(aPBNew);
2658 nE = aPBf->OriginalEdge();
2659 BOPDS_ListOfPaveBlock& aLPBE = myDS->ChangePaveBlocks(nE);
2660 aIt.Initialize(aLPB);
2661 for (; aIt.More(); aIt.Next()) {
2667 // Try to project the edge on the faces
2668 const TColStd_ListOfInteger* pLFaces = thePBFacesMap.Seek(aPBf);
2671 TColStd_ListIteratorOfListOfInteger itLF(*pLFaces);
2672 for (; itLF.More(); itLF.Next())
2674 const Standard_Integer nF = itLF.Value();
2675 BOPDS_FaceInfo& aFI = myDS->ChangeFaceInfo(nF);
2676 const TopoDS_Face& aF = TopoDS::Face(myDS->Shape(nF));
2678 aIt.Initialize(aLPB);
2679 for (; aIt.More(); aIt.Next())
2681 aPB = aIt.ChangeValue();
2682 if (aFI.PaveBlocksOn().Contains(aPB) || aFI.PaveBlocksIn().Contains(aPB))
2685 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
2687 IntTools_EdgeFace anEF;
2690 anEF.SetFuzzyValue(myFuzzyValue);
2691 anEF.SetRange(aPB->Pave1().Parameter(), aPB->Pave2().Parameter());
2692 anEF.SetContext(myContext);
2695 const IntTools_SequenceOfCommonPrts& aCPrts = anEF.CommonParts();
2696 Standard_Boolean bCoincide = (aCPrts.Length() == 1 && aCPrts(1).Type() == TopAbs_EDGE);
2699 aCB = myDS->CommonBlock(aPB);
2702 aCB = new BOPDS_CommonBlock;
2703 aCB->AddPaveBlock(aPB);
2704 myDS->SetCommonBlock(aPB, aCB);
2707 aFI.ChangePaveBlocksIn().Add(aPB);
2713 //=======================================================================
2714 // function: PutClosingPaveOnCurve
2716 //=======================================================================
2717 void BOPAlgo_PaveFiller::PutClosingPaveOnCurve(BOPDS_Curve& aNC)
2719 const IntTools_Curve& aIC = aNC.Curve();
2720 const Handle(Geom_Curve)& aC3D = aIC.Curve();
2726 if (!aIC.HasBounds())
2730 Standard_Real aT[2];
2732 aIC.Bounds(aT[0], aT[1], aP[0], aP[1]);
2734 // Find the pave which has been put at one of the ends
2735 Standard_Integer nV = -1;
2736 // Keep the opposite parameter
2737 Standard_Real aTOp = 0.;
2739 Standard_Boolean bFound = Standard_False;
2741 Handle(BOPDS_PaveBlock)& aPB = aNC.ChangePaveBlock1();
2742 BOPDS_ListOfPave& aLP = aPB->ChangeExtPaves();
2743 BOPDS_ListIteratorOfListOfPave aItLP(aLP);
2744 for (; aItLP.More() && !bFound; aItLP.Next())
2746 const BOPDS_Pave& aPC = aItLP.Value();
2747 Standard_Real aTC = aPC.Parameter();
2748 for (Standard_Integer j = 0; j < 2; ++j)
2750 if (Abs(aTC - aT[j]) < Precision::PConfusion())
2753 aTOp = (!j) ? aT[1] : aT[0];
2754 bFound = Standard_True;
2763 // Check if the curve is closed using the tolerance
2765 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV));
2766 const Standard_Real aTolV = BRep_Tool::Tolerance(aV);
2768 Standard_Real aDist = aP[0].Distance(aP[1]);
2772 // Check if there will be valid range on the curve
2773 Standard_Real aFirst, aLast;
2774 if (!BRepLib::FindValidRange(GeomAdaptor_Curve(aIC.Curve()), aIC.Tolerance(),
2775 aT[0], aP[0], aTolV,
2776 aT[1], aP[1], aTolV,
2782 // Add closing pave to the curve
2785 aPave.SetParameter(aTOp);
2788 //=======================================================================
2789 //function : PreparePostTreatFF
2791 //=======================================================================
2792 void BOPAlgo_PaveFiller::PreparePostTreatFF
2793 (const Standard_Integer aInt,
2794 const Standard_Integer aCur,
2795 const Handle(BOPDS_PaveBlock)& aPB,
2796 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
2797 TopTools_DataMapOfShapeInteger& aMVI,
2798 BOPDS_ListOfPaveBlock& aLPBC)
2800 Standard_Integer nV1, nV2;
2804 aPB->Indices(nV1, nV2);
2805 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
2806 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
2807 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
2808 // Keep info for post treatment
2809 BOPDS_CoupleOfPaveBlocks aCPB;
2810 aCPB.SetIndexInterf(aInt);
2811 aCPB.SetIndex(aCur);
2812 aCPB.SetPaveBlock1(aPB);
2814 aMSCPB.Add(aE, aCPB);
2815 aMVI.Bind(aV1, nV1);
2816 aMVI.Bind(aV2, nV2);
2819 //=======================================================================
2820 //function : CheckPlanes
2822 //=======================================================================
2823 Standard_Boolean BOPAlgo_PaveFiller::CheckPlanes
2824 (const Standard_Integer nF1,
2825 const Standard_Integer nF2)const
2827 Standard_Boolean bToIntersect;
2828 Standard_Integer i, nV2, iCnt;
2829 TColStd_MapIteratorOfMapOfInteger aIt;
2831 bToIntersect=Standard_False;
2833 const BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
2834 const BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
2836 const TColStd_MapOfInteger& aMVIn1=aFI1.VerticesIn();
2837 const TColStd_MapOfInteger& aMVOn1=aFI1.VerticesOn();
2840 for (i=0; (i<2 && !bToIntersect); ++i) {
2841 const TColStd_MapOfInteger& aMV2=(!i) ? aFI2.VerticesIn()
2842 : aFI2.VerticesOn();
2844 aIt.Initialize(aMV2);
2845 for (; aIt.More(); aIt.Next()) {
2847 if (aMVIn1.Contains(nV2) || aMVOn1.Contains(nV2)) {
2850 bToIntersect=!bToIntersect;
2857 return bToIntersect;
2859 //=======================================================================
2860 //function : UpdatePaveBlocks
2862 //=======================================================================
2863 void BOPAlgo_PaveFiller::UpdatePaveBlocks
2864 (const TColStd_DataMapOfIntegerInteger& aDMNewSD)
2866 if (aDMNewSD.IsEmpty()) {
2870 Standard_Integer nSp, aNbPBP, nV[2], i, j;
2871 Standard_Real aT[2];
2872 Standard_Boolean bCB, bRebuild;
2873 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
2874 BOPDS_MapOfPaveBlock aMPB;
2875 TColStd_MapOfInteger aMicroEdges;
2877 BOPDS_ListOfPaveBlock anAllPBs;
2879 // Get pave blocks of section edges
2880 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
2881 Standard_Integer aNbFF = aFFs.Length();
2882 for (i = 0; i < aNbFF; ++i)
2884 const BOPDS_InterfFF& aFF = aFFs(i);
2885 const BOPDS_VectorOfCurve& aVNC = aFF.Curves();
2886 Standard_Integer aNbC = aVNC.Length();
2887 for (j = 0; j < aNbC; ++j)
2889 const BOPDS_Curve& aNC = aVNC(j);
2890 const BOPDS_ListOfPaveBlock& aLPBC = aNC.PaveBlocks();
2891 aItPB.Initialize(aLPBC);
2892 for (; aItPB.More(); aItPB.Next())
2893 anAllPBs.Append(aItPB.Value());
2897 // Get pave blocks from the pool
2898 BOPDS_VectorOfListOfPaveBlock& aPBP = myDS->ChangePaveBlocksPool();
2899 aNbPBP = aPBP.Length();
2900 for (i = 0; i < aNbPBP; ++i) {
2901 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
2902 aItPB.Initialize(aLPB);
2903 for (; aItPB.More(); aItPB.Next())
2904 anAllPBs.Append(aItPB.Value());
2907 // Process all pave blocks
2908 aItPB.Initialize(anAllPBs);
2909 for (; aItPB.More(); aItPB.Next())
2911 Handle(BOPDS_PaveBlock) aPB = aItPB.Value();
2912 const Handle(BOPDS_CommonBlock)& aCB = myDS->CommonBlock(aPB);
2913 bCB = !aCB.IsNull();
2915 aPB = aCB->PaveBlock1();
2918 if (aMPB.Add(aPB)) {
2919 bRebuild = Standard_False;
2920 aPB->Indices(nV[0], nV[1]);
2921 aPB->Range(aT[0], aT[1]);
2923 Standard_Integer nE = aPB->OriginalEdge();
2928 // remember the fact if the edge had different vertices before substitution
2929 Standard_Boolean wasRegularEdge = (nV[0] != nV[1]);
2931 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(nE));
2932 TopoDS_Vertex aVE1, aVE2;
2933 TopExp::Vertices(aE, aVE1, aVE2);
2934 Standard_Boolean isClosedE = !aVE1.IsNull() && !aVE2.IsNull() && aVE1.IsSame(aVE2);
2935 Standard_Boolean isDegEdge = myDS->ShapeInfo(nE).HasFlag();
2937 BOPDS_Pave aPave[2] = {aPB->Pave1(), aPB->Pave2()};
2939 for (j = 0; j < 2; ++j) {
2940 if (aDMNewSD.IsBound(nV[j])) {
2942 nV[j] = aDMNewSD.Find(nV[j]);
2943 // recompute the parameter
2946 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV[j]));
2948 BRep_Tool::Pnt(aV).Distance(BRep_Tool::Pnt(aVE1)) > BRep_Tool::Tolerance(aV) + myFuzzyValue)
2950 Standard_Real aDummy, aTnew;
2951 Standard_Integer iErr = myContext->ComputeVE(aV, aE, aTnew, aDummy, myFuzzyValue);
2957 // choose the correct boundary parameter
2959 BRep_Tool::Range(aE, f, l);
2960 aT[j] = Abs(aT[j] - f) < Abs(aT[j] - l) ? f : l;
2963 aPave[j].SetIndex(nV[j]);
2965 bRebuild = Standard_True;
2972 // It seems the parameters have been recomputed successfully
2973 aPave[0].SetParameter(aT[0]);
2974 aPave[1].SetParameter(aT[1]);
2977 aPB->SetPave1(aPave[0]);
2978 aPB->SetPave2(aPave[1]);
2980 if (wasRegularEdge && !isDegEdge && nV[0] == nV[1]) {
2981 // now edge has the same vertex on both ends;
2982 // check if it is not a regular closed curve.
2983 FillShrunkData(aPB);
2984 if (!aPB->HasShrunkData())
2986 Standard_Integer nEMicro = aPB->Edge();
2988 nEMicro = aPB->OriginalEdge();
2989 // micro edge, so mark it for removal
2990 aMicroEdges.Add(nEMicro);
2994 aPB->Range(aT[0], aT[1]);
2995 nSp = SplitEdge(nE, nV[0], aT[0], nV[1], aT[1]);
3001 }// if (aMPB.Add(aPB)) {
3002 }// for (; aItPB.More(); aItPB.Next()) {
3005 if (aMicroEdges.Extent())
3006 RemovePaveBlocks(aMicroEdges);
3008 //=======================================================================
3009 //function : RemovePaveBlocks
3011 //=======================================================================
3012 void BOPAlgo_PaveFiller::RemovePaveBlocks(const TColStd_MapOfInteger theEdges)
3014 // Remove all pave blocks referring to input edges:
3016 // 1. from the Pave Blocks Pool
3017 BOPDS_VectorOfListOfPaveBlock& aPBP = myDS->ChangePaveBlocksPool();
3018 Standard_Integer aNbPBP = aPBP.Length(), i;
3019 for (i = 0; i < aNbPBP; ++i) {
3020 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
3022 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
3023 while (aItPB.More()) {
3024 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
3025 if (theEdges.Contains(aPB->Edge()))
3032 // 2. from Face Info and section curves
3033 TColStd_MapOfInteger aMPassed;
3034 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
3035 Standard_Integer aNbFF = aFFs.Length(), j;
3036 for (i = 0; i < aNbFF; ++i) {
3037 BOPDS_InterfFF& aFF = aFFs(i);
3038 Standard_Integer nF1, nF2;
3039 aFF.Indices(nF1, nF2);
3041 // rebuild pave block maps of face info
3042 for (j = 0; j < 2; j++) {
3043 Standard_Integer nF = (j == 0 ? nF1 : nF2);
3044 if (!aMPassed.Add(nF))
3046 BOPDS_FaceInfo& aFI = myDS->ChangeFaceInfo(nF);
3047 BOPDS_IndexedMapOfPaveBlock* aIMPB[] = { &aFI.ChangePaveBlocksIn(),
3048 &aFI.ChangePaveBlocksOn(), &aFI.ChangePaveBlocksSc() };
3049 for (Standard_Integer k = 0; k < 3; k++) {
3050 Standard_Integer aNbPB = aIMPB[k]->Extent(), m;
3051 for (m = 1; m <= aNbPB; ++m) {
3052 const Handle(BOPDS_PaveBlock)& aPB = aIMPB[k]->FindKey(m);
3053 if (theEdges.Contains(aPB->Edge()))
3057 BOPDS_IndexedMapOfPaveBlock aMPBCopy = *aIMPB[k];
3059 for (m = 1; m <= aNbPB; ++m) {
3060 const Handle(BOPDS_PaveBlock)& aPB = aMPBCopy(m);
3061 if (!theEdges.Contains(aPB->Edge()))
3067 // remove from Section pave blocks
3068 BOPDS_VectorOfCurve& aVNC = aFF.ChangeCurves();
3069 Standard_Integer aNbC = aVNC.Length();
3070 for (j = 0; j < aNbC; ++j) {
3071 BOPDS_Curve& aNC = aVNC(j);
3072 BOPDS_ListOfPaveBlock& aLPB = aNC.ChangePaveBlocks();
3073 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
3074 while (aItPB.More()) {
3075 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
3076 if (theEdges.Contains(aPB->Edge()))
3084 //=======================================================================
3085 //function : ToleranceFF
3086 //purpose : Computes the TolFF according to the tolerance value and
3087 // types of the faces.
3088 //=======================================================================
3089 Standard_Real ToleranceFF(const BRepAdaptor_Surface& aBAS1,
3090 const BRepAdaptor_Surface& aBAS2)
3092 Standard_Real aTol1 = aBAS1.Tolerance();
3093 Standard_Real aTol2 = aBAS2.Tolerance();
3094 Standard_Real aTolFF = Max(aTol1, aTol2);
3096 Standard_Boolean isAna1, isAna2;
3097 isAna1 = (aBAS1.GetType() == GeomAbs_Plane ||
3098 aBAS1.GetType() == GeomAbs_Cylinder ||
3099 aBAS1.GetType() == GeomAbs_Cone ||
3100 aBAS1.GetType() == GeomAbs_Sphere ||
3101 aBAS1.GetType() == GeomAbs_Torus);
3103 isAna2 = (aBAS2.GetType() == GeomAbs_Plane ||
3104 aBAS2.GetType() == GeomAbs_Cylinder ||
3105 aBAS2.GetType() == GeomAbs_Cone ||
3106 aBAS2.GetType() == GeomAbs_Sphere ||
3107 aBAS2.GetType() == GeomAbs_Torus);
3109 if (!isAna1 || !isAna2) {
3110 aTolFF = Max(aTolFF, 5.e-6);
3114 //=======================================================================
3115 //function : UpdateBlocksWithSharedVertices
3117 //=======================================================================
3118 void BOPAlgo_PaveFiller::UpdateBlocksWithSharedVertices()
3120 if (!myNonDestructive) {
3124 Standard_Integer aNbFF;
3126 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
3127 aNbFF=aFFs.Length();
3132 Standard_Boolean bOnCurve, bHasShapeSD;
3133 Standard_Integer i, nF1, nF2, aNbC, j, nV, nVSD;
3134 Standard_Real aTolV;
3135 TColStd_MapOfInteger aMF;
3137 for (i=0; i<aNbFF; ++i) {
3138 BOPDS_InterfFF& aFF=aFFs(i);
3140 BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
3146 aFF.Indices(nF1, nF2);
3149 myDS->UpdateFaceInfoOn(nF1);
3152 myDS->UpdateFaceInfoOn(nF2);
3155 // Collect old vertices that are shared for nF1, nF2 ->aMI;
3156 TColStd_MapOfInteger aMI;
3157 TColStd_MapIteratorOfMapOfInteger aItMI;
3159 BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
3160 BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
3162 const TColStd_MapOfInteger& aMVOn1=aFI1.VerticesOn();
3163 const TColStd_MapOfInteger& aMVIn1=aFI1.VerticesIn();
3164 const TColStd_MapOfInteger& aMVOn2=aFI2.VerticesOn();
3165 const TColStd_MapOfInteger& aMVIn2=aFI2.VerticesIn();
3167 for (j=0; j<2; ++j) {
3168 const TColStd_MapOfInteger& aMV1=(!j) ? aMVOn1 : aMVIn1;
3169 aItMI.Initialize(aMV1);
3170 for (; aItMI.More(); aItMI.Next()) {
3172 if (myDS->IsNewShape(nV)) {
3175 if (aMVOn2.Contains(nV) || aMVIn2.Contains(nV)) {
3181 // Try to put vertices aMI on curves
3182 for (j=0; j<aNbC; ++j) {
3183 BOPDS_Curve& aNC=aVC.ChangeValue(j);
3184 Standard_Real aTolR3D = Max(aNC.Tolerance(), aNC.TangentialTolerance());
3186 aItMI.Initialize(aMI);
3187 for (; aItMI.More(); aItMI.Next()) {
3190 bHasShapeSD=myDS->HasShapeSD(nV, nVSD);
3195 bOnCurve=EstimatePaveOnCurve(nV, aNC, aTolR3D);
3200 const TopoDS_Vertex& aV=*((TopoDS_Vertex *)&myDS->Shape(nV));
3201 aTolV=BRep_Tool::Tolerance(aV);
3203 UpdateVertex(nV, aTolV);
3205 }//for (j=0; j<aNbC; ++j) {
3206 }//for (i=0; i<aNbFF; ++i) {
3208 UpdateCommonBlocksWithSDVertices();
3210 //=======================================================================
3211 //function : EstimatePaveOnCurve
3213 //=======================================================================
3214 Standard_Boolean BOPAlgo_PaveFiller::EstimatePaveOnCurve
3215 (const Standard_Integer nV,
3216 const BOPDS_Curve& aNC,
3217 const Standard_Real aTolR3D)
3219 Standard_Boolean bIsVertexOnLine;
3222 const TopoDS_Vertex& aV=*((TopoDS_Vertex *)&myDS->Shape(nV));
3223 const IntTools_Curve& aIC=aNC.Curve();
3225 bIsVertexOnLine=myContext->IsVertexOnLine(aV, aIC, aTolR3D, aT);
3226 return bIsVertexOnLine;
3229 //=======================================================================
3230 //function : CorrectToleranceOfSE
3232 //=======================================================================
3233 void BOPAlgo_PaveFiller::CorrectToleranceOfSE()
3235 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
3236 NCollection_IndexedDataMap<Standard_Integer,BOPDS_ListOfPaveBlock> aMVIPBs;
3237 TColStd_MapOfInteger aMVIToReduce;
3238 // Fence map to avoid repeated checking of the same edge
3239 BOPDS_MapOfPaveBlock aMPB;
3241 // 1. iterate on all sections F-F
3242 Standard_Integer aNb = aFFs.Length(), i;
3243 for (i = 0; i < aNb; ++i) {
3244 BOPDS_InterfFF& aFF = aFFs(i);
3246 BOPDS_VectorOfCurve& aVNC = aFF.ChangeCurves();
3247 Standard_Integer aNbC = aVNC.Length(), k;
3248 for (k = 0; k < aNbC; ++k) {
3249 BOPDS_Curve& aNC = aVNC(k);
3250 BOPDS_ListOfPaveBlock& aLPB = aNC.ChangePaveBlocks();
3251 BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPB);
3252 for (; aItLPB.More(); ) {
3253 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
3254 Standard_Integer nE;
3255 if (!aPB->HasEdge(nE)) {
3256 aLPB.Remove(aItLPB);
3260 if (!aMPB.Add(aPB)) {
3265 Standard_Boolean bIsReduced = Standard_False;
3266 if (aPB->OriginalEdge() < 0) {
3267 // It is possible that due to small angle between faces the
3268 // common zone between faces can be large and the tangential
3269 // tolerance of the curve will be large as well.
3270 // Here we're trying to reduce the tolerance of the section
3271 // edge using the valid tolerance of the edge.
3272 // Note, that if the pave block has created common block with
3273 // other edges its valid tolerance could have been changed to
3274 // cover all edges in common block (see PostTreatFF() method).
3275 Standard_Real aTolC = aNC.Tolerance();
3276 Standard_Real aTolTang = aNC.TangentialTolerance();
3277 if (aTolC < aTolTang) {
3278 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(nE));
3279 Standard_Real aTolE = BRep_Tool::Tolerance(aE);
3280 if (aTolC < aTolE) {
3281 // reduce edge tolerance
3282 reinterpret_cast<BRep_TEdge*>(aE.TShape().operator->())->Tolerance(aTolC);
3283 bIsReduced = Standard_True;
3288 // fill in the map vertex index - pave blocks
3289 for (Standard_Integer j=0; j < 2; j++) {
3290 Standard_Integer nV = (j == 0 ? aPB->Pave1().Index() : aPB->Pave2().Index());
3291 myDS->HasShapeSD(nV, nV);
3292 BOPDS_ListOfPaveBlock *pPBList = aMVIPBs.ChangeSeek(nV);
3294 pPBList = &aMVIPBs.ChangeFromIndex(aMVIPBs.Add(nV, BOPDS_ListOfPaveBlock()));
3296 pPBList->Append(aPB);
3298 aMVIToReduce.Add(nV);
3306 if (aMVIToReduce.IsEmpty()) {
3310 // 2. try to reduce tolerances of connected vertices
3311 // 2.1 find all other edges containing these connected vertices to avoid
3312 // reducing the tolerance to the value less than the tolerances of edges,
3313 // i.e. minimal tolerance for the vertex is the max tolerance of the
3314 // edges containing this vertex
3315 TColStd_DataMapOfIntegerReal aMVITol;
3316 BOPDS_VectorOfListOfPaveBlock& aPBP = myDS->ChangePaveBlocksPool();
3317 aNb = aPBP.Length();
3318 for (i = 0; i < aNb; ++i) {
3319 const BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
3320 BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPB);
3321 for (; aItLPB.More(); aItLPB.Next()) {
3322 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
3323 Standard_Integer nE;
3324 if (!aPB->HasEdge(nE)) {
3327 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(nE));
3328 Standard_Real aTolE = BRep_Tool::Tolerance(aE);
3330 Standard_Integer nV[2];
3331 aPB->Indices(nV[0], nV[1]);
3333 for (Standard_Integer j = 0; j < 2; j++) {
3334 if (aMVIToReduce.Contains(nV[j])) {
3335 Standard_Real *aMaxTol = aMVITol.ChangeSeek(nV[j]);
3337 aMVITol.Bind(nV[j], aTolE);
3339 else if (aTolE > *aMaxTol) {
3342 BOPDS_ListOfPaveBlock& aPBList = aMVIPBs.ChangeFromKey(nV[j]);
3343 aPBList.Append(aPB);
3349 // 2.2 reduce tolerances if possible
3350 aNb = aMVIPBs.Extent();
3351 for (i = 1; i <= aNb; ++i) {
3352 Standard_Integer nV = aMVIPBs.FindKey(i);
3353 if (!aMVIToReduce.Contains(nV)) {
3357 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV));
3358 Standard_Real aTolV = BRep_Tool::Tolerance(aV);
3359 Standard_Real aMaxTol = aMVITol.IsBound(nV) ? aMVITol.Find(nV) : 0.;
3360 // it makes no sense to compute the real tolerance if it is
3361 // impossible to reduce the tolerance at least 0.1% of the current value
3362 if (aTolV - aMaxTol < 0.001 * aTolV) {
3366 // compute the maximal distance from the vertex to the adjacent edges
3367 gp_Pnt aP = BRep_Tool::Pnt(aV);
3369 // Avoid repeated checks
3370 BOPDS_MapOfPaveBlock aMPBFence;
3372 const BOPDS_ListOfPaveBlock& aLPB = aMVIPBs.FindFromIndex(i);
3373 BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPB);
3374 for (; aItLPB.More(); aItLPB.Next()) {
3375 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
3376 if (!aMPBFence.Add(aPB)) {
3379 Standard_Integer nE = aPB->Edge();
3380 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(nE));
3381 BRepAdaptor_Curve aC(aE);
3382 for (Standard_Integer iPave = 0; iPave < 2; ++iPave) {
3383 const BOPDS_Pave& aPave = !iPave ? aPB->Pave1() : aPB->Pave2();
3384 Standard_Integer nVSD = aPave.Index();
3385 myDS->HasShapeSD(nVSD, nVSD);
3390 gp_Pnt aPonE = aC.Value(aPave.Parameter());
3391 Standard_Real aDist = aP.Distance(aPonE);
3392 aDist += BRep_Tool::Tolerance(aE);
3393 if (aDist > aMaxTol) {
3399 if (aMaxTol < aTolV) {
3400 reinterpret_cast<BRep_TVertex*>(aV.TShape().operator->())->Tolerance(aMaxTol);
3405 //=======================================================================
3406 //function : PutSEInOtherFaces
3408 //=======================================================================
3409 void BOPAlgo_PaveFiller::PutSEInOtherFaces()
3411 // Try to intersect each section edge with the faces
3412 // not participated in its creation
3414 // Get all section edges
3415 BOPDS_IndexedMapOfPaveBlock aMPBScAll;
3417 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
3418 const Standard_Integer aNbFF = aFFs.Length();
3419 for (Standard_Integer i = 0; i < aNbFF; ++i)
3421 const BOPDS_VectorOfCurve& aVNC = aFFs(i).Curves();
3422 const Standard_Integer aNbC = aVNC.Length();
3423 for (Standard_Integer j = 0; j < aNbC; ++j)
3425 const BOPDS_ListOfPaveBlock& aLPBC = aVNC(j).PaveBlocks();
3426 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPBC);
3427 for (; aItPB.More(); aItPB.Next())
3428 aMPBScAll.Add(aItPB.Value());
3431 // Perform intersection of collected pave blocks
3432 ForceInterfEF(aMPBScAll, Standard_False);
3435 //=======================================================================
3436 //function : RemoveMicroSectionEdges
3438 //=======================================================================
3439 void BOPAlgo_PaveFiller::RemoveMicroSectionEdges
3440 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMSCPB,
3441 BOPDS_IndexedMapOfPaveBlock& theMicroPB)
3443 if (theMSCPB.IsEmpty())
3447 // Get all F/F interferences
3448 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
3450 // Build the new map of section edges avoiding the micro edges
3451 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aSEPBMap;
3452 // Analyze all section edges
3453 Standard_Integer aNbCPB = theMSCPB.Extent();
3454 for (Standard_Integer i = 1; i <= aNbCPB; ++i)
3456 const TopoDS_Shape& aSI = theMSCPB.FindKey(i);
3457 const BOPDS_CoupleOfPaveBlocks& aCPB = theMSCPB(i);
3459 if (aSI.ShapeType() != TopAbs_EDGE)
3462 aSEPBMap.Add(aSI, aCPB);
3466 // Get pave block for analysis
3467 const Handle(BOPDS_PaveBlock)& aPB = aCPB.PaveBlock1();
3470 // Not a real section edge
3471 aSEPBMap.Add(aSI, aCPB);
3475 if (!BOPTools_AlgoTools::IsMicroEdge(TopoDS::Edge(aSI), myContext, Standard_False))
3478 aSEPBMap.Add(aSI, aCPB);
3482 // Micro edge is found, avoid it in the <theMSCPB> map
3483 // and remove from the F/F Intersection info structure
3485 // Get F/F interference which created this micro edge
3486 BOPDS_InterfFF& aFF = aFFs(aCPB.IndexInterf());
3487 // Get curve from which this edge has been created
3488 BOPDS_Curve& aCurve = aFF.ChangeCurves().ChangeValue(aCPB.Index());
3489 // Get all section pave blocks created from this curve
3490 BOPDS_ListOfPaveBlock& aLPBC = aCurve.ChangePaveBlocks();
3491 // Remove pave block from the list
3492 for (BOPDS_ListIteratorOfListOfPaveBlock it(aLPBC); it.More(); it.Next())
3494 if (it.Value() == aPB)
3501 // Add the pave block of "micro" edge into outgoing map for
3502 // unification of its vertices in the PostTreatFF method
3503 theMicroPB.Add(aPB);
3506 // Overwrite the old map if necessary
3507 if (aSEPBMap.Extent() != theMSCPB.Extent())
3508 theMSCPB = aSEPBMap;