1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestFlashReader.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include <iostream>
#include <string>
#include "vtkAMRFlashReader.h"
#include "vtkSetGet.h"
#include "vtkTestUtilities.h"
#include "vtkOverlappingAMR.h"
#include "vtkUniformGridAMRDataIterator.h"
namespace FlashReaderTest {
//------------------------------------------------------------------------------
template<class T>
int CheckValue( std::string name, T actualValue, T expectedValue )
{
if( actualValue != expectedValue )
{
std::cerr << "ERROR: " << name << " value mismatch! ";
std::cerr << "Expected: " << expectedValue << " Actual: " << actualValue;
std::cerr << std::endl;
return 1;
}
return 0;
}
int ComputeMaxNonEmptyLevel(vtkOverlappingAMR* amr)
{
vtkUniformGridAMRDataIterator* iter = vtkUniformGridAMRDataIterator::SafeDownCast(amr->NewIterator());
iter->SetSkipEmptyNodes(true);
int maxLevel(-1);
for(iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
int level = iter->GetCurrentLevel();
if(level>maxLevel)
{
maxLevel = level;
}
}
iter->Delete();
return maxLevel+1;
}
} // END namespace
int TestFlashReader( int argc, char *argv[] )
{
int rc = 0;
int NumBlocksPerLevel[] = {1,8,64,512,3456,15344,78208};
vtkAMRFlashReader *flashReader = vtkAMRFlashReader::New();
char *fileName =
vtkTestUtilities::ExpandDataFileName(argc,argv,
"Data/AMR/Flash/smooth/smooth.flash");
std::cout << "Filename: " << fileName << std::endl;
std::cout.flush();
vtkOverlappingAMR *amr = NULL;
flashReader->SetFileName( fileName );
for(int level = 0; level < flashReader->GetNumberOfLevels(); ++level )
{
flashReader->SetMaxLevel( level );
flashReader->Update();
rc+=FlashReaderTest::CheckValue("LEVEL",flashReader->GetNumberOfLevels(),7);
rc+=FlashReaderTest::CheckValue("BLOCKS",flashReader->GetNumberOfBlocks(),97593);
amr = flashReader->GetOutput();
if( amr != NULL )
{
rc+=FlashReaderTest::CheckValue(
"OUTPUT LEVELS",static_cast<int>(FlashReaderTest::ComputeMaxNonEmptyLevel(amr)),level+1);
rc+=FlashReaderTest::CheckValue(
"NUMBER OF BLOCKS AT LEVEL",
static_cast<int>(amr->GetNumberOfDataSets(level)),
NumBlocksPerLevel[level]
);
}
else
{
std::cerr << "ERROR: output AMR dataset is NULL!";
return 1;
}
} // END for all levels
flashReader->Delete();
delete [] fileName;
return( rc );
}
|