X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=filters%2FclitkImageConvertGenericFilter.cxx;h=944ec8cf8eaec2400f0af676877b18a6a28076d5;hb=9d6949060d302078e7a06fc9b0fbdcf96091b29a;hp=326f06f14f202ba3be38f2da62b03e7a9d6753a4;hpb=0b7c9b1e1215634b02cbd38d4e4ba101d6111ba8;p=clitk.git diff --git a/filters/clitkImageConvertGenericFilter.cxx b/filters/clitkImageConvertGenericFilter.cxx index 326f06f..944ec8c 100644 --- a/filters/clitkImageConvertGenericFilter.cxx +++ b/filters/clitkImageConvertGenericFilter.cxx @@ -1,7 +1,7 @@ /*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv - Authors belong to: + Authors belong to: - University of LYON http://www.universite-lyon.fr/ - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr @@ -14,49 +14,40 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ + ======================================================================-====*/ #ifndef CLITKIMAGECONVERTGENERICFILTER_CXX #define CLITKIMAGECONVERTGENERICFILTER_CXX -/** - ------------------------------------------------- - * @file clitkImageConvertGenericFilter.cxx - * @author David Sarrut - * @date 05 May 2008 10:57:19 - * - * @brief - * - * - -------------------------------------------------*/ #include "clitkImageConvertGenericFilter.h" //-------------------------------------------------------------------- clitk::ImageConvertGenericFilter::ImageConvertGenericFilter(): - clitk::ImageToImageGenericFilter("ImageConvert") { + clitk::ImageToImageGenericFilter("ImageConvert") +{ mOutputPixelTypeName = "NotSpecified"; + mWarningOccur = false; + mWarning = ""; + mDisplayWarning = true; InitializeImageType<2>(); - InitializeImageType<3>(); - InitializeImageType<4>(); + InitializeImageType<3>(); + InitializeImageType<4>(); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- template -void clitk::ImageConvertGenericFilter::InitializeImageType() { - ADD_IMAGE_TYPE(Dim, char); - ADD_IMAGE_TYPE(Dim, short); - ADD_IMAGE_TYPE(Dim, unsigned short); - ADD_IMAGE_TYPE(Dim, int); - ADD_IMAGE_TYPE(Dim, float); - ADD_IMAGE_TYPE(Dim, double); +void clitk::ImageConvertGenericFilter::InitializeImageType() +{ + ADD_DEFAULT_IMAGE_TYPES(Dim); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- template -void clitk::ImageConvertGenericFilter::UpdateWithInputImageType() { +void clitk::ImageConvertGenericFilter::UpdateWithInputImageType() +{ // Verbose stuff if (mIOVerbose) { @@ -65,13 +56,12 @@ void clitk::ImageConvertGenericFilter::UpdateWithInputImageType() { itk::ImageIOBase::Pointer header = clitk::readImageHeader(mInputFilenames[0]); printImageHeader(header, std::cout); std::cout << std::endl; - } - else { + } else { for(unsigned int i=0; i is "; - itk::ImageIOBase::Pointer h = clitk::readImageHeader(mInputFilenames[i]); - printImageHeader(h, std::cout); - std::cout << std::endl; + std::cout << "Input image " << i << " <" << mInputFilenames[i] << "> is "; + itk::ImageIOBase::Pointer h = clitk::readImageHeader(mInputFilenames[i]); + printImageHeader(h, std::cout); + std::cout << std::endl; } } } @@ -82,12 +72,11 @@ void clitk::ImageConvertGenericFilter::UpdateWithInputImageType() { typename InputImageType::Pointer input = this->template GetInput(0); //clitk::writeImage(input, mOutputFilename, mIOVerbose); this->SetNextOutput(input); - } - else { -#define TRY_TYPE(TYPE) \ + } else { +#define TRY_TYPE(TYPE) \ if (IsSameType(mOutputPixelTypeName)) { UpdateWithOutputType(); return; } TRY_TYPE(char); - // TRY_TYPE(signed char); + // TRY_TYPE(signed char); TRY_TYPE(uchar); TRY_TYPE(short); TRY_TYPE(ushort); @@ -97,16 +86,17 @@ void clitk::ImageConvertGenericFilter::UpdateWithInputImageType() { #undef TRY_TYPE std::string list = CreateListOfTypes(); - std::cerr << "Error, I don't know the output type '" << mOutputPixelTypeName - << "'. " << std::endl << "Known types are " << list << "." << std::endl; + std::cerr << "Error, I don't know the output type '" << mOutputPixelTypeName + << "'. " << std::endl << "Known types are " << list << "." << std::endl; exit(0); - } + } } //==================================================================== //==================================================================== template -void clitk::ImageConvertGenericFilter::UpdateWithOutputType() { +void clitk::ImageConvertGenericFilter::UpdateWithOutputType() +{ // Read typename InputImageType::Pointer input =this->template GetInput(0); @@ -114,29 +104,39 @@ void clitk::ImageConvertGenericFilter::UpdateWithOutputType() { typedef typename InputImageType::PixelType PixelType; // Warning + std::ostringstream osstream; if (std::numeric_limits::is_signed) { if (!std::numeric_limits::is_signed) { - std::cerr << "Warning, input type is signed (" << mPixelTypeName << ") while output type is not (" - << mOutputPixelTypeName << "), use at your own responsability." << std::endl; + osstream << "Warning, input type is signed (" << mPixelTypeName << ") while output type is not (" + << mOutputPixelTypeName << "), use at your own responsability." << std::endl; + mWarningOccur = true; } } if (!std::numeric_limits::is_integer) { if (std::numeric_limits::is_integer) { - std::cerr << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is (" - << mOutputPixelTypeName << "), use at your own responsability." << std::endl; + osstream << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is (" + << mOutputPixelTypeName << "), use at your own responsability." << std::endl; + mWarningOccur = true; } } // DD(std::numeric_limits::digits10); // DD(std::numeric_limits::digits10); if (!std::numeric_limits::is_integer) { if (std::numeric_limits::is_integer) { - std::cerr << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is (" - << mOutputPixelTypeName << "), use at your own responsability." << std::endl; + osstream << "Warning, input type is not integer (" << mPixelTypeName << ") while output type is (" + << mOutputPixelTypeName << "), use at your own responsability." << std::endl; + mWarningOccur = true; } } if (std::numeric_limits::digits10 > std::numeric_limits::digits10) { - std::cerr << "Warning, possible loss of precision : input type is (" << mPixelTypeName << ") while output type is (" - << mOutputPixelTypeName << "), use at your own responsability." << std::endl; + osstream << "Warning, possible loss of precision : input type is (" << mPixelTypeName << ") while output type is (" + << mOutputPixelTypeName << "), use at your own responsability." << std::endl; + mWarningOccur = true; + } + + mWarning = osstream.str(); + if (mDisplayWarning) { + std::cerr << mWarning; } // Cast