1 // Copyright (C) 2006 SAMTECH
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File: NMTDS_Iterator.cxx
20 // Created: Sun May 07 15:04:41 2006
21 // Author: Peter KURNEV
25 #include <NMTDS_Iterator.ixx>
27 #include <Bnd_Box.hxx>
29 #include <TColStd_ListOfInteger.hxx>
30 #include <TColStd_ListIteratorOfListOfInteger.hxx>
31 #include <TColStd_MapOfInteger.hxx>
32 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
33 #include <TColStd_DataMapOfIntegerInteger.hxx>
34 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
35 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
36 #include <TColStd_MapOfInteger.hxx>
39 #include <TopoDS_Vertex.hxx>
40 #include <TopoDS_Shape.hxx>
42 #include <TopTools_DataMapOfShapeInteger.hxx>
44 #include <NMTDS_BoxBndTree.hxx>
45 #include <NCollection_UBTreeFiller.hxx>
46 #include <NMTDS_CArray1OfIndexRange.hxx>
47 #include <NMTDS_IndexRange.hxx>
48 #include <NMTDS_PassKeyBoolean.hxx>
49 #include <NMTDS_MapOfPassKeyBoolean.hxx>
50 #include <NMTDS_IndexedDataMapOfShapeBox.hxx>
51 #include <NMTDS_IndexedDataMapOfIntegerShape.hxx>
52 #include <NMTDS_Tools.hxx>
53 #include <NMTDS_DataMapOfIntegerMapOfInteger.hxx>
54 #include <NMTDS_DataMapIteratorOfDataMapOfIntegerMapOfInteger.hxx>
56 //=======================================================================
57 //function : NMTDS_Iterator
59 //=======================================================================
60 NMTDS_Iterator::NMTDS_Iterator()
65 //=======================================================================
66 //function : ~NMTDS_Iterator
68 //=======================================================================
69 NMTDS_Iterator::~NMTDS_Iterator()
72 //=======================================================================
75 //=======================================================================
76 void NMTDS_Iterator::SetDS(const NMTDS_PShapesDataStructure& aDS)
80 //=======================================================================
83 //=======================================================================
84 const NMTDS_ShapesDataStructure& NMTDS_Iterator::DS()const
88 //=======================================================================
89 // function: ExpectedLength
91 //=======================================================================
92 Standard_Integer NMTDS_Iterator::ExpectedLength() const
96 //=======================================================================
97 // function: BlockLength
99 //=======================================================================
100 Standard_Integer NMTDS_Iterator::BlockLength() const
102 Standard_Integer aNbIIs;
103 Standard_Real aCfPredict=.5;
105 aNbIIs=ExpectedLength();
111 aNbIIs=(Standard_Integer) (aCfPredict*(Standard_Real)aNbIIs);
114 //=======================================================================
115 // function: Initialize
117 //=======================================================================
118 void NMTDS_Iterator::Initialize(const TopAbs_ShapeEnum aType1,
119 const TopAbs_ShapeEnum aType2)
123 iX=NMTDS_Tools::TypeToInteger(aType1, aType2);
125 myIterator.Initialize(myLists[iX]);
126 myLength=myLists[iX].Extent();
129 myIterator.Initialize(myEmptyList);
133 //=======================================================================
136 //=======================================================================
137 Standard_Boolean NMTDS_Iterator::More()const
139 return myIterator.More();
141 //=======================================================================
144 //=======================================================================
145 void NMTDS_Iterator::Next()
149 //=======================================================================
152 //=======================================================================
153 void NMTDS_Iterator::Current(Standard_Integer& aIndex1,
154 Standard_Integer& aIndex2,
155 Standard_Boolean& aWithSubShape) const
157 const NMTDS_PassKeyBoolean& aPKB=myIterator.Value();
158 aPKB.Ids(aIndex1, aIndex2);
159 aWithSubShape=aPKB.Flag();
161 //=======================================================================
162 // function: SDVertices
164 //=======================================================================
165 const TColStd_DataMapOfIntegerListOfInteger& NMTDS_Iterator::SDVertices()const
169 //=======================================================================
172 //=======================================================================
173 void NMTDS_Iterator::Prepare()
178 for (i=0; i<6; ++i) {
188 //=======================================================================
189 // function: Intersect
191 //=======================================================================
192 void NMTDS_Iterator::Intersect()
194 Standard_Boolean bFlag;
195 Standard_Integer aNb, i, aNbB, aNbR, iFlag;
196 Standard_Integer i1, i2, aNbSD, iX, j, iDS, jB, iR, k, aNbLV;
197 TColStd_ListIteratorOfListOfInteger aIt;
198 TColStd_DataMapOfIntegerInteger aMII;
199 //modified by NIZNHY-PKV Mon Jan 22 15:08:00 2007f
200 //TColStd_MapOfInteger aMFence;
201 TColStd_DataMapOfIntegerListOfInteger aMVSD;
202 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
203 //modified by NIZNHY-PKV Mon Jan 22 10:21:50 2007t
204 TopTools_DataMapOfShapeInteger aMSI;
205 TopAbs_ShapeEnum aTi, aTj;
206 NMTDS_PassKeyBoolean aPKXB;
207 NMTDS_MapOfPassKeyBoolean aMPKXB;
208 NMTDS_IndexedDataMapOfShapeBox aMSB;
210 NMTDS_BoxBndTreeSelector aSelector;
211 NMTDS_BoxBndTree aBBTree;
212 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
214 const NMTDS_CArray1OfIndexRange& aRanges=myDS->Ranges();
215 aNbR=aRanges.Extent();
217 aNb=myDS->NumberOfShapesOfTheObject();
218 for (i=1; i<=aNb; ++i) {
219 const TopoDS_Shape& aS=myDS->Shape(i);
221 if (NMTDS_Tools::HasBRep(aTi)) {
224 myDS->ComputeBoxEx(i, aBoxEx);
226 aMSB.Add(aS, aBoxEx);
232 for (i=1; i<=aNbB; ++i) {
233 const TopoDS_Shape& aS=aMSB.FindKey(i);
234 const Bnd_Box& aBoxEx=aMSB(i);
236 aTreeFiller.Add(i, aBoxEx);
244 for (iR=1; iR<aNbR; ++iR) {
245 const NMTDS_IndexRange& aR=aRanges(iR);
248 for (i=i1; i<=i2; ++i) {
249 const TopoDS_Shape& aSi=myDS->Shape(i);
251 if (!NMTDS_Tools::HasBRep(aTi)){
254 const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
256 aSelector.SetBox(aBoxEx);
258 aNbSD=aBBTree.Select(aSelector);
264 const TColStd_ListOfInteger& aLI=aSelector.Indices();
267 TColStd_ListOfInteger aLV;
270 for (; aIt.More(); aIt.Next()) {
271 jB=aIt.Value(); // box index in MII
272 j=aMII.Find(jB); // DS index
273 if (j>=i1 && j<=i2) {
274 continue;// same range
279 if (aMPKXB.Add(aPKXB)) {
280 bFlag=Standard_False;// Bounding boxes are intersected
281 const Bnd_Box& aBoxi=myDS->GetBoundingBox(i);
282 const Bnd_Box& aBoxj=myDS->GetBoundingBox(j);
283 if (aBoxi.IsOut(aBoxj)) {
284 bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
286 const TopoDS_Shape& aSj=myDS->Shape(j);
288 iX=NMTDS_Tools::TypeToInteger(aTi, aTj);
289 //bFlag=(iStatus==2);
290 aPKXB.SetFlag(bFlag);
291 myLists[iX].Append(aPKXB);
297 }// if (aMPKXB.Add(aPKXB)) {
298 }// for (; aIt.More(); aIt.Next()) {
303 TColStd_ListOfInteger aLV1;
305 const TopoDS_Vertex& aVi=TopoDS::Vertex(aSi);
307 for (; aIt.More(); aIt.Next()) {
309 const TopoDS_Shape& aSj=myDS->Shape(j);
310 const TopoDS_Vertex& aVj=TopoDS::Vertex(aSj);
311 iFlag=NMTDS_Tools::ComputeVV(aVi, aVj);
317 aMPKXB.Remove(aPKXB);
322 }//for (i=i1; i<=i2; ++i) {
323 }//for (iR=1; iR<aNbR; ++iR) {
329 NMTDS_Iterator::FillMVSD(aMVSD, myMVSD);
331 //=======================================================================
332 //function : FillMVSD
334 //=======================================================================
335 void NMTDS_Iterator::FillMVSD(const TColStd_DataMapOfIntegerListOfInteger& aMVSD,
336 TColStd_DataMapOfIntegerListOfInteger& bMVSD)
338 Standard_Boolean bFound;
339 Standard_Integer aNbVSD, iCnt, i, j, k;
340 TColStd_ListOfInteger aLV;
341 TColStd_ListIteratorOfListOfInteger aIt;
342 TColStd_MapOfInteger aMF;
343 TColStd_MapIteratorOfMapOfInteger aItMI;
344 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
345 NMTDS_DataMapOfIntegerMapOfInteger aDMIMI;
346 NMTDS_DataMapIteratorOfDataMapOfIntegerMapOfInteger aIti, aItj;
348 aNbVSD=aMVSD.Extent();
353 aItVSD.Initialize(aMVSD);
354 for (; aItVSD.More(); aItVSD.Next()) {
355 TColStd_MapOfInteger aMI;
359 const TColStd_ListOfInteger& aLVSD=aItVSD.Value();
360 aIt.Initialize(aLVSD);
361 for (; aIt.More(); aIt.Next()) {
368 aIti.Initialize(aDMIMI);
369 for (; aIti.More(); aIti.Next()) {
371 if (aMF.Contains(i)) {
376 //TColStd_MapOfInteger& aMIi=aDMIMI.ChangeFind(i);
377 TColStd_MapOfInteger *pMIi=(TColStd_MapOfInteger *)&aIti.Value();
378 TColStd_MapOfInteger& aMIi=*pMIi;
382 aItj.Initialize(aDMIMI);
383 for (; aItj.More(); aItj.Next()) {
385 if (aMF.Contains(j)) {
389 //TColStd_MapOfInteger& aMIj=aDMIMI.ChangeFind(j);
390 TColStd_MapOfInteger *pMj=(TColStd_MapOfInteger *)&aItj.Value();
391 TColStd_MapOfInteger& aMIj=*pMj;
393 aItMI.Initialize(aMIj);
394 for (; aItMI.More(); aItMI.Next()) {
396 bFound=aMIi.Contains(k);
405 aItMI.Initialize(aMIj);
406 for (; aItMI.More(); aItMI.Next()) {
414 } //for (; aItj.More(); aItj.Next()) {
421 aItMI.Initialize(aMIi);
422 for (; aItMI.More(); aItMI.Next()) {
429 }// for (; aIti.More(); aIti.Next()) {
435 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItX;
438 printf(" myMVSD.Extent()=%d\n", myMVSD.Extent());
439 aItX.Initialize(myMVSD);
440 for (; aItX.More(); aItX.Next()) {
442 printf(" i=%d (", i);
443 const TColStd_ListOfInteger& aLV=aItX.Value();
445 for (; aIt.More(); aIt.Next()) {