]> Creatis software - clitk.git/blobdiff - tools/clitkInvertVFGenericFilter.txx
With ITKv5, change VectorResample and VectorCast Image Filter to Resample and Cast...
[clitk.git] / tools / clitkInvertVFGenericFilter.txx
index 2ddd46c5b4d6cc51422efd9fb17e5f6d97a4a0a7..93ad21f9aca5c3862c5ec905bb70d5cbf9c97a1f 100644 (file)
 #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<args_info_type>::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,22 +135,42 @@ InvertVFGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
     // Create the InvertVFFilter
     typedef clitk::InvertVFFilter<InputImageType,OutputImageType> FilterType;
     typename FilterType::Pointer filter =FilterType::New();
-    filter->SetInput(input);
-    typename FilterType::SpacingType spacing = input->GetSpacing();
-    typename FilterType::SizeType size = input->GetLargestPossibleRegion().GetSize();
     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; i<InputImageType::ImageDimension; i++) {
         size[i] = header->GetDimensions(i);
         spacing[i] = header->GetSpacing(i);
       }
+
+#if ( ITK_VERSION_MAJOR < 5 )
+      typedef itk::VectorResampleImageFilter<InputImageType, OutputImageType> ResampleFilterType;
+#else
+      typedef itk::ResampleImageFilter<InputImageType, OutputImageType> 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());
     }
-    std::cout << spacing << size << std::endl;
-    filter->SetOutputSpacing(spacing);
-    filter->SetOutputSize(size);
+    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()) )
@@ -160,12 +187,45 @@ InvertVFGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
   }
 
   case 1: {
-    // Create the InverseDeformationFieldFilter
-#if ITK_VERSION_MAJOR >= 4
-    typedef itk::InverseDisplacementFieldImageFilter<InputImageType,OutputImageType> FilterType;
+    // Create the InvertVFFilter
+    typedef clitk::InvertVFFilter<InputImageType,OutputImageType> FilterType;
+    typename FilterType::Pointer filter =FilterType::New();
+    if (m_ArgsInfo.like_given) {
+      typedef ConvertBLUTCoeffsToVFFilter<InputImageType> 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
-    typedef itk::InverseDeformationFieldImageFilter<InputImageType,OutputImageType> FilterType;
+      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; i<Dimension; i++)
+          pad[i]=m_ArgsInfo.pad_arg[i];
+    }
+    filter->SetThreadSafe(m_ArgsInfo.threadSafe_flag);
+    filter->Update();
+    output=filter->GetOutput();
+
+    break;
+  }
+
+  case 2: {
+    // Create the InverseDeformationFieldFilter
+    typedef itk::InverseDisplacementFieldImageFilter<InputImageType,OutputImageType> FilterType;
     typename FilterType::Pointer filter =FilterType::New();
     filter->SetInput(input);
     filter->SetOutputOrigin(input->GetOrigin());
@@ -178,6 +238,7 @@ InvertVFGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
     break;
   }
 
+    
   }
 
   // Output