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 "vtkAMRGaussianPulseSource.h"
16 #include "vtkOverlappingAMR.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] = { { 0, 0 }, { 1, 0 }, { 1, 1 } };
26 
27   int rc = 0;
28 
29   vtkAMRGaussianPulseSource* amrSource = vtkAMRGaussianPulseSource::New();
30   amrSource->Update();
31   vtkOverlappingAMR* amrData = vtkOverlappingAMR::SafeDownCast(amrSource->GetOutput());
32 
33   vtkUniformGridAMRDataIterator* iter =
34     vtkUniformGridAMRDataIterator::SafeDownCast(amrData->NewIterator());
35   iter->InitTraversal();
36   for (int idx = 0; !iter->IsDoneWithTraversal(); iter->GoToNextItem(), ++idx)
37   {
38     unsigned int level = iter->GetCurrentLevel();
39     unsigned int id = iter->GetCurrentIndex();
40     cout << "Level: " << level << " Block: " << id;
41     cout << endl;
42     if (level != expected[idx][0])
43     {
44       ++rc;
45     }
46     if (id != expected[idx][1])
47     {
48       ++rc;
49     }
50   } // END for
51   iter->Delete();
52 
53   amrSource->Delete();
54   return (rc);
55 }
56