Commit 180d2a2b authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: refactor more: moved MeetsCriterion checks to free function

CheckTemplateProperties
parent 93fcf859
......@@ -60,7 +60,6 @@ public:
virtual bool MeetsCriterion( const ComponentBase::CriterionType & criterion ) override;
//static const char * GetName() { return "ItkANTSNeighborhoodCorrelationImageToImageMetricv4"; } ;
static const char * GetDescription() { return "ItkANTSNeighborhoodCorrelationImageToImageMetricv4 Component"; }
private:
......@@ -69,113 +68,13 @@ private:
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
static inline const std::string GetTypeNameString()
{
itkGenericExceptionMacro( << "Unknown ScalarType" << typeid( TPixel ).name() );
// TODO: provide the user instructions how to enable the compilation of the component with the required template types (if desired)
// We might define an exception object that can communicate various error messages: for simple user, for developer user, etc
}
static inline const std::string GetPixelTypeNameString()
// return the class name and the template arguments to uniquely identify this component.
static inline const std::map<std::string, std::string> TemplateProperties()
{
itkGenericExceptionMacro( << "Unknown PixelType" << typeid( TPixel ).name() );
// TODO: provide the user instructions how to enable the compilation of the component with the required template types (if desired)
// We might define an exception object that can communicate various error messages: for simple user, for developer user, etc
return{ { keys::NameOfClass, "ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component" }, { keys::PixelType, PodString<TPixel>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
}
};
// unfortunately partial specialization of member functions is not allowed, without partially specializing the entire class.
/*
template <int Dimensionality>
class ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component < Dimensionality, double >
{
static inline const std::string GetPixelTypeNameString();
};
template <int Dimensionality>
inline const std::string
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component<Dimensionality, double>
::GetPixelTypeNameString()
{
return std::string("double");
}
*/
template< >
inline const std::string
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 2, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 2, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 3, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 3, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 2, float >
::GetTypeNameString()
{
return std::string( "2_float" );
}
template< >
inline const std::string
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 2, double >
::GetTypeNameString()
{
return std::string( "2_double" );
}
template< >
inline const std::string
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 3, float >
::GetTypeNameString()
{
return std::string( "3_float" );
}
template< >
inline const std::string
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< 3, double >
::GetTypeNameString()
{
return std::string( "3_double" );
}
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkANTSNeighborhoodCorrelationImageToImageMetricv4.hxx"
......
......@@ -18,6 +18,7 @@
*=========================================================================*/
#include "selxItkANTSNeighborhoodCorrelationImageToImageMetricv4.h"
#include "selxCheckTemplateProperties.h"
namespace selx
{
......@@ -50,46 +51,20 @@ bool
ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< Dimensionality, TPixel >
::MeetsCriterion( const ComponentBase::CriterionType & criterion )
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
auto status = CheckTemplateProperties(this->TemplateProperties(), criterion);
if (status == CriterionStatus::Satisfied)
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
return true;
}
else if( criterion.first == "Dimensionality" ) //Supports this?
else if (status == CriterionStatus::Failed)
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( std::stoi( criterionValue ) != Dimensionality )
{
meetsCriteria = false;
}
}
}
else if( criterion.first == "PixelType" ) //Supports this?
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != Self::GetPixelTypeNameString() )
{
meetsCriteria = false;
}
}
}
return false;
} // else: CriterionStatus::Unknown
else if( criterion.first == "Radius" ) //Supports this?
{
if( criterion.second.size() != 1 )
{
meetsCriteria = false;
return false;
//itkExceptionMacro("The criterion Sigma may have only 1 value");
}
else
......@@ -102,15 +77,15 @@ ItkANTSNeighborhoodCorrelationImageToImageMetricv4Component< Dimensionality, TPi
radius.Fill( std::stod( criterionValue ) );
this->m_theItkFilter->SetRadius( radius );
meetsCriteria = true;
return true;
}
catch( itk::ExceptionObject & err )
{
//TODO log the error message?
meetsCriteria = false;
return false;
}
}
}
return meetsCriteria;
return false;
}
} //end namespace selx
......@@ -64,8 +64,11 @@ private:
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
// 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, "ItkAffineTransformComponent" }, { keys::InternalComputationValueType, PodString<InternalComputationValueType>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
}
};
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
......
......@@ -18,6 +18,7 @@
*=========================================================================*/
#include "selxItkAffineTransform.h"
#include "selxCheckTemplateProperties.h"
namespace selx
{
......@@ -52,28 +53,16 @@ ItkAffineTransformComponent< InternalComputationValueType, Dimensionality >
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
auto status = CheckTemplateProperties(this->TemplateProperties(), criterion);
if (status == CriterionStatus::Satisfied)
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
return true;
}
else if( criterion.first == "Dimensionality" ) //Supports this?
else if (status == CriterionStatus::Failed)
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( std::stoi( criterionValue ) != Dimensionality )
{
meetsCriteria = false;
}
}
}
return false;
} // else: CriterionStatus::Unknown
return meetsCriteria;
}
} //end namespace selx
......@@ -73,8 +73,11 @@ private:
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
// 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, "ItkGaussianExponentialDiffeomorphicTransformComponent" }, { keys::InternalComputationValueType, PodString<InternalComputationValueType>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
}
};
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
......
......@@ -80,8 +80,7 @@ public:
//BaseClass methods
virtual bool MeetsCriterion( const ComponentBase::CriterionType & criterion ) override;
//static const char * GetName() { return "ItkImageRegistrationMethodv4"; } ;
static const char * GetDescription() { return "ItkImageRegistrationMethodv4 Component"; }
static const char * GetDescription() { return "ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainer Component"; }
private:
......@@ -97,14 +96,9 @@ private:
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
static inline const std::string GetTypeNameString()
static inline const std::map<std::string, std::string> TemplateProperties()
{
itkGenericExceptionMacro( << "Unknown ScalarType" << typeid( TransformInternalComputationValueType ).name() );
// TODO: provide the user instructions how to enable the compilation of the component with the required template types (if desired)
// We might define an exception object that can communicate various error messages: for simple user, for developer user, etc
return{ { keys::NameOfClass, "ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent" }, { keys::InternalComputationValueType, PodString<InternalComputationValueType>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
}
};
} //end namespace selx
......
......@@ -64,8 +64,11 @@ private:
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
// 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, "ItkGradientDescentOptimizerv4Component" }, { keys::InternalComputationValueType, PodString<InternalComputationValueType>::Get() } };
}
};
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
......
......@@ -24,7 +24,7 @@
#include "itkANTSNeighborhoodCorrelationImageToImageMetricv4.h"
#include "itkGradientDescentOptimizerv4.h"
#include "itkImageFileWriter.h"
#include "selxCheckTemplateProperties.h"
namespace selx
{
template< typename TFilter >
......@@ -267,21 +267,20 @@ ItkImageRegistrationMethodv4Component< Dimensionality, TPixel >
template< int Dimensionality, class TPixel >
bool
ItkImageRegistrationMethodv4Component< Dimensionality, TPixel >
::MeetsCriterion( const ComponentBase::CriterionType & criterion )
::MeetsCriterion(const ComponentBase::CriterionType & criterion)
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if (this->TemplateProperties().count(criterion.first) == 1) // e.g. is "Dimensionality" a template property?
bool hasUndefinedCriteria(false);
bool meetsCriteria(false);
auto status = CheckTemplateProperties(this->TemplateProperties(), criterion);
if (status == CriterionStatus::Satisfied)
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second)
{
if (criterionValue != this->TemplateProperties().at(criterion.first))
{
meetsCriteria = false;
}
}
return true;
}
else if (status == CriterionStatus::Failed)
{
return false;
} // else: CriterionStatus::Unknown
else if( criterion.first == "NumberOfLevels" ) //Supports this?
{
meetsCriteria = true;
......
......@@ -67,113 +67,13 @@ private:
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
static inline const std::string GetTypeNameString()
{
itkGenericExceptionMacro( << "Unknown ScalarType" << typeid( TPixel ).name() );
// TODO: provide the user instructions how to enable the compilation of the component with the required template types (if desired)
// We might define an exception object that can communicate various error messages: for simple user, for developer user, etc
}
static inline const std::string GetPixelTypeNameString()
// return the class name and the template arguments to uniquely identify this component.
static inline const std::map<std::string, std::string> TemplateProperties()
{
itkGenericExceptionMacro( << "Unknown PixelType" << typeid( TPixel ).name() );
// TODO: provide the user instructions how to enable the compilation of the component with the required template types (if desired)
// We might define an exception object that can communicate various error messages: for simple user, for developer user, etc
return{ { keys::NameOfClass, "ItkMeanSquaresImageToImageMetricv4Component" }, { keys::PixelType, PodString<TPixel>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
}
};
// unfortunately partial specialization of member functions is not allowed, without partially specializing the entire class.
/*
template <int Dimensionality>
class ItkMeanSquaresImageToImageMetricv4Component < Dimensionality, double >
{
static inline const std::string GetPixelTypeNameString();
};
template <int Dimensionality>
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component<Dimensionality, double>
::GetPixelTypeNameString()
{
return std::string("double");
}
*/
template< >
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component< 2, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component< 2, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component< 3, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component< 3, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component< 2, float >
::GetTypeNameString()
{
return std::string( "2_float" );
}
template< >
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component< 2, double >
::GetTypeNameString()
{
return std::string( "2_double" );
}
template< >
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component< 3, float >
::GetTypeNameString()
{
return std::string( "3_float" );
}
template< >
inline const std::string
ItkMeanSquaresImageToImageMetricv4Component< 3, double >
::GetTypeNameString()
{
return std::string( "3_double" );
}
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkMeanSquaresImageToImageMetricv4.hxx"
......
......@@ -18,6 +18,7 @@
*=========================================================================*/
#include "selxItkMeanSquaresImageToImageMetricv4.h"
#include "selxCheckTemplateProperties.h"
namespace selx
{
......@@ -52,39 +53,15 @@ ItkMeanSquaresImageToImageMetricv4Component< Dimensionality, TPixel >
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
auto status = CheckTemplateProperties(this->TemplateProperties(), criterion);
if (status == CriterionStatus::Satisfied)
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
return true;
}
else if( criterion.first == "Dimensionality" ) //Supports this?
else if (status == CriterionStatus::Failed)
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( std::stoi( criterionValue ) != Dimensionality )
{
meetsCriteria = false;
}
}
}
else if( criterion.first == "PixelType" ) //Supports this?
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != Self::GetPixelTypeNameString() )
{
meetsCriteria = false;
}
}
}
return false;
} // else: CriterionStatus::Unknown
return meetsCriteria;
}
} //end namespace selx
......@@ -90,113 +90,13 @@ private:
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
static inline const std::string GetTypeNameString()
{
itkGenericExceptionMacro( << "Unknown ScalarType" << typeid( TPixel ).name() );
// TODO: provide the user instructions how to enable the compilation of the component with the required template types (if desired)
// We might define an exception object that can communicate various error messages: for simple user, for developer user, etc
}
static inline const std::string GetPixelTypeNameString()
// return the class name and the template arguments to uniquely identify this component.
static inline const std::map<std::string, std::string> TemplateProperties()
{
itkGenericExceptionMacro( << "Unknown PixelType" << typeid( TPixel ).name() );
// TODO: provide the user instructions how to enable the compilation of the component with the required template types (if desired)
// We might define an exception object that can communicate various error messages: for simple user, for developer user, etc
return{ { keys::NameOfClass, "ItkResampleFilterComponent" }, { keys::PixelType, PodString<TPixel>::Get() }, { keys::InternalComputationValueType, PodString<TInternalComputationValue>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
}
};
// unfortunately partial specialization of member functions is not allowed, without partially specializing the entire class.