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