1 #ifndef vvImageReader_TXX
2 #define vvImageReader_TXX
5 #include <itkImageFileReader.h>
6 #include <itkImageSeriesReader.h>
8 #include "clitkCommon.h"
9 #include "itkImageToVTKImageFilter.h"
10 #include "vvFromITK.h"
11 #include "vvConstants.h"
13 template<unsigned int VImageDimension>
14 void vvImageReader::UpdateWithDim(std::string InputPixelType)
16 if (mType == VECTORFIELD)
17 UpdateWithDimAndInputPixelType<itk::Vector<float,3>,VImageDimension>();
18 else if (InputPixelType == "short")
19 UpdateWithDimAndInputPixelType<short,VImageDimension>();
20 else if (InputPixelType == "unsigned_short")
21 UpdateWithDimAndInputPixelType<unsigned short,VImageDimension>();
22 else if (InputPixelType == "char")
23 UpdateWithDimAndInputPixelType<char,VImageDimension>();
24 else if (InputPixelType == "unsigned_char")
25 UpdateWithDimAndInputPixelType<unsigned char,VImageDimension>();
26 else if (InputPixelType == "int")
27 UpdateWithDimAndInputPixelType<int,VImageDimension>();
28 else if (InputPixelType == "double")
29 UpdateWithDimAndInputPixelType<double,VImageDimension>();
30 else if (InputPixelType == "float")
31 UpdateWithDimAndInputPixelType<float,VImageDimension>();
33 std::cerr << "Error, input pixel type : " << InputPixelType << " unknown !" << std::endl;
35 //====================================================================
37 template<class InputPixelType, unsigned int VImageDimension>
38 void vvImageReader::UpdateWithDimAndInputPixelType()
40 if (mType == MERGEDWITHTIME) // In this case we can load the images
41 // one at the time to avoid excessive
44 typedef itk::Image< InputPixelType, VImageDimension-1 > InputImageType;
45 typedef itk::ImageFileReader<InputImageType> ReaderType;
46 typename ReaderType::Pointer reader = ReaderType::New();
47 typedef itk::ImageToVTKImageFilter <InputImageType> ConnectorType;
48 typename ConnectorType::Pointer connector = ConnectorType::New();
49 connector->SetInput(reader->GetOutput());
50 mImage=vvImage::New();
51 for (std::vector<std::string>::const_iterator i=mInputFilenames.begin();i!=mInputFilenames.end();i++)
53 std::cout << (*i) << std::endl;
54 reader->SetFileName(*i);
58 catch ( itk::ExceptionObject & err ) {
59 std::cerr << "Error while reading " << mInputFilenames[0].c_str()
60 << " " << err << std::endl;
61 std::stringstream error;
63 mLastError = error.str();
69 catch ( itk::ExceptionObject & err ) {
70 std::cerr << "Error while setting vvImage from ITK (MERGEDWITHTIME)"
71 << " " << err << std::endl;
73 vtkImageData *image = vtkImageData::New();
74 image->DeepCopy(connector->GetOutput());
75 mImage->AddImage(image);
80 if (mInputFilenames.size() > 1)
82 typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
83 typedef itk::ImageSeriesReader<InputImageType> ReaderType;
84 typename ReaderType::Pointer reader = ReaderType::New();
85 for (std::vector<std::string>::const_iterator i=mInputFilenames.begin();i!=mInputFilenames.end();i++)
86 std::cout << (*i) << std::endl;
87 reader->SetFileNames(mInputFilenames);
88 //if (mUseAnObserver) {
89 //reader->AddObserver(itk::ProgressEvent(), mObserver);
94 catch ( itk::ExceptionObject & err ) {
95 std::cerr << "Error while reading image series:" << err << std::endl;
96 std::stringstream error;
98 mLastError = error.str();
101 if (mType == IMAGEWITHTIME)
102 mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
104 mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
108 typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
109 typedef itk::ImageFileReader<InputImageType> ReaderType;
110 typename ReaderType::Pointer reader = ReaderType::New();
111 reader->SetFileName(mInputFilenames[0]);
112 //if (mUseAnObserver) {
113 //reader->AddObserver(itk::ProgressEvent(), mObserver);
118 catch ( itk::ExceptionObject & err ) {
119 std::cerr << "Error while reading " << mInputFilenames[0].c_str()
120 << " " << err << std::endl;
121 std::stringstream error;
123 mLastError = error.str();
126 if (mType == IMAGEWITHTIME)
127 mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
129 mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
133 //====================================================================
136 #endif /* end #define vvImageReader_TXX */