X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=filters%2FclitkVFResampleGenericFilter.txx;h=5efd0eccc5e89feadba0b843645c3ef7d5129e6e;hb=4934205c18b17f41c1879acbfd70ca2f3b260175;hp=98f3c0640c62a879d228071dda515cdf7fb2936d;hpb=931a42358442f4ee4f314613c991c838d4b4e3b7;p=clitk.git diff --git a/filters/clitkVFResampleGenericFilter.txx b/filters/clitkVFResampleGenericFilter.txx index 98f3c06..5efd0ec 100644 --- a/filters/clitkVFResampleGenericFilter.txx +++ b/filters/clitkVFResampleGenericFilter.txx @@ -1,172 +1,34 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + 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 + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +======================================================================-====*/ #ifndef CLITKVFRESAMPLEGENERICFILTER_TXX #define CLITKVFRESAMPLEGENERICFILTER_TXX - /** ------------------------------------------------= * @file clitkVFResampleGenericFilter.txx * @author David Sarrut * @date 23 Feb 2008 08:40:11 - * - * @brief - * - * + * + * @brief + * + * ------------------------------------------------=*/ //-------------------------------------------------------------------- -template -void VFResampleGenericFilter::Update_WithDim() { -#define TRY_TYPE(TYPE) \ - if (IsSameType(mPixelTypeName)) { Update_WithDimAndPixelType(); return; } - TRY_TYPE(float); -#undef TRY_TYPE - std::string list = CreateListOfTypes(); - std::cerr << "Error, I don't know the type '" << mPixelTypeName << "' for the input image '" - << mInputFilenames[0] << "'." << std::endl << "Known types are " << list << std::endl; - exit(0); -} -//-------------------------------------------------------------------- - -//-------------------------------------------------------------------- -template -void VFResampleGenericFilter::Update_WithDimAndPixelType() { - - if (mNbOfComponents == 1) { - std::cerr << "Error, only one components ? Use clitkImageResample instead." << std::endl; - exit(0); - } - if (mNbOfComponents == 2) Update_WithDimAndPixelTypeAndComponent(); - if (mNbOfComponents == 3) Update_WithDimAndPixelTypeAndComponent(); - if (mNbOfComponents == 4) Update_WithDimAndPixelTypeAndComponent(); -} -//-------------------------------------------------------------------- - -//-------------------------------------------------------------------- -template -void VFResampleGenericFilter::Update_WithDimAndPixelTypeAndComponent() { - // Reading input - typedef itk::Vector DisplacementType; - typedef itk::Image< DisplacementType, Dim > ImageType; - - typename ImageType::Pointer input = clitk::readImage(mInputFilenames, mIOVerbose); - - // Main filter - typename ImageType::Pointer outputImage = ComputeImage(input); - - // Write results - SetNextOutput(outputImage); -} -//-------------------------------------------------------------------- - -//-------------------------------------------------------------------- -template -typename ImageType::Pointer -VFResampleGenericFilter::ComputeImage(typename ImageType::Pointer inputImage) { - - // Check options - static unsigned int dim = ImageType::ImageDimension; - if (mOutputSize.size() != dim) { - std::cerr << "Please set size with " << dim << " dimensions." << std::endl; - return NULL; - } - if (mOutputSpacing.size() != dim) { - std::cerr << "Please set spacing with " << dim << " dimensions." << std::endl; - return NULL; - } - mOutputOrigin.resize(dim); - - if (mApplyGaussianFilterBefore && mSigma.size() != dim) { - std::cerr << "Please set sigma with " << dim << " dimensions." << std::endl; - return NULL; - } - - // Some typedefs - typedef typename ImageType::SizeType SizeType; - typedef typename ImageType::SpacingType SpacingType; - typedef typename ImageType::PointType PointType; - - // Create Image Filter - typedef itk::VectorResampleImageFilter 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; - typename TransformType::Pointer transform = TransformType::New(); - filter->SetTransform(transform); - - // Set filter's parameters - SizeType outputSize; - SpacingType outputSpacing; - PointType outputOrigin; - for(unsigned int i=0; iGetOrigin()[i]; - } - - filter->SetSize(outputSize); - filter->SetOutputSpacing(outputSpacing); - filter->SetOutputOrigin(outputOrigin); - filter->SetDefaultPixelValue(static_cast(mDefaultPixelValue)); - - // Select interpolator - if (mInterpolatorName == "nn") { - typedef itk::VectorNearestNeighborInterpolateImageFunction InterpolatorType; - typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); - filter->SetInterpolator(interpolator); - } - else { - if (mInterpolatorName == "linear") { - typedef itk::VectorLinearInterpolateImageFunction InterpolatorType; - typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); - filter->SetInterpolator(interpolator); - } - else { - std::cerr << "Sorry, I do not know the interpolator (for vector field) '" << mInterpolatorName - << "'. Known interpolators are : nn, linear" << std::endl; - exit(0); - } - } - - // Build initial Gaussian bluring (if needed) - typedef itk::RecursiveGaussianImageFilter GaussianFilterType; - std::vector gaussianFilters; - if (mApplyGaussianFilterBefore) { - for(unsigned int i=0; iSetDirection(i); - gaussianFilters[i]->SetOrder(GaussianFilterType::ZeroOrder); - gaussianFilters[i]->SetNormalizeAcrossScale(false); - gaussianFilters[i]->SetSigma(mSigma[i]); // in millimeter ! - // Set input - if (i==0) gaussianFilters[i]->SetInput(inputImage); - else gaussianFilters[i]->SetInput(gaussianFilters[i-1]->GetOutput()); - } - filter->SetInput(gaussianFilters[ImageType::ImageDimension-1]->GetOutput()); - } - else { - filter->SetInput(inputImage); - } - - // Go ! - try { - filter->Update(); - } - catch( itk::ExceptionObject & err ) { - std::cerr << "Error while filtering " << mInputFilenames[0].c_str() - << " " << err << std::endl; - exit(0); - } - - // Return result - return filter->GetOutput(); - -} -//-------------------------------------------------------------------- - - #endif /* end #define CLITKVFRESAMPLEGENERICFILTER_TXX */