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.hxx>
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>
55 #include <NMTDS_ShapesDataStructure.hxx>
57 //=======================================================================
58 //function : NMTDS_Iterator
60 //=======================================================================
61 NMTDS_Iterator::NMTDS_Iterator()
66 //=======================================================================
67 //function : ~NMTDS_Iterator
69 //=======================================================================
70 NMTDS_Iterator::~NMTDS_Iterator()
73 //=======================================================================
76 //=======================================================================
77 void NMTDS_Iterator::SetDS(const NMTDS_PShapesDataStructure& aDS)
81 //=======================================================================
84 //=======================================================================
85 const NMTDS_ShapesDataStructure& NMTDS_Iterator::DS()const
89 //=======================================================================
90 // function: ExpectedLength
92 //=======================================================================
93 Standard_Integer NMTDS_Iterator::ExpectedLength() const
97 //=======================================================================
98 // function: BlockLength
100 //=======================================================================
101 Standard_Integer NMTDS_Iterator::BlockLength() const
103 Standard_Integer aNbIIs, iTresh;
104 Standard_Real aCfPredict=.5;
106 aNbIIs=ExpectedLength();
111 //modified by NIZNHY-PKV Mon Dec 12 08:50:50 2011f
117 //modified by NIZNHY-PKV Mon Dec 12 08:50:54 2011t
119 aNbIIs=(Standard_Integer) (aCfPredict*(Standard_Real)aNbIIs);
122 //=======================================================================
123 // function: Initialize
125 //=======================================================================
126 void NMTDS_Iterator::Initialize(const TopAbs_ShapeEnum aType1,
127 const TopAbs_ShapeEnum aType2)
131 iX=NMTDS_Tools::TypeToInteger(aType1, aType2);
133 myIterator.Initialize(myLists[iX]);
134 myLength=myLists[iX].Extent();
137 myIterator.Initialize(myEmptyList);
141 //=======================================================================
144 //=======================================================================
145 Standard_Boolean NMTDS_Iterator::More()const
147 return myIterator.More();
149 //=======================================================================
152 //=======================================================================
153 void NMTDS_Iterator::Next()
157 //=======================================================================
160 //=======================================================================
161 void NMTDS_Iterator::Current(Standard_Integer& aIndex1,
162 Standard_Integer& aIndex2,
163 Standard_Boolean& aWithSubShape) const
165 const NMTDS_PairBoolean& aPKB=myIterator.Value();
166 aPKB.Ids(aIndex1, aIndex2);
167 aWithSubShape=aPKB.Flag();
169 //=======================================================================
170 // function: SDVertices
172 //=======================================================================
173 const TColStd_DataMapOfIntegerListOfInteger& NMTDS_Iterator::SDVertices()const
177 //=======================================================================
180 //=======================================================================
181 void NMTDS_Iterator::Prepare()
186 for (i=0; i<6; ++i) {
196 //=======================================================================
197 // function: Intersect
199 //=======================================================================
200 void NMTDS_Iterator::Intersect()
202 Standard_Boolean bFlag;
203 Standard_Integer aNb, i, aNbB, aNbR, iFlag;
204 Standard_Integer i1, i2, aNbSD, iX, j, iDS, jB, iR, k, aNbLV, aNbLV1;
205 TColStd_ListIteratorOfListOfInteger aIt;
206 TColStd_DataMapOfIntegerInteger aMII;
207 TColStd_DataMapOfIntegerListOfInteger aMVSD;
208 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
209 TopTools_DataMapOfShapeInteger aMSI;
210 TopAbs_ShapeEnum aTi, aTj;
211 NMTDS_PairBoolean aPKXB;
212 NMTDS_MapOfPairBoolean aMPKXB;
213 NMTDS_IndexedDataMapOfShapeBox aMSB;
215 NMTDS_BoxBndTreeSelector aSelector;
216 NMTDS_BoxBndTree aBBTree;
217 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
219 const NMTDS_CArray1OfIndexRange& aRanges=myDS->Ranges();
220 aNbR=aRanges.Extent();
222 aNb=myDS->NumberOfShapesOfTheObject();
223 for (i=1; i<=aNb; ++i) {
224 const TopoDS_Shape& aS=myDS->Shape(i);
226 if (NMTDS_Tools::HasBRep(aTi)) {
229 myDS->ComputeBoxEx(i, aBoxEx);
231 aMSB.Add(aS, aBoxEx);
237 for (i=1; i<=aNbB; ++i) {
238 const TopoDS_Shape& aS=aMSB.FindKey(i);
239 const Bnd_Box& aBoxEx=aMSB(i);
241 aTreeFiller.Add(i, aBoxEx);
249 for (iR=1; iR<aNbR; ++iR) {
250 const NMTDS_IndexRange& aR=aRanges(iR);
253 for (i=i1; i<=i2; ++i) {
254 const TopoDS_Shape& aSi=myDS->Shape(i);
256 if (!NMTDS_Tools::HasBRep(aTi)){
259 const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
261 aSelector.SetBox(aBoxEx);
263 aNbSD=aBBTree.Select(aSelector);
269 const TColStd_ListOfInteger& aLI=aSelector.Indices();
272 TColStd_ListOfInteger aLV;
275 for (; aIt.More(); aIt.Next()) {
276 jB=aIt.Value(); // box index in MII
277 j=aMII.Find(jB); // DS index
278 if (j>=i1 && j<=i2) {
279 continue;// same range
284 if (aMPKXB.Add(aPKXB)) {
285 bFlag=Standard_False;// Bounding boxes are intersected
286 const Bnd_Box& aBoxi=myDS->GetBoundingBox(i);
287 const Bnd_Box& aBoxj=myDS->GetBoundingBox(j);
288 if (aBoxi.IsOut(aBoxj)) {
289 bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
291 const TopoDS_Shape& aSj=myDS->Shape(j);
293 iX=NMTDS_Tools::TypeToInteger(aTi, aTj);
294 //bFlag=(iStatus==2);
295 aPKXB.SetFlag(bFlag);
296 myLists[iX].Append(aPKXB);
302 }// if (aMPKXB.Add(aPKXB)) {
303 }// for (; aIt.More(); aIt.Next()) {
308 TColStd_ListOfInteger aLV1;
310 const TopoDS_Vertex& aVi=TopoDS::Vertex(aSi);
312 for (; aIt.More(); aIt.Next()) {
314 const TopoDS_Shape& aSj=myDS->Shape(j);
315 const TopoDS_Vertex& aVj=TopoDS::Vertex(aSj);
316 iFlag=NMTDS_Tools::ComputeVV(aVi, aVj);
322 aMPKXB.Remove(aPKXB);
326 aNbLV1=aLV1.Extent();
331 }//for (i=i1; i<=i2; ++i) {
332 }//for (iR=1; iR<aNbR; ++iR) {
338 NMTDS_Iterator::FillMVSD(aMVSD, myMVSD);
340 //modified by NIZNHY-PKV Mon Dec 12 09:51:29 2011f
343 //modified by NIZNHY-PKV Mon Dec 12 09:51:33 2011t
345 //=======================================================================
346 //function : FillMVSD
348 //=======================================================================
349 void NMTDS_Iterator::FillMVSD(const TColStd_DataMapOfIntegerListOfInteger& aMVSD,
350 TColStd_DataMapOfIntegerListOfInteger& bMVSD)
352 Standard_Boolean bFound;
353 Standard_Integer aNbVSD, iCnt, i, j, k;
354 TColStd_ListOfInteger aLV;
355 TColStd_ListIteratorOfListOfInteger aIt;
356 TColStd_MapOfInteger aMF;
357 TColStd_MapIteratorOfMapOfInteger aItMI;
358 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
359 NMTDS_DataMapOfIntegerMapOfInteger aDMIMI;
360 NMTDS_DataMapIteratorOfDataMapOfIntegerMapOfInteger aIti, aItj;
362 aNbVSD=aMVSD.Extent();
367 aItVSD.Initialize(aMVSD);
368 for (; aItVSD.More(); aItVSD.Next()) {
369 TColStd_MapOfInteger aMI;
373 const TColStd_ListOfInteger& aLVSD=aItVSD.Value();
374 aIt.Initialize(aLVSD);
375 for (; aIt.More(); aIt.Next()) {
382 aIti.Initialize(aDMIMI);
383 for (; aIti.More(); aIti.Next()) {
385 if (aMF.Contains(i)) {
390 //TColStd_MapOfInteger& aMIi=aDMIMI.ChangeFind(i);
391 TColStd_MapOfInteger *pMIi=(TColStd_MapOfInteger *)&aIti.Value();
392 TColStd_MapOfInteger& aMIi=*pMIi;
396 aItj.Initialize(aDMIMI);
397 for (; aItj.More(); aItj.Next()) {
399 if (aMF.Contains(j)) {
403 //TColStd_MapOfInteger& aMIj=aDMIMI.ChangeFind(j);
404 TColStd_MapOfInteger *pMj=(TColStd_MapOfInteger *)&aItj.Value();
405 TColStd_MapOfInteger& aMIj=*pMj;
407 aItMI.Initialize(aMIj);
408 for (; aItMI.More(); aItMI.Next()) {
410 bFound=aMIi.Contains(k);
419 aItMI.Initialize(aMIj);
420 for (; aItMI.More(); aItMI.Next()) {
428 } //for (; aItj.More(); aItj.Next()) {
435 aItMI.Initialize(aMIi);
436 for (; aItMI.More(); aItMI.Next()) {
443 }// for (; aIti.More(); aIti.Next()) {
449 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItX;
452 printf(" myMVSD.Extent()=%d\n", myMVSD.Extent());
453 aItX.Initialize(myMVSD);
454 for (; aItX.More(); aItX.Next()) {
456 printf(" i=%d (", i);
457 const TColStd_ListOfInteger& aLV=aItX.Value();
459 for (; aIt.More(); aIt.Next()) {