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
35 const bool zeroOrigin =
false,
40 typename ReaderType::Pointer reader = ReaderType::New();
44 reader->SetImageIO(imageio);
46 reader->SetFileName(
fileName.c_str());
51 catch (
const itk::ExceptionObject & err)
53 std::cout <<
"Caught an exception: " << std::endl;
54 std::cout << err <<
" " << __FILE__ <<
" " << __LINE__ << std::endl;
59 std::cout <<
"Error while reading in image for patient " <<
fileName << std::endl;
63 typename TImage::Pointer image = reader->GetOutput();
66 double origin[TImage::ImageDimension];
67 for (
unsigned int i = 0; i < TImage::ImageDimension; i++)
71 image->SetOrigin(origin);
76 template <
typename ImageType,
typename ImageIOType>
79 const std::string & filename,
80 typename ImageIOType::Pointer imageio =
nullptr)
84 typename WriterType::Pointer writer = WriterType::New();
88 imageio = ImageIOType::New();
91 writer->SetImageIO(imageio);
93 writer->SetFileName(filename.c_str());
95 writer->SetInput(image);
101 catch (
const itk::ExceptionObject & err)
103 std::cerr <<
"Exception Object caught: " << std::endl << err << std::endl;
113 for (
unsigned int i = 0; i < 3; i++)
119 template <
typename TPixel>
130 pix = (pix << 32) | randgen.lrand32();
134 RandomPix(vnl_random & randgen,
unsigned long long & pix)
136 pix = randgen.lrand32();
137 pix = (pix << 32) | randgen.lrand32();
155 return itksys::SystemTools::RemoveFile(fname);
158 template <
typename ImageType>
164 im->SetDirection(dir);
167 template <
typename ImageType>
168 static typename ImageType::Pointer
170 const typename ImageType::SpacingType & spacing)
172 typename ImageType::Pointer rval = ImageType::New();
173 SetIdentityDirection<ImageType>(rval);
174 rval->SetSpacing(spacing);
175 rval->SetRegions(region);
179 template <
typename ImageType>
180 static typename ImageType::Pointer
182 const typename ImageType::SpacingType & spacing,
185 typename ImageType::Pointer rval = ImageType::New();
186 rval->SetSpacing(spacing);
187 rval->SetRegions(region);
188 rval->SetVectorLength(vecLength);
194 #endif // itkIOTestHelper_h