]> Creatis software - clitk.git/blob - tools/clitkImageConvertGenericFilter.cxx
support for multiple vector image conversions
[clitk.git] / tools / clitkImageConvertGenericFilter.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
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.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ===========================================================================**/
18 #ifndef CLITKIMAGECONVERTGENERICFILTER_CXX
19 #define CLITKIMAGECONVERTGENERICFILTER_CXX
20
21 #include "clitkImageConvertGenericFilter.h"
22 // itk include
23 #include "itkCastImageFilter.h"
24 #include "itkVectorCastImageFilter.h"
25
26 //--------------------------------------------------------------------
27 clitk::ImageConvertGenericFilter::ImageConvertGenericFilter():
28   clitk::ImageToImageGenericFilter<Self>("ImageConvert")
29 {
30   mOutputPixelTypeName = "NotSpecified";
31   mWarningOccur = false;
32   mWarning = "";
33   mDisplayWarning = true;
34   InitializeImageType<2>();
35   InitializeImageType<3>();
36   InitializeImageType<4>();
37 }
38 //--------------------------------------------------------------------
39
40
41 //--------------------------------------------------------------------
42 template<unsigned int Dim>
43 void clitk::ImageConvertGenericFilter::InitializeImageType()
44 {
45   ADD_DEFAULT_IMAGE_TYPES(Dim);
46   ADD_VEC_IMAGE_TYPE(Dim, 2, char)
47   ADD_VEC_IMAGE_TYPE(Dim, 3, char)
48   ADD_VEC_IMAGE_TYPE(Dim, 2, unsigned char)
49   ADD_VEC_IMAGE_TYPE(Dim, 3, unsigned char)
50   ADD_VEC_IMAGE_TYPE(Dim, 2, short)
51   ADD_VEC_IMAGE_TYPE(Dim, 3, short)
52   ADD_VEC_IMAGE_TYPE(Dim, 2, unsigned short)
53   ADD_VEC_IMAGE_TYPE(Dim, 3, unsigned short)
54   ADD_VEC_IMAGE_TYPE(Dim, 2, int)
55   ADD_VEC_IMAGE_TYPE(Dim, 3, int)
56   ADD_VEC_IMAGE_TYPE(Dim, 2, float)
57   ADD_VEC_IMAGE_TYPE(Dim, 3, float)
58   ADD_VEC_IMAGE_TYPE(Dim, 2, double)
59   ADD_VEC_IMAGE_TYPE(Dim, 3, double)
60 }
61 //--------------------------------------------------------------------
62
63
64 //--------------------------------------------------------------------
65 template<class InputImageType>
66 void clitk::ImageConvertGenericFilter::UpdateWithInputImageType()
67 {
68
69   // Verbose stuff
70   if (m_IOVerbose) {
71     if (m_InputFilenames.size() == 1) {
72       std::cout << "Input image <" << m_InputFilenames[0] << "> is ";
73       itk::ImageIOBase::Pointer header = clitk::readImageHeader(m_InputFilenames[0]);
74       printImageHeader(header, std::cout);
75       std::cout << std::endl;
76     } else {
77       for(unsigned int i=0; i<m_InputFilenames.size(); i++) {
78         std::cout << "Input image " << i << " <" << m_InputFilenames[i] << "> is ";
79         itk::ImageIOBase::Pointer h = clitk::readImageHeader(m_InputFilenames[i]);
80         printImageHeader(h, std::cout);
81         std::cout << std::endl;
82       }
83     }
84   }
85
86
87   if ((m_PixelTypeName == mOutputPixelTypeName) || (mOutputPixelTypeName == "NotSpecified")) {
88     //    typename InputImageType::Pointer input = clitk::readImage<InputImageType>(m_InputFilenames);
89     typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
90     //clitk::writeImage<InputImageType>(input, mOutputFilename, m_IOVerbose);
91     this->SetNextOutput<InputImageType>(input);
92   } else {
93 #define TRY_TYPE(TYPE)                                                  \
94     if (IsSameType<TYPE>(mOutputPixelTypeName)) { UpdateWithOutputType<InputImageType, TYPE>(); return; }
95     TRY_TYPE(char);
96     //    TRY_TYPE(signed char);
97     TRY_TYPE(uchar);
98     TRY_TYPE(short);
99     TRY_TYPE(ushort);
100     TRY_TYPE(int); // no uint ...
101     TRY_TYPE(float);
102     TRY_TYPE(double);
103 #undef TRY_TYPE
104     
105     IsSameType<char>("char");
106
107     std::string list = CreateListOfTypes<char, uchar, short, ushort, int, float, double>();
108     std::cerr << "Error, I don't know the output type '" << mOutputPixelTypeName << " (input = " << m_PixelTypeName << ")" 
109               << "'. " << std::endl << "Known types are " << list << "." << std::endl;
110     exit(0);
111   }
112 }
113 //====================================================================
114
115 //====================================================================
116 template<class InputImageType, class OutputPixelType>
117 void clitk::ImageConvertGenericFilter::UpdateWithOutputType()
118 {
119   // Read
120   typename InputImageType::Pointer input =this->template GetInput<InputImageType>(0);
121
122   // Typedef
123   typedef typename InputImageType::PixelType PixelType;
124
125   // Warning
126   std::ostringstream osstream;
127   if (std::numeric_limits<PixelType>::is_signed) {
128     if (!std::numeric_limits<OutputPixelType>::is_signed) {
129       osstream << "Warning, input type is signed (" << m_PixelTypeName << ") while output type is not ("
130                << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
131       mWarningOccur = true;
132     }
133   }
134   if (!std::numeric_limits<PixelType>::is_integer) {
135     if (std::numeric_limits<OutputPixelType>::is_integer) {
136       osstream << "Warning, input type is not integer (" << m_PixelTypeName << ") while output type is ("
137                << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
138       mWarningOccur = true;
139     }
140   }
141   //  DD(std::numeric_limits<PixelType>::digits10);
142   // DD(std::numeric_limits<OutputPixelType>::digits10);
143   if (!std::numeric_limits<PixelType>::is_integer) {
144     if (std::numeric_limits<OutputPixelType>::is_integer) {
145       osstream << "Warning, input type is not integer (" << m_PixelTypeName << ") while output type is ("
146                << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
147       mWarningOccur = true;
148     }
149   }
150   if (std::numeric_limits<PixelType>::digits10 > std::numeric_limits<OutputPixelType>::digits10) {
151     osstream << "Warning, possible loss of precision : input type is (" << m_PixelTypeName << ") while output type is ("
152              << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
153     mWarningOccur = true;
154   }
155
156   mWarning = osstream.str();
157   if (mDisplayWarning) {
158     std::cerr << mWarning;
159   }
160
161   // Cast
162   typedef itk::Image<OutputPixelType,InputImageType::ImageDimension> OutputImageType;
163   typedef itk::CastImageFilter<InputImageType, OutputImageType> FilterType;
164   typename FilterType::Pointer filter = FilterType::New();
165   filter->SetInput(input);
166   filter->Update();
167
168   // Write
169   SetNextOutput<OutputImageType>(filter->GetOutput());
170   //clitk::writeImage<OutputImageType>(filter->GetOutput(), mOutputFilename, m_IOVerbose);
171 }
172 //====================================================================
173
174 // Vector specializations (RP: do we need so many?)
175
176 #define VEC_UPDATE_IMPL(TYPE_IN, COMP, DIM, TYPE_OUT) \
177   template<> \
178   void clitk::ImageConvertGenericFilter::UpdateWithOutputType<itk::Image<itk::Vector<TYPE_IN, COMP>, DIM>, TYPE_OUT>() \
179   { \
180     UpdateWithOutputVectorType<itk::Image<itk::Vector<TYPE_IN, COMP>, DIM>, TYPE_OUT>(); \
181   } 
182
183 VEC_UPDATE_IMPL(char, 2, 2, unsigned char);
184 VEC_UPDATE_IMPL(char, 2, 3, unsigned char);
185 VEC_UPDATE_IMPL(char, 2, 4, unsigned char);
186 VEC_UPDATE_IMPL(char, 2, 2, char);
187 VEC_UPDATE_IMPL(char, 2, 3, char);
188 VEC_UPDATE_IMPL(char, 2, 4, char);
189 VEC_UPDATE_IMPL(char, 2, 2, unsigned short);
190 VEC_UPDATE_IMPL(char, 2, 3, unsigned short);
191 VEC_UPDATE_IMPL(char, 2, 4, unsigned short);
192 VEC_UPDATE_IMPL(char, 2, 2, short);
193 VEC_UPDATE_IMPL(char, 2, 3, short);
194 VEC_UPDATE_IMPL(char, 2, 4, short);
195 VEC_UPDATE_IMPL(char, 2, 2, int);
196 VEC_UPDATE_IMPL(char, 2, 3, int);
197 VEC_UPDATE_IMPL(char, 2, 4, int);
198 VEC_UPDATE_IMPL(char, 2, 2, float);
199 VEC_UPDATE_IMPL(char, 2, 3, float);
200 VEC_UPDATE_IMPL(char, 2, 4, float);
201 VEC_UPDATE_IMPL(char, 2, 2, double);
202 VEC_UPDATE_IMPL(char, 2, 3, double);
203 VEC_UPDATE_IMPL(char, 2, 4, double);
204
205 VEC_UPDATE_IMPL(char, 3, 2, unsigned char);
206 VEC_UPDATE_IMPL(char, 3, 3, unsigned char);
207 VEC_UPDATE_IMPL(char, 3, 4, unsigned char);
208 VEC_UPDATE_IMPL(char, 3, 2, char);
209 VEC_UPDATE_IMPL(char, 3, 3, char);
210 VEC_UPDATE_IMPL(char, 3, 4, char);
211 VEC_UPDATE_IMPL(char, 3, 2, unsigned short);
212 VEC_UPDATE_IMPL(char, 3, 3, unsigned short);
213 VEC_UPDATE_IMPL(char, 3, 4, unsigned short);
214 VEC_UPDATE_IMPL(char, 3, 2, short);
215 VEC_UPDATE_IMPL(char, 3, 3, short);
216 VEC_UPDATE_IMPL(char, 3, 4, short);
217 VEC_UPDATE_IMPL(char, 3, 2, int);
218 VEC_UPDATE_IMPL(char, 3, 3, int);
219 VEC_UPDATE_IMPL(char, 3, 4, int);
220 VEC_UPDATE_IMPL(char, 3, 2, float);
221 VEC_UPDATE_IMPL(char, 3, 3, float);
222 VEC_UPDATE_IMPL(char, 3, 4, float);
223 VEC_UPDATE_IMPL(char, 3, 2, double);
224 VEC_UPDATE_IMPL(char, 3, 3, double);
225 VEC_UPDATE_IMPL(char, 3, 4, double);
226
227 VEC_UPDATE_IMPL(unsigned char, 2, 2, unsigned char);
228 VEC_UPDATE_IMPL(unsigned char, 2, 3, unsigned char);
229 VEC_UPDATE_IMPL(unsigned char, 2, 4, unsigned char);
230 VEC_UPDATE_IMPL(unsigned char, 2, 2, char);
231 VEC_UPDATE_IMPL(unsigned char, 2, 3, char);
232 VEC_UPDATE_IMPL(unsigned char, 2, 4, char);
233 VEC_UPDATE_IMPL(unsigned char, 2, 2, unsigned short);
234 VEC_UPDATE_IMPL(unsigned char, 2, 3, unsigned short);
235 VEC_UPDATE_IMPL(unsigned char, 2, 4, unsigned short);
236 VEC_UPDATE_IMPL(unsigned char, 2, 2, short);
237 VEC_UPDATE_IMPL(unsigned char, 2, 3, short);
238 VEC_UPDATE_IMPL(unsigned char, 2, 4, short);
239 VEC_UPDATE_IMPL(unsigned char, 2, 2, int);
240 VEC_UPDATE_IMPL(unsigned char, 2, 3, int);
241 VEC_UPDATE_IMPL(unsigned char, 2, 4, int);
242 VEC_UPDATE_IMPL(unsigned char, 2, 2, float);
243 VEC_UPDATE_IMPL(unsigned char, 2, 3, float);
244 VEC_UPDATE_IMPL(unsigned char, 2, 4, float);
245 VEC_UPDATE_IMPL(unsigned char, 2, 2, double);
246 VEC_UPDATE_IMPL(unsigned char, 2, 3, double);
247 VEC_UPDATE_IMPL(unsigned char, 2, 4, double);
248
249 VEC_UPDATE_IMPL(unsigned char, 3, 2, unsigned char);
250 VEC_UPDATE_IMPL(unsigned char, 3, 3, unsigned char);
251 VEC_UPDATE_IMPL(unsigned char, 3, 4, unsigned char);
252 VEC_UPDATE_IMPL(unsigned char, 3, 2, char);
253 VEC_UPDATE_IMPL(unsigned char, 3, 3, char);
254 VEC_UPDATE_IMPL(unsigned char, 3, 4, char);
255 VEC_UPDATE_IMPL(unsigned char, 3, 2, unsigned short);
256 VEC_UPDATE_IMPL(unsigned char, 3, 3, unsigned short);
257 VEC_UPDATE_IMPL(unsigned char, 3, 4, unsigned short);
258 VEC_UPDATE_IMPL(unsigned char, 3, 2, short);
259 VEC_UPDATE_IMPL(unsigned char, 3, 3, short);
260 VEC_UPDATE_IMPL(unsigned char, 3, 4, short);
261 VEC_UPDATE_IMPL(unsigned char, 3, 2, int);
262 VEC_UPDATE_IMPL(unsigned char, 3, 3, int);
263 VEC_UPDATE_IMPL(unsigned char, 3, 4, int);
264 VEC_UPDATE_IMPL(unsigned char, 3, 2, float);
265 VEC_UPDATE_IMPL(unsigned char, 3, 3, float);
266 VEC_UPDATE_IMPL(unsigned char, 3, 4, float);
267 VEC_UPDATE_IMPL(unsigned char, 3, 2, double);
268 VEC_UPDATE_IMPL(unsigned char, 3, 3, double);
269 VEC_UPDATE_IMPL(unsigned char, 3, 4, double);
270
271 VEC_UPDATE_IMPL(short, 2, 2, unsigned char);
272 VEC_UPDATE_IMPL(short, 2, 3, unsigned char);
273 VEC_UPDATE_IMPL(short, 2, 4, unsigned char);
274 VEC_UPDATE_IMPL(short, 2, 2, char);
275 VEC_UPDATE_IMPL(short, 2, 3, char);
276 VEC_UPDATE_IMPL(short, 2, 4, char);
277 VEC_UPDATE_IMPL(short, 2, 2, unsigned short);
278 VEC_UPDATE_IMPL(short, 2, 3, unsigned short);
279 VEC_UPDATE_IMPL(short, 2, 4, unsigned short);
280 VEC_UPDATE_IMPL(short, 2, 2, short);
281 VEC_UPDATE_IMPL(short, 2, 3, short);
282 VEC_UPDATE_IMPL(short, 2, 4, short);
283 VEC_UPDATE_IMPL(short, 2, 2, int);
284 VEC_UPDATE_IMPL(short, 2, 3, int);
285 VEC_UPDATE_IMPL(short, 2, 4, int);
286 VEC_UPDATE_IMPL(short, 2, 2, float);
287 VEC_UPDATE_IMPL(short, 2, 3, float);
288 VEC_UPDATE_IMPL(short, 2, 4, float);
289 VEC_UPDATE_IMPL(short, 2, 2, double);
290 VEC_UPDATE_IMPL(short, 2, 3, double);
291 VEC_UPDATE_IMPL(short, 2, 4, double);
292
293 VEC_UPDATE_IMPL(short, 3, 2, unsigned char);
294 VEC_UPDATE_IMPL(short, 3, 3, unsigned char);
295 VEC_UPDATE_IMPL(short, 3, 4, unsigned char);
296 VEC_UPDATE_IMPL(short, 3, 2, char);
297 VEC_UPDATE_IMPL(short, 3, 3, char);
298 VEC_UPDATE_IMPL(short, 3, 4, char);
299 VEC_UPDATE_IMPL(short, 3, 2, unsigned short);
300 VEC_UPDATE_IMPL(short, 3, 3, unsigned short);
301 VEC_UPDATE_IMPL(short, 3, 4, unsigned short);
302 VEC_UPDATE_IMPL(short, 3, 2, short);
303 VEC_UPDATE_IMPL(short, 3, 3, short);
304 VEC_UPDATE_IMPL(short, 3, 4, short);
305 VEC_UPDATE_IMPL(short, 3, 2, int);
306 VEC_UPDATE_IMPL(short, 3, 3, int);
307 VEC_UPDATE_IMPL(short, 3, 4, int);
308 VEC_UPDATE_IMPL(short, 3, 2, float);
309 VEC_UPDATE_IMPL(short, 3, 3, float);
310 VEC_UPDATE_IMPL(short, 3, 4, float);
311 VEC_UPDATE_IMPL(short, 3, 2, double);
312 VEC_UPDATE_IMPL(short, 3, 3, double);
313 VEC_UPDATE_IMPL(short, 3, 4, double);
314
315 VEC_UPDATE_IMPL(unsigned short, 2, 2, unsigned char);
316 VEC_UPDATE_IMPL(unsigned short, 2, 3, unsigned char);
317 VEC_UPDATE_IMPL(unsigned short, 2, 4, unsigned char);
318 VEC_UPDATE_IMPL(unsigned short, 2, 2, char);
319 VEC_UPDATE_IMPL(unsigned short, 2, 3, char);
320 VEC_UPDATE_IMPL(unsigned short, 2, 4, char);
321 VEC_UPDATE_IMPL(unsigned short, 2, 2, unsigned short);
322 VEC_UPDATE_IMPL(unsigned short, 2, 3, unsigned short);
323 VEC_UPDATE_IMPL(unsigned short, 2, 4, unsigned short);
324 VEC_UPDATE_IMPL(unsigned short, 2, 2, short);
325 VEC_UPDATE_IMPL(unsigned short, 2, 3, short);
326 VEC_UPDATE_IMPL(unsigned short, 2, 4, short);
327 VEC_UPDATE_IMPL(unsigned short, 2, 2, int);
328 VEC_UPDATE_IMPL(unsigned short, 2, 3, int);
329 VEC_UPDATE_IMPL(unsigned short, 2, 4, int);
330 VEC_UPDATE_IMPL(unsigned short, 2, 2, float);
331 VEC_UPDATE_IMPL(unsigned short, 2, 3, float);
332 VEC_UPDATE_IMPL(unsigned short, 2, 4, float);
333 VEC_UPDATE_IMPL(unsigned short, 2, 2, double);
334 VEC_UPDATE_IMPL(unsigned short, 2, 3, double);
335 VEC_UPDATE_IMPL(unsigned short, 2, 4, double);
336
337 VEC_UPDATE_IMPL(unsigned short, 3, 2, unsigned char);
338 VEC_UPDATE_IMPL(unsigned short, 3, 3, unsigned char);
339 VEC_UPDATE_IMPL(unsigned short, 3, 4, unsigned char);
340 VEC_UPDATE_IMPL(unsigned short, 3, 2, char);
341 VEC_UPDATE_IMPL(unsigned short, 3, 3, char);
342 VEC_UPDATE_IMPL(unsigned short, 3, 4, char);
343 VEC_UPDATE_IMPL(unsigned short, 3, 2, unsigned short);
344 VEC_UPDATE_IMPL(unsigned short, 3, 3, unsigned short);
345 VEC_UPDATE_IMPL(unsigned short, 3, 4, unsigned short);
346 VEC_UPDATE_IMPL(unsigned short, 3, 2, short);
347 VEC_UPDATE_IMPL(unsigned short, 3, 3, short);
348 VEC_UPDATE_IMPL(unsigned short, 3, 4, short);
349 VEC_UPDATE_IMPL(unsigned short, 3, 2, int);
350 VEC_UPDATE_IMPL(unsigned short, 3, 3, int);
351 VEC_UPDATE_IMPL(unsigned short, 3, 4, int);
352 VEC_UPDATE_IMPL(unsigned short, 3, 2, float);
353 VEC_UPDATE_IMPL(unsigned short, 3, 3, float);
354 VEC_UPDATE_IMPL(unsigned short, 3, 4, float);
355 VEC_UPDATE_IMPL(unsigned short, 3, 2, double);
356 VEC_UPDATE_IMPL(unsigned short, 3, 3, double);
357 VEC_UPDATE_IMPL(unsigned short, 3, 4, double);
358
359 VEC_UPDATE_IMPL(int, 2, 2, unsigned char);
360 VEC_UPDATE_IMPL(int, 2, 3, unsigned char);
361 VEC_UPDATE_IMPL(int, 2, 4, unsigned char);
362 VEC_UPDATE_IMPL(int, 2, 2, char);
363 VEC_UPDATE_IMPL(int, 2, 3, char);
364 VEC_UPDATE_IMPL(int, 2, 4, char);
365 VEC_UPDATE_IMPL(int, 2, 2, unsigned short);
366 VEC_UPDATE_IMPL(int, 2, 3, unsigned short);
367 VEC_UPDATE_IMPL(int, 2, 4, unsigned short);
368 VEC_UPDATE_IMPL(int, 2, 2, short);
369 VEC_UPDATE_IMPL(int, 2, 3, short);
370 VEC_UPDATE_IMPL(int, 2, 4, short);
371 VEC_UPDATE_IMPL(int, 2, 2, int);
372 VEC_UPDATE_IMPL(int, 2, 3, int);
373 VEC_UPDATE_IMPL(int, 2, 4, int);
374 VEC_UPDATE_IMPL(int, 2, 2, float);
375 VEC_UPDATE_IMPL(int, 2, 3, float);
376 VEC_UPDATE_IMPL(int, 2, 4, float);
377 VEC_UPDATE_IMPL(int, 2, 2, double);
378 VEC_UPDATE_IMPL(int, 2, 3, double);
379 VEC_UPDATE_IMPL(int, 2, 4, double);
380
381 VEC_UPDATE_IMPL(int, 3, 2, unsigned char);
382 VEC_UPDATE_IMPL(int, 3, 3, unsigned char);
383 VEC_UPDATE_IMPL(int, 3, 4, unsigned char);
384 VEC_UPDATE_IMPL(int, 3, 2, char);
385 VEC_UPDATE_IMPL(int, 3, 3, char);
386 VEC_UPDATE_IMPL(int, 3, 4, char);
387 VEC_UPDATE_IMPL(int, 3, 2, unsigned short);
388 VEC_UPDATE_IMPL(int, 3, 3, unsigned short);
389 VEC_UPDATE_IMPL(int, 3, 4, unsigned short);
390 VEC_UPDATE_IMPL(int, 3, 2, short);
391 VEC_UPDATE_IMPL(int, 3, 3, short);
392 VEC_UPDATE_IMPL(int, 3, 4, short);
393 VEC_UPDATE_IMPL(int, 3, 2, int);
394 VEC_UPDATE_IMPL(int, 3, 3, int);
395 VEC_UPDATE_IMPL(int, 3, 4, int);
396 VEC_UPDATE_IMPL(int, 3, 2, float);
397 VEC_UPDATE_IMPL(int, 3, 3, float);
398 VEC_UPDATE_IMPL(int, 3, 4, float);
399 VEC_UPDATE_IMPL(int, 3, 2, double);
400 VEC_UPDATE_IMPL(int, 3, 3, double);
401 VEC_UPDATE_IMPL(int, 3, 4, double);
402
403 VEC_UPDATE_IMPL(float, 2, 2, unsigned char);
404 VEC_UPDATE_IMPL(float, 2, 3, unsigned char);
405 VEC_UPDATE_IMPL(float, 2, 4, unsigned char);
406 VEC_UPDATE_IMPL(float, 2, 2, char);
407 VEC_UPDATE_IMPL(float, 2, 3, char);
408 VEC_UPDATE_IMPL(float, 2, 4, char);
409 VEC_UPDATE_IMPL(float, 2, 2, unsigned short);
410 VEC_UPDATE_IMPL(float, 2, 3, unsigned short);
411 VEC_UPDATE_IMPL(float, 2, 4, unsigned short);
412 VEC_UPDATE_IMPL(float, 2, 2, short);
413 VEC_UPDATE_IMPL(float, 2, 3, short);
414 VEC_UPDATE_IMPL(float, 2, 4, short);
415 VEC_UPDATE_IMPL(float, 2, 2, int);
416 VEC_UPDATE_IMPL(float, 2, 3, int);
417 VEC_UPDATE_IMPL(float, 2, 4, int);
418 VEC_UPDATE_IMPL(float, 2, 2, float);
419 VEC_UPDATE_IMPL(float, 2, 3, float);
420 VEC_UPDATE_IMPL(float, 2, 4, float);
421 VEC_UPDATE_IMPL(float, 2, 2, double);
422 VEC_UPDATE_IMPL(float, 2, 3, double);
423 VEC_UPDATE_IMPL(float, 2, 4, double);
424
425 VEC_UPDATE_IMPL(float, 3, 2, unsigned char);
426 VEC_UPDATE_IMPL(float, 3, 3, unsigned char);
427 VEC_UPDATE_IMPL(float, 3, 4, unsigned char);
428 VEC_UPDATE_IMPL(float, 3, 2, char);
429 VEC_UPDATE_IMPL(float, 3, 3, char);
430 VEC_UPDATE_IMPL(float, 3, 4, char);
431 VEC_UPDATE_IMPL(float, 3, 2, unsigned short);
432 VEC_UPDATE_IMPL(float, 3, 3, unsigned short);
433 VEC_UPDATE_IMPL(float, 3, 4, unsigned short);
434 VEC_UPDATE_IMPL(float, 3, 2, short);
435 VEC_UPDATE_IMPL(float, 3, 3, short);
436 VEC_UPDATE_IMPL(float, 3, 4, short);
437 VEC_UPDATE_IMPL(float, 3, 2, int);
438 VEC_UPDATE_IMPL(float, 3, 3, int);
439 VEC_UPDATE_IMPL(float, 3, 4, int);
440 VEC_UPDATE_IMPL(float, 3, 2, float);
441 VEC_UPDATE_IMPL(float, 3, 3, float);
442 VEC_UPDATE_IMPL(float, 3, 4, float);
443 VEC_UPDATE_IMPL(float, 3, 2, double);
444 VEC_UPDATE_IMPL(float, 3, 3, double);
445 VEC_UPDATE_IMPL(float, 3, 4, double);
446
447
448 VEC_UPDATE_IMPL(double, 2, 2, unsigned char);
449 VEC_UPDATE_IMPL(double, 2, 3, unsigned char);
450 VEC_UPDATE_IMPL(double, 2, 4, unsigned char);
451 VEC_UPDATE_IMPL(double, 2, 2, char);
452 VEC_UPDATE_IMPL(double, 2, 3, char);
453 VEC_UPDATE_IMPL(double, 2, 4, char);
454 VEC_UPDATE_IMPL(double, 2, 2, unsigned short);
455 VEC_UPDATE_IMPL(double, 2, 3, unsigned short);
456 VEC_UPDATE_IMPL(double, 2, 4, unsigned short);
457 VEC_UPDATE_IMPL(double, 2, 2, short);
458 VEC_UPDATE_IMPL(double, 2, 3, short);
459 VEC_UPDATE_IMPL(double, 2, 4, short);
460 VEC_UPDATE_IMPL(double, 2, 2, int);
461 VEC_UPDATE_IMPL(double, 2, 3, int);
462 VEC_UPDATE_IMPL(double, 2, 4, int);
463 VEC_UPDATE_IMPL(double, 2, 2, float);
464 VEC_UPDATE_IMPL(double, 2, 3, float);
465 VEC_UPDATE_IMPL(double, 2, 4, float);
466 VEC_UPDATE_IMPL(double, 2, 2, double);
467 VEC_UPDATE_IMPL(double, 2, 3, double);
468 VEC_UPDATE_IMPL(double, 2, 4, double);
469
470 VEC_UPDATE_IMPL(double, 3, 2, unsigned char);
471 VEC_UPDATE_IMPL(double, 3, 3, unsigned char);
472 VEC_UPDATE_IMPL(double, 3, 4, unsigned char);
473 VEC_UPDATE_IMPL(double, 3, 2, char);
474 VEC_UPDATE_IMPL(double, 3, 3, char);
475 VEC_UPDATE_IMPL(double, 3, 4, char);
476 VEC_UPDATE_IMPL(double, 3, 2, unsigned short);
477 VEC_UPDATE_IMPL(double, 3, 3, unsigned short);
478 VEC_UPDATE_IMPL(double, 3, 4, unsigned short);
479 VEC_UPDATE_IMPL(double, 3, 2, short);
480 VEC_UPDATE_IMPL(double, 3, 3, short);
481 VEC_UPDATE_IMPL(double, 3, 4, short);
482 VEC_UPDATE_IMPL(double, 3, 2, int);
483 VEC_UPDATE_IMPL(double, 3, 3, int);
484 VEC_UPDATE_IMPL(double, 3, 4, int);
485 VEC_UPDATE_IMPL(double, 3, 2, float);
486 VEC_UPDATE_IMPL(double, 3, 3, float);
487 VEC_UPDATE_IMPL(double, 3, 4, float);
488 VEC_UPDATE_IMPL(double, 3, 2, double);
489 VEC_UPDATE_IMPL(double, 3, 3, double);
490 VEC_UPDATE_IMPL(double, 3, 4, double);
491 //====================================================================
492
493 //====================================================================
494 template<class InputImageType, class OutputPixelType>
495 void clitk::ImageConvertGenericFilter::UpdateWithOutputVectorType()
496 {
497   // Read
498   typename InputImageType::Pointer input =this->template GetInput<InputImageType>(0);
499
500   // Typedef
501   typedef typename InputImageType::PixelType::ValueType PixelType;
502
503   // Warning
504   std::ostringstream osstream;
505   if (std::numeric_limits<PixelType>::is_signed) {
506     if (!std::numeric_limits<OutputPixelType>::is_signed) {
507       osstream << "Warning, input type is signed (" << m_PixelTypeName << ") while output type is not ("
508                << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
509       mWarningOccur = true;
510     }
511   }
512   if (!std::numeric_limits<PixelType>::is_integer) {
513     if (std::numeric_limits<OutputPixelType>::is_integer) {
514       osstream << "Warning, input type is not integer (" << m_PixelTypeName << ") while output type is ("
515                << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
516       mWarningOccur = true;
517     }
518   }
519   //  DD(std::numeric_limits<PixelType>::digits10);
520   // DD(std::numeric_limits<OutputPixelType>::digits10);
521   if (!std::numeric_limits<PixelType>::is_integer) {
522     if (std::numeric_limits<OutputPixelType>::is_integer) {
523       osstream << "Warning, input type is not integer (" << m_PixelTypeName << ") while output type is ("
524                << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
525       mWarningOccur = true;
526     }
527   }
528   if (std::numeric_limits<PixelType>::digits10 > std::numeric_limits<OutputPixelType>::digits10) {
529     osstream << "Warning, possible loss of precision : input type is (" << m_PixelTypeName << ") while output type is ("
530              << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
531     mWarningOccur = true;
532   }
533
534   mWarning = osstream.str();
535   if (mDisplayWarning) {
536     std::cerr << mWarning;
537   }
538
539   // Cast
540   typedef itk::Image<itk::Vector<OutputPixelType, InputImageType::PixelType::Dimension>, InputImageType::ImageDimension> OutputImageType;
541   typedef itk::VectorCastImageFilter<InputImageType, OutputImageType> FilterType;
542   typename FilterType::Pointer filter = FilterType::New();
543   filter->SetInput(input);
544   filter->Update();
545
546   // Write
547   SetNextOutput<OutputImageType>(filter->GetOutput());
548   //clitk::writeImage<OutputImageType>(filter->GetOutput(), mOutputFilename, m_IOVerbose);
549 }
550 //====================================================================
551
552 #endif /* end #define CLITKIMAGECONVERTGENERICFILTER_CXX */
553