1 #ifndef ITKIMAGEIMPORTER_HPP_
2 #define ITKIMAGEIMPORTER_HPP_
7 #include <itkImageSource.h>
8 #include <itkImageRegionIterator.h>
12 template <
class TImage>
16 void setInput(
typename TImage::Pointer image);
20 void* getITKDataPointer();
22 typename TImage::Pointer mInput;
27 template<
class TImage>
29 createOutputPort<fast::Image>(0);
32 template<
class TImage>
34 typename TImage::Pointer image) {
40 template<
class TImage>
42 typename TImage::PixelType* data;
43 itk::ImageRegionIterator<TImage> imageIterator(mInput,
44 mInput->GetLargestPossibleRegion());
46 typename TImage::RegionType region = mInput->GetLargestPossibleRegion();
47 unsigned int width = region.GetSize()[0];
48 unsigned int height = region.GetSize()[1];
49 if(TImage::ImageDimension == 2) {
50 data =
new typename TImage::PixelType[width*height];
51 while (!imageIterator.IsAtEnd()) {
52 unsigned int x = imageIterator.GetIndex()[0];
53 unsigned int y = imageIterator.GetIndex()[1];
54 data[x + y*width] = imageIterator.Get();
59 unsigned int depth = region.GetSize()[2];
60 data =
new typename TImage::PixelType[width*height*depth];
62 while (!imageIterator.IsAtEnd()) {
63 unsigned int x = imageIterator.GetIndex()[0];
64 unsigned int y = imageIterator.GetIndex()[1];
65 unsigned int z = imageIterator.GetIndex()[2];
66 data[x + y*width + z*width*height] = imageIterator.Get();
77 template<
class TImage>
84 if(
typeid(
typename TImage::PixelType) ==
typeid(
float)) {
86 }
else if(
typeid(
typename TImage::PixelType) ==
typeid(
char)) {
88 }
else if(
typeid(
typename TImage::PixelType) ==
typeid(
unsigned char)) {
90 }
else if(
typeid(
typename TImage::PixelType) ==
typeid(
short)) {
92 }
else if(
typeid(
typename TImage::PixelType) ==
typeid(
unsigned short)) {
95 throw Exception(
"Unsupported pixel type sent to ITKImageImporter");
97 void* data = getITKDataPointer();
98 typename TImage::RegionType region = mInput->GetLargestPossibleRegion();
99 unsigned int width = region.GetSize()[0];
100 unsigned int height = region.GetSize()[1];
101 Image::pointer output = getOutputData<Image>();
102 if(TImage::ImageDimension == 2) {
103 output->create(width, height, type, 1, Host::getInstance(), data);
104 }
else if(TImage::ImageDimension == 3) {
105 unsigned int depth = region.GetSize()[3];
106 output->create(width, height, depth, type, 1, Host::getInstance(), data);
108 throw Exception(
"The ITKImageImporter only supports 2D and 3D images.");