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 mFailOnImageTypeError = true;
34 //--------------------------------------------------------------------
37 //--------------------------------------------------------------------
38 void clitk::ImageToImageGenericFilterBase::SetInputFilenames(const std::vector<std::string> & filenames)
40 mInputFilenames=filenames;
42 //--------------------------------------------------------------------
45 //--------------------------------------------------------------------
46 void clitk::ImageToImageGenericFilterBase::EnableReadOnDisk(bool b)
50 //--------------------------------------------------------------------
53 //--------------------------------------------------------------------
54 void clitk::ImageToImageGenericFilterBase::SetInputFilename(const std::string & filename)
56 std::vector<std::string> f;
57 f.push_back(filename);
60 //--------------------------------------------------------------------
63 //--------------------------------------------------------------------
64 void clitk::ImageToImageGenericFilterBase::AddInputFilename(const std::string & filename)
66 mInputFilenames.push_back(filename);
68 //--------------------------------------------------------------------
71 //--------------------------------------------------------------------
72 void clitk::ImageToImageGenericFilterBase::SetOutputFilename(const std::string & filename)
74 mOutputFilenames.clear();
75 mOutputFilenames.push_back(filename);
77 //--------------------------------------------------------------------
80 //--------------------------------------------------------------------
81 void clitk::ImageToImageGenericFilterBase::AddOutputFilename(const std::string & filename)
83 mOutputFilenames.push_back(filename);
85 //--------------------------------------------------------------------
88 //--------------------------------------------------------------------
89 void clitk::ImageToImageGenericFilterBase::SetOutputFilenames(const std::vector<std::string> & filenames)
91 mOutputFilenames.clear();
92 std::copy(filenames.begin(),filenames.end(),mOutputFilenames.begin());
94 //--------------------------------------------------------------------
97 //--------------------------------------------------------------------
98 std::string clitk::ImageToImageGenericFilterBase::GetOutputFilename()
100 assert(mOutputFilenames.size() == 1);
101 return mOutputFilenames.front();
103 //--------------------------------------------------------------------
106 //--------------------------------------------------------------------
107 void clitk::ImageToImageGenericFilterBase::GetInputImageDimensionAndPixelType(unsigned int& dim, \
108 std::string& pixeltype,unsigned int& components)
110 if (mReadOnDisk && mInputFilenames.size()) {
111 int comp_temp,dim_temp; //clitkCommonImage takes ints
112 ReadImageDimensionAndPixelType(mInputFilenames[0], dim_temp, pixeltype,comp_temp);
113 components=comp_temp;
116 if (mInputVVImages.size()) {
117 pixeltype=mInputVVImages[0]->GetScalarTypeAsString();
118 dim=mInputVVImages[0]->GetNumberOfDimensions();
119 components=mInputVVImages[0]->GetNumberOfScalarComponents();
121 assert(false); //No input image, shouldn't happen
124 std::cout << "Input is " << mDim << "D " << mPixelTypeName << "." << std::endl;
127 //--------------------------------------------------------------------
130 //--------------------------------------------------------------------
131 vvImage::Pointer clitk::ImageToImageGenericFilterBase::GetOutputVVImage ()
133 assert(mOutputVVImages.size());
134 return mOutputVVImages[0];
136 //--------------------------------------------------------------------
139 //--------------------------------------------------------------------
140 std::vector<vvImage::Pointer> clitk::ImageToImageGenericFilterBase::GetOutputVVImages()
142 return mOutputVVImages;
144 //--------------------------------------------------------------------
147 //--------------------------------------------------------------------
148 void clitk::ImageToImageGenericFilterBase::SetInputVVImage (vvImage::Pointer input)
150 mInputVVImages.clear();
151 mInputVVImages.push_back(input);
153 //--------------------------------------------------------------------
156 //--------------------------------------------------------------------
157 void clitk::ImageToImageGenericFilterBase::AddInputVVImage (vvImage::Pointer input)
159 mInputVVImages.push_back(input);
161 //--------------------------------------------------------------------
164 //--------------------------------------------------------------------
165 void clitk::ImageToImageGenericFilterBase::SetInputVVImages (std::vector<vvImage::Pointer> input)
167 mInputVVImages=input;
169 //--------------------------------------------------------------------
172 //--------------------------------------------------------------------
173 void clitk::ImageToImageGenericFilterBase::PrintAvailableImageTypes()
175 std::cout << GetAvailableImageTypes();
177 //--------------------------------------------------------------------
181 //--------------------------------------------------------------------
182 void clitk::ImageToImageGenericFilterBase::ImageTypeError()
184 std::cerr << "**Error** The filter <" << mFilterName << "> is not available for "
185 << mDim << "D images with pixel="
186 << mPixelTypeName << " and "
187 << mNbOfComponents << " component." << std::endl;
188 std::cerr << GetAvailableImageTypes();
191 //--------------------------------------------------------------------
194 //--------------------------------------------------------------------
195 void clitk::ImageToImageGenericFilterBase::SetImageTypeError()
197 std::cerr << "TODO ! " << std::endl;
200 //--------------------------------------------------------------------
203 //--------------------------------------------------------------------
204 const std::string & clitk::ImageToImageGenericFilterBase::GetFilterName()
208 //--------------------------------------------------------------------
211 //--------------------------------------------------------------------
212 void clitk::ImageToImageGenericFilterBase::SetFilterName(std::string & n)
216 //--------------------------------------------------------------------
219 //--------------------------------------------------------------------
220 void clitk::ImageToImageGenericFilterBase::SetIOVerbose(bool b)
224 //--------------------------------------------------------------------
226 #define DEF_SetNextOutput_And_GetInput(PixelType, Dim) \
228 void clitk::ImageToImageGenericFilterBase::SetNextOutput<itk::Image<PixelType, Dim> >(itk::Image<PixelType,Dim>::Pointer output); \
230 itk::Image<PixelType, Dim>::Pointer clitk::ImageToImageGenericFilterBase::GetInput<itk::Image<PixelType, Dim> >(unsigned int n);
232 #define DEF_SetNextOutput_And_GetInput_WithCompo(Compo, Dim) \
234 void clitk::ImageToImageGenericFilterBase::SetNextOutput<itk::Image<itk::Vector<float, Compo>, Dim> >(itk::Image<itk::Vector<float, Compo>,Dim>::Pointer output); \
236 itk::Image<itk::Vector<float,Compo>, Dim>::Pointer clitk::ImageToImageGenericFilterBase::GetInput<itk::Image<itk::Vector<float, Compo>, Dim> >(unsigned int n);
238 DEF_SetNextOutput_And_GetInput(char, 2);
239 DEF_SetNextOutput_And_GetInput(unsigned char, 2);
240 DEF_SetNextOutput_And_GetInput(short, 2);
241 DEF_SetNextOutput_And_GetInput(unsigned short, 2);
242 DEF_SetNextOutput_And_GetInput(int, 2);
243 DEF_SetNextOutput_And_GetInput(float, 2);
244 DEF_SetNextOutput_And_GetInput(double, 2);
246 DEF_SetNextOutput_And_GetInput(char, 3);
247 DEF_SetNextOutput_And_GetInput(unsigned char, 3);
248 DEF_SetNextOutput_And_GetInput(short, 3);
249 DEF_SetNextOutput_And_GetInput(unsigned short, 3);
250 DEF_SetNextOutput_And_GetInput(int, 3);
251 DEF_SetNextOutput_And_GetInput(float, 3);
252 DEF_SetNextOutput_And_GetInput(double, 3);
254 DEF_SetNextOutput_And_GetInput_WithCompo(2, 2);
255 DEF_SetNextOutput_And_GetInput_WithCompo(2, 3);
256 DEF_SetNextOutput_And_GetInput_WithCompo(2, 4);
257 DEF_SetNextOutput_And_GetInput_WithCompo(3, 2);
258 DEF_SetNextOutput_And_GetInput_WithCompo(3, 3);
259 DEF_SetNextOutput_And_GetInput_WithCompo(3, 4);
260 DEF_SetNextOutput_And_GetInput_WithCompo(4, 2);
261 DEF_SetNextOutput_And_GetInput_WithCompo(4, 3);
262 DEF_SetNextOutput_And_GetInput_WithCompo(4, 4);
264 DEF_SetNextOutput_And_GetInput(char, 4);
265 DEF_SetNextOutput_And_GetInput(unsigned char, 4);
266 DEF_SetNextOutput_And_GetInput(short, 4);
267 DEF_SetNextOutput_And_GetInput(unsigned short, 4);
268 DEF_SetNextOutput_And_GetInput(int, 4);
269 DEF_SetNextOutput_And_GetInput(float, 4);
270 DEF_SetNextOutput_And_GetInput(double, 4);
273 //--------------------------------------------------------------------
274 template<class ImageType>
275 void clitk::ImageToImageGenericFilterBase::SetNextOutput(typename ImageType::Pointer output)
277 if (mOutputFilenames.size()) {
278 clitk::writeImage<ImageType>(output, mOutputFilenames.front(), mIOVerbose);
279 mOutputFilenames.pop_front();
281 if (mInputVVImages.size()) //We assume that if a vv image is set as input, we want one as the output
282 mOutputVVImages.push_back(vvImageFromITK<ImageType::ImageDimension,typename ImageType::PixelType>(output));
284 //--------------------------------------------------------------------
287 //--------------------------------------------------------------------
288 template<class ImageType>
289 typename ImageType::Pointer clitk::ImageToImageGenericFilterBase::GetInput(unsigned int n)
291 if (mReadOnDisk && mInputFilenames.size() > n) {
292 return clitk::readImage<ImageType>(mInputFilenames[n], mIOVerbose);
294 if (mInputVVImages.size() > n)
295 return typename ImageType::Pointer(const_cast<ImageType*>(vvImageToITK<ImageType>(mInputVVImages[n]).GetPointer()));
297 assert(false); //No input, this shouldn't happen
298 return typename ImageType::Pointer(NULL);
302 //--------------------------------------------------------------------