X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkInvertVFGenericFilter.txx;h=93ad21f9aca5c3862c5ec905bb70d5cbf9c97a1f;hb=998ca9ca987553dc71578e5584e881f6bd537d91;hp=0cf6cb4a154418ae8e98e33d3496b46def7ab00e;hpb=1e034c70105f0926939acaaa27ddb46e904ae8bf;p=clitk.git diff --git a/tools/clitkInvertVFGenericFilter.txx b/tools/clitkInvertVFGenericFilter.txx index 0cf6cb4..93ad21f 100644 --- a/tools/clitkInvertVFGenericFilter.txx +++ b/tools/clitkInvertVFGenericFilter.txx @@ -3,7 +3,7 @@ Authors belong to: - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -14,10 +14,17 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ +===========================================================================**/ #ifndef clitkInvertVFGenericFilter_txx #define clitkInvertVFGenericFilter_txx +#if ( ITK_VERSION_MAJOR < 5 ) +#include "itkVectorResampleImageFilter.h" +#else +#include "itkResampleImageFilter.h" +#endif +#include "clitkConvertBLUTCoeffsToVFFilter.h" + /* ================================================= * @file clitkInvertVFGenericFilter.txx * @author @@ -117,7 +124,7 @@ InvertVFGenericFilter::UpdateWithDimAndPixelType() typename InputReaderType::Pointer reader = InputReaderType::New(); reader->SetFileName( m_InputFileName); reader->Update(); - typename InputImageType::Pointer input= reader->GetOutput(); + typename InputImageType::Pointer input = reader->GetOutput(); // Filter typename OutputImageType::Pointer output; @@ -128,9 +135,42 @@ InvertVFGenericFilter::UpdateWithDimAndPixelType() // Create the InvertVFFilter typedef clitk::InvertVFFilter FilterType; typename FilterType::Pointer filter =FilterType::New(); - filter->SetInput(input); + if (m_ArgsInfo.like_given) { + typename FilterType::SpacingType spacing; + typename FilterType::SizeType size; + itk::ImageIOBase::Pointer header = readImageHeader(m_ArgsInfo.like_arg); + for(unsigned int i=0; iGetDimensions(i); + 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()); + resampler->SetOutputDirection(input->GetDirection()); + resampler->SetOutputSpacing(spacing); + resampler->SetSize(size); + resampler->Update(); + spacing = resampler->GetOutput()->GetSpacing(); + size = resampler->GetOutput()->GetLargestPossibleRegion().GetSize(); + filter->SetInput(resampler->GetOutput()); + } + else + filter->SetInput(input); + filter->SetVerbose(m_Verbose); - if (m_ArgsInfo.threads_given) filter->SetNumberOfThreads(m_ArgsInfo.threads_arg); + if (m_ArgsInfo.threads_given) { +#if ITK_VERSION_MAJOR <= 4 + filter->SetNumberOfThreads(m_ArgsInfo.threads_arg); +#else + filter->SetNumberOfWorkUnits(m_ArgsInfo.threads_arg); +#endif + } if (m_ArgsInfo.pad_given) { PixelType pad; if (m_ArgsInfo.pad_given != (pad.GetNumberOfComponents()) ) @@ -147,8 +187,45 @@ InvertVFGenericFilter::UpdateWithDimAndPixelType() } case 1: { + // Create the InvertVFFilter + typedef clitk::InvertVFFilter FilterType; + typename FilterType::Pointer filter =FilterType::New(); + if (m_ArgsInfo.like_given) { + 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); + if (m_ArgsInfo.threads_given) { +#if ITK_VERSION_MAJOR <= 4 + filter->SetNumberOfThreads(m_ArgsInfo.threads_arg); +#else + filter->SetNumberOfWorkUnits(m_ArgsInfo.threads_arg); +#endif + } + if (m_ArgsInfo.pad_given) { + PixelType pad; + if (m_ArgsInfo.pad_given != (pad.GetNumberOfComponents()) ) + pad.Fill(m_ArgsInfo.pad_arg[0]); + else + for(unsigned int i=0; iSetThreadSafe(m_ArgsInfo.threadSafe_flag); + filter->Update(); + output=filter->GetOutput(); + + break; + } + + case 2: { // Create the InverseDeformationFieldFilter - typedef itk::InverseDeformationFieldImageFilter FilterType; + typedef itk::InverseDisplacementFieldImageFilter FilterType; typename FilterType::Pointer filter =FilterType::New(); filter->SetInput(input); filter->SetOutputOrigin(input->GetOrigin()); @@ -161,6 +238,7 @@ InvertVFGenericFilter::UpdateWithDimAndPixelType() break; } + } // Output