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 #include "clitkImageToImageGenericFilterBase.h"
21 //--------------------------------------------------------------------
22 clitk::ImageToImageGenericFilterBase::~ImageToImageGenericFilterBase() {}
23 //--------------------------------------------------------------------
26 //--------------------------------------------------------------------
27 clitk::ImageToImageGenericFilterBase::ImageToImageGenericFilterBase(std::string n)
31 m_FailOnImageTypeError = true;
35 //--------------------------------------------------------------------
38 //--------------------------------------------------------------------
39 void clitk::ImageToImageGenericFilterBase::SetInputFilenames(const std::vector<std::string> & filenames)
41 m_InputFilenames = filenames;
43 //--------------------------------------------------------------------
46 //--------------------------------------------------------------------
47 void clitk::ImageToImageGenericFilterBase::EnableReadOnDisk(bool b)
51 //--------------------------------------------------------------------
54 //--------------------------------------------------------------------
55 void clitk::ImageToImageGenericFilterBase::SetInputFilename(const std::string & filename)
57 std::vector<std::string> f;
58 f.push_back(filename);
61 //--------------------------------------------------------------------
64 //--------------------------------------------------------------------
65 void clitk::ImageToImageGenericFilterBase::AddInputFilename(const std::string & filename)
67 m_InputFilenames.push_back(filename);
69 //--------------------------------------------------------------------
72 //--------------------------------------------------------------------
73 void clitk::ImageToImageGenericFilterBase::SetOutputFilename(const std::string & filename)
75 m_OutputFilenames.clear();
76 m_OutputFilenames.push_back(filename);
78 //--------------------------------------------------------------------
81 //--------------------------------------------------------------------
82 void clitk::ImageToImageGenericFilterBase::AddOutputFilename(const std::string & filename)
84 m_OutputFilenames.push_back(filename);
86 //--------------------------------------------------------------------
89 //--------------------------------------------------------------------
90 void clitk::ImageToImageGenericFilterBase::SetOutputFilenames(const std::vector<std::string> & filenames)
92 m_OutputFilenames.clear();
93 std::copy(filenames.begin(),filenames.end(),m_OutputFilenames.begin());
95 //--------------------------------------------------------------------
98 //--------------------------------------------------------------------
99 std::string clitk::ImageToImageGenericFilterBase::GetOutputFilename()
101 assert(m_OutputFilenames.size() == 1);
102 return m_OutputFilenames.front();
104 //--------------------------------------------------------------------
107 //--------------------------------------------------------------------
108 void clitk::ImageToImageGenericFilterBase::GetInputImageDimensionAndPixelType(unsigned int& dim, \
109 std::string& pixeltype,unsigned int& components)
111 if (m_ReadOnDisk && m_InputFilenames.size()) {
112 int comp_temp,dim_temp; //clitkCommonImage takes ints
113 ReadImageDimensionAndPixelType(m_InputFilenames[0], dim_temp, pixeltype,comp_temp);
114 components=comp_temp;
117 if (m_InputVVImages.size()) {
118 pixeltype=m_InputVVImages[0]->GetScalarTypeAsString();
119 dim=m_InputVVImages[0]->GetNumberOfDimensions();
120 components=m_InputVVImages[0]->GetNumberOfScalarComponents();
122 assert(false); //No input image, shouldn't happen
125 std::cout << "Input is " << m_Dim << "D " << m_PixelTypeName << "." << std::endl;
128 //--------------------------------------------------------------------
131 //--------------------------------------------------------------------
132 vvImage::Pointer clitk::ImageToImageGenericFilterBase::GetOutputVVImage ()
134 assert(m_OutputVVImages.size());
135 return m_OutputVVImages[0];
137 //--------------------------------------------------------------------
140 //--------------------------------------------------------------------
141 std::vector<vvImage::Pointer> clitk::ImageToImageGenericFilterBase::GetOutputVVImages()
143 return m_OutputVVImages;
145 //--------------------------------------------------------------------
148 //--------------------------------------------------------------------
149 void clitk::ImageToImageGenericFilterBase::SetInputVVImage (vvImage::Pointer input)
151 m_InputVVImages.clear();
152 m_InputVVImages.push_back(input);
154 //--------------------------------------------------------------------
157 //--------------------------------------------------------------------
158 void clitk::ImageToImageGenericFilterBase::AddInputVVImage (vvImage::Pointer input)
160 m_InputVVImages.push_back(input);
162 //--------------------------------------------------------------------
165 //--------------------------------------------------------------------
166 void clitk::ImageToImageGenericFilterBase::SetInputVVImages (std::vector<vvImage::Pointer> input)
168 m_InputVVImages=input;
170 //--------------------------------------------------------------------
173 //--------------------------------------------------------------------
174 void clitk::ImageToImageGenericFilterBase::PrintAvailableImageTypes()
176 std::cout << GetAvailableImageTypes();
178 //--------------------------------------------------------------------
182 //--------------------------------------------------------------------
183 void clitk::ImageToImageGenericFilterBase::ImageTypeError()
185 std::cerr << "**Error** The filter <" << m_FilterName << "> is not available for "
186 << m_Dim << "D images with pixel="
187 << m_PixelTypeName << " and "
188 << m_NbOfComponents << " component." << std::endl;
189 std::cerr << GetAvailableImageTypes();
192 //--------------------------------------------------------------------
195 //--------------------------------------------------------------------
196 void clitk::ImageToImageGenericFilterBase::SetImageTypeError()
198 std::cerr << "TODO ! " << std::endl;
201 //--------------------------------------------------------------------
204 //--------------------------------------------------------------------
205 const std::string & clitk::ImageToImageGenericFilterBase::GetFilterName()
209 //--------------------------------------------------------------------
212 //--------------------------------------------------------------------
213 void clitk::ImageToImageGenericFilterBase::SetFilterName(std::string & n)
217 //--------------------------------------------------------------------
220 //--------------------------------------------------------------------
221 void clitk::ImageToImageGenericFilterBase::SetIOVerbose(bool b)
225 //--------------------------------------------------------------------
227 #define DEF_SetNextOutput_And_GetInput(PixelType, Dim) \
229 void clitk::ImageToImageGenericFilterBase::SetNextOutput<itk::Image<PixelType, Dim> >(itk::Image<PixelType,Dim>::Pointer output); \
231 itk::Image<PixelType, Dim>::Pointer clitk::ImageToImageGenericFilterBase::GetInput<itk::Image<PixelType, Dim> >(unsigned int n);
233 #define DEF_SetNextOutput_And_GetInput_WithCompo(Compo, Dim) \
235 void clitk::ImageToImageGenericFilterBase::SetNextOutput<itk::Image<itk::Vector<float, Compo>, Dim> >(itk::Image<itk::Vector<float, Compo>,Dim>::Pointer output); \
237 itk::Image<itk::Vector<float,Compo>, Dim>::Pointer clitk::ImageToImageGenericFilterBase::GetInput<itk::Image<itk::Vector<float, Compo>, Dim> >(unsigned int n);
239 DEF_SetNextOutput_And_GetInput(char, 2);
240 DEF_SetNextOutput_And_GetInput(unsigned char, 2);
241 DEF_SetNextOutput_And_GetInput(short, 2);
242 DEF_SetNextOutput_And_GetInput(unsigned short, 2);
243 DEF_SetNextOutput_And_GetInput(int, 2);
244 DEF_SetNextOutput_And_GetInput(float, 2);
245 DEF_SetNextOutput_And_GetInput(double, 2);
247 DEF_SetNextOutput_And_GetInput(char, 3);
248 DEF_SetNextOutput_And_GetInput(unsigned char, 3);
249 DEF_SetNextOutput_And_GetInput(short, 3);
250 DEF_SetNextOutput_And_GetInput(unsigned short, 3);
251 DEF_SetNextOutput_And_GetInput(int, 3);
252 DEF_SetNextOutput_And_GetInput(float, 3);
253 DEF_SetNextOutput_And_GetInput(double, 3);
255 DEF_SetNextOutput_And_GetInput_WithCompo(2, 2);
256 DEF_SetNextOutput_And_GetInput_WithCompo(2, 3);
257 DEF_SetNextOutput_And_GetInput_WithCompo(2, 4);
258 DEF_SetNextOutput_And_GetInput_WithCompo(3, 2);
259 DEF_SetNextOutput_And_GetInput_WithCompo(3, 3);
260 DEF_SetNextOutput_And_GetInput_WithCompo(3, 4);
261 DEF_SetNextOutput_And_GetInput_WithCompo(4, 2);
262 DEF_SetNextOutput_And_GetInput_WithCompo(4, 3);
263 DEF_SetNextOutput_And_GetInput_WithCompo(4, 4);
265 DEF_SetNextOutput_And_GetInput(char, 4);
266 DEF_SetNextOutput_And_GetInput(unsigned char, 4);
267 DEF_SetNextOutput_And_GetInput(short, 4);
268 DEF_SetNextOutput_And_GetInput(unsigned short, 4);
269 DEF_SetNextOutput_And_GetInput(int, 4);
270 DEF_SetNextOutput_And_GetInput(float, 4);
271 DEF_SetNextOutput_And_GetInput(double, 4);
274 //--------------------------------------------------------------------
275 template<class ImageType>
276 void clitk::ImageToImageGenericFilterBase::SetNextOutput(typename ImageType::Pointer output)
278 if (m_OutputFilenames.size()) {
279 clitk::writeImage<ImageType>(output, m_OutputFilenames.front(), m_IOVerbose);
280 m_OutputFilenames.pop_front();
282 if (m_InputVVImages.size()) //We assume that if a vv image is set as input, we want one as the output
283 m_OutputVVImages.push_back(vvImageFromITK<ImageType::ImageDimension,typename ImageType::PixelType>(output));
285 //--------------------------------------------------------------------
288 //--------------------------------------------------------------------
289 template<class ImageType>
290 typename ImageType::Pointer clitk::ImageToImageGenericFilterBase::GetInput(unsigned int n)
292 if (m_ReadOnDisk && m_InputFilenames.size() > n) {
293 return clitk::readImage<ImageType>(m_InputFilenames[n], m_IOVerbose);
295 if (m_InputVVImages.size() > n)
296 return typename ImageType::Pointer(const_cast<ImageType*>(vvImageToITK<ImageType>(m_InputVVImages[n]).GetPointer()));
298 assert(false); //No input, this shouldn't happen
299 return typename ImageType::Pointer(NULL);
303 //--------------------------------------------------------------------