1 #ifndef ITKIMAGEEXPORTER_HPP_
2 #define ITKIMAGEEXPORTER_HPP_
7 #include <itkImageSource.h>
8 #include <itkImageRegionIterator.h>
12 template<
class TImage>
24 itkTypeMacro(MyImageSource, ImageSource);
41 template<
class TImage>
43 createInputPort<Image>(0);
46 template <
class TImage>
50 typename TImage::Pointer output = this->GetOutput();
51 typename TImage::RegionType region;
52 typename TImage::IndexType start;
55 if(input->getDimensions() == 3)
58 typename TImage::SizeType size;
59 size[0] = input->getWidth();
60 size[1] = input->getHeight();
61 if(input->getDimensions() == 3)
62 size[2] = input->getDepth();
65 region.SetIndex(start);
67 output->SetRegions(region);
70 ImageAccess::pointer access = input->getImageAccess(
ACCESS_READ);
71 T * fastPixelData = (T*)access->get();
73 itk::ImageRegionIterator<TImage> imageIterator(output,
74 output->GetLargestPossibleRegion());
75 unsigned int width = input->getWidth();
76 if(input->getDimensions() == 2) {
77 while (!imageIterator.IsAtEnd()) {
78 unsigned int x = imageIterator.GetIndex()[0];
79 unsigned int y = imageIterator.GetIndex()[1];
80 imageIterator.Set(fastPixelData[x + y*width]);
85 unsigned int height = input->getHeight();
87 while (!imageIterator.IsAtEnd()) {
88 unsigned int x = imageIterator.GetIndex()[0];
89 unsigned int y = imageIterator.GetIndex()[1];
90 unsigned int z = imageIterator.GetIndex()[2];
91 imageIterator.Set(fastPixelData[x + y*width + z*width*height]);
98 template<
class TImage>
103 Image::pointer input = getInputData<Image>();
104 if(input->getDimensions() != TImage::ImageDimension)
105 throw Exception(
"The dimension of the input and output images of the ITKImageExporter are unequal.");
107 if(input->getNrOfChannels() != 1)
108 throw Exception(
"The ITKImageExporter currently doesn't support images with multiple components");
112 switch(input->getDataType()) {
119 #endif // ITKIMAGEEXPORTER_HPP_