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 | |
42cf5bc1 |
18 | |
4e57c75e |
19 | #include <Bnd_Box.hxx> |
42cf5bc1 |
20 | #include <BOPCol_BoxBndTree.hxx> |
a2098360 |
21 | #include <BOPCol_NCVector.hxx> |
c7b59798 |
22 | #include <BOPCol_Parallel.hxx> |
42cf5bc1 |
23 | #include <BOPDS_DS.hxx> |
4e57c75e |
24 | #include <BOPDS_IndexRange.hxx> |
42cf5bc1 |
25 | #include <BOPDS_Iterator.hxx> |
4e57c75e |
26 | #include <BOPDS_MapOfPassKeyBoolean.hxx> |
42cf5bc1 |
27 | #include <BOPDS_PassKeyBoolean.hxx> |
4e57c75e |
28 | #include <BOPDS_Tools.hxx> |
42cf5bc1 |
29 | #include <NCollection_IncAllocator.hxx> |
30 | #include <NCollection_UBTreeFiller.hxx> |
31 | #include <TopoDS_Shape.hxx> |
a2098360 |
32 | |
42cf5bc1 |
33 | // |
34 | // |
35 | // |
36 | // |
37 | // |
a2098360 |
38 | ///////////////////////////////////////////////////////////////////////// |
39 | //======================================================================= |
40 | //class : BOPDS_TreeSelector |
41 | //purpose : |
42 | //======================================================================= |
43 | class BOPDS_TSR : public BOPCol_BoxBndTreeSelector{ |
44 | public: |
45 | BOPDS_TSR() : |
46 | BOPCol_BoxBndTreeSelector(), |
47 | myHasBRep(Standard_False), |
48 | myTree(NULL) { |
49 | } |
50 | // |
51 | virtual ~BOPDS_TSR() { |
52 | } |
53 | // |
54 | void SetHasBRep(const Standard_Boolean bFlag) { |
55 | myHasBRep=bFlag; |
56 | } |
57 | // |
58 | void SetTree(BOPCol_BoxBndTree& aTree) { |
59 | myTree=&aTree; |
60 | } |
61 | // |
62 | void Perform() { |
63 | if (myHasBRep) { |
64 | myTree->Select(*this); |
65 | } |
66 | } |
67 | // |
68 | protected: |
69 | Standard_Boolean myHasBRep; |
70 | BOPCol_BoxBndTree *myTree; |
71 | }; |
72 | // |
73 | //======================================================================= |
74 | typedef BOPCol_NCVector <BOPDS_TSR> BOPDS_VectorOfTSR; |
c7b59798 |
75 | typedef BOPCol_Functor <BOPDS_TSR,BOPDS_VectorOfTSR> BOPDS_TSRFunctor; |
76 | typedef BOPCol_Cnt <BOPDS_TSRFunctor, BOPDS_VectorOfTSR> BOPDS_TSRCnt; |
a2098360 |
77 | ///////////////////////////////////////////////////////////////////////// |
4e57c75e |
78 | |
79 | |
80 | //======================================================================= |
81 | //function : |
82 | //purpose : |
83 | //======================================================================= |
ceaa5e27 |
84 | BOPDS_Iterator::BOPDS_Iterator() |
4e57c75e |
85 | : |
a2098360 |
86 | myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()), |
87 | myRunParallel(Standard_False) |
4e57c75e |
88 | { |
402bfe81 |
89 | Standard_Integer i, aNb; |
90 | // |
4e57c75e |
91 | myDS=NULL; |
92 | myLength=0; |
93 | // |
402bfe81 |
94 | aNb=BOPDS_DS::NbInterfTypes(); |
95 | myLists.SetIncrement(aNb); |
96 | for (i=0; i<aNb; ++i) { |
97 | myLists.Append1(); |
98 | } |
4e57c75e |
99 | } |
100 | //======================================================================= |
101 | //function : |
102 | //purpose : |
103 | //======================================================================= |
ceaa5e27 |
104 | BOPDS_Iterator::BOPDS_Iterator |
105 | (const Handle(NCollection_BaseAllocator)& theAllocator) |
4e57c75e |
106 | : |
107 | myAllocator(theAllocator), |
402bfe81 |
108 | myLists(0, theAllocator), |
a2098360 |
109 | myRunParallel(Standard_False) |
4e57c75e |
110 | { |
402bfe81 |
111 | Standard_Integer i, aNb; |
112 | // |
4e57c75e |
113 | myDS=NULL; |
114 | myLength=0; |
115 | // |
402bfe81 |
116 | aNb=BOPDS_DS::NbInterfTypes(); |
117 | myLists.SetIncrement(aNb); |
118 | for (i=0; i<aNb; ++i) { |
119 | myLists.Append1(); |
120 | } |
4e57c75e |
121 | } |
122 | //======================================================================= |
123 | //function : ~ |
124 | //purpose : |
125 | //======================================================================= |
ceaa5e27 |
126 | BOPDS_Iterator::~BOPDS_Iterator() |
4e57c75e |
127 | { |
128 | } |
129 | //======================================================================= |
a2098360 |
130 | //function : SetRunParallel |
131 | //purpose : |
132 | //======================================================================= |
133 | void BOPDS_Iterator::SetRunParallel(const Standard_Boolean theFlag) |
134 | { |
135 | myRunParallel=theFlag; |
136 | } |
137 | //======================================================================= |
138 | //function : RunParallel |
139 | //purpose : |
140 | //======================================================================= |
141 | Standard_Boolean BOPDS_Iterator::RunParallel()const |
142 | { |
143 | return myRunParallel; |
144 | } |
145 | //======================================================================= |
4e57c75e |
146 | // function: SetDS |
147 | // purpose: |
148 | //======================================================================= |
ceaa5e27 |
149 | void BOPDS_Iterator::SetDS(const BOPDS_PDS& aDS) |
4e57c75e |
150 | { |
151 | myDS=aDS; |
152 | } |
153 | //======================================================================= |
154 | // function: DS |
155 | // purpose: |
156 | //======================================================================= |
ceaa5e27 |
157 | const BOPDS_DS& BOPDS_Iterator::DS()const |
4e57c75e |
158 | { |
159 | return *myDS; |
160 | } |
161 | //======================================================================= |
162 | // function: ExpectedLength |
163 | // purpose: |
164 | //======================================================================= |
ceaa5e27 |
165 | Standard_Integer BOPDS_Iterator::ExpectedLength() const |
4e57c75e |
166 | { |
167 | return myLength; |
168 | } |
169 | //======================================================================= |
170 | // function: BlockLength |
171 | // purpose: |
172 | //======================================================================= |
ceaa5e27 |
173 | Standard_Integer BOPDS_Iterator::BlockLength() const |
4e57c75e |
174 | { |
175 | Standard_Integer aNbIIs; |
176 | Standard_Real aCfPredict=.5; |
177 | |
178 | aNbIIs=ExpectedLength(); |
179 | |
180 | if (aNbIIs<=1) { |
181 | return 1; |
182 | } |
183 | // |
184 | aNbIIs=(Standard_Integer) (aCfPredict*(Standard_Real)aNbIIs); |
185 | return aNbIIs; |
186 | } |
187 | //======================================================================= |
188 | // function: Initialize |
189 | // purpose: |
190 | //======================================================================= |
ceaa5e27 |
191 | void BOPDS_Iterator::Initialize(const TopAbs_ShapeEnum aType1, |
a2098360 |
192 | const TopAbs_ShapeEnum aType2) |
4e57c75e |
193 | { |
194 | Standard_Integer iX; |
195 | // |
196 | myLength=0; |
197 | iX=BOPDS_Tools::TypeToInteger(aType1, aType2); |
198 | if (iX>=0) { |
199 | myIterator.Initialize(myLists(iX)); |
200 | myLength=myLists(iX).Extent(); |
201 | } |
202 | } |
203 | //======================================================================= |
204 | // function: More |
205 | // purpose: |
206 | //======================================================================= |
ceaa5e27 |
207 | Standard_Boolean BOPDS_Iterator::More()const |
4e57c75e |
208 | { |
209 | return myIterator.More(); |
210 | } |
211 | //======================================================================= |
212 | // function: Next |
213 | // purpose: |
214 | //======================================================================= |
ceaa5e27 |
215 | void BOPDS_Iterator::Next() |
4e57c75e |
216 | { |
217 | myIterator.Next(); |
218 | } |
219 | //======================================================================= |
220 | // function: Value |
221 | // purpose: |
222 | //======================================================================= |
a2098360 |
223 | void BOPDS_Iterator::Value |
224 | (Standard_Integer& theI1, |
225 | Standard_Integer& theI2, |
226 | Standard_Boolean& theWithSubShape) const |
4e57c75e |
227 | { |
228 | Standard_Integer iT1, iT2, n1, n2; |
229 | // |
230 | const BOPDS_PassKeyBoolean& aPKB=myIterator.Value(); |
231 | aPKB.Ids(n1, n2); |
232 | // |
233 | iT1=(Standard_Integer)(myDS->ShapeInfo(n1).ShapeType()); |
234 | iT2=(Standard_Integer)(myDS->ShapeInfo(n2).ShapeType()); |
235 | // |
236 | theI1=n1; |
237 | theI2=n2; |
238 | if (iT1<iT2) { |
239 | theI1=n2; |
240 | theI2=n1; |
241 | } |
242 | // |
243 | theWithSubShape=aPKB.Flag(); |
244 | } |
4e57c75e |
245 | //======================================================================= |
246 | // function: Prepare |
247 | // purpose: |
248 | //======================================================================= |
ceaa5e27 |
249 | void BOPDS_Iterator::Prepare() |
4e57c75e |
250 | { |
ceaa5e27 |
251 | Standard_Integer i, aNbInterfTypes; |
4e57c75e |
252 | // |
ceaa5e27 |
253 | aNbInterfTypes=BOPDS_DS::NbInterfTypes(); |
4e57c75e |
254 | myLength=0; |
ceaa5e27 |
255 | for (i=0; i<aNbInterfTypes; ++i) { |
4e57c75e |
256 | myLists(i).Clear(); |
257 | } |
258 | // |
259 | if (myDS==NULL){ |
260 | return; |
261 | } |
262 | Intersect(); |
263 | } |
a2098360 |
264 | // |
4e57c75e |
265 | //======================================================================= |
266 | // function: Intersect |
267 | // purpose: |
268 | //======================================================================= |
ceaa5e27 |
269 | void BOPDS_Iterator::Intersect() |
4e57c75e |
270 | { |
271 | Standard_Boolean bFlag; |
a2098360 |
272 | Standard_Integer aNb, i, aNbR, iTi, iTj; |
273 | Standard_Integer i1, i2, aNbSD, iX, j, iR; |
4e57c75e |
274 | TopAbs_ShapeEnum aTi, aTj; |
275 | Handle(NCollection_IncAllocator) aAllocator; |
4e57c75e |
276 | BOPCol_ListIteratorOfListOfInteger aIt; |
277 | // |
278 | //-----------------------------------------------------scope_1 f |
279 | aAllocator=new NCollection_IncAllocator(); |
280 | // |
4e57c75e |
281 | BOPDS_MapOfPassKeyBoolean aMPKXB(100, aAllocator); |
4e57c75e |
282 | BOPDS_PassKeyBoolean aPKXB; |
283 | // |
db8e4b9a |
284 | BOPCol_BoxBndTreeSelector aSelector; |
285 | BOPCol_BoxBndTree aBBTree; |
4e57c75e |
286 | NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree); |
287 | // |
288 | aNb=myDS->NbSourceShapes(); |
a2098360 |
289 | BOPDS_VectorOfTSR aVTSR(aNb, aAllocator); |
290 | // |
4e57c75e |
291 | for (i=0; i<aNb; ++i) { |
292 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
955b3e71 |
293 | bFlag=aSI.IsInterfering(); |
a2098360 |
294 | // |
295 | BOPDS_TSR& aTSR=aVTSR.Append1(); |
296 | // |
297 | aTSR.SetHasBRep(bFlag); |
298 | if (!bFlag) { |
299 | continue; |
4e57c75e |
300 | } |
4e57c75e |
301 | // |
a2098360 |
302 | const Bnd_Box& aBoxEx=aSI.Box(); |
303 | aTSR.SetTree(aBBTree); |
304 | aTSR.SetBox(aBoxEx); |
4e57c75e |
305 | // |
a2098360 |
306 | aTreeFiller.Add(i, aBoxEx); |
4e57c75e |
307 | } |
308 | // |
309 | aTreeFiller.Fill(); |
310 | // |
a2098360 |
311 | //=========================================== |
312 | BOPDS_TSRCnt::Perform(myRunParallel, aVTSR); |
313 | //=========================================== |
314 | // |
4e57c75e |
315 | aNbR=myDS->NbRanges()-1; |
316 | for (iR=0; iR<aNbR; ++iR) { |
317 | const BOPDS_IndexRange& aR=myDS->Range(iR); |
318 | i1=aR.First(); |
319 | i2=aR.Last(); |
320 | for (i=i1; i<=i2; ++i) { |
321 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
322 | // |
955b3e71 |
323 | if (!aSI.IsInterfering()){ |
a2098360 |
324 | continue; |
4e57c75e |
325 | } |
326 | // |
327 | aTi=aSI.ShapeType(); |
a2098360 |
328 | const Bnd_Box& aBoxi=aSI.Box(); |
4e57c75e |
329 | // |
a2098360 |
330 | BOPDS_TSR& aTSRi=aVTSR(i); |
331 | const BOPCol_ListOfInteger& aLI=aTSRi.Indices(); |
332 | aNbSD=aLI.Extent(); |
4e57c75e |
333 | if (!aNbSD){ |
a2098360 |
334 | continue; |
4e57c75e |
335 | } |
336 | // |
4e57c75e |
337 | aIt.Initialize(aLI); |
338 | for (; aIt.More(); aIt.Next()) { |
a2098360 |
339 | j=aIt.Value(); // DS index |
340 | if (j>=i1 && j<=i2) { |
341 | continue;// same range |
342 | } |
343 | // |
344 | const BOPDS_ShapeInfo& aSIj=myDS->ShapeInfo(j); |
345 | aTj=aSIj.ShapeType(); |
346 | iTi=BOPDS_Tools::TypeToInteger(aTi); |
347 | iTj=BOPDS_Tools::TypeToInteger(aTj); |
348 | // |
349 | bFlag=Standard_False; |
350 | if (iTi<iTj) { |
351 | bFlag=aSI.HasSubShape(j); |
352 | } |
353 | else if (iTj<iTi) { |
354 | bFlag=aSIj.HasSubShape(i); |
355 | } |
356 | if (bFlag) { |
357 | continue; |
358 | } |
359 | // |
360 | aPKXB.SetIds(i, j); |
361 | if (aMPKXB.Add(aPKXB)) { |
362 | bFlag=Standard_False;// Bounding boxes are intersected |
363 | const Bnd_Box& aBoxj=aSIj.Box(); |
364 | if (aBoxi.IsOut(aBoxj)) { |
365 | bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected |
366 | } |
367 | // |
368 | iX=BOPDS_Tools::TypeToInteger(aTi, aTj); |
369 | aPKXB.SetFlag(bFlag); |
370 | myLists(iX).Append(aPKXB); |
371 | }// if (aMPKXB.Add(aPKXB)) { |
4e57c75e |
372 | }// for (; aIt.More(); aIt.Next()) { |
373 | }//for (i=i1; i<=i2; ++i) { |
374 | }//for (iR=1; iR<aNbR; ++iR) { |
375 | // |
4e57c75e |
376 | aMPKXB.Clear(); |
a2098360 |
377 | aVTSR.Clear(); |
4e57c75e |
378 | aAllocator.Nullify(); |
379 | //-----------------------------------------------------scope_1 t |
380 | } |