X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkInvertVFGenericFilter.txx;h=a18a6417c6b0ad26c3efc14225fba5d1c7444153;hb=9f0023e9ebaf8ca646681282839175d35eea746b;hp=5cd12c4ce202129c38ac67d59d5629fa590b58e1;hpb=0ebe428ddf5c84373c3eb814e9465f048b1e7d48;p=clitk.git diff --git a/tools/clitkInvertVFGenericFilter.txx b/tools/clitkInvertVFGenericFilter.txx index 5cd12c4..a18a641 100644 --- a/tools/clitkInvertVFGenericFilter.txx +++ b/tools/clitkInvertVFGenericFilter.txx @@ -19,12 +19,7 @@ #define clitkInvertVFGenericFilter_txx #include "itkVectorResampleImageFilter.h" -#include "clitkBSplineDeformableTransform.h" -#if ITK_VERSION_MAJOR >= 4 -#include "itkTransformToDisplacementFieldSource.h" -#else -#include "itkTransformToDeformationFieldSource.h" -#endif +#include "clitkConvertBLUTCoeffsToVFFilter.h" /* ================================================= * @file clitkInvertVFGenericFilter.txx @@ -106,65 +101,6 @@ InvertVFGenericFilter::UpdateWithDim(std::string PixelType) // } } -//------------------------------------------------------------------- -// Convert Coefficient image to DVF -//------------------------------------------------------------------- -template -template -typename DisplacementFieldType::Pointer -InvertVFGenericFilter::CoeffsToDVF(std::string fileName, std::string likeFileName) -{ - typedef clitk::BSplineDeformableTransform TransformType; - typedef typename TransformType::CoefficientImageType CoefficientImageType; - - typedef itk::ImageFileReader CoeffReaderType; - typename CoeffReaderType::Pointer reader = CoeffReaderType::New(); - reader->SetFileName(fileName); - reader->Update(); - - typename TransformType::Pointer transform = TransformType::New(); - transform->SetCoefficientImage(reader->GetOutput()); - -#if ITK_VERSION_MAJOR >= 4 - typedef itk::TransformToDisplacementFieldSource ConvertorType; -#else - typedef itk::TransformToDeformationFieldSource ConvertorType; -#endif - - typedef itk::ImageIOBase ImageIOType; - typename ImageIOType::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(likeFileName.c_str(), itk::ImageIOFactory::ReadMode); - imageIO->SetFileName(likeFileName); - imageIO->ReadImageInformation(); - - typename ConvertorType::Pointer convertor= ConvertorType::New(); - typename ConvertorType::SizeType output_size; - typename ConvertorType::SpacingType output_spacing; - typename ConvertorType::OriginType output_origin; - typename ConvertorType::DirectionType output_direction; - for (unsigned int i = 0; i < DisplacementFieldType::ImageDimension; i++) { - output_size[i] = imageIO->GetDimensions(i); - output_spacing[i] = imageIO->GetSpacing(i); - output_origin[i] = imageIO->GetOrigin(i); - for (unsigned int j = 0; j < DisplacementFieldType::ImageDimension; j++) - output_direction[i][j] = imageIO->GetDirection(i)[j]; - } - - if (m_Verbose) { - std::cout << "Interpolating coefficients with grid:" << std::endl; - std::cout << output_size << output_spacing << std::endl; - } - - convertor->SetNumberOfThreads(1); - convertor->SetTransform(transform); - convertor->SetOutputOrigin(output_origin); - convertor->SetOutputSpacing(output_spacing); - convertor->SetOutputSize(output_size); - convertor->SetOutputDirection(output_direction); - convertor->Update(); - - return convertor->GetOutput(); -} - //------------------------------------------------------------------- // Update with the number of dimensions and the pixeltype @@ -241,7 +177,13 @@ InvertVFGenericFilter::UpdateWithDimAndPixelType() typedef clitk::InvertVFFilter FilterType; typename FilterType::Pointer filter =FilterType::New(); if (m_ArgsInfo.like_given) { - filter->SetInput(CoeffsToDVF(m_InputFileName, m_ArgsInfo.like_arg)); + typedef ConvertBLUTCoeffsToVFFilter VFFilterType; + typename VFFilterType::Pointer vf_filter = VFFilterType::New(); + vf_filter->SetInputFileName(m_InputFileName); + vf_filter->SetLikeFileName(m_ArgsInfo.like_arg); + vf_filter->SetVerbose(m_Verbose); + vf_filter->Update(); + filter->SetInput(vf_filter->GetOutput()); } filter->SetVerbose(m_Verbose); @@ -263,11 +205,7 @@ InvertVFGenericFilter::UpdateWithDimAndPixelType() case 2: { // Create the InverseDeformationFieldFilter -#if ITK_VERSION_MAJOR >= 4 typedef itk::InverseDisplacementFieldImageFilter FilterType; -#else - typedef itk::InverseDeformationFieldImageFilter FilterType; -#endif typename FilterType::Pointer filter =FilterType::New(); filter->SetInput(input); filter->SetOutputOrigin(input->GetOrigin());