Salome HOME
Internal issue 0022865: Restructurization of Partition packages.
[modules/geom.git] / src / NMTTools_NEW / NMTTools_PaveFiller_7.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 // File:        NMTTools_PaveFiller_7.cxx
23 // Author:      Peter KURNEV
24
25 #include <NMTTools_PaveFiller.hxx>
26
27 #include <Bnd_HArray1OfBox.hxx>
28 #include <Bnd_BoundSortBox.hxx>
29 #include <Bnd_Box.hxx>
30 #include <BRepBndLib.hxx>
31
32 #include <TColStd_MapOfInteger.hxx>
33 #include <TColStd_ListOfInteger.hxx>
34 #include <TColStd_IndexedMapOfInteger.hxx>
35 #include <TColStd_ListIteratorOfListOfInteger.hxx>
36
37 #include <GeomAPI_ProjectPointOnCurve.hxx>
38
39 #include <TopAbs_Orientation.hxx>
40
41 #include <TopoDS.hxx>
42 #include <TopoDS_Edge.hxx>
43 #include <TopoDS_Shape.hxx>
44 #include <TopoDS_Vertex.hxx>
45 #include <TopoDS_Compound.hxx>
46
47 #include <TopTools_DataMapOfIntegerShape.hxx>
48 #include <TopTools_DataMapOfShapeInteger.hxx>
49 #include <TopTools_DataMapOfShapeShape.hxx>
50 #include <TopTools_DataMapOfShapeListOfInteger.hxx>
51 #include <TopTools_DataMapIteratorOfDataMapOfIntegerShape.hxx>
52 #include <TopTools_DataMapIteratorOfDataMapOfShapeInteger.hxx>
53 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfInteger.hxx>
54
55 #include <BRep_Builder.hxx>
56 #include <BRep_Tool.hxx>
57
58 #include <TopExp_Explorer.hxx>
59 #include <TopExp.hxx>
60 //
61 #include <IntTools_SequenceOfPntOn2Faces.hxx>
62 #include <IntTools_PntOnFace.hxx>
63 #include <IntTools_PntOn2Faces.hxx>
64 #include <IntTools_Context.hxx>
65
66 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
67
68 #include <BOPTools_SSInterference.hxx>
69 #include <BOPTools_CArray1OfSSInterference.hxx>
70 #include <BOPTools_CArray1OfVVInterference.hxx>
71 #include <BOPTools_VVInterference.hxx>
72 #include <BOPTools_Tools.hxx>
73 #include <BOPTools_ListOfPaveBlock.hxx>
74 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
75 #include <BOPTools_PaveBlock.hxx>
76 #include <BOPTools_Pave.hxx>
77 #include <BOPTools_Tools.hxx>
78
79 #include <NMTDS_Iterator.hxx>
80 #include <NMTDS_ShapesDataStructure.hxx>
81 #include <NMTDS_InterfPool.hxx>
82
83 #include <NMTTools_ListOfCommonBlock.hxx>
84 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
85 #include <NMTTools_MapOfPaveBlock.hxx>
86
87
88 //=======================================================================
89 // function: MakeSplitEdges
90 // purpose:
91 //=======================================================================
92 void NMTTools_PaveFiller::MakeSplitEdges()
93 {
94   myIsDone=Standard_False;
95   //
96   Standard_Boolean bIsNewVertex1, bIsNewVertex2;
97   Standard_Integer i, aNbS, nV1, nV2, aNbPaveBlocks, aNewShapeIndex;
98   Standard_Real    t1, t2;
99   TopAbs_Orientation anOri;
100   TopoDS_Edge aE, aESplit;
101   TopoDS_Vertex aV1, aV2;
102   //
103   aNbS=myDS->NumberOfShapesOfTheObject();
104   for (i=1; i<=aNbS; ++i) {
105     if (myDS->GetShapeType(i) != TopAbs_EDGE)
106       continue;
107     //
108     // Original Edge
109     aE=TopoDS::Edge(myDS->Shape(i));
110     if (BRep_Tool::Degenerated(aE)){
111       continue;
112     }
113     //
114     anOri=aE.Orientation();
115     aE.Orientation(TopAbs_FORWARD);
116     //
117     // Making Split Edges
118     //
119     // Split Set for the Original Edge i
120     BOPTools_ListOfPaveBlock& aSplitEdges=mySplitShapesPool(myDS->RefEdge(i));
121     BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSplitEdges);
122     //
123     aNbPaveBlocks=aSplitEdges.Extent();
124
125     for (; aPBIt.More(); aPBIt.Next()) {
126       BOPTools_PaveBlock& aPB=aPBIt.Value();
127       // aPave1
128       const BOPTools_Pave& aPave1=aPB.Pave1();
129       nV1=aPave1.Index();
130       t1=aPave1.Param();
131       aV1=TopoDS::Vertex(myDS->GetShape(nV1));
132       aV1.Orientation(TopAbs_FORWARD);
133       // aPave2
134       const BOPTools_Pave& aPave2=aPB.Pave2();
135       nV2=aPave2.Index();
136       t2=aPave2.Param();
137       aV2=TopoDS::Vertex(myDS->GetShape(nV2));
138       aV2.Orientation(TopAbs_REVERSED);
139       //xx
140       if (aNbPaveBlocks==1) {
141         bIsNewVertex1=myDS->IsNewShape (nV1);
142         bIsNewVertex2=myDS->IsNewShape (nV2);
143         if (!bIsNewVertex1 && !bIsNewVertex2) {
144           aPB.SetEdge(i);
145           continue;
146         }
147       }
148       //xx
149       BOPTools_Tools::MakeSplitEdge(aE, aV1, t1, aV2, t2, aESplit);
150       //
151       // Add Split Part of the Original Edge to the DS
152       BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
153
154       anASSeq.SetNewSuccessor(nV1);
155       anASSeq.SetNewOrientation(aV1.Orientation());
156
157       anASSeq.SetNewSuccessor(nV2);
158       anASSeq.SetNewOrientation(aV2.Orientation());
159       //
160       if (anOri==TopAbs_INTERNAL) {
161         anASSeq.SetNewAncestor(i);
162         aESplit.Orientation(anOri);
163       }
164       //
165       myDS->InsertShapeAndAncestorsSuccessors(aESplit, anASSeq);
166       aNewShapeIndex=myDS->NumberOfInsertedShapes();
167       myDS->SetState(aNewShapeIndex, BooleanOperations_UNKNOWN);
168       //
169       // Fill Split Set for the Original Edge
170       aPB.SetEdge(aNewShapeIndex);
171       //
172     }
173   }
174   myIsDone=Standard_True;
175 }
176 //=======================================================================
177 // function: UpdateCommonBlocks
178 // purpose:
179 //=======================================================================
180 void NMTTools_PaveFiller::UpdateCommonBlocks(const Standard_Integer)
181 {
182   Standard_Integer nE, aNbS,  nEx, nEMax, j, aNbPoints, aNbLCB, nF;
183   Standard_Real aTolEx, aTolExMax, aTSRMax[2], aTx[2], aTmp;
184   TColStd_ListIteratorOfListOfInteger aItLI;
185   gp_Pnt aPMax[2];
186   TopoDS_Edge aEMax;
187   BOPTools_ListIteratorOfListOfPaveBlock aItLPB, aItLPBS;
188   NMTTools_ListIteratorOfListOfCommonBlock aItLCB;
189   NMTTools_MapOfPaveBlock aMPB;
190   //
191   myIsDone=Standard_False;
192   //
193   aNbS=myDS->NumberOfShapesOfTheObject();
194   for (nE=1; nE<=aNbS; ++nE) {
195     if (myDS->GetShapeType(nE)!=TopAbs_EDGE){
196       continue;
197     }
198     //
199     const TopoDS_Edge& aE=*((TopoDS_Edge*)&myDS->Shape(nE));
200     if (BRep_Tool::Degenerated(aE)){
201       continue;
202     }
203     //
204     NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nE));
205     //modified by NIZNHY-PKV Thu Jan 19 09:03:19 2012f
206     aNbLCB=aLCB.Extent();
207     if (!aNbLCB) {
208       continue;
209     }
210     // 0
211     NMTTools_ListOfCommonBlock aLCBx;
212     //
213     aItLCB.Initialize(aLCB);
214     for (; aItLCB.More(); aItLCB.Next()) {
215       NMTTools_CommonBlock aCBx;
216       //
217       NMTTools_CommonBlock& aCB=aItLCB.ChangeValue();
218       const BOPTools_ListOfPaveBlock &aLPB=aCB.PaveBlocks();
219       aItLPB.Initialize(aLPB);
220       for (; aItLPB.More(); aItLPB.Next()) {
221         const BOPTools_PaveBlock& aPBx=aItLPB.Value();
222         nEx=aPBx.OriginalEdge();
223         BOPTools_ListOfPaveBlock& aLPBS=mySplitShapesPool(myDS->RefEdge(nEx));
224         aItLPBS.Initialize(aLPBS);
225         for (; aItLPBS.More(); aItLPBS.Next()) {
226           const BOPTools_PaveBlock& aPBSx=aItLPBS.Value();
227           if (aPBSx.IsEqual(aPBx)) {
228             aCBx.AddPaveBlock(aPBSx);
229             break;
230           }
231         }// for (; aItLPBS.More(); aItLPBS.Next()) {
232       }// for (; aItLPB.More(); aItLPB.Next()) {
233       //
234       const TColStd_ListOfInteger& aLI=aCB.Faces();
235       aItLI.Initialize(aLI);
236       for (; aItLI.More(); aItLI.Next()) {
237         nF=aItLI.Value();
238         aCBx.AddFace(nF);
239       }
240       //
241       aLCBx.Append(aCBx);
242     }//for (; aItLCB.More(); aItLCB.Next()) {
243     //
244     aLCB.Clear();
245     //
246     aItLCB.Initialize(aLCBx);
247     for (; aItLCB.More(); aItLCB.Next()) {
248       NMTTools_CommonBlock& aCBx=aItLCB.ChangeValue();
249       aLCB.Append(aCBx);
250     }
251     //modified by NIZNHY-PKV Thu Jan 19 09:03:30 2012t
252     // 1
253     aItLCB.Initialize(aLCB);
254     for (; aItLCB.More(); aItLCB.Next()) {
255       NMTTools_CommonBlock& aCB=aItLCB.ChangeValue();
256       //
257       BOPTools_PaveBlock aPBMax;
258       aTolExMax=-1.;
259       const BOPTools_ListOfPaveBlock &aLPB=aCB.PaveBlocks();
260       aItLPB.Initialize(aLPB);
261       for (; aItLPB.More(); aItLPB.Next()) {
262         const BOPTools_PaveBlock& aPBx=aItLPB.Value();
263         nEx=aPBx.OriginalEdge();
264         const TopoDS_Edge& aEx=*((TopoDS_Edge*)&myDS->Shape(nEx));
265         aTolEx=BRep_Tool::Tolerance(aEx);
266         if (aTolEx>aTolExMax) {
267           aTolExMax=aTolEx;
268           aEMax=aEx;
269           aPBMax=aPBx;
270         }
271       }
272       //
273       // 2
274       if (aMPB.Contains(aPBMax)) {
275         continue;
276       }
277       aMPB.Add(aPBMax);
278       //
279       nEMax=aPBMax.OriginalEdge();
280       const IntTools_ShrunkRange& aISRMax=aPBMax.ShrunkRange();
281       const IntTools_Range& aSRMax=aISRMax.ShrunkRange();
282       const Bnd_Box& aBoxMax=aISRMax.BndBox();
283       aSRMax.Range(aTSRMax[0], aTSRMax[1]);
284       for (j=0; j<2; ++j) {
285         BOPTools_Tools::PointOnEdge(aEMax, aTSRMax[j], aPMax[j]);
286       }
287       //
288       // 3
289       aItLPB.Initialize(aLPB);
290       for (; aItLPB.More(); aItLPB.Next()) {
291         const BOPTools_PaveBlock& aPBx=aItLPB.Value();
292         nEx=aPBx.OriginalEdge();
293         if (nEx==nEMax) {
294           continue;
295         }
296         //
297         const TopoDS_Edge& aEx=*((TopoDS_Edge*)&myDS->Shape(nEx));
298         GeomAPI_ProjectPointOnCurve& aPPCx=myContext->ProjPC(aEx);
299         //
300         for (j=0; j<2; ++j) {
301           aPPCx.Perform(aPMax[j]);
302           aNbPoints=aPPCx.NbPoints();
303           if (!aNbPoints) {
304             break;
305           }
306           aTx[j]=aPPCx.LowerDistanceParameter();
307         }
308         if (!aNbPoints) {
309           // correction the range is impossible due to
310           // a projection problem
311           continue;
312         }
313         //
314         if (aTx[0]>aTx[1]){
315           aTmp=aTx[0];
316           aTx[0]=aTx[1];
317           aTx[1]=aTmp;
318         }
319         //
320         // 4 Correction
321         // 4.1 aPBx
322         {
323           const IntTools_ShrunkRange& aISRx=aPBx.ShrunkRange();
324           IntTools_Range *pSRx=(IntTools_Range *)(&aISRx.ShrunkRange());
325           Bnd_Box *pBoxx=(Bnd_Box *)(&aISRx.BndBox());
326           //
327           pSRx->SetFirst(aTx[0]);
328           pSRx->SetLast(aTx[1]);
329           *pBoxx=aBoxMax;
330         }
331         //
332         // 4.2 aPBSx
333         BOPTools_ListOfPaveBlock& aLPBSx=mySplitShapesPool(myDS->RefEdge(nEx));
334         aItLPBS.Initialize(aLPBSx);
335         for (; aItLPBS.More(); aItLPBS.Next()) {
336           const BOPTools_PaveBlock& aPBSx=aItLPBS.Value();
337           if (!aPBSx.IsEqual(aPBx)) {
338             continue;
339           }
340           //
341           const IntTools_ShrunkRange& aISRx=aPBSx.ShrunkRange();
342           IntTools_Range *pSRx=(IntTools_Range *)(&aISRx.ShrunkRange());
343           Bnd_Box *pBoxx=(Bnd_Box *)(&aISRx.BndBox());
344           //
345           pSRx->SetFirst(aTx[0]);
346           pSRx->SetLast(aTx[1]);
347           *pBoxx=aBoxMax;
348         }
349         //
350         //
351       }//for (; aItLPB.More(); aItLPB.Next()) {
352     }//for (; aItLCB.More(); aItLCB.Next()) {
353   }//for (nE=1; nE<=aNbS; ++nE) {
354 }
355 //=======================================================================
356 // function: UpdateCommonBlocks
357 // purpose:
358 //=======================================================================
359 void NMTTools_PaveFiller::UpdateCommonBlocks()
360 {
361   myIsDone=Standard_False;
362   //
363   Standard_Integer nE, aNbS,  nSp, nEx, nSpx;
364   NMTTools_ListIteratorOfListOfCommonBlock aCBIt;
365   BOPTools_ListIteratorOfListOfPaveBlock aPBIt;
366   //
367   aNbS=myDS->NumberOfShapesOfTheObject();
368   //
369   for (nE=1; nE<=aNbS; ++nE) {
370     if (myDS->GetShapeType(nE)!=TopAbs_EDGE){
371       continue;
372     }
373     if (BRep_Tool::Degenerated(TopoDS::Edge(myDS->Shape(nE)))){
374       continue;
375     }
376     //
377     NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nE));
378     /*BOPTools_ListOfPaveBlock& aLPB=*/mySplitShapesPool  (myDS->RefEdge(nE));
379     //
380     aCBIt.Initialize(aLCB);
381     for (; aCBIt.More(); aCBIt.Next()) {
382       NMTTools_CommonBlock& aCB=aCBIt.ChangeValue();
383       //
384       // Among all PBs of aCB the first PB will be one
385       // that have max tolerance value
386       {
387         Standard_Real aTolEx, aTolExMax;
388         BOPTools_ListOfPaveBlock *pLPB, aLPBx;
389         //
390         aTolExMax=-1.;
391         pLPB=(BOPTools_ListOfPaveBlock *)&aCB.PaveBlocks();
392         aPBIt.Initialize(*pLPB);
393         for (; aPBIt.More(); aPBIt.Next()) {
394           const BOPTools_PaveBlock& aPBx=aPBIt.Value();
395           nEx=aPBx.OriginalEdge();
396           const TopoDS_Edge& aEx=TopoDS::Edge(myDS->Shape(nEx));
397           aTolEx=BRep_Tool::Tolerance(aEx);
398           if (aTolEx>aTolExMax) {
399             aTolExMax=aTolEx;
400             aLPBx.Prepend(aPBx);
401           }
402           else{
403             aLPBx.Append(aPBx);
404           }
405         }
406         //
407         pLPB->Clear();
408         *pLPB=aLPBx;
409       }
410       //
411       BOPTools_PaveBlock& aPB=aCB.PaveBlock1(nE);
412       nSp=SplitIndex(aPB);
413       aPB.SetEdge(nSp);
414       //
415       const BOPTools_ListOfPaveBlock& aCBLPB=aCB.PaveBlocks();
416       aPBIt.Initialize(aCBLPB);
417       for (; aPBIt.More(); aPBIt.Next()) {
418         BOPTools_PaveBlock& aPBx=aPBIt.Value();
419         nEx=aPBx.OriginalEdge();
420         if (nEx==nE) {
421           continue;
422         }
423         //
424         nSpx=SplitIndex(aPBx);
425         aPBx.SetEdge(nSpx);
426       }
427       //
428     }
429   }
430 }
431 //=======================================================================
432 // function: SplitIndex
433 // purpose:
434 //=======================================================================
435 Standard_Integer NMTTools_PaveFiller::SplitIndex
436   (const BOPTools_PaveBlock& aPBx) const
437 {
438   Standard_Integer anOriginalEdge, anEdgeIndex=0;
439
440   anOriginalEdge=aPBx.OriginalEdge();
441
442   const BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(anOriginalEdge));
443   //
444   BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
445   for (; anIt.More(); anIt.Next()) {
446     BOPTools_PaveBlock& aPB=anIt.Value();
447     if (aPB.IsEqual(aPBx)) {
448       anEdgeIndex=aPB.Edge();
449       return anEdgeIndex;
450     }
451   }
452   return anEdgeIndex;
453 }
454
455 //=======================================================================
456 // function: UpdatePaveBlocks
457 // purpose:
458 //=======================================================================
459 void NMTTools_PaveFiller::UpdatePaveBlocks()
460 {
461   myIsDone=Standard_False;
462   //
463   Standard_Integer i, aNbFFs, nF1, nF2, aNbF, nF, iRankF, nE, nV1, nV2, aNbPB;
464   Standard_Real aT1, aT2;
465   TColStd_IndexedMapOfInteger aMF, aME;
466   TopExp_Explorer aExp;
467   TopoDS_Vertex aV1, aV2;
468   TopoDS_Edge aE;
469   BOPTools_Pave aPave1, aPave2;
470   BOPTools_PaveBlock aPB;
471   //
472   BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
473   //
474   aNbFFs=aFFs.Extent();
475   for (i=1; i<=aNbFFs; ++i) {
476     BOPTools_SSInterference& aFFi=aFFs(i);
477     aFFi.Indices(nF1, nF2);
478     aMF.Add(nF1);
479     aMF.Add(nF2);
480   }
481   //
482   aNbF=aMF.Extent();
483   for(i=1; i<=aNbF; ++i) {
484     nF=aMF(i);
485     iRankF=myDS->Rank(nF);
486     const TopoDS_Shape aF=myDS->Shape(nF);//mpv
487     aExp.Init(aF, TopAbs_EDGE);
488     for(; aExp.More();  aExp.Next()) {
489       aE=TopoDS::Edge(aExp.Current());
490       //
491       if (BRep_Tool::Degenerated(aE)) {
492         continue;
493       }
494       //
495       nE=myDS->ShapeIndex(aE, iRankF);
496       //
497       if (aME.Contains(nE)) {
498         continue;
499       }
500       aME.Add(nE);
501       //
502       BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(nE));
503       aNbPB=aLPB.Extent();
504       if (aNbPB) {
505         continue;
506       }
507       TopExp::Vertices(aE, aV1, aV2);
508       //
509       nV1=myDS->ShapeIndex(aV1, iRankF);
510       aT1=BRep_Tool::Parameter(aV1, aE);
511       aPave1.SetIndex(nV1);
512       aPave1.SetParam(aT1);
513       //
514       nV2=myDS->ShapeIndex(aV2, iRankF);
515       aT2=BRep_Tool::Parameter(aV2, aE);
516       aPave2.SetIndex(nV2);
517       aPave2.SetParam(aT2);
518       //
519       aPB.SetEdge(nE);
520       aPB.SetOriginalEdge(nE);
521       aPB.SetPave1(aPave1);
522       aPB.SetPave2(aPave2);
523       //
524       aLPB.Append(aPB);
525     }
526   }
527 }
528
529 //=======================================================================
530 // function: MakeAloneVertices
531 // purpose:
532 //=======================================================================
533 void NMTTools_PaveFiller::MakeAloneVertices()
534 {
535   Standard_Integer i, aNbFFs, nF1, nF2, j, aNbPnts, nFx, aNbV;
536   Standard_Real aTolF1, aTolF2, aTolSum, aTolV;
537   TColStd_ListIteratorOfListOfInteger aIt;
538   TColStd_ListOfInteger aLI;
539   TopoDS_Vertex aV;
540   TopoDS_Compound aCompound;
541   BRep_Builder aBB;
542   TopTools_DataMapOfShapeListOfInteger aDMVFF, aDMVFF1;
543   TopTools_DataMapIteratorOfDataMapOfShapeListOfInteger aItDMVFF;
544   TopTools_DataMapOfShapeShape aDMVV;
545   TopTools_DataMapOfIntegerShape aDMIV;
546   TopTools_DataMapOfShapeInteger aDMVI;
547   TopTools_DataMapIteratorOfDataMapOfShapeInteger aItDMVI;
548   TopTools_DataMapIteratorOfDataMapOfIntegerShape aItDMIV;
549   //
550   aBB.MakeCompound(aCompound);
551   //
552   myAloneVertices.Clear();
553   //
554   BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
555   //
556   // 1. Collect alone vertices from FFs
557   aNbV=0;
558   aNbFFs=aFFs.Extent();
559   for (i=1; i<=aNbFFs; ++i) {
560     BOPTools_SSInterference& aFFi=aFFs(i);
561     aFFi.Indices(nF1, nF2);
562     //
563     const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
564     const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
565     //
566     aTolF1=BRep_Tool::Tolerance(aF1);
567     aTolF2=BRep_Tool::Tolerance(aF2);
568     aTolSum=aTolF1+aTolF2;
569     //
570     aLI.Clear();
571     aLI.Append(nF1);
572     aLI.Append(nF2);
573     //
574     const IntTools_SequenceOfPntOn2Faces& aSeqAlonePnts=aFFi.AlonePnts();
575     aNbPnts=aSeqAlonePnts.Length();
576     for (j=1; j<=aNbPnts; ++j) {
577       const gp_Pnt& aP=aSeqAlonePnts(j).P1().Pnt();
578       BOPTools_Tools::MakeNewVertex(aP, aTolSum, aV);
579       aDMVFF.Bind(aV, aLI);
580       aBB.Add(aCompound, aV);
581       ++aNbV;
582     }
583   }
584   if (!aNbV) {
585     return;
586   }
587   //
588   // 2. Try to fuse alone vertices themselves;
589   FuseVertices(aCompound, aDMVV);
590   //
591   // if some are fused, replace them by new ones
592   aItDMVFF.Initialize(aDMVFF);
593   for (;  aItDMVFF.More(); aItDMVFF.Next()) {
594     const TopoDS_Shape& aVx=aItDMVFF.Key();
595     const TColStd_ListOfInteger& aLIx=aItDMVFF.Value();
596     //
597     if (!aDMVV.IsBound(aVx)) {
598       aDMVFF1.Bind(aVx, aLIx);
599     }
600     else {
601       const TopoDS_Shape& aVy=aDMVV.Find(aVx);
602
603       if (aDMVFF1.IsBound(aVy)) {
604         TColStd_ListOfInteger& aLIy=aDMVFF1.ChangeFind(aVy);
605         aIt.Initialize(aLIx);
606         for(; aIt.More(); aIt.Next()) {
607           nFx=aIt.Value();
608           aLIy.Append(nFx);
609         }
610       }
611       else {
612         aDMVFF1.Bind(aVy, aLIx);
613       }
614     }
615   }
616   aDMVFF.Clear();
617   //
618   // refine lists of faces in aDMVFF1;
619   aItDMVFF.Initialize(aDMVFF1);
620   for (;  aItDMVFF.More(); aItDMVFF.Next()) {
621     TColStd_MapOfInteger aMIy;
622     TColStd_ListOfInteger aLIy;
623     //
624     const TopoDS_Shape& aVx=aItDMVFF.Key();
625     TColStd_ListOfInteger& aLIx=aDMVFF1.ChangeFind(aVx);
626     aIt.Initialize(aLIx);
627     for(; aIt.More(); aIt.Next()) {
628       nFx=aIt.Value();
629       if (aMIy.Add(nFx)) {
630         aLIy.Append(nFx);
631       }
632     }
633     aLIx.Clear();
634     aLIx.Append(aLIy);
635   }
636   //==================================
637   //
638   // 3. Collect vertices from DS
639   Standard_Integer aNbS, nV, nVSD, aNbVDS, i1, i2, aNbVSD;
640   //
641   aNbS=myDS->NumberOfShapesOfTheObject();
642   // old shapes
643   for (i=1; i<=aNbS; ++i) {
644     const TopoDS_Shape& aS=myDS->Shape(i);
645     if (aS.ShapeType() != TopAbs_VERTEX){
646       continue;
647     }
648     //
649     nVSD=FindSDVertex(i);
650     nV=(nVSD) ? nVSD : i;
651     const TopoDS_Shape& aVx=myDS->Shape(nV);
652     if (!aDMVI.IsBound(aVx)) {
653       aDMVI.Bind(aVx, nV);
654     }
655   }
656   // new shapes
657   i1=myDS->NumberOfSourceShapes()+1;
658   i2=myDS->NumberOfInsertedShapes();
659   for (i=i1; i<=i2; ++i) {
660     const TopoDS_Shape aS=myDS->Shape(i);//mpv
661     if (aS.ShapeType() != TopAbs_VERTEX){
662       continue;
663     }
664     if (!aDMVI.IsBound(aS)) {
665       aDMVI.Bind(aS, i);
666     }
667   }
668   //
669   // 4. Initialize BoundSortBox on aDMVI
670   //
671   Handle(Bnd_HArray1OfBox) aHAB;
672   Bnd_BoundSortBox aBSB;
673   //
674   aNbVDS=aDMVI.Extent();
675   aHAB=new Bnd_HArray1OfBox(1, aNbVDS);
676   //
677   aItDMVI.Initialize(aDMVI);
678   for (i=1; aItDMVI.More(); aItDMVI.Next(), ++i) {
679     Bnd_Box aBox;
680     //
681     nV=aItDMVI.Value();
682     aV=TopoDS::Vertex(aItDMVI.Key());
683     aTolV=BRep_Tool::Tolerance(aV);
684     aBox.SetGap(aTolV);
685     BRepBndLib::Add(aV, aBox);
686     aHAB->SetValue(i, aBox);
687     //
688     aDMIV.Bind(i, aV);
689   }
690   aBSB.Initialize(aHAB);
691   //
692   // 5. Compare
693   aItDMVFF.Initialize(aDMVFF1);
694   for (;  aItDMVFF.More(); aItDMVFF.Next()) {
695     Bnd_Box aBoxV;
696     //
697     const TColStd_ListOfInteger& aLIFF=aItDMVFF.Value();
698     aV=TopoDS::Vertex(aItDMVFF.Key());
699     //
700     aTolV=BRep_Tool::Tolerance(aV);
701     aBoxV.SetGap(aTolV);
702     BRepBndLib::Add(aV, aBoxV);
703     //
704     const TColStd_ListOfInteger& aLIVSD=aBSB.Compare(aBoxV);
705     aNbVSD=aLIVSD.Extent();
706     if (aNbVSD==0) {
707       // add new vertex in DS and update map myAloneVertices
708       BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
709       //
710       myDS->InsertShapeAndAncestorsSuccessors(aV, anASSeq);
711       nV=myDS->NumberOfInsertedShapes();
712       //
713       aIt.Initialize(aLIFF);
714       for (; aIt.More(); aIt.Next()) {
715         nFx=aIt.Value();
716         if (myAloneVertices.Contains(nFx)) {
717           TColStd_IndexedMapOfInteger& aMVx=myAloneVertices.ChangeFromKey(nFx);
718           aMVx.Add(nV);
719         }
720         else {
721           TColStd_IndexedMapOfInteger aMVx;
722           aMVx.Add(nV);
723           myAloneVertices.Add(nFx, aMVx);
724         }
725       }
726     }
727   }
728   // qqf
729   {
730     Standard_Integer aNbF, aNbAV, nF, k;
731     NMTTools_IndexedDataMapOfIndexedMapOfInteger aMAVF;
732     //
733     aNbF=myAloneVertices.Extent();
734     if (aNbF<2) {
735       return;
736     }
737     //
738     // 1. fill map Alone Vertex/Face ->  aMAVF
739     for (i=1; i<=aNbF; ++i) {
740       nF=myAloneVertices.FindKey(i);
741       const TColStd_IndexedMapOfInteger& aMAV=myAloneVertices(i);
742       aNbAV=aMAV.Extent();
743       for(j=1; j<=aNbAV; ++j) {
744         nV=aMAV(j);
745         if (aMAVF.Contains(nV)) {
746           TColStd_IndexedMapOfInteger& aMF=aMAVF.ChangeFromKey(nV);
747           aMF.Add(nF);
748         }
749         else{
750           TColStd_IndexedMapOfInteger aMF;
751           aMF.Add(nF);
752           aMAVF.Add(nV, aMF);
753         }
754       }
755     }
756     //
757     // 2 Obtain pairs of faces
758     aNbAV=aMAVF.Extent();
759     for (i=1; i<=aNbAV; ++i) {
760       const TColStd_IndexedMapOfInteger& aMF=aMAVF(i);
761       aNbF=aMF.Extent();
762       for(j=1; j<aNbF; ++j) {
763         nF1=aMF(j);
764         for(k=j+1; k<=aNbF; ++k) {
765           nF2=aMF(k);
766           myIP->Add(nF1, nF2, Standard_True, NMTDS_TI_FF);
767         }
768       }
769     }
770   }
771   // qqt
772 }
773 //=======================================================================
774 // function: AloneVertices
775 // purpose:
776 //=======================================================================
777 const NMTTools_IndexedDataMapOfIndexedMapOfInteger&
778   NMTTools_PaveFiller::AloneVertices()const
779 {
780   return myAloneVertices;
781 }
782 //=======================================================================
783 // function: FuseVertices
784 // purpose:
785 //=======================================================================
786 void NMTTools_PaveFiller::FuseVertices
787   (const TopoDS_Shape& aCompound,
788    TopTools_DataMapOfShapeShape& aDMVV)const
789 {
790   Standard_Integer i, aNbVV, n1, n2, nX;
791   NMTTools_PaveFiller tPF;
792   //
793   tPF.SetCompositeShape(aCompound);
794   //
795   tPF.Init();
796   //
797   tPF.PerformVV();
798   //tPF.PerformNewVertices(); //qq
799   //
800   NMTDS_ShapesDataStructure& tDS=*(tPF.DS());
801   NMTDS_InterfPool& tInterfPool=*(tPF.IP());
802   BOPTools_CArray1OfVVInterference& aVVt=tInterfPool.VVInterferences();
803   //
804   aNbVV=aVVt.Extent();
805   for (i=1; i<=aNbVV; ++i) {
806     const BOPTools_VVInterference& aVV=aVVt(i);
807     aVV.Indices(n1, n2);
808     nX=aVV.NewShape();
809     if (nX) {
810       const TopoDS_Shape& aV1=tDS.Shape(n1);
811       const TopoDS_Shape& aV2=tDS.Shape(n2);
812       const TopoDS_Shape& aVx=tDS.Shape(nX);
813       aDMVV.Bind(aV1, aVx);
814       aDMVV.Bind(aV2, aVx);
815     }
816   }
817 }