template <class TImage>
int
{
using ImageType = TImage;
reader->SetFileName(fileName);
try
{
reader->Update();
}
catch (
const itk::ExceptionObject &
e)
{
std::cerr <<
e.what() << std::endl;
return EXIT_FAILURE;
}
image->Graft(reader->GetOutput());
return EXIT_SUCCESS;
}
template <unsigned int VDimension>
int
{
switch (componentType)
{
default:
std::cerr << "Unknown and unsupported component type!" << std::endl;
return EXIT_FAILURE;
{
using PixelType = unsigned char;
if (ReadImage<ImageType>(inputFileName, image) == EXIT_FAILURE)
{
return EXIT_FAILURE;
}
std::cout << image << std::endl;
break;
}
{
using PixelType = char;
if (ReadImage<ImageType>(inputFileName, image) == EXIT_FAILURE)
{
return EXIT_FAILURE;
}
std::cout << image << std::endl;
break;
}
{
using PixelType = unsigned short;
if (ReadImage<ImageType>(inputFileName, image) == EXIT_FAILURE)
{
return EXIT_FAILURE;
}
std::cout << image << std::endl;
break;
}
{
using PixelType = short;
if (ReadImage<ImageType>(inputFileName, image) == EXIT_FAILURE)
{
return EXIT_FAILURE;
}
std::cout << image << std::endl;
break;
}
{
using PixelType = unsigned int;
if (ReadImage<ImageType>(inputFileName, image) == EXIT_FAILURE)
{
return EXIT_FAILURE;
}
std::cout << image << std::endl;
break;
}
{
using PixelType = int;
if (ReadImage<ImageType>(inputFileName, image) == EXIT_FAILURE)
{
return EXIT_FAILURE;
}
std::cout << image << std::endl;
break;
}
{
using PixelType = unsigned long;
if (ReadImage<ImageType>(inputFileName, image) == EXIT_FAILURE)
{
return EXIT_FAILURE;
}
std::cout << image << std::endl;
break;
}
{
using PixelType = long;
if (ReadImage<ImageType>(inputFileName, image) == EXIT_FAILURE)
{
return EXIT_FAILURE;
}
std::cout << image << std::endl;
break;
}
{
using PixelType = float;
if (ReadImage<ImageType>(inputFileName, image) == EXIT_FAILURE)
{
return EXIT_FAILURE;
}
std::cout << image << std::endl;
break;
}
{
using PixelType = double;
if (ReadImage<ImageType>(inputFileName, image) == EXIT_FAILURE)
{
return EXIT_FAILURE;
}
std::cout << image << std::endl;
break;
}
}
return EXIT_SUCCESS;
}
int
main(int argc, char * argv[])
{
if (argc != 2)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0];
std::cerr << " <InputFileName>";
std::cerr << std::endl;
return EXIT_FAILURE;
}
const char * inputFileName = argv[1];
imageIO->SetFileName(inputFileName);
imageIO->ReadImageInformation();
const IOPixelType pixelType = imageIO->GetPixelType();
const IOComponentType componentType = imageIO->GetComponentType();
std::cout << "Component Type is " << imageIO->GetComponentTypeAsString(componentType) << std::endl;
const unsigned int imageDimension = imageIO->GetNumberOfDimensions();
std::cout << "Image Dimension is " << imageDimension << std::endl;
switch (pixelType)
{
{
if (imageDimension == 2)
{
return ReadScalarImage<2>(inputFileName, componentType);
}
else if (imageDimension == 3)
{
return ReadScalarImage<3>(inputFileName, componentType);
}
else if (imageDimension == 4)
{
return ReadScalarImage<4>(inputFileName, componentType);
}
}
default:
std::cerr << "not implemented yet!" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}