X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkWarpImageGenericFilter.txx;h=84bfbaaec7148cc5f133180c3b5290ca608eb491;hb=5578995d9a82792833333eeb3dd5c8ecac967293;hp=8544df2ba33bf859c827513c4219ac8e6301a42b;hpb=c4de479fec231c7d53555dcd21d308f06aad17ec;p=clitk.git diff --git a/tools/clitkWarpImageGenericFilter.txx b/tools/clitkWarpImageGenericFilter.txx index 8544df2..84bfbaa 100644 --- a/tools/clitkWarpImageGenericFilter.txx +++ b/tools/clitkWarpImageGenericFilter.txx @@ -27,6 +27,8 @@ * ===================================================*/ +#include "itkVectorResampleImageFilter.h" +#include "clitkConvertBLUTCoeffsToVFFilter.h" namespace clitk { @@ -78,21 +80,32 @@ WarpImageGenericFilter::UpdateWithDimAndPixelType() typedef itk::Image OutputImageType; typedef itk::Vector DisplacementType; typedef itk::Image DeformationFieldType; - - + // Read the input typedef itk::ImageFileReader InputReaderType; typename InputReaderType::Pointer reader = InputReaderType::New(); reader->SetFileName( m_InputFileName); reader->Update(); typename InputImageType::Pointer input= reader->GetOutput(); - - //Read the deformation field - typedef itk::ImageFileReader DeformationFieldReaderType; - typename DeformationFieldReaderType::Pointer deformationFieldReader= DeformationFieldReaderType::New(); - deformationFieldReader->SetFileName(m_ArgsInfo.vf_arg); - deformationFieldReader->Update(); - typename DeformationFieldType::Pointer deformationField =deformationFieldReader->GetOutput(); + + typename DeformationFieldType::Pointer deformationField; + if (m_ArgsInfo.coeff_given) { + typedef ConvertBLUTCoeffsToVFFilter FilterType; + typename FilterType::Pointer filter = FilterType::New(); + filter->SetInputFileName(m_ArgsInfo.coeff_arg); + filter->SetLikeFileName(m_InputFileName); + filter->SetVerbose(m_Verbose); + filter->Update(); + deformationField = filter->GetOutput(); + } + else { + //Read the deformation field + typedef itk::ImageFileReader DeformationFieldReaderType; + typename DeformationFieldReaderType::Pointer deformationFieldReader= DeformationFieldReaderType::New(); + deformationFieldReader->SetFileName(m_ArgsInfo.vf_arg); + deformationFieldReader->Update(); + deformationField =deformationFieldReader->GetOutput(); + } // Intensity interpolator typedef clitk::GenericVectorInterpolator GenericInterpolatorType; @@ -119,6 +132,7 @@ WarpImageGenericFilter::UpdateWithDimAndPixelType() resampler =itk::VectorResampleImageFilter::New(); resampler->SetInput(deformationField); resampler->SetOutputSpacing(deformationField->GetSpacing()); + resampler->SetOutputDirection(deformationField->GetDirection()); resampler->SetSize(newSize); resampler->SetOutputOrigin(input->GetOrigin()); resampler->SetInterpolator(genericInterpolator->GetInterpolatorPointer()); @@ -139,7 +153,7 @@ WarpImageGenericFilter::UpdateWithDimAndPixelType() // ------------------------------------------- // Spacing like input // ------------------------------------------- - else { + else if (!m_ArgsInfo.coeff_given) { // Get size typename DeformationFieldType::SizeType newSize; for (unsigned int i=0 ; i ::New(); resampler->SetInput(deformationField); resampler->SetOutputSpacing(input->GetSpacing()); + resampler->SetOutputDirection(deformationField->GetDirection()); resampler->SetSize(newSize); resampler->SetOutputOrigin(input->GetOrigin()); resampler->SetInterpolator(genericInterpolator->GetInterpolatorPointer()); @@ -192,15 +207,12 @@ WarpImageGenericFilter::UpdateWithDimAndPixelType() //Backward mapping typedef itk::WarpImageFilter BackwardWarpFilterType; typename BackwardWarpFilterType::Pointer backwardWarpFilter= BackwardWarpFilterType::New(); -#if ITK_VERSION_MAJOR >= 4 backwardWarpFilter->SetDisplacementField( deformationField ); -#else - backwardWarpFilter->SetDeformationField( deformationField ); -#endif backwardWarpFilter->SetEdgePaddingValue( static_cast(m_ArgsInfo.pad_arg) ); backwardWarpFilter->SetOutputSpacing( deformationField->GetSpacing() ); backwardWarpFilter->SetOutputOrigin( input->GetOrigin() ); backwardWarpFilter->SetOutputSize( deformationField->GetLargestPossibleRegion().GetSize() ); + backwardWarpFilter->SetOutputDirection( input->GetDirection() ); typename itk::VectorResampleImageFilter::Pointer resampler =itk::VectorResampleImageFilter::New(); backwardWarpFilter->SetInterpolator(genericInterpolator->GetInterpolatorPointer());