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