18 #ifndef itkIOTestHelper_h
19 #define itkIOTestHelper_h
20 #include "ITKIOImageBaseExport.h"
23 #include "itksys/SystemTools.hxx"
26 #include "vnl/vnl_random.h"
32 template <
typename TImage>
33 static typename TImage::Pointer
ReadImage(
const std::string &fileName,
34 const bool zeroOrigin =
false )
38 typename ReaderType::Pointer reader = ReaderType::New();
40 reader->SetFileName( fileName.c_str() );
47 std::cout <<
"Caught an exception: " << std::endl;
48 std::cout << err <<
" " << __FILE__ <<
" " << __LINE__ << std::endl;
53 std::cout <<
"Error while reading in image for patient " << fileName << std::endl;
57 typename TImage::Pointer image = reader->GetOutput();
60 double origin[TImage::ImageDimension];
61 for(
unsigned int i = 0; i < TImage::ImageDimension; i++)
65 image->SetOrigin(origin);
70 template <
typename ImageType,
typename ImageIOType>
73 const std::string &filename)
77 typename WriterType::Pointer writer = WriterType::New();
79 typename ImageIOType::Pointer imageio(ImageIOType::New());
81 writer->SetImageIO(imageio);
83 writer->SetFileName(filename.c_str());
85 writer->SetInput(image);
92 std::cerr <<
"Exception Object caught: " << std::endl
103 for(
unsigned int i = 0; i < 3; i++)
109 template <
typename TPixel>
120 pix = (pix << 32) | randgen.lrand32();
126 pix = randgen.lrand32();
127 pix = (pix << 32) | randgen.lrand32();
144 return itksys::SystemTools::RemoveFile(fname);
147 template <
typename ImageType>
152 im->SetDirection(dir);
155 template <
typename ImageType>
156 static typename ImageType::Pointer
158 const typename ImageType::SpacingType &spacing)
160 typename ImageType::Pointer rval = ImageType::New();
161 SetIdentityDirection<ImageType>(rval);
162 rval->SetSpacing(spacing);
163 rval->SetRegions(region);
167 template <
typename ImageType>
168 static typename ImageType::Pointer
170 const typename ImageType::SpacingType &spacing,
173 typename ImageType::Pointer rval = ImageType::New();
174 rval->SetSpacing(spacing);
175 rval->SetRegions(region);
176 rval->SetVectorLength(vecLength);
182 #endif // itkIOTestHelper_h
static void RandomPix(vnl_random &randgen, TPixel &pix)
static void RandomPix(vnl_random &randgen, unsigned long long &pix)
static void RandomPix(vnl_random &randgen, float &pix)
static void RandomPix(vnl_random &randgen, itk::RGBPixel< unsigned char > &pix)
ImageBaseType::DirectionType DirectionType
static TImage::Pointer ReadImage(const std::string &fileName, const bool zeroOrigin=false)
static void RandomPix(vnl_random &randgen, long long &pix)
static ImageType::Pointer AllocateImageFromRegionAndSpacing(const typename ImageType::RegionType ®ion, const typename ImageType::SpacingType &spacing, int vecLength)
Standard exception handling object.
static void WriteImage(typename ImageType::Pointer &image, const std::string &filename)
static ImageType::Pointer AllocateImageFromRegionAndSpacing(const typename ImageType::RegionType ®ion, const typename ImageType::SpacingType &spacing)
Represent Red, Green and Blue components for color images.
static void RandomPix(vnl_random &randgen, double &pix)
Writes image data to a single file.
Data source that reads image data from a single file.
static void SetIdentityDirection(typename ImageType::Pointer &im)
Define additional traits for native types such as int or float.
static int Remove(const char *fname)