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
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.
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_BaseAllocator.hxx>
23 #include <NCollection_UBTreeFiller.hxx>
26 #include <TopoDS_Vertex.hxx>
27 #include <TopoDS_Shape.hxx>
29 #include <BOPCol_IndexedDataMapOfShapeBox.hxx>
30 #include <BOPCol_DataMapOfIntegerInteger.hxx>
31 #include <BOPCol_DataMapOfIntegerMapOfInteger.hxx>
32 #include <BOPCol_MapOfInteger.hxx>
34 #include <BOPCol_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>
42 //=======================================================================
45 //=======================================================================
46 BOPDS_Iterator::BOPDS_Iterator()
48 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator())
53 myLists.SetStartSize(BOPDS_DS::NbInterfTypes());
56 //=======================================================================
59 //=======================================================================
60 BOPDS_Iterator::BOPDS_Iterator
61 (const Handle(NCollection_BaseAllocator)& theAllocator)
63 myAllocator(theAllocator),
69 myLists.SetStartSize(BOPDS_DS::NbInterfTypes());
72 //=======================================================================
75 //=======================================================================
76 BOPDS_Iterator::~BOPDS_Iterator()
79 //=======================================================================
82 //=======================================================================
83 void BOPDS_Iterator::SetDS(const BOPDS_PDS& aDS)
87 //=======================================================================
90 //=======================================================================
91 const BOPDS_DS& BOPDS_Iterator::DS()const
95 //=======================================================================
96 // function: ExpectedLength
98 //=======================================================================
99 Standard_Integer BOPDS_Iterator::ExpectedLength() const
103 //=======================================================================
104 // function: BlockLength
106 //=======================================================================
107 Standard_Integer BOPDS_Iterator::BlockLength() const
109 Standard_Integer aNbIIs;
110 Standard_Real aCfPredict=.5;
112 aNbIIs=ExpectedLength();
118 aNbIIs=(Standard_Integer) (aCfPredict*(Standard_Real)aNbIIs);
121 //=======================================================================
122 // function: Initialize
124 //=======================================================================
125 void BOPDS_Iterator::Initialize(const TopAbs_ShapeEnum aType1,
126 const TopAbs_ShapeEnum aType2)
131 iX=BOPDS_Tools::TypeToInteger(aType1, aType2);
133 myIterator.Initialize(myLists(iX));
134 myLength=myLists(iX).Extent();
137 //=======================================================================
140 //=======================================================================
141 Standard_Boolean BOPDS_Iterator::More()const
143 return myIterator.More();
145 //=======================================================================
148 //=======================================================================
149 void BOPDS_Iterator::Next()
153 //=======================================================================
156 //=======================================================================
157 void BOPDS_Iterator::Value(Standard_Integer& theI1,
158 Standard_Integer& theI2,
159 Standard_Boolean& theWithSubShape) const
161 Standard_Integer iT1, iT2, n1, n2;
163 const BOPDS_PassKeyBoolean& aPKB=myIterator.Value();
166 iT1=(Standard_Integer)(myDS->ShapeInfo(n1).ShapeType());
167 iT2=(Standard_Integer)(myDS->ShapeInfo(n2).ShapeType());
176 theWithSubShape=aPKB.Flag();
179 //=======================================================================
182 //=======================================================================
183 void BOPDS_Iterator::Prepare()
185 Standard_Integer i, aNbInterfTypes;
187 aNbInterfTypes=BOPDS_DS::NbInterfTypes();
189 for (i=0; i<aNbInterfTypes; ++i) {
198 //=======================================================================
199 // function: Intersect
201 //=======================================================================
202 void BOPDS_Iterator::Intersect()
204 Standard_Boolean bFlag;
205 Standard_Integer aNb, i, aNbB, aNbR, iTi, iTj;
206 Standard_Integer i1, i2, aNbSD, iX, j, iDS, jB, iR;
207 TopAbs_ShapeEnum aTi, aTj;
208 Handle(NCollection_IncAllocator) aAllocator;
210 BOPCol_ListIteratorOfListOfInteger aIt;
212 //-----------------------------------------------------scope_1 f
213 aAllocator=new NCollection_IncAllocator();
215 BOPCol_DataMapOfShapeInteger aMSI(100, aAllocator);
216 BOPCol_DataMapOfIntegerInteger aMII(100, aAllocator);
217 BOPDS_MapOfPassKeyBoolean aMPKXB(100, aAllocator);
218 BOPCol_IndexedDataMapOfShapeBox aMSB(100, aAllocator);
219 BOPDS_PassKeyBoolean aPKXB;
221 BOPCol_BoxBndTreeSelector aSelector;
222 BOPCol_BoxBndTree aBBTree;
223 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
225 aNb=myDS->NbSourceShapes();
226 for (i=0; i<aNb; ++i) {
227 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
229 const TopoDS_Shape& aS=aSI.Shape();
230 const Bnd_Box& aBoxEx=aSI.Box();
232 aMSB.Add(aS, aBoxEx);
237 for (i=1; i<=aNbB; ++i) {
238 const TopoDS_Shape& aS=aMSB.FindKey(i);
239 const Bnd_Box& aBoxEx=aMSB(i);
241 aTreeFiller.Add(i, aBoxEx);
249 aNbR=myDS->NbRanges()-1;
250 for (iR=0; iR<aNbR; ++iR) {
251 const BOPDS_IndexRange& aR=myDS->Range(iR);
254 for (i=i1; i<=i2; ++i) {
255 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
262 const TopoDS_Shape& aSi=aSI.Shape();
263 const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
265 aSelector.SetBox(aBoxEx);
267 aNbSD=aBBTree.Select(aSelector);
272 const Bnd_Box& aBoxi=myDS->ShapeInfo(i).Box();
274 const BOPCol_ListOfInteger& aLI=aSelector.Indices();
276 for (; aIt.More(); aIt.Next()) {
277 jB=aIt.Value(); // box index in MII
278 j=aMII.Find(jB); // DS index
279 if (j>=i1 && j<=i2) {
280 continue;// same range
283 const BOPDS_ShapeInfo& aSIj=myDS->ShapeInfo(j);
284 aTj=aSIj.ShapeType();
285 iTi=BOPDS_Tools::TypeToInteger(aTi);
286 iTj=BOPDS_Tools::TypeToInteger(aTj);
287 bFlag=Standard_False;
289 bFlag=aSI.HasSubShape(j);
292 bFlag=aSIj.HasSubShape(i);
299 if (aMPKXB.Add(aPKXB)) {
300 bFlag=Standard_False;// Bounding boxes are intersected
301 const Bnd_Box& aBoxj=myDS->ShapeInfo(j).Box();
302 if (aBoxi.IsOut(aBoxj)) {
303 bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
306 iX=BOPDS_Tools::TypeToInteger(aTi, aTj);
307 aPKXB.SetFlag(bFlag);
308 myLists(iX).Append(aPKXB);
309 }// if (aMPKXB.Add(aPKXB)) {
310 }// for (; aIt.More(); aIt.Next()) {
311 }//for (i=i1; i<=i2; ++i) {
312 }//for (iR=1; iR<aNbR; ++iR) {
319 aAllocator.Nullify();
320 //-----------------------------------------------------scope_1 t