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