1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
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
7 // This file is part of Open CASCADE Technology software library.
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
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.
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
18 #include <BOPDS_Iterator.ixx>
20 #include <Bnd_Box.hxx>
22 #include <NCollection_IncAllocator.hxx>
23 #include <NCollection_UBTreeFiller.hxx>
25 #include <TopoDS_Shape.hxx>
27 #include <BOPCol_NCVector.hxx>
28 #include <BOPCol_TBB.hxx>
29 #include <BOPCol_BoxBndTree.hxx>
31 #include <BOPDS_IndexRange.hxx>
32 #include <BOPDS_PassKeyBoolean.hxx>
33 #include <BOPDS_MapOfPassKeyBoolean.hxx>
34 #include <BOPDS_Tools.hxx>
36 /////////////////////////////////////////////////////////////////////////
37 //=======================================================================
38 //class : BOPDS_TreeSelector
40 //=======================================================================
41 class BOPDS_TSR : public BOPCol_BoxBndTreeSelector{
44 BOPCol_BoxBndTreeSelector(),
45 myHasBRep(Standard_False),
49 virtual ~BOPDS_TSR() {
52 void SetHasBRep(const Standard_Boolean bFlag) {
56 void SetTree(BOPCol_BoxBndTree& aTree) {
62 myTree->Select(*this);
67 Standard_Boolean myHasBRep;
68 BOPCol_BoxBndTree *myTree;
71 //=======================================================================
72 typedef BOPCol_NCVector <BOPDS_TSR> BOPDS_VectorOfTSR;
73 typedef BOPCol_TBBFunctor <BOPDS_TSR,BOPDS_VectorOfTSR> BOPDS_TSRFunctor;
74 typedef BOPCol_TBBCnt <BOPDS_TSRFunctor, BOPDS_VectorOfTSR> BOPDS_TSRCnt;
75 /////////////////////////////////////////////////////////////////////////
78 //=======================================================================
81 //=======================================================================
82 BOPDS_Iterator::BOPDS_Iterator()
84 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
85 myRunParallel(Standard_False)
90 myLists.SetStartSize(BOPDS_DS::NbInterfTypes());
93 //=======================================================================
96 //=======================================================================
97 BOPDS_Iterator::BOPDS_Iterator
98 (const Handle(NCollection_BaseAllocator)& theAllocator)
100 myAllocator(theAllocator),
101 myLists(theAllocator),
102 myRunParallel(Standard_False)
107 myLists.SetStartSize(BOPDS_DS::NbInterfTypes());
110 //=======================================================================
113 //=======================================================================
114 BOPDS_Iterator::~BOPDS_Iterator()
117 //=======================================================================
118 //function : SetRunParallel
120 //=======================================================================
121 void BOPDS_Iterator::SetRunParallel(const Standard_Boolean theFlag)
123 myRunParallel=theFlag;
125 //=======================================================================
126 //function : RunParallel
128 //=======================================================================
129 Standard_Boolean BOPDS_Iterator::RunParallel()const
131 return myRunParallel;
133 //=======================================================================
136 //=======================================================================
137 void BOPDS_Iterator::SetDS(const BOPDS_PDS& aDS)
141 //=======================================================================
144 //=======================================================================
145 const BOPDS_DS& BOPDS_Iterator::DS()const
149 //=======================================================================
150 // function: ExpectedLength
152 //=======================================================================
153 Standard_Integer BOPDS_Iterator::ExpectedLength() const
157 //=======================================================================
158 // function: BlockLength
160 //=======================================================================
161 Standard_Integer BOPDS_Iterator::BlockLength() const
163 Standard_Integer aNbIIs;
164 Standard_Real aCfPredict=.5;
166 aNbIIs=ExpectedLength();
172 aNbIIs=(Standard_Integer) (aCfPredict*(Standard_Real)aNbIIs);
175 //=======================================================================
176 // function: Initialize
178 //=======================================================================
179 void BOPDS_Iterator::Initialize(const TopAbs_ShapeEnum aType1,
180 const TopAbs_ShapeEnum aType2)
185 iX=BOPDS_Tools::TypeToInteger(aType1, aType2);
187 myIterator.Initialize(myLists(iX));
188 myLength=myLists(iX).Extent();
191 //=======================================================================
194 //=======================================================================
195 Standard_Boolean BOPDS_Iterator::More()const
197 return myIterator.More();
199 //=======================================================================
202 //=======================================================================
203 void BOPDS_Iterator::Next()
207 //=======================================================================
210 //=======================================================================
211 void BOPDS_Iterator::Value
212 (Standard_Integer& theI1,
213 Standard_Integer& theI2,
214 Standard_Boolean& theWithSubShape) const
216 Standard_Integer iT1, iT2, n1, n2;
218 const BOPDS_PassKeyBoolean& aPKB=myIterator.Value();
221 iT1=(Standard_Integer)(myDS->ShapeInfo(n1).ShapeType());
222 iT2=(Standard_Integer)(myDS->ShapeInfo(n2).ShapeType());
231 theWithSubShape=aPKB.Flag();
233 //=======================================================================
236 //=======================================================================
237 void BOPDS_Iterator::Prepare()
239 Standard_Integer i, aNbInterfTypes;
241 aNbInterfTypes=BOPDS_DS::NbInterfTypes();
243 for (i=0; i<aNbInterfTypes; ++i) {
253 //=======================================================================
254 // function: Intersect
256 //=======================================================================
257 void BOPDS_Iterator::Intersect()
259 Standard_Boolean bFlag;
260 Standard_Integer aNb, i, aNbR, iTi, iTj;
261 Standard_Integer i1, i2, aNbSD, iX, j, iR;
262 TopAbs_ShapeEnum aTi, aTj;
263 Handle(NCollection_IncAllocator) aAllocator;
264 BOPCol_ListIteratorOfListOfInteger aIt;
266 //-----------------------------------------------------scope_1 f
267 aAllocator=new NCollection_IncAllocator();
269 BOPDS_MapOfPassKeyBoolean aMPKXB(100, aAllocator);
270 BOPDS_PassKeyBoolean aPKXB;
272 BOPCol_BoxBndTreeSelector aSelector;
273 BOPCol_BoxBndTree aBBTree;
274 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
276 aNb=myDS->NbSourceShapes();
277 BOPDS_VectorOfTSR aVTSR(aNb, aAllocator);
279 for (i=0; i<aNb; ++i) {
280 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
283 BOPDS_TSR& aTSR=aVTSR.Append1();
285 aTSR.SetHasBRep(bFlag);
290 const Bnd_Box& aBoxEx=aSI.Box();
291 aTSR.SetTree(aBBTree);
294 aTreeFiller.Add(i, aBoxEx);
299 //===========================================
300 BOPDS_TSRCnt::Perform(myRunParallel, aVTSR);
301 //===========================================
303 aNbR=myDS->NbRanges()-1;
304 for (iR=0; iR<aNbR; ++iR) {
305 const BOPDS_IndexRange& aR=myDS->Range(iR);
308 for (i=i1; i<=i2; ++i) {
309 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
316 const Bnd_Box& aBoxi=aSI.Box();
318 BOPDS_TSR& aTSRi=aVTSR(i);
319 const BOPCol_ListOfInteger& aLI=aTSRi.Indices();
326 for (; aIt.More(); aIt.Next()) {
327 j=aIt.Value(); // DS index
328 if (j>=i1 && j<=i2) {
329 continue;// same range
332 const BOPDS_ShapeInfo& aSIj=myDS->ShapeInfo(j);
333 aTj=aSIj.ShapeType();
334 iTi=BOPDS_Tools::TypeToInteger(aTi);
335 iTj=BOPDS_Tools::TypeToInteger(aTj);
337 bFlag=Standard_False;
339 bFlag=aSI.HasSubShape(j);
342 bFlag=aSIj.HasSubShape(i);
349 if (aMPKXB.Add(aPKXB)) {
350 bFlag=Standard_False;// Bounding boxes are intersected
351 const Bnd_Box& aBoxj=aSIj.Box();
352 if (aBoxi.IsOut(aBoxj)) {
353 bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
356 iX=BOPDS_Tools::TypeToInteger(aTi, aTj);
357 aPKXB.SetFlag(bFlag);
358 myLists(iX).Append(aPKXB);
359 }// if (aMPKXB.Add(aPKXB)) {
360 }// for (; aIt.More(); aIt.Next()) {
361 }//for (i=i1; i<=i2; ++i) {
362 }//for (iR=1; iR<aNbR; ++iR) {
366 aAllocator.Nullify();
367 //-----------------------------------------------------scope_1 t