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() {
36 #define TRY_TYPE(TYPE) \
37 if (IsSameType<TYPE>(mPixelTypeName)) { Update_WithDimAndPixelType<Dim, TYPE>(); return; }
38 // TRY_TYPE(signed char);
44 TRY_TYPE(unsigned int);
49 std::string list = CreateListOfTypes<uchar, short, ushort, int, uint, float, double>();
50 std::cerr << "Error, I don't know the type '" << mPixelTypeName << "' for the input image '"
51 << mInputFilenames[0] << "'." << std::endl << "Known types are " << list << std::endl;
54 //====================================================================
56 //====================================================================
57 template<unsigned int Dim, class PixelType>
58 void ImageConvertGenericFilter::Update_WithDimAndPixelType() {
59 if ((mPixelTypeName == mOutputPixelTypeName) || (mOutputPixelTypeName == "NotSpecified")) {
60 typedef itk::Image<PixelType,Dim> InputImageType;
61 typename InputImageType::Pointer input = clitk::readImage<InputImageType>(mInputFilenames);
62 //clitk::writeImage<InputImageType>(input, mOutputFilename, mIOVerbose);
63 this->SetNextOutput<InputImageType>(input);
66 #define TRY_TYPE(TYPE) \
67 if (IsSameType<TYPE>(mOutputPixelTypeName)) { Update_WithDimAndPixelTypeAndOutputType<Dim, PixelType, TYPE>(); return; }
69 // TRY_TYPE(signed char);
73 TRY_TYPE(int); // no uint ...
78 std::string list = CreateListOfTypes<char, uchar, short, ushort, int, float, double>();
79 std::cerr << "Error, I don't know the output type '" << mOutputPixelTypeName
80 << "'. " << std::endl << "Known types are " << list << "." << std::endl;
84 //====================================================================
86 //====================================================================
87 template<unsigned int Dim, class PixelType, class OutputPixelType>
88 void ImageConvertGenericFilter::Update_WithDimAndPixelTypeAndOutputType() {
90 typedef itk::Image<PixelType,Dim> InputImageType;
91 typename InputImageType::Pointer input = clitk::readImage<InputImageType>(mInputFilenames);
94 if (std::numeric_limits<PixelType>::is_signed) {
95 if (!std::numeric_limits<OutputPixelType>::is_signed) {
96 std::cerr << "Warning, input type is signed (" << mPixelTypeName << ") while output type is not ("
97 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
100 if (!std::numeric_limits<PixelType>::is_integer) {
101 if (std::numeric_limits<OutputPixelType>::is_integer) {
102 std::cerr << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is ("
103 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
106 // DD(std::numeric_limits<PixelType>::digits10);
107 // DD(std::numeric_limits<OutputPixelType>::digits10);
108 if (!std::numeric_limits<PixelType>::is_integer) {
109 if (std::numeric_limits<OutputPixelType>::is_integer) {
110 std::cerr << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is ("
111 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
114 if (std::numeric_limits<PixelType>::digits10 > std::numeric_limits<OutputPixelType>::digits10) {
115 std::cerr << "Warning, possible loss of precision : input type is (" << mPixelTypeName << ") while output type is ("
116 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
120 typedef itk::Image<OutputPixelType,Dim> OutputImageType;
121 typedef itk::CastImageFilter<InputImageType, OutputImageType> FilterType;
122 typename FilterType::Pointer filter = FilterType::New();
123 filter->SetInput(input);
127 SetNextOutput<OutputImageType>(filter->GetOutput());
128 //clitk::writeImage<OutputImageType>(filter->GetOutput(), mOutputFilename, mIOVerbose);
130 //====================================================================
132 #endif /* end #define CLITKIMAGECONVERTGENERICFILTER_TXX */