1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
20 #include <BOPDS_SubIterator.ixx>
22 #include <Bnd_Box.hxx>
24 #include <NCollection_BaseAllocator.hxx>
25 #include <NCollection_UBTreeFiller.hxx>
28 #include <TopoDS_Vertex.hxx>
29 #include <TopoDS_Shape.hxx>
31 #include <BOPCol_IndexedDataMapOfShapeBox.hxx>
32 #include <BOPCol_DataMapOfIntegerInteger.hxx>
33 #include <BOPCol_DataMapOfIntegerMapOfInteger.hxx>
34 #include <BOPCol_MapOfInteger.hxx>
36 #include <BOPDS_BoxBndTree.hxx>
37 #include <BOPDS_IndexRange.hxx>
38 #include <BOPDS_PassKeyBoolean.hxx>
39 #include <BOPDS_MapOfPassKeyBoolean.hxx>
40 #include <BOPDS_Tools.hxx>
41 #include <BOPDS_MapOfPassKeyBoolean.hxx>
43 //=======================================================================
46 //=======================================================================
47 BOPDS_SubIterator::BOPDS_SubIterator()
49 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
54 //=======================================================================
57 //=======================================================================
58 BOPDS_SubIterator::BOPDS_SubIterator(const Handle(NCollection_BaseAllocator)& theAllocator)
60 myAllocator(theAllocator),
65 //=======================================================================
68 //=======================================================================
69 BOPDS_SubIterator::~BOPDS_SubIterator()
72 //=======================================================================
75 //=======================================================================
76 void BOPDS_SubIterator::SetDS(const BOPDS_PDS& aDS)
80 //=======================================================================
83 //=======================================================================
84 const BOPDS_DS& BOPDS_SubIterator::DS()const
88 //=======================================================================
89 //function : SetSubSet1
91 //=======================================================================
92 void BOPDS_SubIterator::SetSubSet1(const BOPCol_ListOfInteger& theLI)
94 mySubSet1=(BOPCol_PListOfInteger)&theLI;
96 //=======================================================================
99 //=======================================================================
100 const BOPCol_ListOfInteger& BOPDS_SubIterator::SubSet1()const
104 //=======================================================================
105 //function : SetSubSet2
107 //=======================================================================
108 void BOPDS_SubIterator::SetSubSet2(const BOPCol_ListOfInteger& theLI)
110 mySubSet2=(BOPCol_PListOfInteger)&theLI;
112 //=======================================================================
115 //=======================================================================
116 const BOPCol_ListOfInteger& BOPDS_SubIterator::SubSet2()const
120 //=======================================================================
121 // function: Initialize
123 //=======================================================================
124 void BOPDS_SubIterator::Initialize()
126 myIterator.Initialize(myList);
128 //=======================================================================
131 //=======================================================================
132 Standard_Boolean BOPDS_SubIterator::More()const
134 return myIterator.More();
136 //=======================================================================
139 //=======================================================================
140 void BOPDS_SubIterator::Next()
144 //=======================================================================
147 //=======================================================================
148 void BOPDS_SubIterator::Value(Standard_Integer& theI1,
149 Standard_Integer& theI2) const
151 Standard_Integer iT1, iT2, n1, n2;
153 const BOPDS_PassKeyBoolean& aPKB=myIterator.Value();
156 iT1=(Standard_Integer)(myDS->ShapeInfo(n1).ShapeType());
157 iT2=(Standard_Integer)(myDS->ShapeInfo(n2).ShapeType());
166 //=======================================================================
169 //=======================================================================
170 void BOPDS_SubIterator::Prepare()
177 if (!mySubSet1->Extent() || !mySubSet2->Extent()) {
182 //=======================================================================
183 // function: Intersect
185 //=======================================================================
186 void BOPDS_SubIterator::Intersect()
188 Standard_Integer i, aNbB, aNbSD, j, iDS, jB;
189 Handle(NCollection_IncAllocator) aAllocator;
190 BOPCol_ListIteratorOfListOfInteger aIt, aIt1, aIt2;
191 BOPDS_PassKeyBoolean aPKXB;
193 //-----------------------------------------------------scope_1 f
194 aAllocator=new NCollection_IncAllocator();
196 BOPCol_DataMapOfShapeInteger aMSI(100, aAllocator);
197 BOPCol_DataMapOfIntegerInteger aMII(100, aAllocator);
198 BOPDS_MapOfPassKeyBoolean aMPKXB(100, aAllocator);
199 BOPCol_IndexedDataMapOfShapeBox aMSB(100, aAllocator);
201 BOPDS_BoxBndTreeSelector aSelector;
202 BOPDS_BoxBndTree aBBTree;
203 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
205 aIt1.Initialize(*mySubSet1);
206 for (; aIt1.More(); aIt1.Next()) {
208 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
209 const TopoDS_Shape& aS=aSI.Shape();
210 const Bnd_Box& aBoxEx=aSI.Box();
212 aMSB.Add(aS, aBoxEx);
216 for (i=1; i<=aNbB; ++i) {
217 const TopoDS_Shape& aS=aMSB.FindKey(i);
218 const Bnd_Box& aBoxEx=aMSB(i);
220 aTreeFiller.Add(i, aBoxEx);
228 aIt2.Initialize(*mySubSet2);
229 for (; aIt2.More(); aIt2.Next()) {
232 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
233 const TopoDS_Shape& aSi=aSI.Shape();
234 const Bnd_Box& aBoxEx=aSI.Box();
237 aSelector.SetBox(aBoxEx);
238 aNbSD=aBBTree.Select(aSelector);
242 //const Bnd_Box& aBoxi=myDS->ShapeInfo(i).Box();
244 const BOPCol_ListOfInteger& aLI=aSelector.Indices();
246 for (; aIt.More(); aIt.Next()) {
247 jB=aIt.Value(); // box index in MII
248 j=aMII.Find(jB); // DS index
251 if (aMPKXB.Add(aPKXB)) {
252 myList.Append(aPKXB);
253 }// if (aMPKXB.Add(aPKXB)) {
254 }// for (; aIt.More(); aIt.Next()) {
262 aAllocator.Nullify();
263 //-----------------------------------------------------scope_1 t