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 ======================================================================-====*/
20 #include "clitkImageToImageGenericFilterBase.h"
25 //--------------------------------------------------------------------
26 clitk::ImageToImageGenericFilterBase::~ImageToImageGenericFilterBase() {}
27 //--------------------------------------------------------------------
30 //--------------------------------------------------------------------
31 clitk::ImageToImageGenericFilterBase::ImageToImageGenericFilterBase(std::string n)
35 m_FailOnImageTypeError = true;
39 //--------------------------------------------------------------------
42 //--------------------------------------------------------------------
43 void clitk::ImageToImageGenericFilterBase::SetInputFilenames(const std::vector<std::string> & filenames)
45 m_InputFilenames = filenames;
47 //--------------------------------------------------------------------
50 //--------------------------------------------------------------------
51 void clitk::ImageToImageGenericFilterBase::EnableReadOnDisk(bool b)
55 //--------------------------------------------------------------------
58 //--------------------------------------------------------------------
59 void clitk::ImageToImageGenericFilterBase::SetInputFilename(const std::string & filename)
61 std::vector<std::string> f;
62 f.push_back(filename);
65 //--------------------------------------------------------------------
68 //--------------------------------------------------------------------
69 void clitk::ImageToImageGenericFilterBase::AddInputFilename(const std::string & filename)
71 m_InputFilenames.push_back(filename);
73 //--------------------------------------------------------------------
76 //--------------------------------------------------------------------
77 void clitk::ImageToImageGenericFilterBase::SetOutputFilename(const std::string & filename)
79 m_OutputFilenames.clear();
80 m_OutputFilenames.push_back(filename);
82 //--------------------------------------------------------------------
85 //--------------------------------------------------------------------
86 void clitk::ImageToImageGenericFilterBase::AddOutputFilename(const std::string & filename)
88 m_OutputFilenames.push_back(filename);
90 //--------------------------------------------------------------------
93 //--------------------------------------------------------------------
94 void clitk::ImageToImageGenericFilterBase::SetOutputFilenames(const std::vector<std::string> & filenames)
96 m_OutputFilenames.clear();
97 std::copy(filenames.begin(),filenames.end(),m_OutputFilenames.begin());
99 //--------------------------------------------------------------------
102 //--------------------------------------------------------------------
103 std::string clitk::ImageToImageGenericFilterBase::GetOutputFilename()
105 assert(m_OutputFilenames.size() == 1);
106 return m_OutputFilenames.front();
108 //--------------------------------------------------------------------
111 //--------------------------------------------------------------------
112 void clitk::ImageToImageGenericFilterBase::GetInputImageDimensionAndPixelType(unsigned int& dim, \
113 std::string& pixeltype,unsigned int& components)
115 if (m_ReadOnDisk && m_InputFilenames.size()) {
116 int comp_temp,dim_temp; //clitkCommonImage takes ints
117 ReadImageDimensionAndPixelType(m_InputFilenames[0], dim_temp, pixeltype,comp_temp);
118 components=comp_temp;
121 if (m_InputVVImages.size()) {
122 pixeltype = m_InputVVImages[0]->GetScalarTypeAsITKString();
123 dim = m_InputVVImages[0]->GetNumberOfDimensions();
124 components = m_InputVVImages[0]->GetNumberOfScalarComponents();
126 assert(false); //No input image, shouldn't happen
129 std::cout << "Input is " << m_Dim << "D " << m_PixelTypeName << "." << std::endl;
132 //--------------------------------------------------------------------
135 //--------------------------------------------------------------------
136 vvImage::Pointer clitk::ImageToImageGenericFilterBase::GetOutputVVImage ()
138 assert(m_OutputVVImages.size());
139 return m_OutputVVImages[0];
141 //--------------------------------------------------------------------
144 //--------------------------------------------------------------------
145 std::vector<vvImage::Pointer> clitk::ImageToImageGenericFilterBase::GetOutputVVImages()
147 return m_OutputVVImages;
149 //--------------------------------------------------------------------
152 //--------------------------------------------------------------------
153 void clitk::ImageToImageGenericFilterBase::SetInputVVImage (vvImage::Pointer input)
155 m_InputVVImages.clear();
156 m_InputVVImages.push_back(input);
158 //--------------------------------------------------------------------
161 //--------------------------------------------------------------------
162 void clitk::ImageToImageGenericFilterBase::AddInputVVImage (vvImage::Pointer input)
164 m_InputVVImages.push_back(input);
166 //--------------------------------------------------------------------
169 //--------------------------------------------------------------------
170 void clitk::ImageToImageGenericFilterBase::SetInputVVImages (std::vector<vvImage::Pointer> input)
172 m_InputVVImages=input;
174 //--------------------------------------------------------------------
177 //--------------------------------------------------------------------
178 void clitk::ImageToImageGenericFilterBase::PrintAvailableImageTypes()
180 std::cout << GetAvailableImageTypes();
182 //--------------------------------------------------------------------
186 //--------------------------------------------------------------------
187 void clitk::ImageToImageGenericFilterBase::ImageTypeError()
189 std::cerr << "**Error** The filter <" << m_FilterName << "> is not available for "
190 << m_Dim << "D images with pixel="
191 << m_PixelTypeName << " and "
192 << m_NbOfComponents << " component." << std::endl;
193 std::cerr << GetAvailableImageTypes();
196 //--------------------------------------------------------------------
199 //--------------------------------------------------------------------
200 void clitk::ImageToImageGenericFilterBase::SetImageTypeError()
202 std::cerr << "TODO ! " << std::endl;
205 //--------------------------------------------------------------------
208 //--------------------------------------------------------------------
209 const std::string & clitk::ImageToImageGenericFilterBase::GetFilterName()
213 //--------------------------------------------------------------------
216 //--------------------------------------------------------------------
217 void clitk::ImageToImageGenericFilterBase::SetFilterName(std::string & n)
221 //--------------------------------------------------------------------
224 //--------------------------------------------------------------------
225 void clitk::ImageToImageGenericFilterBase::SetIOVerbose(bool b)
229 //--------------------------------------------------------------------
231 #define DEF_SetNextOutput_And_GetInput(PixelType, Dim) \
233 void clitk::ImageToImageGenericFilterBase::SetNextOutput<itk::Image<PixelType, Dim> >(itk::Image<PixelType,Dim>::Pointer output); \
235 itk::Image<PixelType, Dim>::Pointer clitk::ImageToImageGenericFilterBase::GetInput<itk::Image<PixelType, Dim> >(unsigned int n);
237 #define DEF_SetNextOutput_And_GetInput_WithCompo(Compo, Dim) \
239 void clitk::ImageToImageGenericFilterBase::SetNextOutput<itk::Image<itk::Vector<float, Compo>, Dim> >(itk::Image<itk::Vector<float, Compo>,Dim>::Pointer output); \
241 itk::Image<itk::Vector<float,Compo>, Dim>::Pointer clitk::ImageToImageGenericFilterBase::GetInput<itk::Image<itk::Vector<float, Compo>, Dim> >(unsigned int n);
243 DEF_SetNextOutput_And_GetInput(char, 2);
244 DEF_SetNextOutput_And_GetInput(unsigned char, 2);
245 DEF_SetNextOutput_And_GetInput(short, 2);
246 DEF_SetNextOutput_And_GetInput(unsigned short, 2);
247 DEF_SetNextOutput_And_GetInput(int, 2);
248 DEF_SetNextOutput_And_GetInput(float, 2);
249 DEF_SetNextOutput_And_GetInput(double, 2);
251 DEF_SetNextOutput_And_GetInput(char, 3);
252 DEF_SetNextOutput_And_GetInput(unsigned char, 3);
253 DEF_SetNextOutput_And_GetInput(short, 3);
254 DEF_SetNextOutput_And_GetInput(unsigned short, 3);
255 DEF_SetNextOutput_And_GetInput(int, 3);
256 DEF_SetNextOutput_And_GetInput(float, 3);
257 DEF_SetNextOutput_And_GetInput(double, 3);
259 DEF_SetNextOutput_And_GetInput_WithCompo(2, 2);
260 DEF_SetNextOutput_And_GetInput_WithCompo(2, 3);
261 DEF_SetNextOutput_And_GetInput_WithCompo(2, 4);
262 DEF_SetNextOutput_And_GetInput_WithCompo(3, 2);
263 DEF_SetNextOutput_And_GetInput_WithCompo(3, 3);
264 DEF_SetNextOutput_And_GetInput_WithCompo(3, 4);
265 DEF_SetNextOutput_And_GetInput_WithCompo(4, 2);
266 DEF_SetNextOutput_And_GetInput_WithCompo(4, 3);
267 DEF_SetNextOutput_And_GetInput_WithCompo(4, 4);
269 DEF_SetNextOutput_And_GetInput(char, 4);
270 DEF_SetNextOutput_And_GetInput(unsigned char, 4);
271 DEF_SetNextOutput_And_GetInput(short, 4);
272 DEF_SetNextOutput_And_GetInput(unsigned short, 4);
273 DEF_SetNextOutput_And_GetInput(int, 4);
274 DEF_SetNextOutput_And_GetInput(float, 4);
275 DEF_SetNextOutput_And_GetInput(double, 4);
278 //--------------------------------------------------------------------
279 template<class ImageType>
280 void clitk::ImageToImageGenericFilterBase::SetNextOutput(typename ImageType::Pointer output)
282 if (m_OutputFilenames.size()) {
283 clitk::writeImage<ImageType>(output, m_OutputFilenames.front(), m_IOVerbose);
284 m_OutputFilenames.pop_front();
286 if (m_InputVVImages.size()) //We assume that if a vv image is set as input, we want one as the output
287 m_OutputVVImages.push_back(vvImageFromITK<ImageType::ImageDimension,typename ImageType::PixelType>(output));
289 //--------------------------------------------------------------------
292 //--------------------------------------------------------------------
293 template<class ImageType>
294 typename ImageType::Pointer clitk::ImageToImageGenericFilterBase::GetInput(unsigned int n)
296 if (m_ReadOnDisk && m_InputFilenames.size() > n) {
297 return clitk::readImage<ImageType>(m_InputFilenames[n], m_IOVerbose);
299 if (m_InputVVImages.size() > n)
300 return typename ImageType::Pointer(const_cast<ImageType*>(vvImageToITK<ImageType>(m_InputVVImages[n]).GetPointer()));
302 assert(false); //No input, this shouldn't happen
303 return typename ImageType::Pointer(NULL);
307 //--------------------------------------------------------------------