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 -------------------------------------------------
22 * @file clitkImageConvertGenericFilter.cxx
23 * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
24 * @date 05 May 2008 10:57:19
29 -------------------------------------------------*/
31 #include "clitkImageConvertGenericFilter.h"
33 //--------------------------------------------------------------------
34 clitk::ImageConvertGenericFilter::ImageConvertGenericFilter():
35 clitk::ImageToImageGenericFilter<Self>("ImageConvert") {
36 mOutputPixelTypeName = "NotSpecified";
37 InitializeImageType<2>();
38 InitializeImageType<3>();
39 InitializeImageType<4>();
41 //--------------------------------------------------------------------
44 //--------------------------------------------------------------------
45 template<unsigned int Dim>
46 void clitk::ImageConvertGenericFilter::InitializeImageType() {
47 ADD_IMAGE_TYPE(Dim, char);
48 ADD_IMAGE_TYPE(Dim, short);
49 ADD_IMAGE_TYPE(Dim, unsigned short);
50 ADD_IMAGE_TYPE(Dim, int);
51 ADD_IMAGE_TYPE(Dim, float);
52 ADD_IMAGE_TYPE(Dim, double);
54 //--------------------------------------------------------------------
57 //--------------------------------------------------------------------
58 template<class InputImageType>
59 void clitk::ImageConvertGenericFilter::UpdateWithInputImageType() {
63 if (mInputFilenames.size() == 1) {
64 std::cout << "Input image <" << mInputFilenames[0] << "> is ";
65 itk::ImageIOBase::Pointer header = clitk::readImageHeader(mInputFilenames[0]);
66 printImageHeader(header, std::cout);
67 std::cout << std::endl;
70 for(unsigned int i=0; i<mInputFilenames.size(); i++) {
71 std::cout << "Input image " << i << " <" << mInputFilenames[i] << "> is ";
72 itk::ImageIOBase::Pointer h = clitk::readImageHeader(mInputFilenames[i]);
73 printImageHeader(h, std::cout);
74 std::cout << std::endl;
80 if ((mPixelTypeName == mOutputPixelTypeName) || (mOutputPixelTypeName == "NotSpecified")) {
81 // typename InputImageType::Pointer input = clitk::readImage<InputImageType>(mInputFilenames);
82 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
83 //clitk::writeImage<InputImageType>(input, mOutputFilename, mIOVerbose);
84 this->SetNextOutput<InputImageType>(input);
87 #define TRY_TYPE(TYPE) \
88 if (IsSameType<TYPE>(mOutputPixelTypeName)) { UpdateWithOutputType<InputImageType, TYPE>(); return; }
90 // TRY_TYPE(signed char);
94 TRY_TYPE(int); // no uint ...
99 std::string list = CreateListOfTypes<char, uchar, short, ushort, int, float, double>();
100 std::cerr << "Error, I don't know the output type '" << mOutputPixelTypeName
101 << "'. " << std::endl << "Known types are " << list << "." << std::endl;
105 //====================================================================
107 //====================================================================
108 template<class InputImageType, class OutputPixelType>
109 void clitk::ImageConvertGenericFilter::UpdateWithOutputType() {
111 typename InputImageType::Pointer input =this->template GetInput<InputImageType>(0);
114 typedef typename InputImageType::PixelType PixelType;
117 if (std::numeric_limits<PixelType>::is_signed) {
118 if (!std::numeric_limits<OutputPixelType>::is_signed) {
119 std::cerr << "Warning, input type is signed (" << mPixelTypeName << ") while output type is not ("
120 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
123 if (!std::numeric_limits<PixelType>::is_integer) {
124 if (std::numeric_limits<OutputPixelType>::is_integer) {
125 std::cerr << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is ("
126 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
129 // DD(std::numeric_limits<PixelType>::digits10);
130 // DD(std::numeric_limits<OutputPixelType>::digits10);
131 if (!std::numeric_limits<PixelType>::is_integer) {
132 if (std::numeric_limits<OutputPixelType>::is_integer) {
133 std::cerr << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is ("
134 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
137 if (std::numeric_limits<PixelType>::digits10 > std::numeric_limits<OutputPixelType>::digits10) {
138 std::cerr << "Warning, possible loss of precision : input type is (" << mPixelTypeName << ") while output type is ("
139 << mOutputPixelTypeName << "), use at your own responsability." << std::endl;
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, mIOVerbose);
153 //====================================================================
156 #endif /* end #define CLITKIMAGECONVERTGENERICFILTER_CXX */