X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkImageConvertGenericFilter.cxx;h=51a43a029a60fa239ebd0840465751af3198cd63;hb=d9c8c6e6c759655fc24d05d47b962d2ba574b95d;hp=b36ba044b30353c660300c1660d02df3276c7c15;hpb=0fe907bc305f611ba8bc2ab95e287658efaefede;p=clitk.git diff --git a/tools/clitkImageConvertGenericFilter.cxx b/tools/clitkImageConvertGenericFilter.cxx index b36ba04..51a43a0 100644 --- a/tools/clitkImageConvertGenericFilter.cxx +++ b/tools/clitkImageConvertGenericFilter.cxx @@ -15,22 +15,33 @@ - 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 #include "clitkImageConvertGenericFilter.h" -// itk include -#include "itkCastImageFilter.h" -#include "itkVectorCastImageFilter.h" +#include "vvImageReader.h" +#include "vvImageWriter.h" +#include "itkFlipImageFilter.h" +#include "itkGDCMImageIO.h" +#include + +#include "gdcmReader.h" +#include "gdcmAttribute.h" +#include "gdcmPrinter.h" +#include "gdcmDict.h" +#include "gdcmStringFilter.h" //-------------------------------------------------------------------- clitk::ImageConvertGenericFilter::ImageConvertGenericFilter(): clitk::ImageToImageGenericFilter("ImageConvert") { mOutputPixelTypeName = "NotSpecified"; - mWarningOccur = false; - mWarning = ""; mDisplayWarning = true; + mWarning = ""; + mWarningOccur = false; + SetCorrectNegativeSpacingFlag(false); + InitializeImageType<2>(); InitializeImageType<3>(); InitializeImageType<4>(); @@ -43,20 +54,10 @@ template void clitk::ImageConvertGenericFilter::InitializeImageType() { ADD_DEFAULT_IMAGE_TYPES(Dim); - ADD_VEC_IMAGE_TYPE(Dim, 2, char) - ADD_VEC_IMAGE_TYPE(Dim, 3, char) - ADD_VEC_IMAGE_TYPE(Dim, 2, unsigned char) - ADD_VEC_IMAGE_TYPE(Dim, 3, unsigned char) - ADD_VEC_IMAGE_TYPE(Dim, 2, short) - ADD_VEC_IMAGE_TYPE(Dim, 3, short) - ADD_VEC_IMAGE_TYPE(Dim, 2, unsigned short) - ADD_VEC_IMAGE_TYPE(Dim, 3, unsigned short) - ADD_VEC_IMAGE_TYPE(Dim, 2, int) - ADD_VEC_IMAGE_TYPE(Dim, 3, int) - 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) + 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); } //-------------------------------------------------------------------- @@ -65,7 +66,6 @@ void clitk::ImageConvertGenericFilter::InitializeImageType() template void clitk::ImageConvertGenericFilter::UpdateWithInputImageType() { - // Verbose stuff if (m_IOVerbose) { if (m_InputFilenames.size() == 1) { @@ -83,471 +83,169 @@ 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); + } - if ((m_PixelTypeName == mOutputPixelTypeName) || (mOutputPixelTypeName == "NotSpecified")) { - // typename InputImageType::Pointer input = clitk::readImage(m_InputFilenames); - 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 - - IsSameType("char"); - - std::string list = CreateListOfTypes(); - std::cerr << "Error, I don't know the output type '" << mOutputPixelTypeName << " (input = " << m_PixelTypeName << ")" - << "'. " << std::endl << "Known types are " << list << "." << std::endl; - exit(0); - } -} -//==================================================================== + vvImageReader::Pointer reader = vvImageReader::New(); + reader->SetInputFilenames(m_InputFilenames); + reader->Update(vvImageReader::IMAGE); -//==================================================================== -template -void clitk::ImageConvertGenericFilter::UpdateWithOutputType() -{ - // Read - typename InputImageType::Pointer input =this->template GetInput(0); + 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")) { - // Typedef - typedef typename InputImageType::PixelType PixelType; + // Get input image + typename InputImageType::Pointer input = this->template GetInput(0); - // Warning - 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; - } - } - 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; - } - } - // 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; + if (mCorrectNegativeSpacingFlag) { + // Read dicom + gdcm::Reader reader; + reader.SetFileName(m_InputFilenames[0].c_str()); + // if (!reader.CanReadFile(m_InputFilenames[0])) { + // std::cout << "Error: " << m_InputFilenames[0] << " is not a dicom file. Abort." << std::endl; + // exit(0); + // } + reader.Read(); + + // the dataset is the the set of element we are interested in: + gdcm::DataSet & ds = reader.GetFile().GetDataSet(); + + // Read the attribute SpacingBetweenSlices, check if negative and replace + gdcm::Attribute<0x0018,0x0088> SpacingBetweenSlices; + SpacingBetweenSlices.SetFromDataSet(ds); + double s = SpacingBetweenSlices.GetValue(); + if (s >=0) { + std::cout << "Error: no negative spacing found SpacingBetweenSlices = " << s << " Abort. " << std::endl; + exit(0); + } + s = -s; + + // Set spacing + typename InputImageType::SpacingType spacing = input->GetSpacing(); + spacing[2] = s; + input->SetSpacing(spacing); + + // Flip + typedef itk::FlipImageFilter< InputImageType > FilterType; + typename FilterType::Pointer filter = FilterType::New(); + typedef typename FilterType::FlipAxesArrayType FlipAxesArrayType; + FlipAxesArrayType flipArray; + flipArray[0] = false; + flipArray[1] = false; + flipArray[2] = true; + filter->SetFlipAxes(flipArray); + filter->SetInput(input); + filter->Update(); + + // Read the attribute Image Position (Patient) + gdcm::Tag DetectorInformationSequenceTag(0x0054,0x0022); + const gdcm::DataElement & DIS = ds.GetDataElement(DetectorInformationSequenceTag); + if (!DIS.GetByteValue()) { + std::cout << "Error: could not find 0x0054,0x0022 tag. Abort." << std::endl; + exit(0); + } + gdcm::SmartPointer sqf = DIS.GetValueAsSQ(); + gdcm::Item & item = sqf->GetItem(1); + gdcm::DataSet & ds_position = item.GetNestedDataSet(); + gdcm::Attribute<0x0020,0x0032> ImagePositionPatient; + ImagePositionPatient.SetFromDataSet(ds_position); + double x = ImagePositionPatient.GetValue(0); + double y = ImagePositionPatient.GetValue(1); + double z = ImagePositionPatient.GetValue(2); + + // Set offset + typename InputImageType::PointType origin = input->GetOrigin(); + origin[0] = x; + origin[1] = y; + origin[2] = z; + input->SetOrigin(origin); + + // Orientation + typename InputImageType::DirectionType direction = input->GetDirection(); + direction[2][2] = -1; + input->SetDirection(direction); + + // Empty meta info + itk::MetaDataDictionary dict;// = new itk::MetaDataDictionary; + input->SetMetaDataDictionary(dict); } - } - 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; - } - mWarning = osstream.str(); - if (mDisplayWarning) { - std::cerr << mWarning; - } + typedef itk::ChangeInformationImageFilter CIType; + typename CIType::Pointer changeInfo = CIType::New(); + if(mNoNiiMeta) { + changeInfo->SetInput(input); + typename CIType::PointType o = input->GetOrigin(); + o[0] *= -1.; + o[1] *= -1.; + typename CIType::DirectionType d = input->GetDirection(); + d[0][0] *= -1.; + d[1][1] *= -1.; + changeInfo->ChangeDirectionOn(); + changeInfo->ChangeOriginOn(); + changeInfo->SetOutputOrigin(o); + changeInfo->SetOutputDirection(d); + changeInfo->Update(); + input = changeInfo->GetOutput(); + } - // Cast - typedef itk::Image OutputImageType; - typedef itk::CastImageFilter FilterType; - typename FilterType::Pointer filter = FilterType::New(); - filter->SetInput(input); - filter->Update(); + this->SetNextOutput(input); - // Write - SetNextOutput(filter->GetOutput()); - //clitk::writeImage(filter->GetOutput(), mOutputFilename, m_IOVerbose); + } else { + // "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); + } } //==================================================================== -// Vector specializations (RP: do we need so many?) - -#define VEC_UPDATE_IMPL(TYPE_IN, COMP, DIM, TYPE_OUT) \ - template<> \ - void clitk::ImageConvertGenericFilter::UpdateWithOutputType, DIM>, TYPE_OUT>() \ - { \ - UpdateWithOutputVectorType, DIM>, TYPE_OUT>(); \ - } - -VEC_UPDATE_IMPL(char, 2, 2, unsigned char); -VEC_UPDATE_IMPL(char, 2, 3, unsigned char); -VEC_UPDATE_IMPL(char, 2, 4, unsigned char); -VEC_UPDATE_IMPL(char, 2, 2, char); -VEC_UPDATE_IMPL(char, 2, 3, char); -VEC_UPDATE_IMPL(char, 2, 4, char); -VEC_UPDATE_IMPL(char, 2, 2, unsigned short); -VEC_UPDATE_IMPL(char, 2, 3, unsigned short); -VEC_UPDATE_IMPL(char, 2, 4, unsigned short); -VEC_UPDATE_IMPL(char, 2, 2, short); -VEC_UPDATE_IMPL(char, 2, 3, short); -VEC_UPDATE_IMPL(char, 2, 4, short); -VEC_UPDATE_IMPL(char, 2, 2, int); -VEC_UPDATE_IMPL(char, 2, 3, int); -VEC_UPDATE_IMPL(char, 2, 4, int); -VEC_UPDATE_IMPL(char, 2, 2, float); -VEC_UPDATE_IMPL(char, 2, 3, float); -VEC_UPDATE_IMPL(char, 2, 4, float); -VEC_UPDATE_IMPL(char, 2, 2, double); -VEC_UPDATE_IMPL(char, 2, 3, double); -VEC_UPDATE_IMPL(char, 2, 4, double); - -VEC_UPDATE_IMPL(char, 3, 2, unsigned char); -VEC_UPDATE_IMPL(char, 3, 3, unsigned char); -VEC_UPDATE_IMPL(char, 3, 4, unsigned char); -VEC_UPDATE_IMPL(char, 3, 2, char); -VEC_UPDATE_IMPL(char, 3, 3, char); -VEC_UPDATE_IMPL(char, 3, 4, char); -VEC_UPDATE_IMPL(char, 3, 2, unsigned short); -VEC_UPDATE_IMPL(char, 3, 3, unsigned short); -VEC_UPDATE_IMPL(char, 3, 4, unsigned short); -VEC_UPDATE_IMPL(char, 3, 2, short); -VEC_UPDATE_IMPL(char, 3, 3, short); -VEC_UPDATE_IMPL(char, 3, 4, short); -VEC_UPDATE_IMPL(char, 3, 2, int); -VEC_UPDATE_IMPL(char, 3, 3, int); -VEC_UPDATE_IMPL(char, 3, 4, int); -VEC_UPDATE_IMPL(char, 3, 2, float); -VEC_UPDATE_IMPL(char, 3, 3, float); -VEC_UPDATE_IMPL(char, 3, 4, float); -VEC_UPDATE_IMPL(char, 3, 2, double); -VEC_UPDATE_IMPL(char, 3, 3, double); -VEC_UPDATE_IMPL(char, 3, 4, double); - -VEC_UPDATE_IMPL(unsigned char, 2, 2, unsigned char); -VEC_UPDATE_IMPL(unsigned char, 2, 3, unsigned char); -VEC_UPDATE_IMPL(unsigned char, 2, 4, unsigned char); -VEC_UPDATE_IMPL(unsigned char, 2, 2, char); -VEC_UPDATE_IMPL(unsigned char, 2, 3, char); -VEC_UPDATE_IMPL(unsigned char, 2, 4, char); -VEC_UPDATE_IMPL(unsigned char, 2, 2, unsigned short); -VEC_UPDATE_IMPL(unsigned char, 2, 3, unsigned short); -VEC_UPDATE_IMPL(unsigned char, 2, 4, unsigned short); -VEC_UPDATE_IMPL(unsigned char, 2, 2, short); -VEC_UPDATE_IMPL(unsigned char, 2, 3, short); -VEC_UPDATE_IMPL(unsigned char, 2, 4, short); -VEC_UPDATE_IMPL(unsigned char, 2, 2, int); -VEC_UPDATE_IMPL(unsigned char, 2, 3, int); -VEC_UPDATE_IMPL(unsigned char, 2, 4, int); -VEC_UPDATE_IMPL(unsigned char, 2, 2, float); -VEC_UPDATE_IMPL(unsigned char, 2, 3, float); -VEC_UPDATE_IMPL(unsigned char, 2, 4, float); -VEC_UPDATE_IMPL(unsigned char, 2, 2, double); -VEC_UPDATE_IMPL(unsigned char, 2, 3, double); -VEC_UPDATE_IMPL(unsigned char, 2, 4, double); - -VEC_UPDATE_IMPL(unsigned char, 3, 2, unsigned char); -VEC_UPDATE_IMPL(unsigned char, 3, 3, unsigned char); -VEC_UPDATE_IMPL(unsigned char, 3, 4, unsigned char); -VEC_UPDATE_IMPL(unsigned char, 3, 2, char); -VEC_UPDATE_IMPL(unsigned char, 3, 3, char); -VEC_UPDATE_IMPL(unsigned char, 3, 4, char); -VEC_UPDATE_IMPL(unsigned char, 3, 2, unsigned short); -VEC_UPDATE_IMPL(unsigned char, 3, 3, unsigned short); -VEC_UPDATE_IMPL(unsigned char, 3, 4, unsigned short); -VEC_UPDATE_IMPL(unsigned char, 3, 2, short); -VEC_UPDATE_IMPL(unsigned char, 3, 3, short); -VEC_UPDATE_IMPL(unsigned char, 3, 4, short); -VEC_UPDATE_IMPL(unsigned char, 3, 2, int); -VEC_UPDATE_IMPL(unsigned char, 3, 3, int); -VEC_UPDATE_IMPL(unsigned char, 3, 4, int); -VEC_UPDATE_IMPL(unsigned char, 3, 2, float); -VEC_UPDATE_IMPL(unsigned char, 3, 3, float); -VEC_UPDATE_IMPL(unsigned char, 3, 4, float); -VEC_UPDATE_IMPL(unsigned char, 3, 2, double); -VEC_UPDATE_IMPL(unsigned char, 3, 3, double); -VEC_UPDATE_IMPL(unsigned char, 3, 4, double); - -VEC_UPDATE_IMPL(short, 2, 2, unsigned char); -VEC_UPDATE_IMPL(short, 2, 3, unsigned char); -VEC_UPDATE_IMPL(short, 2, 4, unsigned char); -VEC_UPDATE_IMPL(short, 2, 2, char); -VEC_UPDATE_IMPL(short, 2, 3, char); -VEC_UPDATE_IMPL(short, 2, 4, char); -VEC_UPDATE_IMPL(short, 2, 2, unsigned short); -VEC_UPDATE_IMPL(short, 2, 3, unsigned short); -VEC_UPDATE_IMPL(short, 2, 4, unsigned short); -VEC_UPDATE_IMPL(short, 2, 2, short); -VEC_UPDATE_IMPL(short, 2, 3, short); -VEC_UPDATE_IMPL(short, 2, 4, short); -VEC_UPDATE_IMPL(short, 2, 2, int); -VEC_UPDATE_IMPL(short, 2, 3, int); -VEC_UPDATE_IMPL(short, 2, 4, int); -VEC_UPDATE_IMPL(short, 2, 2, float); -VEC_UPDATE_IMPL(short, 2, 3, float); -VEC_UPDATE_IMPL(short, 2, 4, float); -VEC_UPDATE_IMPL(short, 2, 2, double); -VEC_UPDATE_IMPL(short, 2, 3, double); -VEC_UPDATE_IMPL(short, 2, 4, double); - -VEC_UPDATE_IMPL(short, 3, 2, unsigned char); -VEC_UPDATE_IMPL(short, 3, 3, unsigned char); -VEC_UPDATE_IMPL(short, 3, 4, unsigned char); -VEC_UPDATE_IMPL(short, 3, 2, char); -VEC_UPDATE_IMPL(short, 3, 3, char); -VEC_UPDATE_IMPL(short, 3, 4, char); -VEC_UPDATE_IMPL(short, 3, 2, unsigned short); -VEC_UPDATE_IMPL(short, 3, 3, unsigned short); -VEC_UPDATE_IMPL(short, 3, 4, unsigned short); -VEC_UPDATE_IMPL(short, 3, 2, short); -VEC_UPDATE_IMPL(short, 3, 3, short); -VEC_UPDATE_IMPL(short, 3, 4, short); -VEC_UPDATE_IMPL(short, 3, 2, int); -VEC_UPDATE_IMPL(short, 3, 3, int); -VEC_UPDATE_IMPL(short, 3, 4, int); -VEC_UPDATE_IMPL(short, 3, 2, float); -VEC_UPDATE_IMPL(short, 3, 3, float); -VEC_UPDATE_IMPL(short, 3, 4, float); -VEC_UPDATE_IMPL(short, 3, 2, double); -VEC_UPDATE_IMPL(short, 3, 3, double); -VEC_UPDATE_IMPL(short, 3, 4, double); - -VEC_UPDATE_IMPL(unsigned short, 2, 2, unsigned char); -VEC_UPDATE_IMPL(unsigned short, 2, 3, unsigned char); -VEC_UPDATE_IMPL(unsigned short, 2, 4, unsigned char); -VEC_UPDATE_IMPL(unsigned short, 2, 2, char); -VEC_UPDATE_IMPL(unsigned short, 2, 3, char); -VEC_UPDATE_IMPL(unsigned short, 2, 4, char); -VEC_UPDATE_IMPL(unsigned short, 2, 2, unsigned short); -VEC_UPDATE_IMPL(unsigned short, 2, 3, unsigned short); -VEC_UPDATE_IMPL(unsigned short, 2, 4, unsigned short); -VEC_UPDATE_IMPL(unsigned short, 2, 2, short); -VEC_UPDATE_IMPL(unsigned short, 2, 3, short); -VEC_UPDATE_IMPL(unsigned short, 2, 4, short); -VEC_UPDATE_IMPL(unsigned short, 2, 2, int); -VEC_UPDATE_IMPL(unsigned short, 2, 3, int); -VEC_UPDATE_IMPL(unsigned short, 2, 4, int); -VEC_UPDATE_IMPL(unsigned short, 2, 2, float); -VEC_UPDATE_IMPL(unsigned short, 2, 3, float); -VEC_UPDATE_IMPL(unsigned short, 2, 4, float); -VEC_UPDATE_IMPL(unsigned short, 2, 2, double); -VEC_UPDATE_IMPL(unsigned short, 2, 3, double); -VEC_UPDATE_IMPL(unsigned short, 2, 4, double); - -VEC_UPDATE_IMPL(unsigned short, 3, 2, unsigned char); -VEC_UPDATE_IMPL(unsigned short, 3, 3, unsigned char); -VEC_UPDATE_IMPL(unsigned short, 3, 4, unsigned char); -VEC_UPDATE_IMPL(unsigned short, 3, 2, char); -VEC_UPDATE_IMPL(unsigned short, 3, 3, char); -VEC_UPDATE_IMPL(unsigned short, 3, 4, char); -VEC_UPDATE_IMPL(unsigned short, 3, 2, unsigned short); -VEC_UPDATE_IMPL(unsigned short, 3, 3, unsigned short); -VEC_UPDATE_IMPL(unsigned short, 3, 4, unsigned short); -VEC_UPDATE_IMPL(unsigned short, 3, 2, short); -VEC_UPDATE_IMPL(unsigned short, 3, 3, short); -VEC_UPDATE_IMPL(unsigned short, 3, 4, short); -VEC_UPDATE_IMPL(unsigned short, 3, 2, int); -VEC_UPDATE_IMPL(unsigned short, 3, 3, int); -VEC_UPDATE_IMPL(unsigned short, 3, 4, int); -VEC_UPDATE_IMPL(unsigned short, 3, 2, float); -VEC_UPDATE_IMPL(unsigned short, 3, 3, float); -VEC_UPDATE_IMPL(unsigned short, 3, 4, float); -VEC_UPDATE_IMPL(unsigned short, 3, 2, double); -VEC_UPDATE_IMPL(unsigned short, 3, 3, double); -VEC_UPDATE_IMPL(unsigned short, 3, 4, double); - -VEC_UPDATE_IMPL(int, 2, 2, unsigned char); -VEC_UPDATE_IMPL(int, 2, 3, unsigned char); -VEC_UPDATE_IMPL(int, 2, 4, unsigned char); -VEC_UPDATE_IMPL(int, 2, 2, char); -VEC_UPDATE_IMPL(int, 2, 3, char); -VEC_UPDATE_IMPL(int, 2, 4, char); -VEC_UPDATE_IMPL(int, 2, 2, unsigned short); -VEC_UPDATE_IMPL(int, 2, 3, unsigned short); -VEC_UPDATE_IMPL(int, 2, 4, unsigned short); -VEC_UPDATE_IMPL(int, 2, 2, short); -VEC_UPDATE_IMPL(int, 2, 3, short); -VEC_UPDATE_IMPL(int, 2, 4, short); -VEC_UPDATE_IMPL(int, 2, 2, int); -VEC_UPDATE_IMPL(int, 2, 3, int); -VEC_UPDATE_IMPL(int, 2, 4, int); -VEC_UPDATE_IMPL(int, 2, 2, float); -VEC_UPDATE_IMPL(int, 2, 3, float); -VEC_UPDATE_IMPL(int, 2, 4, float); -VEC_UPDATE_IMPL(int, 2, 2, double); -VEC_UPDATE_IMPL(int, 2, 3, double); -VEC_UPDATE_IMPL(int, 2, 4, double); - -VEC_UPDATE_IMPL(int, 3, 2, unsigned char); -VEC_UPDATE_IMPL(int, 3, 3, unsigned char); -VEC_UPDATE_IMPL(int, 3, 4, unsigned char); -VEC_UPDATE_IMPL(int, 3, 2, char); -VEC_UPDATE_IMPL(int, 3, 3, char); -VEC_UPDATE_IMPL(int, 3, 4, char); -VEC_UPDATE_IMPL(int, 3, 2, unsigned short); -VEC_UPDATE_IMPL(int, 3, 3, unsigned short); -VEC_UPDATE_IMPL(int, 3, 4, unsigned short); -VEC_UPDATE_IMPL(int, 3, 2, short); -VEC_UPDATE_IMPL(int, 3, 3, short); -VEC_UPDATE_IMPL(int, 3, 4, short); -VEC_UPDATE_IMPL(int, 3, 2, int); -VEC_UPDATE_IMPL(int, 3, 3, int); -VEC_UPDATE_IMPL(int, 3, 4, int); -VEC_UPDATE_IMPL(int, 3, 2, float); -VEC_UPDATE_IMPL(int, 3, 3, float); -VEC_UPDATE_IMPL(int, 3, 4, float); -VEC_UPDATE_IMPL(int, 3, 2, double); -VEC_UPDATE_IMPL(int, 3, 3, double); -VEC_UPDATE_IMPL(int, 3, 4, double); - -VEC_UPDATE_IMPL(float, 2, 2, unsigned char); -VEC_UPDATE_IMPL(float, 2, 3, unsigned char); -VEC_UPDATE_IMPL(float, 2, 4, unsigned char); -VEC_UPDATE_IMPL(float, 2, 2, char); -VEC_UPDATE_IMPL(float, 2, 3, char); -VEC_UPDATE_IMPL(float, 2, 4, char); -VEC_UPDATE_IMPL(float, 2, 2, unsigned short); -VEC_UPDATE_IMPL(float, 2, 3, unsigned short); -VEC_UPDATE_IMPL(float, 2, 4, unsigned short); -VEC_UPDATE_IMPL(float, 2, 2, short); -VEC_UPDATE_IMPL(float, 2, 3, short); -VEC_UPDATE_IMPL(float, 2, 4, short); -VEC_UPDATE_IMPL(float, 2, 2, int); -VEC_UPDATE_IMPL(float, 2, 3, int); -VEC_UPDATE_IMPL(float, 2, 4, int); -VEC_UPDATE_IMPL(float, 2, 2, float); -VEC_UPDATE_IMPL(float, 2, 3, float); -VEC_UPDATE_IMPL(float, 2, 4, float); -VEC_UPDATE_IMPL(float, 2, 2, double); -VEC_UPDATE_IMPL(float, 2, 3, double); -VEC_UPDATE_IMPL(float, 2, 4, double); - -VEC_UPDATE_IMPL(float, 3, 2, unsigned char); -VEC_UPDATE_IMPL(float, 3, 3, unsigned char); -VEC_UPDATE_IMPL(float, 3, 4, unsigned char); -VEC_UPDATE_IMPL(float, 3, 2, char); -VEC_UPDATE_IMPL(float, 3, 3, char); -VEC_UPDATE_IMPL(float, 3, 4, char); -VEC_UPDATE_IMPL(float, 3, 2, unsigned short); -VEC_UPDATE_IMPL(float, 3, 3, unsigned short); -VEC_UPDATE_IMPL(float, 3, 4, unsigned short); -VEC_UPDATE_IMPL(float, 3, 2, short); -VEC_UPDATE_IMPL(float, 3, 3, short); -VEC_UPDATE_IMPL(float, 3, 4, short); -VEC_UPDATE_IMPL(float, 3, 2, int); -VEC_UPDATE_IMPL(float, 3, 3, int); -VEC_UPDATE_IMPL(float, 3, 4, int); -VEC_UPDATE_IMPL(float, 3, 2, float); -VEC_UPDATE_IMPL(float, 3, 3, float); -VEC_UPDATE_IMPL(float, 3, 4, float); -VEC_UPDATE_IMPL(float, 3, 2, double); -VEC_UPDATE_IMPL(float, 3, 3, double); -VEC_UPDATE_IMPL(float, 3, 4, double); - - -VEC_UPDATE_IMPL(double, 2, 2, unsigned char); -VEC_UPDATE_IMPL(double, 2, 3, unsigned char); -VEC_UPDATE_IMPL(double, 2, 4, unsigned char); -VEC_UPDATE_IMPL(double, 2, 2, char); -VEC_UPDATE_IMPL(double, 2, 3, char); -VEC_UPDATE_IMPL(double, 2, 4, char); -VEC_UPDATE_IMPL(double, 2, 2, unsigned short); -VEC_UPDATE_IMPL(double, 2, 3, unsigned short); -VEC_UPDATE_IMPL(double, 2, 4, unsigned short); -VEC_UPDATE_IMPL(double, 2, 2, short); -VEC_UPDATE_IMPL(double, 2, 3, short); -VEC_UPDATE_IMPL(double, 2, 4, short); -VEC_UPDATE_IMPL(double, 2, 2, int); -VEC_UPDATE_IMPL(double, 2, 3, int); -VEC_UPDATE_IMPL(double, 2, 4, int); -VEC_UPDATE_IMPL(double, 2, 2, float); -VEC_UPDATE_IMPL(double, 2, 3, float); -VEC_UPDATE_IMPL(double, 2, 4, float); -VEC_UPDATE_IMPL(double, 2, 2, double); -VEC_UPDATE_IMPL(double, 2, 3, double); -VEC_UPDATE_IMPL(double, 2, 4, double); - -VEC_UPDATE_IMPL(double, 3, 2, unsigned char); -VEC_UPDATE_IMPL(double, 3, 3, unsigned char); -VEC_UPDATE_IMPL(double, 3, 4, unsigned char); -VEC_UPDATE_IMPL(double, 3, 2, char); -VEC_UPDATE_IMPL(double, 3, 3, char); -VEC_UPDATE_IMPL(double, 3, 4, char); -VEC_UPDATE_IMPL(double, 3, 2, unsigned short); -VEC_UPDATE_IMPL(double, 3, 3, unsigned short); -VEC_UPDATE_IMPL(double, 3, 4, unsigned short); -VEC_UPDATE_IMPL(double, 3, 2, short); -VEC_UPDATE_IMPL(double, 3, 3, short); -VEC_UPDATE_IMPL(double, 3, 4, short); -VEC_UPDATE_IMPL(double, 3, 2, int); -VEC_UPDATE_IMPL(double, 3, 3, int); -VEC_UPDATE_IMPL(double, 3, 4, int); -VEC_UPDATE_IMPL(double, 3, 2, float); -VEC_UPDATE_IMPL(double, 3, 3, float); -VEC_UPDATE_IMPL(double, 3, 4, float); -VEC_UPDATE_IMPL(double, 3, 2, double); -VEC_UPDATE_IMPL(double, 3, 3, double); -VEC_UPDATE_IMPL(double, 3, 4, double); //==================================================================== -//==================================================================== -template -void clitk::ImageConvertGenericFilter::UpdateWithOutputVectorType() +template +void clitk::ImageConvertGenericFilter::CheckTypes( + std::string inType, std::string outType +) { - // Read - typename InputImageType::Pointer input =this->template GetInput(0); - - // Typedef - typedef typename InputImageType::PixelType::ValueType PixelType; - - // Warning 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, InputImageType::ImageDimension> OutputImageType; - typedef itk::VectorCastImageFilter 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 */ +#endif /* end #define CLITKIMAGECONVERTGENERICFILTER_CXX */