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_CXX
19 #define CLITKIMAGECONVERTGENERICFILTER_CXX
21 #include "clitkImageConvertGenericFilter.h"
23 //--------------------------------------------------------------------
24 clitk::ImageConvertGenericFilter::ImageConvertGenericFilter():
25 clitk::ImageToImageGenericFilter<Self>("ImageConvert") {
26 mOutputPixelTypeName = "NotSpecified";
27 mWarningOccur = false;
29 mDisplayWarning = true;
30 InitializeImageType<2>();
31 InitializeImageType<3>();
32 InitializeImageType<4>();
34 //--------------------------------------------------------------------
37 //--------------------------------------------------------------------
38 template<unsigned int Dim>
39 void clitk::ImageConvertGenericFilter::InitializeImageType() {
40 ADD_DEFAULT_IMAGE_TYPES(Dim);
42 //--------------------------------------------------------------------
45 //--------------------------------------------------------------------
46 template<class InputImageType>
47 void clitk::ImageConvertGenericFilter::UpdateWithInputImageType() {
51 if (mInputFilenames.size() == 1) {
52 std::cout << "Input image <" << mInputFilenames[0] << "> is ";
53 itk::ImageIOBase::Pointer header = clitk::readImageHeader(mInputFilenames[0]);
54 printImageHeader(header, std::cout);
55 std::cout << std::endl;
58 for(unsigned int i=0; i<mInputFilenames.size(); i++) {
59 std::cout << "Input image " << i << " <" << mInputFilenames[i] << "> is ";
60 itk::ImageIOBase::Pointer h = clitk::readImageHeader(mInputFilenames[i]);
61 printImageHeader(h, std::cout);
62 std::cout << std::endl;
68 if ((mPixelTypeName == mOutputPixelTypeName) || (mOutputPixelTypeName == "NotSpecified")) {
69 // typename InputImageType::Pointer input = clitk::readImage<InputImageType>(mInputFilenames);
70 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
71 //clitk::writeImage<InputImageType>(input, mOutputFilename, mIOVerbose);
72 this->SetNextOutput<InputImageType>(input);
75 #define TRY_TYPE(TYPE) \
76 if (IsSameType<TYPE>(mOutputPixelTypeName)) { UpdateWithOutputType<InputImageType, TYPE>(); return; }
78 // TRY_TYPE(signed char);
82 TRY_TYPE(int); // no uint ...
87 std::string list = CreateListOfTypes<char, uchar, short, ushort, int, float, double>();
88 std::cerr << "Error, I don't know the output type '" << mOutputPixelTypeName
89 << "'. " << std::endl << "Known types are " << list << "." << std::endl;
93 //====================================================================
95 //====================================================================
96 template<class InputImageType, class OutputPixelType>
97 void clitk::ImageConvertGenericFilter::UpdateWithOutputType() {
99 typename InputImageType::Pointer input =this->template GetInput<InputImageType>(0);
102 typedef typename InputImageType::PixelType PixelType;
105 std::ostringstream osstream;
106 if (std::numeric_limits<PixelType>::is_signed) {
107 if (!std::numeric_limits<OutputPixelType>::is_signed) {
108 osstream << "Warning, input type is signed (" << mPixelTypeName << ") while output type is not ("
109 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
110 mWarningOccur = true;
113 if (!std::numeric_limits<PixelType>::is_integer) {
114 if (std::numeric_limits<OutputPixelType>::is_integer) {
115 osstream << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is ("
116 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
117 mWarningOccur = true;
120 // DD(std::numeric_limits<PixelType>::digits10);
121 // DD(std::numeric_limits<OutputPixelType>::digits10);
122 if (!std::numeric_limits<PixelType>::is_integer) {
123 if (std::numeric_limits<OutputPixelType>::is_integer) {
124 osstream << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is ("
125 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
126 mWarningOccur = true;
129 if (std::numeric_limits<PixelType>::digits10 > std::numeric_limits<OutputPixelType>::digits10) {
130 osstream << "Warning, possible loss of precision : input type is (" << mPixelTypeName << ") while output type is ("
131 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
132 mWarningOccur = true;
135 mWarning = osstream.str();
136 if (mDisplayWarning) {
137 std::cerr << mWarning;
141 typedef itk::Image<OutputPixelType,InputImageType::ImageDimension> OutputImageType;
142 typedef itk::CastImageFilter<InputImageType, OutputImageType> FilterType;
143 typename FilterType::Pointer filter = FilterType::New();
144 filter->SetInput(input);
148 SetNextOutput<OutputImageType>(filter->GetOutput());
149 //clitk::writeImage<OutputImageType>(filter->GetOutput(), mOutputFilename, mIOVerbose);
151 //====================================================================
154 #endif /* end #define CLITKIMAGECONVERTGENERICFILTER_CXX */