Commit e73cbc1c authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: refactored Sinks and Sources to use TemplateProperties() in

MeetsCriterion()
parent 8fc4cd1e
......@@ -76,59 +76,14 @@ private:
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
static inline const std::string GetTypeNameString()
// 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 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
return{ { keys::NameOfClass, "DisplacementFieldItkImageFilterSinkComponent" }, { keys::PixelType, PodString<TPixel>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
}
static inline const std::string GetPixelTypeNameString()
{
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
}
};
template< >
inline const std::string
DisplacementFieldItkImageFilterSinkComponent< 2, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
DisplacementFieldItkImageFilterSinkComponent< 2, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
DisplacementFieldItkImageFilterSinkComponent< 3, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
DisplacementFieldItkImageFilterSinkComponent< 3, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxDisplacementFieldItkImageFilterSink.hxx"
......
......@@ -98,39 +98,16 @@ DisplacementFieldItkImageFilterSinkComponent< Dimensionality, TPixel >::MeetsCri
{
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
if( criterion.first == "IsVectorField" )
{
meetsCriteria = true;
......
......@@ -73,59 +73,14 @@ private:
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
static inline const std::string GetTypeNameString()
// 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 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
return{ { keys::NameOfClass, "ItkImageSinkComponent" }, { keys::PixelType, PodString<TPixel>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
}
static inline const std::string GetPixelTypeNameString()
{
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
}
};
template< >
inline const std::string
ItkImageSinkComponent< 2, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkImageSinkComponent< 2, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkImageSinkComponent< 3, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkImageSinkComponent< 3, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkImageSink.hxx"
......
......@@ -97,41 +97,18 @@ template< int Dimensionality, class TPixel >
bool
ItkImageSinkComponent< Dimensionality, TPixel >::MeetsCriterion( const ComponentBase::CriterionType & criterion )
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
bool hasUndefinedCriteria(false);
bool meetsCriteria(false);
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
......@@ -62,60 +62,13 @@ private:
typename ItkImageType::Pointer m_Image;
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, "ItkImageSourceComponent" }, { keys::PixelType, PodString<TPixel>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
}
};
template< >
inline const std::string
ItkImageSourceComponent< 2, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkImageSourceComponent< 2, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkImageSourceComponent< 3, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkImageSourceComponent< 3, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkImageSource.hxx"
......
......@@ -76,41 +76,18 @@ bool
ItkImageSourceComponent< Dimensionality, TPixel >
::MeetsCriterion( const ComponentBase::CriterionType & criterion )
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
bool hasUndefinedCriteria(false);
bool meetsCriteria(false);
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
......@@ -70,60 +70,12 @@ private:
typename ItkImageType::Pointer m_Image;
protected:
/* The following struct returns the string name of computation type */
/* default implementation */
static inline const std::string GetTypeNameString()
// 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 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()
{
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, "ItkImageSourceFixedComponent" }, { keys::PixelType, PodString<TPixel>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
}
};
template< >
inline const std::string
ItkImageSourceFixedComponent< 2, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkImageSourceFixedComponent< 2, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkImageSourceFixedComponent< 3, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkImageSourceFixedComponent< 3, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkImageSourceFixed.hxx"
......
......@@ -89,41 +89,18 @@ bool
ItkImageSourceFixedComponent< Dimensionality, TPixel >
::MeetsCriterion( const ComponentBase::CriterionType & criterion )
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
bool hasUndefinedCriteria(false);
bool meetsCriteria(false);
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
......@@ -64,59 +64,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, "ItkImageSourceMovingComponent" }, { keys::PixelType, PodString<TPixel>::Get() }, { keys::Dimensionality, std::to_string(Dimensionality) } };
}
};
template< >
inline const std::string
ItkImageSourceMovingComponent< 2, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkImageSourceMovingComponent< 2, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkImageSourceMovingComponent< 3, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkImageSourceMovingComponent< 3, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkImageSourceMoving.hxx"
......
......@@ -76,41 +76,18 @@ bool
ItkImageSourceMovingComponent< Dimensionality, TPixel >
::MeetsCriterion( const ComponentBase::CriterionType & criterion )
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
bool hasUndefinedCriteria(false);
bool meetsCriteria(false);
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
......@@ -74,59 +74,13 @@ private:
protected:
/* The following struct returns the string name of computation type */
/* default implementation */