Back to index

salome-geom  6.5.0
GEOMAlgo_Builder_2.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 // File:        GEOMAlgo_Builder_2.cxx
00023 // Author:      Peter KURNEV
00024 
00025 #include <GEOMAlgo_Builder.hxx>
00026 
00027 #include <TColStd_IndexedMapOfInteger.hxx>
00028 #include <TColStd_ListOfInteger.hxx>
00029 
00030 #include <TopAbs_Orientation.hxx>
00031 
00032 #include <TopoDS.hxx>
00033 #include <TopoDS_Face.hxx>
00034 #include <TopoDS_Edge.hxx>
00035 #include <TopoDS_Shape.hxx>
00036 #include <TopoDS_Compound.hxx>
00037 
00038 #include <TopTools_IndexedMapOfShape.hxx>
00039 #include <TopTools_ListOfShape.hxx>
00040 #include <TopTools_MapOfShape.hxx>
00041 #include <TopTools_ListIteratorOfListOfShape.hxx>
00042 
00043 #include <TopExp.hxx>
00044 #include <TopExp_Explorer.hxx>
00045 
00046 #include <BRep_Tool.hxx>
00047 #include <BRep_Builder.hxx>
00048 #include <BRepAlgo_Image.hxx>
00049 #include <BRepTools.hxx>
00050 
00051 #include <IntTools_Context.hxx>
00052 #include <IntTools_FClass2d.hxx>
00053 
00054 #include <BooleanOperations_OnceExplorer.hxx>
00055 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
00056 #include <BOPTools_ListOfPaveBlock.hxx>
00057 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
00058 #include <BOPTools_CArray1OfSSInterference.hxx>
00059 #include <BOPTools_SSInterference.hxx>
00060 #include <BOPTools_SequenceOfCurves.hxx>
00061 #include <BOPTools_Curve.hxx>
00062 #include <BOPTools_ListOfPaveBlock.hxx>
00063 #include <BOPTools_PaveBlock.hxx>
00064 #include <BOPTools_Tools3D.hxx>
00065 #include <BOPTools_CArray1OfVSInterference.hxx>
00066 #include <BOPTools_VSInterference.hxx>
00067 #include <BOPTools_ESInterference.hxx>
00068 #include <BOPTools_CArray1OfESInterference.hxx>
00069 
00070 #include <NMTDS_ShapesDataStructure.hxx>
00071 #include <NMTDS_InterfPool.hxx>
00072 
00073 #include <NMTTools_PaveFiller.hxx>
00074 #include <NMTTools_ListOfCoupleOfShape.hxx>
00075 #include <NMTTools_Tools.hxx>
00076 #include <NMTTools_CoupleOfShape.hxx>
00077 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
00078 #include <NMTTools_Tools.hxx>
00079 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
00080 #include <NMTTools_ListOfCommonBlock.hxx>
00081 #include <NMTTools_CommonBlock.hxx>
00082 #include <NMTTools_IndexedDataMapOfIndexedMapOfInteger.hxx>
00083 //
00084 #include <GEOMAlgo_Tools3D.hxx>
00085 #include <GEOMAlgo_WireEdgeSet.hxx>
00086 #include <GEOMAlgo_BuilderFace.hxx>
00087 
00088 #include <GEOMAlgo_ShapeSet.hxx>
00089 //
00090 #include <NMTDS_BoxBndTree.hxx>
00091 #include <NCollection_UBTreeFiller.hxx>
00092 #include <Bnd_Box.hxx>
00093 #include <BRepBndLib.hxx>
00094 #include <TopTools_DataMapOfIntegerShape.hxx>
00095 #include <TColStd_ListOfInteger.hxx>
00096 #include <TColStd_ListIteratorOfListOfInteger.hxx>
00097 #include <TopTools_DataMapOfShapeInteger.hxx>
00098 
00099 static
00100   void UpdateCandidates(const Standard_Integer ,
00101                         const Standard_Integer ,
00102                         NMTTools_IndexedDataMapOfIndexedMapOfInteger& );
00103 
00104 //modified by NIZNHY-PKV Thu Feb 16 12:24:52 2012f
00105 static
00106   Standard_Boolean IsClosed(const TopoDS_Edge& ,
00107                          const TopoDS_Face& );
00108 //modified by NIZNHY-PKV Thu Feb 16 12:24:56 2012t
00109 
00110 //=======================================================================
00111 //function : FillImagesFaces
00112 //purpose  :
00113 //=======================================================================
00114 void GEOMAlgo_Builder::FillImagesFaces()
00115 {
00116   myErrorStatus=0;
00117   //
00118   FillIn2DParts();
00119   BuildSplitFaces();
00120   FillSameDomainFaces();
00121   FillImagesFaces1();
00122   FillInternalVertices();
00123 }
00124 
00125 //=======================================================================
00126 // function: FillIn2DParts
00127 // purpose:
00128 //=======================================================================
00129 void GEOMAlgo_Builder::FillIn2DParts()
00130 {
00131   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
00132   NMTTools_PaveFiller* pPF=myPaveFiller;
00133   NMTDS_InterfPool* pIP=pPF->IP();
00134   BOPTools_CArray1OfSSInterference& aFFs=pIP->SSInterferences();
00135   NMTTools_CommonBlockPool& aCBP=pPF->ChangeCommonBlockPool();
00136   //
00137   Standard_Integer  j, nSpIn, nSpSc, aNbCurves;
00138   Standard_Integer aNbS, nF, aNbCBP, n1, n2, aNbFFs, aNbSpIn;
00139   TopTools_MapOfShape  aMFence;
00140   TopTools_ListOfShape aLSpIn;
00141   TopoDS_Face aF;
00142   NMTTools_ListIteratorOfListOfCommonBlock aItCB;
00143   BOPTools_ListIteratorOfListOfPaveBlock aItPB;
00144   //
00145   myInParts.Clear();
00146   //
00147   aNbFFs=aFFs.Extent();
00148   aNbCBP=aCBP.Extent();
00149   //
00150   aNbS=aDS.NumberOfShapesOfTheObject();
00151   for (nF=1; nF<=aNbS; ++nF) {
00152     if (aDS.GetShapeType(nF)!=TopAbs_FACE) {
00153       continue;
00154     }
00155     //
00156     aF=TopoDS::Face(aDS.Shape(nF));
00157     //
00158     aMFence.Clear();
00159     aLSpIn.Clear();
00160     //
00161     // 1. In Parts
00162     BOPTools_ListOfPaveBlock aLPBIn;
00163     //
00164     pPF->RealSplitsInFace(nF, aLPBIn);
00165     //
00166     aItPB.Initialize(aLPBIn);
00167     for (; aItPB.More(); aItPB.Next()) {
00168       const BOPTools_PaveBlock& aPB1=aItPB.Value();
00169       nSpIn=aPB1.Edge();
00170       const TopoDS_Shape& aSpIn=aDS.Shape(nSpIn);
00171       aLSpIn.Append(aSpIn);
00172     }
00173     //
00174     // 2. Section Parts
00175     for (j=1; j<=aNbFFs; ++j) {
00176       BOPTools_SSInterference& aFF=aFFs(j);
00177       aFF.Indices(n1, n2);
00178       if (!(n1==nF || n2==nF)) {
00179         continue;
00180       }
00181       BOPTools_SequenceOfCurves& aSC=aFF.Curves();
00182       aNbCurves=aSC.Length();
00183       if (!aNbCurves) {
00184         continue;
00185       }
00186       //
00187       const BOPTools_Curve& aBC=aSC(1);
00188       const BOPTools_ListOfPaveBlock& aLPB=aBC.NewPaveBlocks();
00189       aItPB.Initialize(aLPB);
00190       for (; aItPB.More(); aItPB.Next()) {
00191         const BOPTools_PaveBlock& aPBSc=aItPB.Value();
00192         nSpSc=aPBSc.Edge();
00193         const TopoDS_Shape& aSpSc=aDS.Shape(nSpSc);
00194         if (aMFence.Add(aSpSc)){
00195           aLSpIn.Append(aSpSc);
00196         }
00197       }
00198     }
00199     aNbSpIn=aLSpIn.Extent();
00200     if (aNbSpIn) {
00201       myInParts.Add(aF, aLSpIn);
00202     }
00203   }//for (nF=1; nF<=aNbS; ++nF) {
00204 }
00205 
00206 //=======================================================================
00207 // function: BuildSplitFaces
00208 // purpose:
00209 //=======================================================================
00210 void GEOMAlgo_Builder::BuildSplitFaces()
00211 {
00212   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
00213   NMTTools_PaveFiller* pPF=myPaveFiller;
00214   NMTDS_InterfPool* pIP=pPF->IP();
00215   BOPTools_CArray1OfSSInterference& aFFs=pIP->SSInterferences();
00216   const Handle(IntTools_Context)& aCtx= pPF->Context();
00217   //
00218   Standard_Boolean bToReverse, bIsClosed, bIsDegenerated;
00219   Standard_Integer i, aNb, aNbF, nF;
00220   TopTools_MapOfShape aMFence;
00221   TColStd_IndexedMapOfInteger aMFP;
00222   TopExp_Explorer anExp;
00223   TopoDS_Face aFF;
00224   TopoDS_Edge aSp, aEE;
00225   TopTools_ListIteratorOfListOfShape aIt;
00226   TopAbs_Orientation anOriF, anOriE;
00227   //
00228   mySplitFaces.Clear();
00229   //
00230   // 1. Select Faces to process (MFP)
00231   aNb=aDS.NumberOfShapesOfTheObject();
00232   for (i=1; i<=aNb; ++i) {
00233     const TopoDS_Shape& aF=aDS.Shape(i);
00234     if (aF.ShapeType()!=TopAbs_FACE) {
00235       continue;
00236     }
00237     if (!aMFence.Add(aF)) {
00238       continue;
00239     }
00240     //
00241     if (myInParts.Contains(aF)) {
00242       aMFP.Add(i);
00243       continue;
00244     }
00245     //
00246     anExp.Init(aF, TopAbs_EDGE);
00247     for (; anExp.More(); anExp.Next()) {
00248       const TopoDS_Shape& aE=anExp.Current();
00249       if (myImages.HasImage(aE)) {
00250         aMFP.Add(i);
00251         break;
00252       }
00253     }
00254     //
00255     //===
00256     {
00257       Standard_Integer aNbFFs, aNbSE, j, n1, n2;
00258       //
00259       aNbFFs=aFFs.Extent();
00260       for (j=1; j<=aNbFFs; ++j) {
00261         BOPTools_SSInterference& aFFj=aFFs(j);
00262         aFFj.Indices(n1, n2);
00263         if (!(n1==i || n2==i)) {
00264           continue;
00265         }
00266         //
00267         const TColStd_ListOfInteger& aLSE=aFFj.SharedEdges();
00268         aNbSE=aLSE.Extent();
00269         if (aNbSE) {
00270           aMFP.Add(i);
00271           break;
00272         }
00273       }
00274     }
00275     //===
00276     //
00277   }// for (i=1; i<=aNb; ++i)
00278   //
00279   // 2. ProcessFaces
00280   aNbF=aMFP.Extent();
00281   for (i=1; i<=aNbF; ++i) {
00282     nF=aMFP(i);
00283     const TopoDS_Face& aF=TopoDS::Face(aDS.Shape(nF));
00284     anOriF=aF.Orientation();
00285     aFF=aF;
00286     aFF.Orientation(TopAbs_FORWARD);
00287     //
00288     aMFence.Clear();
00289     //
00290     // 2.1. Fill WES
00291     GEOMAlgo_WireEdgeSet aWES;
00292     aWES.SetFace(aFF);
00293     //
00294     //  2.1.1. Add Split parts
00295     anExp.Init(aFF, TopAbs_EDGE);
00296     for (; anExp.More(); anExp.Next()) {
00297       const TopoDS_Edge& aE=TopoDS::Edge(anExp.Current());
00298       anOriE=aE.Orientation();
00299       //
00300       if (!myImages.HasImage(aE)) {
00301         if (anOriE==TopAbs_INTERNAL) {
00302           aEE=aE;
00303           aEE.Orientation(TopAbs_FORWARD);
00304           aWES.AddStartElement(aEE);
00305           aEE.Orientation(TopAbs_REVERSED);
00306           aWES.AddStartElement(aEE);
00307         }
00308         else {
00309           aWES.AddStartElement(aE);
00310         }
00311         continue;
00312       }
00313       //
00314       bIsDegenerated=BRep_Tool::Degenerated(aE);
00315       //modified by NIZNHY-PKV Wed Mar 07 07:46:09 2012f
00316       bIsClosed=IsClosed(aE, aF);
00317       //bIsClosed=BRep_Tool::IsClosed(aE, aF);
00318       //modified by NIZNHY-PKV Wed Mar 07 07:46:13 2012t
00319       //
00320       const TopTools_ListOfShape& aLIE=myImages.Image(aE);
00321       aIt.Initialize(aLIE);
00322       for (; aIt.More(); aIt.Next()) {
00323         aSp=TopoDS::Edge(aIt.Value());
00324         //
00325         if (bIsDegenerated) {
00326           aSp.Orientation(anOriE);
00327           aWES.AddStartElement(aSp);
00328           continue;
00329         }
00330         //
00331         if (anOriE==TopAbs_INTERNAL) {
00332           aSp.Orientation(TopAbs_FORWARD);
00333           aWES.AddStartElement(aSp);
00334           aSp.Orientation(TopAbs_REVERSED);
00335           aWES.AddStartElement(aSp);
00336           continue;
00337         }
00338         //
00339         if (bIsClosed){
00340           if (aMFence.Add(aSp)) {
00341             //
00342             if (!BRep_Tool::IsClosed(aSp, aF)){
00343               BOPTools_Tools3D::DoSplitSEAMOnFace(aSp, aF);
00344             }
00345             //
00346             aSp.Orientation(TopAbs_FORWARD);
00347             aWES.AddStartElement(aSp);
00348             aSp.Orientation(TopAbs_REVERSED);
00349             aWES.AddStartElement(aSp);
00350           }
00351           continue;
00352         }// if (aMFence.Add(aSp))
00353         //
00354         aSp.Orientation(anOriE);
00355         bToReverse=BOPTools_Tools3D::IsSplitToReverse1(aSp, aE, aCtx);
00356         if (bToReverse) {
00357           aSp.Reverse();
00358         }
00359         aWES.AddStartElement(aSp);
00360       }// for (; aIt.More(); aIt.Next()) {
00361     }// for (; anExp.More(); anExp.Next()) {
00362     //
00363     // 2.1.2. Add In2D Parts
00364     if (myInParts.Contains(aF)) {
00365       const TopTools_ListOfShape& aLE=myInParts.FindFromKey(aF);
00366       aIt.Initialize(aLE);
00367       for (; aIt.More(); aIt.Next()) {
00368         aSp=TopoDS::Edge(aIt.Value());
00369         //
00370         aSp.Orientation(TopAbs_FORWARD);
00371         aWES.AddStartElement(aSp);
00372         //
00373         aSp.Orientation(TopAbs_REVERSED);
00374         aWES.AddStartElement(aSp);
00375       }
00376     }
00377     //
00378     // 2.2. Build images Faces
00379     TopTools_ListOfShape aLFR;
00380     GEOMAlgo_ShapeSet aS1, aS2;
00381     //
00382     const TopTools_ListOfShape& aSE=aWES.StartElements();
00383     aS1.Add(aSE);
00384     aS2.Add(aFF, TopAbs_EDGE);
00385     if (aS1.IsEqual(aS2)) {
00386       aLFR.Append(aF);
00387     }
00388     else {
00389       GEOMAlgo_BuilderFace aBF;
00390       //
00391       aBF.SetFace(aFF);
00392       aBF.SetContext(aCtx);
00393       aBF.SetShapes(aSE);
00394       // <-DEB
00395       aBF.Perform();
00396       //
00397       const TopTools_ListOfShape& aLF=aBF.Areas();
00398       aIt.Initialize(aLF);
00399       for (; aIt.More(); aIt.Next()) {
00400         TopoDS_Shape& aFR=aIt.Value();
00401         if (anOriF==TopAbs_REVERSED) {
00402           aFR.Orientation(TopAbs_REVERSED);
00403         }
00404         aLFR.Append(aFR);
00405       }
00406     }
00407     //
00408     // 2.3. Collect draft images Faces
00409     mySplitFaces.Bind(aF, aLFR);
00410   }//for (i=1; i<=aNbF; ++i)
00411 }
00412 
00413 //=======================================================================
00414 // function: FillSameDomainFaces
00415 // purpose:
00416 //=======================================================================
00417 void GEOMAlgo_Builder::FillSameDomainFaces()
00418 {
00419   Standard_Boolean bIsSDF, bHasImage1, bHasImage2, bForward;
00420   Standard_Integer i, j, aNbFF, nF1, nF2, aNbPBInOn, aNbC, aNbSE;
00421   Standard_Integer aNbF1, aNbF2, i2s, aNbSD;
00422   TopTools_MapOfShape aMFence;
00423   TopTools_ListOfShape aLX1, aLX2;
00424   TopTools_ListIteratorOfListOfShape aItF1, aItF2;
00425   NMTTools_ListOfCoupleOfShape aLCS;
00426   //
00427   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
00428   NMTTools_PaveFiller* pPF=myPaveFiller;
00429   NMTDS_InterfPool* pIP=pPF->IP();
00430   BOPTools_CArray1OfSSInterference& aFFs=pIP->SSInterferences();
00431   const Handle(IntTools_Context)& aCtx= pPF->Context();
00432   //
00433   //
00434   //mySameDomainShapes.Clear();
00435   //
00436   // 1. For each FF find among images of faces
00437   //    all pairs of same domain faces (SDF) [=> aLCS]
00438   aNbFF=aFFs.Extent();
00439   for (i=1; i<=aNbFF; ++i) {
00440     BOPTools_SSInterference& aFF=aFFs(i);
00441     aFF.Indices(nF1, nF2);
00442     //
00443     const TopoDS_Face& aF1=TopoDS::Face(aDS.Shape(nF1));
00444     const TopoDS_Face& aF2=TopoDS::Face(aDS.Shape(nF2));
00445     //
00446     // if there are no in/on 2D split parts the faces nF1, nF2
00447     // can not be SDF
00448     const BOPTools_ListOfPaveBlock& aLPBInOn=aFF.PaveBlocks();
00449     aNbPBInOn=aLPBInOn.Extent();
00450     //
00451     //===
00452     const TColStd_ListOfInteger& aLSE=aFF.SharedEdges();
00453     aNbSE=aLSE.Extent();
00454     if (!aNbPBInOn && !aNbSE) {
00455       continue;
00456     }
00457     //===
00458     //
00459     // if there is at least one section edge between faces nF1, nF2
00460     // they can not be SDF
00461     BOPTools_SequenceOfCurves& aSC=aFF.Curves();
00462     aNbC=aSC.Length();
00463     if (aNbC) {
00464       continue;
00465     }
00466     //
00467     // the faces are suspected to be SDF.
00468     // Try to find SDF among images of nF1, nF2
00469     aMFence.Clear();
00470     //
00471     //--------------------------------------------------------
00472     bHasImage1=mySplitFaces.HasImage(aF1);
00473     bHasImage2=mySplitFaces.HasImage(aF2);
00474     //
00475     aLX1.Clear();
00476     if (!bHasImage1) {
00477       aLX1.Append(aF1);
00478     }
00479     //
00480     aLX2.Clear();
00481     if (!bHasImage2) {
00482       aLX2.Append(aF2);
00483     }
00484     //
00485     const TopTools_ListOfShape& aLF1r=(bHasImage1)? mySplitFaces.Image(aF1) : aLX1;
00486     const TopTools_ListOfShape& aLF2r=(bHasImage2)? mySplitFaces.Image(aF2) : aLX2;
00487     //
00488     TopTools_DataMapOfIntegerShape aMIS;
00489     TColStd_ListIteratorOfListOfInteger aItLI;
00490     NMTDS_BoxBndTreeSelector aSelector;
00491     NMTDS_BoxBndTree aBBTree;
00492     NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
00493     //
00494     aNbF1=aLF1r.Extent();
00495     aNbF2=aLF2r.Extent();
00496     bForward=(aNbF1<aNbF2);
00497     //
00498     const TopTools_ListOfShape& aLF1=bForward ? aLF1r : aLF2r;
00499     const TopTools_ListOfShape& aLF2=bForward ? aLF2r : aLF1r;
00500     //
00501     // 1. aTreeFiller
00502     aItF2.Initialize(aLF2);
00503     for (i2s=1; aItF2.More(); aItF2.Next(), ++i2s) {
00504       Bnd_Box aBoxF2s;
00505       //
00506       const TopoDS_Face& aF2s=*((TopoDS_Face*)(&aItF2.Value()));
00507       //
00508       BRepBndLib::Add(aF2s, aBoxF2s);
00509       //
00510       aMIS.Bind(i2s, aF2s);
00511       //
00512       aTreeFiller.Add(i2s, aBoxF2s);
00513     }//for (i2s=1; aItF2.More(); aItF2.Next(), ++i2s) {
00514     //
00515     aTreeFiller.Fill();
00516     //
00517     // 2.
00518     aItF1.Initialize(aLF1);
00519     for (j=1; aItF1.More(); aItF1.Next(), ++j) {
00520       Bnd_Box aBoxF1x;
00521       //
00522       const TopoDS_Face& aF1x=*((TopoDS_Face*)(&aItF1.Value()));
00523       //
00524       BRepBndLib::Add(aF1x, aBoxF1x);
00525       //
00526       aSelector.Clear();
00527       aSelector.SetBox(aBoxF1x);
00528       aNbSD=aBBTree.Select(aSelector);
00529       if (!aNbSD) {
00530         continue;
00531       }
00532       //
00533       const TColStd_ListOfInteger& aLI=aSelector.Indices();
00534       aItLI.Initialize(aLI);
00535       for (; aItLI.More(); aItLI.Next()) {
00536         i2s=aItLI.Value();
00537         const TopoDS_Face& aF2y=*((TopoDS_Face*)(&aMIS.Find(i2s)));
00538         //
00539         bIsSDF=NMTTools_Tools::AreFacesSameDomain(aF1x, aF2y, aCtx);
00540         if (bIsSDF) {
00541           if (aMFence.Contains(aF1x) || aMFence.Contains(aF2y)) {
00542             continue;
00543           }
00544           aMFence.Add(aF1x);
00545           aMFence.Add(aF2y);
00546           //
00547           NMTTools_CoupleOfShape aCS;
00548           //
00549           aCS.SetShape1(aF1x);
00550           aCS.SetShape2(aF2y);
00551           aLCS.Append(aCS);
00552           //
00553           if (bForward) {
00554             if (aF1x==aF1) {
00555               if (!mySplitFaces.HasImage(aF1)) {
00556                 mySplitFaces.Bind(aF1, aF1);
00557               }
00558             }
00559             if (aF2y==aF2) {
00560               if (!mySplitFaces.HasImage(aF2)) {
00561                 mySplitFaces.Bind(aF2, aF2);
00562               }
00563             }
00564           }
00565           else {
00566             if (aF1x==aF2) {
00567               if (!mySplitFaces.HasImage(aF2)) {
00568                 mySplitFaces.Bind(aF2, aF2);
00569               }
00570             }
00571             if (aF2y==aF1) {
00572               if (!mySplitFaces.HasImage(aF1)) {
00573                 mySplitFaces.Bind(aF1, aF1);
00574               }
00575             }
00576           }
00577           //
00578           break;
00579         }//if (bIsSDF) {
00580       }//for (; aItLI.More(); aItLI.Next()) {
00581     }//for (; aItF1.More(); aItF1.Next()) {
00582   }//for (i=1; i<=aNbFF; ++i)
00583   //-------------------------------------------------------------
00584   aNbC=aLCS.Extent();
00585   if (!aNbC) {
00586     return;
00587   }
00588   //
00589   // 2. Find Chains
00590   NMTTools_IndexedDataMapOfShapeIndexedMapOfShape aMC;
00591   //
00592   NMTTools_Tools::FindChains(aLCS, aMC);
00593   //
00594   Standard_Boolean bIsImage;
00595   Standard_Integer aIx, aIxMin, aNbMSDF, k, aNbMFj;
00596   TopoDS_Shape aFOld, aFSDmin;
00597   TopTools_IndexedMapOfShape aMFj;
00598   TopTools_DataMapOfShapeInteger aDMSI;
00599   //
00600   aItF1.Initialize(myShapes);
00601   for (j=1; aItF1.More(); aItF1.Next(), ++j) {
00602     const TopoDS_Shape& aSj=aItF1.Value();
00603     aMFj.Clear();
00604     TopExp::MapShapes(aSj, TopAbs_FACE, aMFj);
00605     aNbMFj=aMFj.Extent();
00606     for (k=1; k<=aNbMFj; ++k) {
00607       const TopoDS_Shape& aFk=aMFj(k);
00608       if (!aDMSI.IsBound(aFk)) {
00609        aDMSI.Bind(aFk, j);
00610       }
00611     }
00612   }
00613   //
00614   // 3. Fill the map of SDF mySameDomainFaces
00615   aNbC=aMC.Extent();
00616   for (i=1; i<=aNbC; ++i) {
00617    // const TopoDS_Shape& aF=aMC.FindKey(i);
00618     const TopTools_IndexedMapOfShape& aMSDF=aMC(i);
00619     //
00620     aNbMSDF=aMSDF.Extent();
00621     for (j=1; j<=aNbMSDF; ++j) {
00622       const TopoDS_Shape& aFSD=aMSDF(j);
00623       bIsImage=mySplitFaces.IsImage(aFSD);
00624       aFOld=aFSD;
00625       if (bIsImage) {
00626        aFOld=mySplitFaces.ImageFrom(aFSD);
00627       }
00628       //
00629       aIx=aDMSI.Find(aFOld);
00630       if (j==1) {
00631        aIxMin=aIx;
00632        aFSDmin=aFSD;
00633        continue;
00634       }
00635       else {
00636        if (aIx<aIxMin) {
00637          aIxMin=aIx;
00638          aFSDmin=aFSD;
00639        }
00640       }
00641     }
00642     //
00643     for (j=1; j<=aNbMSDF; ++j) {
00644       const TopoDS_Shape& aFSD=aMSDF(j);
00645       mySameDomainShapes.Add(aFSD, aFSDmin);
00646     }
00647   }
00648   //
00649 }
00650 
00651 //=======================================================================
00652 // function: FillImagesFaces1
00653 // purpose:
00654 //=======================================================================
00655 void GEOMAlgo_Builder::FillImagesFaces1()
00656 {
00657   Standard_Integer i, aNb, iSense, aNbLFx;
00658   TopoDS_Face aF, aFSp, aFSD;
00659   TopTools_ListOfShape aLFx;
00660   TopTools_ListIteratorOfListOfShape aIt;
00661   //
00662   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
00663   //
00664   aNb=aDS.NumberOfShapesOfTheObject();
00665   for (i=1; i<=aNb; ++i) {
00666     const TopoDS_Shape& aS=aDS.Shape(i);
00667     if (aS.ShapeType()!=TopAbs_FACE) {
00668       continue;
00669     }
00670     //
00671     if (!mySplitFaces.HasImage(aS)) {
00672       continue;
00673     }
00674     //
00675     aF=*((TopoDS_Face*)&aS);
00676     //
00677     aLFx.Clear();
00678     const TopTools_ListOfShape& aLF=mySplitFaces.Image(aF);
00679     aIt.Initialize(aLF);
00680     for (; aIt.More(); aIt.Next()) {
00681       aFSp=*((TopoDS_Face*)(&aIt.Value()));
00682       if (!mySameDomainShapes.Contains(aFSp)) {
00683         aLFx.Append(aFSp);
00684       }
00685       else {
00686         const TopoDS_Shape& aSx=mySameDomainShapes.FindFromKey(aFSp);
00687         aFSD=*((TopoDS_Face*)(&aSx));
00688         iSense=GEOMAlgo_Tools3D::Sense(aFSp, aFSD);
00689         if (iSense<0) {
00690           aFSD.Reverse();
00691         }
00692         aLFx.Append(aFSD);
00693       }
00694     }
00695     //
00696     if (!myImages.HasImage(aF)) {
00697       aNbLFx=aLFx.Extent();
00698       if (aNbLFx==1) {
00699         const TopoDS_Shape& aFx=aLFx.First();
00700         if (aF.IsSame(aFx)) {
00701           continue;
00702         }
00703       }
00704       myImages.Bind(aF, aLFx);
00705     }
00706   }
00707 }
00708 
00709 //=======================================================================
00710 // function: FillInternalVertices
00711 // purpose:
00712 //=======================================================================
00713 void GEOMAlgo_Builder::FillInternalVertices()
00714 {
00715   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
00716   NMTTools_PaveFiller* pPF=myPaveFiller;
00717   NMTDS_InterfPool* pIP=pPF->IP();
00718   const Handle(IntTools_Context)& aCtx= pPF->Context();
00719   //
00720   BOPTools_CArray1OfVSInterference& aVFs=pIP->VSInterferences();
00721   BOPTools_CArray1OfESInterference& aEFs=pIP->ESInterferences();
00722   const NMTTools_IndexedDataMapOfIndexedMapOfInteger& aMAV=pPF->AloneVertices();
00723   //
00724   Standard_Boolean bHasImage;
00725   Standard_Integer i, j, nF, aNbS, nV, nVSD, n1, n2, iFlag;
00726   Standard_Integer aNbVFs, aNbAVF, aNbEFs, aNbVC, aNbE, aNbV;
00727   Standard_Real aU1, aU2, aTol;
00728   NMTTools_IndexedDataMapOfIndexedMapOfInteger aMFMV;
00729   TopTools_MapOfShape aMFence;
00730   TopTools_ListIteratorOfListOfShape aIt, aItV;
00731   BRep_Builder aBB;
00732   //
00733   // 1. Collect face-vertex candidates [aMFMV]
00734   //
00735   // 1.1. VFs
00736   aNbVFs=aVFs.Extent();
00737   for (i=1; i<=aNbVFs; ++i) {
00738     const BOPTools_VSInterference& aVS=aVFs(i);
00739     aVS.Indices(n1, n2);
00740     nF=n2;
00741     nV=n1;
00742     if (aDS.Shape(n1).ShapeType()==TopAbs_FACE) {
00743       nF=n1;
00744       nV=n2;
00745     }
00746     nVSD=pPF->FindSDVertex(nV);
00747     if (nVSD) {
00748       nV=nVSD;
00749     }
00750     //
00751     UpdateCandidates(nF, nV, aMFMV);
00752   }
00753   //
00754   // 1.2 EFs
00755   aNbEFs=aEFs.Extent();
00756   for (i=1; i<=aNbEFs; ++i) {
00757     const BOPTools_ESInterference& aEF=aEFs(i);
00758     aEF.Indices(n1, n2);
00759     nV=aEF.NewShape();
00760     if (!nV) {
00761       continue;
00762     }
00763     const TopoDS_Shape& aSnew=aDS.Shape(nV);
00764     if (aSnew.ShapeType()!=TopAbs_VERTEX) {
00765       continue;
00766     }
00767     //
00768     nF=(aDS.Shape(n1).ShapeType()==TopAbs_FACE) ? n1 : n2;
00769     nVSD=pPF->FindSDVertex(nV);
00770     if (nVSD) {
00771       nV=nVSD;
00772     }
00773     UpdateCandidates(nF, nV, aMFMV);
00774   }
00775   //
00776   aNbS=aDS.NumberOfShapesOfTheObject();
00777   for (nF=1; nF<=aNbS; ++nF) {
00778     const TopoDS_Shape& aF=aDS.Shape(nF);
00779     //
00780     if (aF.ShapeType()!=TopAbs_FACE) {
00781       continue;
00782     }
00783     if (!aMFence.Add(aF)) {
00784       continue;
00785     }
00786     //
00787     const TopoDS_Face& aFF=TopoDS::Face(aF);
00788     aTol=BRep_Tool::Tolerance(aFF);
00789     //
00790     // 1.3 FFs
00791     if (aMAV.Contains(nF)) {
00792       const TColStd_IndexedMapOfInteger& aMAVF=aMAV.FindFromKey(nF);
00793       aNbAVF=aMAVF.Extent();
00794       for (j=1; j<=aNbAVF; ++j) {
00795         nV=aMAVF(j);
00796         nVSD=pPF->FindSDVertex(nV);
00797         if (nVSD) {
00798           nV=nVSD;
00799         }
00800         //
00801         UpdateCandidates(nF, nV, aMFMV);
00802       }
00803     }
00804     //
00805     // 1.4 Internal vertices of the face nF
00806     BooleanOperations_OnceExplorer aExp(aDS);
00807     aExp.Init(nF, TopAbs_VERTEX);
00808     for (; aExp.More(); aExp.Next()) {
00809       nV=aExp.Current();
00810       const TopoDS_Shape& aV=aDS.Shape(nV);
00811       if (aV.Orientation()==TopAbs_INTERNAL) {
00812         nVSD=pPF->FindSDVertex(nV);
00813         if (nVSD) {
00814           nV=nVSD;
00815         }
00816         //
00817         UpdateCandidates(nF, nV, aMFMV);
00818       }
00819     }
00820     //
00821     // 2. Process face nF
00822     if (!aMFMV.Contains(nF)) {
00823       continue;
00824     }
00825     //
00826     const TColStd_IndexedMapOfInteger& aMVC=aMFMV.FindFromKey(nF);
00827     aNbVC=aMVC.Extent();
00828     if (!aNbVC) {
00829       continue;
00830     }
00831     //
00832     // 2.1 Refine candidates
00833     TopTools_IndexedDataMapOfShapeListOfShape aMVE;
00834     TopTools_ListOfShape aLV;
00835     //
00836     bHasImage=myImages.HasImage(aF);
00837     if (bHasImage) {
00838       const TopTools_ListOfShape& aLFx=myImages.Image(aF);
00839       aIt.Initialize(aLFx);
00840       for (; aIt.More(); aIt.Next()) {
00841         const TopoDS_Shape& aFx=aIt.Value();
00842         TopExp::MapShapesAndAncestors(aFx, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
00843       }
00844     }
00845     else {
00846       Standard_Boolean bFaceToProcess;
00847       //
00848       TopExp::MapShapesAndAncestors(aF, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
00849       bFaceToProcess=Standard_False;
00850       for (j=1; j<=aNbVC; ++j) {
00851         nV=aMVC(j);
00852         const TopoDS_Shape& aV=aDS.Shape(nV);
00853         if (!aMVE.Contains(aV)) {
00854           bFaceToProcess=!bFaceToProcess;
00855           break;
00856         }
00857       }
00858       if (!bFaceToProcess) {
00859         continue;
00860       }
00861     }// else
00862     //
00863     for (j=1; j<=aNbVC; ++j) {
00864       nV=aMVC(j);
00865       const TopoDS_Shape& aV=aDS.Shape(nV);
00866       if (aMVE.Contains(aV)) {
00867         const TopTools_ListOfShape& aLE=aMVE.FindFromKey(aV);
00868         aNbE=aLE.Extent();
00869         if (aNbE) {
00870           continue;
00871         }
00872       }
00873       aLV.Append(aV);
00874     }
00875     //
00876     aNbV=aLV.Extent();
00877     if (aNbV) {
00878       //  3. Try to put vertices into the face(s)
00879       aItV.Initialize(aLV);
00880       for (; aItV.More(); aItV.Next()) {
00881         TopoDS_Vertex aV=TopoDS::Vertex(aItV.Value());
00882         aV.Orientation(TopAbs_INTERNAL);
00883         //
00884         bHasImage=myImages.HasImage(aF);
00885         if (bHasImage) {
00886           const TopTools_ListOfShape& aLFx=myImages.Image(aF);
00887           aIt.Initialize(aLFx);
00888           for (; aIt.More(); aIt.Next()) {
00889             TopoDS_Face aFx=TopoDS::Face(aIt.Value());
00890             // update classifier
00891             IntTools_FClass2d& aClsf=aCtx->FClass2d(aFx);
00892             aClsf.Init(aFx, aTol);
00893             //
00894             iFlag=aCtx->ComputeVS (aV, aFx, aU1, aU2);
00895             if (!iFlag) {
00896               aBB.Add(aFx, aV);
00897               break;
00898             }
00899           }
00900         }
00901         else {
00902           const TopoDS_Face& aFx=TopoDS::Face(aF);
00903           // update classifier
00904           IntTools_FClass2d& aClsf=aCtx->FClass2d(aFx);
00905           aClsf.Init(aFx, aTol);
00906           //
00907           iFlag=aCtx->ComputeVS (aV, aFx, aU1, aU2);
00908           if (!iFlag) {
00909             TopoDS_Face aFz;
00910             //
00911             GEOMAlgo_Tools3D::CopyFace(aFx, aFz);
00912             aBB.Add(aFz, aV);
00913             myImages.Bind(aF, aFz);
00914           }
00915         }
00916       }// for (; aItV.More(); aItV.Next()) {
00917     }// if (aNbV) {
00918   }// for (nF=1; nF<=aNb; ++nF) {
00919 }
00920 
00921 //=======================================================================
00922 // function: UpdateCandidates
00923 // purpose:
00924 //=======================================================================
00925 void UpdateCandidates(const Standard_Integer theNF,
00926                       const Standard_Integer theNV,
00927                        NMTTools_IndexedDataMapOfIndexedMapOfInteger& theMFMV)
00928 {
00929   if (theMFMV.Contains(theNF)) {
00930     TColStd_IndexedMapOfInteger& aMV=theMFMV.ChangeFromKey(theNF);
00931     aMV.Add(theNV);
00932   }
00933   else {
00934     TColStd_IndexedMapOfInteger aMV;
00935     aMV.Add(theNV);
00936     theMFMV.Add(theNF, aMV);
00937   }
00938 }
00939 
00940 //modified by NIZNHY-PKV Thu Feb 16 12:25:16 2012f
00941 //=======================================================================
00942 //function : IsClosed
00943 //purpose  :
00944 //=======================================================================
00945 Standard_Boolean IsClosed(const TopoDS_Edge& aE,
00946                        const TopoDS_Face& aF)
00947 {
00948   Standard_Boolean bRet;
00949   //
00950   bRet=BRep_Tool::IsClosed(aE, aF);
00951   if (bRet) {
00952     TopTools_MapOfShape aM;
00953     TopExp_Explorer aExp(aF, TopAbs_EDGE);
00954     for (; aExp.More(); aExp.Next()) {
00955       const TopoDS_Shape& aEx=aExp.Current();
00956       //
00957       if (aM.Add(aEx)) {
00958        bRet=aEx.IsSame(aE);
00959        if (bRet) {
00960          break;
00961        }
00962       }
00963     }
00964   }
00965   return bRet;
00966 }
00967 //modified by NIZNHY-PKV Thu Feb 16 12:25:25 2012t
00968 
00969 /*
00970     {
00971       TopoDS_Compound aCx;
00972       BRep_Builder aBBx;
00973       TopTools_ListIteratorOfListOfShape aItx;
00974       //
00975       aBBx.MakeCompound(aCx);
00976       aBBx.Add(aCx, aFF);
00977       aItx.Initialize(aSE);
00978       for (; aItx.More(); aItx.Next()) {
00979         TopoDS_Shape& aEx=aItx.Value();
00980         aBBx.Add(aCx, aEx);
00981       }
00982       int a=0;
00983     }
00984     */