Commit 5f75dab4 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: let Overlord use AddProviding/AcceptingInterfaceCriteria

parent b107f8b7
......@@ -581,7 +581,7 @@ TEST_F( RegistrationItkv4Test, FullyConfigured3dAffine )
connection5Parameters[ "NameOfInterface" ] = { "itkMetricv4Interface" };
blueprint->AddConnection( "Metric", "RegistrationMethod", connection5Parameters );
blueprint->AddConnection( "FixedImageSource", "Transform", { {} } );
//blueprint->AddConnection( "FixedImageSource", "Transform", { {} } );
blueprint->AddConnection( "Transform", "RegistrationMethod", { {} } );
blueprint->AddConnection( "Optimizer", "RegistrationMethod", { {} } );
......
......@@ -62,24 +62,21 @@ public:
virtual int AcceptConnectionFrom( ComponentBase * ) = 0;
/** if there is any failed criterion, return false (like a short - circuit AND) */
//TODO deprecate:
bool MeetsCriteria( const CriteriaType & criteria );
bool MeetsCriterionBase( const CriterionType & criterion );
virtual bool MeetsCriterion( const CriterionType & criterion ) = 0;
virtual interfaceStatus CanAcceptConnectionFrom(ComponentBase*, const InterfaceCriteriaType) = 0;
protected:
virtual bool HasAcceptingInterface( const char * ) = 0;
virtual bool HasProvidingInterface( const char * ) = 0;
//experimental:
virtual unsigned int CountAcceptingInterfaces(const InterfaceCriteriaType) = 0;
virtual unsigned int CountProvidingInterfaces(const InterfaceCriteriaType) = 0;
protected:
virtual bool HasAcceptingInterface( const char * ) = 0;
virtual bool HasProvidingInterface( const char * ) = 0;
ComponentBase() {}
virtual ~ComponentBase() {}
......
......@@ -68,7 +68,7 @@ public:
/** Check for multiple versus 1 or 0 components*/
bool HasMultipleComponents( void );
unsigned int CountCompatibleInterfaces(ComponentBasePointer other);
unsigned int RequireAcceptInterfaceFrom(ComponentBasePointer other, const InterfaceCriteriaType & interfaceCriteria);
/** Return Component or Nullptr*/
ComponentBasePointer GetComponent( void );
......
......@@ -269,7 +269,7 @@ struct Properties
//static_assert(StaticErrorMessageRevealT<T>::False, "Please Implement InterfaceProperties<InterfaceType> for this InterfaceType");
static const std::map<std::string, std::string> Get()
{
return{ { "Name", InterfaceName< T >::Get() } };
return{ { "NameOfInterface", InterfaceName< T >::Get() } };
}
};
......@@ -280,7 +280,7 @@ struct Properties< itkImageFixedInterface< D, TPixel >>
{
static const std::map<std::string, std::string> Get()
{
return{ { "Name", InterfaceName< itkImageFixedInterface< D, TPixel> >::Get() }, { "Dimensionality", "3" }, { "PixelType", "float" } };
return{ { "NameOfInterface", InterfaceName< itkImageFixedInterface< D, TPixel> >::Get() }, { "Dimensionality", "3" }, { "PixelType", "float" } };
}
};
......@@ -289,7 +289,7 @@ struct Properties< MetricValueInterface >
{
static const std::map<std::string, std::string> Get()
{
return{ { "Name", "MetricValueInterface" } };
return{ { "NameOfInterface", "MetricValueInterface" } };
}
};
} // end namespace selx
......
......@@ -147,12 +147,12 @@ Accepting< FirstInterface, RestInterfaces ... >::CanAcceptConnectionFrom(Compone
{
ComponentBase::interfaceStatus restInterfacesStatus = Accepting< RestInterfaces ... >::CanAcceptConnectionFrom(other, interfaceCriteria);
// if multiple interfaces were a succes we do not have to check any further interfaces.
// if multiple interfaces were a success we do not have to check any further interfaces.
if (restInterfacesStatus == ComponentBase::interfaceStatus::multiple)
{
return ComponentBase::interfaceStatus::multiple;
}
// if a previous interface was a success, we can have either succes or multiple (successes)
// if a previous interface was a success, we can have either success or multiple (successes)
else if (restInterfacesStatus == ComponentBase::interfaceStatus::success)
{
unsigned int interfaceMeetsCriteria = Count<FirstInterface>::MeetsCriteria(interfaceCriteria);
......@@ -173,7 +173,7 @@ Accepting< FirstInterface, RestInterfaces ... >::CanAcceptConnectionFrom(Compone
}
}
}
// if a previous interface was noprovider, we can have either succes or noprovider (we know that there was at least 1 acceptor)
// if a previous interface was noprovider, we can have either success or noprovider (we know that there was at least 1 acceptor)
else if (restInterfacesStatus == ComponentBase::interfaceStatus::noprovider)
{
unsigned int interfaceMeetsCriteria = Count<FirstInterface>::MeetsCriteria(interfaceCriteria);
......@@ -194,7 +194,7 @@ Accepting< FirstInterface, RestInterfaces ... >::CanAcceptConnectionFrom(Compone
}
}
}
// if a previous interface was noacceptor, we can have noaccepter, succes or noprovider
// if a previous interface was noaccepter, we can have noaccepter, success or noprovider
else if (restInterfacesStatus == ComponentBase::interfaceStatus::noaccepter)
{
unsigned int interfaceMeetsCriteria = Count<FirstInterface>::MeetsCriteria(interfaceCriteria);
......@@ -215,6 +215,8 @@ Accepting< FirstInterface, RestInterfaces ... >::CanAcceptConnectionFrom(Compone
}
}
}
// never reached
return ComponentBase::interfaceStatus::noaccepter;
}
......
......@@ -70,12 +70,13 @@ ComponentSelector::AddProvidingInterfaceCriteria(const InterfaceCriteriaType & i
});
}
//Require CompatibleInterfaces
unsigned int ComponentSelector::CountCompatibleInterfaces(ComponentBasePointer other)
// CompatibleInterfaces
unsigned int ComponentSelector::RequireAcceptInterfaceFrom(ComponentBasePointer other, const InterfaceCriteriaType & interfaceCriteria)
{
this->m_PossibleComponents.remove_if([&](ComponentBasePointer component){
return !component->CanAcceptConnectionFrom(other);
this->m_PossibleComponents.remove_if([&](ComponentBasePointer component){auto status = component->CanAcceptConnectionFrom(other, interfaceCriteria);
return status == ComponentBase::interfaceStatus::noaccepter || status == ComponentBase::interfaceStatus::noprovider;
});
return 0;
}
ComponentSelector::ComponentBasePointer
......
......@@ -159,30 +159,26 @@ Overlord::ApplyConnectionConfiguration()
{
for( auto const & outgoingName : this->m_Blueprint->GetOutputNames( name ) )
{
//TODO check direction upstream/downstream input/output source/target
Blueprint::ParameterMapType connectionProperties = this->m_Blueprint->GetConnection( name, outgoingName );
//TODO
//TODO:
//1: this lambda function converts the blueprint properties: map<string,vector<string>> to interfacecriteria: map<string,string>, consider redesign.
//2: connection blueprint->addConnection("myfirstnode","mysecondnode",{{}}) creates connectionProperties {"",[]} which is not an empty map.
ComponentBase::InterfaceCriteriaType interfaceCriteria;
std::for_each(connectionProperties.begin(), connectionProperties.end(), [interfaceCriteria](Blueprint::ParameterMapType::value_type kv) mutable { interfaceCriteria[kv.first] = kv.second[0]; });
std::for_each(connectionProperties.begin(), connectionProperties.end(), [interfaceCriteria](Blueprint::ParameterMapType::value_type kv) mutable { if (kv.second.size() > 0) interfaceCriteria[kv.first] = kv.second[0]; });
this->m_ComponentSelectorContainer[name]->AddProvidingInterfaceCriteria(interfaceCriteria);
this->m_ComponentSelectorContainer[outgoingName]->AddAcceptingInterfaceCriteria(interfaceCriteria);
std::cout << " Blueprint Connection: " << name << " -> " << outgoingName << std::endl;
std::for_each(interfaceCriteria.begin(), interfaceCriteria.end(), [](ComponentBase::InterfaceCriteriaType::value_type kv) mutable { std::cout << " { " << kv.first << ": " << kv.second << " }\n"; });
if( connectionProperties.count( "NameOfInterface" ) > 0 )
{
this->m_ComponentSelectorContainer[ name ]->AddCriterion( { keys::HasProvidingInterface, connectionProperties[ keys::NameOfInterface ] } );
this->m_ComponentSelectorContainer[ outgoingName ]->AddCriterion( { keys::HasAcceptingInterface,
connectionProperties[ keys::NameOfInterface ] } );
std::cout << " Blueprint Node: " << name << std::endl << " HasProvidingInterface " << connectionProperties[ keys::NameOfInterface ][ 0 ]
<< std::endl;
std::cout << " Blueprint Node: " << outgoingName << std::endl << " HasAcceptingInterface "
<< connectionProperties[ keys::NameOfInterface ][ 0 ] << std::endl;
}
if( ( this->m_ComponentSelectorContainer[ outgoingName ]->HasMultipleComponents() == false )
&& ( this->m_ComponentSelectorContainer[ outgoingName ]->GetComponent().IsNull() ) )
{
std::stringstream msg;
msg << "Too many criteria for Component " << outgoingName << std::endl;
msg << outgoingName << " does not accept a connection of given criteria" << std::endl;
throw std::runtime_error( msg.str() );
}
}
......@@ -190,7 +186,7 @@ Overlord::ApplyConnectionConfiguration()
&& ( this->m_ComponentSelectorContainer[ name ]->GetComponent().IsNull() ) )
{
std::stringstream msg;
msg << "Too many criteria for Component " << name << std::endl;
msg << name << " does not provide a connection of given criteria" << std::endl;
throw std::runtime_error( msg.str() );
}
}
......@@ -253,7 +249,8 @@ Overlord::GetSourceInterfaces()
for( const auto & componentSelector : this->m_ComponentSelectorContainer )
{
ComponentBase::Pointer component = componentSelector.second->GetComponent();
if( component->MeetsCriterionBase( { keys::HasProvidingInterface, { keys::SourceInterface } } ) )
if (component->CountProvidingInterfaces({ { keys::NameOfInterface, keys::SourceInterface } }) == 1)
{
SourceInterface * provingSourceInterface = dynamic_cast< SourceInterface * >( component.GetPointer() );
if( provingSourceInterface == nullptr ) // is actually a double-check for sanity: based on criterion cast should be successful
......@@ -276,7 +273,7 @@ Overlord::GetSinkInterfaces()
for( auto const & componentSelector : this->m_ComponentSelectorContainer )
{
ComponentBase::Pointer component = componentSelector.second->GetComponent();
if( component->MeetsCriterionBase( { keys::HasProvidingInterface, { keys::SinkInterface } } ) )
if (component->CountProvidingInterfaces({ { keys::NameOfInterface, keys::SinkInterface } }) == 1)
{
SinkInterface * provingSinkInterface = dynamic_cast< SinkInterface * >( component.GetPointer() );
if( provingSinkInterface == nullptr ) // is actually a double-check for sanity: based on criterion cast should be successful
......
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