Back to index

salome-geom  6.5.0
NMTDS_IteratorCheckerSI.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File:        NMTDS_IteratorChecker.hxx
00021 // Author:      Peter KURNEV
00022 
00023 #include <NMTDS_IteratorCheckerSI.hxx>
00024 
00025 #include <TopAbs_ShapeEnum.hxx>
00026 #include <gp_Pnt.hxx>
00027 #include <Bnd_Box.hxx>
00028 //
00029 #include <TopoDS_Shape.hxx>
00030 #include <TopoDS_Vertex.hxx>
00031 #include <TopoDS.hxx>
00032 #include <BRep_Tool.hxx>
00033 //
00034 #include <TColStd_IndexedMapOfInteger.hxx>
00035 #include <TColStd_ListOfInteger.hxx>
00036 #include <TColStd_DataMapOfIntegerInteger.hxx>
00037 #include <TColStd_ListIteratorOfListOfInteger.hxx>
00038 #include <TColStd_MapOfInteger.hxx>
00039 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
00040 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
00041 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
00042 //
00043 #include <TopTools_DataMapOfShapeInteger.hxx>
00044 //
00045 #include <NCollection_UBTreeFiller.hxx>
00046 #include <NMTDS_BoxBndTree.hxx>
00047 #include <NMTDS_ShapesDataStructure.hxx>
00048 #include <NMTDS_CArray1OfIndexRange.hxx>
00049 #include <NMTDS_IndexRange.hxx>
00050 #include <NMTDS_PairBoolean.hxx>
00051 #include <NMTDS_MapOfPairBoolean.hxx>
00052 #include <NMTDS_IndexedDataMapOfShapeBox.hxx>
00053 #include <NMTDS_Tools.hxx>
00054 
00055 //=======================================================================
00056 //function : 
00057 //purpose  : 
00058 //=======================================================================
00059 NMTDS_IteratorCheckerSI::NMTDS_IteratorCheckerSI()
00060 :
00061   NMTDS_Iterator()
00062 {
00063 }
00064 //=======================================================================
00065 //function : ~
00066 //purpose  : 
00067 //=======================================================================
00068 NMTDS_IteratorCheckerSI::~NMTDS_IteratorCheckerSI()
00069 {
00070 }
00071 //=======================================================================
00072 // function: Intersect
00073 // purpose: 
00074 //=======================================================================
00075 void NMTDS_IteratorCheckerSI::Intersect()
00076 {
00077   Standard_Boolean bFlag;
00078   Standard_Integer aNbS, i, aNbA, aNbB, iFlag;
00079   Standard_Integer aNbSD, iX, j, iDS, jB, k, aNbLV;
00080   TColStd_ListIteratorOfListOfInteger aIt;
00081   TColStd_DataMapOfIntegerInteger aMII;
00082   TColStd_DataMapOfIntegerListOfInteger aMVSD;
00083   TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
00084   TopTools_DataMapOfShapeInteger aMSI;
00085   TopAbs_ShapeEnum aTi, aTj;
00086   NMTDS_PairBoolean aPKXB; 
00087   NMTDS_MapOfPairBoolean aMPKXB;
00088   NMTDS_IndexedDataMapOfShapeBox aMSB;
00089   NMTDS_MapOfPairBoolean aMPA;//myPairsAvoid
00090   //
00091   NMTDS_BoxBndTreeSelector aSelector;
00092   NMTDS_BoxBndTree aBBTree;
00093   NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
00094   //
00095   aNbS=myDS->NumberOfShapesOfTheObject();
00096   //
00097   // myPairsAvoid, aMSI, aMSB
00098   for (i=1; i<=aNbS; ++i) {
00099     const TopoDS_Shape& aSi=myDS->Shape(i);
00100     aTi=aSi.ShapeType();
00101     if (NMTDS_Tools::HasBRep(aTi)) {
00102       if (aTi!=TopAbs_VERTEX) {
00103         TColStd_IndexedMapOfInteger aMA;
00104         //
00105         myDS->GetAllSuccessors(i, aMA);
00106         //
00107         aNbA=aMA.Extent();
00108         for (j=1; j<=aNbA; ++j) {
00109           iX=aMA(j);
00110           aPKXB.Clear();
00111           aPKXB.SetIds(i, iX);
00112           aMPA.Add(aPKXB);
00113         }
00114       }
00115       else {
00116         aPKXB.Clear();
00117         aPKXB.SetIds(i, i);
00118         aMPA.Add(aPKXB);
00119       }
00120       //
00121       Bnd_Box aBoxEx;
00122       //
00123       myDS->ComputeBoxEx(i, aBoxEx);
00124       aMSI.Bind(aSi, i);
00125       aMSB.Add(aSi, aBoxEx);
00126     }
00127   }
00128   // 
00129   // aMII
00130   aNbB=aMSB.Extent();
00131   for (i=1; i<=aNbB; ++i) {
00132     const TopoDS_Shape& aS=aMSB.FindKey(i);
00133     const Bnd_Box& aBoxEx=aMSB(i);
00134     //
00135     aTreeFiller.Add(i, aBoxEx);
00136     //
00137     iDS=aMSI.Find(aS);
00138     aMII.Bind(i, iDS);
00139   }
00140   //
00141   aTreeFiller.Fill();
00142   //
00143   for (i=1; i<=aNbS; ++i) {
00144     const TopoDS_Shape& aSi=myDS->Shape(i);
00145     aTi=aSi.ShapeType();
00146     if (!NMTDS_Tools::HasBRep(aTi)){
00147       continue;
00148     }
00149     const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
00150     aSelector.Clear();
00151     aSelector.SetBox(aBoxEx);
00152     //
00153     aNbSD=aBBTree.Select(aSelector);
00154     if (!aNbSD){
00155       continue;
00156     }
00157     //
00158     const TColStd_ListOfInteger& aLI=aSelector.Indices();
00159     //
00160     k=0;
00161     TColStd_ListOfInteger aLV;
00162     //
00163     aIt.Initialize(aLI);
00164     for (; aIt.More(); aIt.Next()) {
00165       jB=aIt.Value();  // box index in MII
00166       j=aMII.Find(jB); // DS index
00167       //
00168       aPKXB.SetIds(i, j);
00169       if (aMPA.Contains(aPKXB)) {
00170         continue;
00171       }
00172       //
00173       if (aMPKXB.Add(aPKXB)) {
00174         bFlag=Standard_False;// Bounding boxes are intersected
00175         const Bnd_Box& aBoxi=myDS->GetBoundingBox(i);
00176         const Bnd_Box& aBoxj=myDS->GetBoundingBox(j);
00177         if (aBoxi.IsOut(aBoxj)) {
00178           bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
00179         }
00180         const TopoDS_Shape& aSj=myDS->Shape(j);
00181         aTj=aSj.ShapeType();
00182         iX=NMTDS_Tools::TypeToInteger(aTi, aTj);
00183         //bFlag=(iStatus==2);
00184         aPKXB.SetFlag(bFlag);
00185         myLists[iX].Append(aPKXB);
00186         //
00187         // VSD prepare
00188         if (iX==5) { //VV
00189           aLV.Append(j);
00190         }
00191       }// if (aMPKXB.Add(aPKXB)) {
00192     }// for (; aIt.More(); aIt.Next()) {
00193     //
00194     // VSD treatment
00195     aNbLV=aLV.Extent();
00196     if (aNbLV) {
00197       TColStd_ListOfInteger aLV1;
00198       //
00199       const TopoDS_Vertex& aVi=TopoDS::Vertex(aSi);
00200       aIt.Initialize(aLV);
00201       for (; aIt.More(); aIt.Next()) {
00202         j=aIt.Value();  
00203         const TopoDS_Shape&  aSj=myDS->Shape(j);
00204         const TopoDS_Vertex& aVj=TopoDS::Vertex(aSj);
00205         iFlag=NMTDS_Tools::ComputeVV(aVi, aVj);
00206         if (!iFlag) {
00207           aLV1.Append(j);
00208         }
00209         else {
00210           aPKXB.SetIds(i, j);
00211           aMPKXB.Remove(aPKXB);
00212         }
00213       } 
00214       aMVSD.Bind(i, aLV1);
00215     }
00216   }//for (i=1; i<=aNbS; ++i) {
00217   //
00218   //
00219   // 2. Chains
00220   //=================
00221   myMVSD.Clear();
00222   NMTDS_Iterator::FillMVSD(aMVSD, myMVSD);
00223 }
00224