X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkImageConvertGenericFilter.cxx;h=2783053fdb2d7546c4096948e621c38a7a4fdeb2;hb=8c110a6b043a6b85c1a0c4762fbfff4c3bea5c7d;hp=b7702cc694aa5450cff434d37f0c6a5698df53a4;hpb=08d1fd56ac1d08bd228d9e557f5472a395e9b708;p=clitk.git diff --git a/tools/clitkImageConvertGenericFilter.cxx b/tools/clitkImageConvertGenericFilter.cxx index b7702cc..2783053 100644 --- a/tools/clitkImageConvertGenericFilter.cxx +++ b/tools/clitkImageConvertGenericFilter.cxx @@ -19,15 +19,18 @@ #define CLITKIMAGECONVERTGENERICFILTER_CXX #include "clitkImageConvertGenericFilter.h" +#include "vvImageReader.h" +#include "vvImageWriter.h" //-------------------------------------------------------------------- clitk::ImageConvertGenericFilter::ImageConvertGenericFilter(): clitk::ImageToImageGenericFilter("ImageConvert") { mOutputPixelTypeName = "NotSpecified"; - mWarningOccur = false; - mWarning = ""; mDisplayWarning = true; + mWarning = ""; + mWarningOccur = false; + InitializeImageType<2>(); InitializeImageType<3>(); InitializeImageType<4>(); @@ -40,6 +43,10 @@ template void clitk::ImageConvertGenericFilter::InitializeImageType() { ADD_DEFAULT_IMAGE_TYPES(Dim); + ADD_VEC_IMAGE_TYPE(Dim, 2, float); + ADD_VEC_IMAGE_TYPE(Dim, 3, float); + ADD_VEC_IMAGE_TYPE(Dim, 2, double); + ADD_VEC_IMAGE_TYPE(Dim, 3, double); } //-------------------------------------------------------------------- @@ -48,7 +55,6 @@ void clitk::ImageConvertGenericFilter::InitializeImageType() template void clitk::ImageConvertGenericFilter::UpdateWithInputImageType() { - // Verbose stuff if (m_IOVerbose) { if (m_InputFilenames.size() == 1) { @@ -66,91 +72,74 @@ void clitk::ImageConvertGenericFilter::UpdateWithInputImageType() } } + if(mVV) { + if (mOutputPixelTypeName != "NotSpecified" || m_WriteCompression) { + std::cerr << "--vv is not compatible with --compression and --type options." << std::endl; + exit(-1); + } + + vvImageReader::Pointer reader = vvImageReader::New(); + reader->SetInputFilenames(m_InputFilenames); + reader->Update(vvImageReader::IMAGE); - if ((m_PixelTypeName == mOutputPixelTypeName) || (mOutputPixelTypeName == "NotSpecified")) { - // typename InputImageType::Pointer input = clitk::readImage(m_InputFilenames); + vvImageWriter::Pointer writer = vvImageWriter::New(); + writer->SetOutputFileName(m_OutputFilenames.front()); + writer->SetSaveTransform(true); + writer->SetInput(reader->GetOutput()); + writer->Update(); + return; + } + else if ((m_PixelTypeName == mOutputPixelTypeName) || (mOutputPixelTypeName == "NotSpecified")) { typename InputImageType::Pointer input = this->template GetInput(0); - //clitk::writeImage(input, mOutputFilename, m_IOVerbose); this->SetNextOutput(input); } else { -#define TRY_TYPE(TYPE) \ - if (IsSameType(mOutputPixelTypeName)) { UpdateWithOutputType(); return; } - TRY_TYPE(char); - // TRY_TYPE(signed char); - TRY_TYPE(uchar); - TRY_TYPE(short); - TRY_TYPE(ushort); - TRY_TYPE(int); // no uint ... - TRY_TYPE(float); - TRY_TYPE(double); -#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; - exit(0); + // "trick" to call independent versions of update according to the + // pixel type (vector or scalar), using partial specializations + if (!UpdateWithSelectiveOutputType::IS_VECTOR>::Run(*this, mOutputPixelTypeName)) + exit(-1); } } //==================================================================== //==================================================================== -template -void clitk::ImageConvertGenericFilter::UpdateWithOutputType() -{ - // Read - typename InputImageType::Pointer input =this->template GetInput(0); - // Typedef - typedef typename InputImageType::PixelType PixelType; - - // Warning +template +void clitk::ImageConvertGenericFilter::CheckTypes( + std::string inType, std::string outType +) +{ std::ostringstream osstream; if (std::numeric_limits::is_signed) { if (!std::numeric_limits::is_signed) { - osstream << "Warning, input type is signed (" << m_PixelTypeName << ") while output type is not (" - << mOutputPixelTypeName << "), use at your own responsability." << std::endl; - mWarningOccur = true; + osstream << "Warning, input type is signed ("; } } if (!std::numeric_limits::is_integer) { if (std::numeric_limits::is_integer) { - osstream << "Warning, input type is not integer (" << m_PixelTypeName << ") while output type is (" - << mOutputPixelTypeName << "), use at your own responsability." << std::endl; - mWarningOccur = true; + osstream << "Warning, input type is not integer ("; } } // DD(std::numeric_limits::digits10); // DD(std::numeric_limits::digits10); if (!std::numeric_limits::is_integer) { if (std::numeric_limits::is_integer) { - osstream << "Warning, input type is not integer (" << m_PixelTypeName << ") while output type is (" - << mOutputPixelTypeName << "), use at your own responsability." << std::endl; - mWarningOccur = true; + osstream << "Warning, input type is not integer ("; } } if (std::numeric_limits::digits10 > std::numeric_limits::digits10) { - osstream << "Warning, possible loss of precision : input type is (" << m_PixelTypeName << ") while output type is (" - << mOutputPixelTypeName << "), use at your own responsability." << std::endl; - mWarningOccur = true; + osstream << "Warning, possible loss of precision : input type is (" ; } - mWarning = osstream.str(); - if (mDisplayWarning) { - std::cerr << mWarning; + if (!osstream.str().empty()) + { + mWarningOccur = true; + osstream << inType << ") while output type is (" << outType << "), use at your own responsability." << std::endl; + mWarning = osstream.str(); + if (mDisplayWarning) { + std::cerr << mWarning; + } } - - // Cast - typedef itk::Image OutputImageType; - typedef itk::CastImageFilter FilterType; - typename FilterType::Pointer filter = FilterType::New(); - filter->SetInput(input); - filter->Update(); - - // Write - SetNextOutput(filter->GetOutput()); - //clitk::writeImage(filter->GetOutput(), mOutputFilename, m_IOVerbose); } -//==================================================================== #endif /* end #define CLITKIMAGECONVERTGENERICFILTER_CXX */