4e57c75e |
1 | // Created by: Peter KURNEV |
973c2be1 |
2 | // Copyright (c) 2010-2014 OPEN CASCADE SAS |
4e57c75e |
3 | // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE |
4 | // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, |
5 | // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS |
6 | // |
973c2be1 |
7 | // This file is part of Open CASCADE Technology software library. |
4e57c75e |
8 | // |
d5f74e42 |
9 | // This library is free software; you can redistribute it and/or modify it under |
10 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
11 | // by the Free Software Foundation, with special exception defined in the file |
12 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
13 | // distribution for complete text of the license and disclaimer of any warranty. |
4e57c75e |
14 | // |
973c2be1 |
15 | // Alternatively, this file may be used under the terms of Open CASCADE |
16 | // commercial license or contractual agreement. |
4e57c75e |
17 | |
18 | #include <BOPDS_Iterator.ixx> |
19 | // |
20 | #include <Bnd_Box.hxx> |
21 | // |
22 | #include <NCollection_BaseAllocator.hxx> |
23 | #include <NCollection_UBTreeFiller.hxx> |
24 | // |
25 | #include <TopoDS.hxx> |
26 | #include <TopoDS_Vertex.hxx> |
27 | #include <TopoDS_Shape.hxx> |
28 | // |
29 | #include <BOPCol_IndexedDataMapOfShapeBox.hxx> |
30 | #include <BOPCol_DataMapOfIntegerInteger.hxx> |
31 | #include <BOPCol_DataMapOfIntegerMapOfInteger.hxx> |
32 | #include <BOPCol_MapOfInteger.hxx> |
33 | // |
db8e4b9a |
34 | #include <BOPCol_BoxBndTree.hxx> |
4e57c75e |
35 | #include <BOPDS_IndexRange.hxx> |
36 | #include <BOPDS_PassKeyBoolean.hxx> |
37 | #include <BOPDS_MapOfPassKeyBoolean.hxx> |
38 | #include <BOPDS_Tools.hxx> |
39 | #include <BOPDS_MapOfPassKeyBoolean.hxx> |
40 | |
41 | |
42 | //======================================================================= |
43 | //function : |
44 | //purpose : |
45 | //======================================================================= |
ceaa5e27 |
46 | BOPDS_Iterator::BOPDS_Iterator() |
4e57c75e |
47 | : |
48 | myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()) |
49 | { |
50 | myDS=NULL; |
51 | myLength=0; |
52 | // |
ceaa5e27 |
53 | myLists.SetStartSize(BOPDS_DS::NbInterfTypes()); |
4e57c75e |
54 | myLists.Init(); |
55 | } |
56 | //======================================================================= |
57 | //function : |
58 | //purpose : |
59 | //======================================================================= |
ceaa5e27 |
60 | BOPDS_Iterator::BOPDS_Iterator |
61 | (const Handle(NCollection_BaseAllocator)& theAllocator) |
4e57c75e |
62 | : |
63 | myAllocator(theAllocator), |
64 | myLists(theAllocator) |
65 | { |
66 | myDS=NULL; |
67 | myLength=0; |
68 | // |
ceaa5e27 |
69 | myLists.SetStartSize(BOPDS_DS::NbInterfTypes()); |
4e57c75e |
70 | myLists.Init(); |
71 | } |
72 | //======================================================================= |
73 | //function : ~ |
74 | //purpose : |
75 | //======================================================================= |
ceaa5e27 |
76 | BOPDS_Iterator::~BOPDS_Iterator() |
4e57c75e |
77 | { |
78 | } |
79 | //======================================================================= |
80 | // function: SetDS |
81 | // purpose: |
82 | //======================================================================= |
ceaa5e27 |
83 | void BOPDS_Iterator::SetDS(const BOPDS_PDS& aDS) |
4e57c75e |
84 | { |
85 | myDS=aDS; |
86 | } |
87 | //======================================================================= |
88 | // function: DS |
89 | // purpose: |
90 | //======================================================================= |
ceaa5e27 |
91 | const BOPDS_DS& BOPDS_Iterator::DS()const |
4e57c75e |
92 | { |
93 | return *myDS; |
94 | } |
95 | //======================================================================= |
96 | // function: ExpectedLength |
97 | // purpose: |
98 | //======================================================================= |
ceaa5e27 |
99 | Standard_Integer BOPDS_Iterator::ExpectedLength() const |
4e57c75e |
100 | { |
101 | return myLength; |
102 | } |
103 | //======================================================================= |
104 | // function: BlockLength |
105 | // purpose: |
106 | //======================================================================= |
ceaa5e27 |
107 | Standard_Integer BOPDS_Iterator::BlockLength() const |
4e57c75e |
108 | { |
109 | Standard_Integer aNbIIs; |
110 | Standard_Real aCfPredict=.5; |
111 | |
112 | aNbIIs=ExpectedLength(); |
113 | |
114 | if (aNbIIs<=1) { |
115 | return 1; |
116 | } |
117 | // |
118 | aNbIIs=(Standard_Integer) (aCfPredict*(Standard_Real)aNbIIs); |
119 | return aNbIIs; |
120 | } |
121 | //======================================================================= |
122 | // function: Initialize |
123 | // purpose: |
124 | //======================================================================= |
ceaa5e27 |
125 | void BOPDS_Iterator::Initialize(const TopAbs_ShapeEnum aType1, |
126 | const TopAbs_ShapeEnum aType2) |
4e57c75e |
127 | { |
128 | Standard_Integer iX; |
129 | // |
130 | myLength=0; |
131 | iX=BOPDS_Tools::TypeToInteger(aType1, aType2); |
132 | if (iX>=0) { |
133 | myIterator.Initialize(myLists(iX)); |
134 | myLength=myLists(iX).Extent(); |
135 | } |
136 | } |
137 | //======================================================================= |
138 | // function: More |
139 | // purpose: |
140 | //======================================================================= |
ceaa5e27 |
141 | Standard_Boolean BOPDS_Iterator::More()const |
4e57c75e |
142 | { |
143 | return myIterator.More(); |
144 | } |
145 | //======================================================================= |
146 | // function: Next |
147 | // purpose: |
148 | //======================================================================= |
ceaa5e27 |
149 | void BOPDS_Iterator::Next() |
4e57c75e |
150 | { |
151 | myIterator.Next(); |
152 | } |
153 | //======================================================================= |
154 | // function: Value |
155 | // purpose: |
156 | //======================================================================= |
ceaa5e27 |
157 | void BOPDS_Iterator::Value(Standard_Integer& theI1, |
158 | Standard_Integer& theI2, |
159 | Standard_Boolean& theWithSubShape) const |
4e57c75e |
160 | { |
161 | Standard_Integer iT1, iT2, n1, n2; |
162 | // |
163 | const BOPDS_PassKeyBoolean& aPKB=myIterator.Value(); |
164 | aPKB.Ids(n1, n2); |
165 | // |
166 | iT1=(Standard_Integer)(myDS->ShapeInfo(n1).ShapeType()); |
167 | iT2=(Standard_Integer)(myDS->ShapeInfo(n2).ShapeType()); |
168 | // |
169 | theI1=n1; |
170 | theI2=n2; |
171 | if (iT1<iT2) { |
172 | theI1=n2; |
173 | theI2=n1; |
174 | } |
175 | // |
176 | theWithSubShape=aPKB.Flag(); |
177 | } |
178 | |
179 | //======================================================================= |
180 | // function: Prepare |
181 | // purpose: |
182 | //======================================================================= |
ceaa5e27 |
183 | void BOPDS_Iterator::Prepare() |
4e57c75e |
184 | { |
ceaa5e27 |
185 | Standard_Integer i, aNbInterfTypes; |
4e57c75e |
186 | // |
ceaa5e27 |
187 | aNbInterfTypes=BOPDS_DS::NbInterfTypes(); |
4e57c75e |
188 | myLength=0; |
ceaa5e27 |
189 | for (i=0; i<aNbInterfTypes; ++i) { |
4e57c75e |
190 | myLists(i).Clear(); |
191 | } |
192 | // |
193 | if (myDS==NULL){ |
194 | return; |
195 | } |
196 | Intersect(); |
197 | } |
198 | //======================================================================= |
199 | // function: Intersect |
200 | // purpose: |
201 | //======================================================================= |
ceaa5e27 |
202 | void BOPDS_Iterator::Intersect() |
4e57c75e |
203 | { |
204 | Standard_Boolean bFlag; |
72e88cf7 |
205 | Standard_Integer aNb, i, aNbB, aNbR, iTi, iTj; |
4e57c75e |
206 | Standard_Integer i1, i2, aNbSD, iX, j, iDS, jB, iR; |
207 | TopAbs_ShapeEnum aTi, aTj; |
208 | Handle(NCollection_IncAllocator) aAllocator; |
209 | // |
210 | BOPCol_ListIteratorOfListOfInteger aIt; |
211 | // |
212 | //-----------------------------------------------------scope_1 f |
213 | aAllocator=new NCollection_IncAllocator(); |
214 | // |
215 | BOPCol_DataMapOfShapeInteger aMSI(100, aAllocator); |
216 | BOPCol_DataMapOfIntegerInteger aMII(100, aAllocator); |
217 | BOPDS_MapOfPassKeyBoolean aMPKXB(100, aAllocator); |
218 | BOPCol_IndexedDataMapOfShapeBox aMSB(100, aAllocator); |
219 | BOPDS_PassKeyBoolean aPKXB; |
220 | // |
db8e4b9a |
221 | BOPCol_BoxBndTreeSelector aSelector; |
222 | BOPCol_BoxBndTree aBBTree; |
4e57c75e |
223 | NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree); |
224 | // |
225 | aNb=myDS->NbSourceShapes(); |
226 | for (i=0; i<aNb; ++i) { |
227 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
228 | if (aSI.HasBRep()) { |
229 | const TopoDS_Shape& aS=aSI.Shape(); |
230 | const Bnd_Box& aBoxEx=aSI.Box(); |
231 | aMSI.Bind(aS, i); |
232 | aMSB.Add(aS, aBoxEx); |
233 | } |
234 | } |
235 | // |
236 | aNbB=aMSB.Extent(); |
237 | for (i=1; i<=aNbB; ++i) { |
238 | const TopoDS_Shape& aS=aMSB.FindKey(i); |
239 | const Bnd_Box& aBoxEx=aMSB(i); |
240 | // |
241 | aTreeFiller.Add(i, aBoxEx); |
242 | // |
243 | iDS=aMSI.Find(aS); |
244 | aMII.Bind(i, iDS); |
245 | } |
246 | // |
247 | aTreeFiller.Fill(); |
248 | // |
249 | aNbR=myDS->NbRanges()-1; |
250 | for (iR=0; iR<aNbR; ++iR) { |
251 | const BOPDS_IndexRange& aR=myDS->Range(iR); |
252 | i1=aR.First(); |
253 | i2=aR.Last(); |
254 | for (i=i1; i<=i2; ++i) { |
255 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
256 | // |
257 | if (!aSI.HasBRep()){ |
258 | continue; |
259 | } |
260 | // |
261 | aTi=aSI.ShapeType(); |
262 | const TopoDS_Shape& aSi=aSI.Shape(); |
263 | const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi); |
264 | aSelector.Clear(); |
265 | aSelector.SetBox(aBoxEx); |
266 | // |
267 | aNbSD=aBBTree.Select(aSelector); |
268 | if (!aNbSD){ |
269 | continue; |
270 | } |
271 | // |
272 | const Bnd_Box& aBoxi=myDS->ShapeInfo(i).Box(); |
273 | // |
274 | const BOPCol_ListOfInteger& aLI=aSelector.Indices(); |
275 | aIt.Initialize(aLI); |
276 | for (; aIt.More(); aIt.Next()) { |
277 | jB=aIt.Value(); // box index in MII |
278 | j=aMII.Find(jB); // DS index |
279 | if (j>=i1 && j<=i2) { |
280 | continue;// same range |
281 | } |
282 | // |
72e88cf7 |
283 | const BOPDS_ShapeInfo& aSIj=myDS->ShapeInfo(j); |
284 | aTj=aSIj.ShapeType(); |
285 | iTi=BOPDS_Tools::TypeToInteger(aTi); |
286 | iTj=BOPDS_Tools::TypeToInteger(aTj); |
287 | bFlag=Standard_False; |
288 | if (iTi<iTj) { |
289 | bFlag=aSI.HasSubShape(j); |
290 | } |
291 | else if (iTj<iTi) { |
292 | bFlag=aSIj.HasSubShape(i); |
293 | } |
294 | if (bFlag) { |
295 | continue; |
296 | } |
297 | // |
4e57c75e |
298 | aPKXB.SetIds(i, j); |
299 | if (aMPKXB.Add(aPKXB)) { |
300 | bFlag=Standard_False;// Bounding boxes are intersected |
301 | const Bnd_Box& aBoxj=myDS->ShapeInfo(j).Box(); |
302 | if (aBoxi.IsOut(aBoxj)) { |
303 | bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected |
304 | } |
305 | // |
4e57c75e |
306 | iX=BOPDS_Tools::TypeToInteger(aTi, aTj); |
307 | aPKXB.SetFlag(bFlag); |
308 | myLists(iX).Append(aPKXB); |
309 | }// if (aMPKXB.Add(aPKXB)) { |
310 | }// for (; aIt.More(); aIt.Next()) { |
311 | }//for (i=i1; i<=i2; ++i) { |
312 | }//for (iR=1; iR<aNbR; ++iR) { |
313 | // |
314 | aMSI.Clear(); |
315 | aMII.Clear(); |
316 | aMPKXB.Clear(); |
317 | aMSB.Clear(); |
318 | // |
319 | aAllocator.Nullify(); |
320 | //-----------------------------------------------------scope_1 t |
321 | } |