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.
16 #include <Bnd_Box.hxx>
17 #include <BOPCol_BoxBndTree.hxx>
18 #include <BOPCol_DataMapOfIntegerInteger.hxx>
19 #include <BOPCol_DataMapOfIntegerMapOfInteger.hxx>
20 #include <BOPCol_IndexedDataMapOfShapeBox.hxx>
21 #include <BOPCol_MapOfInteger.hxx>
22 #include <BOPDS_DS.hxx>
23 #include <BOPDS_IndexRange.hxx>
24 #include <BOPDS_MapOfPassKeyBoolean.hxx>
25 #include <BOPDS_PassKeyBoolean.hxx>
26 #include <BOPDS_SubIterator.hxx>
27 #include <BOPDS_Tools.hxx>
28 #include <NCollection_IncAllocator.hxx>
29 #include <NCollection_UBTreeFiller.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Vertex.hxx>
39 //=======================================================================
42 //=======================================================================
43 BOPDS_SubIterator::BOPDS_SubIterator()
45 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
50 //=======================================================================
53 //=======================================================================
54 BOPDS_SubIterator::BOPDS_SubIterator(const Handle(NCollection_BaseAllocator)& theAllocator)
56 myAllocator(theAllocator),
61 //=======================================================================
64 //=======================================================================
65 BOPDS_SubIterator::~BOPDS_SubIterator()
68 //=======================================================================
71 //=======================================================================
72 void BOPDS_SubIterator::SetDS(const BOPDS_PDS& aDS)
76 //=======================================================================
79 //=======================================================================
80 const BOPDS_DS& BOPDS_SubIterator::DS()const
84 //=======================================================================
85 //function : SetSubSet1
87 //=======================================================================
88 void BOPDS_SubIterator::SetSubSet1(const BOPCol_ListOfInteger& theLI)
90 mySubSet1=(BOPCol_PListOfInteger)&theLI;
92 //=======================================================================
95 //=======================================================================
96 const BOPCol_ListOfInteger& BOPDS_SubIterator::SubSet1()const
100 //=======================================================================
101 //function : SetSubSet2
103 //=======================================================================
104 void BOPDS_SubIterator::SetSubSet2(const BOPCol_ListOfInteger& theLI)
106 mySubSet2=(BOPCol_PListOfInteger)&theLI;
108 //=======================================================================
111 //=======================================================================
112 const BOPCol_ListOfInteger& BOPDS_SubIterator::SubSet2()const
116 //=======================================================================
117 // function: Initialize
119 //=======================================================================
120 void BOPDS_SubIterator::Initialize()
122 myIterator.Initialize(myList);
124 //=======================================================================
127 //=======================================================================
128 Standard_Boolean BOPDS_SubIterator::More()const
130 return myIterator.More();
132 //=======================================================================
135 //=======================================================================
136 void BOPDS_SubIterator::Next()
140 //=======================================================================
143 //=======================================================================
144 void BOPDS_SubIterator::Value(Standard_Integer& theI1,
145 Standard_Integer& theI2) const
147 Standard_Integer iT1, iT2, n1, n2;
149 const BOPDS_PassKeyBoolean& aPKB=myIterator.Value();
152 iT1=(Standard_Integer)(myDS->ShapeInfo(n1).ShapeType());
153 iT2=(Standard_Integer)(myDS->ShapeInfo(n2).ShapeType());
162 //=======================================================================
165 //=======================================================================
166 void BOPDS_SubIterator::Prepare()
173 if (!mySubSet1->Extent() || !mySubSet2->Extent()) {
178 //=======================================================================
179 // function: Intersect
181 //=======================================================================
182 void BOPDS_SubIterator::Intersect()
184 Standard_Integer i, aNbB, aNbSD, j, iDS, jB;
185 Handle(NCollection_IncAllocator) aAllocator;
186 BOPCol_ListIteratorOfListOfInteger aIt, aIt1, aIt2;
187 BOPDS_PassKeyBoolean aPKXB;
189 //-----------------------------------------------------scope_1 f
190 aAllocator=new NCollection_IncAllocator();
192 BOPCol_DataMapOfShapeInteger aMSI(100, aAllocator);
193 BOPCol_DataMapOfIntegerInteger aMII(100, aAllocator);
194 BOPDS_MapOfPassKeyBoolean aMPKXB(100, aAllocator);
195 BOPCol_IndexedDataMapOfShapeBox aMSB(100, aAllocator);
197 BOPCol_BoxBndTreeSelector aSelector;
198 BOPCol_BoxBndTree aBBTree;
199 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
201 aIt1.Initialize(*mySubSet1);
202 for (; aIt1.More(); aIt1.Next()) {
204 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
205 const TopoDS_Shape& aS=aSI.Shape();
206 const Bnd_Box& aBoxEx=aSI.Box();
208 aMSB.Add(aS, aBoxEx);
212 for (i=1; i<=aNbB; ++i) {
213 const TopoDS_Shape& aS=aMSB.FindKey(i);
214 const Bnd_Box& aBoxEx=aMSB(i);
216 aTreeFiller.Add(i, aBoxEx);
224 aIt2.Initialize(*mySubSet2);
225 for (; aIt2.More(); aIt2.Next()) {
228 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
229 const Bnd_Box& aBoxEx=aSI.Box();
232 aSelector.SetBox(aBoxEx);
233 aNbSD=aBBTree.Select(aSelector);
237 //const Bnd_Box& aBoxi=myDS->ShapeInfo(i).Box();
239 const BOPCol_ListOfInteger& aLI=aSelector.Indices();
241 for (; aIt.More(); aIt.Next()) {
242 jB=aIt.Value(); // box index in MII
243 j=aMII.Find(jB); // DS index
246 if (aMPKXB.Add(aPKXB)) {
247 myList.Append(aPKXB);
248 }// if (aMPKXB.Add(aPKXB)) {
249 }// for (; aIt.More(); aIt.Next()) {
257 aAllocator.Nullify();
258 //-----------------------------------------------------scope_1 t