--- /dev/null
+/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.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
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
+
+ It is distributed under dual licence
+
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+#ifndef clitkCoeffsToDVF_h
+#define clitkCoeffsToDVF_h
+
+#include "clitkBSplineDeformableTransform.h"
+#if ITK_VERSION_MAJOR >= 4
+#include "itkTransformToDisplacementFieldSource.h"
+#else
+#include "itkTransformToDeformationFieldSource.h"
+#endif
+
+//-------------------------------------------------------------------
+// Convert Coefficient image to DVF
+//-------------------------------------------------------------------
+template<class DisplacementFieldType>
+typename DisplacementFieldType::Pointer
+CoeffsToDVF(std::string fileName, std::string likeFileName, bool verbose = false)
+{
+ typedef clitk::BSplineDeformableTransform<double, DisplacementFieldType::ImageDimension, DisplacementFieldType::ImageDimension> TransformType;
+ typedef typename TransformType::CoefficientImageType CoefficientImageType;
+
+ typedef itk::ImageFileReader<CoefficientImageType> 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<DisplacementFieldType, double> ConvertorType;
+#else
+ typedef itk::TransformToDeformationFieldSource<DisplacementFieldType, double> 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 (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();
+}
+
+#endif
//Templated members
template<unsigned int Dimension> void UpdateWithDim(std::string PixelType);
template<unsigned int Dimension, class PixelType> void UpdateWithDimAndPixelType();
- template<class DisplacementFieldType> typename DisplacementFieldType::Pointer CoeffsToDVF(std::string fileName, std::string likeFileName);
std::string m_InputName1;
std::string m_InputName2;
#define __clitkComposeVFGenericFilter_txx
#include "clitkComposeVFGenericFilter.h"
-#include "clitkBSplineDeformableTransform.h"
-#include "clitkBSplineDeformableTransformInitializer.h"
-#if ITK_VERSION_MAJOR >= 4
-#include "itkTransformToDisplacementFieldSource.h"
-#else
-#include "itkTransformToDeformationFieldSource.h"
-#endif
+#include "clitkCoeffsToDVF.h"
namespace clitk
{
}
}
- template<class DisplacementFieldType>
- typename DisplacementFieldType::Pointer ComposeVFGenericFilter::CoeffsToDVF(std::string fileName, std::string likeFileName)
- {
- typedef clitk::BSplineDeformableTransform<double, DisplacementFieldType::ImageDimension, DisplacementFieldType::ImageDimension> TransformType;
- typedef typename TransformType::CoefficientImageType CoefficientImageType;
-
- typedef itk::ImageFileReader<CoefficientImageType> 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<DisplacementFieldType, double> ConvertorType;
-#else
- typedef itk::TransformToDeformationFieldSource<DisplacementFieldType, double> 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();
- }
template<unsigned int Dimension, class PixelType>
void ComposeVFGenericFilter::UpdateWithDimAndPixelType()
//Define the image type
if (m_Type == 1) {
- input1 = this->CoeffsToDVF<ImageType>(m_InputName1, m_LikeImage);
- input2 = this->CoeffsToDVF<ImageType>(m_InputName2, m_LikeImage);
+ input1 = CoeffsToDVF<ImageType>(m_InputName1, m_LikeImage, m_Verbose);
+ input2 = CoeffsToDVF<ImageType>(m_InputName2, m_LikeImage, m_Verbose);
}
else {
//Read the input1
//----------------------------------------
template <unsigned int Dimension> void UpdateWithDim(std::string PixelType);
template <unsigned int Dimension, class PixelType> void UpdateWithDimAndPixelType();
- template<class DisplacementFieldType> typename DisplacementFieldType::Pointer CoeffsToDVF(std::string fileName, std::string likeFileName);
//----------------------------------------
#define clitkInvertVFGenericFilter_txx
#include "itkVectorResampleImageFilter.h"
-#include "clitkBSplineDeformableTransform.h"
-#if ITK_VERSION_MAJOR >= 4
-#include "itkTransformToDisplacementFieldSource.h"
-#else
-#include "itkTransformToDeformationFieldSource.h"
-#endif
+#include "clitkCoeffsToDVF.h"
/* =================================================
* @file clitkInvertVFGenericFilter.txx
// }
}
-//-------------------------------------------------------------------
-// Convert Coefficient image to DVF
-//-------------------------------------------------------------------
-template<class args_info_type>
-template<class DisplacementFieldType>
-typename DisplacementFieldType::Pointer
-InvertVFGenericFilter<args_info_type>::CoeffsToDVF(std::string fileName, std::string likeFileName)
-{
- typedef clitk::BSplineDeformableTransform<double, DisplacementFieldType::ImageDimension, DisplacementFieldType::ImageDimension> TransformType;
- typedef typename TransformType::CoefficientImageType CoefficientImageType;
-
- typedef itk::ImageFileReader<CoefficientImageType> 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<DisplacementFieldType, double> ConvertorType;
-#else
- typedef itk::TransformToDeformationFieldSource<DisplacementFieldType, double> 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
//----------------------------------------
template <unsigned int Dimension> void UpdateWithDim(std::string PixelType);
template <unsigned int Dimension, class PixelType> void UpdateWithDimAndPixelType();
- template<class DisplacementFieldType> typename DisplacementFieldType::Pointer CoeffsToDVF(std::string fileName, std::string likeFileName);
//----------------------------------------
// Data members
===================================================*/
#include "itkVectorResampleImageFilter.h"
-#include "clitkBSplineDeformableTransform.h"
-#if ITK_VERSION_MAJOR >= 4
-#include "itkTransformToDisplacementFieldSource.h"
-#else
-#include "itkTransformToDeformationFieldSource.h"
-#endif
+#include "clitkCoeffsToDVF.h"
namespace clitk
{
}
}
-//-------------------------------------------------------------------
-// Convert Coefficient image to DVF
-//-------------------------------------------------------------------
-template<class DisplacementFieldType>
-typename DisplacementFieldType::Pointer
-WarpImageGenericFilter::CoeffsToDVF(std::string fileName, std::string likeFileName)
-{
- typedef clitk::BSplineDeformableTransform<double, DisplacementFieldType::ImageDimension, DisplacementFieldType::ImageDimension> TransformType;
- typedef typename TransformType::CoefficientImageType CoefficientImageType;
-
- typedef itk::ImageFileReader<CoefficientImageType> 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<DisplacementFieldType, double> ConvertorType;
-#else
- typedef itk::TransformToDeformationFieldSource<DisplacementFieldType, double> 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
typename DeformationFieldType::Pointer deformationField;
if (m_ArgsInfo.coeff_given) {
- deformationField = CoeffsToDVF<DeformationFieldType>(m_ArgsInfo.coeff_arg, m_InputFileName);
+ deformationField = CoeffsToDVF<DeformationFieldType>(m_ArgsInfo.coeff_arg, m_InputFileName, m_Verbose);
}
else {
//Read the deformation field