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
|
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html 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 "gdcmTesting.h"
#include "gdcmImageReader.h"
#include "gdcmImage.h"
int TestImageReaderPixelSpacing(int argc, char *argv[])
{
int ret = 0;
const char *filenames[] = { "CRIMAGE", "DXIMAGE", "MGIMAGE" };
const unsigned int nfiles = sizeof(filenames)/sizeof(*filenames);
const char *root = gdcm::Testing::GetPixelSpacingDataRoot();
if( !root || !*root )
{
std::cerr << "root is not defined" << std::endl;
return 1;
}
std::string sroot = root;
sroot += "/DISCIMG/IMAGES/";
const double spacing_ref[] = {0.5, 0.5};
for(unsigned int i = 0; i < nfiles; ++i)
{
std::string filename = sroot + filenames[i];
//std::cout << filename << std::endl;
gdcm::ImageReader r;
r.SetFileName( filename.c_str() );
if( !r.Read() )
{
ret++;
std::cerr << "could not read: " << filename << std::endl;
}
const gdcm::Image &image = r.GetImage();
const double *spacing = image.GetSpacing();
std::cout << spacing[0] << ","
<< spacing[1] << ","
<< spacing[2] << std::endl;
if( spacing[0] != spacing_ref[0]
|| spacing[1] != spacing_ref[1] )
{
std::cerr << "Wrong spacing for: " << filename << std::endl;
++ret;
}
}
return ret;
}
|