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>
68 #include <Geom_Surface.hxx>
69 #include <TopLoc_Location.hxx>
72 Standard_Boolean IsPairFound(const Standard_Integer nF1,
73 const Standard_Integer nF2,
74 BOPTools_InterferencePool* myIntrPool,
75 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWhat,
76 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWith);
79 void FMapWhat(const Standard_Integer nF,
80 BOPTools_InterferencePool* myIntrPool,
81 TColStd_IndexedMapOfInteger& aMapWhat);
83 void FMapWith(const Standard_Integer nF,
84 BOPTools_InterferencePool* myIntrPool,
85 TColStd_IndexedMapOfInteger& aMapWith);
87 Standard_Boolean IsFound(const TColStd_IndexedMapOfInteger& aMapWhat,
88 const TColStd_IndexedMapOfInteger& aMapWith);
90 //=======================================================================
91 // function: PerformFF
93 //=======================================================================
94 void NMTTools_PaveFiller::PerformFF()
96 myIsDone=Standard_False;
98 Standard_Boolean bIsFound, bJustAdd, bIsComputed;
99 Standard_Integer n1, n2, anIndexIn, nF1, nF2, aBlockLength, aNbFFs;
100 Standard_Boolean bToApproxC3d, bToApproxC2dOnS1, bToApproxC2dOnS2, bIsDone;
101 Standard_Integer aNbCurves, aNbPoints;
102 Standard_Real anApproxTol, aTolR3D, aTolR2D;
103 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMapWhat, aMapWith;
104 IntTools_SequenceOfPntOn2Faces aPnts;
105 IntTools_SequenceOfCurves aCvs;
106 BooleanOperations_KindOfInterference aTypeFF=BooleanOperations_SurfaceSurface;
108 BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
110 // F/F Interferences [BooleanOperations_SurfaceSurface]
111 myDSIt.Initialize(TopAbs_FACE, TopAbs_FACE);
113 // BlockLength correction
114 aNbFFs=ExpectedPoolLength();
115 aBlockLength=aFFs.BlockLength();
116 if (aNbFFs > aBlockLength) {
117 aFFs.SetBlockLength(aNbFFs);
120 for (; myDSIt.More(); myDSIt.Next()) {
121 myDSIt.Current(n1, n2, bJustAdd);
123 bIsComputed=myIntrPool->IsComputed(n1, n2);
138 bIsFound=IsPairFound(nF1, nF2, myIntrPool, aMapWhat, aMapWith);
142 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
145 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
146 anIndexIn=aFFs.Append(anInterf);
147 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
152 const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
153 const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
156 bToApproxC3d = mySectionAttribute.Approximation();
157 bToApproxC2dOnS1 = mySectionAttribute.PCurveOnS1();
158 bToApproxC2dOnS2 = mySectionAttribute.PCurveOnS2();
162 IntTools_FaceFace aFF;
164 aFF.SetParameters (bToApproxC3d, bToApproxC2dOnS1,
165 bToApproxC2dOnS2, anApproxTol);
167 aFF.Perform(aF1, aF2);
169 bIsDone=aFF.IsDone();
173 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
176 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
177 anIndexIn=aFFs.Append(anInterf);
178 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
183 aTolR3D=aFF.TolReached3d();
184 aTolR2D=aFF.TolReached2d();
185 if (aTolR3D < 1.e-7){
189 aFF.PrepareLines3D();
191 const IntTools_SequenceOfCurves& aCvsX=aFF.Lines();
192 const IntTools_SequenceOfPntOn2Faces& aPntsX=aFF.Points();
194 aNbCurves=aCvsX.Length();
195 aNbPoints=aPntsX.Length();
197 if (!aNbCurves && !aNbPoints) {
198 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
199 anIndexIn=aFFs.Append(anInterf);
200 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
205 BOPTools_SSInterference anInterf (nF1, nF2, aTolR3D, aTolR2D, aCvsX, aPntsX);
206 anIndexIn=aFFs.Append(anInterf);
207 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
210 }// for (; myDSIt.More(); myDSIt.Next())
212 myIsDone=Standard_True;
214 //=======================================================================
215 // function: MakeBlocks
217 //=======================================================================
218 void NMTTools_PaveFiller::MakeBlocks()
220 myIsDone=Standard_False;
222 Standard_Boolean bIsExistingPaveBlock, bIsValidIn2D;
223 Standard_Integer i, aNbFFs, nF1, nF2, aBid=0;
224 Standard_Integer nV1, nV2, j, aNbCurves;
225 Standard_Real aTolR3D, aTol2D, aT1, aT2, aTolPPC=Precision::PConfusion();
226 TColStd_MapOfInteger aMap;
227 NMTTools_IndexedDataMapOfShapePaveBlock aMEPB;
228 BooleanOperations_IndexedDataMapOfShapeInteger aMapEI;
230 BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
232 // 1. Produce Section Edges from intersection curves
233 // between each pair of faces
235 aNbFFs=aFFs.Extent();
236 for (i=1; i<=aNbFFs; ++i) {
237 BOPTools_SSInterference& aFFi=aFFs(i);
240 aFFi.Indices(nF1, nF2);
241 const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
242 const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
244 // Add blocks that are existing ones for this FF-interference
245 BOPTools_ListOfPaveBlock aLPB;
246 RealSplitsInFace (aBid, nF1, nF2, aLPB);
247 RealSplitsInFace (aBid, nF2, nF1, aLPB);
248 RealSplitsOnFace (aBid, nF1, nF2, aLPB);
251 BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
252 for (; anIt.More(); anIt.Next()) {
253 const BOPTools_PaveBlock& aPB=anIt.Value();
254 aFFi.AppendBlock(aPB);
255 nV1=aPB.Pave1().Index();
256 nV2=aPB.Pave2().Index();
261 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
262 aNbCurves=aSCvs.Length();
267 aTolR3D=aFFi.TolR3D();
268 aTol2D=(aTolR3D < 1.e-3) ? 1.e-3 : aTolR3D;
270 BOPTools_PaveSet aPSF;
272 PrepareSetForFace (nF1, nF2, aPSF);
274 // Put Paves On Curves
275 for (j=1; j<=aNbCurves; ++j) {
276 BOPTools_Curve& aBC=aSCvs(j);
278 const IntTools_Curve& aC=aBC.Curve();
279 Handle (Geom_Curve) aC3D= aC.Curve();
281 PutPaveOnCurve (aPSF, aTolR3D, aBC);
284 // Put bounding paves on curves
285 for (j=1; j<=aNbCurves; ++j) {
286 BOPTools_Curve& aBC=aSCvs(j);
287 PutBoundPaveOnCurve (aBC, aFFi);
290 // Pave Blocks on Curves
291 for (j=1; j<=aNbCurves; ++j) {
292 BOPTools_Curve& aBC=aSCvs(j);
293 const IntTools_Curve& aIC= aBC.Curve();
294 BOPTools_PaveSet& aPaveSet=aBC.Set();
296 BOPTools_PaveBlockIterator aPBIter(0, aPaveSet);
297 for (; aPBIter.More(); aPBIter.Next()) {
298 BOPTools_PaveBlock& aPBNew=aPBIter.Value();
299 aPBNew.SetCurve(aIC);
300 aPBNew.SetFace1(nF1);
301 aPBNew.SetFace2(nF2);
303 nV1=aPBNew.Pave1().Index();
304 nV2=aPBNew.Pave2().Index();
305 aT1=aPBNew.Pave1().Param();
306 aT2=aPBNew.Pave2().Param();
308 if((nV1==nV2) && (Abs(aT2 - aT1) < aTolPPC)) {
312 bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aFFi);
313 if (bIsExistingPaveBlock) {
314 // aPBNew was (or just lays) boundary PB
317 // Checking of validity in 2D
319 bIsValidIn2D=myContext.IsValidBlockForFaces(aT1, aT2, aIC, aF1, aF2, aTol2D);
324 //aBC.AppendNewBlock(aPBNew);
329 const TopoDS_Vertex& aV1=TopoDS::Vertex(myDS->Shape(nV1));
330 const TopoDS_Vertex& aV2=TopoDS::Vertex(myDS->Shape(nV2));
332 BOPTools_Tools::MakeSectEdge (aIC, aV1, aT1, aV2, aT2, aES);
335 Standard_Real aTolR2D;
337 aTolR2D=aFFi.TolR2D();
338 Handle(Geom2d_Curve) aC2D1=aIC.FirstCurve2d();
339 Handle(Geom2d_Curve) aC2D2=aIC.SecondCurve2d();
341 NMTTools_Tools::MakePCurve(aES, aF1, aC2D1, aTolR2D);
342 NMTTools_Tools::MakePCurve(aES, aF2, aC2D2, aTolR2D);
345 aMEPB.Add(aES, aPBNew);
348 } // end of for (j=1; j<=aNbCurves; ++j)
349 }// for (i=1; i<=aNbFFs; ++i)
350 //=============================================================
352 // II. Post treatment
354 // Input data: aMEPB, aMapEI
355 // Result : section edges in myDS
357 Standard_Integer aNbSE;
359 aNbSE=aMEPB.Extent();
361 // there is nothing to do here
366 TopoDS_Compound aCompound;
368 // 1. Make compound from SE
369 aBB.MakeCompound(aCompound);
370 for (i=1; i<=aNbSE; ++i) {
371 const TopoDS_Shape& aSE=aMEPB.FindKey(i);
372 aBB.Add(aCompound, aSE);
376 // 2. Intersect SE using auxiliary Filler
377 NMTDS_ShapesDataStructure tDS;
379 tDS.SetCompositeShape(aCompound);
382 BOPTools_InterferencePool tIP(tDS);
383 NMTTools_PaveFiller tPF(tIP);
388 tPF.PerformNewVertices();
391 tPF.myPavePool.Resize (tPF.myNbEdges);
399 tPF.myCommonBlockPool.Resize (tPF.myNbEdges);
400 tPF.mySplitShapesPool.Resize (tPF.myNbEdges);
401 tPF.myPavePoolNew .Resize (tPF.myNbEdges);
403 tPF.PreparePaveBlocks(TopAbs_VERTEX, TopAbs_EDGE);
404 tPF.PreparePaveBlocks(TopAbs_EDGE, TopAbs_EDGE);
408 tPF.RefinePavePool ();
410 tPF.myPavePoolNew.Destroy();
412 tPF.MakeSplitEdges();
413 tPF.UpdateCommonBlocks();
415 // 3. Treatment of the result of intersection
417 Standard_Integer aNbOld, aNbLines, aNbPB, mV1, mV2, nE, mE, iFF;
418 TopAbs_ShapeEnum aType;
419 BOPTools_ListIteratorOfListOfPaveBlock aIt;
420 BOPTColStd_IndexedDataMapOfIntegerInteger aMNewOld;
422 const BOPTools_SplitShapesPool& aSSP=tPF.mySplitShapesPool;
423 const NMTTools_CommonBlockPool& aCBP=tPF.myCommonBlockPool;
425 aNbLines=tDS.NumberOfInsertedShapes();
426 aNbOld=tDS.NumberOfShapesOfTheObject();
428 // 3.1 Links between indices in tDS and DS (kept in aMNewOld)
430 // 3.1.1.Old vertices [ links ]
431 for (i=1; i<=aNbOld; ++i) {
432 const TopoDS_Shape& aV=tDS.Shape(i);
433 aType=aV.ShapeType();
434 if (aType!=TopAbs_VERTEX) {
438 for (j=1; j<=aNbSE; ++j) {
439 const BOPTools_PaveBlock& aPBSE=aMEPB(j);
440 nV1=aPBSE.Pave1().Index();
441 const TopoDS_Shape& aV1=myDS->Shape(nV1);
442 if (aV1.IsSame(aV)) {
443 aMNewOld.Add(i, nV1);
446 nV2=aPBSE.Pave2().Index();
447 const TopoDS_Shape& aV2=myDS->Shape(nV2);
448 if (aV2.IsSame(aV)) {
449 aMNewOld.Add(i, nV2);
455 // 3.1.2. New vertices [ links ]
456 i=tDS.NumberOfSourceShapes()+1;
457 for (; i<=aNbLines; ++i) {
458 const TopoDS_Shape& aV=tDS.Shape(i);
459 aType=aV.ShapeType();
460 if (aType!=TopAbs_VERTEX) {
464 // Insert new vertex in myDS
465 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
466 myDS->InsertShapeAndAncestorsSuccessors(aV, anASSeq);
467 nV1=myDS->NumberOfInsertedShapes();
469 aMNewOld.Add(i, nV1);
472 // 3.2. Treatment of section edges (SE)
473 for (i=1; i<=aNbOld; ++i) {
474 const TopoDS_Shape& aE=tDS.Shape(i);
475 aType=aE.ShapeType();
476 if (aType!=TopAbs_EDGE) {
480 // block of section edge that we already have for this SE
481 BOPTools_PaveBlock& aPBSE=aMEPB.ChangeFromKey(aE);
483 // Corresponding FF-interference
484 iFF=aMapEI.FindFromKey(aE);
485 BOPTools_SSInterference& aFFi=aFFs(iFF);
486 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
488 BOPTools_Curve& aBC=aSCvs(1);
490 const BOPTools_ListOfPaveBlock& aLPB=aSSP(tDS.RefEdge(i));
494 // no pave blocks -> use aPBSE and whole edge aE
495 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
497 nV1=aPBSE.Pave1().Index();
498 const TopoDS_Shape& aV1=myDS->Shape(nV1);
499 nV2=aPBSE.Pave2().Index();
500 const TopoDS_Shape& aV2=myDS->Shape(nV2);
502 anASSeq.SetNewSuccessor(nV1);
503 anASSeq.SetNewOrientation(aV1.Orientation());
504 anASSeq.SetNewSuccessor(nV2);
505 anASSeq.SetNewOrientation(aV2.Orientation());
507 myDS->InsertShapeAndAncestorsSuccessors(aE, anASSeq);
508 nE=myDS->NumberOfInsertedShapes();
511 aBC.AppendNewBlock(aPBSE);
518 const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
519 const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
521 const NMTTools_ListOfCommonBlock& aLCB=aCBP(tDS.RefEdge(i));
522 NMTTools_CommonBlockAPI aCBAPI(aLCB);
524 aIt.Initialize(aLPB);
525 for (; aIt.More(); aIt.Next()) {
526 BOPTools_PaveBlock aPB=aIt.Value();
528 if (aCBAPI.IsCommonBlock(aPB)) {
529 // it can be Common Block
530 Standard_Real aTolEx;
531 Handle(Geom2d_Curve) aC2D1, aC2D2;
532 TopoDS_Face aF1FWD, aF2FWD;
534 NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB);
535 const BOPTools_ListOfPaveBlock& aLPBx=aCB.PaveBlocks();
537 aPB=aCB.PaveBlock1();
538 mE=aPB.Edge(); // index of edge in tDS
539 const TopoDS_Edge& aEx=TopoDS::Edge(tDS.Shape(mE));
540 aTolEx=BRep_Tool::Tolerance(aEx);
542 //modified by NIZNHY-PKV Mon Dec 27 14:30:15 2004 f
545 aF1FWD.Orientation(TopAbs_FORWARD);
546 NMTTools_Tools::MakePCurve(aEx, aF1FWD, aC2D1, aTolEx);
549 aF2FWD.Orientation(TopAbs_FORWARD);
550 NMTTools_Tools::MakePCurve(aEx, aF2FWD, aC2D2, aTolEx);
552 // block A has been removed
553 //modified by NIZNHY-PKV Mon Dec 27 14:33:26 2004 t
554 } //if (aCBAPI.IsCommonBlock(aPB))
557 mE=aPB.Edge(); // index of edge in tDS
558 const TopoDS_Shape& aSp=tDS.Shape(mE);
560 const BOPTools_Pave& aPave1=aPB.Pave1();
562 mV1=aPave1.Index(); // index in tDS
563 nV1=aMNewOld.FindFromKey(mV1); // index in myDS
564 const TopoDS_Shape& aV1=myDS->Shape(nV1);
566 const BOPTools_Pave& aPave2=aPB.Pave2();
569 nV2=aMNewOld.FindFromKey(mV2);
570 const TopoDS_Shape& aV2=myDS->Shape(nV2);
572 if (!aMNewOld.Contains(mE)) {
573 // add new SE to the myDS
574 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
576 anASSeq.SetNewSuccessor(nV1);
577 anASSeq.SetNewOrientation(aV1.Orientation());
579 anASSeq.SetNewSuccessor(nV2);
580 anASSeq.SetNewOrientation(aV2.Orientation());
582 myDS->InsertShapeAndAncestorsSuccessors(aSp, anASSeq);
583 nE=myDS->NumberOfInsertedShapes();
585 aMNewOld.Add(mE, nE);
588 nE=aMNewOld.FindFromKey(mE);
591 BOPTools_PaveBlock aPBx;
592 BOPTools_Pave aP1, aP2;
608 aBC.AppendNewBlock(aPBx);
609 }// for (; aIt.More(); aIt.Next())
610 }// for (i=1; i<=aNbOld; ++i)
612 myIsDone=Standard_True;
614 //=======================================================================
615 // function: MakePCurves
617 //=======================================================================
618 void NMTTools_PaveFiller::MakePCurves()
620 Standard_Integer i, aNb, nF1, nF2, nE;
621 TopoDS_Face aF1FWD, aF2FWD;
622 BOPTools_ListIteratorOfListOfPaveBlock anIt;
624 BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
627 for (i=1; i<=aNb; i++) {
628 BOPTools_SSInterference& aFF=aFFs(i);
629 aFF.Indices(nF1, nF2);
631 const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
632 const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
635 aF1FWD.Orientation(TopAbs_FORWARD);
637 aF2FWD.Orientation(TopAbs_FORWARD);
639 // In, On parts processing
640 const BOPTools_ListOfPaveBlock& aLPBInOn=aFF.PaveBlocks();
642 anIt.Initialize(aLPBInOn);
643 for (; anIt.More(); anIt.Next()) {
644 const BOPTools_PaveBlock& aPB=anIt.Value();
646 const TopoDS_Edge& aE=TopoDS::Edge(myDS->Shape(nE));
648 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF1FWD);
649 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF2FWD);
652 // Section Edges processing
654 Standard_Integer aNbCurves, k, aNbV;
655 Standard_Real aTolEdge, aTolR2D, aTolFact, aTolV, aTolVmax;
658 BOPTools_SequenceOfCurves& aSC=aFF.Curves();
659 aNbCurves=aSC.Length();
664 const BOPTools_Curve& aBC=aSC(1);
665 const BOPTools_ListOfPaveBlock& aLPB=aBC.NewPaveBlocks();
666 anIt.Initialize(aLPB);
667 for (; anIt.More(); anIt.Next()) {
668 const BOPTools_PaveBlock& aPB=anIt.Value();
670 const TopoDS_Edge& aE=TopoDS::Edge(myDS->Shape(nE));
672 aTolEdge=BRep_Tool::Tolerance(aE);
673 aTolR2D=aFF.TolR2D();
674 aTolFact=Max(aTolEdge, aTolR2D);
676 // Check vertices tolerances and correct them if necessary
677 // to prevent situation when TolE > TolV
679 TopTools_IndexedMapOfShape aVMap;
680 TopExp::MapShapes(aE, TopAbs_VERTEX, aVMap);
684 for (k=1; k<=aNbV; ++k) {
685 const TopoDS_Vertex& aV=TopoDS::Vertex(aVMap(k));
686 aTolV=BRep_Tool::Tolerance(aV);
687 if (aTolV>aTolVmax) {
692 if (aTolFact>aTolVmax) {
696 Standard_Real aTFirst, aTLast, aOutFirst, aOutLast, aOutTol;
697 Handle(Geom2d_Curve) aC2D1, aC2D1A, aC2D2, aC2D2A;
698 Handle(Geom_TrimmedCurve)aC3DETrim;
700 const Handle(Geom_Curve)& aC3DE=BRep_Tool::Curve(aE, aTFirst, aTLast);
701 aC3DETrim=new Geom_TrimmedCurve(aC3DE, aTFirst, aTLast);
704 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF1FWD);
705 BOPTools_Tools2D::CurveOnSurface(aE, aF1FWD, aC2D1, aOutFirst, aOutLast, aOutTol, Standard_True);
707 if (aC3DE->IsPeriodic()) {
708 BOPTools_Tools2D::AdjustPCurveOnFace(aF1FWD, aTFirst, aTLast, aC2D1, aC2D1A);
711 BOPTools_Tools2D::AdjustPCurveOnFace(aF1FWD, aC3DETrim, aC2D1, aC2D1A);
714 aBB.UpdateEdge(aE, aC2D1A, aF1FWD, aTolFact);
717 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF2FWD);
718 BOPTools_Tools2D::CurveOnSurface(aE, aF2FWD, aC2D2, aOutFirst, aOutLast, aOutTol, Standard_True);
720 if (aC3DE->IsPeriodic()) {
721 BOPTools_Tools2D::AdjustPCurveOnFace(aF2FWD, aTFirst, aTLast, aC2D2, aC2D2A);
724 BOPTools_Tools2D::AdjustPCurveOnFace(aF2FWD, aC3DETrim, aC2D2, aC2D2A);
727 aBB.UpdateEdge(aE, aC2D2A, aF2FWD, aTolFact);
733 //=======================================================================
734 // function: IsExistingPaveBlock
736 //=======================================================================
737 Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
738 const BOPTools_SSInterference& aFFi)
740 Standard_Boolean bFlag=Standard_False;
741 Standard_Integer nVNew1, nVNew2, nV1, nV2, iC;
742 Standard_Real aTolR3D;
743 BOPTools_ListIteratorOfListOfPaveBlock anIt;
745 aTolR3D=aFFi.TolR3D();
747 nVNew1=aPBNew.Pave1().Index();
748 nVNew2=aPBNew.Pave2().Index();
750 const BOPTools_ListOfPaveBlock& aLPBR=aFFi.PaveBlocks();
751 anIt.Initialize(aLPBR);
752 for (; anIt.More(); anIt.Next()) {
753 const BOPTools_PaveBlock& aPBR=anIt.Value();
754 nV1=aPBR.Pave1().Index();
755 nV2=aPBR.Pave2().Index();
756 if (nVNew1==nV1 || nVNew1==nV2 || nVNew2==nV1 || nVNew2==nV2) {
758 iC=CheckIntermediatePoint(aPBNew, aPBR, aTolR3D);
766 //=======================================================================
767 // function: CheckIntermediatePoint
769 //=======================================================================
770 Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
771 const BOPTools_PaveBlock& aPBR,
772 const Standard_Real aTolC)
775 Standard_Real aT11, aT12, aTM, aTmp;
776 Standard_Integer iVM, nE2;
782 const BOPTools_Pave& aPave11=aPB.Pave1();
783 aT11=aPave11.Param();
785 const BOPTools_Pave& aPave12=aPB.Pave2();
786 aT12=aPave12.Param();
788 aTM=IntTools_Tools::IntermediatePoint (aT11, aT12);
790 const IntTools_Curve& aIC=aPB.Curve();
793 aBB.MakeVertex (aVM, aPM, aTolC);
797 const TopoDS_Edge& aE2=TopoDS::Edge(myDS->GetShape(nE2));
799 iVM=myContext.ComputeVE(aVM, aE2, aTmp);
803 //=======================================================================
804 // function: PutBoundPaveOnCurve
806 //=======================================================================
807 void NMTTools_PaveFiller::PutBoundPaveOnCurve(BOPTools_Curve& aBC,
808 BOPTools_SSInterference& aFFi)
810 Standard_Boolean bHasBounds, bVF;
811 Standard_Integer nF1, nF2;
812 Standard_Real aT1, aT2, aTolR3D;
815 const IntTools_Curve& aIC=aBC.Curve();
816 bHasBounds=aIC.HasBounds ();
822 aIC.Bounds (aT1, aT2, aP1, aP2);
825 aFFi.Indices(nF1, nF2);
826 aTolR3D=aFFi.TolR3D();
828 const TopoDS_Face& aF1=TopoDS::Face(myDS->GetShape(nF1));
829 const TopoDS_Face& aF2=TopoDS::Face(myDS->GetShape(nF2));
831 bVF=myContext.IsValidPointForFaces (aP1, aF1, aF2, aTolR3D);
833 PutBoundPaveOnCurve (aP1, aT1, aBC, aFFi);
836 bVF=myContext.IsValidPointForFaces (aP2, aF1, aF2, aTolR3D);
838 PutBoundPaveOnCurve (aP2, aT2, aBC, aFFi);
841 //=======================================================================
842 // function: PutBoundPaveOnCurve
844 //=======================================================================
845 void NMTTools_PaveFiller::PutBoundPaveOnCurve(const gp_Pnt& aP,
846 const Standard_Real aT,
848 BOPTools_SSInterference& aFFi)
850 Standard_Boolean bFound1, bFound2;
852 Standard_Real aTolV=aFFi.TolR3D();
854 BOPTools_Pave aPave1, aPave2, aPave;
855 BOPTools_PaveSet& aCPS=aBC.Set();
856 BOPTools_PaveSet& aFFiPS=aFFi.NewPaveSet();
857 const IntTools_Curve& aIC=aBC.Curve();
859 bFound1=FindPave(aP, aTolV, aCPS , aPave1);
860 bFound2=FindPave(aP, aTolV, aFFiPS, aPave2);
862 if (!bFound1 && !bFound2) {
863 TopoDS_Vertex aNewVertex;
864 BOPTools_Tools::MakeNewVertex(aP, aTolV, aNewVertex);
866 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
867 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
868 nV=myDS->NumberOfInsertedShapes();
873 aFFiPS.Append(aPave);
875 // Append Techno Vertex to the Curve
876 TColStd_ListOfInteger& aTVs=aBC.TechnoVertices();
880 if (bFound1 && !bFound2) {
884 aFFiPS.Append(aPave);
886 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
887 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
890 if (!bFound1 && bFound2) {
896 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
897 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
900 //=======================================================================
901 // function: FindPave
903 //=======================================================================
904 Standard_Boolean NMTTools_PaveFiller::FindPave(const gp_Pnt& aP,
905 const Standard_Real aTolPV,
906 const BOPTools_PaveSet& aPS,
907 BOPTools_Pave& aPave)
910 Standard_Boolean bIsVertex=Standard_False;
912 const BOPTools_ListOfPave& aLP=aPS.Set();
913 BOPTools_ListIteratorOfListOfPave anIt(aLP);
914 for (; anIt.More(); anIt.Next()) {
915 const BOPTools_Pave& aPC=anIt.Value();
917 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
918 bIsVertex=IntTools_Tools::IsVertex (aP, aTolPV, aV);
926 //=======================================================================
927 // function: PrepareSetForFace
929 //=======================================================================
930 void NMTTools_PaveFiller::PrepareSetForFace(const Standard_Integer nF1,
931 const Standard_Integer nF2,
932 BOPTools_PaveSet& aPSF)
934 Standard_Integer nV1, nV2;
935 TColStd_MapOfInteger aMap;
936 BOPTools_ListOfPaveBlock aLPB1, aLPB2;
937 BOPTools_ListIteratorOfListOfPaveBlock anIt;
939 RealSplitsFace(nF1, aLPB1);
940 RealSplitsFace(nF2, aLPB2);
944 anIt.Initialize(aLPB1);
945 for (; anIt.More(); anIt.Next()) {
946 const BOPTools_PaveBlock& aPB=anIt.Value();
947 const BOPTools_Pave& aPave1=aPB.Pave1();
949 if (!aMap.Contains(nV1)) {
953 const BOPTools_Pave& aPave2=aPB.Pave2();
955 if (!aMap.Contains(nV2)) {
961 //=======================================================================
962 // function: PutPaveOnCurve
964 //=======================================================================
965 void NMTTools_PaveFiller::PutPaveOnCurve(const BOPTools_PaveSet& aPaveSet,
966 const Standard_Real aTolR3D,
970 Standard_Boolean bIsVertexOnLine;
972 BOPTools_ListIteratorOfListOfPave anIt;
974 GeomAdaptor_Curve aGAC;
976 const IntTools_Curve& aC=aBC.Curve();
977 Handle (Geom_Curve) aC3D= aC.Curve();
979 BndLib_Add3dCurve::Add(aGAC, aTolR3D, aBBC);
981 const BOPTools_ListOfPave& aLP=aPaveSet.Set();
982 anIt.Initialize(aLP);
983 for (; anIt.More(); anIt.Next()) {
984 const BOPTools_Pave& aPave=anIt.Value();
987 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
990 BRepBndLib::Add(aV, aBBV);
991 if (aBBC.IsOut(aBBV)){
995 bIsVertexOnLine=myContext.IsVertexOnLine(aV, aC, aTolR3D, aT);
997 if (bIsVertexOnLine) {
998 BOPTools_Pave aPaveNew(nV, aT, BooleanOperations_SurfaceSurface);
999 BOPTools_PaveSet& aPS=aBC.Set();
1000 aPS.Append(aPaveNew);
1002 BOPTools_Tools::UpdateVertex (aC, aT, aV);
1007 //=======================================================================
1008 // function: IsPairFound
1010 //=======================================================================
1011 Standard_Boolean IsPairFound(const Standard_Integer nF1,
1012 const Standard_Integer nF2,
1013 BOPTools_InterferencePool* myIntrPool,
1014 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWhat,
1015 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWith)
1017 Standard_Boolean bIsFound;
1019 if (!aMapWhat.Contains(nF1)) {
1020 TColStd_IndexedMapOfInteger aMWhat;
1021 FMapWhat(nF1, myIntrPool, aMWhat);
1022 aMapWhat.Add(nF1, aMWhat);
1025 if (!aMapWith.Contains(nF2)) {
1026 TColStd_IndexedMapOfInteger aMWith;
1027 FMapWith(nF2, myIntrPool, aMWith);
1028 aMapWith.Add(nF2, aMWith);
1031 const TColStd_IndexedMapOfInteger& aMWht=aMapWhat.FindFromKey(nF1);
1032 const TColStd_IndexedMapOfInteger& aMWit=aMapWith.FindFromKey(nF2);
1034 bIsFound=IsFound(aMWht, aMWit);
1038 //=======================================================================
1039 // function: FMapWhat
1041 //=======================================================================
1042 void FMapWhat(const Standard_Integer nF,
1043 BOPTools_InterferencePool* myIntrPool,
1044 TColStd_IndexedMapOfInteger& aMapWhat)
1047 Standard_Integer nE, nV;
1051 BooleanOperations_ShapesDataStructure* myDS=myIntrPool->DS();
1052 BooleanOperations_OnceExplorer aExp(*myDS);
1056 aExp.Init(nF, TopAbs_VERTEX);
1057 for (; aExp.More(); aExp.Next()) {
1062 aExp.Init(nF, TopAbs_EDGE);
1063 for (; aExp.More(); aExp.Next()) {
1068 //=======================================================================
1069 // function: FMapWith
1071 //=======================================================================
1072 void FMapWith(const Standard_Integer nF,
1073 BOPTools_InterferencePool* myIntrPool,
1074 TColStd_IndexedMapOfInteger& aMapWith)
1076 TColStd_IndexedMapOfInteger aMapWhat;
1078 FMapWhat(nF, myIntrPool, aMapWhat);
1081 Standard_Integer i, aNb, anIndex, aWhat, aWith;
1082 BOPTools_ListIteratorOfListOfInterference anIt;
1084 const BOPTools_CArray1OfInterferenceLine& anArrIL= myIntrPool->InterferenceTable();
1086 aNb=aMapWhat.Extent();
1087 for (i=1; i<=aNb; i++) {
1090 const BOPTools_InterferenceLine& aWithLine=anArrIL(aWhat);
1092 const BOPTools_ListOfInterference& aLI=aWithLine.List();
1093 anIt.Initialize(aLI);
1094 for (; anIt.More(); anIt.Next()) {
1095 const BOPTools_Interference& anIntf=anIt.Value();
1096 anIndex=anIntf.Index();
1098 aWith=anIntf.With();
1099 aMapWith.Add(aWith);
1104 //=======================================================================
1105 // function: IsFound
1107 //=======================================================================
1108 Standard_Boolean IsFound(const TColStd_IndexedMapOfInteger& aMapWhat,
1109 const TColStd_IndexedMapOfInteger& aMapWith)
1111 Standard_Boolean bFlag=Standard_False;
1112 Standard_Integer i, aNb, aWhat;
1114 aNb=aMapWhat.Extent();
1115 for (i=1; i<=aNb; i++) {
1117 if (aMapWith.Contains(aWhat)) {
1125 for (k=0; k<2; ++k) {
1126 nF=(!k) ? nF1 : nF2;
1127 const TopoDS_Face& aF=TopoDS::Face(myDS->Shape(nF));
1129 bHasPCOnF=BOPTools_Tools2D::HasCurveOnSurface(aEx, aF);
1134 bFound=Standard_False;
1135 aItPBx.Initialize(aLPBx);
1136 for (; aItPBx.More(); aItPBx.Next()) {
1137 BOPTools_PaveBlock& aPBx=aIt.Value();
1138 nEOrx=aPBx.OriginalEdge();
1139 const TopoDS_Shape& aEOrx=tDS.Shape(nEOrx);
1140 BOPTools_PaveBlock& aPBSEx=aMEPB.ChangeFromKey(aEOrx);
1141 aT1x=aPBSEx.Pave1().Param();
1142 aT2x=aPBSEx.Pave2().Param();
1143 const IntTools_Curve& aICx=aPBSEx.Curve();
1145 nF1x=aPBSEx.Face1();
1146 nF2x=aPBSEx.Face2();
1149 Handle(Geom2d_Curve) aC2D1x=aICx.FirstCurve2d();
1150 Handle(Geom2d_TrimmedCurve)aC2D1xT =new Geom2d_TrimmedCurve(aC2D1x, aT1x, aT2x);
1151 aBB.UpdateEdge(aEx, aC2D1xT, aF, aTolEx);
1157 Handle(Geom2d_Curve) aC2D2x=aICx.SecondCurve2d();
1158 Handle(Geom2d_TrimmedCurve)aC2D2xT =new Geom2d_TrimmedCurve(aC2D2x, aT1x, aT2x);
1159 aBB.UpdateEdge(aEx, aC2D2xT, aF, aTolEx);
1165 BRepLib::SameParameter(aEx, aTolEx, Standard_True);