Commit 8fc4cd1e authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: cleanup and added InternalComputationValueType as template parameter

of itkMeanSquaredDifferenceMetricComponent
parent cd259328
......@@ -31,7 +31,7 @@ template< int Dimensionality, class TPixel >
class ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component :
public SuperElastixComponent<
Accepting< >,
Providing< itkMetricv4Interface< Dimensionality, TPixel >>
Providing< itkMetricv4Interface< Dimensionality, TPixel, double >>
>
{
public:
......
......@@ -33,14 +33,14 @@
namespace selx
{
template< int Dimensionality, class TPixel, class InternalComputationValueType>
template< int Dimensionality, class PixelType, class InternalComputationValueType>
class ItkImageRegistrationMethodv4Component :
public SuperElastixComponent<
Accepting< itkImageFixedInterface< Dimensionality, TPixel >,
itkImageMovingInterface< Dimensionality, TPixel >,
Accepting< itkImageFixedInterface< Dimensionality, PixelType >,
itkImageMovingInterface< Dimensionality, PixelType >,
itkTransformInterface< InternalComputationValueType, Dimensionality >,
itkTransformParametersAdaptorsContainerInterface< InternalComputationValueType, Dimensionality >,
itkMetricv4Interface< Dimensionality, TPixel >,
itkMetricv4Interface< Dimensionality, PixelType, InternalComputationValueType >,
itkOptimizerv4Interface< InternalComputationValueType >
>,
Providing< itkTransformInterface< InternalComputationValueType, Dimensionality >,
......@@ -57,38 +57,32 @@ public:
ItkImageRegistrationMethodv4Component();
virtual ~ItkImageRegistrationMethodv4Component();
typedef TPixel PixelType;
using TransformInternalComputationValueType = InternalComputationValueType;
// Get the type definitions from the interfaces
typedef typename itkOptimizerv4Interface< TransformInternalComputationValueType >::InternalComputationValueType
OptimizerInternalComputationValueType; //should be from class template
typedef typename itkImageFixedInterface< Dimensionality, TPixel >::ItkImageType FixedImageType;
typedef typename itkImageMovingInterface< Dimensionality, TPixel >::ItkImageType MovingImageType;
typedef typename itkTransformInterface< TransformInternalComputationValueType, Dimensionality >::TransformType TransformType;
typedef typename itkTransformInterface< TransformInternalComputationValueType, Dimensionality >::TransformPointer TransformPointer;
using FixedImageType = typename itkImageFixedInterface< Dimensionality, PixelType >::ItkImageType;
using MovingImageType = typename itkImageMovingInterface< Dimensionality, PixelType >::ItkImageType;
using TransformType = typename itkTransformInterface< InternalComputationValueType, Dimensionality >::TransformType;
using TransformPointer = typename itkTransformInterface< InternalComputationValueType, Dimensionality >::TransformPointer;
using TransformParametersAdaptorsContainerInterfaceType
= itkTransformParametersAdaptorsContainerInterface< TransformInternalComputationValueType, Dimensionality >;
= itkTransformParametersAdaptorsContainerInterface< InternalComputationValueType, Dimensionality >;
typedef itk::ImageRegistrationMethodv4< FixedImageType, MovingImageType > TheItkFilterType;
typedef itk::ImageRegistrationMethodv4< FixedImageType, MovingImageType, TransformType > TheItkFilterType;
typedef typename TheItkFilterType::ImageMetricType ImageMetricType;
typedef itk::RegistrationParameterScalesFromPhysicalShift< ImageMetricType > ScalesEstimatorType;
//Accepting Interfaces:
virtual int Set( itkImageFixedInterface< Dimensionality, TPixel > * ) override;
virtual int Set(itkImageFixedInterface< Dimensionality, PixelType > *) override;
virtual int Set( itkImageMovingInterface< Dimensionality, TPixel > * ) override;
virtual int Set(itkImageMovingInterface< Dimensionality, PixelType > *) override;
virtual int Set( itkTransformInterface< TransformInternalComputationValueType, Dimensionality > * ) override;
virtual int Set( itkTransformInterface< InternalComputationValueType, Dimensionality > * ) override;
virtual int Set( TransformParametersAdaptorsContainerInterfaceType * ) override;
virtual int Set( itkMetricv4Interface< Dimensionality, TPixel > * ) override;
virtual int Set(itkMetricv4Interface< Dimensionality, PixelType, InternalComputationValueType > *) override;
virtual int Set( itkOptimizerv4Interface< OptimizerInternalComputationValueType > * ) override;
virtual int Set( itkOptimizerv4Interface< InternalComputationValueType > * ) override;
//Providing Interfaces:
virtual TransformPointer GetItkTransform() override;
......@@ -115,7 +109,7 @@ protected:
// return the class name and the template arguments to uniquely identify this component.
static inline const std::map<std::string, std::string> TemplateProperties()
{
return{ { keys::NameOfClass, "ItkImageRegistrationMethodv4Component" }, { keys::PixelType, PodString<TPixel>::Get() },{ keys::InternalComputationValueType, PodString<InternalComputationValueType>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
return{ { keys::NameOfClass, "ItkImageRegistrationMethodv4Component" }, { keys::PixelType, PodString<PixelType>::Get() }, { keys::InternalComputationValueType, PodString<InternalComputationValueType>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
}
};
......
......@@ -61,8 +61,10 @@ public:
typename TFilter::ShrinkFactorsPerDimensionContainerType shrinkFactors = filter->GetShrinkFactorsPerDimension( currentLevel );
typename TFilter::SmoothingSigmasArrayType smoothingSigmas = filter->GetSmoothingSigmasPerLevel();
typename TFilter::TransformParametersAdaptorsContainerType adaptors = filter->GetTransformParametersAdaptorsPerLevel();
const itk::ObjectToObjectOptimizerBase * optimizerBase = filter->GetOptimizer();
// TODO optimizer is can be ObjectToObjectOptimizerBaseTemplate<double> or ObjectToObjectOptimizerBaseTemplate<float>
// dynamic cast will fail on <float>, since GradientDescentOptimizerv4Type is by default <double>
auto * optimizerBase = filter->GetOptimizer();
typedef itk::GradientDescentOptimizerv4 GradientDescentOptimizerv4Type;
typename GradientDescentOptimizerv4Type::ConstPointer optimizer = dynamic_cast< const GradientDescentOptimizerv4Type * >( optimizerBase );
if( !optimizer )
......@@ -159,7 +161,7 @@ ItkImageRegistrationMethodv4Component< Dimensionality, TPixel, InternalComputati
template< int Dimensionality, class TPixel, class InternalComputationValueType >
int
ItkImageRegistrationMethodv4Component< Dimensionality, TPixel, InternalComputationValueType >::Set( itkTransformInterface< TransformInternalComputationValueType,
ItkImageRegistrationMethodv4Component< Dimensionality, TPixel, InternalComputationValueType >::Set( itkTransformInterface< InternalComputationValueType,
Dimensionality > * component )
{
this->m_theItkFilter->SetInitialTransform( component->GetItkTransform() );
......@@ -180,7 +182,7 @@ ItkImageRegistrationMethodv4Component< Dimensionality, TPixel, InternalComputati
template< int Dimensionality, class TPixel, class InternalComputationValueType >
int
ItkImageRegistrationMethodv4Component< Dimensionality, TPixel, InternalComputationValueType >::Set( itkMetricv4Interface< Dimensionality, TPixel > * component )
ItkImageRegistrationMethodv4Component< Dimensionality, TPixel, InternalComputationValueType >::Set(itkMetricv4Interface< Dimensionality, TPixel, InternalComputationValueType > * component)
{
//TODO: The optimizer must be set explicitly, since this is a work-around for a bug in itkRegistrationMethodv4.
//TODO: report bug to itk: when setting a metric, the optimizer must be set explicitly as well, since default optimizer setup breaks.
......@@ -192,7 +194,7 @@ ItkImageRegistrationMethodv4Component< Dimensionality, TPixel, InternalComputati
template< int Dimensionality, class TPixel, class InternalComputationValueType >
int
ItkImageRegistrationMethodv4Component< Dimensionality, TPixel, InternalComputationValueType >::Set( itkOptimizerv4Interface< OptimizerInternalComputationValueType > * component )
ItkImageRegistrationMethodv4Component< Dimensionality, TPixel, InternalComputationValueType >::Set(itkOptimizerv4Interface< InternalComputationValueType > * component)
{
//TODO: The optimizer must be set explicitly, since this is a work-around for a bug in itkRegistrationMethodv4.
//TODO: report bug to itk: when setting a metric, the optimizer must be set explicitly as well, since default optimizer setup breaks.
......@@ -214,7 +216,8 @@ ItkImageRegistrationMethodv4Component< Dimensionality, TPixel, InternalComputati
ImageMetricType * theMetric = dynamic_cast< ImageMetricType * >( this->m_theItkFilter->GetModifiableMetric() );
auto optimizer = dynamic_cast< itk::GradientDescentOptimizerv4 * >( this->m_theItkFilter->GetModifiableOptimizer() );
//auto optimizer = dynamic_cast< itk::GradientDescentOptimizerv4 * >( this->m_theItkFilter->GetModifiableOptimizer() );
auto optimizer = this->m_theItkFilter->GetModifiableOptimizer();
//auto optimizer = dynamic_cast<itk::ObjectToObjectOptimizerBaseTemplate< InternalComputationValueType > *>(this->m_theItkFilter->GetModifiableOptimizer());
auto transform = this->m_theItkFilter->GetModifiableTransform();
......@@ -232,12 +235,12 @@ ItkImageRegistrationMethodv4Component< Dimensionality, TPixel, InternalComputati
scalesEstimator->SetTransformForward( true );
scalesEstimator->SetSmallParameterVariation( 1.0 );
optimizer->SetScalesEstimator( ITK_NULLPTR );
//optimizer->SetScalesEstimator( ITK_NULLPTR );
//optimizer->SetScalesEstimator(scalesEstimator);
optimizer->SetDoEstimateLearningRateOnce( false ); //true by default
optimizer->SetDoEstimateLearningRateAtEachIteration( false );
//optimizer->SetDoEstimateLearningRateOnce( false ); //true by default
//optimizer->SetDoEstimateLearningRateAtEachIteration( false );
this->m_theItkFilter->SetOptimizer( optimizer );
//this->m_theItkFilter->SetOptimizer( optimizer );
if( this->m_TransformAdaptorsContainerInterface != nullptr )
{
......@@ -369,7 +372,7 @@ ItkImageRegistrationMethodv4Component< Dimensionality, TPixel, InternalComputati
}
}
itk::Array< TransformInternalComputationValueType > smoothingSigmasPerLevel;
itk::Array< InternalComputationValueType > smoothingSigmasPerLevel;
smoothingSigmasPerLevel.SetSize( impliedNumberOfResolutions );
......
......@@ -27,11 +27,11 @@
#include "selxMacro.h"
namespace selx
{
template< int Dimensionality, class TPixel >
template< int Dimensionality, class TPixel, class InternalComputationValueType >
class ItkMeanSquaresImageToImageMetricv4Component :
public SuperElastixComponent<
Accepting< >,
Providing< itkMetricv4Interface< Dimensionality, TPixel >>
Providing< itkMetricv4Interface< Dimensionality, TPixel, InternalComputationValueType >>
>
{
public:
......@@ -48,11 +48,12 @@ public:
// fixed and moving image types are all the same, these aliases can be used to be explicit.
typedef itk::Image< PixelType, Dimensionality > FixedImageType;
typedef itk::Image< PixelType, Dimensionality > MovingImageType;
using VirtualImageType = FixedImageType;
typedef typename itk::ImageToImageMetricv4< FixedImageType, MovingImageType > ImageToImageMetricv4Type;
typedef typename ImageToImageMetricv4Type::Pointer ItkMetricv4Pointer;
typedef typename itk::MeanSquaresImageToImageMetricv4< FixedImageType, MovingImageType > TheItkFilterType;
typedef typename itk::MeanSquaresImageToImageMetricv4< FixedImageType, MovingImageType, VirtualImageType, InternalComputationValueType > TheItkFilterType;
virtual ItkMetricv4Pointer GetItkMetricv4() override;
......@@ -70,7 +71,7 @@ protected:
// return the class name and the template arguments to uniquely identify this component.
static inline const std::map<std::string, std::string> TemplateProperties()
{
return{ { keys::NameOfClass, "ItkMeanSquaresImageToImageMetricv4Component" }, { keys::PixelType, PodString<TPixel>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
return{ { keys::NameOfClass, "ItkMeanSquaresImageToImageMetricv4Component" }, { keys::PixelType, PodString<TPixel>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) }, { keys::InternalComputationValueType, PodString<InternalComputationValueType>::Get() } };
}
};
......
......@@ -22,8 +22,8 @@
namespace selx
{
template< int Dimensionality, class TPixel >
ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel >::ItkMeanSquaresImageToImageMetricv4Component()
template< int Dimensionality, class TPixel, class InternalComputationValueType >
ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel, InternalComputationValueType >::ItkMeanSquaresImageToImageMetricv4Component()
{
m_theItkFilter = TheItkFilterType::New();
......@@ -32,23 +32,23 @@ ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel >::ItkMeanSq
}
template< int Dimensionality, class TPixel >
ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel >::~ItkMeanSquaresImageToImageMetricv4Component()
template< int Dimensionality, class TPixel, class InternalComputationValueType >
ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel, InternalComputationValueType >::~ItkMeanSquaresImageToImageMetricv4Component()
{
}
template< int Dimensionality, class TPixel >
typename ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel >::ItkMetricv4Pointer
ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel >::GetItkMetricv4()
template< int Dimensionality, class TPixel, class InternalComputationValueType >
typename ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel, InternalComputationValueType >::ItkMetricv4Pointer
ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel, InternalComputationValueType >::GetItkMetricv4()
{
return (ItkMetricv4Pointer)this->m_theItkFilter;
}
template< int Dimensionality, class TPixel >
template< int Dimensionality, class TPixel, class InternalComputationValueType >
bool
ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel >
ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel, InternalComputationValueType >
::MeetsCriterion( const ComponentBase::CriterionType & criterion )
{
bool hasUndefinedCriteria( false );
......
......@@ -90,9 +90,9 @@ public:
ItkImageRegistrationMethodv4Component< 3, double, double >,
ItkImageRegistrationMethodv4Component< 2, float, double >,
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 3, double >,
ItkMeanSquaresImageToImageMetricv4Component< 3, double >,
ItkMeanSquaresImageToImageMetricv4Component< 3, double, double >,
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 2, float >,
ItkMeanSquaresImageToImageMetricv4Component< 2, float >,
ItkMeanSquaresImageToImageMetricv4Component< 2, float,double >,
ItkGradientDescentOptimizerv4Component< double >,
ItkAffineTransformComponent< double, 3 >,
ItkGaussianExponentialDiffeomorphicTransformComponent< double, 3 >,
......
......@@ -72,7 +72,7 @@ public:
MonolithicTransformixComponent< 2, float >,
ItkImageRegistrationMethodv4Component< 2, float, double >,
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 2, float >,
ItkMeanSquaresImageToImageMetricv4Component< 2, float >,
ItkMeanSquaresImageToImageMetricv4Component< 2, float, double >,
ItkGradientDescentOptimizerv4Component< double >,
ItkGaussianExponentialDiffeomorphicTransformComponent< double, 2 >,
ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent< 2, double >,
......
......@@ -40,7 +40,7 @@ class ItkSyNImageRegistrationMethodComponent :
public SuperElastixComponent<
Accepting< itkImageFixedInterface< Dimensionality, TPixel >,
itkImageMovingInterface< Dimensionality, TPixel >,
itkMetricv4Interface< Dimensionality, TPixel >
itkMetricv4Interface< Dimensionality, TPixel, double >
>,
Providing< itkTransformInterface< double, Dimensionality >,
RunRegistrationInterface
......@@ -75,7 +75,7 @@ public:
virtual int Set( itkImageMovingInterface< Dimensionality, TPixel > * ) override;
virtual int Set( itkMetricv4Interface< Dimensionality, TPixel > * ) override;
virtual int Set(itkMetricv4Interface< Dimensionality, TPixel, double > *) override;
//Providing Interfaces:
virtual TransformPointer GetItkTransform() override;
......
......@@ -70,7 +70,7 @@ ItkSyNImageRegistrationMethodComponent< Dimensionality, TPixel >
template< int Dimensionality, class TPixel >
int
ItkSyNImageRegistrationMethodComponent< Dimensionality, TPixel >::Set( itkMetricv4Interface< Dimensionality, TPixel > * component )
ItkSyNImageRegistrationMethodComponent< Dimensionality, TPixel >::Set(itkMetricv4Interface< Dimensionality, TPixel, double > * component)
{
this->m_theItkFilter->SetMetric( component->GetItkMetricv4() );
......
......@@ -89,9 +89,9 @@ public:
ItkSyNImageRegistrationMethodComponent< 3, double >,
ItkSyNImageRegistrationMethodComponent< 2, float >,
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 3, double >,
ItkMeanSquaresImageToImageMetricv4Component< 3, double >,
ItkMeanSquaresImageToImageMetricv4Component< 3, double, double>,
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 2, float >,
ItkMeanSquaresImageToImageMetricv4Component< 2, float >,
ItkMeanSquaresImageToImageMetricv4Component< 2, float, double >,
ItkAffineTransformComponent< double, 3 >,
ItkGaussianExponentialDiffeomorphicTransformComponent< double, 3 >,
ItkTransformDisplacementFilterComponent< 2, float, double >,
......
......@@ -168,12 +168,12 @@ struct Properties< SinkInterface >
}
};
template< int D, class TPixel >
struct Properties< itkMetricv4Interface< D, TPixel >>
template< int D, class TPixel, class InternalComputationValueType >
struct Properties< itkMetricv4Interface< D, TPixel, InternalComputationValueType >>
{
static const std::map<std::string, std::string> Get()
{
return{ { keys::NameOfInterface, "itkMetricv4Interface" }, { keys::Dimensionality, std::to_string(D) }, { keys::PixelType, PodString<TPixel>::Get() } };
return{ { keys::NameOfInterface, "itkMetricv4Interface" }, { keys::Dimensionality, std::to_string(D) }, { keys::PixelType, PodString<TPixel>::Get() }, { keys::InternalComputationValueType, PodString<InternalComputationValueType>::Get() } };
}
};
......
......@@ -224,14 +224,15 @@ public:
virtual void ReconnectTransform() = 0;
};
template< int Dimensionality, class TPixel >
template< int Dimensionality, class TPixel, class InternalComputationValueType >
class itkMetricv4Interface
{
public:
typedef typename itk::Image< TPixel, Dimensionality > FixedImageType;
typedef typename itk::Image< TPixel, Dimensionality > MovingImageType;
typedef typename itk::ImageToImageMetricv4< FixedImageType, MovingImageType > ImageToImageMetricv4Type;
using FixedImageType = itk::Image< TPixel, Dimensionality >;
using MovingImageType = FixedImageType;
using VirtualImageType = FixedImageType;
typedef typename itk::ImageToImageMetricv4< FixedImageType, MovingImageType, VirtualImageType, InternalComputationValueType > ImageToImageMetricv4Type;
virtual typename ImageToImageMetricv4Type::Pointer GetItkMetricv4() = 0;
};
......
......@@ -124,9 +124,9 @@ TEST_F(OverlordTest, DeduceComponentsFromConnections)
ItkImageRegistrationMethodv4Component< 3, double, double>,
ItkImageRegistrationMethodv4Component< 3, float, double >,
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 3, double >,
ItkMeanSquaresImageToImageMetricv4Component< 3, double >,
ItkMeanSquaresImageToImageMetricv4Component< 3, double, double >,
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 3, float >,
ItkMeanSquaresImageToImageMetricv4Component< 3, float >,
ItkMeanSquaresImageToImageMetricv4Component< 3, float, double >,
ItkAffineTransformComponent< double, 3 >,
ItkGaussianExponentialDiffeomorphicTransformComponent< double, 3 >,
ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent< 3, double >,
......
......@@ -51,7 +51,7 @@ using DefaultComponents = selx::TypeList<
MonolithicTransformixComponent< 2, float >,
ItkImageRegistrationMethodv4Component< 2, float, double>,
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 2, float >,
ItkMeanSquaresImageToImageMetricv4Component< 2, float >,
ItkMeanSquaresImageToImageMetricv4Component< 2, float, double >,
ItkGradientDescentOptimizerv4Component< double >,
ItkGaussianExponentialDiffeomorphicTransformComponent< double, 2 >,
ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent< 2, double >,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment