1 // Copyright (C) 2007-2010 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
23 // File: NMTDS_Iterator.cxx
24 // Created: Sun May 07 15:04:41 2006
25 // Author: Peter KURNEV
27 #include <NMTDS_Iterator.ixx>
29 #include <Bnd_Box.hxx>
31 #include <TColStd_ListOfInteger.hxx>
32 #include <TColStd_ListIteratorOfListOfInteger.hxx>
33 #include <TColStd_MapOfInteger.hxx>
34 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
35 #include <TColStd_DataMapOfIntegerInteger.hxx>
36 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
37 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
38 #include <TColStd_MapOfInteger.hxx>
41 #include <TopoDS_Vertex.hxx>
42 #include <TopoDS_Shape.hxx>
44 #include <TopTools_DataMapOfShapeInteger.hxx>
46 #include <NMTDS_BoxBndTree.hxx>
47 #include <NCollection_UBTreeFiller.hxx>
48 #include <NMTDS_CArray1OfIndexRange.hxx>
49 #include <NMTDS_IndexRange.hxx>
50 #include <NMTDS_PassKeyBoolean.hxx>
51 #include <NMTDS_MapOfPassKeyBoolean.hxx>
52 #include <NMTDS_IndexedDataMapOfShapeBox.hxx>
53 #include <NMTDS_IndexedDataMapOfIntegerShape.hxx>
54 #include <NMTDS_Tools.hxx>
55 #include <NMTDS_DataMapOfIntegerMapOfInteger.hxx>
56 #include <NMTDS_DataMapIteratorOfDataMapOfIntegerMapOfInteger.hxx>
58 //=======================================================================
59 //function : NMTDS_Iterator
61 //=======================================================================
62 NMTDS_Iterator::NMTDS_Iterator()
67 //=======================================================================
68 //function : ~NMTDS_Iterator
70 //=======================================================================
71 NMTDS_Iterator::~NMTDS_Iterator()
74 //=======================================================================
77 //=======================================================================
78 void NMTDS_Iterator::SetDS(const NMTDS_PShapesDataStructure& aDS)
82 //=======================================================================
85 //=======================================================================
86 const NMTDS_ShapesDataStructure& NMTDS_Iterator::DS()const
90 //=======================================================================
91 // function: ExpectedLength
93 //=======================================================================
94 Standard_Integer NMTDS_Iterator::ExpectedLength() const
98 //=======================================================================
99 // function: BlockLength
101 //=======================================================================
102 Standard_Integer NMTDS_Iterator::BlockLength() const
104 Standard_Integer aNbIIs;
105 Standard_Real aCfPredict=.5;
107 aNbIIs=ExpectedLength();
113 aNbIIs=(Standard_Integer) (aCfPredict*(Standard_Real)aNbIIs);
116 //=======================================================================
117 // function: Initialize
119 //=======================================================================
120 void NMTDS_Iterator::Initialize(const TopAbs_ShapeEnum aType1,
121 const TopAbs_ShapeEnum aType2)
125 iX=NMTDS_Tools::TypeToInteger(aType1, aType2);
127 myIterator.Initialize(myLists[iX]);
128 myLength=myLists[iX].Extent();
131 myIterator.Initialize(myEmptyList);
135 //=======================================================================
138 //=======================================================================
139 Standard_Boolean NMTDS_Iterator::More()const
141 return myIterator.More();
143 //=======================================================================
146 //=======================================================================
147 void NMTDS_Iterator::Next()
151 //=======================================================================
154 //=======================================================================
155 void NMTDS_Iterator::Current(Standard_Integer& aIndex1,
156 Standard_Integer& aIndex2,
157 Standard_Boolean& aWithSubShape) const
159 const NMTDS_PassKeyBoolean& aPKB=myIterator.Value();
160 aPKB.Ids(aIndex1, aIndex2);
161 aWithSubShape=aPKB.Flag();
163 //=======================================================================
164 // function: SDVertices
166 //=======================================================================
167 const TColStd_DataMapOfIntegerListOfInteger& NMTDS_Iterator::SDVertices()const
171 //=======================================================================
174 //=======================================================================
175 void NMTDS_Iterator::Prepare()
180 for (i=0; i<6; ++i) {
190 //=======================================================================
191 // function: Intersect
193 //=======================================================================
194 void NMTDS_Iterator::Intersect()
196 Standard_Boolean bFlag;
197 Standard_Integer aNb, i, aNbB, aNbR, iFlag;
198 Standard_Integer i1, i2, aNbSD, iX, j, iDS, jB, iR, k, aNbLV, aNbLV1;
199 TColStd_ListIteratorOfListOfInteger aIt;
200 TColStd_DataMapOfIntegerInteger aMII;
201 TColStd_DataMapOfIntegerListOfInteger aMVSD;
202 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
203 TopTools_DataMapOfShapeInteger aMSI;
204 TopAbs_ShapeEnum aTi, aTj;
205 NMTDS_PassKeyBoolean aPKXB;
206 NMTDS_MapOfPassKeyBoolean aMPKXB;
207 NMTDS_IndexedDataMapOfShapeBox aMSB;
209 NMTDS_BoxBndTreeSelector aSelector;
210 NMTDS_BoxBndTree aBBTree;
211 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
213 const NMTDS_CArray1OfIndexRange& aRanges=myDS->Ranges();
214 aNbR=aRanges.Extent();
216 aNb=myDS->NumberOfShapesOfTheObject();
217 for (i=1; i<=aNb; ++i) {
218 const TopoDS_Shape& aS=myDS->Shape(i);
220 if (NMTDS_Tools::HasBRep(aTi)) {
223 myDS->ComputeBoxEx(i, aBoxEx);
225 aMSB.Add(aS, aBoxEx);
231 for (i=1; i<=aNbB; ++i) {
232 const TopoDS_Shape& aS=aMSB.FindKey(i);
233 const Bnd_Box& aBoxEx=aMSB(i);
235 aTreeFiller.Add(i, aBoxEx);
243 for (iR=1; iR<aNbR; ++iR) {
244 const NMTDS_IndexRange& aR=aRanges(iR);
247 for (i=i1; i<=i2; ++i) {
248 const TopoDS_Shape& aSi=myDS->Shape(i);
250 if (!NMTDS_Tools::HasBRep(aTi)){
253 const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
255 aSelector.SetBox(aBoxEx);
257 aNbSD=aBBTree.Select(aSelector);
263 const TColStd_ListOfInteger& aLI=aSelector.Indices();
266 TColStd_ListOfInteger aLV;
269 for (; aIt.More(); aIt.Next()) {
270 jB=aIt.Value(); // box index in MII
271 j=aMII.Find(jB); // DS index
272 if (j>=i1 && j<=i2) {
273 continue;// same range
278 if (aMPKXB.Add(aPKXB)) {
279 bFlag=Standard_False;// Bounding boxes are intersected
280 const Bnd_Box& aBoxi=myDS->GetBoundingBox(i);
281 const Bnd_Box& aBoxj=myDS->GetBoundingBox(j);
282 if (aBoxi.IsOut(aBoxj)) {
283 bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
285 const TopoDS_Shape& aSj=myDS->Shape(j);
287 iX=NMTDS_Tools::TypeToInteger(aTi, aTj);
288 //bFlag=(iStatus==2);
289 aPKXB.SetFlag(bFlag);
290 myLists[iX].Append(aPKXB);
296 }// if (aMPKXB.Add(aPKXB)) {
297 }// for (; aIt.More(); aIt.Next()) {
302 TColStd_ListOfInteger aLV1;
304 const TopoDS_Vertex& aVi=TopoDS::Vertex(aSi);
306 for (; aIt.More(); aIt.Next()) {
308 const TopoDS_Shape& aSj=myDS->Shape(j);
309 const TopoDS_Vertex& aVj=TopoDS::Vertex(aSj);
310 iFlag=NMTDS_Tools::ComputeVV(aVi, aVj);
316 aMPKXB.Remove(aPKXB);
320 //modified by NIZNHY-PKV Mon Sep 27 08:31:04 2010f
321 aNbLV1=aLV1.Extent();
325 //aMVSD.Bind(i, aLV1);
326 //modified by NIZNHY-PKV Mon Sep 27 08:31:21 2010t
328 }//for (i=i1; i<=i2; ++i) {
329 }//for (iR=1; iR<aNbR; ++iR) {
335 NMTDS_Iterator::FillMVSD(aMVSD, myMVSD);
337 //=======================================================================
338 //function : FillMVSD
340 //=======================================================================
341 void NMTDS_Iterator::FillMVSD(const TColStd_DataMapOfIntegerListOfInteger& aMVSD,
342 TColStd_DataMapOfIntegerListOfInteger& bMVSD)
344 Standard_Boolean bFound;
345 Standard_Integer aNbVSD, iCnt, i, j, k;
346 TColStd_ListOfInteger aLV;
347 TColStd_ListIteratorOfListOfInteger aIt;
348 TColStd_MapOfInteger aMF;
349 TColStd_MapIteratorOfMapOfInteger aItMI;
350 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
351 NMTDS_DataMapOfIntegerMapOfInteger aDMIMI;
352 NMTDS_DataMapIteratorOfDataMapOfIntegerMapOfInteger aIti, aItj;
354 aNbVSD=aMVSD.Extent();
359 aItVSD.Initialize(aMVSD);
360 for (; aItVSD.More(); aItVSD.Next()) {
361 TColStd_MapOfInteger aMI;
365 const TColStd_ListOfInteger& aLVSD=aItVSD.Value();
366 aIt.Initialize(aLVSD);
367 for (; aIt.More(); aIt.Next()) {
374 aIti.Initialize(aDMIMI);
375 for (; aIti.More(); aIti.Next()) {
377 if (aMF.Contains(i)) {
382 //TColStd_MapOfInteger& aMIi=aDMIMI.ChangeFind(i);
383 TColStd_MapOfInteger *pMIi=(TColStd_MapOfInteger *)&aIti.Value();
384 TColStd_MapOfInteger& aMIi=*pMIi;
388 aItj.Initialize(aDMIMI);
389 for (; aItj.More(); aItj.Next()) {
391 if (aMF.Contains(j)) {
395 //TColStd_MapOfInteger& aMIj=aDMIMI.ChangeFind(j);
396 TColStd_MapOfInteger *pMj=(TColStd_MapOfInteger *)&aItj.Value();
397 TColStd_MapOfInteger& aMIj=*pMj;
399 aItMI.Initialize(aMIj);
400 for (; aItMI.More(); aItMI.Next()) {
402 bFound=aMIi.Contains(k);
411 aItMI.Initialize(aMIj);
412 for (; aItMI.More(); aItMI.Next()) {
420 } //for (; aItj.More(); aItj.Next()) {
427 aItMI.Initialize(aMIi);
428 for (; aItMI.More(); aItMI.Next()) {
435 }// for (; aIti.More(); aIti.Next()) {
441 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItX;
444 printf(" myMVSD.Extent()=%d\n", myMVSD.Extent());
445 aItX.Initialize(myMVSD);
446 for (; aItX.More(); aItX.Next()) {
448 printf(" i=%d (", i);
449 const TColStd_ListOfInteger& aLV=aItX.Value();
451 for (; aIt.More(); aIt.Next()) {