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://www.centreleonberard.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_CXX
19 #define CLITKIMAGECONVERTGENERICFILTER_CXX
21 #include "clitkImageConvertGenericFilter.h"
23 //--------------------------------------------------------------------
24 clitk::ImageConvertGenericFilter::ImageConvertGenericFilter():
25 clitk::ImageToImageGenericFilter<Self>("ImageConvert")
27 mOutputPixelTypeName = "NotSpecified";
28 mWarningOccur = false;
30 mDisplayWarning = true;
31 InitializeImageType<2>();
32 InitializeImageType<3>();
33 InitializeImageType<4>();
35 //--------------------------------------------------------------------
38 //--------------------------------------------------------------------
39 template<unsigned int Dim>
40 void clitk::ImageConvertGenericFilter::InitializeImageType()
42 ADD_DEFAULT_IMAGE_TYPES(Dim);
44 //--------------------------------------------------------------------
47 //--------------------------------------------------------------------
48 template<class InputImageType>
49 void clitk::ImageConvertGenericFilter::UpdateWithInputImageType()
54 if (m_InputFilenames.size() == 1) {
55 std::cout << "Input image <" << m_InputFilenames[0] << "> is ";
56 itk::ImageIOBase::Pointer header = clitk::readImageHeader(m_InputFilenames[0]);
57 printImageHeader(header, std::cout);
58 std::cout << std::endl;
60 for(unsigned int i=0; i<m_InputFilenames.size(); i++) {
61 std::cout << "Input image " << i << " <" << m_InputFilenames[i] << "> is ";
62 itk::ImageIOBase::Pointer h = clitk::readImageHeader(m_InputFilenames[i]);
63 printImageHeader(h, std::cout);
64 std::cout << std::endl;
70 if ((m_PixelTypeName == mOutputPixelTypeName) || (mOutputPixelTypeName == "NotSpecified")) {
71 // typename InputImageType::Pointer input = clitk::readImage<InputImageType>(m_InputFilenames);
72 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
73 //clitk::writeImage<InputImageType>(input, mOutputFilename, m_IOVerbose);
74 this->SetNextOutput<InputImageType>(input);
76 #define TRY_TYPE(TYPE) \
77 if (IsSameType<TYPE>(mOutputPixelTypeName)) { UpdateWithOutputType<InputImageType, TYPE>(); return; }
79 // TRY_TYPE(signed char);
83 TRY_TYPE(int); // no uint ...
88 std::string list = CreateListOfTypes<char, uchar, short, ushort, int, float, double>();
89 std::cerr << "Error, I don't know the output type '" << mOutputPixelTypeName
90 << "'. " << std::endl << "Known types are " << list << "." << std::endl;
94 //====================================================================
96 //====================================================================
97 template<class InputImageType, class OutputPixelType>
98 void clitk::ImageConvertGenericFilter::UpdateWithOutputType()
101 typename InputImageType::Pointer input =this->template GetInput<InputImageType>(0);
104 typedef typename InputImageType::PixelType PixelType;
107 std::ostringstream osstream;
108 if (std::numeric_limits<PixelType>::is_signed) {
109 if (!std::numeric_limits<OutputPixelType>::is_signed) {
110 osstream << "Warning, input type is signed (" << m_PixelTypeName << ") while output type is not ("
111 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
112 mWarningOccur = true;
115 if (!std::numeric_limits<PixelType>::is_integer) {
116 if (std::numeric_limits<OutputPixelType>::is_integer) {
117 osstream << "Warning, input type is not integer (" << m_PixelTypeName << ") while output type is ("
118 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
119 mWarningOccur = true;
122 // DD(std::numeric_limits<PixelType>::digits10);
123 // DD(std::numeric_limits<OutputPixelType>::digits10);
124 if (!std::numeric_limits<PixelType>::is_integer) {
125 if (std::numeric_limits<OutputPixelType>::is_integer) {
126 osstream << "Warning, input type is not integer (" << m_PixelTypeName << ") while output type is ("
127 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
128 mWarningOccur = true;
131 if (std::numeric_limits<PixelType>::digits10 > std::numeric_limits<OutputPixelType>::digits10) {
132 osstream << "Warning, possible loss of precision : input type is (" << m_PixelTypeName << ") while output type is ("
133 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
134 mWarningOccur = true;
137 mWarning = osstream.str();
138 if (mDisplayWarning) {
139 std::cerr << mWarning;
143 typedef itk::Image<OutputPixelType,InputImageType::ImageDimension> OutputImageType;
144 typedef itk::CastImageFilter<InputImageType, OutputImageType> FilterType;
145 typename FilterType::Pointer filter = FilterType::New();
146 filter->SetInput(input);
150 SetNextOutput<OutputImageType>(filter->GetOutput());
151 //clitk::writeImage<OutputImageType>(filter->GetOutput(), mOutputFilename, m_IOVerbose);
153 //====================================================================
156 #endif /* end #define CLITKIMAGECONVERTGENERICFILTER_CXX */