1 /*------------------------------------------------------------------------=
3 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
4 l'Image). All rights reserved. See Doc/License.txt or
5 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
7 This software is distributed WITHOUT ANY WARRANTY; without even
8 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9 PURPOSE. See the above copyright notices for more information.
11 ------------------------------------------------------------------------=*/
13 #ifndef CLITKIMAGECONVERTGENERICFILTER_TXX
14 #define CLITKIMAGECONVERTGENERICFILTER_TXX
17 =================================================
18 * @file clitkImageConvertGenericFilter.txx
19 * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
20 * @date 05 May 2008 11:14:20
25 =================================================*/
29 //====================================================================
30 template<unsigned int Dim>
31 void ImageConvertGenericFilter::Update_WithDim() {
32 #define TRY_TYPE(TYPE) \
33 if (IsSameType<TYPE>(mPixelTypeName)) { Update_WithDimAndPixelType<Dim, TYPE>(); return; }
34 // TRY_TYPE(signed char);
40 TRY_TYPE(unsigned int);
45 std::string list = CreateListOfTypes<uchar, short, ushort, int, uint, float, double>();
46 std::cerr << "Error, I don't know the type '" << mPixelTypeName << "' for the input image '"
47 << mInputFilenames[0] << "'." << std::endl << "Known types are " << list << std::endl;
50 //====================================================================
52 //====================================================================
53 template<unsigned int Dim, class PixelType>
54 void ImageConvertGenericFilter::Update_WithDimAndPixelType() {
55 if ((mPixelTypeName == mOutputPixelTypeName) || (mOutputPixelTypeName == "NotSpecified")) {
56 typedef itk::Image<PixelType,Dim> InputImageType;
57 typename InputImageType::Pointer input = clitk::readImage<InputImageType>(mInputFilenames);
58 //clitk::writeImage<InputImageType>(input, mOutputFilename, mIOVerbose);
59 this->SetNextOutput<InputImageType>(input);
62 #define TRY_TYPE(TYPE) \
63 if (IsSameType<TYPE>(mOutputPixelTypeName)) { Update_WithDimAndPixelTypeAndOutputType<Dim, PixelType, TYPE>(); return; }
65 // TRY_TYPE(signed char);
69 TRY_TYPE(int); // no uint ...
74 std::string list = CreateListOfTypes<char, uchar, short, ushort, int, float, double>();
75 std::cerr << "Error, I don't know the output type '" << mOutputPixelTypeName
76 << "'. " << std::endl << "Known types are " << list << "." << std::endl;
80 //====================================================================
82 //====================================================================
83 template<unsigned int Dim, class PixelType, class OutputPixelType>
84 void ImageConvertGenericFilter::Update_WithDimAndPixelTypeAndOutputType() {
86 typedef itk::Image<PixelType,Dim> InputImageType;
87 typename InputImageType::Pointer input = clitk::readImage<InputImageType>(mInputFilenames);
90 if (std::numeric_limits<PixelType>::is_signed) {
91 if (!std::numeric_limits<OutputPixelType>::is_signed) {
92 std::cerr << "Warning, input type is signed (" << mPixelTypeName << ") while output type is not ("
93 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
96 if (!std::numeric_limits<PixelType>::is_integer) {
97 if (std::numeric_limits<OutputPixelType>::is_integer) {
98 std::cerr << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is ("
99 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
102 // DD(std::numeric_limits<PixelType>::digits10);
103 // DD(std::numeric_limits<OutputPixelType>::digits10);
104 if (!std::numeric_limits<PixelType>::is_integer) {
105 if (std::numeric_limits<OutputPixelType>::is_integer) {
106 std::cerr << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is ("
107 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
110 if (std::numeric_limits<PixelType>::digits10 > std::numeric_limits<OutputPixelType>::digits10) {
111 std::cerr << "Warning, possible loss of precision : input type is (" << mPixelTypeName << ") while output type is ("
112 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
116 typedef itk::Image<OutputPixelType,Dim> OutputImageType;
117 typedef itk::CastImageFilter<InputImageType, OutputImageType> FilterType;
118 typename FilterType::Pointer filter = FilterType::New();
119 filter->SetInput(input);
123 SetNextOutput<OutputImageType>(filter->GetOutput());
124 //clitk::writeImage<OutputImageType>(filter->GetOutput(), mOutputFilename, mIOVerbose);
126 //====================================================================
128 #endif /* end #define CLITKIMAGECONVERTGENERICFILTER_TXX */