Salome HOME
CMake porting.
[modules/geom.git] / src / NMTDS / NMTDS_IteratorCheckerSI.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File:        NMTDS_IteratorChecker.hxx
21 // Author:      Peter KURNEV
22
23 #include <NMTDS_IteratorCheckerSI.hxx>
24
25 #include <TopAbs_ShapeEnum.hxx>
26 #include <gp_Pnt.hxx>
27 #include <Bnd_Box.hxx>
28 //
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Vertex.hxx>
31 #include <TopoDS.hxx>
32 #include <BRep_Tool.hxx>
33 //
34 #include <TColStd_IndexedMapOfInteger.hxx>
35 #include <TColStd_ListOfInteger.hxx>
36 #include <TColStd_DataMapOfIntegerInteger.hxx>
37 #include <TColStd_ListIteratorOfListOfInteger.hxx>
38 #include <TColStd_MapOfInteger.hxx>
39 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
40 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
41 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
42 //
43 #include <TopTools_DataMapOfShapeInteger.hxx>
44 //
45 #include <NCollection_UBTreeFiller.hxx>
46 #include <NMTDS_BoxBndTree.hxx>
47 #include <NMTDS_ShapesDataStructure.hxx>
48 #include <NMTDS_CArray1OfIndexRange.hxx>
49 #include <NMTDS_IndexRange.hxx>
50 #include <NMTDS_PairBoolean.hxx>
51 #include <NMTDS_MapOfPairBoolean.hxx>
52 #include <NMTDS_IndexedDataMapOfShapeBox.hxx>
53 #include <NMTDS_Tools.hxx>
54
55 //=======================================================================
56 //function : 
57 //purpose  : 
58 //=======================================================================
59 NMTDS_IteratorCheckerSI::NMTDS_IteratorCheckerSI()
60 :
61   NMTDS_Iterator()
62 {
63 }
64 //=======================================================================
65 //function : ~
66 //purpose  : 
67 //=======================================================================
68 NMTDS_IteratorCheckerSI::~NMTDS_IteratorCheckerSI()
69 {
70 }
71 //=======================================================================
72 // function: Intersect
73 // purpose: 
74 //=======================================================================
75 void NMTDS_IteratorCheckerSI::Intersect()
76 {
77   Standard_Boolean bFlag;
78   Standard_Integer aNbS, i, aNbA, aNbB, iFlag;
79   Standard_Integer aNbSD, iX, j, iDS, jB, k, aNbLV;
80   TColStd_ListIteratorOfListOfInteger aIt;
81   TColStd_DataMapOfIntegerInteger aMII;
82   TColStd_DataMapOfIntegerListOfInteger aMVSD;
83   TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
84   TopTools_DataMapOfShapeInteger aMSI;
85   TopAbs_ShapeEnum aTi, aTj;
86   NMTDS_PairBoolean aPKXB; 
87   NMTDS_MapOfPairBoolean aMPKXB;
88   NMTDS_IndexedDataMapOfShapeBox aMSB;
89   NMTDS_MapOfPairBoolean aMPA;//myPairsAvoid
90   //
91   NMTDS_BoxBndTreeSelector aSelector;
92   NMTDS_BoxBndTree aBBTree;
93   NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
94   //
95   aNbS=myDS->NumberOfShapesOfTheObject();
96   //
97   // myPairsAvoid, aMSI, aMSB
98   for (i=1; i<=aNbS; ++i) {
99     const TopoDS_Shape& aSi=myDS->Shape(i);
100     aTi=aSi.ShapeType();
101     if (NMTDS_Tools::HasBRep(aTi)) {
102       if (aTi!=TopAbs_VERTEX) {
103         TColStd_IndexedMapOfInteger aMA;
104         //
105         myDS->GetAllSuccessors(i, aMA);
106         //
107         aNbA=aMA.Extent();
108         for (j=1; j<=aNbA; ++j) {
109           iX=aMA(j);
110           aPKXB.Clear();
111           aPKXB.SetIds(i, iX);
112           aMPA.Add(aPKXB);
113         }
114       }
115       else {
116         aPKXB.Clear();
117         aPKXB.SetIds(i, i);
118         aMPA.Add(aPKXB);
119       }
120       //
121       Bnd_Box aBoxEx;
122       //
123       myDS->ComputeBoxEx(i, aBoxEx);
124       aMSI.Bind(aSi, i);
125       aMSB.Add(aSi, aBoxEx);
126     }
127   }
128   // 
129   // aMII
130   aNbB=aMSB.Extent();
131   for (i=1; i<=aNbB; ++i) {
132     const TopoDS_Shape& aS=aMSB.FindKey(i);
133     const Bnd_Box& aBoxEx=aMSB(i);
134     //
135     aTreeFiller.Add(i, aBoxEx);
136     //
137     iDS=aMSI.Find(aS);
138     aMII.Bind(i, iDS);
139   }
140   //
141   aTreeFiller.Fill();
142   //
143   for (i=1; i<=aNbS; ++i) {
144     const TopoDS_Shape& aSi=myDS->Shape(i);
145     aTi=aSi.ShapeType();
146     if (!NMTDS_Tools::HasBRep(aTi)){
147       continue;
148     }
149     const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
150     aSelector.Clear();
151     aSelector.SetBox(aBoxEx);
152     //
153     aNbSD=aBBTree.Select(aSelector);
154     if (!aNbSD){
155       continue;
156     }
157     //
158     const TColStd_ListOfInteger& aLI=aSelector.Indices();
159     //
160     k=0;
161     TColStd_ListOfInteger aLV;
162     //
163     aIt.Initialize(aLI);
164     for (; aIt.More(); aIt.Next()) {
165       jB=aIt.Value();  // box index in MII
166       j=aMII.Find(jB); // DS index
167       //
168       aPKXB.SetIds(i, j);
169       if (aMPA.Contains(aPKXB)) {
170         continue;
171       }
172       //
173       if (aMPKXB.Add(aPKXB)) {
174         bFlag=Standard_False;// Bounding boxes are intersected
175         const Bnd_Box& aBoxi=myDS->GetBoundingBox(i);
176         const Bnd_Box& aBoxj=myDS->GetBoundingBox(j);
177         if (aBoxi.IsOut(aBoxj)) {
178           bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
179         }
180         const TopoDS_Shape& aSj=myDS->Shape(j);
181         aTj=aSj.ShapeType();
182         iX=NMTDS_Tools::TypeToInteger(aTi, aTj);
183         //bFlag=(iStatus==2);
184         aPKXB.SetFlag(bFlag);
185         myLists[iX].Append(aPKXB);
186         //
187         // VSD prepare
188         if (iX==5) { //VV
189           aLV.Append(j);
190         }
191       }// if (aMPKXB.Add(aPKXB)) {
192     }// for (; aIt.More(); aIt.Next()) {
193     //
194     // VSD treatment
195     aNbLV=aLV.Extent();
196     if (aNbLV) {
197       TColStd_ListOfInteger aLV1;
198       //
199       const TopoDS_Vertex& aVi=TopoDS::Vertex(aSi);
200       aIt.Initialize(aLV);
201       for (; aIt.More(); aIt.Next()) {
202         j=aIt.Value();  
203         const TopoDS_Shape&  aSj=myDS->Shape(j);
204         const TopoDS_Vertex& aVj=TopoDS::Vertex(aSj);
205         iFlag=NMTDS_Tools::ComputeVV(aVi, aVj);
206         if (!iFlag) {
207           aLV1.Append(j);
208         }
209         else {
210           aPKXB.SetIds(i, j);
211           aMPKXB.Remove(aPKXB);
212         }
213       } 
214       aMVSD.Bind(i, aLV1);
215     }
216   }//for (i=1; i<=aNbS; ++i) {
217   //
218   //
219   // 2. Chains
220   //=================
221   myMVSD.Clear();
222   NMTDS_Iterator::FillMVSD(aMVSD, myMVSD);
223 }
224