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"
22 #include "vvImageReader.h"
23 #include "vvImageWriter.h"
25 //--------------------------------------------------------------------
26 clitk::ImageConvertGenericFilter::ImageConvertGenericFilter():
27 clitk::ImageToImageGenericFilter<Self>("ImageConvert")
29 mOutputPixelTypeName = "NotSpecified";
30 mDisplayWarning = true;
32 mWarningOccur = false;
34 InitializeImageType<2>();
35 InitializeImageType<3>();
36 InitializeImageType<4>();
38 //--------------------------------------------------------------------
41 //--------------------------------------------------------------------
42 template<unsigned int Dim>
43 void clitk::ImageConvertGenericFilter::InitializeImageType()
45 ADD_DEFAULT_IMAGE_TYPES(Dim);
46 ADD_VEC_IMAGE_TYPE(Dim, 2, float);
47 ADD_VEC_IMAGE_TYPE(Dim, 3, float);
48 ADD_VEC_IMAGE_TYPE(Dim, 2, double);
49 ADD_VEC_IMAGE_TYPE(Dim, 3, double);
51 //--------------------------------------------------------------------
54 //--------------------------------------------------------------------
55 template<class InputImageType>
56 void clitk::ImageConvertGenericFilter::UpdateWithInputImageType()
60 if (m_InputFilenames.size() == 1) {
61 std::cout << "Input image <" << m_InputFilenames[0] << "> is ";
62 itk::ImageIOBase::Pointer header = clitk::readImageHeader(m_InputFilenames[0]);
63 printImageHeader(header, std::cout);
64 std::cout << std::endl;
66 for(unsigned int i=0; i<m_InputFilenames.size(); i++) {
67 std::cout << "Input image " << i << " <" << m_InputFilenames[i] << "> is ";
68 itk::ImageIOBase::Pointer h = clitk::readImageHeader(m_InputFilenames[i]);
69 printImageHeader(h, std::cout);
70 std::cout << std::endl;
76 if (mOutputPixelTypeName != "NotSpecified" || m_WriteCompression) {
77 std::cerr << "--vv is not compatible with --compression and --type options." << std::endl;
81 vvImageReader::Pointer reader = vvImageReader::New();
82 reader->SetInputFilenames(m_InputFilenames);
83 reader->Update(vvImageReader::IMAGE);
85 vvImageWriter::Pointer writer = vvImageWriter::New();
86 writer->SetOutputFileName(m_OutputFilenames.front());
87 writer->SetSaveTransform(true);
88 writer->SetInput(reader->GetOutput());
92 else if ((m_PixelTypeName == mOutputPixelTypeName) || (mOutputPixelTypeName == "NotSpecified")) {
93 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
94 this->SetNextOutput<InputImageType>(input);
96 // "trick" to call independent versions of update according to the
97 // pixel type (vector or scalar), using partial specializations
98 if (!UpdateWithSelectiveOutputType<InputImageType, ImageConvertTraits<typename InputImageType::PixelType>::IS_VECTOR>::Run(*this, mOutputPixelTypeName))
102 //====================================================================
104 //====================================================================
106 template<class PixelType, class OutputPixelType>
107 void clitk::ImageConvertGenericFilter::CheckTypes(
108 std::string inType, std::string outType
111 std::ostringstream osstream;
112 if (std::numeric_limits<PixelType>::is_signed) {
113 if (!std::numeric_limits<OutputPixelType>::is_signed) {
114 osstream << "Warning, input type is signed (";
117 if (!std::numeric_limits<PixelType>::is_integer) {
118 if (std::numeric_limits<OutputPixelType>::is_integer) {
119 osstream << "Warning, input type is not integer (";
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 (";
129 if (std::numeric_limits<PixelType>::digits10 > std::numeric_limits<OutputPixelType>::digits10) {
130 osstream << "Warning, possible loss of precision : input type is (" ;
133 if (!osstream.str().empty())
135 mWarningOccur = true;
136 osstream << inType << ") while output type is (" << outType << "), use at your own responsability." << std::endl;
137 mWarning = osstream.str();
138 if (mDisplayWarning) {
139 std::cerr << mWarning;
145 #endif /* end #define CLITKIMAGECONVERTGENERICFILTER_CXX */