1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: NMTDS_Iterator.cxx
21 // Created: Sun May 07 15:04:41 2006
22 // Author: Peter KURNEV
26 #include <NMTDS_Iterator.ixx>
27 #include <NMTDS_CArray1OfIndexRange.hxx>
28 #include <NMTDS_IndexRange.hxx>
29 #include <Bnd_Box.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TColStd_ListOfInteger.hxx>
32 #include <TColStd_Array1OfListOfInteger.hxx>
33 #include <TColStd_ListIteratorOfListOfInteger.hxx>
34 #include <TColStd_MapOfInteger.hxx>
35 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
36 #include <NMTDS_PassKeyBoolean.hxx>
37 #include <NMTDS_MapOfPassKeyBoolean.hxx>
38 #include <NMTDS_IndexedDataMapOfShapeBox.hxx>
39 #include <NMTDS_IndexedDataMapOfIntegerShape.hxx>
40 #include <Bnd_HArray1OfBox.hxx>
41 #include <Bnd_BoundSortBox.hxx>
42 #include <TColStd_ListOfInteger.hxx>
43 #include <TColStd_DataMapOfIntegerInteger.hxx>
44 #include <TopTools_DataMapOfShapeInteger.hxx>
45 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
46 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
47 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
48 #include <TColStd_MapOfInteger.hxx>
50 #include <NMTDS_BoxBndTree.hxx>
51 #include <NCollection_UBTreeFiller.hxx>
54 void ComputeBoxEx(const Standard_Integer aIx,
55 NMTDS_ShapesDataStructure* pDS,
59 Standard_Boolean IsValidType(const TopAbs_ShapeEnum aT);
62 Standard_Integer TypeToInteger(const TopAbs_ShapeEnum aType1,
63 const TopAbs_ShapeEnum aType2);
66 //=======================================================================
67 //function : NMTDS_Iterator
69 //=======================================================================
70 NMTDS_Iterator::NMTDS_Iterator()
75 //=======================================================================
76 //function : ~NMTDS_Iterator
78 //=======================================================================
79 NMTDS_Iterator::~NMTDS_Iterator()
82 //=======================================================================
85 //=======================================================================
86 void NMTDS_Iterator::SetDS(const NMTDS_PShapesDataStructure& aDS)
90 //=======================================================================
93 //=======================================================================
94 const NMTDS_ShapesDataStructure& NMTDS_Iterator::DS()const
98 //=======================================================================
99 // function: ExpectedLength
101 //=======================================================================
102 Standard_Integer NMTDS_Iterator::ExpectedLength() const
106 //=======================================================================
107 // function: Initialize
109 //=======================================================================
110 void NMTDS_Iterator::Initialize(const TopAbs_ShapeEnum aType1,
111 const TopAbs_ShapeEnum aType2)
115 iX=TypeToInteger(aType1, aType2);
117 myIterator.Initialize(myLists[iX]);
118 myLength=myLists[iX].Extent();
121 myIterator.Initialize(myEmptyList);
125 //=======================================================================
128 //=======================================================================
129 Standard_Boolean NMTDS_Iterator::More()const
131 return myIterator.More();
133 //=======================================================================
136 //=======================================================================
137 void NMTDS_Iterator::Next()
141 //=======================================================================
144 //=======================================================================
145 void NMTDS_Iterator::Current(Standard_Integer& aIndex1,
146 Standard_Integer& aIndex2,
147 Standard_Boolean& aWithSubShape) const
149 const NMTDS_PassKeyBoolean& aPKB=myIterator.Value();
150 aPKB.Ids(aIndex1, aIndex2);
151 aWithSubShape=aPKB.Flag();
153 //=======================================================================
154 // function: SDVertices
156 //=======================================================================
157 const TColStd_DataMapOfIntegerListOfInteger& NMTDS_Iterator::SDVertices()const
162 //=======================================================================
165 //=======================================================================
166 void NMTDS_Iterator::Prepare()
168 Standard_Boolean bFlag;
169 Standard_Integer aNb, i, aNbB, aNbR;
170 Standard_Integer i1, i2, aNbSD, iX, j, iDS, jB, iR, k, aNbLV;
171 TColStd_ListIteratorOfListOfInteger aIt;
172 TColStd_DataMapOfIntegerInteger aMII;
173 TColStd_MapOfInteger aMFence;
174 TopTools_DataMapOfShapeInteger aMSI;
175 TopAbs_ShapeEnum aTi, aTj;
176 NMTDS_PassKeyBoolean aPKXB;
177 NMTDS_MapOfPassKeyBoolean aMPKXB;
178 NMTDS_IndexedDataMapOfShapeBox aMSB;
179 Handle(Bnd_HArray1OfBox) aHAB;
180 Bnd_BoundSortBox aBSB;
182 NMTDS_BoxBndTreeSelector aSelector;
183 NMTDS_BoxBndTree aBBTree;
184 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
191 for (i=0; i<6; ++i) {
196 const NMTDS_CArray1OfIndexRange& aRanges=myPDS->Ranges();
197 aNbR=aRanges.Extent();
199 aNb=myPDS->NumberOfShapesOfTheObject();
200 for (i=1; i<=aNb; ++i) {
201 const TopoDS_Shape& aS=myPDS->Shape(i);
203 if (IsValidType(aTi)) {
206 ComputeBoxEx(i, myPDS, aBoxEx);
208 aMSB.Add(aS, aBoxEx);
214 for (i=1; i<=aNbB; ++i) {
215 const TopoDS_Shape& aS=aMSB.FindKey(i);
216 const Bnd_Box& aBoxEx=aMSB(i);
218 aTreeFiller.Add(i, aBoxEx);
226 for (iR=1; iR<aNbR; ++iR) {
227 const NMTDS_IndexRange& aR=aRanges(iR);
230 for (i=i1; i<=i2; ++i) {
231 const TopoDS_Shape& aSi=myPDS->Shape(i);
233 if (!IsValidType(aTi)){
236 const Bnd_Box& aBoxEx=aMSB.FindFromKey(aSi);
238 aSelector.SetBox(aBoxEx);
240 aNbSD=aBBTree.Select(aSelector);
246 const TColStd_ListOfInteger& aLI=aSelector.Indices();
249 TColStd_ListOfInteger aLV;
252 for (; aIt.More(); aIt.Next()) {
253 jB=aIt.Value(); // box index in MII
254 j=aMII.Find(jB); // DS index
255 if (j>=i1 && j<=i2) {
256 continue;// same range
260 if (aMPKXB.Add(aPKXB)) {
261 bFlag=Standard_False;// Bounding boxes are intersected
262 const Bnd_Box& aBoxi=myPDS->GetBoundingBox(i);
263 const Bnd_Box& aBoxj=myPDS->GetBoundingBox(j);
264 if (aBoxi.IsOut(aBoxj)) {
265 bFlag=!bFlag; //Bounding boxes of Sub-shapes are intersected
267 const TopoDS_Shape& aSj=myPDS->Shape(j);
269 iX=TypeToInteger(aTi, aTj);
271 aPKXB.SetFlag(bFlag);
272 myLists[iX].Append(aPKXB);
276 if (aMFence.Add(j)) {
280 }// if (aMPKXB.Add(aPKXB)) {
281 }// for (; aIt.More(); aIt.Next()) {
288 }//for (i=i1; i<=i2; ++i) {
289 }//for (iR=1; iR<aNbR; ++iR) {
292 //=======================================================================
293 // function: IsValidType
295 //=======================================================================
296 Standard_Boolean IsValidType(const TopAbs_ShapeEnum aTi)
298 return (aTi==TopAbs_VERTEX || aTi==TopAbs_EDGE || aTi==TopAbs_FACE);
300 //=======================================================================
301 // function: ComputeBoxEx
303 //=======================================================================
304 void ComputeBoxEx(const Standard_Integer aIx,
305 NMTDS_ShapesDataStructure* pDS,
308 Standard_Integer i, aNbS, iS;
310 const Bnd_Box& aBox=pDS->GetBoundingBox(aIx);
313 aNbS=pDS->NumberOfSuccessors(aIx);
314 for (i=1; i<=aNbS; ++i) {
316 iS=pDS->GetSuccessor(aIx, i);
317 ComputeBoxEx(iS, pDS, aBoxS);
322 //=======================================================================
323 // function: TypeToInteger
325 //=======================================================================
326 Standard_Integer TypeToInteger(const TopAbs_ShapeEnum aType1,
327 const TopAbs_ShapeEnum aType2)
329 Standard_Integer iRet, iT1, iT2, iX;
332 iT1=(Standard_Integer)aType1;
333 iT2=(Standard_Integer)aType2;
367 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger aIt1;
368 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aIt2;
371 printf(" aMVLV.Extent()=%d\n", aMVLV.Extent());
372 aIt1.Initialize(aMVLV);
373 for (; aIt1.More(); aIt1.Next()) {
375 printf(" i=%d (", i);
376 const TColStd_ListOfInteger& aLV=aIt1.Value();
378 for (; aIt.More(); aIt.Next()) {
386 printf(" aMVV.Extent()=%d\n", aMVV.Extent());
387 aIt2.Initialize(aMVV);
388 for (; aIt2.More(); aIt2.Next()) {
391 printf(" (%d, %d)\n", i, j);