Commit 02960bf1 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: removed deprecated MeetCriterionBase

parent ecbb068e
......@@ -69,6 +69,11 @@ private:
std::set< AfterRegistrationInterface * > m_AfterRegistrationInterfaces;
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, "RegistrationControllerComponent" } };
}
};
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
......
......@@ -83,19 +83,17 @@ template< bool dummy >
bool
RegistrationControllerComponent< dummy >::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 (status == CriterionStatus::Failed)
{
return false;
} // else: CriterionStatus::Unknown
return meetsCriteria;
}
} //end namespace selx
......@@ -65,12 +65,23 @@ GDOptimizer3rdPartyComponent
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
if( criterion.first == "NameOfClass" )
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
if( criterionValue != "GDOptimizer3rdPartyComponent" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
}
else if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
......
......@@ -57,12 +57,23 @@ GDOptimizer4thPartyComponent
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
if( criterion.first == "NameOfClass" )
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
if( criterionValue != "GDOptimizer4rdPartyComponent" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
}
else if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
......
......@@ -41,12 +41,24 @@ MetricComponent1
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
if( criterion.first == "NameOfClass" )
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
if( criterionValue != "MetricComponent1" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
return false;
}
}
}
else if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
return false;
......
......@@ -52,17 +52,29 @@ SSDMetric3rdPartyComponent
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
if( criterion.first == "NameOfClass" )
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
if( criterionValue != "SSDMetric3rdPartyComponent" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
}
else if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
return false;
}
}
}
return meetsCriteria;
}
} //end namespace selx
......@@ -45,17 +45,29 @@ SSDMetric4thPartyComponent
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
if( criterion.first == "NameOfClass" )
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
if( criterionValue != "SSDMetric4thPartyComponent" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
}
else if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
return false;
}
}
}
return meetsCriteria;
}
} //end namespace selx
......@@ -33,12 +33,24 @@ TransformComponent1::MeetsCriterion( const CriterionType & criterion )
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "ComponentProperty" )
if( criterion.first == "NameOfClass" )
{
meetsCriteria = true;
for( auto const & criterionValue : criterion.second ) // auto&& preferred?
{
if( criterionValue != "SomeProperty" ) // e.g. "GradientDescent", "SupportsSparseSamples
if( criterionValue != "TransformComponent1" ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
return false;
}
}
}
if (criterion.first == "ComponentProperty")
{
meetsCriteria = true;
for (auto const & criterionValue : criterion.second) // auto&& preferred?
{
if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
return false;
......
......@@ -66,113 +66,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, "ItkSmoothingRecursiveGaussianImageFilterComponent" }, { 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 ItkSmoothingRecursiveGaussianImageFilterComponent < Dimensionality, double >
{
static inline const std::string GetPixelTypeNameString();
};
template <int Dimensionality>
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent<Dimensionality, double>
::GetPixelTypeNameString()
{
return std::string("double");
}
*/
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 2, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 2, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 3, float >
::GetPixelTypeNameString()
{
return std::string( "float" );
}
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 3, double >
::GetPixelTypeNameString()
{
return std::string( "double" );
}
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 2, float >
::GetTypeNameString()
{
return std::string( "2_float" );
}
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 2, double >
::GetTypeNameString()
{
return std::string( "2_double" );
}
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 3, float >
::GetTypeNameString()
{
return std::string( "3_float" );
}
template< >
inline const std::string
ItkSmoothingRecursiveGaussianImageFilterComponent< 3, double >
::GetTypeNameString()
{
return std::string( "3_double" );
}
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkSmoothingRecursiveGaussianImageFilterComponent.hxx"
......
......@@ -61,41 +61,18 @@ bool
ItkSmoothingRecursiveGaussianImageFilterComponent< 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
else if( criterion.first == "Sigma" ) //Supports this?
{
if( criterion.second.size() != 1 )
......
......@@ -85,30 +85,18 @@ bool
ItkGaussianExponentialDiffeomorphicTransformComponent< InternalComputationValueType, Dimensionality >
::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;
}
}
}
return false;
} // else: CriterionStatus::Unknown
return meetsCriteria;
}
} //end namespace selx
......@@ -88,30 +88,17 @@ bool
ItkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerComponent< Dimensionality, TransformInternalComputationValueType >
::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;
}
}
}
return false;
} // else: CriterionStatus::Unknown
else if( criterion.first == "ShrinkFactorsPerLevel" ) //Supports this?
{
meetsCriteria = true;
......
......@@ -54,20 +54,19 @@ bool
ItkGradientDescentOptimizerv4Component< InternalComputationValueType >
::MeetsCriterion( const ComponentBase::CriterionType & criterion )
{
bool hasUndefinedCriteria( false );
bool meetsCriteria( false );
if( criterion.first == "InternalComputationValueType" )
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 != PodString< InternalComputationValueType >::Get() ) // e.g. "GradientDescent", "SupportsSparseSamples
{
meetsCriteria = false;
}
}
return true;
}
else if( criterion.first == "NumberOfIterations" ) //Supports this?
else if (status == CriterionStatus::Failed)
{
return false;
} // else: CriterionStatus::Unknown
if( criterion.first == "NumberOfIterations" ) //Supports this?
{
if( criterion.second.size() != 1 )
{
......
......@@ -59,9 +59,6 @@ public:
virtual int AcceptConnectionFrom( ComponentBase * ) = 0;
/** if there is any failed criterion, return false (like a short - circuit AND) */
bool MeetsCriterionBase( const CriterionType & criterion );
virtual bool MeetsCriterion( const CriterionType & criterion ) = 0;
virtual InterfaceStatus CanAcceptConnectionFrom( ComponentBase *, const InterfaceCriteriaType ) = 0;
......@@ -70,7 +67,7 @@ public:
virtual unsigned int CountProvidingInterfaces( const InterfaceCriteriaType ) = 0;
virtual const std::map< std::string, std::string > TemplateProperties() { return {}; }; //TODO should be overridden
virtual const std::map< std::string, std::string > TemplateProperties(); //TODO should be overridden
protected:
......
......@@ -21,20 +21,6 @@
namespace selx
{
//TODO deprecate this method: let derived class handle this (using selxCheckTemplateProperties.h)
bool
ComponentBase::MeetsCriterionBase( const CriterionType & criterion )
{
if( criterion.first == "NameOfClass" )
{
if( criterion.second.size() != 1 )
{
itkExceptionMacro( "The criterion NameOfClass may have only 1 value" );
}
return ( criterion.second[ 0 ] == this->GetNameOfClass() );
}
// else pass criterion to derived Component
return this->MeetsCriterion( criterion );
}
const std::map< std::string, std::string > ComponentBase::TemplateProperties()
{ return{}; }
} // end namespace selx
......@@ -50,7 +50,7 @@ void
ComponentSelector::AddCriterion( const CriterionType & criterion )
{
this->m_PossibleComponents.remove_if([ & ]( ComponentBasePointer component ){
return !component->MeetsCriterionBase( criterion );
return !component->MeetsCriterion( criterion );
} );
}
......
......@@ -134,7 +134,7 @@ TEST_F( ComponentFactoryTest, AddCriteria )
EXPECT_NO_THROW( ComponentFactory< TransformComponent1 >::RegisterOneFactory() );
EXPECT_NO_THROW( ComponentFactory< MetricComponent1 >::RegisterOneFactory() );
CriterionType nonSelectiveCriterion( "ComponentProperty", { "SomeProperty" } );
CriterionType nonSelectiveCriterion({ "ComponentProperty", { "SomeProperty" } });
CriterionType criterion1( { "ComponentOutput", { "Transform" } } );
......