Salome HOME
Update copyright
[modules/geom.git] / src / NMTDS / NMTDS_IteratorCheckerSI.cxx
1 // Copyright (C) 2007-2011  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.cxx
21 // Created:     Tue Feb  6 10:37:59 2007
22 // Author:      Peter KURNEV
23 //
24 #include <NMTDS_IteratorCheckerSI.ixx>
25
26 #include <TopAbs_ShapeEnum.hxx>
27 #include <gp_Pnt.hxx>
28 #include <Bnd_Box.hxx>
29 //
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Vertex.hxx>
32 #include <TopoDS.hxx>
33 #include <BRep_Tool.hxx>
34 //
35 #include <TColStd_IndexedMapOfInteger.hxx>
36 #include <TColStd_ListOfInteger.hxx>
37 #include <TColStd_DataMapOfIntegerInteger.hxx>
38 #include <TColStd_ListIteratorOfListOfInteger.hxx>
39 #include <TColStd_MapOfInteger.hxx>
40 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
41 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
42 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
43 //
44 #include <TopTools_DataMapOfShapeInteger.hxx>
45 //
46 #include <NCollection_UBTreeFiller.hxx>
47 #include <NMTDS_BoxBndTree.hxx>
48 #include <NMTDS_ShapesDataStructure.hxx>
49 #include <NMTDS_CArray1OfIndexRange.hxx>
50 #include <NMTDS_IndexRange.hxx>
51 #include <NMTDS_PassKeyBoolean.hxx>
52 #include <NMTDS_MapOfPassKeyBoolean.hxx>
53 #include <NMTDS_IndexedDataMapOfShapeBox.hxx>
54 #include <NMTDS_Tools.hxx>
55
56 //=======================================================================
57 //function : 
58 //purpose  : 
59 //=======================================================================
60   NMTDS_IteratorCheckerSI::NMTDS_IteratorCheckerSI()
61 :
62   NMTDS_Iterator()
63 {
64 }
65 //=======================================================================
66 //function : ~
67 //purpose  : 
68 //=======================================================================
69   NMTDS_IteratorCheckerSI::~NMTDS_IteratorCheckerSI()
70 {
71 }
72 //=======================================================================
73 // function: Intersect
74 // purpose: 
75 //=======================================================================
76   void NMTDS_IteratorCheckerSI::Intersect()
77 {
78   Standard_Boolean bFlag;
79   Standard_Integer aNbS, i, aNbA, aNbB, iFlag;
80   Standard_Integer aNbSD, iX, j, iDS, jB, k, aNbLV;
81   TColStd_ListIteratorOfListOfInteger aIt;
82   TColStd_DataMapOfIntegerInteger aMII;
83   TColStd_DataMapOfIntegerListOfInteger aMVSD;
84   TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
85   TopTools_DataMapOfShapeInteger aMSI;
86   TopAbs_ShapeEnum aTi, aTj;
87   NMTDS_PassKeyBoolean aPKXB; 
88   NMTDS_MapOfPassKeyBoolean aMPKXB;
89   NMTDS_IndexedDataMapOfShapeBox aMSB;
90   NMTDS_MapOfPassKeyBoolean aMPA;//myPairsAvoid
91   //
92   NMTDS_BoxBndTreeSelector aSelector;
93   NMTDS_BoxBndTree aBBTree;
94   NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
95   //
96   aNbS=myDS->NumberOfShapesOfTheObject();
97   //
98   // myPairsAvoid, aMSI, aMSB
99   for (i=1; i<=aNbS; ++i) {
100     const TopoDS_Shape& aSi=myDS->Shape(i);
101     aTi=aSi.ShapeType();
102     if (NMTDS_Tools::HasBRep(aTi)) {
103       if (aTi!=TopAbs_VERTEX) {
104         TColStd_IndexedMapOfInteger aMA;
105         //
106         myDS->GetAllSuccessors(i, aMA);
107         //
108         aNbA=aMA.Extent();
109         for (j=1; j<=aNbA; ++j) {
110           iX=aMA(j);
111           aPKXB.Clear();
112           aPKXB.SetIds(i, iX);
113           aMPA.Add(aPKXB);
114         }
115       }
116       else {
117         aPKXB.Clear();
118         aPKXB.SetIds(i, i);
119         aMPA.Add(aPKXB);
120       }
121       //
122       Bnd_Box aBoxEx;
123       //
124       myDS->ComputeBoxEx(i, aBoxEx);
125       aMSI.Bind(aSi, i);
126       aMSB.Add(aSi, aBoxEx);
127     }
128   }
129   // 
130   // aMII
131   aNbB=aMSB.Extent();
132   for (i=1; i<=aNbB; ++i) {
133     const TopoDS_Shape& aS=aMSB.FindKey(i);
134     const Bnd_Box& aBoxEx=aMSB(i);
135     //
136     aTreeFiller.Add(i, aBoxEx);
137     //
138     iDS=aMSI.Find(aS);
139     aMII.Bind(i, iDS);
140   }
141   //
142   aTreeFiller.Fill();
143   //
144   for (i=1; i<=aNbS; ++i) {
145     const TopoDS_Shape& aSi=myDS->Shape(i);
146     aTi=aSi.ShapeType();
147     if (!NMTDS_Tools::HasBRep(aTi)){
148       continue;
149     }
150     const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
151     aSelector.Clear();
152     aSelector.SetBox(aBoxEx);
153     //
154     aNbSD=aBBTree.Select(aSelector);
155     if (!aNbSD){
156       continue;
157     }
158     //
159     const TColStd_ListOfInteger& aLI=aSelector.Indices();
160     //
161     k=0;
162     TColStd_ListOfInteger aLV;
163     //
164     aIt.Initialize(aLI);
165     for (; aIt.More(); aIt.Next()) {
166       jB=aIt.Value();  // box index in MII
167       j=aMII.Find(jB); // DS index
168       //
169       aPKXB.SetIds(i, j);
170       if (aMPA.Contains(aPKXB)) {
171         continue;
172       }
173       //
174       if (aMPKXB.Add(aPKXB)) {
175         bFlag=Standard_False;// Bounding boxes are intersected
176         const Bnd_Box& aBoxi=myDS->GetBoundingBox(i);
177         const Bnd_Box& aBoxj=myDS->GetBoundingBox(j);
178         if (aBoxi.IsOut(aBoxj)) {
179           bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
180         }
181         const TopoDS_Shape& aSj=myDS->Shape(j);
182         aTj=aSj.ShapeType();
183         iX=NMTDS_Tools::TypeToInteger(aTi, aTj);
184         //bFlag=(iStatus==2);
185         aPKXB.SetFlag(bFlag);
186         myLists[iX].Append(aPKXB);
187         //
188         // VSD prepare
189         if (iX==5) { //VV
190           aLV.Append(j);
191         }
192       }// if (aMPKXB.Add(aPKXB)) {
193     }// for (; aIt.More(); aIt.Next()) {
194     //
195     // VSD treatment
196     aNbLV=aLV.Extent();
197     if (aNbLV) {
198       TColStd_ListOfInteger aLV1;
199       //
200       const TopoDS_Vertex& aVi=TopoDS::Vertex(aSi);
201       aIt.Initialize(aLV);
202       for (; aIt.More(); aIt.Next()) {
203         j=aIt.Value();  
204         const TopoDS_Shape&  aSj=myDS->Shape(j);
205         const TopoDS_Vertex& aVj=TopoDS::Vertex(aSj);
206         iFlag=NMTDS_Tools::ComputeVV(aVi, aVj);
207         if (!iFlag) {
208           aLV1.Append(j);
209         }
210         else {
211           aPKXB.SetIds(i, j);
212           aMPKXB.Remove(aPKXB);
213         }
214       } 
215       aMVSD.Bind(i, aLV1);
216     }
217   }//for (i=1; i<=aNbS; ++i) {
218   //
219   //
220   // 2. Chains
221   //=================
222   myMVSD.Clear();
223   NMTDS_Iterator::FillMVSD(aMVSD, myMVSD);
224 }
225