1 #ifndef CLITKIMAGECONVERTGENERICFILTER_TXX
2 #define CLITKIMAGECONVERTGENERICFILTER_TXX
4 =================================================
5 * @file clitkImageConvertGenericFilter.txx
6 * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
7 * @date 05 May 2008 11:14:20
12 =================================================*/
16 //====================================================================
17 template<unsigned int Dim>
18 void ImageConvertGenericFilter::Update_WithDim() {
19 #define TRY_TYPE(TYPE) \
20 if (IsSameType<TYPE>(mPixelTypeName)) { Update_WithDimAndPixelType<Dim, TYPE>(); return; }
21 // TRY_TYPE(signed char);
27 TRY_TYPE(unsigned int);
32 std::string list = CreateListOfTypes<uchar, short, ushort, int, uint, float, double>();
33 std::cerr << "Error, I don't know the type '" << mPixelTypeName << "' for the input image '"
34 << mInputFilenames[0] << "'." << std::endl << "Known types are " << list << std::endl;
37 //====================================================================
39 //====================================================================
40 template<unsigned int Dim, class PixelType>
41 void ImageConvertGenericFilter::Update_WithDimAndPixelType() {
42 if ((mPixelTypeName == mOutputPixelTypeName) || (mOutputPixelTypeName == "NotSpecified")) {
43 typedef itk::Image<PixelType,Dim> InputImageType;
44 typename InputImageType::Pointer input = clitk::readImage<InputImageType>(mInputFilenames);
45 //clitk::writeImage<InputImageType>(input, mOutputFilename, mIOVerbose);
46 this->SetNextOutput<InputImageType>(input);
49 #define TRY_TYPE(TYPE) \
50 if (IsSameType<TYPE>(mOutputPixelTypeName)) { Update_WithDimAndPixelTypeAndOutputType<Dim, PixelType, TYPE>(); return; }
52 // TRY_TYPE(signed char);
56 TRY_TYPE(int); // no uint ...
61 std::string list = CreateListOfTypes<char, uchar, short, ushort, int, float, double>();
62 std::cerr << "Error, I don't know the output type '" << mOutputPixelTypeName
63 << "'. " << std::endl << "Known types are " << list << "." << std::endl;
67 //====================================================================
69 //====================================================================
70 template<unsigned int Dim, class PixelType, class OutputPixelType>
71 void ImageConvertGenericFilter::Update_WithDimAndPixelTypeAndOutputType() {
73 typedef itk::Image<PixelType,Dim> InputImageType;
74 typename InputImageType::Pointer input = clitk::readImage<InputImageType>(mInputFilenames);
77 if (std::numeric_limits<PixelType>::is_signed) {
78 if (!std::numeric_limits<OutputPixelType>::is_signed) {
79 std::cerr << "Warning, input type is signed (" << mPixelTypeName << ") while output type is not ("
80 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
83 if (!std::numeric_limits<PixelType>::is_integer) {
84 if (std::numeric_limits<OutputPixelType>::is_integer) {
85 std::cerr << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is ("
86 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
89 // DD(std::numeric_limits<PixelType>::digits10);
90 // DD(std::numeric_limits<OutputPixelType>::digits10);
91 if (!std::numeric_limits<PixelType>::is_integer) {
92 if (std::numeric_limits<OutputPixelType>::is_integer) {
93 std::cerr << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is ("
94 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
97 if (std::numeric_limits<PixelType>::digits10 > std::numeric_limits<OutputPixelType>::digits10) {
98 std::cerr << "Warning, possible loss of precision : input type is (" << mPixelTypeName << ") while output type is ("
99 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
103 typedef itk::Image<OutputPixelType,Dim> OutputImageType;
104 typedef itk::CastImageFilter<InputImageType, OutputImageType> FilterType;
105 typename FilterType::Pointer filter = FilterType::New();
106 filter->SetInput(input);
110 SetNextOutput<OutputImageType>(filter->GetOutput());
111 //clitk::writeImage<OutputImageType>(filter->GetOutput(), mOutputFilename, mIOVerbose);
113 //====================================================================
115 #endif /* end #define CLITKIMAGECONVERTGENERICFILTER_TXX */