1 // Copyright (C) 2007-2008 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 // Created: Sun May 07 15:04:41 2006
24 // Author: Peter KURNEV
26 #include <NMTDS_Iterator.ixx>
28 #include <Bnd_Box.hxx>
30 #include <TColStd_ListOfInteger.hxx>
31 #include <TColStd_ListIteratorOfListOfInteger.hxx>
32 #include <TColStd_MapOfInteger.hxx>
33 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
34 #include <TColStd_DataMapOfIntegerInteger.hxx>
35 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
36 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
37 #include <TColStd_MapOfInteger.hxx>
40 #include <TopoDS_Vertex.hxx>
41 #include <TopoDS_Shape.hxx>
43 #include <TopTools_DataMapOfShapeInteger.hxx>
45 #include <NMTDS_BoxBndTree.hxx>
46 #include <NCollection_UBTreeFiller.hxx>
47 #include <NMTDS_CArray1OfIndexRange.hxx>
48 #include <NMTDS_IndexRange.hxx>
49 #include <NMTDS_PassKeyBoolean.hxx>
50 #include <NMTDS_MapOfPassKeyBoolean.hxx>
51 #include <NMTDS_IndexedDataMapOfShapeBox.hxx>
52 #include <NMTDS_IndexedDataMapOfIntegerShape.hxx>
53 #include <NMTDS_Tools.hxx>
54 #include <NMTDS_DataMapOfIntegerMapOfInteger.hxx>
55 #include <NMTDS_DataMapIteratorOfDataMapOfIntegerMapOfInteger.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;
104 Standard_Real aCfPredict=.5;
106 aNbIIs=ExpectedLength();
112 aNbIIs=(Standard_Integer) (aCfPredict*(Standard_Real)aNbIIs);
115 //=======================================================================
116 // function: Initialize
118 //=======================================================================
119 void NMTDS_Iterator::Initialize(const TopAbs_ShapeEnum aType1,
120 const TopAbs_ShapeEnum aType2)
124 iX=NMTDS_Tools::TypeToInteger(aType1, aType2);
126 myIterator.Initialize(myLists[iX]);
127 myLength=myLists[iX].Extent();
130 myIterator.Initialize(myEmptyList);
134 //=======================================================================
137 //=======================================================================
138 Standard_Boolean NMTDS_Iterator::More()const
140 return myIterator.More();
142 //=======================================================================
145 //=======================================================================
146 void NMTDS_Iterator::Next()
150 //=======================================================================
153 //=======================================================================
154 void NMTDS_Iterator::Current(Standard_Integer& aIndex1,
155 Standard_Integer& aIndex2,
156 Standard_Boolean& aWithSubShape) const
158 const NMTDS_PassKeyBoolean& aPKB=myIterator.Value();
159 aPKB.Ids(aIndex1, aIndex2);
160 aWithSubShape=aPKB.Flag();
162 //=======================================================================
163 // function: SDVertices
165 //=======================================================================
166 const TColStd_DataMapOfIntegerListOfInteger& NMTDS_Iterator::SDVertices()const
170 //=======================================================================
173 //=======================================================================
174 void NMTDS_Iterator::Prepare()
179 for (i=0; i<6; ++i) {
189 //=======================================================================
190 // function: Intersect
192 //=======================================================================
193 void NMTDS_Iterator::Intersect()
195 Standard_Boolean bFlag;
196 Standard_Integer aNb, i, aNbB, aNbR, iFlag;
197 Standard_Integer i1, i2, aNbSD, iX, j, iDS, jB, iR, k, aNbLV;
198 TColStd_ListIteratorOfListOfInteger aIt;
199 TColStd_DataMapOfIntegerInteger aMII;
200 //modified by NIZNHY-PKV Mon Jan 22 15:08:00 2007f
201 //TColStd_MapOfInteger aMFence;
202 TColStd_DataMapOfIntegerListOfInteger aMVSD;
203 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
204 //modified by NIZNHY-PKV Mon Jan 22 10:21:50 2007t
205 TopTools_DataMapOfShapeInteger aMSI;
206 TopAbs_ShapeEnum aTi, aTj;
207 NMTDS_PassKeyBoolean aPKXB;
208 NMTDS_MapOfPassKeyBoolean aMPKXB;
209 NMTDS_IndexedDataMapOfShapeBox aMSB;
211 NMTDS_BoxBndTreeSelector aSelector;
212 NMTDS_BoxBndTree aBBTree;
213 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
215 const NMTDS_CArray1OfIndexRange& aRanges=myDS->Ranges();
216 aNbR=aRanges.Extent();
218 aNb=myDS->NumberOfShapesOfTheObject();
219 for (i=1; i<=aNb; ++i) {
220 const TopoDS_Shape& aS=myDS->Shape(i);
222 if (NMTDS_Tools::HasBRep(aTi)) {
225 myDS->ComputeBoxEx(i, aBoxEx);
227 aMSB.Add(aS, aBoxEx);
233 for (i=1; i<=aNbB; ++i) {
234 const TopoDS_Shape& aS=aMSB.FindKey(i);
235 const Bnd_Box& aBoxEx=aMSB(i);
237 aTreeFiller.Add(i, aBoxEx);
245 for (iR=1; iR<aNbR; ++iR) {
246 const NMTDS_IndexRange& aR=aRanges(iR);
249 for (i=i1; i<=i2; ++i) {
250 const TopoDS_Shape& aSi=myDS->Shape(i);
252 if (!NMTDS_Tools::HasBRep(aTi)){
255 const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
257 aSelector.SetBox(aBoxEx);
259 aNbSD=aBBTree.Select(aSelector);
265 const TColStd_ListOfInteger& aLI=aSelector.Indices();
268 TColStd_ListOfInteger aLV;
271 for (; aIt.More(); aIt.Next()) {
272 jB=aIt.Value(); // box index in MII
273 j=aMII.Find(jB); // DS index
274 if (j>=i1 && j<=i2) {
275 continue;// same range
280 if (aMPKXB.Add(aPKXB)) {
281 bFlag=Standard_False;// Bounding boxes are intersected
282 const Bnd_Box& aBoxi=myDS->GetBoundingBox(i);
283 const Bnd_Box& aBoxj=myDS->GetBoundingBox(j);
284 if (aBoxi.IsOut(aBoxj)) {
285 bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
287 const TopoDS_Shape& aSj=myDS->Shape(j);
289 iX=NMTDS_Tools::TypeToInteger(aTi, aTj);
290 //bFlag=(iStatus==2);
291 aPKXB.SetFlag(bFlag);
292 myLists[iX].Append(aPKXB);
298 }// if (aMPKXB.Add(aPKXB)) {
299 }// for (; aIt.More(); aIt.Next()) {
304 TColStd_ListOfInteger aLV1;
306 const TopoDS_Vertex& aVi=TopoDS::Vertex(aSi);
308 for (; aIt.More(); aIt.Next()) {
310 const TopoDS_Shape& aSj=myDS->Shape(j);
311 const TopoDS_Vertex& aVj=TopoDS::Vertex(aSj);
312 iFlag=NMTDS_Tools::ComputeVV(aVi, aVj);
318 aMPKXB.Remove(aPKXB);
323 }//for (i=i1; i<=i2; ++i) {
324 }//for (iR=1; iR<aNbR; ++iR) {
330 NMTDS_Iterator::FillMVSD(aMVSD, myMVSD);
332 //=======================================================================
333 //function : FillMVSD
335 //=======================================================================
336 void NMTDS_Iterator::FillMVSD(const TColStd_DataMapOfIntegerListOfInteger& aMVSD,
337 TColStd_DataMapOfIntegerListOfInteger& bMVSD)
339 Standard_Boolean bFound;
340 Standard_Integer aNbVSD, iCnt, i, j, k;
341 TColStd_ListOfInteger aLV;
342 TColStd_ListIteratorOfListOfInteger aIt;
343 TColStd_MapOfInteger aMF;
344 TColStd_MapIteratorOfMapOfInteger aItMI;
345 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItVSD;
346 NMTDS_DataMapOfIntegerMapOfInteger aDMIMI;
347 NMTDS_DataMapIteratorOfDataMapOfIntegerMapOfInteger aIti, aItj;
349 aNbVSD=aMVSD.Extent();
354 aItVSD.Initialize(aMVSD);
355 for (; aItVSD.More(); aItVSD.Next()) {
356 TColStd_MapOfInteger aMI;
360 const TColStd_ListOfInteger& aLVSD=aItVSD.Value();
361 aIt.Initialize(aLVSD);
362 for (; aIt.More(); aIt.Next()) {
369 aIti.Initialize(aDMIMI);
370 for (; aIti.More(); aIti.Next()) {
372 if (aMF.Contains(i)) {
377 //TColStd_MapOfInteger& aMIi=aDMIMI.ChangeFind(i);
378 TColStd_MapOfInteger *pMIi=(TColStd_MapOfInteger *)&aIti.Value();
379 TColStd_MapOfInteger& aMIi=*pMIi;
383 aItj.Initialize(aDMIMI);
384 for (; aItj.More(); aItj.Next()) {
386 if (aMF.Contains(j)) {
390 //TColStd_MapOfInteger& aMIj=aDMIMI.ChangeFind(j);
391 TColStd_MapOfInteger *pMj=(TColStd_MapOfInteger *)&aItj.Value();
392 TColStd_MapOfInteger& aMIj=*pMj;
394 aItMI.Initialize(aMIj);
395 for (; aItMI.More(); aItMI.Next()) {
397 bFound=aMIi.Contains(k);
406 aItMI.Initialize(aMIj);
407 for (; aItMI.More(); aItMI.Next()) {
415 } //for (; aItj.More(); aItj.Next()) {
422 aItMI.Initialize(aMIi);
423 for (; aItMI.More(); aItMI.Next()) {
430 }// for (; aIti.More(); aIti.Next()) {
436 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aItX;
439 printf(" myMVSD.Extent()=%d\n", myMVSD.Extent());
440 aItX.Initialize(myMVSD);
441 for (; aItX.More(); aItX.Next()) {
443 printf(" i=%d (", i);
444 const TColStd_ListOfInteger& aLV=aItX.Value();
446 for (; aIt.More(); aIt.Next()) {