Commit 93fcf859 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: refactor of template properties and MeetsCritria. Done for

itkRegistrationMethodv4Component, TODO: all other components
parent 930d3ede
......@@ -112,113 +112,14 @@ 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, "ItkImageRegistrationMethodv4Component" }, { 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 ItkImageRegistrationMethodv4Component < Dimensionality, double >
{
static inline const std::string GetPixelTypeNameString();
};
template <int Dimensionality>
inline const std::string
ItkImageRegistrationMethodv4Component<Dimensionality, double>
::GetPixelTypeNameString()
{
return std::string("double");
}
*/
template< >
inline const std::string
ItkImageRegistrationMethodv4Component< 2, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkImageRegistrationMethodv4Component< 2, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkImageRegistrationMethodv4Component< 3, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkImageRegistrationMethodv4Component< 3, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkImageRegistrationMethodv4Component< 2, float >
::GetTypeNameString()
{
return std::string( "2_float" );
}
template< >
inline const std::string
ItkImageRegistrationMethodv4Component< 2, double >
::GetTypeNameString()
{
return std::string( "2_double" );
}
template< >
inline const std::string
ItkImageRegistrationMethodv4Component< 3, float >
::GetTypeNameString()
{
return std::string( "3_float" );
}
template< >
inline const std::string
ItkImageRegistrationMethodv4Component< 3, double >
::GetTypeNameString()
{
return std::string( "3_double" );
}
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkImageRegistrationMethodv4Component.hxx"
......
......@@ -271,34 +271,12 @@ ItkImageRegistrationMethodv4Component< Dimensionality, TPixel >
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
if (this->TemplateProperties().count(criterion.first) == 1) // e.g. is "Dimensionality" a template property?
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
}
else if( criterion.first == "Dimensionality" ) //Supports this?
{
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?
for (auto const & criterionValue : criterion.second)
{
if( criterionValue != Self::GetPixelTypeNameString() )
if (criterionValue != this->TemplateProperties().at(criterion.first))
{
meetsCriteria = false;
}
......
......@@ -32,6 +32,7 @@ namespace selx
namespace keys
{
const char * const NameOfInterface = "NameOfInterface"; // Each Interface has a sting name
const char * const NameOfClass = "NameOfClass"; // Each Component has a sting name
const char * const Dimensionality = "Dimensionality"; // Template int parameter
const char * const PixelType = "PixelType"; // Template POD parameter
const char * const InternalComputationValueType = "InternalComputationValueType"; // Template POD parameter for transforms or optimizers etc.
......
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