1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2012 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 // The content of this file is subject to the Open CASCADE Technology Public
8 // License Version 6.5 (the "License"). You may not use the content of this file
9 // except in compliance with the License. Please obtain a copy of the License
10 // at http://www.opencascade.org and read it completely before using this file.
12 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
13 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
15 // The Original Code and all software distributed under the License is
16 // distributed on an "AS IS" basis, without warranty of any kind, and the
17 // Initial Developer hereby disclaims all such warranties, including without
18 // limitation, any warranties of merchantability, fitness for a particular
19 // purpose or non-infringement. Please see the License for the specific terms
20 // and conditions governing the rights and limitations under the License.
23 #include <BOPDS_Iterator.ixx>
25 #include <Bnd_Box.hxx>
27 #include <NCollection_BaseAllocator.hxx>
28 #include <NCollection_UBTreeFiller.hxx>
31 #include <TopoDS_Vertex.hxx>
32 #include <TopoDS_Shape.hxx>
34 #include <BOPCol_IndexedDataMapOfShapeBox.hxx>
35 #include <BOPCol_DataMapOfIntegerInteger.hxx>
36 #include <BOPCol_DataMapOfIntegerMapOfInteger.hxx>
37 #include <BOPCol_MapOfInteger.hxx>
39 #include <BOPDS_BoxBndTree.hxx>
40 #include <BOPDS_IndexRange.hxx>
41 #include <BOPDS_PassKeyBoolean.hxx>
42 #include <BOPDS_MapOfPassKeyBoolean.hxx>
43 #include <BOPDS_Tools.hxx>
44 #include <BOPDS_MapOfPassKeyBoolean.hxx>
47 //=======================================================================
50 //=======================================================================
51 BOPDS_Iterator::BOPDS_Iterator()
53 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator())
58 myLists.SetStartSize(6);
61 //=======================================================================
64 //=======================================================================
65 BOPDS_Iterator::BOPDS_Iterator(const Handle(NCollection_BaseAllocator)& theAllocator)
67 myAllocator(theAllocator),
73 myLists.SetStartSize(6);
76 //=======================================================================
79 //=======================================================================
80 BOPDS_Iterator::~BOPDS_Iterator()
83 //=======================================================================
86 //=======================================================================
87 void BOPDS_Iterator::SetDS(const BOPDS_PDS& aDS)
91 //=======================================================================
94 //=======================================================================
95 const BOPDS_DS& BOPDS_Iterator::DS()const
99 //=======================================================================
100 // function: ExpectedLength
102 //=======================================================================
103 Standard_Integer BOPDS_Iterator::ExpectedLength() const
107 //=======================================================================
108 // function: BlockLength
110 //=======================================================================
111 Standard_Integer BOPDS_Iterator::BlockLength() const
113 Standard_Integer aNbIIs;
114 Standard_Real aCfPredict=.5;
116 aNbIIs=ExpectedLength();
122 aNbIIs=(Standard_Integer) (aCfPredict*(Standard_Real)aNbIIs);
125 //=======================================================================
126 // function: Initialize
128 //=======================================================================
129 void BOPDS_Iterator::Initialize(const TopAbs_ShapeEnum aType1,
130 const TopAbs_ShapeEnum aType2)
135 iX=BOPDS_Tools::TypeToInteger(aType1, aType2);
137 myIterator.Initialize(myLists(iX));
138 myLength=myLists(iX).Extent();
141 //=======================================================================
144 //=======================================================================
145 Standard_Boolean BOPDS_Iterator::More()const
147 return myIterator.More();
149 //=======================================================================
152 //=======================================================================
153 void BOPDS_Iterator::Next()
157 //=======================================================================
160 //=======================================================================
161 void BOPDS_Iterator::Value(Standard_Integer& theI1,
162 Standard_Integer& theI2,
163 Standard_Boolean& theWithSubShape) const
165 Standard_Integer iT1, iT2, n1, n2;
167 const BOPDS_PassKeyBoolean& aPKB=myIterator.Value();
170 iT1=(Standard_Integer)(myDS->ShapeInfo(n1).ShapeType());
171 iT2=(Standard_Integer)(myDS->ShapeInfo(n2).ShapeType());
180 theWithSubShape=aPKB.Flag();
183 //=======================================================================
186 //=======================================================================
187 void BOPDS_Iterator::Prepare()
192 for (i=0; i<6; ++i) {
201 //=======================================================================
202 // function: Intersect
204 //=======================================================================
205 void BOPDS_Iterator::Intersect()
207 Standard_Boolean bFlag;
208 Standard_Integer aNb, i, aNbB, aNbR;
209 Standard_Integer i1, i2, aNbSD, iX, j, iDS, jB, iR;
210 TopAbs_ShapeEnum aTi, aTj;
211 Handle(NCollection_IncAllocator) aAllocator;
213 BOPCol_ListIteratorOfListOfInteger aIt;
215 //-----------------------------------------------------scope_1 f
216 aAllocator=new NCollection_IncAllocator();
218 BOPCol_DataMapOfShapeInteger aMSI(100, aAllocator);
219 BOPCol_DataMapOfIntegerInteger aMII(100, aAllocator);
220 BOPDS_MapOfPassKeyBoolean aMPKXB(100, aAllocator);
221 BOPCol_IndexedDataMapOfShapeBox aMSB(100, aAllocator);
222 BOPDS_PassKeyBoolean aPKXB;
224 BOPDS_BoxBndTreeSelector aSelector;
225 BOPDS_BoxBndTree aBBTree;
226 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
228 aNb=myDS->NbSourceShapes();
229 for (i=0; i<aNb; ++i) {
230 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
232 const TopoDS_Shape& aS=aSI.Shape();
233 const Bnd_Box& aBoxEx=aSI.Box();
235 aMSB.Add(aS, aBoxEx);
240 for (i=1; i<=aNbB; ++i) {
241 const TopoDS_Shape& aS=aMSB.FindKey(i);
242 const Bnd_Box& aBoxEx=aMSB(i);
244 aTreeFiller.Add(i, aBoxEx);
252 aNbR=myDS->NbRanges()-1;
253 for (iR=0; iR<aNbR; ++iR) {
254 const BOPDS_IndexRange& aR=myDS->Range(iR);
257 for (i=i1; i<=i2; ++i) {
258 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
265 const TopoDS_Shape& aSi=aSI.Shape();
266 const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
268 aSelector.SetBox(aBoxEx);
270 aNbSD=aBBTree.Select(aSelector);
275 const Bnd_Box& aBoxi=myDS->ShapeInfo(i).Box();
277 const BOPCol_ListOfInteger& aLI=aSelector.Indices();
279 for (; aIt.More(); aIt.Next()) {
280 jB=aIt.Value(); // box index in MII
281 j=aMII.Find(jB); // DS index
282 if (j>=i1 && j<=i2) {
283 continue;// same range
287 if (aMPKXB.Add(aPKXB)) {
288 bFlag=Standard_False;// Bounding boxes are intersected
289 const Bnd_Box& aBoxj=myDS->ShapeInfo(j).Box();
290 if (aBoxi.IsOut(aBoxj)) {
291 bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
294 aTj=myDS->ShapeInfo(j).ShapeType();
295 iX=BOPDS_Tools::TypeToInteger(aTi, aTj);
296 aPKXB.SetFlag(bFlag);
297 myLists(iX).Append(aPKXB);
298 }// if (aMPKXB.Add(aPKXB)) {
299 }// for (; aIt.More(); aIt.Next()) {
300 }//for (i=i1; i<=i2; ++i) {
301 }//for (iR=1; iR<aNbR; ++iR) {
308 aAllocator.Nullify();
309 //-----------------------------------------------------scope_1 t