1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #ifndef vvImageReader_TXX
19 #define vvImageReader_TXX
22 #include <itkImageFileReader.h>
23 #include <itkImageSeriesReader.h>
25 #include "clitkCommon.h"
26 #include "itkImageToVTKImageFilter.h"
27 #include "vvFromITK.h"
28 #include "vvConstants.h"
30 template<unsigned int VImageDimension>
31 void vvImageReader::UpdateWithDim(std::string InputPixelType)
33 if (mType == VECTORFIELD)
34 UpdateWithDimAndInputPixelType<itk::Vector<float,3>,VImageDimension>();
35 else if (InputPixelType == "short")
36 UpdateWithDimAndInputPixelType<short,VImageDimension>();
37 else if (InputPixelType == "unsigned_short")
38 UpdateWithDimAndInputPixelType<unsigned short,VImageDimension>();
39 else if (InputPixelType == "char")
40 UpdateWithDimAndInputPixelType<char,VImageDimension>();
41 else if (InputPixelType == "unsigned_char")
42 UpdateWithDimAndInputPixelType<unsigned char,VImageDimension>();
43 else if (InputPixelType == "int")
44 UpdateWithDimAndInputPixelType<int,VImageDimension>();
45 else if (InputPixelType == "double")
46 UpdateWithDimAndInputPixelType<double,VImageDimension>();
47 else if (InputPixelType == "float")
48 UpdateWithDimAndInputPixelType<float,VImageDimension>();
50 std::cerr << "Error, input pixel type : " << InputPixelType << " unknown !" << std::endl;
52 //====================================================================
54 template<class InputPixelType, unsigned int VImageDimension>
55 void vvImageReader::UpdateWithDimAndInputPixelType()
57 if (mType == MERGEDWITHTIME) // In this case we can load the images
58 // one at the time to avoid excessive
61 typedef itk::Image< InputPixelType, VImageDimension-1 > InputImageType;
62 typedef itk::ImageFileReader<InputImageType> ReaderType;
63 typename ReaderType::Pointer reader = ReaderType::New();
64 typedef itk::ImageToVTKImageFilter <InputImageType> ConnectorType;
65 typename ConnectorType::Pointer connector = ConnectorType::New();
66 connector->SetInput(reader->GetOutput());
67 mImage=vvImage::New();
68 for (std::vector<std::string>::const_iterator i=mInputFilenames.begin();i!=mInputFilenames.end();i++)
70 std::cout << (*i) << std::endl;
71 reader->SetFileName(*i);
75 catch ( itk::ExceptionObject & err ) {
76 std::cerr << "Error while reading " << mInputFilenames[0].c_str()
77 << " " << err << std::endl;
78 std::stringstream error;
80 mLastError = error.str();
86 catch ( itk::ExceptionObject & err ) {
87 std::cerr << "Error while setting vvImage from ITK (MERGEDWITHTIME)"
88 << " " << err << std::endl;
90 vtkImageData *image = vtkImageData::New();
91 image->DeepCopy(connector->GetOutput());
92 mImage->AddImage(image);
97 if (mInputFilenames.size() > 1)
99 typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
100 typedef itk::ImageSeriesReader<InputImageType> ReaderType;
101 typename ReaderType::Pointer reader = ReaderType::New();
102 for (std::vector<std::string>::const_iterator i=mInputFilenames.begin();i!=mInputFilenames.end();i++)
103 std::cout << (*i) << std::endl;
104 reader->SetFileNames(mInputFilenames);
105 //if (mUseAnObserver) {
106 //reader->AddObserver(itk::ProgressEvent(), mObserver);
111 catch ( itk::ExceptionObject & err ) {
112 std::cerr << "Error while reading image series:" << err << std::endl;
113 std::stringstream error;
115 mLastError = error.str();
118 if (mType == IMAGEWITHTIME)
119 mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
121 mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
125 typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
126 typedef itk::ImageFileReader<InputImageType> ReaderType;
127 typename ReaderType::Pointer reader = ReaderType::New();
128 reader->SetFileName(mInputFilenames[0]);
129 //if (mUseAnObserver) {
130 //reader->AddObserver(itk::ProgressEvent(), mObserver);
135 catch ( itk::ExceptionObject & err ) {
136 std::cerr << "Error while reading " << mInputFilenames[0].c_str()
137 << " " << err << std::endl;
138 std::stringstream error;
140 mLastError = error.str();
143 if (mType == IMAGEWITHTIME)
144 mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
146 mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
150 //====================================================================
153 #endif /* end #define vvImageReader_TXX */