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 CLITKIMAGECONVERTGENERICFILTER_TXX
19 #define CLITKIMAGECONVERTGENERICFILTER_TXX
21 =================================================
22 * @file clitkImageConvertGenericFilter.txx
23 * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
24 * @date 05 May 2008 11:14:20
29 =================================================*/
33 //====================================================================
34 template<unsigned int Dim>
35 void ImageConvertGenericFilter::Update_WithDim()
37 #define TRY_TYPE(TYPE) \
38 if (IsSameType<TYPE>(mPixelTypeName)) { Update_WithDimAndPixelType<Dim, TYPE>(); return; }
39 // TRY_TYPE(signed char);
45 TRY_TYPE(unsigned int);
50 std::string list = CreateListOfTypes<uchar, short, ushort, int, uint, float, double>();
51 std::cerr << "Error, I don't know the type '" << mPixelTypeName << "' for the input image '"
52 << mInputFilenames[0] << "'." << std::endl << "Known types are " << list << std::endl;
55 //====================================================================
57 //====================================================================
58 template<unsigned int Dim, class PixelType>
59 void ImageConvertGenericFilter::Update_WithDimAndPixelType()
61 if ((mPixelTypeName == mOutputPixelTypeName) || (mOutputPixelTypeName == "NotSpecified")) {
62 typedef itk::Image<PixelType,Dim> InputImageType;
63 typename InputImageType::Pointer input = clitk::readImage<InputImageType>(mInputFilenames);
64 //clitk::writeImage<InputImageType>(input, mOutputFilename, mIOVerbose);
65 this->SetNextOutput<InputImageType>(input);
67 #define TRY_TYPE(TYPE) \
68 if (IsSameType<TYPE>(mOutputPixelTypeName)) { Update_WithDimAndPixelTypeAndOutputType<Dim, PixelType, TYPE>(); return; }
70 // TRY_TYPE(signed char);
74 TRY_TYPE(int); // no uint ...
79 std::string list = CreateListOfTypes<char, uchar, short, ushort, int, float, double>();
80 std::cerr << "Error, I don't know the output type '" << mOutputPixelTypeName
81 << "'. " << std::endl << "Known types are " << list << "." << std::endl;
85 //====================================================================
87 //====================================================================
88 template<unsigned int Dim, class PixelType, class OutputPixelType>
89 void ImageConvertGenericFilter::Update_WithDimAndPixelTypeAndOutputType()
92 typedef itk::Image<PixelType,Dim> InputImageType;
93 typename InputImageType::Pointer input = clitk::readImage<InputImageType>(mInputFilenames);
96 if (std::numeric_limits<PixelType>::is_signed) {
97 if (!std::numeric_limits<OutputPixelType>::is_signed) {
98 std::cerr << "Warning, input type is signed (" << mPixelTypeName << ") while output type is not ("
99 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
102 if (!std::numeric_limits<PixelType>::is_integer) {
103 if (std::numeric_limits<OutputPixelType>::is_integer) {
104 std::cerr << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is ("
105 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
108 // DD(std::numeric_limits<PixelType>::digits10);
109 // DD(std::numeric_limits<OutputPixelType>::digits10);
110 if (!std::numeric_limits<PixelType>::is_integer) {
111 if (std::numeric_limits<OutputPixelType>::is_integer) {
112 std::cerr << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is ("
113 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
116 if (std::numeric_limits<PixelType>::digits10 > std::numeric_limits<OutputPixelType>::digits10) {
117 std::cerr << "Warning, possible loss of precision : input type is (" << mPixelTypeName << ") while output type is ("
118 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
122 typedef itk::Image<OutputPixelType,Dim> OutputImageType;
123 typedef itk::CastImageFilter<InputImageType, OutputImageType> FilterType;
124 typename FilterType::Pointer filter = FilterType::New();
125 filter->SetInput(input);
129 SetNextOutput<OutputImageType>(filter->GetOutput());
130 //clitk::writeImage<OutputImageType>(filter->GetOutput(), mOutputFilename, mIOVerbose);
132 //====================================================================
134 #endif /* end #define CLITKIMAGECONVERTGENERICFILTER_TXX */