f7643cbc45fbd2f048befc2d747d731823a2f186
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_5.cxx
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
6 //
7 // This file is part of Open CASCADE Technology software library.
8 //
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.
14 //
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
17
18
19 #include <Precision.hxx>
20
21 #include <Bnd_Box.hxx>
22 #include <BOPAlgo_PaveFiller.hxx>
23 #include <BOPAlgo_SectionAttribute.hxx>
24 #include <BOPAlgo_Tools.hxx>
25 #include <BOPCol_MapOfInteger.hxx>
26 #include <BOPCol_NCVector.hxx>
27 #include <BOPCol_Parallel.hxx>
28 #include <BOPCol_DataMapOfShapeReal.hxx>
29 #include <BOPDS_CommonBlock.hxx>
30 #include <BOPDS_CoupleOfPaveBlocks.hxx>
31 #include <BOPDS_Curve.hxx>
32 #include <BOPDS_DataMapOfPaveBlockListOfInteger.hxx>
33 #include <BOPDS_DS.hxx>
34 #include <BOPDS_Interf.hxx>
35 #include <BOPDS_Iterator.hxx>
36 #include <BOPDS_MapOfPaveBlock.hxx>
37 #include <BOPDS_Pave.hxx>
38 #include <BOPDS_PaveBlock.hxx>
39 #include <BOPTools_AlgoTools.hxx>
40 #include <BRep_Builder.hxx>
41 #include <BRep_Tool.hxx>
42 #include <BRepAdaptor_Curve.hxx>
43 #include <BRepBndLib.hxx>
44 #include <GeomAPI_ProjectPointOnSurf.hxx>
45 #include <gp_Pnt.hxx>
46 #include <IntTools_CommonPrt.hxx>
47 #include <IntTools_Context.hxx>
48 #include <IntTools_EdgeFace.hxx>
49 #include <IntTools_Range.hxx>
50 #include <IntTools_SequenceOfCommonPrts.hxx>
51 #include <IntTools_Tools.hxx>
52 #include <TopoDS.hxx>
53 #include <TopoDS_Edge.hxx>
54 #include <TopoDS_Face.hxx>
55 #include <TopoDS_Vertex.hxx>
56
57 //=======================================================================
58 //class    : BOPAlgo_EdgeFace
59 //purpose  : 
60 //=======================================================================
61 class BOPAlgo_EdgeFace : 
62   public IntTools_EdgeFace,
63   public BOPAlgo_Algo {
64  
65  public:
66   DEFINE_STANDARD_ALLOC
67   
68   BOPAlgo_EdgeFace() : 
69     IntTools_EdgeFace(), 
70     BOPAlgo_Algo(),
71     myIE(-1), myIF(-1) {
72   };
73   //
74   virtual ~BOPAlgo_EdgeFace(){
75   };
76   //
77   void SetIndices(const Standard_Integer nE,
78                   const Standard_Integer nF) {
79     myIE=nE;
80     myIF=nF;
81   }
82   //
83   void Indices(Standard_Integer& nE,
84                Standard_Integer& nF) {
85     nE=myIE;
86     nF=myIF;
87   }
88   //
89   void SetNewSR(const IntTools_Range& aR){
90     myNewSR=aR;
91   }
92   //
93   IntTools_Range& NewSR(){
94     return myNewSR;
95   }
96   //
97   void SetPaveBlock(const Handle(BOPDS_PaveBlock)& aPB) {
98     myPB=aPB;
99   }
100   //
101   Handle(BOPDS_PaveBlock)& PaveBlock() {
102     return myPB;
103   }
104   //
105   virtual void Perform() {
106     BOPAlgo_Algo::UserBreak();
107     IntTools_EdgeFace::Perform();
108   }
109   //
110  protected:
111   Standard_Integer myIE;
112   Standard_Integer myIF;
113   IntTools_Range myNewSR;
114   Handle(BOPDS_PaveBlock) myPB;
115 };
116 //
117 //=======================================================================
118 typedef BOPCol_NCVector<BOPAlgo_EdgeFace> BOPAlgo_VectorOfEdgeFace; 
119 //
120 typedef BOPCol_ContextFunctor 
121   <BOPAlgo_EdgeFace,
122   BOPAlgo_VectorOfEdgeFace,
123   Handle(IntTools_Context), 
124   IntTools_Context> BOPAlgo_EdgeFaceFunctor;
125 //
126 typedef BOPCol_ContextCnt 
127   <BOPAlgo_EdgeFaceFunctor,
128   BOPAlgo_VectorOfEdgeFace,
129   Handle(IntTools_Context)> BOPAlgo_EdgeFaceCnt;
130 //
131 //=======================================================================
132 //function : PerformEF
133 //purpose  : 
134 //=======================================================================
135 void BOPAlgo_PaveFiller::PerformEF()
136 {
137   Standard_Integer iSize;
138   //
139   myErrorStatus=0;
140   //
141   FillShrunkData(TopAbs_EDGE, TopAbs_FACE);
142   //
143   myIterator->Initialize(TopAbs_EDGE, TopAbs_FACE);
144   iSize=myIterator->ExpectedLength();
145   if (!iSize) {
146     return; 
147   }
148   //
149   Standard_Boolean bJustAdd, bV[2];
150   Standard_Boolean bV1, bV2, bExpressCompute;
151   Standard_Integer nV1, nV2;
152   Standard_Integer nE, nF, aDiscretize, i, aNbCPrts, iX, nV[2];
153   Standard_Integer aNbEdgeFace, k;
154   Standard_Real aTolE, aTolF, aTS1, aTS2, aT1, aT2, aDeflection;
155   Handle(NCollection_BaseAllocator) aAllocator;
156   TopAbs_ShapeEnum aType;
157   BOPDS_ListIteratorOfListOfPaveBlock aIt;
158   BOPAlgo_VectorOfEdgeFace aVEdgeFace; 
159   //-----------------------------------------------------scope f
160   //
161   aAllocator=NCollection_BaseAllocator::CommonBaseAllocator();
162   //
163   BOPCol_MapOfInteger aMIEFC(100, aAllocator);
164   BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMVCPB(100, aAllocator);
165   BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, aAllocator);
166   //
167   aDiscretize=35;
168   aDeflection=0.01;
169   //
170   BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
171   aEFs.SetIncrement(iSize);
172   //
173   for (; myIterator->More(); myIterator->Next()) {
174     myIterator->Value(nE, nF, bJustAdd);
175     if(bJustAdd) {
176       continue;
177     }
178     //
179     const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
180     if (aSIE.HasFlag()){//degenerated 
181       continue;
182     }
183     //
184     const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape()));
185     const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF)));
186     const Bnd_Box& aBBF=myDS->ShapeInfo(nF).Box(); 
187     //
188     BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
189     const BOPDS_IndexedMapOfPaveBlock& aMPBF=aFI.PaveBlocksOn();
190     //
191     const BOPCol_MapOfInteger& aMVIn=aFI.VerticesIn();
192     const BOPCol_MapOfInteger& aMVOn=aFI.VerticesOn();
193     //
194     aTolE=BRep_Tool::Tolerance(aE);
195     aTolF=BRep_Tool::Tolerance(aF);
196     //
197     BOPDS_ListOfPaveBlock& aLPB=myDS->ChangePaveBlocks(nE);
198     aIt.Initialize(aLPB);
199     for (; aIt.More(); aIt.Next()) {
200       Handle(BOPDS_PaveBlock)& aPB=aIt.ChangeValue();
201       //
202       const Handle(BOPDS_PaveBlock) aPBR=myDS->RealPaveBlock(aPB);
203       if (aMPBF.Contains(aPBR)) {
204         continue;
205       }
206       //
207       if (!aPB->HasShrunkData()) {
208         continue;
209       }
210       //
211       Bnd_Box aBBE;
212       aPB->ShrunkData(aTS1, aTS2, aBBE);
213       //
214       if (aBBF.IsOut (aBBE)) {
215         continue;
216       }
217       //
218       aPBR->Indices(nV1, nV2);
219       bV1=aMVIn.Contains(nV1) || aMVOn.Contains(nV1);
220       bV2=aMVIn.Contains(nV2) || aMVOn.Contains(nV2);
221       bExpressCompute=bV1 && bV2;
222       //
223       BOPAlgo_EdgeFace& aEdgeFace=aVEdgeFace.Append1();
224       //
225       aEdgeFace.SetIndices(nE, nF);
226       aEdgeFace.SetPaveBlock(aPB);
227       //
228       aEdgeFace.SetEdge (aE);
229       aEdgeFace.SetFace (aF);
230       aEdgeFace.SetTolE (aTolE);
231       aEdgeFace.SetTolF (aTolF);
232       aEdgeFace.SetDiscretize (aDiscretize);
233       aEdgeFace.SetDeflection (aDeflection);
234       aEdgeFace.UseQuickCoincidenceCheck(bExpressCompute);
235       //
236       IntTools_Range aSR(aTS1, aTS2);
237       IntTools_Range anewSR=aSR;
238       BOPTools_AlgoTools::CorrectRange(aE, aF, aSR, anewSR);
239       aEdgeFace.SetNewSR(anewSR);
240       //
241       aPB->Range(aT1, aT2);
242       IntTools_Range aPBRange(aT1, aT2);
243       aSR = aPBRange;
244       BOPTools_AlgoTools::CorrectRange(aE, aF, aSR, aPBRange);
245       aEdgeFace.SetRange (aPBRange);
246       aEdgeFace.SetProgressIndicator(myProgressIndicator);
247       //
248     }//for (; aIt.More(); aIt.Next()) {
249   }//for (; myIterator->More(); myIterator->Next()) {
250   //
251   aNbEdgeFace=aVEdgeFace.Extent();
252   //=================================================================
253   BOPAlgo_EdgeFaceCnt::Perform(myRunParallel, aVEdgeFace, myContext);
254   //=================================================================
255   //
256   for (k=0; k < aNbEdgeFace; ++k) {
257     BOPAlgo_EdgeFace& aEdgeFace=aVEdgeFace(k);
258     if (!aEdgeFace.IsDone()) {
259       continue;
260     }
261     //~~~
262     aEdgeFace.Indices(nE, nF);
263     //
264     const TopoDS_Edge& aE=aEdgeFace.Edge();
265     const TopoDS_Face& aF=aEdgeFace.Face();
266     //
267     aTolE=aEdgeFace.TolE();
268     aTolF=aEdgeFace.TolF();
269     const IntTools_Range& anewSR=aEdgeFace.NewSR();
270     Handle(BOPDS_PaveBlock)& aPB=aEdgeFace.PaveBlock();
271     //
272     aPB->Range(aT1, aT2);
273     aPB->Indices(nV[0], nV[1]);
274     //
275     BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
276     const BOPCol_MapOfInteger& aMIFOn=aFI.VerticesOn();
277     const BOPCol_MapOfInteger& aMIFIn=aFI.VerticesIn();
278     //~~~
279     const IntTools_SequenceOfCommonPrts& aCPrts=aEdgeFace.CommonParts();
280     aNbCPrts = aCPrts.Length();
281     //
282     Standard_Boolean bLinePlane = Standard_False;
283     if (aNbCPrts) {
284       BRepAdaptor_Curve aBAC(aE);
285       BRepAdaptor_Surface aBAS(aF, Standard_False);
286       //
287       bLinePlane = (aBAC.GetType() == GeomAbs_Line &&
288                     aBAS.GetType() == GeomAbs_Plane);
289     }
290
291     for (i=1; i<=aNbCPrts; ++i) {
292       const IntTools_CommonPrt& aCPart=aCPrts(i);
293       aType=aCPart.Type();
294       switch (aType) {
295         case TopAbs_VERTEX:  {
296           Standard_Boolean bIsOnPave[2];
297           Standard_Integer j;
298           Standard_Real aT, aTolToDecide; 
299           TopoDS_Vertex aVnew;
300           //
301           IntTools_Tools::VertexParameter(aCPart, aT);
302           BOPTools_AlgoTools::MakeNewVertex(aE, aT, aF, aVnew);
303           //
304           const IntTools_Range& aR=aCPart.Range1();
305           aTolToDecide=5.e-8;
306           //
307           IntTools_Range aR1(aT1,anewSR.First()),aR2(anewSR.Last(), aT2);
308           //
309           bIsOnPave[0]=IntTools_Tools::IsInRange(aR1, aR, aTolToDecide); 
310           bIsOnPave[1]=IntTools_Tools::IsInRange(aR2, aR, aTolToDecide); 
311           //
312           if ((bIsOnPave[0] && bIsOnPave[1]) || 
313               (bLinePlane && (bIsOnPave[0] || bIsOnPave[1]))) {
314             bV[0]=CheckFacePaves(nV[0], aMIFOn, aMIFIn);
315             bV[1]=CheckFacePaves(nV[1], aMIFOn, aMIFIn);
316             if (bV[0] && bV[1]) {
317               IntTools_CommonPrt aCP = aCPart;
318               aCP.SetType(TopAbs_EDGE);
319               BOPDS_InterfEF& aEF=aEFs.Append1();
320               iX=aEFs.Extent()-1;
321               aEF.SetIndices(nE, nF);
322               aEF.SetCommonPart(aCP);
323               myDS->AddInterf(nE, nF);
324               //
325               aMIEFC.Add(nF);
326               //           
327               BOPAlgo_Tools::FillMap(aPB, nF, aMPBLI, aAllocator);
328               break;
329             }
330           }
331           for (j=0; j<2; ++j) {
332             if (bIsOnPave[j]) {
333               bV[j]=CheckFacePaves(nV[j], aMIFOn, aMIFIn);
334               if (bV[j]) {
335                 const TopoDS_Vertex& aV=
336                   (*(TopoDS_Vertex *)(&myDS->Shape(nV[j])));
337                 //
338                 Standard_Real f, l, aTolVnew, aDistPP, aTolPC, aTolV;
339                 //
340                 const Handle(Geom_Curve)& aCur = BRep_Tool::Curve(aE, f, l);
341                 //
342                 gp_Pnt aP1 = BRep_Tool::Pnt(aV);
343                 gp_Pnt aP2 = aCur->Value(aT);
344                 //
345                 
346                 aDistPP=aP1.Distance(aP2);
347                 
348                 aTolPC=Precision::PConfusion();
349                 aTolV=BRep_Tool::Tolerance(aV);
350                 if (aDistPP > (aTolV+aTolPC)) {
351                   aTolVnew=Max(aTolE, aDistPP);
352                   UpdateVertex(nV[j], aTolVnew);
353               }
354               }
355               else {
356                 bIsOnPave[j] = ForceInterfVF(nV[j], nF);
357               }
358             }
359           }
360           //
361           if (!bIsOnPave[0] && !bIsOnPave[1]) {
362             if (CheckFacePaves(aVnew, aMIFOn)) {
363               continue;
364             }
365             //
366             Standard_Real aTolVnew = BRep_Tool::Tolerance(aVnew);
367             aTolVnew = Max(aTolVnew, Max(aTolE, aTolF));
368             BRep_Builder().UpdateVertex(aVnew, aTolVnew);
369             if (bLinePlane) {
370               // increase tolerance for Line/Plane intersection, but do not update 
371               // the vertex till its intersection with some other shape
372               IntTools_Range aCR = aCPart.Range1();
373               aTolVnew = Max(aTolVnew, (aCR.Last() - aCR.First()) / 2.);
374             }
375             //
376             const gp_Pnt& aPnew = BRep_Tool::Pnt(aVnew);
377             //
378             if (!myContext->IsPointInFace(aPnew, aF, aTolVnew)) {
379               continue;
380             }
381             //
382             aMIEFC.Add(nF);
383             // 1
384             BOPDS_InterfEF& aEF=aEFs.Append1();
385             iX=aEFs.Extent()-1;
386             aEF.SetIndices(nE, nF);
387             aEF.SetCommonPart(aCPart);
388             // 2
389             myDS->AddInterf(nE, nF);
390             // 3
391             BOPDS_CoupleOfPaveBlocks aCPB;
392             //
393             aCPB.SetPaveBlocks(aPB, aPB);
394             aCPB.SetIndexInterf(iX);
395             aCPB.SetTolerance(aTolVnew);
396             aMVCPB.Add(aVnew, aCPB);
397           }
398         }
399           break;
400         case TopAbs_EDGE:  {
401           aMIEFC.Add(nF);
402           //
403           // 1
404           BOPDS_InterfEF& aEF=aEFs.Append1();
405           iX=aEFs.Extent()-1;
406           aEF.SetIndices(nE, nF);
407           //
408           bV[0]=CheckFacePaves(nV[0], aMIFOn, aMIFIn);
409           bV[1]=CheckFacePaves(nV[1], aMIFOn, aMIFIn);
410           if (!bV[0] || !bV[1]) {
411             myDS->AddInterf(nE, nF);
412             break;
413           }
414           aEF.SetCommonPart(aCPart);
415           // 2
416           myDS->AddInterf(nE, nF);
417           // 3
418           BOPAlgo_Tools::FillMap(aPB, nF, aMPBLI, aAllocator);
419           
420         }
421           break; 
422         default:
423           break; 
424       }//switch (aType) {
425     }//for (i=1; i<=aNbCPrts; ++i) {
426   }// for (k=0; k < aNbEdgeEdge; ++k) {
427   // 
428   //=========================================
429   // post treatment
430   //=========================================
431   BOPAlgo_Tools::PerformCommonBlocks(aMPBLI, aAllocator, myDS);
432   PerformVerticesEF(aMVCPB, aAllocator);
433   //
434   // Update FaceInfoIn for all faces having EF common parts
435   BOPCol_MapIteratorOfMapOfInteger aItMI;
436   aItMI.Initialize(aMIEFC);
437   for (; aItMI.More(); aItMI.Next()) {
438     nF=aItMI.Value();
439     myDS->UpdateFaceInfoIn(nF);
440   }
441   // Refine FaceInfoOn to remove all formal pave blocks 
442   // made during EF processing 
443   //myDS->RefineFaceInfoOn();
444   //-----------------------------------------------------scope t
445   aMIEFC.Clear();
446   aMVCPB.Clear();
447   aMPBLI.Clear();
448   ////aAllocator.Nullify();
449 }
450 //=======================================================================
451 //function : PerformVerticesEF
452 //purpose  : 
453 //=======================================================================
454 Standard_Integer BOPAlgo_PaveFiller::PerformVerticesEF
455   (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMVCPB,
456    const Handle(NCollection_BaseAllocator)& theAllocator)
457 {
458   Standard_Integer aNbV, iRet;
459   //
460   iRet=0;
461   aNbV=theMVCPB.Extent();
462   if (!aNbV) {
463     return iRet;
464   }
465   //
466   Standard_Integer nVx, nVSD, iV, iErr, nE, iFlag, iX, i, aNbPBLI;
467   Standard_Real aT, dummy;
468   BOPCol_ListIteratorOfListOfShape aItLS;
469   BOPCol_ListIteratorOfListOfInteger aItLI;
470   BOPDS_PDS aPDS;
471   BOPDS_ShapeInfo aSI;
472   BOPDS_Pave aPave;
473   //
474   BOPCol_ListOfShape aLS(theAllocator);
475   BOPCol_DataMapOfShapeInteger aMVI(100, theAllocator);
476   BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, theAllocator);
477   BOPAlgo_PaveFiller aPF(theAllocator); 
478   BOPCol_DataMapOfShapeReal aMVIniTol;
479   //
480   aSI.SetShapeType(TopAbs_VERTEX);
481   BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
482   //
483   // 1 prepare arguments
484   for (i=1; i<=aNbV; ++i) {
485     const TopoDS_Vertex& aV = TopoDS::Vertex(theMVCPB.FindKey(i));
486     aLS.Append(aV);
487     // if an enlarged tolerance is associated with the vertex then update it 
488     // remembering its initial tolerance
489     Standard_Real aTolEnlarged = theMVCPB.FindFromIndex(i).Tolerance();
490     Standard_Real aIniTol = BRep_Tool::Tolerance(aV);
491     if (aTolEnlarged > aIniTol) {
492       aMVIniTol.Bind(aV, aIniTol);
493       BRep_Builder().UpdateVertex(aV, aTolEnlarged);
494     }
495   }
496   //
497   // 2 Fuse vertices
498   aPF.SetIsPrimary(Standard_False);
499   aPF.SetNonDestructive(myNonDestructive);
500   aPF.SetArguments(aLS);
501   aPF.Perform();
502   iErr=aPF.ErrorStatus();
503   if (iErr) {
504     iRet=1;
505     return iRet;
506   }
507   aPDS=aPF.PDS();
508   //
509   // Recompute common vertex for each SD group containing enlarged vertex;
510   // for that first fill in the map of SD vertex -> its counterparts
511   BOPCol_IndexedDataMapOfShapeListOfShape aImages;
512   aItLS.Initialize(aLS);
513   for (; aItLS.More(); aItLS.Next()) {
514     const TopoDS_Shape& aVx = aItLS.Value();
515     nVx = aPDS->Index(aVx);
516     //
517     const TopoDS_Shape& aV = (aPDS->HasShapeSD(nVx, nVSD) ? aPDS->Shape(nVSD) : aVx);
518     BOPCol_ListOfShape* pLst = aImages.ChangeSeek(aV);
519     if (!pLst) {
520       pLst = &aImages.ChangeFromIndex(aImages.Add(aV, BOPCol_ListOfShape()));
521     }
522     pLst->Append(aVx);
523   }
524   // 3 Add new vertices to theDS; 
525   for (i = 1; i <= aImages.Extent(); i++) {
526     TopoDS_Vertex aV = TopoDS::Vertex(aImages.FindKey(i));
527     const BOPCol_ListOfShape& aLVSD = aImages.FindFromIndex(i);
528     Standard_Boolean isReset = Standard_False;
529     BOPCol_ListIteratorOfListOfShape it(aLVSD);
530     for (; it.More(); it.Next()) {
531       const TopoDS_Vertex& aVx = TopoDS::Vertex(it.Value());
532       const Standard_Real* pTolIni = aMVIniTol.Seek(aVx);
533       if (pTolIni) {
534         // reset enlarged vertex tolerance to the initial value
535         reinterpret_cast<BRep_TVertex*>(aVx.TShape().operator->())->Tolerance(*pTolIni);
536         isReset = Standard_True;
537       }
538     }
539     TopoDS_Vertex aVnew = aV;
540     if (isReset && aLVSD.Extent() > 1) {
541       // make new vertex again
542       BOPTools_AlgoTools::MakeVertex(aLVSD, aVnew);
543     }
544     // index of new vertex in theDS -> iV
545     aSI.SetShape(aVnew);
546     iV = myDS->Append(aSI);
547     //
548     BOPDS_ShapeInfo& aSIDS = myDS->ChangeShapeInfo(iV);
549     Bnd_Box& aBox = aSIDS.ChangeBox();
550     BRepBndLib::Add(aVnew, aBox);
551     aBox.SetGap(aBox.GetGap() + Precision::Confusion());
552     //
553     aMVI.Bind(aV, iV);
554   }
555   //
556   // 4 Map PaveBlock/ListOfVertices to add to this PaveBlock ->aMPBLI
557   aItLS.Initialize(aLS);
558   for (; aItLS.More(); aItLS.Next()) {
559     const TopoDS_Shape& aVx=aItLS.Value();
560     nVx=aPDS->Index(aVx);
561     //
562     const TopoDS_Shape& aV = (aPDS->HasShapeSD(nVx, nVSD) ? aPDS->Shape(nVSD) : aVx);
563     iV = aMVI.Find(aV);
564     //
565     BOPDS_CoupleOfPaveBlocks &aCPB=theMVCPB.ChangeFromKey(aVx);
566     aCPB.SetIndex(iV);
567     // update EF interference
568     iX=aCPB.IndexInterf();
569     BOPDS_InterfEF& aEF=aEFs(iX);
570     aEF.SetIndexNew(iV);
571     // map aMPBLI
572     const Handle(BOPDS_PaveBlock)& aPB=aCPB.PaveBlock1();
573     if (aMPBLI.Contains(aPB)) {
574       BOPCol_ListOfInteger& aLI=aMPBLI.ChangeFromKey(aPB);
575       aLI.Append(iV);
576     }
577     else {
578       BOPCol_ListOfInteger aLI(theAllocator);
579       aLI.Append(iV);
580       aMPBLI.Add(aPB, aLI);
581     }
582   }
583   //
584   // 5 
585   // 5.1  Compute Extra Paves and 
586   // 5.2. Add Extra Paves to the PaveBlocks
587   aNbPBLI=aMPBLI.Extent();
588   for (i=1; i<=aNbPBLI; ++i) {
589     Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
590     const BOPCol_ListOfInteger& aLI=aMPBLI.FindFromIndex(i);
591     nE=aPB->OriginalEdge();
592     const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
593     // 
594     aItLI.Initialize(aLI);
595     for (; aItLI.More(); aItLI.Next()) {
596       nVx=aItLI.Value();
597       const TopoDS_Vertex& aVx=(*(TopoDS_Vertex *)(&myDS->Shape(nVx)));
598       //
599       iFlag=myContext->ComputeVE (aVx, aE, aT, dummy);
600       if (!iFlag) {
601         aPave.SetIndex(nVx);
602         aPave.SetParameter(aT);
603         aPB->AppendExtPave(aPave);
604       }
605     }
606   }
607   // 6  Split PaveBlocks
608   for (i=1; i<=aNbPBLI; ++i) {
609     Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
610     nE=aPB->OriginalEdge();
611     // 3
612     if (!myDS->IsCommonBlock(aPB)) {
613       myDS->UpdatePaveBlock(aPB);
614     }
615     else {
616       const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
617       myDS->UpdateCommonBlock(aCB);
618     }    
619   }//for (; aItMPBLI.More(); aItMPBLI.Next()) {
620   // 
621   return iRet;
622 }
623 //=======================================================================
624 // function: CheckFacePaves
625 // purpose: 
626 //=======================================================================
627 Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves 
628   (const Standard_Integer nVx,
629    const BOPCol_MapOfInteger& aMIFOn,
630    const BOPCol_MapOfInteger& aMIFIn)
631 {
632   Standard_Boolean bRet;
633   Standard_Integer nV;
634   BOPCol_MapIteratorOfMapOfInteger aIt;
635   //
636   bRet=Standard_False;
637   //
638   aIt.Initialize(aMIFOn);
639   for (; aIt.More(); aIt.Next()) {
640     nV=aIt.Value();
641     if (nV==nVx) {
642       bRet=!bRet;
643       return bRet;
644     }
645   }
646   aIt.Initialize(aMIFIn);
647   for (; aIt.More(); aIt.Next()) {
648     nV=aIt.Value();
649     if (nV==nVx) {
650       bRet=!bRet;
651       return bRet;
652     }
653   }
654   //
655   return bRet;
656 }
657 //=======================================================================
658 // function: CheckFacePaves
659 // purpose: 
660 //=======================================================================
661 Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves 
662   (const TopoDS_Vertex& aVnew,
663    const BOPCol_MapOfInteger& aMIF)
664 {
665   Standard_Boolean bRet;
666   Standard_Integer nV, iFlag;
667   BOPCol_MapIteratorOfMapOfInteger aIt;
668   //
669   bRet=Standard_True;
670   //
671   aIt.Initialize(aMIF);
672   for (; aIt.More(); aIt.Next()) {
673     nV=aIt.Value();
674     const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV)));
675     iFlag=BOPTools_AlgoTools::ComputeVV(aVnew, aV);
676     if (!iFlag) {
677       return bRet;
678     }
679   }
680   //
681   return !bRet;
682 }
683 //=======================================================================
684 //function : ForceInterfVF
685 //purpose  : 
686 //=======================================================================
687 Standard_Boolean BOPAlgo_PaveFiller::ForceInterfVF
688   (const Standard_Integer nV, 
689    const Standard_Integer nF)
690 {
691   Standard_Boolean bRet;
692   Standard_Integer iFlag, nVx;
693   Standard_Real U, V, aTolVNew;
694   //
695   bRet = Standard_False;
696   const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV);
697   const TopoDS_Face&   aF = *(TopoDS_Face*)  &myDS->Shape(nF);
698   //
699   iFlag = myContext->ComputeVF(aV, aF, U, V, aTolVNew);
700   if (iFlag == 0 || iFlag == -2) {
701     bRet=!bRet;
702   //
703     BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
704     aVFs.SetIncrement(10);
705     // 1
706     BOPDS_InterfVF& aVF=aVFs.Append1();
707     //
708     aVF.SetIndices(nV, nF);
709     aVF.SetUV(U, V);
710     // 2
711     myDS->AddInterf(nV, nF);
712     //
713     // 3 update vertex V/F if necessary
714     nVx=UpdateVertex(nV, aTolVNew);
715     // 4
716     if (myDS->IsNewShape(nVx)) {
717       aVF.SetIndexNew(nVx);
718     }
719     //
720     BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
721     BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
722     aMVIn.Add(nVx);
723   }
724   return bRet;
725 }