]> Creatis software - clitk.git/blobdiff - tools/clitkWarpImageGenericFilter.txx
With ITKv5, change VectorResample and VectorCast Image Filter to Resample and Cast...
[clitk.git] / tools / clitkWarpImageGenericFilter.txx
index 2ecc5d5dc0eabf20fc3a23c9f99974e1099fbf95..c3f58b37d225dc41181009664831ea7f1f093808 100644 (file)
  *
  ===================================================*/
 
+#if ( ITK_VERSION_MAJOR < 5 )
+#include "itkVectorResampleImageFilter.h"
+#else
+#include "itkResampleImageFilter.h"
+#endif
+#include "clitkConvertBLUTCoeffsToVFFilter.h"
 
 namespace clitk
 {
@@ -78,21 +84,32 @@ WarpImageGenericFilter::UpdateWithDimAndPixelType()
   typedef itk::Image<PixelType, Dimension> OutputImageType;
   typedef itk::Vector<float, Dimension> DisplacementType;
   typedef itk::Image<DisplacementType, Dimension> DeformationFieldType;
-
-
+  
   // Read the input
   typedef itk::ImageFileReader<InputImageType> 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<DeformationFieldType> 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<DeformationFieldType> 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<DeformationFieldType> DeformationFieldReaderType;
+    typename  DeformationFieldReaderType::Pointer deformationFieldReader= DeformationFieldReaderType::New();
+    deformationFieldReader->SetFileName(m_ArgsInfo.vf_arg);
+    deformationFieldReader->Update();
+    deformationField =deformationFieldReader->GetOutput();
+  }
 
   // Intensity interpolator
   typedef clitk::GenericVectorInterpolator<args_info_clitkWarpImage, DeformationFieldType, double> GenericInterpolatorType;
@@ -115,10 +132,16 @@ WarpImageGenericFilter::UpdateWithDimAndPixelType()
     genericInterpolator->SetArgsInfo(m_ArgsInfo);
 
     // Resample to match the extent of the input
+#if ( ITK_VERSION_MAJOR < 5 )
     typename itk::VectorResampleImageFilter<DeformationFieldType, DeformationFieldType >::Pointer
     resampler =itk::VectorResampleImageFilter<DeformationFieldType, DeformationFieldType >::New();
+#else
+    typename itk::ResampleImageFilter<DeformationFieldType, DeformationFieldType >::Pointer
+    resampler =itk::ResampleImageFilter<DeformationFieldType, DeformationFieldType >::New();
+#endif
     resampler->SetInput(deformationField);
     resampler->SetOutputSpacing(deformationField->GetSpacing());
+    resampler->SetOutputDirection(deformationField->GetDirection());
     resampler->SetSize(newSize);
     resampler->SetOutputOrigin(input->GetOrigin());
     resampler->SetInterpolator(genericInterpolator->GetInterpolatorPointer());
@@ -139,17 +162,23 @@ WarpImageGenericFilter::UpdateWithDimAndPixelType()
   // -------------------------------------------
   // Spacing like input
   // -------------------------------------------
-  else {
+  else if (!m_ArgsInfo.coeff_given) {
     // Get size
     typename DeformationFieldType::SizeType newSize;
     for (unsigned int i=0 ; i <Dimension; i++)
       newSize[i]=input->GetLargestPossibleRegion().GetSize()[i];
 
     // Resample to match the extent of the input
+#if ( ITK_VERSION_MAJOR < 5 )
     typename itk::VectorResampleImageFilter<DeformationFieldType, DeformationFieldType >::Pointer
     resampler =itk::VectorResampleImageFilter<DeformationFieldType, DeformationFieldType >::New();
+#else
+    typename itk::ResampleImageFilter<DeformationFieldType, DeformationFieldType >::Pointer
+    resampler =itk::ResampleImageFilter<DeformationFieldType, DeformationFieldType >::New();
+#endif
     resampler->SetInput(deformationField);
     resampler->SetOutputSpacing(input->GetSpacing());
+    resampler->SetOutputDirection(deformationField->GetDirection());
     resampler->SetSize(newSize);
     resampler->SetOutputOrigin(input->GetOrigin());
     resampler->SetInterpolator(genericInterpolator->GetInterpolatorPointer());
@@ -192,13 +221,19 @@ WarpImageGenericFilter::UpdateWithDimAndPixelType()
     //Backward mapping
     typedef itk::WarpImageFilter<InputImageType, InputImageType, DeformationFieldType> BackwardWarpFilterType;
     typename BackwardWarpFilterType::Pointer backwardWarpFilter= BackwardWarpFilterType::New();
-    backwardWarpFilter->SetDeformationField( deformationField );
+    backwardWarpFilter->SetDisplacementField( deformationField );
     backwardWarpFilter->SetEdgePaddingValue( static_cast<PixelType>(m_ArgsInfo.pad_arg) );
     backwardWarpFilter->SetOutputSpacing( deformationField->GetSpacing() );
     backwardWarpFilter->SetOutputOrigin( input->GetOrigin() );
     backwardWarpFilter->SetOutputSize( deformationField->GetLargestPossibleRegion().GetSize() );
+    backwardWarpFilter->SetOutputDirection( input->GetDirection() );
+#if ( ITK_VERSION_MAJOR < 5 )
     typename itk::VectorResampleImageFilter<DeformationFieldType, DeformationFieldType >::Pointer
     resampler =itk::VectorResampleImageFilter<DeformationFieldType, DeformationFieldType >::New();
+#else
+    typename itk::ResampleImageFilter<DeformationFieldType, DeformationFieldType >::Pointer
+    resampler =itk::ResampleImageFilter<DeformationFieldType, DeformationFieldType >::New();
+#endif
     backwardWarpFilter->SetInterpolator(genericInterpolator->GetInterpolatorPointer());
     warpFilter=backwardWarpFilter;
   }