1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestAMRIterator.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 #include "vtkOverlappingAMR.h"
16 #include "vtkAMRGaussianPulseSource.h"
17 #include "vtkUniformGridAMRDataIterator.h"
18
19 #include <iostream>
20 #include <string>
21
22 //-----------------------------------------------------------------------------
TestAMRIterator(int,char * [])23 int TestAMRIterator( int, char *[] )
24 {
25 unsigned int expected[3][2] =
26 {
27 {0,0},
28 {1,0},
29 {1,1}
30 };
31
32 int rc = 0;
33
34 vtkAMRGaussianPulseSource *amrSource = vtkAMRGaussianPulseSource::New();
35 amrSource->Update();
36 vtkOverlappingAMR *amrData =
37 vtkOverlappingAMR::SafeDownCast( amrSource->GetOutput() );
38
39
40 vtkUniformGridAMRDataIterator *iter = vtkUniformGridAMRDataIterator::SafeDownCast(amrData->NewIterator());
41 iter->InitTraversal();
42 for(int idx=0 ;!iter->IsDoneWithTraversal(); iter->GoToNextItem(),++idx )
43 {
44 unsigned int level = iter->GetCurrentLevel();
45 unsigned int id = iter->GetCurrentIndex();
46 cout << "Level: " << level << " Block: " << id;
47 cout << endl;
48 if( level != expected[idx][0] )
49 {
50 ++rc;
51 }
52 if( id != expected[idx][1] )
53 {
54 ++rc;
55 }
56 } // END for
57 iter->Delete();
58
59 amrSource->Delete();
60 return( rc );
61 }
62