Commit 21ed6655 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: minor improvements in overlord and test

parent 0be3fef7
......@@ -46,83 +46,88 @@ namespace selx
{
public:
typedef ComponentBase::CriteriaType CriteriaType;
typedef ComponentBase::CriterionType CriterionType;
typedef ComponentBase::ParameterValueType ParameterValueType;
typedef ComponentBase ComponentType;
typedef ComponentSelector::Pointer ComponentSelectorPointer;
typedef Blueprint BlueprintType;
typedef BlueprintType::ComponentNameType ComponentNameType;
typedef BlueprintType::ComponentNamesType ComponentNamesType;
typedef std::map< ComponentNameType, ComponentSelectorPointer> ComponentSelectorContainerType;
typedef ComponentSelectorContainerType::iterator ComponentSelectorIteratorType;
typedef AnyFileReader AnyFileReaderType;
typedef AnyFileWriter AnyFileWriterType;
typedef Blueprint::ComponentNameType ComponentNameType;
typedef std::map <
std::string, SourceInterface* > SourceInterfaceMapType;
typedef std::map <
std::string, SinkInterface* > SinkInterfaceMapType;
Overlord();
~Overlord() {};
SourceInterfaceMapType GetSourceInterfaces();
SinkInterfaceMapType GetSinkInterfaces();
SinkInterface::DataObjectPointer GetInitializedOutput(const Overlord::ComponentNameType&);
typedef itk::VectorContainer <
unsigned int, ComponentType::Pointer > ComponentsContainerType;
//void SetBlueprint(Blueprint const * blueprint){
// m_Blueprint = blueprint;
//}
void SetBlueprint(Blueprint::Pointer blueprint){
//Overlord should be constructed with a blueprint.
m_Blueprint = blueprint;
}
/** Read configuration at the blueprints nodes and edges and return true if all components could be uniquely selected*/
bool Configure();
/** if all components are uniquely selected, they can be connected */
bool ConnectComponents();
/** Run the (registration) algorithm */
void Execute();
AnyFileReaderType::Pointer GetInputFileReader(const ComponentNameType&);
AnyFileWriterType::Pointer GetOutputFileWriter(const ComponentNameType&);
SourceInterfaceMapType GetSourceInterfaces();
SinkInterfaceMapType GetSinkInterfaces();
AnyFileReader::Pointer GetInputFileReader(const ComponentNameType&);
AnyFileWriter::Pointer GetOutputFileWriter(const ComponentNameType&);
SinkInterface::DataObjectPointer GetInitializedOutput(const Overlord::ComponentNameType&);
protected:
public: // temporarily from private to public during refactoring SuperElastixFilter.
private:
typedef ComponentBase::CriteriaType CriteriaType;
typedef ComponentBase::CriterionType CriterionType;
typedef ComponentBase::ParameterValueType ParameterValueType;
typedef ComponentSelector::Pointer ComponentSelectorPointer;
typedef Blueprint::ComponentNamesType ComponentNamesType;
typedef std::map< ComponentNameType, ComponentSelectorPointer> ComponentSelectorContainerType;
typedef ComponentSelectorContainerType::iterator ComponentSelectorIteratorType;
/** Read configuration at the blueprints nodes and try to find instantiated components */
void ApplyNodeConfiguration();
/** Read configuration at the blueprints edges and try to find instantiated components */
void ApplyConnectionConfiguration();
private:
//bool UpdateSelectors();
void FindAfterRegistration();
void FindRunRegistration();
/** See which components need more configuration criteria */
ComponentNamesType GetNonUniqueComponentNames();
void ConnectSources();
void ConnectSinks();
void RunRegistrations();
void AfterRegistrations();
void ReconnectTransforms();
//TODO make const correct
//Overlord should be constructed with a blueprint.
//Blueprint::ConstPointer m_Blueprint;
//Blueprint const * m_Blueprint;
Blueprint::Pointer m_Blueprint;
// A selector for each node, that each can hold multiple instantiated components. Ultimately is should be 1 component each.
ComponentSelectorContainerType m_ComponentSelectorContainer;
bool m_isConfigured;
bool m_allUniqueComponents;
/** Flow handling: todo move to a controller component */
void FindAfterRegistration();
void FindRunRegistration();
void RunRegistrations();
void AfterRegistrations();
void ReconnectTransforms();
typedef itk::VectorContainer <
unsigned int, ComponentBase::Pointer > ComponentsContainerType;
ComponentsContainerType::Pointer m_RunRegistrationComponents;
ComponentsContainerType::Pointer m_AfterRegistrationComponents;
};
......
......@@ -21,7 +21,7 @@
namespace selx
{
Overlord::Overlord() : m_isConfigured(false), m_allUniqueComponents(false)
Overlord::Overlord() : m_isConfigured(false)
{
this->m_RunRegistrationComponents = ComponentsContainerType::New();
this->m_AfterRegistrationComponents = ComponentsContainerType::New();
......@@ -29,14 +29,17 @@ namespace selx
bool Overlord::Configure()
{
//TODO: make a while loop until stable:
// - for each unique component propagate the required interfaces to neighboring components as added criterion
if (!this->m_isConfigured)
{
std::cout << "Applying Component Criteria" << std::endl;
this->ApplyNodeConfiguration();
ComponentNamesType nonUniqueComponentNames;
nonUniqueComponentNames = this->GetNonUniqueComponentNames();
auto nonUniqueComponentNames = this->GetNonUniqueComponentNames();
std::cout << nonUniqueComponentNames.size() << " out of " << m_Blueprint->GetComponentNames().size() << " Components could not be uniquely selected" << std::endl << std::endl;
std::cout << "Applying Connection Criteria" << std::endl;
......@@ -44,26 +47,19 @@ namespace selx
nonUniqueComponentNames = this->GetNonUniqueComponentNames();
std::cout << nonUniqueComponentNames.size() << " out of " << m_Blueprint->GetComponentNames().size() << " Components could not be uniquely selected" << std::endl << std::endl;
if (nonUniqueComponentNames.size() > 0)
{
this->m_allUniqueComponents = false;
std::cout << std::endl << "These Nodes need more criteria: " << std::endl;
for (const auto & nonUniqueComponentName : nonUniqueComponentNames)
{
std::cout << nonUniqueComponentName<< std::endl;
}
}
else
this->m_isConfigured = true;
}
auto nonUniqueComponentNames = this->GetNonUniqueComponentNames();
if (nonUniqueComponentNames.size() > 0)
{
std::cout << std::endl << "These Nodes need more criteria: " << std::endl;
for (const auto & nonUniqueComponentName : nonUniqueComponentNames)
{
this->m_allUniqueComponents = true;
std::cout << nonUniqueComponentName<< std::endl;
}
//TODO: make a while loop until stable:
// - for each unique component propagate the required interfaces to neighboring components as added criterion
this->m_isConfigured = true;
return false;
}
return this->m_allUniqueComponents;
return true;
}
Overlord::ComponentNamesType Overlord::GetNonUniqueComponentNames()
......@@ -202,7 +198,7 @@ namespace selx
/** Scans all Components to find those with Sourcing capability and store them in SourceComponents list */
SourceInterfaceMapType sourceInterfaceMap;
for (const auto & componentSelector : (this->m_ComponentSelectorContainer))
for (const auto & componentSelector : this->m_ComponentSelectorContainer)
{
ComponentBase::Pointer component = componentSelector.second->GetComponent();
if (component->MeetsCriterionBase({ "HasProvidingInterface", { "SourceInterface" } }))
......@@ -224,7 +220,7 @@ namespace selx
/** Scans all Components to find those with Sinking capability and store them in SinkComponents list */
SinkInterfaceMapType sinkInterfaceMap;
for (auto const & componentSelector : (this->m_ComponentSelectorContainer))
for (auto const & componentSelector : this->m_ComponentSelectorContainer)
{
ComponentBase::Pointer component = componentSelector.second->GetComponent();
if (component->MeetsCriterionBase({ "HasProvidingInterface", { "SinkInterface" } }))
......@@ -242,10 +238,10 @@ namespace selx
void Overlord::FindRunRegistration()
{
/** Scans all Components to find those with Sourcing capability and store them in SourceComponents list */
/** Scans all Components to find those with FindRunRegistration capability and store them in m_RunRegistrationComponents list */
const CriterionType runRegistrationCriterion = CriterionType("HasProvidingInterface", { "RunRegistrationInterface" });
for (auto const & componentSelector : (this->m_ComponentSelectorContainer))
for (auto const & componentSelector : this->m_ComponentSelectorContainer)
{
ComponentBase::Pointer component = componentSelector.second->GetComponent();
if (component->MeetsCriterionBase(runRegistrationCriterion))
......@@ -257,10 +253,10 @@ namespace selx
void Overlord::FindAfterRegistration()
{
/** Scans all Components to find those with Sourcing capability and store them in SourceComponents list */
/** Scans all Components to find those with FindAfterRegistration capability and store them in m_AfterRegistrationComponents list */
const CriterionType afterRegistrationCriterion = CriterionType("HasProvidingInterface", { "AfterRegistrationInterface" });
for (auto const & componentSelector : (this->m_ComponentSelectorContainer))
for (auto const & componentSelector : this->m_ComponentSelectorContainer)
{
ComponentBase::Pointer component = componentSelector.second->GetComponent();
if (component->MeetsCriterionBase(afterRegistrationCriterion))
......@@ -307,7 +303,7 @@ namespace selx
/** Scans all Components to find those with ReconnectTransform capability and call them */
const CriterionType criterion = CriterionType("HasProvidingInterface", { "ReconnectTransformInterface" });
for (auto const & componentSelector : (this->m_ComponentSelectorContainer))
for (auto const & componentSelector : this->m_ComponentSelectorContainer)
{
ComponentBase::Pointer component = componentSelector.second->GetComponent();
if (component->MeetsCriterionBase(criterion))
......
......@@ -92,4 +92,14 @@ TEST_F(OverlordTest, Configure)
EXPECT_TRUE(allUniqueComponents);
}
TEST_F(OverlordTest, Connect)
{
std::unique_ptr<Overlord> overlord(new Overlord());
overlord->SetBlueprint(blueprint);
EXPECT_NO_THROW(bool allUniqueComponents = overlord->Configure());
bool success;
EXPECT_NO_THROW(success = overlord->ConnectComponents());
}
} // namespace selx
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