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