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 mDisplayWarning = true;
30 mWarningOccur = false;
32 InitializeImageType<2>();
33 InitializeImageType<3>();
34 InitializeImageType<4>();
36 //--------------------------------------------------------------------
39 //--------------------------------------------------------------------
40 template<unsigned int Dim>
41 void clitk::ImageConvertGenericFilter::InitializeImageType()
43 ADD_DEFAULT_IMAGE_TYPES(Dim);
44 ADD_VEC_IMAGE_TYPE(Dim, 2, float);
45 ADD_VEC_IMAGE_TYPE(Dim, 3, float);
46 ADD_VEC_IMAGE_TYPE(Dim, 2, double);
47 ADD_VEC_IMAGE_TYPE(Dim, 3, double);
49 //--------------------------------------------------------------------
52 //--------------------------------------------------------------------
53 template<class InputImageType>
54 void clitk::ImageConvertGenericFilter::UpdateWithInputImageType()
58 if (m_InputFilenames.size() == 1) {
59 std::cout << "Input image <" << m_InputFilenames[0] << "> is ";
60 itk::ImageIOBase::Pointer header = clitk::readImageHeader(m_InputFilenames[0]);
61 printImageHeader(header, std::cout);
62 std::cout << std::endl;
64 for(unsigned int i=0; i<m_InputFilenames.size(); i++) {
65 std::cout << "Input image " << i << " <" << m_InputFilenames[i] << "> is ";
66 itk::ImageIOBase::Pointer h = clitk::readImageHeader(m_InputFilenames[i]);
67 printImageHeader(h, std::cout);
68 std::cout << std::endl;
73 if ((m_PixelTypeName == mOutputPixelTypeName) || (mOutputPixelTypeName == "NotSpecified")) {
74 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
75 this->SetNextOutput<InputImageType>(input);
77 // "trick" to call independent versions of update according to the
78 // pixel type (vector or scalar), using partial specializations
79 if (!UpdateWithSelectiveOutputType<InputImageType, ImageConvertTraits<typename InputImageType::PixelType>::IS_VECTOR>::Run(*this, mOutputPixelTypeName))
83 //====================================================================
85 //====================================================================
87 template<class PixelType, class OutputPixelType>
88 void clitk::ImageConvertGenericFilter::CheckTypes(
89 std::string inType, std::string outType
92 std::ostringstream osstream;
93 if (std::numeric_limits<PixelType>::is_signed) {
94 if (!std::numeric_limits<OutputPixelType>::is_signed) {
95 osstream << "Warning, input type is signed (";
98 if (!std::numeric_limits<PixelType>::is_integer) {
99 if (std::numeric_limits<OutputPixelType>::is_integer) {
100 osstream << "Warning, input type is not integer (";
103 // DD(std::numeric_limits<PixelType>::digits10);
104 // DD(std::numeric_limits<OutputPixelType>::digits10);
105 if (!std::numeric_limits<PixelType>::is_integer) {
106 if (std::numeric_limits<OutputPixelType>::is_integer) {
107 osstream << "Warning, input type is not integer (";
110 if (std::numeric_limits<PixelType>::digits10 > std::numeric_limits<OutputPixelType>::digits10) {
111 osstream << "Warning, possible loss of precision : input type is (" ;
114 if (!osstream.str().empty())
116 mWarningOccur = true;
117 osstream << inType << ") while output type is (" << outType << "), use at your own responsability." << std::endl;
118 mWarning = osstream.str();
119 if (mDisplayWarning) {
120 std::cerr << mWarning;
126 #endif /* end #define CLITKIMAGECONVERTGENERICFILTER_CXX */