From 998ca9ca987553dc71578e5584e881f6bd537d91 Mon Sep 17 00:00:00 2001 From: tbaudier Date: Thu, 10 Oct 2019 09:15:00 +0200 Subject: [PATCH] With ITKv5, change VectorResample and VectorCast Image Filter to Resample and Cast Image Filter I did not success to modify clitk::VectorBSplineInterpolateImageFunction according to this commit --- registration/clitkGenericVectorInterpolator.h | 9 +++++++++ .../clitkGenericVectorInterpolator.txx | 12 ++++++++++-- tools/clitkAffineTransformGenericFilter.h | 2 ++ tools/clitkAffineTransformGenericFilter.txx | 4 ++++ tools/clitkImageConvertGenericFilter.h | 6 ++++++ tools/clitkInvertVFGenericFilter.txx | 8 ++++++++ tools/clitkVFResampleGenericFilter.cxx | 12 ++++++++++++ tools/clitkVFResampleGenericFilter.h | 8 +++++++- tools/clitkWarpImageGenericFilter.h | 4 ++++ tools/clitkWarpImageGenericFilter.txx | 19 +++++++++++++++++++ vv/vvMidPosition.cxx | 9 +++++++++ 11 files changed, 90 insertions(+), 3 deletions(-) diff --git a/registration/clitkGenericVectorInterpolator.h b/registration/clitkGenericVectorInterpolator.h index 73bfa96..e6aa766 100644 --- a/registration/clitkGenericVectorInterpolator.h +++ b/registration/clitkGenericVectorInterpolator.h @@ -20,8 +20,13 @@ #include "clitkImageCommon.h" //itk include +#if ( ITK_VERSION_MAJOR < 5 ) #include "itkVectorNearestNeighborInterpolateImageFunction.h" #include "itkVectorLinearInterpolateImageFunction.h" +#else +#include "itkNearestNeighborInterpolateImageFunction.h" +#include "itkLinearInterpolateImageFunction.h" +#endif #include "clitkVectorBSplineInterpolateImageFunction.h" #include "clitkVectorBSplineInterpolateImageFunctionWithLUT.h" @@ -56,7 +61,11 @@ namespace clitk typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; +#if ( ITK_VERSION_MAJOR < 5 ) typedef itk::VectorInterpolateImageFunction InterpolatorType; +#else + typedef itk::InterpolateImageFunction InterpolatorType; +#endif typedef typename InterpolatorType::Pointer InterpolatorPointer; /** Method for creation through the object factory. */ diff --git a/registration/clitkGenericVectorInterpolator.txx b/registration/clitkGenericVectorInterpolator.txx index 001399d..cd9c0f7 100644 --- a/registration/clitkGenericVectorInterpolator.txx +++ b/registration/clitkGenericVectorInterpolator.txx @@ -48,17 +48,25 @@ namespace clitk { case 0: +#if ( ITK_VERSION_MAJOR < 5 ) interpolator= itk::VectorNearestNeighborInterpolateImageFunction< ImageType,TCoordRep >::New(); +#else + interpolator= itk::NearestNeighborInterpolateImageFunction< ImageType,TCoordRep >::New(); +#endif if (m_Verbose) std::cout<<"Using nearestneighbor interpolation..."<::New(); +#else + interpolator = itk::LinearInterpolateImageFunction< ImageType,TCoordRep >::New(); +#endif if (m_Verbose) std::cout<<"Using linear interpolation..."<::Pointer m =clitk::VectorBSplineInterpolateImageFunction< ImageType,TCoordRep >::New(); m->SetSplineOrder(m_ArgsInfo.interpVFOrder_arg); @@ -76,7 +84,7 @@ namespace clitk if (m_Verbose) std::cout<<"Using BLUT interpolation..."< ResampleFilterType; +#else + typedef itk::ResampleImageFilter< InputImageType,OutputImageType, double > ResampleFilterType; +#endif typename ResampleFilterType::Pointer resampler = ResampleFilterType::New(); // Matrix diff --git a/tools/clitkImageConvertGenericFilter.h b/tools/clitkImageConvertGenericFilter.h index 4f1a100..a317473 100644 --- a/tools/clitkImageConvertGenericFilter.h +++ b/tools/clitkImageConvertGenericFilter.h @@ -32,7 +32,9 @@ // itk include #include "itkCastImageFilter.h" +#if ( ITK_VERSION_MAJOR < 5 ) #include "itkVectorCastImageFilter.h" +#endif namespace clitk { @@ -208,7 +210,11 @@ namespace clitk { // Cast typedef itk::Image, InputImageType::ImageDimension> OutputImageType; +#if ( ITK_VERSION_MAJOR < 5 ) typedef itk::VectorCastImageFilter FilterType; +#else + typedef itk::CastImageFilter FilterType; +#endif typename FilterType::Pointer cast_filter = FilterType::New(); cast_filter->SetInput(input); cast_filter->Update(); diff --git a/tools/clitkInvertVFGenericFilter.txx b/tools/clitkInvertVFGenericFilter.txx index 405540c..93ad21f 100644 --- a/tools/clitkInvertVFGenericFilter.txx +++ b/tools/clitkInvertVFGenericFilter.txx @@ -18,7 +18,11 @@ #ifndef clitkInvertVFGenericFilter_txx #define clitkInvertVFGenericFilter_txx +#if ( ITK_VERSION_MAJOR < 5 ) #include "itkVectorResampleImageFilter.h" +#else +#include "itkResampleImageFilter.h" +#endif #include "clitkConvertBLUTCoeffsToVFFilter.h" /* ================================================= @@ -140,7 +144,11 @@ InvertVFGenericFilter::UpdateWithDimAndPixelType() spacing[i] = header->GetSpacing(i); } +#if ( ITK_VERSION_MAJOR < 5 ) typedef itk::VectorResampleImageFilter ResampleFilterType; +#else + typedef itk::ResampleImageFilter ResampleFilterType; +#endif typename ResampleFilterType::Pointer resampler = ResampleFilterType::New(); resampler->SetInput(input); resampler->SetOutputOrigin(input->GetOrigin()); diff --git a/tools/clitkVFResampleGenericFilter.cxx b/tools/clitkVFResampleGenericFilter.cxx index d287fec..d60b8d0 100644 --- a/tools/clitkVFResampleGenericFilter.cxx +++ b/tools/clitkVFResampleGenericFilter.cxx @@ -111,7 +111,11 @@ clitk::VFResampleGenericFilter::ComputeImage(typename ImageType::Pointer inputIm typedef typename ImageType::PointType PointType; // Create Image Filter +#if ( ITK_VERSION_MAJOR < 5 ) typedef itk::VectorResampleImageFilter FilterType; +#else + typedef itk::ResampleImageFilter FilterType; +#endif typename FilterType::Pointer filter = FilterType::New(); // Instance of the transform object to be passed to the resample @@ -137,12 +141,20 @@ clitk::VFResampleGenericFilter::ComputeImage(typename ImageType::Pointer inputIm // Select interpolator if (mInterpolatorName == "nn") { +#if ( ITK_VERSION_MAJOR < 5 ) typedef itk::VectorNearestNeighborInterpolateImageFunction InterpolatorType; +#else + typedef itk::NearestNeighborInterpolateImageFunction InterpolatorType; +#endif typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); filter->SetInterpolator(interpolator); } else { if (mInterpolatorName == "linear") { +#if ( ITK_VERSION_MAJOR < 5 ) typedef itk::VectorLinearInterpolateImageFunction InterpolatorType; +#else + typedef itk::LinearInterpolateImageFunction InterpolatorType; +#endif typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); filter->SetInterpolator(interpolator); } else { diff --git a/tools/clitkVFResampleGenericFilter.h b/tools/clitkVFResampleGenericFilter.h index b406882..027be39 100644 --- a/tools/clitkVFResampleGenericFilter.h +++ b/tools/clitkVFResampleGenericFilter.h @@ -39,10 +39,16 @@ #include "itkImageSeriesReader.h" #include "itkImageFileWriter.h" #include "itkRecursiveGaussianImageFilter.h" +#if ( ITK_VERSION_MAJOR < 5 ) #include "itkVectorResampleImageFilter.h" -#include "itkAffineTransform.h" #include "itkVectorNearestNeighborInterpolateImageFunction.h" #include "itkVectorLinearInterpolateImageFunction.h" +#else +#include "itkResampleImageFilter.h" +#include "itkNearestNeighborInterpolateImageFunction.h" +#include "itkLinearInterpolateImageFunction.h" +#endif +#include "itkAffineTransform.h" #include "itkBSplineInterpolateImageFunction.h" #include "itkBSplineInterpolateImageFunctionWithLUT.h" #include "itkCommand.h" diff --git a/tools/clitkWarpImageGenericFilter.h b/tools/clitkWarpImageGenericFilter.h index 0ce874d..58da907 100644 --- a/tools/clitkWarpImageGenericFilter.h +++ b/tools/clitkWarpImageGenericFilter.h @@ -39,7 +39,11 @@ //itk include #include "itkLightObject.h" #include "itkWarpImageFilter.h" +#if ( ITK_VERSION_MAJOR < 5 ) #include "itkVectorResampleImageFilter.h" +#else +#include "itkResampleImageFilter.h" +#endif namespace clitk { diff --git a/tools/clitkWarpImageGenericFilter.txx b/tools/clitkWarpImageGenericFilter.txx index 84bfbaa..c3f58b3 100644 --- a/tools/clitkWarpImageGenericFilter.txx +++ b/tools/clitkWarpImageGenericFilter.txx @@ -27,7 +27,11 @@ * ===================================================*/ +#if ( ITK_VERSION_MAJOR < 5 ) #include "itkVectorResampleImageFilter.h" +#else +#include "itkResampleImageFilter.h" +#endif #include "clitkConvertBLUTCoeffsToVFFilter.h" namespace clitk @@ -128,8 +132,13 @@ WarpImageGenericFilter::UpdateWithDimAndPixelType() genericInterpolator->SetArgsInfo(m_ArgsInfo); // Resample to match the extent of the input +#if ( ITK_VERSION_MAJOR < 5 ) typename itk::VectorResampleImageFilter::Pointer resampler =itk::VectorResampleImageFilter::New(); +#else + typename itk::ResampleImageFilter::Pointer + resampler =itk::ResampleImageFilter::New(); +#endif resampler->SetInput(deformationField); resampler->SetOutputSpacing(deformationField->GetSpacing()); resampler->SetOutputDirection(deformationField->GetDirection()); @@ -160,8 +169,13 @@ WarpImageGenericFilter::UpdateWithDimAndPixelType() newSize[i]=input->GetLargestPossibleRegion().GetSize()[i]; // Resample to match the extent of the input +#if ( ITK_VERSION_MAJOR < 5 ) typename itk::VectorResampleImageFilter::Pointer resampler =itk::VectorResampleImageFilter::New(); +#else + typename itk::ResampleImageFilter::Pointer + resampler =itk::ResampleImageFilter::New(); +#endif resampler->SetInput(deformationField); resampler->SetOutputSpacing(input->GetSpacing()); resampler->SetOutputDirection(deformationField->GetDirection()); @@ -213,8 +227,13 @@ WarpImageGenericFilter::UpdateWithDimAndPixelType() backwardWarpFilter->SetOutputOrigin( input->GetOrigin() ); backwardWarpFilter->SetOutputSize( deformationField->GetLargestPossibleRegion().GetSize() ); backwardWarpFilter->SetOutputDirection( input->GetDirection() ); +#if ( ITK_VERSION_MAJOR < 5 ) typename itk::VectorResampleImageFilter::Pointer resampler =itk::VectorResampleImageFilter::New(); +#else + typename itk::ResampleImageFilter::Pointer + resampler =itk::ResampleImageFilter::New(); +#endif backwardWarpFilter->SetInterpolator(genericInterpolator->GetInterpolatorPointer()); warpFilter=backwardWarpFilter; } diff --git a/vv/vvMidPosition.cxx b/vv/vvMidPosition.cxx index d4192d6..ed5880b 100644 --- a/vv/vvMidPosition.cxx +++ b/vv/vvMidPosition.cxx @@ -18,7 +18,11 @@ #include #include +#if ( ITK_VERSION_MAJOR < 5 ) #include +#else +#include +#endif #include "vvMidPosition.h" #include "clitkCommon.h" @@ -95,8 +99,13 @@ vvImage::Pointer WarpRefImage(OutputVFType::Pointer vf,vvImage::Pointer image,in //We resample the VF because itk's warp filter doesn't like it when the vf and the image have //different spacings +#if ( ITK_VERSION_MAJOR < 5 ) typename itk::VectorResampleImageFilter::Pointer resampler =itk::VectorResampleImageFilter::New(); +#else + typename itk::ResampleImageFilter::Pointer + resampler =itk::ResampleImageFilter::New(); +#endif resampler->SetInput(vf); resampler->SetOutputSpacing(input->GetSpacing()); resampler->SetOutputOrigin(vf->GetOrigin()); -- 2.45.0