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.
19 #include <Bnd_Box.hxx>
20 #include <BOPCol_BoxBndTree.hxx>
21 #include <BOPCol_NCVector.hxx>
22 #include <BOPCol_Parallel.hxx>
23 #include <BOPDS_DS.hxx>
24 #include <BOPDS_IndexRange.hxx>
25 #include <BOPDS_Iterator.hxx>
26 #include <BOPDS_MapOfPassKeyBoolean.hxx>
27 #include <BOPDS_PassKeyBoolean.hxx>
28 #include <BOPDS_Tools.hxx>
29 #include <NCollection_UBTreeFiller.hxx>
30 #include <TopoDS_Shape.hxx>
37 /////////////////////////////////////////////////////////////////////////
38 //=======================================================================
39 //class : BOPDS_TreeSelector
41 //=======================================================================
42 class BOPDS_TSR : public BOPCol_BoxBndTreeSelector{
45 BOPCol_BoxBndTreeSelector(),
46 myHasBRep(Standard_False),
50 virtual ~BOPDS_TSR() {
53 void SetHasBRep(const Standard_Boolean bFlag) {
57 void SetTree(BOPCol_BoxBndTree& aTree) {
63 myTree->Select(*this);
68 Standard_Boolean myHasBRep;
69 BOPCol_BoxBndTree *myTree;
72 //=======================================================================
73 typedef BOPCol_NCVector <BOPDS_TSR> BOPDS_VectorOfTSR;
74 typedef BOPCol_Functor <BOPDS_TSR,BOPDS_VectorOfTSR> BOPDS_TSRFunctor;
75 typedef BOPCol_Cnt <BOPDS_TSRFunctor, BOPDS_VectorOfTSR> BOPDS_TSRCnt;
76 /////////////////////////////////////////////////////////////////////////
79 //=======================================================================
82 //=======================================================================
83 BOPDS_Iterator::BOPDS_Iterator()
85 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
86 myRunParallel(Standard_False)
88 Standard_Integer i, aNb;
93 aNb=BOPDS_DS::NbInterfTypes();
94 myLists.SetIncrement(aNb);
95 for (i=0; i<aNb; ++i) {
99 //=======================================================================
102 //=======================================================================
103 BOPDS_Iterator::BOPDS_Iterator
104 (const Handle(NCollection_BaseAllocator)& theAllocator)
106 myAllocator(theAllocator),
107 myLists(0, theAllocator),
108 myRunParallel(Standard_False)
110 Standard_Integer i, aNb;
115 aNb=BOPDS_DS::NbInterfTypes();
116 myLists.SetIncrement(aNb);
117 for (i=0; i<aNb; ++i) {
121 //=======================================================================
124 //=======================================================================
125 BOPDS_Iterator::~BOPDS_Iterator()
128 //=======================================================================
129 //function : SetRunParallel
131 //=======================================================================
132 void BOPDS_Iterator::SetRunParallel(const Standard_Boolean theFlag)
134 myRunParallel=theFlag;
136 //=======================================================================
137 //function : RunParallel
139 //=======================================================================
140 Standard_Boolean BOPDS_Iterator::RunParallel()const
142 return myRunParallel;
144 //=======================================================================
147 //=======================================================================
148 void BOPDS_Iterator::SetDS(const BOPDS_PDS& aDS)
152 //=======================================================================
155 //=======================================================================
156 const BOPDS_DS& BOPDS_Iterator::DS()const
160 //=======================================================================
161 // function: ExpectedLength
163 //=======================================================================
164 Standard_Integer BOPDS_Iterator::ExpectedLength() const
168 //=======================================================================
169 // function: BlockLength
171 //=======================================================================
172 Standard_Integer BOPDS_Iterator::BlockLength() const
174 Standard_Integer aNbIIs;
175 Standard_Real aCfPredict=.5;
177 aNbIIs=ExpectedLength();
183 aNbIIs=(Standard_Integer) (aCfPredict*(Standard_Real)aNbIIs);
186 //=======================================================================
187 // function: Initialize
189 //=======================================================================
190 void BOPDS_Iterator::Initialize(const TopAbs_ShapeEnum aType1,
191 const TopAbs_ShapeEnum aType2)
196 iX=BOPDS_Tools::TypeToInteger(aType1, aType2);
198 myIterator.Initialize(myLists(iX));
199 myLength=myLists(iX).Extent();
202 //=======================================================================
205 //=======================================================================
206 Standard_Boolean BOPDS_Iterator::More()const
208 return myIterator.More();
210 //=======================================================================
213 //=======================================================================
214 void BOPDS_Iterator::Next()
218 //=======================================================================
221 //=======================================================================
222 void BOPDS_Iterator::Value
223 (Standard_Integer& theI1,
224 Standard_Integer& theI2,
225 Standard_Boolean& theWithSubShape) const
227 Standard_Integer iT1, iT2, n1, n2;
229 const BOPDS_PassKeyBoolean& aPKB=myIterator.Value();
232 iT1=(Standard_Integer)(myDS->ShapeInfo(n1).ShapeType());
233 iT2=(Standard_Integer)(myDS->ShapeInfo(n2).ShapeType());
242 theWithSubShape=aPKB.Flag();
244 //=======================================================================
247 //=======================================================================
248 void BOPDS_Iterator::Prepare()
250 Standard_Integer i, aNbInterfTypes;
252 aNbInterfTypes=BOPDS_DS::NbInterfTypes();
254 for (i=0; i<aNbInterfTypes; ++i) {
264 //=======================================================================
265 // function: Intersect
267 //=======================================================================
268 void BOPDS_Iterator::Intersect()
270 Standard_Boolean bFlag;
271 Standard_Integer aNb, i, aNbR, iTi, iTj;
272 Standard_Integer i1, i2, aNbSD, iX, j, iR;
273 TopAbs_ShapeEnum aTi, aTj;
274 Handle(NCollection_BaseAllocator) aAllocator;
275 BOPCol_ListIteratorOfListOfInteger aIt;
277 //-----------------------------------------------------scope_1 f
278 aAllocator=NCollection_BaseAllocator::CommonBaseAllocator();
280 BOPDS_MapOfPassKeyBoolean aMPKXB(100, aAllocator);
281 BOPDS_PassKeyBoolean aPKXB;
283 BOPCol_BoxBndTreeSelector aSelector;
284 BOPCol_BoxBndTree aBBTree;
285 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
287 aNb=myDS->NbSourceShapes();
288 BOPDS_VectorOfTSR aVTSR(aNb, aAllocator);
290 for (i=0; i<aNb; ++i) {
291 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
292 bFlag=aSI.IsInterfering();
294 BOPDS_TSR& aTSR=aVTSR.Append1();
296 aTSR.SetHasBRep(bFlag);
301 const Bnd_Box& aBoxEx=aSI.Box();
302 aTSR.SetTree(aBBTree);
305 aTreeFiller.Add(i, aBoxEx);
310 //===========================================
311 BOPDS_TSRCnt::Perform(myRunParallel, aVTSR);
312 //===========================================
314 aNbR=myDS->NbRanges()-1;
315 for (iR=0; iR<aNbR; ++iR) {
316 const BOPDS_IndexRange& aR=myDS->Range(iR);
319 for (i=i1; i<=i2; ++i) {
320 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
322 if (!aSI.IsInterfering()){
327 const Bnd_Box& aBoxi=aSI.Box();
329 BOPDS_TSR& aTSRi=aVTSR(i);
330 const BOPCol_ListOfInteger& aLI=aTSRi.Indices();
337 for (; aIt.More(); aIt.Next()) {
338 j=aIt.Value(); // DS index
339 if (j>=i1 && j<=i2) {
340 continue;// same range
343 const BOPDS_ShapeInfo& aSIj=myDS->ShapeInfo(j);
344 aTj=aSIj.ShapeType();
345 iTi=BOPDS_Tools::TypeToInteger(aTi);
346 iTj=BOPDS_Tools::TypeToInteger(aTj);
348 bFlag=Standard_False;
350 bFlag=aSI.HasSubShape(j);
353 bFlag=aSIj.HasSubShape(i);
360 if (aMPKXB.Add(aPKXB)) {
361 bFlag=Standard_False;// Bounding boxes are intersected
362 const Bnd_Box& aBoxj=aSIj.Box();
363 if (aBoxi.IsOut(aBoxj)) {
364 bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
367 iX=BOPDS_Tools::TypeToInteger(aTi, aTj);
368 aPKXB.SetFlag(bFlag);
369 myLists(iX).Append(aPKXB);
370 }// if (aMPKXB.Add(aPKXB)) {
371 }// for (; aIt.More(); aIt.Next()) {
372 }//for (i=i1; i<=i2; ++i) {
373 }//for (iR=1; iR<aNbR; ++iR) {
377 //-----------------------------------------------------scope_1 t