Back to index

salome-geom  6.5.0
NMTTools_PaveFiller_7.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File:        NMTTools_PaveFiller_7.cxx
00024 // Author:      Peter KURNEV
00025 
00026 #include <NMTTools_PaveFiller.hxx>
00027 
00028 #include <Bnd_HArray1OfBox.hxx>
00029 #include <Bnd_BoundSortBox.hxx>
00030 #include <Bnd_Box.hxx>
00031 #include <BRepBndLib.hxx>
00032 
00033 #include <TColStd_MapOfInteger.hxx>
00034 #include <TColStd_ListOfInteger.hxx>
00035 #include <TColStd_IndexedMapOfInteger.hxx>
00036 #include <TColStd_ListIteratorOfListOfInteger.hxx>
00037 
00038 #include <GeomAPI_ProjectPointOnCurve.hxx>
00039 
00040 #include <TopAbs_Orientation.hxx>
00041 
00042 #include <TopoDS.hxx>
00043 #include <TopoDS_Edge.hxx>
00044 #include <TopoDS_Shape.hxx>
00045 #include <TopoDS_Vertex.hxx>
00046 #include <TopoDS_Compound.hxx>
00047 
00048 #include <TopTools_DataMapOfIntegerShape.hxx>
00049 #include <TopTools_DataMapOfShapeInteger.hxx>
00050 #include <TopTools_DataMapOfShapeShape.hxx>
00051 #include <TopTools_DataMapOfShapeListOfInteger.hxx>
00052 #include <TopTools_DataMapIteratorOfDataMapOfIntegerShape.hxx>
00053 #include <TopTools_DataMapIteratorOfDataMapOfShapeInteger.hxx>
00054 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfInteger.hxx>
00055 
00056 #include <BRep_Builder.hxx>
00057 #include <BRep_Tool.hxx>
00058 
00059 #include <TopExp_Explorer.hxx>
00060 #include <TopExp.hxx>
00061 //
00062 #include <IntTools_SequenceOfPntOn2Faces.hxx>
00063 #include <IntTools_PntOnFace.hxx>
00064 #include <IntTools_PntOn2Faces.hxx>
00065 #include <IntTools_Context.hxx>
00066 
00067 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
00068 
00069 #include <BOPTools_SSInterference.hxx>
00070 #include <BOPTools_CArray1OfSSInterference.hxx>
00071 #include <BOPTools_CArray1OfVVInterference.hxx>
00072 #include <BOPTools_VVInterference.hxx>
00073 #include <BOPTools_Tools.hxx>
00074 #include <BOPTools_ListOfPaveBlock.hxx>
00075 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
00076 #include <BOPTools_PaveBlock.hxx>
00077 #include <BOPTools_Pave.hxx>
00078 #include <BOPTools_Tools.hxx>
00079 
00080 #include <NMTDS_Iterator.hxx>
00081 #include <NMTDS_ShapesDataStructure.hxx>
00082 #include <NMTDS_InterfPool.hxx>
00083 
00084 #include <NMTTools_ListOfCommonBlock.hxx>
00085 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
00086 #include <NMTTools_MapOfPaveBlock.hxx>
00087 
00088 
00089 //=======================================================================
00090 // function: MakeSplitEdges
00091 // purpose:
00092 //=======================================================================
00093 void NMTTools_PaveFiller::MakeSplitEdges()
00094 {
00095   myIsDone=Standard_False;
00096   //
00097   Standard_Boolean bIsNewVertex1, bIsNewVertex2;
00098   Standard_Integer i, aNbS, nV1, nV2, aNbPaveBlocks, aNewShapeIndex;
00099   Standard_Real    t1, t2;
00100   TopAbs_Orientation anOri;
00101   TopoDS_Edge aE, aESplit;
00102   TopoDS_Vertex aV1, aV2;
00103   //
00104   aNbS=myDS->NumberOfShapesOfTheObject();
00105   for (i=1; i<=aNbS; ++i) {
00106     if (myDS->GetShapeType(i) != TopAbs_EDGE)
00107       continue;
00108     //
00109     // Original Edge
00110     aE=TopoDS::Edge(myDS->Shape(i));
00111     if (BRep_Tool::Degenerated(aE)){
00112       continue;
00113     }
00114     //
00115     anOri=aE.Orientation();
00116     aE.Orientation(TopAbs_FORWARD);
00117     //
00118     // Making Split Edges
00119     //
00120     // Split Set for the Original Edge i
00121     BOPTools_ListOfPaveBlock& aSplitEdges=mySplitShapesPool(myDS->RefEdge(i));
00122     BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSplitEdges);
00123     //
00124     aNbPaveBlocks=aSplitEdges.Extent();
00125 
00126     for (; aPBIt.More(); aPBIt.Next()) {
00127       BOPTools_PaveBlock& aPB=aPBIt.Value();
00128       // aPave1
00129       const BOPTools_Pave& aPave1=aPB.Pave1();
00130       nV1=aPave1.Index();
00131       t1=aPave1.Param();
00132       aV1=TopoDS::Vertex(myDS->GetShape(nV1));
00133       aV1.Orientation(TopAbs_FORWARD);
00134       // aPave2
00135       const BOPTools_Pave& aPave2=aPB.Pave2();
00136       nV2=aPave2.Index();
00137       t2=aPave2.Param();
00138       aV2=TopoDS::Vertex(myDS->GetShape(nV2));
00139       aV2.Orientation(TopAbs_REVERSED);
00140       //xx
00141       if (aNbPaveBlocks==1) {
00142         bIsNewVertex1=myDS->IsNewShape (nV1);
00143         bIsNewVertex2=myDS->IsNewShape (nV2);
00144         if (!bIsNewVertex1 && !bIsNewVertex2) {
00145           aPB.SetEdge(i);
00146           continue;
00147         }
00148       }
00149       //xx
00150       BOPTools_Tools::MakeSplitEdge(aE, aV1, t1, aV2, t2, aESplit);
00151       //
00152       // Add Split Part of the Original Edge to the DS
00153       BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
00154 
00155       anASSeq.SetNewSuccessor(nV1);
00156       anASSeq.SetNewOrientation(aV1.Orientation());
00157 
00158       anASSeq.SetNewSuccessor(nV2);
00159       anASSeq.SetNewOrientation(aV2.Orientation());
00160       //
00161       if (anOri==TopAbs_INTERNAL) {
00162         anASSeq.SetNewAncestor(i);
00163         aESplit.Orientation(anOri);
00164       }
00165       //
00166       myDS->InsertShapeAndAncestorsSuccessors(aESplit, anASSeq);
00167       aNewShapeIndex=myDS->NumberOfInsertedShapes();
00168       myDS->SetState(aNewShapeIndex, BooleanOperations_UNKNOWN);
00169       //
00170       // Fill Split Set for the Original Edge
00171       aPB.SetEdge(aNewShapeIndex);
00172       //
00173     }
00174   }
00175   myIsDone=Standard_True;
00176 }
00177 //=======================================================================
00178 // function: UpdateCommonBlocks
00179 // purpose:
00180 //=======================================================================
00181 void NMTTools_PaveFiller::UpdateCommonBlocks(const Standard_Integer)
00182 {
00183   Standard_Integer nE, aNbS,  nEx, nEMax, j, aNbPoints, aNbLCB, nF;
00184   Standard_Real aTolEx, aTolExMax, aTSRMax[2], aTx[2], aTmp;
00185   TColStd_ListIteratorOfListOfInteger aItLI;
00186   gp_Pnt aPMax[2];
00187   TopoDS_Edge aEMax;
00188   BOPTools_ListIteratorOfListOfPaveBlock aItLPB, aItLPBS;
00189   NMTTools_ListIteratorOfListOfCommonBlock aItLCB;
00190   NMTTools_MapOfPaveBlock aMPB;
00191   //
00192   myIsDone=Standard_False;
00193   //
00194   aNbS=myDS->NumberOfShapesOfTheObject();
00195   for (nE=1; nE<=aNbS; ++nE) {
00196     if (myDS->GetShapeType(nE)!=TopAbs_EDGE){
00197       continue;
00198     }
00199     //
00200     const TopoDS_Edge& aE=*((TopoDS_Edge*)&myDS->Shape(nE));
00201     if (BRep_Tool::Degenerated(aE)){
00202       continue;
00203     }
00204     //
00205     NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nE));
00206     //modified by NIZNHY-PKV Thu Jan 19 09:03:19 2012f
00207     aNbLCB=aLCB.Extent();
00208     if (!aNbLCB) {
00209       continue;
00210     }
00211     // 0
00212     NMTTools_ListOfCommonBlock aLCBx;
00213     //
00214     aItLCB.Initialize(aLCB);
00215     for (; aItLCB.More(); aItLCB.Next()) {
00216       NMTTools_CommonBlock aCBx;
00217       //
00218       NMTTools_CommonBlock& aCB=aItLCB.ChangeValue();
00219       const BOPTools_ListOfPaveBlock &aLPB=aCB.PaveBlocks();
00220       aItLPB.Initialize(aLPB);
00221       for (; aItLPB.More(); aItLPB.Next()) {
00222         const BOPTools_PaveBlock& aPBx=aItLPB.Value();
00223         nEx=aPBx.OriginalEdge();
00224         BOPTools_ListOfPaveBlock& aLPBS=mySplitShapesPool(myDS->RefEdge(nEx));
00225         aItLPBS.Initialize(aLPBS);
00226         for (; aItLPBS.More(); aItLPBS.Next()) {
00227           const BOPTools_PaveBlock& aPBSx=aItLPBS.Value();
00228           if (aPBSx.IsEqual(aPBx)) {
00229             aCBx.AddPaveBlock(aPBSx);
00230             break;
00231           }
00232         }// for (; aItLPBS.More(); aItLPBS.Next()) {
00233       }// for (; aItLPB.More(); aItLPB.Next()) {
00234       //
00235       const TColStd_ListOfInteger& aLI=aCB.Faces();
00236       aItLI.Initialize(aLI);
00237       for (; aItLI.More(); aItLI.Next()) {
00238         nF=aItLI.Value();
00239         aCBx.AddFace(nF);
00240       }
00241       //
00242       aLCBx.Append(aCBx);
00243     }//for (; aItLCB.More(); aItLCB.Next()) {
00244     //
00245     aLCB.Clear();
00246     //
00247     aItLCB.Initialize(aLCBx);
00248     for (; aItLCB.More(); aItLCB.Next()) {
00249       NMTTools_CommonBlock& aCBx=aItLCB.ChangeValue();
00250       aLCB.Append(aCBx);
00251     }
00252     //modified by NIZNHY-PKV Thu Jan 19 09:03:30 2012t
00253     // 1
00254     aItLCB.Initialize(aLCB);
00255     for (; aItLCB.More(); aItLCB.Next()) {
00256       NMTTools_CommonBlock& aCB=aItLCB.ChangeValue();
00257       //
00258       BOPTools_PaveBlock aPBMax;
00259       aTolExMax=-1.;
00260       const BOPTools_ListOfPaveBlock &aLPB=aCB.PaveBlocks();
00261       aItLPB.Initialize(aLPB);
00262       for (; aItLPB.More(); aItLPB.Next()) {
00263         const BOPTools_PaveBlock& aPBx=aItLPB.Value();
00264         nEx=aPBx.OriginalEdge();
00265         const TopoDS_Edge& aEx=*((TopoDS_Edge*)&myDS->Shape(nEx));
00266         aTolEx=BRep_Tool::Tolerance(aEx);
00267         if (aTolEx>aTolExMax) {
00268           aTolExMax=aTolEx;
00269           aEMax=aEx;
00270           aPBMax=aPBx;
00271         }
00272       }
00273       //
00274       // 2
00275       if (aMPB.Contains(aPBMax)) {
00276         continue;
00277       }
00278       aMPB.Add(aPBMax);
00279       //
00280       nEMax=aPBMax.OriginalEdge();
00281       const IntTools_ShrunkRange& aISRMax=aPBMax.ShrunkRange();
00282       const IntTools_Range& aSRMax=aISRMax.ShrunkRange();
00283       const Bnd_Box& aBoxMax=aISRMax.BndBox();
00284       aSRMax.Range(aTSRMax[0], aTSRMax[1]);
00285       for (j=0; j<2; ++j) {
00286         BOPTools_Tools::PointOnEdge(aEMax, aTSRMax[j], aPMax[j]);
00287       }
00288       //
00289       // 3
00290       aItLPB.Initialize(aLPB);
00291       for (; aItLPB.More(); aItLPB.Next()) {
00292         const BOPTools_PaveBlock& aPBx=aItLPB.Value();
00293         nEx=aPBx.OriginalEdge();
00294         if (nEx==nEMax) {
00295           continue;
00296         }
00297         //
00298         const TopoDS_Edge& aEx=*((TopoDS_Edge*)&myDS->Shape(nEx));
00299         GeomAPI_ProjectPointOnCurve& aPPCx=myContext->ProjPC(aEx);
00300         //
00301         for (j=0; j<2; ++j) {
00302           aPPCx.Perform(aPMax[j]);
00303           aNbPoints=aPPCx.NbPoints();
00304           if (!aNbPoints) {
00305             break;
00306           }
00307           aTx[j]=aPPCx.LowerDistanceParameter();
00308         }
00309         if (!aNbPoints) {
00310           // correction the range is impossible due to
00311           // a projection problem
00312           continue;
00313         }
00314         //
00315         if (aTx[0]>aTx[1]){
00316           aTmp=aTx[0];
00317           aTx[0]=aTx[1];
00318           aTx[1]=aTmp;
00319         }
00320         //
00321         // 4 Correction
00322         // 4.1 aPBx
00323         {
00324           const IntTools_ShrunkRange& aISRx=aPBx.ShrunkRange();
00325           IntTools_Range *pSRx=(IntTools_Range *)(&aISRx.ShrunkRange());
00326           Bnd_Box *pBoxx=(Bnd_Box *)(&aISRx.BndBox());
00327           //
00328           pSRx->SetFirst(aTx[0]);
00329           pSRx->SetLast(aTx[1]);
00330           *pBoxx=aBoxMax;
00331         }
00332         //
00333         // 4.2 aPBSx
00334         BOPTools_ListOfPaveBlock& aLPBSx=mySplitShapesPool(myDS->RefEdge(nEx));
00335         aItLPBS.Initialize(aLPBSx);
00336         for (; aItLPBS.More(); aItLPBS.Next()) {
00337           const BOPTools_PaveBlock& aPBSx=aItLPBS.Value();
00338           if (!aPBSx.IsEqual(aPBx)) {
00339             continue;
00340           }
00341           //
00342           const IntTools_ShrunkRange& aISRx=aPBSx.ShrunkRange();
00343           IntTools_Range *pSRx=(IntTools_Range *)(&aISRx.ShrunkRange());
00344           Bnd_Box *pBoxx=(Bnd_Box *)(&aISRx.BndBox());
00345           //
00346           pSRx->SetFirst(aTx[0]);
00347           pSRx->SetLast(aTx[1]);
00348           *pBoxx=aBoxMax;
00349         }
00350         //
00351         //
00352       }//for (; aItLPB.More(); aItLPB.Next()) {
00353     }//for (; aItLCB.More(); aItLCB.Next()) {
00354   }//for (nE=1; nE<=aNbS; ++nE) {
00355 }
00356 //=======================================================================
00357 // function: UpdateCommonBlocks
00358 // purpose:
00359 //=======================================================================
00360 void NMTTools_PaveFiller::UpdateCommonBlocks()
00361 {
00362   myIsDone=Standard_False;
00363   //
00364   Standard_Integer nE, aNbS,  nSp, nEx, nSpx;
00365   NMTTools_ListIteratorOfListOfCommonBlock aCBIt;
00366   BOPTools_ListIteratorOfListOfPaveBlock aPBIt;
00367   //
00368   aNbS=myDS->NumberOfShapesOfTheObject();
00369   //
00370   for (nE=1; nE<=aNbS; ++nE) {
00371     if (myDS->GetShapeType(nE)!=TopAbs_EDGE){
00372       continue;
00373     }
00374     if (BRep_Tool::Degenerated(TopoDS::Edge(myDS->Shape(nE)))){
00375       continue;
00376     }
00377     //
00378     NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nE));
00379     /*BOPTools_ListOfPaveBlock& aLPB=*/mySplitShapesPool  (myDS->RefEdge(nE));
00380     //
00381     aCBIt.Initialize(aLCB);
00382     for (; aCBIt.More(); aCBIt.Next()) {
00383       NMTTools_CommonBlock& aCB=aCBIt.ChangeValue();
00384       //
00385       // Among all PBs of aCB the first PB will be one
00386       // that have max tolerance value
00387       {
00388         Standard_Real aTolEx, aTolExMax;
00389         BOPTools_ListOfPaveBlock *pLPB, aLPBx;
00390         //
00391         aTolExMax=-1.;
00392         pLPB=(BOPTools_ListOfPaveBlock *)&aCB.PaveBlocks();
00393         aPBIt.Initialize(*pLPB);
00394         for (; aPBIt.More(); aPBIt.Next()) {
00395           const BOPTools_PaveBlock& aPBx=aPBIt.Value();
00396           nEx=aPBx.OriginalEdge();
00397           const TopoDS_Edge& aEx=TopoDS::Edge(myDS->Shape(nEx));
00398           aTolEx=BRep_Tool::Tolerance(aEx);
00399           if (aTolEx>aTolExMax) {
00400             aTolExMax=aTolEx;
00401             aLPBx.Prepend(aPBx);
00402           }
00403           else{
00404             aLPBx.Append(aPBx);
00405           }
00406         }
00407         //
00408         pLPB->Clear();
00409         *pLPB=aLPBx;
00410       }
00411       //
00412       BOPTools_PaveBlock& aPB=aCB.PaveBlock1(nE);
00413       nSp=SplitIndex(aPB);
00414       aPB.SetEdge(nSp);
00415       //
00416       const BOPTools_ListOfPaveBlock& aCBLPB=aCB.PaveBlocks();
00417       aPBIt.Initialize(aCBLPB);
00418       for (; aPBIt.More(); aPBIt.Next()) {
00419         BOPTools_PaveBlock& aPBx=aPBIt.Value();
00420         nEx=aPBx.OriginalEdge();
00421         if (nEx==nE) {
00422           continue;
00423         }
00424         //
00425         nSpx=SplitIndex(aPBx);
00426         aPBx.SetEdge(nSpx);
00427       }
00428       //
00429     }
00430   }
00431 }
00432 //=======================================================================
00433 // function: SplitIndex
00434 // purpose:
00435 //=======================================================================
00436 Standard_Integer NMTTools_PaveFiller::SplitIndex
00437   (const BOPTools_PaveBlock& aPBx) const
00438 {
00439   Standard_Integer anOriginalEdge, anEdgeIndex=0;
00440 
00441   anOriginalEdge=aPBx.OriginalEdge();
00442 
00443   const BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(anOriginalEdge));
00444   //
00445   BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
00446   for (; anIt.More(); anIt.Next()) {
00447     BOPTools_PaveBlock& aPB=anIt.Value();
00448     if (aPB.IsEqual(aPBx)) {
00449       anEdgeIndex=aPB.Edge();
00450       return anEdgeIndex;
00451     }
00452   }
00453   return anEdgeIndex;
00454 }
00455 
00456 //=======================================================================
00457 // function: UpdatePaveBlocks
00458 // purpose:
00459 //=======================================================================
00460 void NMTTools_PaveFiller::UpdatePaveBlocks()
00461 {
00462   myIsDone=Standard_False;
00463   //
00464   Standard_Integer i, aNbFFs, nF1, nF2, aNbF, nF, iRankF, nE, nV1, nV2, aNbPB;
00465   Standard_Real aT1, aT2;
00466   TColStd_IndexedMapOfInteger aMF, aME;
00467   TopExp_Explorer aExp;
00468   TopoDS_Vertex aV1, aV2;
00469   TopoDS_Edge aE;
00470   BOPTools_Pave aPave1, aPave2;
00471   BOPTools_PaveBlock aPB;
00472   //
00473   BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
00474   //
00475   aNbFFs=aFFs.Extent();
00476   for (i=1; i<=aNbFFs; ++i) {
00477     BOPTools_SSInterference& aFFi=aFFs(i);
00478     aFFi.Indices(nF1, nF2);
00479     aMF.Add(nF1);
00480     aMF.Add(nF2);
00481   }
00482   //
00483   aNbF=aMF.Extent();
00484   for(i=1; i<=aNbF; ++i) {
00485     nF=aMF(i);
00486     iRankF=myDS->Rank(nF);
00487     const TopoDS_Shape aF=myDS->Shape(nF);//mpv
00488     aExp.Init(aF, TopAbs_EDGE);
00489     for(; aExp.More();  aExp.Next()) {
00490       aE=TopoDS::Edge(aExp.Current());
00491       //
00492       if (BRep_Tool::Degenerated(aE)) {
00493         continue;
00494       }
00495       //
00496       nE=myDS->ShapeIndex(aE, iRankF);
00497       //
00498       if (aME.Contains(nE)) {
00499         continue;
00500       }
00501       aME.Add(nE);
00502       //
00503       BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(nE));
00504       aNbPB=aLPB.Extent();
00505       if (aNbPB) {
00506         continue;
00507       }
00508       TopExp::Vertices(aE, aV1, aV2);
00509       //
00510       nV1=myDS->ShapeIndex(aV1, iRankF);
00511       aT1=BRep_Tool::Parameter(aV1, aE);
00512       aPave1.SetIndex(nV1);
00513       aPave1.SetParam(aT1);
00514       //
00515       nV2=myDS->ShapeIndex(aV2, iRankF);
00516       aT2=BRep_Tool::Parameter(aV2, aE);
00517       aPave2.SetIndex(nV2);
00518       aPave2.SetParam(aT2);
00519       //
00520       aPB.SetEdge(nE);
00521       aPB.SetOriginalEdge(nE);
00522       aPB.SetPave1(aPave1);
00523       aPB.SetPave2(aPave2);
00524       //
00525       aLPB.Append(aPB);
00526     }
00527   }
00528 }
00529 
00530 //=======================================================================
00531 // function: MakeAloneVertices
00532 // purpose:
00533 //=======================================================================
00534 void NMTTools_PaveFiller::MakeAloneVertices()
00535 {
00536   Standard_Integer i, aNbFFs, nF1, nF2, j, aNbPnts, nFx, aNbV;
00537   Standard_Real aTolF1, aTolF2, aTolSum, aTolV;
00538   TColStd_ListIteratorOfListOfInteger aIt;
00539   TColStd_ListOfInteger aLI;
00540   TopoDS_Vertex aV;
00541   TopoDS_Compound aCompound;
00542   BRep_Builder aBB;
00543   TopTools_DataMapOfShapeListOfInteger aDMVFF, aDMVFF1;
00544   TopTools_DataMapIteratorOfDataMapOfShapeListOfInteger aItDMVFF;
00545   TopTools_DataMapOfShapeShape aDMVV;
00546   TopTools_DataMapOfIntegerShape aDMIV;
00547   TopTools_DataMapOfShapeInteger aDMVI;
00548   TopTools_DataMapIteratorOfDataMapOfShapeInteger aItDMVI;
00549   TopTools_DataMapIteratorOfDataMapOfIntegerShape aItDMIV;
00550   //
00551   aBB.MakeCompound(aCompound);
00552   //
00553   myAloneVertices.Clear();
00554   //
00555   BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
00556   //
00557   // 1. Collect alone vertices from FFs
00558   aNbV=0;
00559   aNbFFs=aFFs.Extent();
00560   for (i=1; i<=aNbFFs; ++i) {
00561     BOPTools_SSInterference& aFFi=aFFs(i);
00562     aFFi.Indices(nF1, nF2);
00563     //
00564     const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
00565     const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
00566     //
00567     aTolF1=BRep_Tool::Tolerance(aF1);
00568     aTolF2=BRep_Tool::Tolerance(aF2);
00569     aTolSum=aTolF1+aTolF2;
00570     //
00571     aLI.Clear();
00572     aLI.Append(nF1);
00573     aLI.Append(nF2);
00574     //
00575     const IntTools_SequenceOfPntOn2Faces& aSeqAlonePnts=aFFi.AlonePnts();
00576     aNbPnts=aSeqAlonePnts.Length();
00577     for (j=1; j<=aNbPnts; ++j) {
00578       const gp_Pnt& aP=aSeqAlonePnts(j).P1().Pnt();
00579       BOPTools_Tools::MakeNewVertex(aP, aTolSum, aV);
00580       aDMVFF.Bind(aV, aLI);
00581       aBB.Add(aCompound, aV);
00582       ++aNbV;
00583     }
00584   }
00585   if (!aNbV) {
00586     return;
00587   }
00588   //
00589   // 2. Try to fuse alone vertices themselves;
00590   FuseVertices(aCompound, aDMVV);
00591   //
00592   // if some are fused, replace them by new ones
00593   aItDMVFF.Initialize(aDMVFF);
00594   for (;  aItDMVFF.More(); aItDMVFF.Next()) {
00595     const TopoDS_Shape& aVx=aItDMVFF.Key();
00596     const TColStd_ListOfInteger& aLIx=aItDMVFF.Value();
00597     //
00598     if (!aDMVV.IsBound(aVx)) {
00599       aDMVFF1.Bind(aVx, aLIx);
00600     }
00601     else {
00602       const TopoDS_Shape& aVy=aDMVV.Find(aVx);
00603 
00604       if (aDMVFF1.IsBound(aVy)) {
00605         TColStd_ListOfInteger& aLIy=aDMVFF1.ChangeFind(aVy);
00606         aIt.Initialize(aLIx);
00607         for(; aIt.More(); aIt.Next()) {
00608           nFx=aIt.Value();
00609           aLIy.Append(nFx);
00610         }
00611       }
00612       else {
00613         aDMVFF1.Bind(aVy, aLIx);
00614       }
00615     }
00616   }
00617   aDMVFF.Clear();
00618   //
00619   // refine lists of faces in aDMVFF1;
00620   aItDMVFF.Initialize(aDMVFF1);
00621   for (;  aItDMVFF.More(); aItDMVFF.Next()) {
00622     TColStd_MapOfInteger aMIy;
00623     TColStd_ListOfInteger aLIy;
00624     //
00625     const TopoDS_Shape& aVx=aItDMVFF.Key();
00626     TColStd_ListOfInteger& aLIx=aDMVFF1.ChangeFind(aVx);
00627     aIt.Initialize(aLIx);
00628     for(; aIt.More(); aIt.Next()) {
00629       nFx=aIt.Value();
00630       if (aMIy.Add(nFx)) {
00631         aLIy.Append(nFx);
00632       }
00633     }
00634     aLIx.Clear();
00635     aLIx.Append(aLIy);
00636   }
00637   //==================================
00638   //
00639   // 3. Collect vertices from DS
00640   Standard_Integer aNbS, nV, nVSD, aNbVDS, i1, i2, aNbVSD;
00641   //
00642   aNbS=myDS->NumberOfShapesOfTheObject();
00643   // old shapes
00644   for (i=1; i<=aNbS; ++i) {
00645     const TopoDS_Shape& aS=myDS->Shape(i);
00646     if (aS.ShapeType() != TopAbs_VERTEX){
00647       continue;
00648     }
00649     //
00650     nVSD=FindSDVertex(i);
00651     nV=(nVSD) ? nVSD : i;
00652     const TopoDS_Shape& aVx=myDS->Shape(nV);
00653     if (!aDMVI.IsBound(aVx)) {
00654       aDMVI.Bind(aVx, nV);
00655     }
00656   }
00657   // new shapes
00658   i1=myDS->NumberOfSourceShapes()+1;
00659   i2=myDS->NumberOfInsertedShapes();
00660   for (i=i1; i<=i2; ++i) {
00661     const TopoDS_Shape aS=myDS->Shape(i);//mpv
00662     if (aS.ShapeType() != TopAbs_VERTEX){
00663       continue;
00664     }
00665     if (!aDMVI.IsBound(aS)) {
00666       aDMVI.Bind(aS, i);
00667     }
00668   }
00669   //
00670   // 4. Initialize BoundSortBox on aDMVI
00671   //
00672   Handle(Bnd_HArray1OfBox) aHAB;
00673   Bnd_BoundSortBox aBSB;
00674   //
00675   aNbVDS=aDMVI.Extent();
00676   aHAB=new Bnd_HArray1OfBox(1, aNbVDS);
00677   //
00678   aItDMVI.Initialize(aDMVI);
00679   for (i=1; aItDMVI.More(); aItDMVI.Next(), ++i) {
00680     Bnd_Box aBox;
00681     //
00682     nV=aItDMVI.Value();
00683     aV=TopoDS::Vertex(aItDMVI.Key());
00684     aTolV=BRep_Tool::Tolerance(aV);
00685     aBox.SetGap(aTolV);
00686     BRepBndLib::Add(aV, aBox);
00687     aHAB->SetValue(i, aBox);
00688     //
00689     aDMIV.Bind(i, aV);
00690   }
00691   aBSB.Initialize(aHAB);
00692   //
00693   // 5. Compare
00694   aItDMVFF.Initialize(aDMVFF1);
00695   for (;  aItDMVFF.More(); aItDMVFF.Next()) {
00696     Bnd_Box aBoxV;
00697     //
00698     const TColStd_ListOfInteger& aLIFF=aItDMVFF.Value();
00699     aV=TopoDS::Vertex(aItDMVFF.Key());
00700     //
00701     aTolV=BRep_Tool::Tolerance(aV);
00702     aBoxV.SetGap(aTolV);
00703     BRepBndLib::Add(aV, aBoxV);
00704     //
00705     const TColStd_ListOfInteger& aLIVSD=aBSB.Compare(aBoxV);
00706     aNbVSD=aLIVSD.Extent();
00707     if (aNbVSD==0) {
00708       // add new vertex in DS and update map myAloneVertices
00709       BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
00710       //
00711       myDS->InsertShapeAndAncestorsSuccessors(aV, anASSeq);
00712       nV=myDS->NumberOfInsertedShapes();
00713       //
00714       aIt.Initialize(aLIFF);
00715       for (; aIt.More(); aIt.Next()) {
00716         nFx=aIt.Value();
00717         if (myAloneVertices.Contains(nFx)) {
00718           TColStd_IndexedMapOfInteger& aMVx=myAloneVertices.ChangeFromKey(nFx);
00719           aMVx.Add(nV);
00720         }
00721         else {
00722           TColStd_IndexedMapOfInteger aMVx;
00723           aMVx.Add(nV);
00724           myAloneVertices.Add(nFx, aMVx);
00725         }
00726       }
00727     }
00728   }
00729   // qqf
00730   {
00731     Standard_Integer aNbF, aNbAV, nF, k;
00732     NMTTools_IndexedDataMapOfIndexedMapOfInteger aMAVF;
00733     //
00734     aNbF=myAloneVertices.Extent();
00735     if (aNbF<2) {
00736       return;
00737     }
00738     //
00739     // 1. fill map Alone Vertex/Face ->  aMAVF
00740     for (i=1; i<=aNbF; ++i) {
00741       nF=myAloneVertices.FindKey(i);
00742       const TColStd_IndexedMapOfInteger& aMAV=myAloneVertices(i);
00743       aNbAV=aMAV.Extent();
00744       for(j=1; j<=aNbAV; ++j) {
00745         nV=aMAV(j);
00746         if (aMAVF.Contains(nV)) {
00747           TColStd_IndexedMapOfInteger& aMF=aMAVF.ChangeFromKey(nV);
00748           aMF.Add(nF);
00749         }
00750         else{
00751           TColStd_IndexedMapOfInteger aMF;
00752           aMF.Add(nF);
00753           aMAVF.Add(nV, aMF);
00754         }
00755       }
00756     }
00757     //
00758     // 2 Obtain pairs of faces
00759     aNbAV=aMAVF.Extent();
00760     for (i=1; i<=aNbAV; ++i) {
00761       const TColStd_IndexedMapOfInteger& aMF=aMAVF(i);
00762       aNbF=aMF.Extent();
00763       for(j=1; j<aNbF; ++j) {
00764         nF1=aMF(j);
00765         for(k=j+1; k<=aNbF; ++k) {
00766           nF2=aMF(k);
00767           myIP->Add(nF1, nF2, Standard_True, NMTDS_TI_FF);
00768         }
00769       }
00770     }
00771   }
00772   // qqt
00773 }
00774 //=======================================================================
00775 // function: AloneVertices
00776 // purpose:
00777 //=======================================================================
00778 const NMTTools_IndexedDataMapOfIndexedMapOfInteger&
00779   NMTTools_PaveFiller::AloneVertices()const
00780 {
00781   return myAloneVertices;
00782 }
00783 //=======================================================================
00784 // function: FuseVertices
00785 // purpose:
00786 //=======================================================================
00787 void NMTTools_PaveFiller::FuseVertices
00788   (const TopoDS_Shape& aCompound,
00789    TopTools_DataMapOfShapeShape& aDMVV)const
00790 {
00791   Standard_Integer i, aNbVV, n1, n2, nX;
00792   NMTTools_PaveFiller tPF;
00793   //
00794   tPF.SetCompositeShape(aCompound);
00795   //
00796   tPF.Init();
00797   //
00798   tPF.PerformVV();
00799   //tPF.PerformNewVertices(); //qq
00800   //
00801   NMTDS_ShapesDataStructure& tDS=*(tPF.DS());
00802   NMTDS_InterfPool& tInterfPool=*(tPF.IP());
00803   BOPTools_CArray1OfVVInterference& aVVt=tInterfPool.VVInterferences();
00804   //
00805   aNbVV=aVVt.Extent();
00806   for (i=1; i<=aNbVV; ++i) {
00807     const BOPTools_VVInterference& aVV=aVVt(i);
00808     aVV.Indices(n1, n2);
00809     nX=aVV.NewShape();
00810     if (nX) {
00811       const TopoDS_Shape& aV1=tDS.Shape(n1);
00812       const TopoDS_Shape& aV2=tDS.Shape(n2);
00813       const TopoDS_Shape& aVx=tDS.Shape(nX);
00814       aDMVV.Bind(aV1, aVx);
00815       aDMVV.Bind(aV2, aVx);
00816     }
00817   }
00818 }