18 #ifndef __itkIOTestHelper_h
19 #define __itkIOTestHelper_h
22 #include "itksys/SystemTools.hxx"
25 #include "vnl/vnl_random.h"
31 template <
typename TImage>
32 static typename TImage::Pointer
ReadImage(
const std::string &fileName,
33 const bool zeroOrigin =
false )
37 typename ReaderType::Pointer reader = ReaderType::New();
39 reader->SetFileName( fileName.c_str() );
46 std::cout <<
"Caught an exception: " << std::endl;
47 std::cout << err <<
" " << __FILE__ <<
" " << __LINE__ << std::endl;
52 std::cout <<
"Error while reading in image for patient " << fileName << std::endl;
56 typename TImage::Pointer image = reader->GetOutput();
59 double origin[TImage::ImageDimension];
60 for(
unsigned int i = 0; i < TImage::ImageDimension; i++)
64 image->SetOrigin(origin);
69 template <
class ImageType,
class ImageIOType>
72 const std::string &filename)
76 typename WriterType::Pointer writer = WriterType::New();
78 typename ImageIOType::Pointer imageio(ImageIOType::New());
80 writer->SetImageIO(imageio);
82 writer->SetFileName(filename.c_str());
84 writer->SetInput(image);
91 std::cerr <<
"Exception Object caught: " << std::endl
102 for(
unsigned int i = 0; i < 3; i++)
108 template <
typename TPixel>
129 return itksys::SystemTools::RemoveFile(fname);
132 template <
class ImageType>
135 typename ImageType::DirectionType dir;
137 im->SetDirection(dir);
140 template <
class ImageType>
141 static typename ImageType::Pointer
143 const typename ImageType::SpacingType &spacing)
145 typename ImageType::Pointer rval = ImageType::New();
146 SetIdentityDirection<ImageType>(rval);
147 rval->SetSpacing(spacing);
148 rval->SetRegions(region);
152 template <
class ImageType>
153 static typename ImageType::Pointer
155 const typename ImageType::SpacingType &spacing,
158 typename ImageType::Pointer rval = ImageType::New();
159 rval->SetSpacing(spacing);
160 rval->SetRegions(region);
161 rval->SetVectorLength(vecLength);
167 #endif // __itkIOTestHelper_h