X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=filters%2FclitkImageResampleGenericFilter.cxx;h=aa84b8e4fba1eafcced7237585e9a7a043954e71;hb=1bbbd127f84b5f5949b2cbb82badb9193b3f59e8;hp=3e4e28e19f92c9e9eabff1cb77134b321a25370e;hpb=1d93f10f32528c9ef0002c051c2140f8485b39fb;p=clitk.git diff --git a/filters/clitkImageResampleGenericFilter.cxx b/filters/clitkImageResampleGenericFilter.cxx index 3e4e28e..aa84b8e 100644 --- a/filters/clitkImageResampleGenericFilter.cxx +++ b/filters/clitkImageResampleGenericFilter.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 @@ -23,7 +23,7 @@ * @author David Sarrut * @date 23 Feb 2008 08:37:53 - * @brief + * @brief -------------------------------------------------------------------*/ @@ -38,6 +38,7 @@ #include "itkResampleImageFilter.h" #include "itkAffineTransform.h" #include "itkNearestNeighborInterpolateImageFunction.h" +#include "itkWindowedSincInterpolateImageFunction.h" #include "itkLinearInterpolateImageFunction.h" #include "itkBSplineInterpolateImageFunction.h" #include "itkBSplineInterpolateImageFunctionWithLUT.h" @@ -45,7 +46,8 @@ //-------------------------------------------------------------------- clitk::ImageResampleGenericFilter::ImageResampleGenericFilter(): - ImageToImageGenericFilter("ImageResample") { + ImageToImageGenericFilter("ImageResample") +{ mApplyGaussianFilterBefore = false; mDefaultPixelValue = 0.0; mInterpolatorName = "NN"; @@ -59,7 +61,8 @@ clitk::ImageResampleGenericFilter::ImageResampleGenericFilter(): //-------------------------------------------------------------------- template -void clitk::ImageResampleGenericFilter::InitializeImageTypeWithDim() { +void clitk::ImageResampleGenericFilter::InitializeImageTypeWithDim() +{ ADD_DEFAULT_IMAGE_TYPES(Dim); } //-------------------------------------------------------------------- @@ -67,7 +70,8 @@ void clitk::ImageResampleGenericFilter::InitializeImageTypeWithDim() { //-------------------------------------------------------------------- template -void clitk::ImageResampleGenericFilter::UpdateWithInputImageType() { +void clitk::ImageResampleGenericFilter::UpdateWithInputImageType() +{ // Some typedefs typedef typename InputImageType::SizeType SizeType; @@ -105,7 +109,7 @@ void clitk::ImageResampleGenericFilter::UpdateWithInputImageType() { // Create Image Filter typedef itk::ResampleImageFilter FilterType; typename FilterType::Pointer filter = FilterType::New(); - + // Instance of the transform object to be passed to the resample // filter. By default, identity transform is applied typedef itk::AffineTransform TransformType; @@ -129,36 +133,38 @@ void clitk::ImageResampleGenericFilter::UpdateWithInputImageType() { // Select interpolator if (mInterpolatorName == "nn") { - typedef itk::NearestNeighborInterpolateImageFunction InterpolatorType; + typedef itk::NearestNeighborInterpolateImageFunction InterpolatorType; typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); filter->SetInterpolator(interpolator); - } - else { + } else { if (mInterpolatorName == "linear") { - typedef itk::LinearInterpolateImageFunction InterpolatorType; + typedef itk::LinearInterpolateImageFunction InterpolatorType; typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); filter->SetInterpolator(interpolator); - } - else { - if (mInterpolatorName == "bspline") { - typedef itk::BSplineInterpolateImageFunction InterpolatorType; - typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); - interpolator->SetSplineOrder(mBSplineOrder); - filter->SetInterpolator(interpolator); - } - else { - if (mInterpolatorName == "blut") { - typedef itk::BSplineInterpolateImageFunctionWithLUT InterpolatorType; - typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); - interpolator->SetSplineOrder(mBSplineOrder); - interpolator->SetLUTSamplingFactor(mSamplingFactors[0]); - filter->SetInterpolator(interpolator); - } - else { - std::cerr << "Sorry, I do not know the interpolator '" << mInterpolatorName - << "'. Known interpolators are : nn, linear, bspline, blut" << std::endl; - exit(0); - } + } else { + if (mInterpolatorName == "windowed sinc") { + typedef itk::WindowedSincInterpolateImageFunction InterpolatorType; + typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); + filter->SetInterpolator(interpolator); + } else { + if (mInterpolatorName == "bspline") { + typedef itk::BSplineInterpolateImageFunction InterpolatorType; + typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); + interpolator->SetSplineOrder(mBSplineOrder); + filter->SetInterpolator(interpolator); + } else { + if (mInterpolatorName == "blut") { + typedef itk::BSplineInterpolateImageFunctionWithLUT InterpolatorType; + typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); + interpolator->SetSplineOrder(mBSplineOrder); + interpolator->SetLUTSamplingFactor(mSamplingFactors[0]); + filter->SetInterpolator(interpolator); + } else { + std::cerr << "Sorry, I do not know the interpolator '" << mInterpolatorName + << "'. Known interpolators are : nn, linear, bspline, blut" << std::endl; + exit(0); + } + } } } } @@ -180,23 +186,21 @@ void clitk::ImageResampleGenericFilter::UpdateWithInputImageType() { else gaussianFilters[i]->SetInput(gaussianFilters[i-1]->GetOutput()); } filter->SetInput(gaussianFilters[InputImageType::ImageDimension-1]->GetOutput()); - } - else { + } else { filter->SetInput(input); } // Go ! - try { + try { filter->Update(); - } - catch( itk::ExceptionObject & err ) { - std::cerr << "Error while filtering " << mInputFilenames[0].c_str() - << " " << err << std::endl; + } catch( itk::ExceptionObject & err ) { + std::cerr << "Error while filtering " << mInputFilenames[0].c_str() + << " " << err << std::endl; exit(0); } // Get result - typename InputImageType::Pointer outputImage = filter->GetOutput(); + typename InputImageType::Pointer outputImage = filter->GetOutput(); // Write/save results this->SetNextOutput(outputImage); @@ -206,27 +210,31 @@ void clitk::ImageResampleGenericFilter::UpdateWithInputImageType() { //-------------------------------------------------------------------- -void clitk::ImageResampleGenericFilter::SetOutputSize(const std::vector & size) { +void clitk::ImageResampleGenericFilter::SetOutputSize(const std::vector & size) +{ mOutputSize.resize(size.size()); std::copy(size.begin(), size.end(), mOutputSize.begin()); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -void clitk::ImageResampleGenericFilter::SetOutputSpacing(const std::vector & spacing) { +void clitk::ImageResampleGenericFilter::SetOutputSpacing(const std::vector & spacing) +{ mOutputSpacing.resize(spacing.size()); std::copy(spacing.begin(), spacing.end(), mOutputSpacing.begin()); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -void clitk::ImageResampleGenericFilter::SetInterpolationName(const std::string & inter) { +void clitk::ImageResampleGenericFilter::SetInterpolationName(const std::string & inter) +{ mInterpolatorName = inter; } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -void clitk::ImageResampleGenericFilter::SetGaussianSigma(const std::vector & sigma) { +void clitk::ImageResampleGenericFilter::SetGaussianSigma(const std::vector & sigma) +{ mApplyGaussianFilterBefore = true; mSigma.resize(sigma.size()); std::copy(sigma.begin(), sigma.end(), mSigma.begin());