1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 // This file is part of Open CASCADE Technology software library.
9 // This library is free software; you can redistribute it and/or modify it under
10 // the terms of the GNU Lesser General Public License version 2.1 as published
11 // by the Free Software Foundation, with special exception defined in the file
12 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 // distribution for complete text of the license and disclaimer of any warranty.
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
18 #include <Bnd_Box.hxx>
19 #include <BOPAlgo_PaveFiller.hxx>
20 #include <BOPAlgo_SectionAttribute.hxx>
21 #include <BOPAlgo_Tools.hxx>
22 #include <BOPAlgo_Alerts.hxx>
23 #include <BOPCol_DataMapOfShapeInteger.hxx>
24 #include <BOPCol_ListOfInteger.hxx>
25 #include <BOPCol_ListOfShape.hxx>
26 #include <BOPCol_MapOfInteger.hxx>
27 #include <BOPCol_NCVector.hxx>
28 #include <BOPCol_Parallel.hxx>
29 #include <BOPDS_CommonBlock.hxx>
30 #include <BOPDS_CoupleOfPaveBlocks.hxx>
31 #include <BOPDS_Curve.hxx>
32 #include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx>
33 #include <BOPDS_DS.hxx>
34 #include <BOPDS_FaceInfo.hxx>
35 #include <BOPDS_Interf.hxx>
36 #include <BOPDS_Iterator.hxx>
37 #include <BOPDS_ListOfPave.hxx>
38 #include <BOPDS_ListOfPaveBlock.hxx>
39 #include <BOPDS_MapOfPaveBlock.hxx>
40 #include <BOPDS_PaveBlock.hxx>
41 #include <BOPDS_Point.hxx>
42 #include <BOPDS_ShapeInfo.hxx>
43 #include <BOPDS_VectorOfCurve.hxx>
44 #include <BOPDS_VectorOfPoint.hxx>
45 #include <BOPTools.hxx>
46 #include <BOPTools_AlgoTools.hxx>
47 #include <BOPTools_AlgoTools3D.hxx>
48 #include <BRep_Builder.hxx>
49 #include <BRep_Tool.hxx>
50 #include <BRep_TEdge.hxx>
51 #include <BRepAdaptor_Curve.hxx>
52 #include <BRepAdaptor_Surface.hxx>
53 #include <BRepBndLib.hxx>
54 #include <BRepBuilderAPI_MakeVertex.hxx>
55 #include <BRepTools.hxx>
56 #include <Geom2d_Curve.hxx>
57 #include <Geom_Curve.hxx>
58 #include <GeomAPI_ProjectPointOnCurve.hxx>
59 #include <GeomAPI_ProjectPointOnSurf.hxx>
61 #include <IntSurf_ListOfPntOn2S.hxx>
62 #include <IntSurf_PntOn2S.hxx>
63 #include <IntTools.hxx>
64 #include <IntTools_Context.hxx>
65 #include <IntTools_Curve.hxx>
66 #include <IntTools_EdgeFace.hxx>
67 #include <IntTools_FaceFace.hxx>
68 #include <IntTools_PntOn2Faces.hxx>
69 #include <IntTools_SequenceOfCurves.hxx>
70 #include <IntTools_SequenceOfPntOn2Faces.hxx>
71 #include <IntTools_ShrunkRange.hxx>
72 #include <IntTools_Tools.hxx>
73 #include <Precision.hxx>
75 #include <TopExp_Explorer.hxx>
77 #include <TopoDS_Compound.hxx>
78 #include <TopoDS_Edge.hxx>
79 #include <TopoDS_Face.hxx>
80 #include <TopoDS_Vertex.hxx>
83 static 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();
147 IntTools_FaceFace::Perform(myF1, myF2);
151 Standard_Integer myIF1;
152 Standard_Integer myIF2;
153 Standard_Real myTolFF;
158 //=======================================================================
159 typedef BOPCol_NCVector
160 <BOPAlgo_FaceFace> BOPAlgo_VectorOfFaceFace;
162 typedef BOPCol_Functor
164 BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceFunctor;
167 <BOPAlgo_FaceFaceFunctor,
168 BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceCnt;
169 /////////////////////////////////////////////////////////////////////////
170 //=======================================================================
171 //function : PerformFF
173 //=======================================================================
174 void BOPAlgo_PaveFiller::PerformFF()
176 myIterator->Initialize(TopAbs_FACE, TopAbs_FACE);
177 Standard_Integer iSize = myIterator->ExpectedLength();
182 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
183 aFFs.SetIncrement(iSize);
185 // Options for the intersection algorithm
186 Standard_Boolean bApprox = mySectionAttribute.Approximation(),
187 bCompC2D1 = mySectionAttribute.PCurveOnS1(),
188 bCompC2D2 = mySectionAttribute.PCurveOnS2();
189 Standard_Real anApproxTol = 1.e-7;
190 // Post-processing options
191 Standard_Boolean bSplitCurve = Standard_False;
193 // Fence map to store faces with updated FaceInfo structure
194 BOPCol_MapOfInteger aMIFence;
195 // Prepare the pairs of faces for intersection
196 BOPAlgo_VectorOfFaceFace aVFaceFace;
197 Standard_Integer nF1, nF2;
199 for (; myIterator->More(); myIterator->Next()) {
200 myIterator->Value(nF1, nF2);
202 const TopoDS_Face& aF1=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
203 const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
205 if (aMIFence.Add(nF1)) {
206 myDS->UpdateFaceInfoOn(nF1);
207 myDS->UpdateFaceInfoIn(nF1);
209 if (aMIFence.Add(nF2)) {
210 myDS->UpdateFaceInfoOn(nF2);
211 myDS->UpdateFaceInfoIn(nF2);
214 const BRepAdaptor_Surface& aBAS1 = myContext->SurfaceAdaptor(aF1);
215 const BRepAdaptor_Surface& aBAS2 = myContext->SurfaceAdaptor(aF2);
216 if (aBAS1.GetType() == GeomAbs_Plane &&
217 aBAS2.GetType() == GeomAbs_Plane) {
218 // Check if the planes are really interfering
219 Standard_Boolean bToIntersect = CheckPlanes(nF1, nF2);
221 BOPDS_InterfFF& aFF=aFFs.Append1();
222 aFF.SetIndices(nF1, nF2);
228 if (myGlue == BOPAlgo_GlueOff) {
229 BOPAlgo_FaceFace& aFaceFace=aVFaceFace.Append1();
231 aFaceFace.SetIndices(nF1, nF2);
232 aFaceFace.SetFaces(aF1, aF2);
233 // compute minimal tolerance for the curves
234 Standard_Real aTolFF = ToleranceFF(aBAS1, aBAS2);
235 aFaceFace.SetTolFF(aTolFF);
237 IntSurf_ListOfPntOn2S aListOfPnts;
238 GetEFPnts(nF1, nF2, aListOfPnts);
239 Standard_Integer aNbLP = aListOfPnts.Extent();
241 aFaceFace.SetList(aListOfPnts);
244 aFaceFace.SetParameters(bApprox, bCompC2D1, bCompC2D2, anApproxTol);
245 aFaceFace.SetFuzzyValue(myFuzzyValue);
246 aFaceFace.SetProgressIndicator(myProgressIndicator);
249 // for the Glue mode just add all interferences of that type
250 BOPDS_InterfFF& aFF = aFFs.Append1();
251 aFF.SetIndices(nF1, nF2);
252 aFF.SetTangentFaces(Standard_False);
255 }//for (; myIterator->More(); myIterator->Next()) {
257 //======================================================
258 // Perform intersection
259 BOPAlgo_FaceFaceCnt::Perform(myRunParallel, aVFaceFace);
260 //======================================================
261 // Treatment of the results
262 Standard_Integer k, aNbFaceFace = aVFaceFace.Extent();
263 for (k = 0; k < aNbFaceFace; ++k) {
264 BOPAlgo_FaceFace& aFaceFace = aVFaceFace(k);
265 aFaceFace.Indices(nF1, nF2);
266 if (!aFaceFace.IsDone()) {
267 BOPDS_InterfFF& aFF = aFFs.Append1();
268 aFF.SetIndices(nF1, nF2);
273 Standard_Boolean bTangentFaces = aFaceFace.TangentFaces();
274 Standard_Real aTolFF = aFaceFace.TolFF();
276 aFaceFace.PrepareLines3D(bSplitCurve);
278 const IntTools_SequenceOfCurves& aCvsX = aFaceFace.Lines();
279 const IntTools_SequenceOfPntOn2Faces& aPntsX = aFaceFace.Points();
281 Standard_Integer aNbCurves = aCvsX.Length();
282 Standard_Integer aNbPoints = aPntsX.Length();
284 if (aNbCurves || aNbPoints) {
285 myDS->AddInterf(nF1, nF2);
288 BOPDS_InterfFF& aFF = aFFs.Append1();
289 aFF.SetIndices(nF1, nF2);
290 aFF.SetTangentFaces(bTangentFaces);
291 aFF.Init(aNbCurves, aNbPoints);
294 // Fix bounding box expanding coefficient.
295 Standard_Real aBoxExpandValue = aTolFF;
298 // Modify geometric expanding coefficient by topology value,
299 // since this bounding box used in sharing (vertex or edge).
300 Standard_Real aMaxVertexTol = Max(BRep_Tool::MaxTolerance(aFaceFace.Face1(), TopAbs_VERTEX),
301 BRep_Tool::MaxTolerance(aFaceFace.Face2(), TopAbs_VERTEX));
302 aBoxExpandValue += aMaxVertexTol;
305 BOPDS_VectorOfCurve& aVNC = aFF.ChangeCurves();
306 for (Standard_Integer i = 1; i <= aNbCurves; ++i) {
308 const IntTools_Curve& aIC = aCvsX(i);
309 Standard_Boolean bIsValid = IntTools_Tools::CheckCurve(aIC, aBox);
311 BOPDS_Curve& aNC = aVNC.Append1();
313 // make sure that the bounding box has the maximal gap
314 aBox.Enlarge(aBoxExpandValue);
316 aNC.SetTolerance(Max(aIC.Tolerance(), aTolFF));
321 BOPDS_VectorOfPoint& aVNP = aFF.ChangePoints();
322 for (Standard_Integer i = 1; i <= aNbPoints; ++i) {
323 const IntTools_PntOn2Faces& aPi = aPntsX(i);
324 const gp_Pnt& aP = aPi.P1().Pnt();
326 BOPDS_Point& aNP = aVNP.Append1();
331 //=======================================================================
332 //function : MakeBlocks
334 //=======================================================================
335 void BOPAlgo_PaveFiller::MakeBlocks()
337 if (myGlue != BOPAlgo_GlueOff) {
341 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
342 Standard_Integer aNbFF = aFFs.Extent();
347 Standard_Boolean bExist, bValid2D;
348 Standard_Integer i, nF1, nF2, aNbC, aNbP, j;
349 Standard_Integer nV1, nV2;
350 Standard_Real aT1, aT2;
351 Handle(NCollection_BaseAllocator) aAllocator;
352 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
354 Handle(BOPDS_PaveBlock) aPBOut;
356 //-----------------------------------------------------scope f
358 NCollection_BaseAllocator::CommonBaseAllocator();
360 BOPCol_ListOfInteger aLSE(aAllocator), aLBV(aAllocator);
361 BOPCol_MapOfInteger aMVOnIn(100, aAllocator),
362 aMVStick(100,aAllocator), aMVEF(100, aAllocator),
363 aMI(100, aAllocator), aMVBounds(100, aAllocator);
364 BOPDS_IndexedMapOfPaveBlock aMPBOnIn(100, aAllocator);
365 BOPDS_MapOfPaveBlock aMPBAdd(100, aAllocator), aMPBCommon;
366 BOPDS_ListOfPaveBlock aLPB(aAllocator);
367 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMSCPB(100, aAllocator);
368 BOPCol_DataMapOfShapeInteger aMVI(100, aAllocator);
369 BOPDS_DataMapOfPaveBlockListOfPaveBlock aDMExEdges(100, aAllocator);
370 BOPCol_DataMapOfIntegerReal aMVTol(100, aAllocator);
371 BOPCol_DataMapOfIntegerInteger aDMNewSD(100, aAllocator);
372 BOPCol_DataMapOfIntegerListOfInteger aDMVLV;
373 BOPCol_DataMapOfIntegerListOfInteger aDMBV(100, aAllocator);
374 BOPCol_DataMapIteratorOfDataMapOfIntegerReal aItMV;
375 BOPCol_IndexedMapOfShape aMicroEdges(100, aAllocator);
377 for (i=0; i<aNbFF; ++i) {
381 BOPDS_InterfFF& aFF=aFFs(i);
382 aFF.Indices(nF1, nF2);
384 BOPDS_VectorOfPoint& aVP=aFF.ChangePoints();
386 BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
388 if (!aNbP && !aNbC) {
392 const TopoDS_Face& aF1=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
393 const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
395 Standard_Real aTolFF = Max(BRep_Tool::Tolerance(aF1), BRep_Tool::Tolerance(aF2));
397 BOPDS_FaceInfo& aFI1 = myDS->ChangeFaceInfo(nF1);
398 BOPDS_FaceInfo& aFI2 = myDS->ChangeFaceInfo(nF2);
407 myDS->SubShapesOnIn(nF1, nF2, aMVOnIn, aMPBOnIn, aMPBCommon);
408 myDS->SharedEdges(nF1, nF2, aLSE, aAllocator);
410 Standard_Boolean bHasRealSectionEdge = Standard_False;
412 for (j=0; j<aNbP; ++j) {
414 BOPDS_CoupleOfPaveBlocks aCPB;
416 BOPDS_Point& aNP=aVP.ChangeValue(j);
417 const gp_Pnt& aP=aNP.Pnt();
419 bExist=IsExistingVertex(aP, aTolFF, aMVOnIn);
421 BOPTools_AlgoTools::MakeNewVertex(aP, aTolFF, aV);
423 aCPB.SetIndexInterf(i);
425 aMSCPB.Add(aV, aCPB);
432 GetStickVertices(nF1, nF2, aMVStick, aMVEF, aMI);
434 for (j = 0; j < aNbC; ++j) {
435 BOPDS_Curve& aNC = aVC.ChangeValue(j);
437 aNC.InitPaveBlock1();
439 PutPavesOnCurve(aMVOnIn, aNC, nF1, nF2, aMI, aMVEF, aMVTol, aDMVLV);
442 // if some E-F vertex was put on a curve due to large E-F intersection range,
443 // and it also was put on another curve correctly then remove this vertex from
444 // the first curve. Detect such case if the distance to curve exceeds aTolR3D.
445 FilterPavesOnCurves(aVC);
447 for (j = 0; j<aNbC; ++j) {
448 BOPDS_Curve& aNC=aVC.ChangeValue(j);
449 const IntTools_Curve& aIC=aNC.Curve();
451 PutStickPavesOnCurve(aF1, aF2, aMI, aNC, aMVStick, aMVTol, aDMVLV);
454 PutEFPavesOnCurve(aNC, aMI, aMVEF, aMVTol, aDMVLV);
457 if (aIC.HasBounds()) {
460 PutBoundPaveOnCurve(aF1, aF2, aNC, aLBV);
462 if (!aLBV.IsEmpty()) {
464 BOPCol_ListIteratorOfListOfInteger aItI(aLBV);
465 for (; aItI.More(); aItI.Next()) {
466 aMVBounds.Add(aItI.Value());
470 }//for (j=0; j<aNbC; ++j) {
472 // Put closing pave if needed
473 for (j=0; j<aNbC; ++j) {
474 BOPDS_Curve& aNC=aVC.ChangeValue(j);
475 PutClosingPaveOnCurve (aNC);
478 // 3. Make section edges
479 for (j=0; j<aNbC; ++j) {
480 BOPDS_Curve& aNC=aVC.ChangeValue(j);
481 const IntTools_Curve& aIC=aNC.Curve();
482 Standard_Real aTolR3D = Max(aNC.Tolerance(), aNC.TangentialTolerance());
484 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
485 Handle(BOPDS_PaveBlock)& aPB1=aNC.ChangePaveBlock1();
488 aPB1->Update(aLPB, Standard_False);
490 aItLPB.Initialize(aLPB);
491 for (; aItLPB.More(); aItLPB.Next()) {
492 Handle(BOPDS_PaveBlock)& aPB=aItLPB.ChangeValue();
493 aPB->Indices(nV1, nV2);
494 aPB->Range (aT1, aT2);
496 if (fabs(aT1 - aT2) < Precision::PConfusion()) {
500 bValid2D=myContext->IsValidBlockForFaces(aT1, aT2, aIC,
506 bExist=IsExistingPaveBlock(aPB, aNC, aLSE);
511 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
512 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
515 BOPTools_AlgoTools::MakeEdge (aIC, aV1, aT1, aV2, aT2, aTolR3D, aES);
517 // check for micro edge
518 if (BOPTools_AlgoTools::IsMicroEdge(aES, myContext, Standard_False)) {
519 // If the section edge is a micro edge, i.e. the whole edge is
520 // covered by the tolerance spheres of its vertices, it will be
521 // passed into post treatment process to fuse its vertices.
522 // The edge itself will not be kept.
523 if (!aMVBounds.Contains(nV1) && !aMVBounds.Contains(nV2)) {
524 aMicroEdges.Add(aES);
525 // keep vertices for post treatment
532 Standard_Real aTolNew;
533 bExist=IsExistingPaveBlock(aPB, aNC, aTolR3D, aMPBOnIn, aMPBCommon, aPBOut, aTolNew);
535 if (!aMPBAdd.Contains(aPBOut)) {
536 Standard_Boolean bInBothFaces = Standard_True;
537 if (!myDS->IsCommonBlock(aPBOut)) {
542 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(nE);
543 aTolE = BRep_Tool::Tolerance(aE);
544 if (aTolNew < aNC.Tolerance())
545 aTolNew = aNC.Tolerance(); // use real tolerance of intersection
546 if (aTolNew > aTolE) {
547 UpdateEdgeTolerance(nE, aTolNew);
549 bInBothFaces = Standard_False;
552 bInBothFaces = (aFI1.PaveBlocksOn().Contains(aPBOut) ||
553 aFI1.PaveBlocksIn().Contains(aPBOut))&&
554 (aFI2.PaveBlocksOn().Contains(aPBOut) ||
555 aFI2.PaveBlocksIn().Contains(aPBOut));
559 PreparePostTreatFF(i, j, aPBOut, aMSCPB, aMVI, aLPBC);
566 BOPTools_AlgoTools::MakePCurve(aES, aF1, aF2, aIC,
567 mySectionAttribute.PCurveOnS1(),
568 mySectionAttribute.PCurveOnS2(),
571 // Append the Pave Block to the Curve j
574 // Keep info for post treatment
575 BOPDS_CoupleOfPaveBlocks aCPB;
576 aCPB.SetIndexInterf(i);
578 aCPB.SetPaveBlock1(aPB);
580 aMSCPB.Add(aES, aCPB);
587 bHasRealSectionEdge = Standard_True;
591 }//for (j=0; j<aNbC; ++j) {
593 //back to previous tolerance values for unused vertices
594 //and forget about SD groups of such vertices
595 aItMV.Initialize(aMVTol);
596 for (; aItMV.More(); aItMV.Next()) {
598 Standard_Real aTol = aItMV.Value();
600 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV1);
601 const Handle(BRep_TVertex)& TV =
602 *((Handle(BRep_TVertex)*)&aV.TShape());
605 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV1);
606 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
608 BRepBndLib::Add(aV, aBoxDS);
609 aBoxDS.SetGap(aBoxDS.GetGap() + Precision::Confusion());
611 if (aDMVLV.IsBound(nV1))
615 ProcessExistingPaveBlocks(i, aMPBOnIn, aDMBV, aMSCPB, aMVI, aMPBAdd);
617 // If the pair of faces has produced any real section edges
618 // it is necessary to check if these edges do not intersect
619 // any common IN edges of the faces. For that, all such edges
620 // are added for Post Treatment along with sections edges.
621 if (bHasRealSectionEdge) {
622 const BOPDS_IndexedMapOfPaveBlock& aMPBIn1 = aFI1.PaveBlocksIn();
623 const BOPDS_IndexedMapOfPaveBlock& aMPBIn2 = aFI2.PaveBlocksIn();
625 // For simplicity add all IN edges into the first set of section curves.
626 // These existing edges will be removed from the set on the post treatment
627 // stage in the UpdateFaceInfo function.
628 BOPDS_ListOfPaveBlock& aLPBC = aVC.ChangeValue(0).ChangePaveBlocks();
630 Standard_Integer aNbIn1 = aMPBIn1.Extent();
631 for (j = 1; j <= aNbIn1; ++j) {
632 const Handle(BOPDS_PaveBlock)& aPB = aMPBIn1(j);
633 if (aMPBIn2.Contains(aPB) && aMPBAdd.Add(aPB)) {
634 PreparePostTreatFF(i, 0, aPB, aMSCPB, aMVI, aLPBC);
638 }//for (i=0; i<aNbFF; ++i) {
641 MakeSDVerticesFF(aDMVLV, aDMNewSD);
642 PostTreatFF(aMSCPB, aDMExEdges, aDMNewSD, aMicroEdges, aAllocator);
646 // reduce tolerances of section edges where it is appropriate
647 CorrectToleranceOfSE();
650 UpdateFaceInfo(aDMExEdges, aDMNewSD);
651 //Update all pave blocks
652 UpdatePaveBlocks(aDMNewSD);
654 // Treat possible common zones by trying to put each section edge
655 // into all faces, not participated in creation of that edge, as IN edge
658 //-----------------------------------------------------scope t
667 //=======================================================================
668 //function : MakeSDVerticesFF
670 //=======================================================================
671 void BOPAlgo_PaveFiller::MakeSDVerticesFF
672 (const BOPCol_DataMapOfIntegerListOfInteger& theDMVLV,
673 BOPCol_DataMapOfIntegerInteger& theDMNewSD)
675 // Create a new SD vertex for each group of coinciding vertices
676 // and put new substitutions to theDMNewSD.
677 BOPCol_DataMapIteratorOfDataMapOfIntegerListOfInteger aItG(theDMVLV);
678 for (; aItG.More(); aItG.Next()) {
679 const BOPCol_ListOfInteger& aList = aItG.Value();
680 // make SD vertices w/o creation of interfs
681 Standard_Integer nSD = MakeSDVertices(aList, Standard_False);
683 BOPCol_ListIteratorOfListOfInteger aItL(aList);
684 for (; aItL.More(); aItL.Next()) {
685 Standard_Integer nV = aItL.Value();
686 theDMNewSD.Bind(nV, nSD);
691 //=======================================================================
692 //function : PostTreatFF
694 //=======================================================================
695 void BOPAlgo_PaveFiller::PostTreatFF
696 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMSCPB,
697 BOPDS_DataMapOfPaveBlockListOfPaveBlock& aDMExEdges,
698 BOPCol_DataMapOfIntegerInteger& aDMNewSD,
699 const BOPCol_IndexedMapOfShape& theMicroEdges,
700 const Handle(NCollection_BaseAllocator)& theAllocator)
702 Standard_Integer aNbS = theMSCPB.Extent();
707 Standard_Boolean bHasPaveBlocks, bOld;
708 Standard_Integer nSx, nVSD, iX, iP, iC, j, nV, iV = 0, iE, k;
709 Standard_Integer aNbLPBx;
710 TopAbs_ShapeEnum aType;
712 BOPCol_ListIteratorOfListOfShape aItLS;
713 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
715 Handle(BOPDS_PaveBlock) aPB1;
719 BOPCol_ListOfShape aLS(theAllocator);
720 BOPAlgo_PaveFiller aPF(theAllocator);
721 aPF.SetIsPrimary(Standard_False);
722 aPF.SetNonDestructive(myNonDestructive);
724 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
726 Standard_Integer aNbME = theMicroEdges.Extent();
728 if (aNbS==1 && (aNbME == 0)) {
729 const TopoDS_Shape& aS=theMSCPB.FindKey(1);
730 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromIndex(1);
732 aType=aS.ShapeType();
733 if (aType==TopAbs_VERTEX) {
734 aSI.SetShapeType(aType);
736 iV=myDS->Append(aSI);
738 iX=aCPB.IndexInterf();
740 BOPDS_InterfFF& aFF=aFFs(iX);
741 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
742 BOPDS_Point& aNP=aVNP(iP);
745 else if (aType==TopAbs_EDGE) {
746 aPB1=aCPB.PaveBlock1();
748 if (aPB1->HasEdge()) {
749 BOPDS_ListOfPaveBlock aLPBx;
751 aDMExEdges.Bind(aPB1, aLPBx);
753 aSI.SetShapeType(aType);
755 iE=myDS->Append(aSI);
763 // 1 prepare arguments
764 BOPCol_MapOfShape anAddedSD;
765 for (k=1; k<=aNbS; ++k) {
766 const TopoDS_Shape& aS=theMSCPB.FindKey(k);
768 // add vertices-candidates for SD from the map aDMNewSD,
769 // so that they took part in fuse operation.
770 TopoDS_Iterator itV(aS);
771 for (; itV.More(); itV.Next())
773 const TopoDS_Shape& aVer = itV.Value();
774 Standard_Integer iVer = myDS->Index(aVer);
775 const Standard_Integer* pSD = aDMNewSD.Seek(iVer);
778 const TopoDS_Shape& aVSD = myDS->Shape(*pSD);
779 if (anAddedSD.Add(aVSD))
785 // The section edges considered as a micro should be
786 // specially treated - their vertices should be united and
787 // the edge itself should be removed. Thus, we add only
788 // its vertices into operation.
791 for (k = 1; k <= aNbME; ++k) {
792 const TopoDS_Edge& aEM = TopoDS::Edge(theMicroEdges(k));
794 TopoDS_Vertex aVerts[2];
795 TopExp::Vertices(aEM, aVerts[0], aVerts[1]);
796 for (Standard_Integer i = 0; i < 2; ++i) {
797 nV = myDS->Index(aVerts[i]);
798 const Standard_Integer* pSD = aDMNewSD.Seek(nV);
800 aVerts[i] = TopoDS::Vertex(myDS->Shape(*pSD));
803 if (anAddedSD.Add(aVerts[i])) {
804 aLS.Append(aVerts[i]);
808 if (aVerts[0].IsSame(aVerts[1])) {
812 // make sure these vertices will be united
813 const gp_Pnt& aP1 = BRep_Tool::Pnt(aVerts[0]);
814 const gp_Pnt& aP2 = BRep_Tool::Pnt(aVerts[1]);
816 Standard_Real aDist = aP1.Distance(aP2);
817 Standard_Real aTolV1 = BRep_Tool::Tolerance(aVerts[0]);
818 Standard_Real aTolV2 = BRep_Tool::Tolerance(aVerts[1]);
820 aDist -= (aTolV1 + aTolV2);
823 aBB.UpdateVertex(aVerts[0], aTolV1 + aDist);
824 aBB.UpdateVertex(aVerts[1], aTolV2 + aDist);
829 aPF.SetProgressIndicator(myProgressIndicator);
830 aPF.SetRunParallel(myRunParallel);
831 aPF.SetArguments(aLS);
833 if (aPF.HasErrors()) {
834 AddError (new BOPAlgo_AlertPostTreatFF);
839 // Map to store the real tolerance of the common block
840 // and avoid repeated computation of it
841 NCollection_DataMap<Handle(BOPDS_CommonBlock),
843 TColStd_MapTransientHasher> aMCBTol;
844 // Map to avoid creation of different pave blocks for
845 // the same intersection edge
846 NCollection_DataMap<Standard_Integer, Handle(BOPDS_PaveBlock)> aMEPB;
848 aItLS.Initialize(aLS);
849 for (; aItLS.More(); aItLS.Next()) {
850 const TopoDS_Shape& aSx=aItLS.Value();
851 nSx=aPDS->Index(aSx);
852 const BOPDS_ShapeInfo& aSIx=aPDS->ShapeInfo(nSx);
854 aType=aSIx.ShapeType();
856 if (aType==TopAbs_VERTEX) {
857 Standard_Boolean bIntersectionPoint = theMSCPB.Contains(aSx);
859 if (aPDS->HasShapeSD(nSx, nVSD)) {
860 aV=aPDS->Shape(nVSD);
865 // index of new vertex in theDS -> iV
866 iV = myDS->Index(aV);
868 aSI.SetShapeType(aType);
870 iV=myDS->Append(aSI);
873 if (!bIntersectionPoint) {
874 // save SD connection
875 nSx = myDS->Index(aSx);
876 aDMNewSD.Bind(nSx, iV);
877 myDS->AddShapeSD(nSx, iV);
880 // update FF interference
881 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx);
882 iX=aCPB.IndexInterf();
884 BOPDS_InterfFF& aFF=aFFs(iX);
885 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
886 BOPDS_Point& aNP=aVNP(iP);
889 }//if (aType==TopAbs_VERTEX) {
891 else if (aType==TopAbs_EDGE) {
892 bHasPaveBlocks=aPDS->HasPaveBlocks(nSx);
893 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx);
894 iX=aCPB.IndexInterf();
896 aPB1=aCPB.PaveBlock1();
898 bOld = aPB1->HasEdge();
900 BOPDS_ListOfPaveBlock aLPBx;
901 aDMExEdges.Bind(aPB1, aLPBx);
904 if (!bHasPaveBlocks) {
906 aDMExEdges.ChangeFind(aPB1).Append(aPB1);
909 aSI.SetShapeType(aType);
911 iE = myDS->Append(aSI);
917 BOPDS_InterfFF& aFF=aFFs(iX);
918 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
919 BOPDS_Curve& aNC=aVNC(iC);
920 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
922 // check if edge occured to be micro edge;
923 // note we check not the edge aSx itself, but its image in aPDS
924 const BOPDS_ListOfPaveBlock& aLPBx = aPDS->PaveBlocks(nSx);
925 aNbLPBx = aLPBx.Extent();
926 if (aPDS->HasPaveBlocks(nSx) &&
927 (aNbLPBx == 0 || (aNbLPBx == 1 && !aLPBx.First()->HasShrunkData()))) {
928 BOPDS_ListIteratorOfListOfPaveBlock it(aLPBC);
929 for (; it.More(); it.Next()) {
930 if (it.Value() == aPB1) {
938 if (bOld && !aNbLPBx) {
939 aDMExEdges.ChangeFind(aPB1).Append(aPB1);
944 aItLPB.Initialize(aLPBC);
945 for (; aItLPB.More(); aItLPB.Next()) {
946 const Handle(BOPDS_PaveBlock)& aPBC=aItLPB.Value();
948 aLPBC.Remove(aItLPB);
955 aItLPB.Initialize(aLPBx);
956 for (; aItLPB.More(); aItLPB.Next()) {
957 const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value();
958 const Handle(BOPDS_PaveBlock) aPBRx=aPDS->RealPaveBlock(aPBx);
960 // update vertices of paves
961 aPave[0] = aPBx->Pave1();
962 aPave[1] = aPBx->Pave2();
963 for (j=0; j<2; ++j) {
964 nV = aPave[j].Index();
965 aV = aPDS->Shape(nV);
966 // index of new vertex in myDS -> iV
967 iV = myDS->Index(aV);
969 aSI.SetShapeType(TopAbs_VERTEX);
971 iV = myDS->Append(aSI);
973 const BOPDS_Pave& aP1 = !j ? aPB1->Pave1() : aPB1->Pave2();
974 if (aP1.Index() != iV) {
975 if (aP1.Parameter() == aPave[j].Parameter()) {
976 aDMNewSD.Bind(aP1.Index(), iV);
977 myDS->AddShapeSD(aP1.Index(), iV);
980 // check aPDS to have the SD connection between these vertices
981 const TopoDS_Shape& aVPave = myDS->Shape(aP1.Index());
982 Standard_Integer nVnewSD, nVnew = aPDS->Index(aVPave);
983 if (aPDS->HasShapeSD(nVnew, nVnewSD)) {
985 aDMNewSD.Bind(aP1.Index(), iV);
986 myDS->AddShapeSD(aP1.Index(), iV);
992 aPave[j].SetIndex(iV);
996 aE=aPDS->Shape(aPBRx->Edge());
997 iE = myDS->Index(aE);
999 aSI.SetShapeType(aType);
1001 iE=myDS->Append(aSI);
1004 // update real edge tolerance according to distances in common block if any
1005 if (aPDS->IsCommonBlock(aPBRx)) {
1006 const Handle(BOPDS_CommonBlock)& aCB = aPDS->CommonBlock(aPBRx);
1007 Standard_Real *pTol = aMCBTol.ChangeSeek(aCB);
1009 Standard_Real aTol = BOPAlgo_Tools::ComputeToleranceOfCB(aCB, aPDS, aPF.Context());
1010 pTol = aMCBTol.Bound(aCB, aTol);
1013 if (aNC.Tolerance() < *pTol) {
1014 aNC.SetTolerance(*pTol);
1017 // append new PaveBlock to aLPBC
1018 Handle(BOPDS_PaveBlock) *pPBC = aMEPB.ChangeSeek(iE);
1020 pPBC = aMEPB.Bound(iE, new BOPDS_PaveBlock());
1021 BOPDS_Pave aPaveR1, aPaveR2;
1022 aPaveR1 = aPBRx->Pave1();
1023 aPaveR2 = aPBRx->Pave2();
1024 aPaveR1.SetIndex(myDS->Index(aPDS->Shape(aPaveR1.Index())));
1025 aPaveR2.SetIndex(myDS->Index(aPDS->Shape(aPaveR2.Index())));
1027 (*pPBC)->SetPave1(aPaveR1);
1028 (*pPBC)->SetPave2(aPaveR2);
1029 (*pPBC)->SetEdge(iE);
1033 (*pPBC)->SetOriginalEdge(aPB1->OriginalEdge());
1034 aDMExEdges.ChangeFind(aPB1).Append(*pPBC);
1037 aLPBC.Append(*pPBC);
1042 }//else if (aType==TopAbs_EDGE)
1043 }//for (; aItLS.More(); aItLS.Next()) {
1045 // Update SD for vertices that did not participate in operation
1046 BOPCol_DataMapOfIntegerInteger::Iterator itDM(aDMNewSD);
1047 for (; itDM.More(); itDM.Next())
1049 const Standard_Integer* pSD = aDMNewSD.Seek(itDM.Value());
1052 itDM.ChangeValue() = *pSD;
1053 myDS->AddShapeSD(itDM.Key(), *pSD);
1059 //=======================================================================
1060 //function : UpdateFaceInfo
1062 //=======================================================================
1063 void BOPAlgo_PaveFiller::UpdateFaceInfo
1064 (BOPDS_DataMapOfPaveBlockListOfPaveBlock& theDME,
1065 const BOPCol_DataMapOfIntegerInteger& theDMV)
1067 Standard_Integer i, j, nV1, nF1, nF2,
1069 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
1070 BOPCol_MapOfInteger aMF;
1072 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
1073 aNbFF=aFFs.Extent();
1075 //1. Sections (curves, points);
1076 for (i=0; i<aNbFF; ++i) {
1077 BOPDS_InterfFF& aFF=aFFs(i);
1078 aFF.Indices(nF1, nF2);
1080 BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
1081 BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
1083 // 1.1. Section edges
1084 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
1086 for (j=0; j<aNbC; ++j) {
1087 BOPDS_Curve& aNC=aVNC(j);
1088 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
1090 // Add section edges to face info
1091 aItLPB.Initialize(aLPBC);
1092 for (; aItLPB.More(); ) {
1093 const Handle(BOPDS_PaveBlock)& aPB=aItLPB.Value();
1095 // Treat existing pave blocks
1096 if (theDME.IsBound(aPB)) {
1097 BOPDS_ListOfPaveBlock& aLPB=theDME.ChangeFind(aPB);
1098 UpdateExistingPaveBlocks(aPB, aLPB, nF1, nF2);
1099 aLPBC.Remove(aItLPB);
1103 aFI1.ChangePaveBlocksSc().Add(aPB);
1104 aFI2.ChangePaveBlocksSc().Add(aPB);
1109 // 1.2. Section vertices
1110 const BOPDS_VectorOfPoint& aVNP=aFF.Points();
1112 for (j=0; j<aNbP; ++j) {
1113 const BOPDS_Point& aNP=aVNP(j);
1118 aFI1.ChangeVerticesSc().Add(nV1);
1119 aFI2.ChangeVerticesSc().Add(nV1);
1126 Standard_Boolean bVerts, bEdges;
1128 bVerts = theDMV.Extent() > 0;
1129 bEdges = theDME.Extent() > 0;
1131 if (!bVerts && !bEdges) {
1135 // 2. Update Face Info information with new vertices and new
1136 // pave blocks created in PostTreatFF from existing ones
1137 Standard_Integer nV2, aNbPB;
1138 BOPCol_MapIteratorOfMapOfInteger aItMF;
1139 BOPCol_DataMapIteratorOfDataMapOfIntegerInteger aItMV;
1141 aItMF.Initialize(aMF);
1142 for (; aItMF.More(); aItMF.Next()) {
1143 nF1 = aItMF.Value();
1145 BOPDS_FaceInfo& aFI = myDS->ChangeFaceInfo(nF1);
1147 // 2.1. Update information about vertices
1149 BOPCol_MapOfInteger& aMVOn = aFI.ChangeVerticesOn();
1150 BOPCol_MapOfInteger& aMVIn = aFI.ChangeVerticesIn();
1152 aItMV.Initialize(theDMV);
1153 for (; aItMV.More(); aItMV.Next()) {
1155 nV2 = aItMV.Value();
1157 if (aMVOn.Remove(nV1)) {
1161 if (aMVIn.Remove(nV1)) {
1164 } // for (; aItMV.More(); aItMV.Next()) {
1167 // 2.2. Update information about pave blocks
1169 BOPDS_IndexedMapOfPaveBlock& aMPBOn = aFI.ChangePaveBlocksOn();
1170 BOPDS_IndexedMapOfPaveBlock& aMPBIn = aFI.ChangePaveBlocksIn();
1172 BOPDS_IndexedMapOfPaveBlock aMPBCopy;
1173 for (i = 0; i < 2; ++i) {
1174 BOPDS_IndexedMapOfPaveBlock& aMPBOnIn = !i ? aMPBOn : aMPBIn;
1175 aMPBCopy = aMPBOnIn;
1178 aNbPB = aMPBCopy.Extent();
1179 for (j = 1; j <= aNbPB; ++j) {
1180 const Handle(BOPDS_PaveBlock)& aPB = aMPBCopy(j);
1181 if (theDME.IsBound(aPB)) {
1182 const BOPDS_ListOfPaveBlock& aLPB = theDME.Find(aPB);
1183 if (aLPB.IsEmpty()) {
1188 aItLPB.Initialize(aLPB);
1189 for (; aItLPB.More(); aItLPB.Next()) {
1190 const Handle(BOPDS_PaveBlock)& aPB1 = aItLPB.Value();
1197 } // for (j = 1; j <= aNbPB; ++j) {
1198 } // for (i = 0; i < 2; ++i) {
1202 //=======================================================================
1203 //function : IsExistingVertex
1205 //=======================================================================
1206 Standard_Boolean BOPAlgo_PaveFiller::IsExistingVertex
1208 const Standard_Real theTolR3D,
1209 const BOPCol_MapOfInteger& aMVOnIn)const
1211 Standard_Boolean bRet;
1212 Standard_Integer nV, iFlag;
1213 Standard_Real aTolCheck;
1216 BOPCol_MapIteratorOfMapOfInteger aIt;
1218 aTolCheck = theTolR3D + myFuzzyValue;
1222 aBoxP.Enlarge(theTolR3D);
1224 aIt.Initialize(aMVOnIn);
1225 for (; aIt.More(); aIt.Next()) {
1227 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1228 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&aSIV.Shape()));
1229 const Bnd_Box& aBoxV=aSIV.Box();
1231 if (!aBoxP.IsOut(aBoxV)) {
1232 iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP, aTolCheck);
1240 //=======================================================================
1241 //function : IsExistingPaveBlock
1243 //=======================================================================
1244 Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock
1245 (const Handle(BOPDS_PaveBlock)& thePB,
1246 const BOPDS_Curve& theNC,
1247 const BOPCol_ListOfInteger& theLSE)
1249 Standard_Boolean bRet=Standard_True;
1251 if (theLSE.IsEmpty()) {
1255 Standard_Real aT1, aT2, aTm, aTx, aTolE, aTolCheck, aTol, aDist;
1256 Standard_Integer nE, iFlag, nV1, nV2;
1259 BOPCol_ListIteratorOfListOfInteger aItLI;
1261 thePB->Range(aT1, aT2);
1262 thePB->Indices(nV1, nV2);
1263 const TopoDS_Vertex &aV1 = TopoDS::Vertex(myDS->Shape(nV1)),
1264 &aV2 = TopoDS::Vertex(myDS->Shape(nV2));
1265 const Standard_Real aTolV1 = BRep_Tool::Tolerance(aV1),
1266 aTolV2 = BRep_Tool::Tolerance(aV2);
1268 aTol = Max(aTolV1, aTolV2);
1270 aTm=IntTools_Tools::IntermediatePoint (aT1, aT2);
1271 theNC.Curve().D0(aTm, aPm);
1273 aBoxPm.Enlarge(aTol);
1275 aItLI.Initialize(theLSE);
1276 for (; aItLI.More(); aItLI.Next()) {
1280 const BOPDS_ShapeInfo& aSIE=myDS->ChangeShapeInfo(nE);
1281 const Bnd_Box& aBoxE=aSIE.Box();
1282 if (!aBoxE.IsOut(aBoxPm)) {
1283 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape()));
1284 aTolE = BRep_Tool::Tolerance(aE);
1285 aTolCheck = Max(aTolE, aTol) + myFuzzyValue;
1286 iFlag = myContext->ComputePE(aPm, aTolCheck, aE, aTx, aDist);
1295 //=======================================================================
1296 //function : IsExistingPaveBlock
1298 //=======================================================================
1299 Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock
1300 (const Handle(BOPDS_PaveBlock)& thePB,
1301 const BOPDS_Curve& theNC,
1302 const Standard_Real theTolR3D,
1303 const BOPDS_IndexedMapOfPaveBlock& theMPBOnIn,
1304 const BOPDS_MapOfPaveBlock& theMPBCommon,
1305 Handle(BOPDS_PaveBlock)& aPBOut,
1306 Standard_Real& theTolNew)
1308 Standard_Boolean bRet;
1309 Standard_Real aT1, aT2, aTm, aTx, aTolCheck;
1310 Standard_Integer nSp, iFlag1, iFlag2, nV11, nV12, nV21, nV22, i, aNbPB;
1311 gp_Pnt aP1, aPm, aP2;
1312 Bnd_Box aBoxP1, aBoxPm, aBoxP2, aBoxTmp;
1314 bRet=Standard_False;
1315 aTolCheck = theTolR3D + myFuzzyValue;
1316 const IntTools_Curve& aIC=theNC.Curve();
1318 thePB->Range(aT1, aT2);
1319 thePB->Indices(nV11, nV12);
1320 const Standard_Real aTolV11 = BRep_Tool::Tolerance(TopoDS::Vertex(myDS->Shape(nV11)));
1321 const Standard_Real aTolV12 = BRep_Tool::Tolerance(TopoDS::Vertex(myDS->Shape(nV12)));
1322 const Standard_Real aTolV1 = Max(aTolV11, aTolV12) + myFuzzyValue;
1327 aBoxP1.Enlarge(aTolV11);
1328 //intermediate point
1329 aTm=IntTools_Tools::IntermediatePoint (aT1, aT2);
1335 aBoxP2.Enlarge(aTolV12);
1338 aNbPB = theMPBOnIn.Extent();
1339 for (i = 1; i <= aNbPB; ++i) {
1340 const Handle(BOPDS_PaveBlock)& aPB = theMPBOnIn(i);
1341 aPB->Indices(nV21, nV22);
1342 const Standard_Real aTolV21 = BRep_Tool::Tolerance(TopoDS::Vertex(myDS->Shape(nV21)));
1343 const Standard_Real aTolV22 = BRep_Tool::Tolerance(TopoDS::Vertex(myDS->Shape(nV22)));
1344 const Standard_Real aTolV2 = Max(aTolV21, aTolV22) + myFuzzyValue;
1348 const BOPDS_ShapeInfo& aSISp=myDS->ChangeShapeInfo(nSp);
1349 const TopoDS_Edge& aSp=(*(TopoDS_Edge *)(&aSISp.Shape()));
1350 const Bnd_Box& aBoxSp=aSISp.Box();
1352 iFlag1 = (nV11 == nV21 || nV11 == nV22) ? 2 :
1353 (!aBoxSp.IsOut(aBoxP1) ? 1 : 0);
1354 iFlag2 = (nV12 == nV21 || nV12 == nV22) ? 2 :
1355 (!aBoxSp.IsOut(aBoxP2) ? 1 : 0);
1356 if (iFlag1 && iFlag2) {
1357 Standard_Real aDist = 0.;
1359 Standard_Real aRealTol = aTolCheck;
1360 if (myDS->IsCommonBlock(aPB))
1362 aRealTol = Max(aRealTol, Max(aTolV1, aTolV2));
1363 if (theMPBCommon.Contains(aPB))
1364 // for an edge, which is a common block with a face,
1365 // increase the chance to coincide with section curve
1370 aBoxTmp.Enlarge(aRealTol);
1372 if (aBoxSp.IsOut(aBoxTmp) || myContext->ComputePE(aPm,
1380 iFlag1 = !myContext->ComputePE(aP1, aRealTol, aSp, aTx, aDist);
1381 if (iFlag1 && theTolNew < aDist)
1386 iFlag2 = !myContext->ComputePE(aP2, aRealTol, aSp, aTx, aDist);
1387 if (iFlag2 && theTolNew < aDist)
1391 if (iFlag1 && iFlag2) {
1400 //=======================================================================
1401 //function : PutBoundPaveOnCurve
1403 //=======================================================================
1404 void BOPAlgo_PaveFiller::PutBoundPaveOnCurve(const TopoDS_Face& aF1,
1405 const TopoDS_Face& aF2,
1407 BOPCol_ListOfInteger& aLVB)
1409 Standard_Boolean bVF;
1410 Standard_Integer nV, iFlag, nVn, j, aNbEP;
1411 Standard_Real aT[2], aTmin, aTmax, aTV, aTol, aTolVnew;
1414 BOPDS_ListIteratorOfListOfPave aItLP;
1415 BOPDS_Pave aPn, aPMM[2];
1417 aTolVnew = Precision::Confusion();
1419 const IntTools_Curve& aIC=aNC.Curve();
1420 aIC.Bounds(aT[0], aT[1], aP[0], aP[1]);
1421 Standard_Real aTolR3D = Max(aNC.Tolerance(), aNC.TangentialTolerance());
1423 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1424 const BOPDS_ListOfPave& aLP=aPB->ExtPaves();
1431 aItLP.Initialize(aLP);
1432 for (; aItLP.More(); aItLP.Next()) {
1433 const BOPDS_Pave& aPv=aItLP.Value();
1434 aPv.Contents(nV, aTV);
1446 for (j=0; j<2; ++j) {
1447 //if curve is closed, process only one bound
1448 if (j && aP[1].IsEqual(aP[0], aTolVnew)) {
1458 aTol = aTolR3D+Precision::Confusion();
1459 aBoxP.Enlarge(aTol);
1460 const BOPDS_Pave& aPV=aPMM[j];
1462 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1463 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&aSIV.Shape()));
1464 const Bnd_Box& aBoxV=aSIV.Box();
1465 if (!aBoxP.IsOut(aBoxV)){
1466 iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP[j], aTol);
1471 bVF=myContext->IsValidPointForFaces (aP[j], aF1, aF2, aTolR3D);
1476 BOPDS_ShapeInfo aSIVn;
1478 BOPTools_AlgoTools::MakeNewVertex(aP[j], aTolR3D, aVn);
1479 aSIVn.SetShapeType(TopAbs_VERTEX);
1480 aSIVn.SetShape(aVn);
1482 nVn=myDS->Append(aSIVn);
1485 aPn.SetParameter(aT[j]);
1486 aPB->AppendExtPave(aPn);
1488 aVn=(*(TopoDS_Vertex *)(&myDS->Shape(nVn)));
1489 BOPTools_AlgoTools::UpdateVertex (aIC, aT[j], aVn);
1491 aTolVnew = BRep_Tool::Tolerance(aVn);
1493 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nVn);
1494 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
1495 BRepBndLib::Add(aVn, aBoxDS);
1496 aBoxDS.SetGap(aBoxDS.GetGap() + Precision::Confusion());
1503 //=======================================================================
1504 //function : PutPavesOnCurve
1506 //=======================================================================
1507 void BOPAlgo_PaveFiller::PutPavesOnCurve
1508 (const BOPCol_MapOfInteger& aMVOnIn,
1510 const Standard_Integer nF1,
1511 const Standard_Integer nF2,
1512 const BOPCol_MapOfInteger& aMI,
1513 const BOPCol_MapOfInteger& aMVEF,
1514 BOPCol_DataMapOfIntegerReal& aMVTol,
1515 BOPCol_DataMapOfIntegerListOfInteger& aDMVLV)
1517 Standard_Boolean bInBothFaces;
1518 Standard_Integer nV;
1519 BOPCol_MapIteratorOfMapOfInteger aIt;
1521 const Bnd_Box& aBoxC=aNC.Box();
1522 Standard_Real aTolR3D = Max(aNC.Tolerance(), aNC.TangentialTolerance());
1524 //Put EF vertices first
1525 aIt.Initialize(aMVEF);
1526 for (; aIt.More(); aIt.Next()) {
1528 PutPaveOnCurve(nV, aTolR3D, aNC, aMI, aMVTol, aDMVLV, 2);
1530 //Put all other vertices
1531 aIt.Initialize(aMVOnIn);
1532 for (; aIt.More(); aIt.Next()) {
1534 if (aMVEF.Contains(nV)) {
1538 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1539 const Bnd_Box& aBoxV=aSIV.Box();
1541 if (aBoxC.IsOut(aBoxV)){
1544 if (!myDS->IsNewShape(nV)) {
1545 const BOPDS_FaceInfo& aFI1 = myDS->FaceInfo(nF1);
1546 const BOPDS_FaceInfo& aFI2 = myDS->FaceInfo(nF2);
1548 bInBothFaces = (aFI1.VerticesOn().Contains(nV) ||
1549 aFI1.VerticesIn().Contains(nV))&&
1550 (aFI2.VerticesOn().Contains(nV) ||
1551 aFI2.VerticesIn().Contains(nV));
1552 if (!bInBothFaces) {
1557 PutPaveOnCurve(nV, aTolR3D, aNC, aMI, aMVTol, aDMVLV, 1);
1561 //=======================================================================
1562 //function : FilterPavesOnCurves
1564 //=======================================================================
1566 struct PaveBlockDist {
1567 Handle(BOPDS_PaveBlock) PB;
1568 Standard_Real Dist; // square distance from vertex to the paveblock
1569 Standard_Real SinAngle; // sinus of angle between projection vector
1570 // and tangent at projection point
1571 Standard_Real Tolerance; // tolerance of the section curve
1574 void BOPAlgo_PaveFiller::FilterPavesOnCurves(const BOPDS_VectorOfCurve& theVNC)
1576 // For each vertex found in ExtPaves of pave blocks of section curves
1577 // collect list of pave blocks with distance to the curve
1578 NCollection_IndexedDataMap<Standard_Integer,NCollection_List<PaveBlockDist> > aIDMVertPBs;
1580 const Standard_Real anEps = gp::Resolution();
1581 for (i = 0; i < theVNC.Extent(); ++i)
1583 const BOPDS_Curve& aNC = theVNC(i);
1584 const IntTools_Curve& aIC = aNC.Curve();
1585 const Standard_Real aTolR3D = Max(aNC.Tolerance(), aNC.TangentialTolerance());
1586 GeomAdaptor_Curve aGAC(aIC.Curve());
1587 const Handle(BOPDS_PaveBlock)& aPB = aNC.PaveBlocks().First();
1588 const BOPDS_ListOfPave& aPaves = aPB->ExtPaves();
1589 BOPDS_ListOfPave::Iterator itPaves(aPaves);
1590 for (; itPaves.More(); itPaves.Next())
1592 const BOPDS_Pave& aPave = itPaves.Value();
1593 Standard_Integer nV = aPave.Index();
1594 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV));
1595 // compute distance from vertex to the point on curve with vertex parameter
1596 gp_Pnt aPV = BRep_Tool::Pnt(aV);
1597 Standard_Real aPar = aPave.Parameter();
1600 aGAC.D1(aPar, aPonC, aD1);
1601 gp_Vec aProjVec(aPV, aPonC);
1602 Standard_Real aSqDist = aProjVec.SquareMagnitude();
1603 Standard_Real aSqD1Mod = aD1.SquareMagnitude();
1604 Standard_Real aSin = aProjVec.CrossSquareMagnitude(aD1);
1605 if (aSqDist > anEps && aSqD1Mod > anEps)
1606 aSin = sqrt(aSin / aSqDist / aSqD1Mod);
1607 NCollection_List<PaveBlockDist>* pList = aIDMVertPBs.ChangeSeek(nV);
1609 pList = &aIDMVertPBs.ChangeFromIndex(aIDMVertPBs.Add(nV, NCollection_List<PaveBlockDist>()));
1610 PaveBlockDist aPBD = { aPB, aSqDist, aSin, aTolR3D };
1611 pList->Append(aPBD);
1615 // Process each vertex
1616 const Standard_Real aSinAngleMin = 0.5; // angle below which projection is suspicious
1617 for (i = 1; i <= aIDMVertPBs.Extent(); i++)
1619 Standard_Integer nV = aIDMVertPBs.FindKey(i);
1620 const NCollection_List<PaveBlockDist>& aList = aIDMVertPBs(i);
1621 // Find a pave with minimal distance
1622 Standard_Real aMinDist = RealLast();
1623 Handle(BOPDS_PaveBlock) aPBMinDist;
1624 NCollection_List<PaveBlockDist>::Iterator itL(aList);
1625 for (; itL.More(); itL.Next())
1627 const PaveBlockDist& aPBD = itL.Value();
1628 if (aPBD.Dist < aMinDist)
1630 aMinDist = aPBD.Dist;
1631 aPBMinDist = aPBD.PB;
1634 // Remove a vertex from a pave block if the distance is greater than the tolerance
1635 // and there are other pave blocks for which the distance is less than the current.
1636 // Do not remove a vertex if it is projected on the curve with quite large angle
1637 // (see test bugs modalg_6 bug27761).
1638 for (itL.Init(aList); itL.More(); itL.Next())
1640 const PaveBlockDist& aPBD = itL.Value();
1641 Standard_Real aCheckDist = 100. * Max(aPBD.Tolerance*aPBD.Tolerance, aMinDist);
1642 if (aPBD.Dist > aCheckDist && aPBD.SinAngle < aSinAngleMin)
1644 aPBD.PB->RemoveExtPave(nV);
1650 //=======================================================================
1651 //function : ExtendedTolerance
1653 //=======================================================================
1654 Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance
1655 (const Standard_Integer nV,
1656 const BOPCol_MapOfInteger& aMI,
1657 Standard_Real& aTolVExt,
1658 const Standard_Integer aType)
1660 Standard_Boolean bFound = Standard_False;
1661 if (!(myDS->IsNewShape(nV))) {
1665 Standard_Integer i, k, aNbLines, aNbInt;
1666 Standard_Real aT11, aT12, aD1, aD2, aD;
1668 gp_Pnt aPV, aP11, aP12;
1674 } else if (aType == 2) {
1678 aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1679 aPV=BRep_Tool::Pnt(aV);
1681 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
1682 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1684 for (; k<aNbInt; ++k) {
1685 aNbLines = !k ? aEEs.Extent() : aEFs.Extent();
1686 for (i = 0; i < aNbLines; ++i) {
1687 BOPDS_Interf *aInt = !k ? (BOPDS_Interf*) (&aEEs(i)) :
1688 (BOPDS_Interf*) (&aEFs(i));
1689 if (aInt->IndexNew() == nV) {
1690 if (aMI.Contains(aInt->Index1()) &&
1691 aMI.Contains(aInt->Index2())) {
1692 const IntTools_CommonPrt& aComPrt = !k ? aEEs(i).CommonPart() :
1693 aEFs(i).CommonPart();
1695 const TopoDS_Edge& aE1=aComPrt.Edge1();
1696 aComPrt.Range1(aT11, aT12);
1697 BOPTools_AlgoTools::PointOnEdge(aE1, aT11, aP11);
1698 BOPTools_AlgoTools::PointOnEdge(aE1, aT12, aP12);
1699 aD1=aPV.Distance(aP11);
1700 aD2=aPV.Distance(aP12);
1701 aD=(aD1>aD2)? aD1 : aD2;
1706 }//if (aMI.Contains(aEF.Index1()) && aMI.Contains(aEF.Index2())) {
1707 }//if (aInt->IndexNew() == nV) {
1708 }//for (i = 0; i < aNbLines; ++i) {
1709 }//for (k=0; k<2; ++k) {
1713 //=======================================================================
1714 //function : GetEFPnts
1716 //=======================================================================
1717 void BOPAlgo_PaveFiller::GetEFPnts
1718 (const Standard_Integer nF1,
1719 const Standard_Integer nF2,
1720 IntSurf_ListOfPntOn2S& aListOfPnts)
1722 Standard_Integer nE, nF, nFOpposite, aNbEFs, i;
1723 Standard_Real U1, U2, V1, V2, f, l;
1724 BOPCol_MapOfInteger aMI;
1726 //collect indexes of all shapes from nF1 and nF2.
1727 GetFullShapeMap(nF1, aMI);
1728 GetFullShapeMap(nF2, aMI);
1730 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1731 aNbEFs = aEFs.Extent();
1733 for(i = 0; i < aNbEFs; ++i) {
1734 const BOPDS_InterfEF& aEF = aEFs(i);
1735 if (aEF.HasIndexNew()) {
1736 aEF.Indices(nE, nFOpposite);
1737 if(aMI.Contains(nE) && aMI.Contains(nFOpposite)) {
1738 const IntTools_CommonPrt& aCP = aEF.CommonPart();
1739 Standard_Real aPar = aCP.VertexParameter1();
1740 const TopoDS_Edge& aE = (*(TopoDS_Edge*)(&myDS->Shape(nE)));
1741 const TopoDS_Face& aFOpposite =
1742 (*(TopoDS_Face*)(&myDS->Shape(nFOpposite)));
1744 const Handle(Geom_Curve)& aCurve = BRep_Tool::Curve(aE, f, l);
1746 nF = (nFOpposite == nF1) ? nF2 : nF1;
1747 const TopoDS_Face& aF = (*(TopoDS_Face*)(&myDS->Shape(nF)));
1748 Handle(Geom2d_Curve) aPCurve =
1749 BRep_Tool::CurveOnSurface(aE, aF, f, l);
1751 GeomAPI_ProjectPointOnSurf& aProj=myContext->ProjPS(aFOpposite);
1754 aCurve->D0(aPar, aPoint);
1755 IntSurf_PntOn2S aPnt;
1756 if(!aPCurve.IsNull()) {
1757 gp_Pnt2d aP2d = aPCurve->Value(aPar);
1758 aProj.Perform(aPoint);
1759 if(aProj.IsDone()) {
1760 aProj.LowerDistanceParameters(U1,V1);
1762 aPnt.SetValue(aP2d.X(),aP2d.Y(),U1,V1);
1764 aPnt.SetValue(U1,V1,aP2d.X(),aP2d.Y());
1766 aListOfPnts.Append(aPnt);
1770 GeomAPI_ProjectPointOnSurf& aProj1 = myContext->ProjPS(aF);
1771 aProj1.Perform(aPoint);
1772 aProj.Perform(aPoint);
1773 if(aProj1.IsDone() && aProj.IsDone()){
1774 aProj1.LowerDistanceParameters(U1,V1);
1775 aProj.LowerDistanceParameters(U2,V2);
1777 aPnt.SetValue(U1,V1,U2,V2);
1779 aPnt.SetValue(U2,V2,U1,V1);
1781 aListOfPnts.Append(aPnt);
1789 //=======================================================================
1790 //function : PutEFPavesOnCurve
1792 //=======================================================================
1793 void BOPAlgo_PaveFiller::PutEFPavesOnCurve
1795 const BOPCol_MapOfInteger& aMI,
1796 const BOPCol_MapOfInteger& aMVEF,
1797 BOPCol_DataMapOfIntegerReal& aMVTol,
1798 BOPCol_DataMapOfIntegerListOfInteger& aDMVLV)
1800 if (!aMVEF.Extent()) {
1804 const IntTools_Curve& aIC=aNC.Curve();
1805 GeomAbs_CurveType aTypeC;
1807 if (!(aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve)) {
1811 Standard_Integer nV;
1812 BOPCol_MapOfInteger aMV;
1815 RemoveUsedVertices(aNC, aMV);
1816 if (!aMV.Extent()) {
1820 Standard_Real aDist;
1823 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1824 GeomAPI_ProjectPointOnCurve& aProjPT = myContext->ProjPT(aC3D);
1826 BOPCol_MapIteratorOfMapOfInteger aItMI;
1827 aItMI.Initialize(aMV);
1828 for (; aItMI.More(); aItMI.Next()) {
1830 const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1831 gp_Pnt aPV = BRep_Tool::Pnt(aV);
1832 aProjPT.Perform(aPV);
1833 Standard_Integer aNbPoints = aProjPT.NbPoints();
1835 aDist = aProjPT.LowerDistance();
1836 PutPaveOnCurve(nV, aDist, aNC, aMI, aMVTol, aDMVLV);
1841 //=======================================================================
1842 //function : ProcessUnUsedVertices
1844 //=======================================================================
1845 void BOPAlgo_PaveFiller::PutStickPavesOnCurve
1846 (const TopoDS_Face& aF1,
1847 const TopoDS_Face& aF2,
1848 const BOPCol_MapOfInteger& aMI,
1850 const BOPCol_MapOfInteger& aMVStick,
1851 BOPCol_DataMapOfIntegerReal& aMVTol,
1852 BOPCol_DataMapOfIntegerListOfInteger& aDMVLV)
1854 BOPCol_MapOfInteger aMV;
1855 aMV.Assign(aMVStick);
1856 RemoveUsedVertices(aNC, aMV);
1858 if (!aMV.Extent()) {
1862 Handle(Geom_Surface) aS1=BRep_Tool::Surface(aF1);
1863 Handle(Geom_Surface) aS2=BRep_Tool::Surface(aF2);
1865 const IntTools_Curve& aIC=aNC.Curve();
1866 //if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
1867 Handle(Geom2d_Curve) aC2D[2];
1869 aC2D[0]=aIC.FirstCurve2d();
1870 aC2D[1]=aIC.SecondCurve2d();
1871 if (!aC2D[0].IsNull() && !aC2D[1].IsNull()) {
1872 Standard_Integer nV, m, n;
1873 Standard_Real aTC[2], aD, aD2, u, v, aDT2, aScPr, aDScPr;
1877 BOPCol_MapIteratorOfMapOfInteger aItMI, aItMI1;
1879 aDT2=2e-7; // the rich criteria
1880 aDScPr=5.e-9; // the creasing criteria
1881 aIC.Bounds(aTC[0], aTC[1], aPC[0], aPC[1]);
1883 aItMI.Initialize(aMV);
1884 for (; aItMI.More(); aItMI.Next()) {
1886 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&myDS->Shape(nV));
1887 aPV=BRep_Tool::Pnt(aV);
1889 for (m=0; m<2; ++m) {
1890 aD2=aPC[m].SquareDistance(aPV);
1891 if (aD2>aDT2) {// no rich
1895 for (n=0; n<2; ++n) {
1896 Handle(Geom_Surface)& aS=(!n)? aS1 : aS2;
1897 aC2D[n]->D0(aTC[m], aP2D);
1899 BOPTools_AlgoTools3D::GetNormalToSurface(aS, u, v, aDN[n]);
1902 aScPr=aDN[0]*aDN[1];
1912 // The intersection curve aIC is vanishing curve (the crease)
1915 PutPaveOnCurve(nV, aD, aNC, aMI, aMVTol, aDMVLV);
1917 }//for (jVU=1; jVU=aNbVU; ++jVU) {
1919 //}//if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
1920 //}//if(aType1==GeomAbs_Torus || aType2==GeomAbs_Torus) {
1923 //=======================================================================
1924 //function : GetStickVertices
1926 //=======================================================================
1927 void BOPAlgo_PaveFiller::GetStickVertices(const Standard_Integer nF1,
1928 const Standard_Integer nF2,
1929 BOPCol_MapOfInteger& aMVStick,
1930 BOPCol_MapOfInteger& aMVEF,
1931 BOPCol_MapOfInteger& aMI)
1933 Standard_Integer nS1, nS2, nVNew, aTypeInt, i;
1935 BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV();
1936 BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
1937 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
1938 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
1939 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1941 Standard_Integer aNbLines[5] = {
1942 aVVs.Extent(), aVEs.Extent(), aEEs.Extent(),
1943 aVFs.Extent(), aEFs.Extent()
1945 //collect indices of all shapes from nF1 and nF2.
1947 GetFullShapeMap(nF1, aMI);
1948 GetFullShapeMap(nF2, aMI);
1950 //collect VV, VE, EE, VF interferences
1951 for (aTypeInt = 0; aTypeInt < 4; ++aTypeInt) {
1952 for (i = 0; i < aNbLines[aTypeInt]; ++i) {
1953 BOPDS_Interf* aInt = (aTypeInt==0) ? (BOPDS_Interf*)(&aVVs(i)) :
1954 ((aTypeInt==1) ? (BOPDS_Interf*)(&aVEs(i)) :
1955 ((aTypeInt==2) ? (BOPDS_Interf*)(&aEEs(i)) :
1956 (BOPDS_Interf*)(&aVFs(i))));
1957 if (aInt->HasIndexNew()) {
1958 aInt->Indices(nS1, nS2);
1959 if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
1960 nVNew = aInt->IndexNew();
1961 aMVStick.Add(nVNew);
1966 //collect EF interferences
1967 for (i = 0; i < aNbLines[4]; ++i) {
1968 const BOPDS_InterfEF& aInt = aEFs(i);
1969 if (aInt.HasIndexNew()) {
1970 aInt.Indices(nS1, nS2);
1971 if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
1972 nVNew = aInt.IndexNew();
1973 aMVStick.Add(nVNew);
1980 //=======================================================================
1981 // function: GetFullShapeMap
1983 //=======================================================================
1984 void BOPAlgo_PaveFiller::GetFullShapeMap(const Standard_Integer nF,
1985 BOPCol_MapOfInteger& aMI)
1987 BOPCol_ListIteratorOfListOfInteger aIt;
1988 Standard_Integer nS;
1990 const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(nF);
1991 const BOPCol_ListOfInteger& aLI = aSI.SubShapes();
1994 aIt.Initialize(aLI);
1995 for (; aIt.More(); aIt.Next()) {
2001 //=======================================================================
2002 // function: RemoveUsedVertices
2004 //=======================================================================
2005 void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
2006 BOPCol_MapOfInteger& aMV)
2008 if (!aMV.Extent()) {
2011 Standard_Integer nV;
2013 BOPDS_ListIteratorOfListOfPave aItLP;
2015 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
2016 const BOPDS_ListOfPave& aLP = aPB->ExtPaves();
2017 aItLP.Initialize(aLP);
2018 for (;aItLP.More();aItLP.Next()) {
2019 aPave = aItLP.Value();
2025 //=======================================================================
2026 //function : PutPaveOnCurve
2028 //=======================================================================
2029 void BOPAlgo_PaveFiller::PutPaveOnCurve
2030 (const Standard_Integer nV,
2031 const Standard_Real aTolR3D,
2032 const BOPDS_Curve& aNC,
2033 const BOPCol_MapOfInteger& aMI,
2034 BOPCol_DataMapOfIntegerReal& aMVTol,
2035 BOPCol_DataMapOfIntegerListOfInteger& aDMVLV,
2036 const Standard_Integer iCheckExtend)
2038 Standard_Boolean bIsVertexOnLine;
2041 const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
2042 const Handle(BOPDS_PaveBlock)& aPB = aNC.PaveBlocks().First();
2043 const IntTools_Curve& aIC = aNC.Curve();
2045 Standard_Real aTolV = (aMVTol.IsBound(nV) ? aMVTol(nV) : BRep_Tool::Tolerance(aV));
2047 bIsVertexOnLine = myContext->IsVertexOnLine(aV, aTolV, aIC, aTolR3D + myFuzzyValue, aT);
2048 if (!bIsVertexOnLine && iCheckExtend) {
2049 ExtendedTolerance(nV, aMI, aTolV, iCheckExtend);
2050 bIsVertexOnLine = myContext->IsVertexOnLine(aV, aTolV, aIC, aTolR3D + myFuzzyValue, aT);
2053 if (bIsVertexOnLine) {
2054 // check if aPB contains the parameter aT
2055 Standard_Boolean bExist;
2056 Standard_Integer nVUsed;
2057 Standard_Real aPTol, aDTol;
2061 GeomAdaptor_Curve aGAC(aIC.Curve());
2062 aPTol = aGAC.Resolution(Max(aTolR3D, aTolV));
2064 bExist = aPB->ContainsParameter(aT, aPTol, nVUsed);
2066 // use existing pave
2067 BOPCol_ListOfInteger* pList = aDMVLV.ChangeSeek(nVUsed);
2069 pList = aDMVLV.Bound(nVUsed, BOPCol_ListOfInteger());
2070 pList->Append(nVUsed);
2071 if (!aMVTol.IsBound(nVUsed)) {
2072 const TopoDS_Vertex& aVUsed = (*(TopoDS_Vertex *)(&myDS->Shape(nVUsed)));
2073 aTolV = BRep_Tool::Tolerance(aVUsed);
2074 aMVTol.Bind(nVUsed, aTolV);
2077 // avoid repeated elements in the list
2078 BOPCol_ListIteratorOfListOfInteger aItLI(*pList);
2079 for (; aItLI.More(); aItLI.Next()) {
2080 if (aItLI.Value() == nV) {
2084 if (!aItLI.More()) {
2087 // save initial tolerance for the vertex
2088 if (!aMVTol.IsBound(nV)) {
2089 aTolV = BRep_Tool::Tolerance(aV);
2090 aMVTol.Bind(nV, aTolV);
2097 aPave.SetParameter(aT);
2098 aPB->AppendExtPave(aPave);
2100 gp_Pnt aP1 = aGAC.Value(aT);
2101 aTolV = BRep_Tool::Tolerance(aV);
2102 gp_Pnt aP2 = BRep_Tool::Pnt(aV);
2103 Standard_Real aDist = aP1.Distance(aP2);
2104 if (aDist > aTolV) {
2105 BRep_Builder().UpdateVertex(aV, aDist + aDTol);
2107 if (!aMVTol.IsBound(nV)) {
2108 aMVTol.Bind(nV, aTolV);
2111 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV);
2112 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
2113 BRepBndLib::Add(aV, aBoxDS);
2114 aBoxDS.SetGap(aBoxDS.GetGap() + Precision::Confusion());
2120 //=======================================================================
2121 //function : ProcessExistingPaveBlocks
2123 //=======================================================================
2124 void BOPAlgo_PaveFiller::ProcessExistingPaveBlocks
2125 (const Standard_Integer theInt,
2126 const BOPDS_IndexedMapOfPaveBlock& aMPBOnIn,
2127 const BOPCol_DataMapOfIntegerListOfInteger& aDMBV,
2128 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
2129 BOPCol_DataMapOfShapeInteger& aMVI,
2130 BOPDS_MapOfPaveBlock& aMPB)
2132 if (aDMBV.IsEmpty()) {
2136 Standard_Real aT, dummy;
2137 Standard_Integer i, nV, nE, iC, aNbPB, iFlag;
2138 BOPCol_ListIteratorOfListOfInteger aItLI;
2139 BOPCol_DataMapIteratorOfDataMapOfIntegerListOfInteger aItBV;
2141 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
2142 BOPDS_InterfFF& aFF = aFFs(theInt);
2143 BOPDS_VectorOfCurve& aVC = aFF.ChangeCurves();
2145 aNbPB = aMPBOnIn.Extent();
2147 aItBV.Initialize(aDMBV);
2148 for (; aItBV.More(); aItBV.Next()) {
2150 const BOPCol_ListOfInteger& aLBV = aItBV.Value();
2152 BOPDS_Curve& aNC = aVC.ChangeValue(iC);
2153 BOPDS_ListOfPaveBlock& aLPBC = aNC.ChangePaveBlocks();
2155 aItLI.Initialize(aLBV);
2156 for (; aItLI.More(); aItLI.Next()) {
2158 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
2159 const Bnd_Box& aBoxV=aSIV.Box();
2160 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&aSIV.Shape();
2161 if (!aMVI.IsBound(aV)) {
2165 for (i = 1; i <= aNbPB; ++i) {
2166 const Handle(BOPDS_PaveBlock)& aPB = aMPBOnIn(i);
2167 if (aPB->Pave1().Index() == nV || aPB->Pave2().Index() == nV) {
2171 if (aMPB.Contains(aPB)) {
2174 if (myDS->ShapeInfo(aPB->OriginalEdge()).HasFlag()) { // skip degenerated edges
2179 const BOPDS_ShapeInfo& aSIE = myDS->ShapeInfo(nE);
2180 const Bnd_Box& aBoxE = aSIE.Box();
2182 if (aBoxV.IsOut(aBoxE)) {
2186 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aSIE.Shape();
2188 iFlag = myContext->ComputeVE(aV, aE, aT, dummy, myFuzzyValue);
2191 PreparePostTreatFF(theInt, iC, aPB, aMSCPB, aMVI, aLPBC);
2197 //=======================================================================
2198 //function : UpdateExistingPaveBlocks
2200 //=======================================================================
2201 void BOPAlgo_PaveFiller::UpdateExistingPaveBlocks
2202 (const Handle(BOPDS_PaveBlock)& aPBf,
2203 BOPDS_ListOfPaveBlock& aLPB,
2204 const Standard_Integer nF1,
2205 const Standard_Integer nF2)
2207 if (!aLPB.Extent()) {
2211 Standard_Integer nE;
2212 Standard_Boolean bCB;
2213 Handle(BOPDS_PaveBlock) aPB, aPB1, aPB2, aPB2n;
2214 Handle(BOPDS_CommonBlock) aCB;
2215 BOPDS_ListIteratorOfListOfPaveBlock aIt, aIt1, aIt2;
2217 BOPDS_FaceInfo& aFI1 = myDS->ChangeFaceInfo(nF1);
2218 BOPDS_FaceInfo& aFI2 = myDS->ChangeFaceInfo(nF2);
2220 BOPDS_IndexedMapOfPaveBlock& aMPBOn1 = aFI1.ChangePaveBlocksOn();
2221 BOPDS_IndexedMapOfPaveBlock& aMPBIn1 = aFI1.ChangePaveBlocksIn();
2222 BOPDS_IndexedMapOfPaveBlock& aMPBOn2 = aFI2.ChangePaveBlocksOn();
2223 BOPDS_IndexedMapOfPaveBlock& aMPBIn2 = aFI2.ChangePaveBlocksIn();
2225 // 1. Remove old pave blocks
2226 const Handle(BOPDS_CommonBlock)& aCB1 = myDS->CommonBlock(aPBf);
2227 bCB = !aCB1.IsNull();
2228 BOPDS_ListOfPaveBlock aLPB1;
2231 aLPB1.Assign(aCB1->PaveBlocks());
2235 aIt1.Initialize(aLPB1);
2236 for (; aIt1.More(); aIt1.Next()) {
2237 aPB1 = aIt1.Value();
2238 nE = aPB1->OriginalEdge();
2240 BOPDS_ListOfPaveBlock& aLPB2 = myDS->ChangePaveBlocks(nE);
2241 aIt2.Initialize(aLPB2);
2242 for (; aIt2.More(); aIt2.Next()) {
2243 aPB2 = aIt2.Value();
2251 // 2. Update pave blocks
2253 // Create new common blocks
2254 BOPDS_ListOfPaveBlock aLPBNew;
2255 const BOPCol_ListOfInteger& aFaces = aCB1->Faces();
2256 aIt.Initialize(aLPB);
2257 for (; aIt.More(); aIt.Next()) {
2258 const Handle(BOPDS_PaveBlock)& aPBValue = aIt.Value();
2259 BOPDS_Pave aPBValuePaves[2] = {aPBValue->Pave1(), aPBValue->Pave2()};
2261 aCB = new BOPDS_CommonBlock;
2262 aIt1.Initialize(aLPB1);
2263 for (; aIt1.More(); aIt1.Next()) {
2264 aPB2 = aIt1.Value();
2265 nE = aPB2->OriginalEdge();
2267 // Create new pave block
2268 aPB2n = new BOPDS_PaveBlock;
2269 if (aPBValue->OriginalEdge() == nE) {
2270 aPB2n->SetPave1(aPBValuePaves[0]);
2271 aPB2n->SetPave2(aPBValuePaves[1]);
2274 // For the different original edge compute the parameters of paves
2275 BOPDS_Pave aPave[2];
2276 for (Standard_Integer i = 0; i < 2; ++i) {
2277 Standard_Integer nV = aPBValuePaves[i].Index();
2278 aPave[i].SetIndex(nV);
2279 if (nV == aPB2->Pave1().Index()) {
2280 aPave[i].SetParameter(aPB2->Pave1().Parameter());
2282 else if (nV == aPB2->Pave2().Index()) {
2283 aPave[i].SetParameter(aPB2->Pave2().Parameter());
2286 // Compute the parameter by projecting the point
2287 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV));
2288 const TopoDS_Edge& aEOr = TopoDS::Edge(myDS->Shape(nE));
2289 Standard_Real aTOut, aDist;
2290 Standard_Integer iErr = myContext->ComputeVE(aV, aEOr, aTOut, aDist, myFuzzyValue);
2292 aPave[i].SetParameter(aTOut);
2295 // Unable to project - set the parameter of the closest boundary
2296 const TopoDS_Vertex& aV1 = TopoDS::Vertex(myDS->Shape(aPB2->Pave1().Index()));
2297 const TopoDS_Vertex& aV2 = TopoDS::Vertex(myDS->Shape(aPB2->Pave2().Index()));
2299 gp_Pnt aP = BRep_Tool::Pnt(aV);
2300 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
2301 gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
2303 Standard_Real aDist1 = aP.SquareDistance(aP1);
2304 Standard_Real aDist2 = aP.SquareDistance(aP2);
2306 aPave[i].SetParameter(aDist1 < aDist2 ? aPB2->Pave1().Parameter() : aPB2->Pave2().Parameter());
2311 if (aPave[1].Parameter() < aPave[0].Parameter()) {
2312 BOPDS_Pave aPaveTmp = aPave[0];
2313 aPave[0] = aPave[1];
2314 aPave[1] = aPaveTmp;
2317 aPB2n->SetPave1(aPave[0]);
2318 aPB2n->SetPave2(aPave[1]);
2321 aPB2n->SetEdge(aPBValue->Edge());
2322 aPB2n->SetOriginalEdge(nE);
2323 aCB->AddPaveBlock(aPB2n);
2324 myDS->SetCommonBlock(aPB2n, aCB);
2325 myDS->ChangePaveBlocks(nE).Append(aPB2n);
2327 aCB->SetFaces(aFaces);
2329 const Handle(BOPDS_PaveBlock)& aPBNew = aCB->PaveBlocks().First();
2330 aLPBNew.Append(aPBNew);
2336 nE = aPBf->OriginalEdge();
2337 BOPDS_ListOfPaveBlock& aLPBE = myDS->ChangePaveBlocks(nE);
2338 aIt.Initialize(aLPB);
2339 for (; aIt.More(); aIt.Next()) {
2345 Standard_Boolean bIn1, bIn2;
2347 bIn1 = aMPBOn1.Contains(aPBf) || aMPBIn1.Contains(aPBf);
2348 bIn2 = aMPBOn2.Contains(aPBf) || aMPBIn2.Contains(aPBf);
2354 // 3. Check new pave blocks for coincidence
2355 // with the opposite face.
2356 // In case of coincidence create common blocks
2357 Standard_Integer nF;
2359 nF = bIn1 ? nF2 : nF1;
2360 const TopoDS_Face& aF = *(TopoDS_Face*)&myDS->Shape(nF);
2361 BOPDS_IndexedMapOfPaveBlock& aMPBIn = bIn1 ? aMPBIn2 : aMPBIn1;
2363 aIt.Initialize(aLPB);
2364 for (; aIt.More(); aIt.Next()) {
2365 Handle(BOPDS_PaveBlock)& aPBChangeValue = aIt.ChangeValue();
2366 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPBChangeValue->Edge());
2368 IntTools_EdgeFace anEF;
2371 anEF.SetFuzzyValue(myFuzzyValue);
2372 anEF.SetRange(aPBChangeValue->Pave1().Parameter(), aPBChangeValue->Pave2().Parameter());
2373 anEF.SetContext(myContext);
2376 const IntTools_SequenceOfCommonPrts& aCPrts=anEF.CommonParts();
2377 if (aCPrts.Length() == 1) {
2378 Standard_Boolean bCoinc = (aCPrts(1).Type() == TopAbs_EDGE);
2381 aCB = myDS->CommonBlock(aPBChangeValue);
2383 aCB = new BOPDS_CommonBlock;
2384 aCB->AddPaveBlock(aPBChangeValue);
2385 myDS->SetCommonBlock(aPBChangeValue, aCB);
2389 aMPBIn.Add(aPBChangeValue);
2394 //=======================================================================
2395 // function: PutClosingPaveOnCurve
2397 //=======================================================================
2398 void BOPAlgo_PaveFiller::PutClosingPaveOnCurve(BOPDS_Curve& aNC)
2400 Standard_Boolean bIsClosed, bHasBounds, bAdded;
2401 Standard_Integer nVC, j;
2402 Standard_Real aT[2], aTC, dT, aTx;
2405 BOPDS_ListIteratorOfListOfPave aItLP;
2407 const IntTools_Curve& aIC=aNC.Curve();
2408 const Handle(Geom_Curve)& aC3D=aIC.Curve();
2413 bIsClosed=IntTools_Tools::IsClosed(aC3D);
2418 bHasBounds=aIC.HasBounds ();
2423 bAdded=Standard_False;
2424 dT=Precision::PConfusion();
2425 aIC.Bounds (aT[0], aT[1], aP[0], aP[1]);
2427 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
2428 BOPDS_ListOfPave& aLP=aPB->ChangeExtPaves();
2430 aItLP.Initialize(aLP);
2431 for (; aItLP.More() && !bAdded; aItLP.Next()) {
2432 const BOPDS_Pave& aPC=aItLP.Value();
2434 aTC=aPC.Parameter();
2436 for (j=0; j<2; ++j) {
2437 if (fabs(aTC-aT[j]) < dT) {
2438 aTx=(!j) ? aT[1] : aT[0];
2440 aPVx.SetParameter(aTx);
2443 bAdded=Standard_True;
2449 //=======================================================================
2450 //function : PreparePostTreatFF
2452 //=======================================================================
2453 void BOPAlgo_PaveFiller::PreparePostTreatFF
2454 (const Standard_Integer aInt,
2455 const Standard_Integer aCur,
2456 const Handle(BOPDS_PaveBlock)& aPB,
2457 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
2458 BOPCol_DataMapOfShapeInteger& aMVI,
2459 BOPDS_ListOfPaveBlock& aLPBC)
2461 Standard_Integer nV1, nV2;
2465 aPB->Indices(nV1, nV2);
2466 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
2467 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
2468 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
2469 // Keep info for post treatment
2470 BOPDS_CoupleOfPaveBlocks aCPB;
2471 aCPB.SetIndexInterf(aInt);
2472 aCPB.SetIndex(aCur);
2473 aCPB.SetPaveBlock1(aPB);
2475 aMSCPB.Add(aE, aCPB);
2476 aMVI.Bind(aV1, nV1);
2477 aMVI.Bind(aV2, nV2);
2480 //=======================================================================
2481 //function : CheckPlanes
2483 //=======================================================================
2484 Standard_Boolean BOPAlgo_PaveFiller::CheckPlanes
2485 (const Standard_Integer nF1,
2486 const Standard_Integer nF2)const
2488 Standard_Boolean bToIntersect;
2489 Standard_Integer i, nV2, iCnt;
2490 BOPCol_MapIteratorOfMapOfInteger aIt;
2492 bToIntersect=Standard_False;
2494 const BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
2495 const BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
2497 const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
2498 const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
2501 for (i=0; (i<2 && !bToIntersect); ++i) {
2502 const BOPCol_MapOfInteger& aMV2=(!i) ? aFI2.VerticesIn()
2503 : aFI2.VerticesOn();
2505 aIt.Initialize(aMV2);
2506 for (; aIt.More(); aIt.Next()) {
2508 if (aMVIn1.Contains(nV2) || aMVOn1.Contains(nV2)) {
2511 bToIntersect=!bToIntersect;
2518 return bToIntersect;
2520 //=======================================================================
2521 //function : UpdatePaveBlocks
2523 //=======================================================================
2524 void BOPAlgo_PaveFiller::UpdatePaveBlocks
2525 (const BOPCol_DataMapOfIntegerInteger& aDMNewSD)
2527 if (aDMNewSD.IsEmpty()) {
2531 Standard_Integer nSp, aNbPBP, nV[2], i, j;
2532 Standard_Real aT[2];
2533 Standard_Boolean bCB, bRebuild;
2534 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
2535 BOPDS_MapOfPaveBlock aMPB;
2536 BOPCol_MapOfInteger aMicroEdges;
2538 BOPDS_ListOfPaveBlock anAllPBs;
2540 // Get pave blocks of section edges
2541 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
2542 Standard_Integer aNbFF = aFFs.Extent();
2543 for (i = 0; i < aNbFF; ++i)
2545 const BOPDS_InterfFF& aFF = aFFs(i);
2546 const BOPDS_VectorOfCurve& aVNC = aFF.Curves();
2547 Standard_Integer aNbC = aVNC.Extent();
2548 for (j = 0; j < aNbC; ++j)
2550 const BOPDS_Curve& aNC = aVNC(j);
2551 const BOPDS_ListOfPaveBlock& aLPBC = aNC.PaveBlocks();
2552 aItPB.Initialize(aLPBC);
2553 for (; aItPB.More(); aItPB.Next())
2554 anAllPBs.Append(aItPB.Value());
2558 // Get pave blocks from the pool
2559 BOPDS_VectorOfListOfPaveBlock& aPBP = myDS->ChangePaveBlocksPool();
2560 aNbPBP = aPBP.Extent();
2561 for (i = 0; i < aNbPBP; ++i) {
2562 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
2563 aItPB.Initialize(aLPB);
2564 for (; aItPB.More(); aItPB.Next())
2565 anAllPBs.Append(aItPB.Value());
2568 // Process all pave blocks
2569 aItPB.Initialize(anAllPBs);
2570 for (; aItPB.More(); aItPB.Next())
2572 Handle(BOPDS_PaveBlock) aPB = aItPB.Value();
2573 const Handle(BOPDS_CommonBlock)& aCB = myDS->CommonBlock(aPB);
2574 bCB = !aCB.IsNull();
2576 aPB = aCB->PaveBlock1();
2579 if (aMPB.Add(aPB)) {
2580 bRebuild = Standard_False;
2581 aPB->Indices(nV[0], nV[1]);
2582 aPB->Range(aT[0], aT[1]);
2583 // remember the fact if the edge had different vertices before substitution
2584 Standard_Boolean wasRegularEdge = (nV[0] != nV[1]);
2586 for (j = 0; j < 2; ++j) {
2587 if (aDMNewSD.IsBound(nV[j])) {
2590 nV[j] = aDMNewSD.Find(nV[j]);
2591 aPave.SetIndex(nV[j]);
2592 aPave.SetParameter(aT[j]);
2594 bRebuild = Standard_True;
2596 aPB->SetPave1(aPave);
2599 aPB->SetPave2(aPave);
2605 Standard_Boolean isDegEdge = myDS->ShapeInfo(aPB->Edge()).HasFlag();
2606 if (wasRegularEdge && !isDegEdge && nV[0] == nV[1]) {
2607 // now edge has the same vertex on both ends;
2608 // check if it is not a regular closed curve.
2609 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(aPB->Edge()));
2610 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV[0]));
2611 Standard_Real aLength = IntTools::Length(aE);
2612 Standard_Real aTolV = BRep_Tool::Tolerance(aV);
2613 if (aLength <= aTolV * 2.) {
2614 // micro edge, so mark it for removal
2615 aMicroEdges.Add(aPB->Edge());
2619 nSp = SplitEdge(aPB->Edge(), nV[0], aT[0], nV[1], aT[1]);
2625 }// if (aMPB.Add(aPB)) {
2626 }// for (; aItPB.More(); aItPB.Next()) {
2629 if (aMicroEdges.Extent())
2630 RemovePaveBlocks(aMicroEdges);
2632 //=======================================================================
2633 //function : RemovePaveBlocks
2635 //=======================================================================
2636 void BOPAlgo_PaveFiller::RemovePaveBlocks(const BOPCol_MapOfInteger theEdges)
2638 // Remove all pave blocks referring to input edges:
2640 // 1. from the Pave Blocks Pool
2641 BOPDS_VectorOfListOfPaveBlock& aPBP = myDS->ChangePaveBlocksPool();
2642 Standard_Integer aNbPBP = aPBP.Extent(), i;
2643 for (i = 0; i < aNbPBP; ++i) {
2644 BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
2646 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
2647 while (aItPB.More()) {
2648 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
2649 if (theEdges.Contains(aPB->Edge()))
2656 // 2. from Face Info and section curves
2657 BOPCol_MapOfInteger aMPassed;
2658 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
2659 Standard_Integer aNbFF = aFFs.Extent(), j;
2660 for (i = 0; i < aNbFF; ++i) {
2661 BOPDS_InterfFF& aFF = aFFs(i);
2662 Standard_Integer nF1, nF2;
2663 aFF.Indices(nF1, nF2);
2665 // rebuild pave block maps of face info
2666 for (j = 0; j < 2; j++) {
2667 Standard_Integer nF = (j == 0 ? nF1 : nF2);
2668 if (!aMPassed.Add(nF))
2670 BOPDS_FaceInfo& aFI = myDS->ChangeFaceInfo(nF);
2671 BOPDS_IndexedMapOfPaveBlock* aIMPB[] = { &aFI.ChangePaveBlocksIn(),
2672 &aFI.ChangePaveBlocksOn(), &aFI.ChangePaveBlocksSc() };
2673 for (Standard_Integer k = 0; k < 3; k++) {
2674 Standard_Integer aNbPB = aIMPB[k]->Extent(), m;
2675 for (m = 1; m <= aNbPB; ++m) {
2676 const Handle(BOPDS_PaveBlock)& aPB = aIMPB[k]->FindKey(m);
2677 if (theEdges.Contains(aPB->Edge()))
2681 BOPDS_IndexedMapOfPaveBlock aMPBCopy = *aIMPB[k];
2683 for (m = 1; m <= aNbPB; ++m) {
2684 const Handle(BOPDS_PaveBlock)& aPB = aMPBCopy(m);
2685 if (!theEdges.Contains(aPB->Edge()))
2691 // remove from Section pave blocks
2692 BOPDS_VectorOfCurve& aVNC = aFF.ChangeCurves();
2693 Standard_Integer aNbC = aVNC.Extent();
2694 for (j = 0; j < aNbC; ++j) {
2695 BOPDS_Curve& aNC = aVNC(j);
2696 BOPDS_ListOfPaveBlock& aLPB = aNC.ChangePaveBlocks();
2697 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
2698 while (aItPB.More()) {
2699 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
2700 if (theEdges.Contains(aPB->Edge()))
2708 //=======================================================================
2709 //function : ToleranceFF
2710 //purpose : Computes the TolFF according to the tolerance value and
2711 // types of the faces.
2712 //=======================================================================
2713 Standard_Real ToleranceFF(const BRepAdaptor_Surface& aBAS1,
2714 const BRepAdaptor_Surface& aBAS2)
2716 Standard_Real aTol1 = aBAS1.Tolerance();
2717 Standard_Real aTol2 = aBAS2.Tolerance();
2718 Standard_Real aTolFF = Max(aTol1, aTol2);
2720 Standard_Boolean isAna1, isAna2;
2721 isAna1 = (aBAS1.GetType() == GeomAbs_Plane ||
2722 aBAS1.GetType() == GeomAbs_Cylinder ||
2723 aBAS1.GetType() == GeomAbs_Cone ||
2724 aBAS1.GetType() == GeomAbs_Sphere ||
2725 aBAS1.GetType() == GeomAbs_Torus);
2727 isAna2 = (aBAS2.GetType() == GeomAbs_Plane ||
2728 aBAS2.GetType() == GeomAbs_Cylinder ||
2729 aBAS2.GetType() == GeomAbs_Cone ||
2730 aBAS2.GetType() == GeomAbs_Sphere ||
2731 aBAS2.GetType() == GeomAbs_Torus);
2733 if (!isAna1 || !isAna2) {
2734 aTolFF = Max(aTolFF, 5.e-6);
2738 //=======================================================================
2739 //function : UpdateBlocksWithSharedVertices
2741 //=======================================================================
2742 void BOPAlgo_PaveFiller::UpdateBlocksWithSharedVertices()
2744 if (!myNonDestructive) {
2748 Standard_Integer aNbFF;
2750 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
2751 aNbFF=aFFs.Extent();
2756 Standard_Boolean bOnCurve, bHasShapeSD;
2757 Standard_Integer i, nF1, nF2, aNbC, j, nV, nVSD;
2758 Standard_Real aTolV;
2759 BOPCol_MapOfInteger aMF;
2761 for (i=0; i<aNbFF; ++i) {
2762 BOPDS_InterfFF& aFF=aFFs(i);
2764 BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
2770 aFF.Indices(nF1, nF2);
2773 myDS->UpdateFaceInfoOn(nF1);
2776 myDS->UpdateFaceInfoOn(nF2);
2779 // Collect old vertices that are shared for nF1, nF2 ->aMI;
2780 BOPCol_MapOfInteger aMI;
2781 BOPCol_MapIteratorOfMapOfInteger aItMI;
2783 BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
2784 BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
2786 const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
2787 const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
2788 const BOPCol_MapOfInteger& aMVOn2=aFI2.VerticesOn();
2789 const BOPCol_MapOfInteger& aMVIn2=aFI2.VerticesIn();
2791 for (j=0; j<2; ++j) {
2792 const BOPCol_MapOfInteger& aMV1=(!j) ? aMVOn1 : aMVIn1;
2793 aItMI.Initialize(aMV1);
2794 for (; aItMI.More(); aItMI.Next()) {
2796 if (myDS->IsNewShape(nV)) {
2799 if (aMVOn2.Contains(nV) || aMVIn2.Contains(nV)) {
2805 // Try to put vertices aMI on curves
2806 for (j=0; j<aNbC; ++j) {
2807 BOPDS_Curve& aNC=aVC.ChangeValue(j);
2808 Standard_Real aTolR3D = Max(aNC.Tolerance(), aNC.TangentialTolerance());
2810 aItMI.Initialize(aMI);
2811 for (; aItMI.More(); aItMI.Next()) {
2814 bHasShapeSD=myDS->HasShapeSD(nV, nVSD);
2819 bOnCurve=EstimatePaveOnCurve(nV, aNC, aTolR3D);
2824 const TopoDS_Vertex& aV=*((TopoDS_Vertex *)&myDS->Shape(nV));
2825 aTolV=BRep_Tool::Tolerance(aV);
2827 UpdateVertex(nV, aTolV);
2829 }//for (j=0; j<aNbC; ++j) {
2830 }//for (i=0; i<aNbFF; ++i) {
2832 UpdateCommonBlocksWithSDVertices();
2834 //=======================================================================
2835 //function : EstimatePaveOnCurve
2837 //=======================================================================
2838 Standard_Boolean BOPAlgo_PaveFiller::EstimatePaveOnCurve
2839 (const Standard_Integer nV,
2840 const BOPDS_Curve& aNC,
2841 const Standard_Real aTolR3D)
2843 Standard_Boolean bIsVertexOnLine;
2846 const TopoDS_Vertex& aV=*((TopoDS_Vertex *)&myDS->Shape(nV));
2847 const IntTools_Curve& aIC=aNC.Curve();
2849 bIsVertexOnLine=myContext->IsVertexOnLine(aV, aIC, aTolR3D, aT);
2850 return bIsVertexOnLine;
2853 //=======================================================================
2854 //function : CorrectToleranceOfSE
2856 //=======================================================================
2857 void BOPAlgo_PaveFiller::CorrectToleranceOfSE()
2859 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
2860 NCollection_IndexedDataMap<Standard_Integer,BOPDS_ListOfPaveBlock> aMVIPBs;
2861 BOPCol_MapOfInteger aMVIToReduce;
2862 // Fence map to avoid repeated checking of the same edge
2863 BOPDS_MapOfPaveBlock aMPB;
2865 // 1. iterate on all sections F-F
2866 Standard_Integer aNb = aFFs.Extent(), i;
2867 for (i = 0; i < aNb; ++i) {
2868 BOPDS_InterfFF& aFF = aFFs(i);
2870 BOPDS_VectorOfCurve& aVNC = aFF.ChangeCurves();
2871 Standard_Integer aNbC = aVNC.Extent(), k;
2872 for (k = 0; k < aNbC; ++k) {
2873 BOPDS_Curve& aNC = aVNC(k);
2874 BOPDS_ListOfPaveBlock& aLPB = aNC.ChangePaveBlocks();
2875 BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPB);
2876 for (; aItLPB.More(); ) {
2877 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
2878 Standard_Integer nE;
2879 if (!aPB->HasEdge(nE)) {
2880 aLPB.Remove(aItLPB);
2884 if (!aMPB.Add(aPB)) {
2889 Standard_Boolean bIsReduced = Standard_False;
2890 if (aPB->OriginalEdge() < 0) {
2891 // It is possible that due to small angle between faces the
2892 // common zone between faces can be large and the tangential
2893 // tolerance of the curve will be large as well.
2894 // Here we're trying to reduce the tolerance of the section
2895 // edge using the valid tolerance of the edge.
2896 // Note, that if the pave block has created common block with
2897 // other edges its valid tolerance could have been changed to
2898 // cover all edges in common block (see PostTreatFF() method).
2899 Standard_Real aTolC = aNC.Tolerance();
2900 Standard_Real aTolTang = aNC.TangentialTolerance();
2901 if (aTolC < aTolTang) {
2902 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(nE));
2903 Standard_Real aTolE = BRep_Tool::Tolerance(aE);
2904 if (aTolC < aTolE) {
2905 // reduce edge tolerance
2906 reinterpret_cast<BRep_TEdge*>(aE.TShape().operator->())->Tolerance(aTolC);
2907 bIsReduced = Standard_True;
2912 // fill in the map vertex index - pave blocks
2913 for (Standard_Integer j=0; j < 2; j++) {
2914 Standard_Integer nV = (j == 0 ? aPB->Pave1().Index() : aPB->Pave2().Index());
2915 myDS->HasShapeSD(nV, nV);
2916 BOPDS_ListOfPaveBlock *pPBList = aMVIPBs.ChangeSeek(nV);
2918 pPBList = &aMVIPBs.ChangeFromIndex(aMVIPBs.Add(nV, BOPDS_ListOfPaveBlock()));
2920 pPBList->Append(aPB);
2922 aMVIToReduce.Add(nV);
2930 if (aMVIToReduce.IsEmpty()) {
2934 // 2. try to reduce tolerances of connected vertices
2935 // 2.1 find all other edges containing these connected vertices to avoid
2936 // reducing the tolerance to the value less than the tolerances of edges,
2937 // i.e. minimal tolerance for the vertex is the max tolerance of the
2938 // edges containing this vertex
2939 BOPCol_DataMapOfIntegerReal aMVITol;
2940 BOPDS_VectorOfListOfPaveBlock& aPBP = myDS->ChangePaveBlocksPool();
2941 aNb = aPBP.Extent();
2942 for (i = 0; i < aNb; ++i) {
2943 const BOPDS_ListOfPaveBlock& aLPB = aPBP(i);
2944 BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPB);
2945 for (; aItLPB.More(); aItLPB.Next()) {
2946 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
2947 Standard_Integer nE;
2948 if (!aPB->HasEdge(nE)) {
2951 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(nE));
2952 Standard_Real aTolE = BRep_Tool::Tolerance(aE);
2954 Standard_Integer nV[2];
2955 aPB->Indices(nV[0], nV[1]);
2957 for (Standard_Integer j = 0; j < 2; j++) {
2958 if (aMVIToReduce.Contains(nV[j])) {
2959 Standard_Real *aMaxTol = aMVITol.ChangeSeek(nV[j]);
2961 aMVITol.Bind(nV[j], aTolE);
2963 else if (aTolE > *aMaxTol) {
2971 // 2.2 reduce tolerances if possible
2972 aNb = aMVIPBs.Extent();
2973 for (i = 1; i <= aNb; ++i) {
2974 Standard_Integer nV = aMVIPBs.FindKey(i);
2975 if (!aMVIToReduce.Contains(nV)) {
2979 const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV));
2980 Standard_Real aTolV = BRep_Tool::Tolerance(aV);
2981 Standard_Real aMaxTol = aMVITol.IsBound(nV) ? aMVITol.Find(nV) : 0.;
2982 // it makes no sense to compute the real tolerance if it is
2983 // impossible to reduce the tolerance at least 0.1% of the current value
2984 if (aTolV - aMaxTol < 0.001 * aTolV) {
2988 // compute the maximal distance from the vertex to the adjacent edges
2989 gp_Pnt aP = BRep_Tool::Pnt(aV);
2991 // Avoid repeated checks
2992 BOPDS_MapOfPaveBlock aMPBFence;
2994 const BOPDS_ListOfPaveBlock& aLPB = aMVIPBs.FindFromIndex(i);
2995 BOPDS_ListIteratorOfListOfPaveBlock aItLPB(aLPB);
2996 for (; aItLPB.More(); aItLPB.Next()) {
2997 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
2998 if (!aMPBFence.Add(aPB)) {
3001 Standard_Integer nE = aPB->Edge();
3002 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(nE));
3003 BRepAdaptor_Curve aC(aE);
3004 for (Standard_Integer iPave = 0; iPave < 2; ++iPave) {
3005 const BOPDS_Pave& aPave = !iPave ? aPB->Pave1() : aPB->Pave2();
3006 Standard_Integer nVSD = aPave.Index();
3007 myDS->HasShapeSD(nVSD, nVSD);
3012 gp_Pnt aPonE = aC.Value(aPave.Parameter());
3013 Standard_Real aDist = aP.Distance(aPonE);
3014 aDist += BRep_Tool::Tolerance(aE);
3015 if (aDist > aMaxTol) {
3021 if (aMaxTol < aTolV) {
3022 reinterpret_cast<BRep_TVertex*>(aV.TShape().operator->())->Tolerance(aMaxTol);
3027 //=======================================================================
3028 //function : PutSEInOtherFaces
3030 //=======================================================================
3031 void BOPAlgo_PaveFiller::PutSEInOtherFaces()
3033 // Try to intersect each section edge with the faces
3034 // not participated in its creation
3036 // 1. Get all section edges
3037 BOPDS_IndexedMapOfPaveBlock aMPBScAll;
3039 BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
3040 Standard_Integer i, j, aNbFF = aFFs.Extent();
3042 for (i = 0; i < aNbFF; ++i) {
3043 const BOPDS_VectorOfCurve& aVNC = aFFs(i).Curves();
3044 Standard_Integer aNbC = aVNC.Extent();
3045 for (j = 0; j < aNbC; ++j) {
3046 const BOPDS_ListOfPaveBlock& aLPBC = aVNC(j).PaveBlocks();
3047 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPBC);
3048 for (; aItPB.More(); aItPB.Next()) {
3049 aMPBScAll.Add(aItPB.Value());
3054 Standard_Integer aNbPBSc = aMPBScAll.Extent();
3056 // 2. Loop for all faces and check each section curve
3057 Standard_Integer aNbS = myDS->NbSourceShapes();
3058 for (i = 0; i < aNbS; ++i) {
3059 const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(i);
3060 if (aSI.ShapeType() != TopAbs_FACE) {
3064 const TopoDS_Face& aF = (*(TopoDS_Face*)(&aSI.Shape()));
3065 BOPDS_FaceInfo& aFI = myDS->ChangeFaceInfo(i);
3067 // IN edges to add new ones
3068 BOPDS_IndexedMapOfPaveBlock& aMFPBIn = aFI.ChangePaveBlocksIn();
3069 // Section edges to check the participation of the face
3070 const BOPDS_IndexedMapOfPaveBlock& aMFPBSc = aFI.PaveBlocksSc();
3072 // Get vertices of the face to check that vertices of the
3073 // processed section edge belong to the face
3074 BOPCol_MapOfInteger aMFVerts;
3075 // Get vertices from ON, IN and Sc pave blocks of the face
3076 for (j = 0; j < 3; ++j) {
3077 const BOPDS_IndexedMapOfPaveBlock& aMPB =
3078 !j ? aFI.PaveBlocksOn() : (j == 1 ? aMFPBIn : aMFPBSc);
3079 Standard_Integer aNbPB = aMPB.Extent();
3080 for (Standard_Integer k = 1; k <= aNbPB; ++k) {
3081 const Handle(BOPDS_PaveBlock)& aPB = aMPB(k);
3082 aMFVerts.Add(aPB->Pave1().Index());
3083 aMFVerts.Add(aPB->Pave2().Index());
3086 // Add ON, IN and Sc vertices of the face
3087 for (j = 0; j < 3; ++j) {
3088 const BOPCol_MapOfInteger& aMFV = !j ? aFI.VerticesOn() :
3089 (j == 1 ? aFI.VerticesIn() : aFI.VerticesSc());
3090 BOPCol_MapIteratorOfMapOfInteger aItMI(aMFV);
3091 for (; aItMI.More(); aItMI.Next()) {
3092 aMFVerts.Add(aItMI.Value());
3096 // Check each section edge for possible belonging to the face
3097 for (j = 1; j <= aNbPBSc; ++j) {
3098 const Handle(BOPDS_PaveBlock)& aPB = aMPBScAll(j);
3099 if (aMFPBSc.Contains(aPB)) {
3103 // Both vertices of the section edge should belong to the face
3104 if (!aMFVerts.Contains(aPB->Pave1().Index()) ||
3105 !aMFVerts.Contains(aPB->Pave2().Index())) {
3109 // Perform intersection
3110 const TopoDS_Edge& aE = TopoDS::Edge(myDS->Shape(aPB->Edge()));
3112 IntTools_EdgeFace anEFInt;
3113 anEFInt.SetEdge(aE);
3114 anEFInt.SetFace(aF);
3115 anEFInt.SetFuzzyValue(myFuzzyValue);
3116 anEFInt.SetRange(aPB->Pave1().Parameter(), aPB->Pave2().Parameter());
3117 anEFInt.SetContext(myContext);
3118 anEFInt.UseQuickCoincidenceCheck(Standard_True);
3121 const IntTools_SequenceOfCommonPrts& aCPrts = anEFInt.CommonParts();
3122 if ((aCPrts.Length() == 1) && (aCPrts(1).Type() == TopAbs_EDGE)) {
3123 Handle(BOPDS_CommonBlock) aCB;
3124 if (myDS->IsCommonBlock(aPB)) {
3125 aCB = myDS->CommonBlock(aPB);
3128 aCB = new BOPDS_CommonBlock;
3129 aCB->AddPaveBlock(aPB);