1 // File: NMTTools_PaveFiller_6.cxx
2 // Created: Fri Dec 19 10:27:31 2003
3 // Author: Peter KURNEV
6 #include <NMTTools_PaveFiller.ixx>
8 #include <Precision.hxx>
10 #include <TColStd_IndexedMapOfInteger.hxx>
11 #include <TColStd_MapOfInteger.hxx>
13 #include <Geom2d_Curve.hxx>
14 #include <Geom_TrimmedCurve.hxx>
16 #include <GeomAdaptor_Curve.hxx>
17 #include <BndLib_Add3dCurve.hxx>
19 #include <TopoDS_Face.hxx>
21 #include <TopoDS_Compound.hxx>
25 #include <BRep_Builder.hxx>
26 #include <BRep_Tool.hxx>
27 #include <BRepBndLib.hxx>
29 #include <TopTools_IndexedMapOfShape.hxx>
31 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
32 #include <BOPTColStd_IndexedDataMapOfIntegerInteger.hxx>
34 #include <BooleanOperations_IndexedDataMapOfShapeInteger.hxx>
35 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
36 #include <BooleanOperations_OnceExplorer.hxx>
37 #include <BooleanOperations_ShapesDataStructure.hxx>
39 #include <IntTools_SequenceOfPntOn2Faces.hxx>
40 #include <IntTools_SequenceOfCurves.hxx>
41 #include <IntTools_FaceFace.hxx>
42 #include <IntTools_Tools.hxx>
44 #include <BOPTools_CArray1OfSSInterference.hxx>
45 #include <BOPTools_ListIteratorOfListOfInterference.hxx>
46 #include <BOPTools_CArray1OfInterferenceLine.hxx>
47 #include <BOPTools_InterferenceLine.hxx>
48 #include <BOPTools_ListOfInterference.hxx>
49 #include <BOPTools_Interference.hxx>
50 #include <BOPTools_InterferencePool.hxx>
51 #include <BOPTools_SSInterference.hxx>
52 #include <BOPTools_ListOfPaveBlock.hxx>
53 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
54 #include <BOPTools_PaveBlock.hxx>
55 #include <BOPTools_ListIteratorOfListOfPave.hxx>
56 #include <BOPTools_Tools.hxx>
57 #include <BOPTools_PaveBlockIterator.hxx>
58 #include <BOPTools_Tools2D.hxx>
60 #include <NMTDS_ShapesDataStructure.hxx>
61 #include <NMTTools_IndexedDataMapOfShapePaveBlock.hxx>
62 #include <NMTTools_CommonBlockAPI.hxx>
63 #include <Geom2d_Curve.hxx>
64 #include <NMTTools_Tools.hxx>
65 #include <BRepLib.hxx>
66 #include <Geom2d_TrimmedCurve.hxx>
69 Standard_Boolean IsPairFound(const Standard_Integer nF1,
70 const Standard_Integer nF2,
71 BOPTools_InterferencePool* myIntrPool,
72 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWhat,
73 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWith);
76 void FMapWhat(const Standard_Integer nF,
77 BOPTools_InterferencePool* myIntrPool,
78 TColStd_IndexedMapOfInteger& aMapWhat);
80 void FMapWith(const Standard_Integer nF,
81 BOPTools_InterferencePool* myIntrPool,
82 TColStd_IndexedMapOfInteger& aMapWith);
84 Standard_Boolean IsFound(const TColStd_IndexedMapOfInteger& aMapWhat,
85 const TColStd_IndexedMapOfInteger& aMapWith);
87 //=======================================================================
88 // function: PerformFF
90 //=======================================================================
91 void NMTTools_PaveFiller::PerformFF()
93 myIsDone=Standard_False;
95 Standard_Boolean bIsFound, bJustAdd, bIsComputed;
96 Standard_Integer n1, n2, anIndexIn, nF1, nF2, aBlockLength, aNbFFs;
97 Standard_Boolean bToApproxC3d, bToApproxC2dOnS1, bToApproxC2dOnS2, bIsDone;
98 Standard_Integer aNbCurves, aNbPoints;
99 Standard_Real anApproxTol, aTolR3D, aTolR2D;
100 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMapWhat, aMapWith;
101 IntTools_SequenceOfPntOn2Faces aPnts;
102 IntTools_SequenceOfCurves aCvs;
103 BooleanOperations_KindOfInterference aTypeFF=BooleanOperations_SurfaceSurface;
105 BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
107 // F/F Interferences [BooleanOperations_SurfaceSurface]
108 myDSIt.Initialize(TopAbs_FACE, TopAbs_FACE);
110 // BlockLength correction
111 aNbFFs=ExpectedPoolLength();
112 aBlockLength=aFFs.BlockLength();
113 if (aNbFFs > aBlockLength) {
114 aFFs.SetBlockLength(aNbFFs);
117 for (; myDSIt.More(); myDSIt.Next()) {
118 myDSIt.Current(n1, n2, bJustAdd);
120 bIsComputed=myIntrPool->IsComputed(n1, n2);
135 bIsFound=IsPairFound(nF1, nF2, myIntrPool, aMapWhat, aMapWith);
139 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
142 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
143 anIndexIn=aFFs.Append(anInterf);
144 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
149 const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
150 const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
153 bToApproxC3d = mySectionAttribute.Approximation();
154 bToApproxC2dOnS1 = mySectionAttribute.PCurveOnS1();
155 bToApproxC2dOnS2 = mySectionAttribute.PCurveOnS2();
159 IntTools_FaceFace aFF;
161 aFF.SetParameters (bToApproxC3d, bToApproxC2dOnS1,
162 bToApproxC2dOnS2, anApproxTol);
164 aFF.Perform(aF1, aF2);
166 bIsDone=aFF.IsDone();
170 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
173 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
174 anIndexIn=aFFs.Append(anInterf);
175 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
180 aTolR3D=aFF.TolReached3d();
181 aTolR2D=aFF.TolReached2d();
182 if (aTolR3D < 1.e-7){
186 aFF.PrepareLines3D();
188 const IntTools_SequenceOfCurves& aCvsX=aFF.Lines();
189 const IntTools_SequenceOfPntOn2Faces& aPntsX=aFF.Points();
191 aNbCurves=aCvsX.Length();
192 aNbPoints=aPntsX.Length();
194 if (!aNbCurves && !aNbPoints) {
195 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
196 anIndexIn=aFFs.Append(anInterf);
197 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
202 BOPTools_SSInterference anInterf (nF1, nF2, aTolR3D, aTolR2D, aCvsX, aPntsX);
203 anIndexIn=aFFs.Append(anInterf);
204 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
207 }// for (; myDSIt.More(); myDSIt.Next())
209 myIsDone=Standard_True;
211 //=======================================================================
212 // function: MakeBlocks
214 //=======================================================================
215 void NMTTools_PaveFiller::MakeBlocks()
217 myIsDone=Standard_False;
219 Standard_Boolean bIsExistingPaveBlock, bIsValidIn2D;
220 Standard_Integer i, aNbFFs, nF1, nF2, aBid=0;
221 Standard_Integer nV1, nV2, j, aNbCurves;
222 Standard_Real aTolR3D, aTol2D, aT1, aT2, aTolPPC=Precision::PConfusion();
223 TColStd_MapOfInteger aMap;
224 NMTTools_IndexedDataMapOfShapePaveBlock aMEPB;
225 BooleanOperations_IndexedDataMapOfShapeInteger aMapEI;
227 BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
229 // 1. Produce Section Edges from intersection curves
230 // between each pair of faces
232 aNbFFs=aFFs.Extent();
233 for (i=1; i<=aNbFFs; ++i) {
234 BOPTools_SSInterference& aFFi=aFFs(i);
237 aFFi.Indices(nF1, nF2);
238 const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
239 const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
241 // Add blocks that are existing ones for this FF-interference
242 BOPTools_ListOfPaveBlock aLPB;
243 RealSplitsInFace (aBid, nF1, nF2, aLPB);
244 RealSplitsInFace (aBid, nF2, nF1, aLPB);
245 RealSplitsOnFace (aBid, nF1, nF2, aLPB);
248 BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
249 for (; anIt.More(); anIt.Next()) {
250 const BOPTools_PaveBlock& aPB=anIt.Value();
251 aFFi.AppendBlock(aPB);
252 nV1=aPB.Pave1().Index();
253 nV2=aPB.Pave2().Index();
258 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
259 aNbCurves=aSCvs.Length();
264 aTolR3D=aFFi.TolR3D();
265 aTol2D=(aTolR3D < 1.e-3) ? 1.e-3 : aTolR3D;
267 BOPTools_PaveSet aPSF;
269 PrepareSetForFace (nF1, nF2, aPSF);
271 // Put Paves On Curves
272 for (j=1; j<=aNbCurves; ++j) {
273 BOPTools_Curve& aBC=aSCvs(j);
275 const IntTools_Curve& aC=aBC.Curve();
276 Handle (Geom_Curve) aC3D= aC.Curve();
278 PutPaveOnCurve (aPSF, aTolR3D, aBC);
281 // Put bounding paves on curves
282 for (j=1; j<=aNbCurves; ++j) {
283 BOPTools_Curve& aBC=aSCvs(j);
284 PutBoundPaveOnCurve (aBC, aFFi);
287 // Pave Blocks on Curves
288 for (j=1; j<=aNbCurves; ++j) {
289 BOPTools_Curve& aBC=aSCvs(j);
290 const IntTools_Curve& aIC= aBC.Curve();
291 BOPTools_PaveSet& aPaveSet=aBC.Set();
293 BOPTools_PaveBlockIterator aPBIter(0, aPaveSet);
294 for (; aPBIter.More(); aPBIter.Next()) {
295 BOPTools_PaveBlock& aPBNew=aPBIter.Value();
296 aPBNew.SetCurve(aIC);
297 aPBNew.SetFace1(nF1);
298 aPBNew.SetFace2(nF2);
300 nV1=aPBNew.Pave1().Index();
301 nV2=aPBNew.Pave2().Index();
302 aT1=aPBNew.Pave1().Param();
303 aT2=aPBNew.Pave2().Param();
305 if((nV1==nV2) && (Abs(aT2 - aT1) < aTolPPC)) {
309 bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aFFi);
310 if (bIsExistingPaveBlock) {
311 // aPBNew was (or just lays) boundary PB
314 // Checking of validity in 2D
316 bIsValidIn2D=myContext.IsValidBlockForFaces(aT1, aT2, aIC, aF1, aF2, aTol2D);
321 //aBC.AppendNewBlock(aPBNew);
326 const TopoDS_Vertex& aV1=TopoDS::Vertex(myDS->Shape(nV1));
327 const TopoDS_Vertex& aV2=TopoDS::Vertex(myDS->Shape(nV2));
329 BOPTools_Tools::MakeSectEdge (aIC, aV1, aT1, aV2, aT2, aES);
332 Standard_Real aTolR2D;
334 aTolR2D=aFFi.TolR2D();
335 Handle(Geom2d_Curve) aC2D1=aIC.FirstCurve2d();
336 Handle(Geom2d_Curve) aC2D2=aIC.SecondCurve2d();
338 NMTTools_Tools::MakePCurve(aES, aF1, aC2D1, aTolR2D);
339 NMTTools_Tools::MakePCurve(aES, aF2, aC2D2, aTolR2D);
342 aMEPB.Add(aES, aPBNew);
345 } // end of for (j=1; j<=aNbCurves; ++j)
346 }// for (i=1; i<=aNbFFs; ++i)
347 //=============================================================
349 // II. Post treatment
351 // Input data: aMEPB, aMapEI
352 // Result : section edges in myDS
354 Standard_Integer aNbSE;
356 aNbSE=aMEPB.Extent();
358 // there is nothing to do here
363 TopoDS_Compound aCompound;
365 // 1. Make compound from SE
366 aBB.MakeCompound(aCompound);
367 for (i=1; i<=aNbSE; ++i) {
368 const TopoDS_Shape& aSE=aMEPB.FindKey(i);
369 aBB.Add(aCompound, aSE);
373 // 2. Intersect SE using auxiliary Filler
374 NMTDS_ShapesDataStructure tDS;
376 tDS.SetCompositeShape(aCompound);
379 BOPTools_InterferencePool tIP(tDS);
380 NMTTools_PaveFiller tPF(tIP);
385 tPF.PerformNewVertices();
388 tPF.myPavePool.Resize (tPF.myNbEdges);
396 tPF.myCommonBlockPool.Resize (tPF.myNbEdges);
397 tPF.mySplitShapesPool.Resize (tPF.myNbEdges);
398 tPF.myPavePoolNew .Resize (tPF.myNbEdges);
400 tPF.PreparePaveBlocks(TopAbs_VERTEX, TopAbs_EDGE);
401 tPF.PreparePaveBlocks(TopAbs_EDGE, TopAbs_EDGE);
405 tPF.RefinePavePool ();
407 tPF.myPavePoolNew.Destroy();
409 tPF.MakeSplitEdges();
410 tPF.UpdateCommonBlocks();
412 // 3. Treatment of the result of intersection
414 Standard_Integer aNbOld, aNbLines, aNbPB, mV1, mV2, nE, mE, iFF;
415 TopAbs_ShapeEnum aType;
416 BOPTools_ListIteratorOfListOfPaveBlock aIt;
417 BOPTColStd_IndexedDataMapOfIntegerInteger aMNewOld;
419 const BOPTools_SplitShapesPool& aSSP=tPF.mySplitShapesPool;
420 const NMTTools_CommonBlockPool& aCBP=tPF.myCommonBlockPool;
422 aNbLines=tDS.NumberOfInsertedShapes();
423 aNbOld=tDS.NumberOfShapesOfTheObject();
425 // 3.1 Links between indices in tDS and DS (kept in aMNewOld)
427 // 3.1.1.Old vertices [ links ]
428 for (i=1; i<=aNbOld; ++i) {
429 const TopoDS_Shape& aV=tDS.Shape(i);
430 aType=aV.ShapeType();
431 if (aType!=TopAbs_VERTEX) {
435 for (j=1; j<=aNbSE; ++j) {
436 const BOPTools_PaveBlock& aPBSE=aMEPB(j);
437 nV1=aPBSE.Pave1().Index();
438 const TopoDS_Shape& aV1=myDS->Shape(nV1);
439 if (aV1.IsSame(aV)) {
440 aMNewOld.Add(i, nV1);
443 nV2=aPBSE.Pave2().Index();
444 const TopoDS_Shape& aV2=myDS->Shape(nV2);
445 if (aV2.IsSame(aV)) {
446 aMNewOld.Add(i, nV2);
452 // 3.1.2. New vertices [ links ]
453 i=tDS.NumberOfSourceShapes()+1;
454 for (; i<=aNbLines; ++i) {
455 const TopoDS_Shape& aV=tDS.Shape(i);
456 aType=aV.ShapeType();
457 if (aType!=TopAbs_VERTEX) {
461 // Insert new vertex in myDS
462 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
463 myDS->InsertShapeAndAncestorsSuccessors(aV, anASSeq);
464 nV1=myDS->NumberOfInsertedShapes();
466 aMNewOld.Add(i, nV1);
469 // 3.2. Treatment of section edges (SE)
470 for (i=1; i<=aNbOld; ++i) {
471 const TopoDS_Shape& aE=tDS.Shape(i);
472 aType=aE.ShapeType();
473 if (aType!=TopAbs_EDGE) {
477 // block of section edge that we already have for this SE
478 BOPTools_PaveBlock& aPBSE=aMEPB.ChangeFromKey(aE);
480 // Corresponding FF-interference
481 iFF=aMapEI.FindFromKey(aE);
482 BOPTools_SSInterference& aFFi=aFFs(iFF);
483 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
485 BOPTools_Curve& aBC=aSCvs(1);
487 const BOPTools_ListOfPaveBlock& aLPB=aSSP(tDS.RefEdge(i));
491 // no pave blocks -> use aPBSE and whole edge aE
492 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
494 nV1=aPBSE.Pave1().Index();
495 const TopoDS_Shape& aV1=myDS->Shape(nV1);
496 nV2=aPBSE.Pave2().Index();
497 const TopoDS_Shape& aV2=myDS->Shape(nV2);
499 anASSeq.SetNewSuccessor(nV1);
500 anASSeq.SetNewOrientation(aV1.Orientation());
501 anASSeq.SetNewSuccessor(nV2);
502 anASSeq.SetNewOrientation(aV2.Orientation());
504 myDS->InsertShapeAndAncestorsSuccessors(aE, anASSeq);
505 nE=myDS->NumberOfInsertedShapes();
508 aBC.AppendNewBlock(aPBSE);
515 const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
516 const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
518 const NMTTools_ListOfCommonBlock& aLCB=aCBP(tDS.RefEdge(i));
519 NMTTools_CommonBlockAPI aCBAPI(aLCB);
521 aIt.Initialize(aLPB);
522 for (; aIt.More(); aIt.Next()) {
523 BOPTools_PaveBlock aPB=aIt.Value();
525 if (aCBAPI.IsCommonBlock(aPB)) {
526 // it can be Common Block
527 Standard_Boolean bHasPCOnF, bFound;
528 Standard_Integer nF, k, nEOrx, nF1x, nF2x;
529 Standard_Real aTolEx, aT1x, aT2x;
530 BOPTools_ListIteratorOfListOfPaveBlock aItPBx;
532 NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB);
533 const BOPTools_ListOfPaveBlock& aLPBx=aCB.PaveBlocks();
535 aPB=aCB.PaveBlock1();
536 mE=aPB.Edge(); // index of edge in tDS
537 const TopoDS_Edge& aEx=TopoDS::Edge(tDS.Shape(mE));
538 aTolEx=BRep_Tool::Tolerance(aEx);
540 for (k=0; k<2; ++k) {
542 const TopoDS_Face& aF=TopoDS::Face(myDS->Shape(nF));
544 bHasPCOnF=BOPTools_Tools2D::HasCurveOnSurface(aEx, aF);
549 bFound=Standard_False;
550 aItPBx.Initialize(aLPBx);
551 for (; aItPBx.More(); aItPBx.Next()) {
552 BOPTools_PaveBlock& aPBx=aIt.Value();
553 nEOrx=aPBx.OriginalEdge();
554 const TopoDS_Shape& aEOrx=tDS.Shape(nEOrx);
555 BOPTools_PaveBlock& aPBSEx=aMEPB.ChangeFromKey(aEOrx);
556 aT1x=aPBSEx.Pave1().Param();
557 aT2x=aPBSEx.Pave2().Param();
558 const IntTools_Curve& aICx=aPBSEx.Curve();
564 Handle(Geom2d_Curve) aC2D1x=aICx.FirstCurve2d();
565 Handle(Geom2d_TrimmedCurve)aC2D1xT =new Geom2d_TrimmedCurve(aC2D1x, aT1x, aT2x);
566 aBB.UpdateEdge(aEx, aC2D1xT, aF, aTolEx);
572 Handle(Geom2d_Curve) aC2D2x=aICx.SecondCurve2d();
573 Handle(Geom2d_TrimmedCurve)aC2D2xT =new Geom2d_TrimmedCurve(aC2D2x, aT1x, aT2x);
574 aBB.UpdateEdge(aEx, aC2D2xT, aF, aTolEx);
580 BRepLib::SameParameter(aEx, aTolEx, Standard_True);
583 } //if (aCBAPI.IsCommonBlock(aPB))
586 mE=aPB.Edge(); // index of edge in tDS
587 const TopoDS_Shape& aSp=tDS.Shape(mE);
589 const BOPTools_Pave& aPave1=aPB.Pave1();
591 mV1=aPave1.Index(); // index in tDS
592 nV1=aMNewOld.FindFromKey(mV1); // index in myDS
593 const TopoDS_Shape& aV1=myDS->Shape(nV1);
595 const BOPTools_Pave& aPave2=aPB.Pave2();
598 nV2=aMNewOld.FindFromKey(mV2);
599 const TopoDS_Shape& aV2=myDS->Shape(nV2);
601 if (!aMNewOld.Contains(mE)) {
602 // add new SE to the myDS
603 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
605 anASSeq.SetNewSuccessor(nV1);
606 anASSeq.SetNewOrientation(aV1.Orientation());
608 anASSeq.SetNewSuccessor(nV2);
609 anASSeq.SetNewOrientation(aV2.Orientation());
611 myDS->InsertShapeAndAncestorsSuccessors(aSp, anASSeq);
612 nE=myDS->NumberOfInsertedShapes();
614 aMNewOld.Add(mE, nE);
617 nE=aMNewOld.FindFromKey(mE);
620 BOPTools_PaveBlock aPBx;
621 BOPTools_Pave aP1, aP2;
637 aBC.AppendNewBlock(aPBx);
638 }// for (; aIt.More(); aIt.Next())
639 }// for (i=1; i<=aNbOld; ++i)
641 myIsDone=Standard_True;
643 //=======================================================================
644 // function: MakePCurves
646 //=======================================================================
647 void NMTTools_PaveFiller::MakePCurves()
649 Standard_Integer i, aNb, nF1, nF2, nE;
650 TopoDS_Face aF1FWD, aF2FWD;
651 BOPTools_ListIteratorOfListOfPaveBlock anIt;
653 BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
656 for (i=1; i<=aNb; i++) {
657 BOPTools_SSInterference& aFF=aFFs(i);
658 aFF.Indices(nF1, nF2);
660 const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
661 const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
664 aF1FWD.Orientation(TopAbs_FORWARD);
666 aF2FWD.Orientation(TopAbs_FORWARD);
668 // In, On parts processing
669 const BOPTools_ListOfPaveBlock& aLPBInOn=aFF.PaveBlocks();
671 anIt.Initialize(aLPBInOn);
672 for (; anIt.More(); anIt.Next()) {
673 const BOPTools_PaveBlock& aPB=anIt.Value();
675 const TopoDS_Edge& aE=TopoDS::Edge(myDS->Shape(nE));
677 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF1FWD);
678 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF2FWD);
681 // Section Edges processing
683 Standard_Integer aNbCurves, k, aNbV;
684 Standard_Real aTolEdge, aTolR2D, aTolFact, aTolV, aTolVmax;
687 BOPTools_SequenceOfCurves& aSC=aFF.Curves();
688 aNbCurves=aSC.Length();
693 const BOPTools_Curve& aBC=aSC(1);
694 const BOPTools_ListOfPaveBlock& aLPB=aBC.NewPaveBlocks();
695 anIt.Initialize(aLPB);
696 for (; anIt.More(); anIt.Next()) {
697 const BOPTools_PaveBlock& aPB=anIt.Value();
699 const TopoDS_Edge& aE=TopoDS::Edge(myDS->Shape(nE));
701 aTolEdge=BRep_Tool::Tolerance(aE);
702 aTolR2D=aFF.TolR2D();
703 aTolFact=Max(aTolEdge, aTolR2D);
705 // Check vertices tolerances and correct them if necessary
706 // to prevent situation when TolE > TolV
708 TopTools_IndexedMapOfShape aVMap;
709 TopExp::MapShapes(aE, TopAbs_VERTEX, aVMap);
713 for (k=1; k<=aNbV; ++k) {
714 const TopoDS_Vertex& aV=TopoDS::Vertex(aVMap(k));
715 aTolV=BRep_Tool::Tolerance(aV);
716 if (aTolV>aTolVmax) {
721 if (aTolFact>aTolVmax) {
725 Standard_Real aTFirst, aTLast, aOutFirst, aOutLast, aOutTol;
726 Handle(Geom2d_Curve) aC2D1, aC2D1A, aC2D2, aC2D2A;
727 Handle(Geom_TrimmedCurve)aC3DETrim;
729 const Handle(Geom_Curve)& aC3DE=BRep_Tool::Curve(aE, aTFirst, aTLast);
730 aC3DETrim=new Geom_TrimmedCurve(aC3DE, aTFirst, aTLast);
733 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF1FWD);
734 BOPTools_Tools2D::CurveOnSurface(aE, aF1FWD, aC2D1, aOutFirst, aOutLast, aOutTol, Standard_True);
736 if (aC3DE->IsPeriodic()) {
737 BOPTools_Tools2D::AdjustPCurveOnFace(aF1FWD, aTFirst, aTLast, aC2D1, aC2D1A);
740 BOPTools_Tools2D::AdjustPCurveOnFace(aF1FWD, aC3DETrim, aC2D1, aC2D1A);
743 aBB.UpdateEdge(aE, aC2D1A, aF1FWD, aTolFact);
746 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF2FWD);
747 BOPTools_Tools2D::CurveOnSurface(aE, aF2FWD, aC2D2, aOutFirst, aOutLast, aOutTol, Standard_True);
749 if (aC3DE->IsPeriodic()) {
750 BOPTools_Tools2D::AdjustPCurveOnFace(aF2FWD, aTFirst, aTLast, aC2D2, aC2D2A);
753 BOPTools_Tools2D::AdjustPCurveOnFace(aF2FWD, aC3DETrim, aC2D2, aC2D2A);
756 aBB.UpdateEdge(aE, aC2D2A, aF2FWD, aTolFact);
762 //=======================================================================
763 // function: IsExistingPaveBlock
765 //=======================================================================
766 Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
767 const BOPTools_SSInterference& aFFi)
769 Standard_Boolean bFlag=Standard_False;
770 Standard_Integer nVNew1, nVNew2, nV1, nV2, iC;
771 Standard_Real aTolR3D;
772 BOPTools_ListIteratorOfListOfPaveBlock anIt;
774 aTolR3D=aFFi.TolR3D();
776 nVNew1=aPBNew.Pave1().Index();
777 nVNew2=aPBNew.Pave2().Index();
779 const BOPTools_ListOfPaveBlock& aLPBR=aFFi.PaveBlocks();
780 anIt.Initialize(aLPBR);
781 for (; anIt.More(); anIt.Next()) {
782 const BOPTools_PaveBlock& aPBR=anIt.Value();
783 nV1=aPBR.Pave1().Index();
784 nV2=aPBR.Pave2().Index();
785 if (nVNew1==nV1 || nVNew1==nV2 || nVNew2==nV1 || nVNew2==nV2) {
787 iC=CheckIntermediatePoint(aPBNew, aPBR, aTolR3D);
795 //=======================================================================
796 // function: CheckIntermediatePoint
798 //=======================================================================
799 Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
800 const BOPTools_PaveBlock& aPBR,
801 const Standard_Real aTolC)
804 Standard_Real aT11, aT12, aTM, aTmp;
805 Standard_Integer iVM, nE2;
811 const BOPTools_Pave& aPave11=aPB.Pave1();
812 aT11=aPave11.Param();
814 const BOPTools_Pave& aPave12=aPB.Pave2();
815 aT12=aPave12.Param();
817 aTM=IntTools_Tools::IntermediatePoint (aT11, aT12);
819 const IntTools_Curve& aIC=aPB.Curve();
822 aBB.MakeVertex (aVM, aPM, aTolC);
826 const TopoDS_Edge& aE2=TopoDS::Edge(myDS->GetShape(nE2));
828 iVM=myContext.ComputeVE(aVM, aE2, aTmp);
832 //=======================================================================
833 // function: PutBoundPaveOnCurve
835 //=======================================================================
836 void NMTTools_PaveFiller::PutBoundPaveOnCurve(BOPTools_Curve& aBC,
837 BOPTools_SSInterference& aFFi)
839 Standard_Boolean bHasBounds, bVF;
840 Standard_Integer nF1, nF2;
841 Standard_Real aT1, aT2, aTolR3D;
844 const IntTools_Curve& aIC=aBC.Curve();
845 bHasBounds=aIC.HasBounds ();
851 aIC.Bounds (aT1, aT2, aP1, aP2);
854 aFFi.Indices(nF1, nF2);
855 aTolR3D=aFFi.TolR3D();
857 const TopoDS_Face& aF1=TopoDS::Face(myDS->GetShape(nF1));
858 const TopoDS_Face& aF2=TopoDS::Face(myDS->GetShape(nF2));
860 bVF=myContext.IsValidPointForFaces (aP1, aF1, aF2, aTolR3D);
862 PutBoundPaveOnCurve (aP1, aT1, aBC, aFFi);
865 bVF=myContext.IsValidPointForFaces (aP2, aF1, aF2, aTolR3D);
867 PutBoundPaveOnCurve (aP2, aT2, aBC, aFFi);
870 //=======================================================================
871 // function: PutBoundPaveOnCurve
873 //=======================================================================
874 void NMTTools_PaveFiller::PutBoundPaveOnCurve(const gp_Pnt& aP,
875 const Standard_Real aT,
877 BOPTools_SSInterference& aFFi)
879 Standard_Boolean bFound1, bFound2;
881 Standard_Real aTolV=aFFi.TolR3D();
883 BOPTools_Pave aPave1, aPave2, aPave;
884 BOPTools_PaveSet& aCPS=aBC.Set();
885 BOPTools_PaveSet& aFFiPS=aFFi.NewPaveSet();
886 const IntTools_Curve& aIC=aBC.Curve();
888 bFound1=FindPave(aP, aTolV, aCPS , aPave1);
889 bFound2=FindPave(aP, aTolV, aFFiPS, aPave2);
891 if (!bFound1 && !bFound2) {
892 TopoDS_Vertex aNewVertex;
893 BOPTools_Tools::MakeNewVertex(aP, aTolV, aNewVertex);
895 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
896 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
897 nV=myDS->NumberOfInsertedShapes();
902 aFFiPS.Append(aPave);
904 // Append Techno Vertex to the Curve
905 TColStd_ListOfInteger& aTVs=aBC.TechnoVertices();
909 if (bFound1 && !bFound2) {
913 aFFiPS.Append(aPave);
915 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
916 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
919 if (!bFound1 && bFound2) {
925 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
926 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
929 //=======================================================================
930 // function: FindPave
932 //=======================================================================
933 Standard_Boolean NMTTools_PaveFiller::FindPave(const gp_Pnt& aP,
934 const Standard_Real aTolPV,
935 const BOPTools_PaveSet& aPS,
936 BOPTools_Pave& aPave)
939 Standard_Boolean bIsVertex=Standard_False;
941 const BOPTools_ListOfPave& aLP=aPS.Set();
942 BOPTools_ListIteratorOfListOfPave anIt(aLP);
943 for (; anIt.More(); anIt.Next()) {
944 const BOPTools_Pave& aPC=anIt.Value();
946 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
947 bIsVertex=IntTools_Tools::IsVertex (aP, aTolPV, aV);
955 //=======================================================================
956 // function: PrepareSetForFace
958 //=======================================================================
959 void NMTTools_PaveFiller::PrepareSetForFace(const Standard_Integer nF1,
960 const Standard_Integer nF2,
961 BOPTools_PaveSet& aPSF)
963 Standard_Integer nV1, nV2;
964 TColStd_MapOfInteger aMap;
965 BOPTools_ListOfPaveBlock aLPB1, aLPB2;
966 BOPTools_ListIteratorOfListOfPaveBlock anIt;
968 RealSplitsFace(nF1, aLPB1);
969 RealSplitsFace(nF2, aLPB2);
973 anIt.Initialize(aLPB1);
974 for (; anIt.More(); anIt.Next()) {
975 const BOPTools_PaveBlock& aPB=anIt.Value();
976 const BOPTools_Pave& aPave1=aPB.Pave1();
978 if (!aMap.Contains(nV1)) {
982 const BOPTools_Pave& aPave2=aPB.Pave2();
984 if (!aMap.Contains(nV2)) {
990 //=======================================================================
991 // function: PutPaveOnCurve
993 //=======================================================================
994 void NMTTools_PaveFiller::PutPaveOnCurve(const BOPTools_PaveSet& aPaveSet,
995 const Standard_Real aTolR3D,
999 Standard_Boolean bIsVertexOnLine;
1001 BOPTools_ListIteratorOfListOfPave anIt;
1003 GeomAdaptor_Curve aGAC;
1005 const IntTools_Curve& aC=aBC.Curve();
1006 Handle (Geom_Curve) aC3D= aC.Curve();
1008 BndLib_Add3dCurve::Add(aGAC, aTolR3D, aBBC);
1010 const BOPTools_ListOfPave& aLP=aPaveSet.Set();
1011 anIt.Initialize(aLP);
1012 for (; anIt.More(); anIt.Next()) {
1013 const BOPTools_Pave& aPave=anIt.Value();
1016 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
1019 BRepBndLib::Add(aV, aBBV);
1020 if (aBBC.IsOut(aBBV)){
1024 bIsVertexOnLine=myContext.IsVertexOnLine(aV, aC, aTolR3D, aT);
1026 if (bIsVertexOnLine) {
1027 BOPTools_Pave aPaveNew(nV, aT, BooleanOperations_SurfaceSurface);
1028 BOPTools_PaveSet& aPS=aBC.Set();
1029 aPS.Append(aPaveNew);
1031 BOPTools_Tools::UpdateVertex (aC, aT, aV);
1036 //=======================================================================
1037 // function: IsPairFound
1039 //=======================================================================
1040 Standard_Boolean IsPairFound(const Standard_Integer nF1,
1041 const Standard_Integer nF2,
1042 BOPTools_InterferencePool* myIntrPool,
1043 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWhat,
1044 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWith)
1046 Standard_Boolean bIsFound;
1048 if (!aMapWhat.Contains(nF1)) {
1049 TColStd_IndexedMapOfInteger aMWhat;
1050 FMapWhat(nF1, myIntrPool, aMWhat);
1051 aMapWhat.Add(nF1, aMWhat);
1054 if (!aMapWith.Contains(nF2)) {
1055 TColStd_IndexedMapOfInteger aMWith;
1056 FMapWith(nF2, myIntrPool, aMWith);
1057 aMapWith.Add(nF2, aMWith);
1060 const TColStd_IndexedMapOfInteger& aMWht=aMapWhat.FindFromKey(nF1);
1061 const TColStd_IndexedMapOfInteger& aMWit=aMapWith.FindFromKey(nF2);
1063 bIsFound=IsFound(aMWht, aMWit);
1067 //=======================================================================
1068 // function: FMapWhat
1070 //=======================================================================
1071 void FMapWhat(const Standard_Integer nF,
1072 BOPTools_InterferencePool* myIntrPool,
1073 TColStd_IndexedMapOfInteger& aMapWhat)
1076 Standard_Integer nE, nV;
1080 BooleanOperations_ShapesDataStructure* myDS=myIntrPool->DS();
1081 BooleanOperations_OnceExplorer aExp(*myDS);
1085 aExp.Init(nF, TopAbs_VERTEX);
1086 for (; aExp.More(); aExp.Next()) {
1091 aExp.Init(nF, TopAbs_EDGE);
1092 for (; aExp.More(); aExp.Next()) {
1097 //=======================================================================
1098 // function: FMapWith
1100 //=======================================================================
1101 void FMapWith(const Standard_Integer nF,
1102 BOPTools_InterferencePool* myIntrPool,
1103 TColStd_IndexedMapOfInteger& aMapWith)
1105 TColStd_IndexedMapOfInteger aMapWhat;
1107 FMapWhat(nF, myIntrPool, aMapWhat);
1110 Standard_Integer i, aNb, anIndex, aWhat, aWith;
1111 BOPTools_ListIteratorOfListOfInterference anIt;
1113 const BOPTools_CArray1OfInterferenceLine& anArrIL= myIntrPool->InterferenceTable();
1115 aNb=aMapWhat.Extent();
1116 for (i=1; i<=aNb; i++) {
1119 const BOPTools_InterferenceLine& aWithLine=anArrIL(aWhat);
1121 const BOPTools_ListOfInterference& aLI=aWithLine.List();
1122 anIt.Initialize(aLI);
1123 for (; anIt.More(); anIt.Next()) {
1124 const BOPTools_Interference& anIntf=anIt.Value();
1125 anIndex=anIntf.Index();
1127 aWith=anIntf.With();
1128 aMapWith.Add(aWith);
1133 //=======================================================================
1134 // function: IsFound
1136 //=======================================================================
1137 Standard_Boolean IsFound(const TColStd_IndexedMapOfInteger& aMapWhat,
1138 const TColStd_IndexedMapOfInteger& aMapWith)
1140 Standard_Boolean bFlag=Standard_False;
1141 Standard_Integer i, aNb, aWhat;
1143 aNb=aMapWhat.Extent();
1144 for (i=1; i<=aNb; i++) {
1146 if (aMapWith.Contains(aWhat)) {