1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: NMTDS_Iterator.cxx
23 // 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_PairBoolean.hxx>
49 #include <NMTDS_MapOfPairBoolean.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, iTresh;
103 Standard_Real aCfPredict=.5;
105 aNbIIs=ExpectedLength();
110 //modified by NIZNHY-PKV Mon Dec 12 08:50:50 2011f
116 //modified by NIZNHY-PKV Mon Dec 12 08:50:54 2011t
118 aNbIIs=(Standard_Integer) (aCfPredict*(Standard_Real)aNbIIs);
121 //=======================================================================
122 // function: Initialize
124 //=======================================================================
125 void NMTDS_Iterator::Initialize(const TopAbs_ShapeEnum aType1,
126 const TopAbs_ShapeEnum aType2)
130 iX=NMTDS_Tools::TypeToInteger(aType1, aType2);
132 myIterator.Initialize(myLists[iX]);
133 myLength=myLists[iX].Extent();
136 myIterator.Initialize(myEmptyList);
140 //=======================================================================
143 //=======================================================================
144 Standard_Boolean NMTDS_Iterator::More()const
146 return myIterator.More();
148 //=======================================================================
151 //=======================================================================
152 void NMTDS_Iterator::Next()
156 //=======================================================================
159 //=======================================================================
160 void NMTDS_Iterator::Current(Standard_Integer& aIndex1,
161 Standard_Integer& aIndex2,
162 Standard_Boolean& aWithSubShape) const
164 const NMTDS_PairBoolean& aPKB=myIterator.Value();
165 aPKB.Ids(aIndex1, aIndex2);
166 aWithSubShape=aPKB.Flag();
168 //=======================================================================
169 // function: SDVertices
171 //=======================================================================
172 const TColStd_DataMapOfIntegerListOfInteger& NMTDS_Iterator::SDVertices()const
176 //=======================================================================
179 //=======================================================================
180 void NMTDS_Iterator::Prepare()
185 for (i=0; i<6; ++i) {
195 //=======================================================================
196 // function: Intersect
198 //=======================================================================
199 void NMTDS_Iterator::Intersect()
201 Standard_Boolean bFlag;
202 Standard_Integer aNb, i, aNbB, aNbR, iFlag;
203 Standard_Integer i1, i2, aNbSD, iX, j, iDS, jB, iR, k, aNbLV, aNbLV1;
204 TColStd_ListIteratorOfListOfInteger aIt;
205 TColStd_DataMapOfIntegerInteger aMII;
206 TColStd_DataMapOfIntegerListOfInteger aMVSD;
207 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
208 TopTools_DataMapOfShapeInteger aMSI;
209 TopAbs_ShapeEnum aTi, aTj;
210 NMTDS_PairBoolean aPKXB;
211 NMTDS_MapOfPairBoolean aMPKXB;
212 NMTDS_IndexedDataMapOfShapeBox aMSB;
214 NMTDS_BoxBndTreeSelector aSelector;
215 NMTDS_BoxBndTree aBBTree;
216 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
218 const NMTDS_CArray1OfIndexRange& aRanges=myDS->Ranges();
219 aNbR=aRanges.Extent();
221 aNb=myDS->NumberOfShapesOfTheObject();
222 for (i=1; i<=aNb; ++i) {
223 const TopoDS_Shape& aS=myDS->Shape(i);
225 if (NMTDS_Tools::HasBRep(aTi)) {
228 myDS->ComputeBoxEx(i, aBoxEx);
230 aMSB.Add(aS, aBoxEx);
236 for (i=1; i<=aNbB; ++i) {
237 const TopoDS_Shape& aS=aMSB.FindKey(i);
238 const Bnd_Box& aBoxEx=aMSB(i);
240 aTreeFiller.Add(i, aBoxEx);
248 for (iR=1; iR<aNbR; ++iR) {
249 const NMTDS_IndexRange& aR=aRanges(iR);
252 for (i=i1; i<=i2; ++i) {
253 const TopoDS_Shape& aSi=myDS->Shape(i);
255 if (!NMTDS_Tools::HasBRep(aTi)){
258 const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
260 aSelector.SetBox(aBoxEx);
262 aNbSD=aBBTree.Select(aSelector);
268 const TColStd_ListOfInteger& aLI=aSelector.Indices();
271 TColStd_ListOfInteger aLV;
274 for (; aIt.More(); aIt.Next()) {
275 jB=aIt.Value(); // box index in MII
276 j=aMII.Find(jB); // DS index
277 if (j>=i1 && j<=i2) {
278 continue;// same range
283 if (aMPKXB.Add(aPKXB)) {
284 bFlag=Standard_False;// Bounding boxes are intersected
285 const Bnd_Box& aBoxi=myDS->GetBoundingBox(i);
286 const Bnd_Box& aBoxj=myDS->GetBoundingBox(j);
287 if (aBoxi.IsOut(aBoxj)) {
288 bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
290 const TopoDS_Shape& aSj=myDS->Shape(j);
292 iX=NMTDS_Tools::TypeToInteger(aTi, aTj);
293 //bFlag=(iStatus==2);
294 aPKXB.SetFlag(bFlag);
295 myLists[iX].Append(aPKXB);
301 }// if (aMPKXB.Add(aPKXB)) {
302 }// for (; aIt.More(); aIt.Next()) {
307 TColStd_ListOfInteger aLV1;
309 const TopoDS_Vertex& aVi=TopoDS::Vertex(aSi);
311 for (; aIt.More(); aIt.Next()) {
313 const TopoDS_Shape& aSj=myDS->Shape(j);
314 const TopoDS_Vertex& aVj=TopoDS::Vertex(aSj);
315 iFlag=NMTDS_Tools::ComputeVV(aVi, aVj);
321 aMPKXB.Remove(aPKXB);
325 aNbLV1=aLV1.Extent();
330 }//for (i=i1; i<=i2; ++i) {
331 }//for (iR=1; iR<aNbR; ++iR) {
337 NMTDS_Iterator::FillMVSD(aMVSD, myMVSD);
339 //modified by NIZNHY-PKV Mon Dec 12 09:51:29 2011f
342 //modified by NIZNHY-PKV Mon Dec 12 09:51:33 2011t
344 //=======================================================================
345 //function : FillMVSD
347 //=======================================================================
348 void NMTDS_Iterator::FillMVSD(const TColStd_DataMapOfIntegerListOfInteger& aMVSD,
349 TColStd_DataMapOfIntegerListOfInteger& bMVSD)
351 Standard_Boolean bFound;
352 Standard_Integer aNbVSD, iCnt, i, j, k;
353 TColStd_ListOfInteger aLV;
354 TColStd_ListIteratorOfListOfInteger aIt;
355 TColStd_MapOfInteger aMF;
356 TColStd_MapIteratorOfMapOfInteger aItMI;
357 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
358 NMTDS_DataMapOfIntegerMapOfInteger aDMIMI;
359 NMTDS_DataMapIteratorOfDataMapOfIntegerMapOfInteger aIti, aItj;
361 aNbVSD=aMVSD.Extent();
366 aItVSD.Initialize(aMVSD);
367 for (; aItVSD.More(); aItVSD.Next()) {
368 TColStd_MapOfInteger aMI;
372 const TColStd_ListOfInteger& aLVSD=aItVSD.Value();
373 aIt.Initialize(aLVSD);
374 for (; aIt.More(); aIt.Next()) {
381 aIti.Initialize(aDMIMI);
382 for (; aIti.More(); aIti.Next()) {
384 if (aMF.Contains(i)) {
389 //TColStd_MapOfInteger& aMIi=aDMIMI.ChangeFind(i);
390 TColStd_MapOfInteger *pMIi=(TColStd_MapOfInteger *)&aIti.Value();
391 TColStd_MapOfInteger& aMIi=*pMIi;
395 aItj.Initialize(aDMIMI);
396 for (; aItj.More(); aItj.Next()) {
398 if (aMF.Contains(j)) {
402 //TColStd_MapOfInteger& aMIj=aDMIMI.ChangeFind(j);
403 TColStd_MapOfInteger *pMj=(TColStd_MapOfInteger *)&aItj.Value();
404 TColStd_MapOfInteger& aMIj=*pMj;
406 aItMI.Initialize(aMIj);
407 for (; aItMI.More(); aItMI.Next()) {
409 bFound=aMIi.Contains(k);
418 aItMI.Initialize(aMIj);
419 for (; aItMI.More(); aItMI.Next()) {
427 } //for (; aItj.More(); aItj.Next()) {
434 aItMI.Initialize(aMIi);
435 for (; aItMI.More(); aItMI.Next()) {
442 }// for (; aIti.More(); aIti.Next()) {
448 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItX;
451 printf(" myMVSD.Extent()=%d\n", myMVSD.Extent());
452 aItX.Initialize(myMVSD);
453 for (; aItX.More(); aItX.Next()) {
455 printf(" i=%d (", i);
456 const TColStd_ListOfInteger& aLV=aItX.Value();
458 for (; aIt.More(); aIt.Next()) {