1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <BOPDS_SubIterator.ixx>
17 #include <Bnd_Box.hxx>
19 #include <NCollection_BaseAllocator.hxx>
20 #include <NCollection_UBTreeFiller.hxx>
23 #include <TopoDS_Vertex.hxx>
24 #include <TopoDS_Shape.hxx>
26 #include <BOPCol_IndexedDataMapOfShapeBox.hxx>
27 #include <BOPCol_DataMapOfIntegerInteger.hxx>
28 #include <BOPCol_DataMapOfIntegerMapOfInteger.hxx>
29 #include <BOPCol_MapOfInteger.hxx>
30 #include <BOPCol_BoxBndTree.hxx>
32 #include <BOPDS_IndexRange.hxx>
33 #include <BOPDS_PassKeyBoolean.hxx>
34 #include <BOPDS_MapOfPassKeyBoolean.hxx>
35 #include <BOPDS_Tools.hxx>
36 #include <BOPDS_MapOfPassKeyBoolean.hxx>
38 //=======================================================================
41 //=======================================================================
42 BOPDS_SubIterator::BOPDS_SubIterator()
44 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
49 //=======================================================================
52 //=======================================================================
53 BOPDS_SubIterator::BOPDS_SubIterator(const Handle(NCollection_BaseAllocator)& theAllocator)
55 myAllocator(theAllocator),
60 //=======================================================================
63 //=======================================================================
64 BOPDS_SubIterator::~BOPDS_SubIterator()
67 //=======================================================================
70 //=======================================================================
71 void BOPDS_SubIterator::SetDS(const BOPDS_PDS& aDS)
75 //=======================================================================
78 //=======================================================================
79 const BOPDS_DS& BOPDS_SubIterator::DS()const
83 //=======================================================================
84 //function : SetSubSet1
86 //=======================================================================
87 void BOPDS_SubIterator::SetSubSet1(const BOPCol_ListOfInteger& theLI)
89 mySubSet1=(BOPCol_PListOfInteger)&theLI;
91 //=======================================================================
94 //=======================================================================
95 const BOPCol_ListOfInteger& BOPDS_SubIterator::SubSet1()const
99 //=======================================================================
100 //function : SetSubSet2
102 //=======================================================================
103 void BOPDS_SubIterator::SetSubSet2(const BOPCol_ListOfInteger& theLI)
105 mySubSet2=(BOPCol_PListOfInteger)&theLI;
107 //=======================================================================
110 //=======================================================================
111 const BOPCol_ListOfInteger& BOPDS_SubIterator::SubSet2()const
115 //=======================================================================
116 // function: Initialize
118 //=======================================================================
119 void BOPDS_SubIterator::Initialize()
121 myIterator.Initialize(myList);
123 //=======================================================================
126 //=======================================================================
127 Standard_Boolean BOPDS_SubIterator::More()const
129 return myIterator.More();
131 //=======================================================================
134 //=======================================================================
135 void BOPDS_SubIterator::Next()
139 //=======================================================================
142 //=======================================================================
143 void BOPDS_SubIterator::Value(Standard_Integer& theI1,
144 Standard_Integer& theI2) const
146 Standard_Integer iT1, iT2, n1, n2;
148 const BOPDS_PassKeyBoolean& aPKB=myIterator.Value();
151 iT1=(Standard_Integer)(myDS->ShapeInfo(n1).ShapeType());
152 iT2=(Standard_Integer)(myDS->ShapeInfo(n2).ShapeType());
161 //=======================================================================
164 //=======================================================================
165 void BOPDS_SubIterator::Prepare()
172 if (!mySubSet1->Extent() || !mySubSet2->Extent()) {
177 //=======================================================================
178 // function: Intersect
180 //=======================================================================
181 void BOPDS_SubIterator::Intersect()
183 Standard_Integer i, aNbB, aNbSD, j, iDS, jB;
184 Handle(NCollection_IncAllocator) aAllocator;
185 BOPCol_ListIteratorOfListOfInteger aIt, aIt1, aIt2;
186 BOPDS_PassKeyBoolean aPKXB;
188 //-----------------------------------------------------scope_1 f
189 aAllocator=new NCollection_IncAllocator();
191 BOPCol_DataMapOfShapeInteger aMSI(100, aAllocator);
192 BOPCol_DataMapOfIntegerInteger aMII(100, aAllocator);
193 BOPDS_MapOfPassKeyBoolean aMPKXB(100, aAllocator);
194 BOPCol_IndexedDataMapOfShapeBox aMSB(100, aAllocator);
196 BOPCol_BoxBndTreeSelector aSelector;
197 BOPCol_BoxBndTree aBBTree;
198 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
200 aIt1.Initialize(*mySubSet1);
201 for (; aIt1.More(); aIt1.Next()) {
203 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
204 const TopoDS_Shape& aS=aSI.Shape();
205 const Bnd_Box& aBoxEx=aSI.Box();
207 aMSB.Add(aS, aBoxEx);
211 for (i=1; i<=aNbB; ++i) {
212 const TopoDS_Shape& aS=aMSB.FindKey(i);
213 const Bnd_Box& aBoxEx=aMSB(i);
215 aTreeFiller.Add(i, aBoxEx);
223 aIt2.Initialize(*mySubSet2);
224 for (; aIt2.More(); aIt2.Next()) {
227 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
228 const Bnd_Box& aBoxEx=aSI.Box();
231 aSelector.SetBox(aBoxEx);
232 aNbSD=aBBTree.Select(aSelector);
236 //const Bnd_Box& aBoxi=myDS->ShapeInfo(i).Box();
238 const BOPCol_ListOfInteger& aLI=aSelector.Indices();
240 for (; aIt.More(); aIt.Next()) {
241 jB=aIt.Value(); // box index in MII
242 j=aMII.Find(jB); // DS index
245 if (aMPKXB.Add(aPKXB)) {
246 myList.Append(aPKXB);
247 }// if (aMPKXB.Add(aPKXB)) {
248 }// for (; aIt.More(); aIt.Next()) {
256 aAllocator.Nullify();
257 //-----------------------------------------------------scope_1 t