Skip to content
Snippets Groups Projects
Commit 2f66846b authored by Kasper Marstal's avatar Kasper Marstal
Browse files

ENH: Add interface of managing components

parent 768d320f
No related branches found
No related tags found
No related merge requests found
...@@ -21,10 +21,14 @@ public: ...@@ -21,10 +21,14 @@ public:
typedef std::vector< std::string > ParameterValueType; typedef std::vector< std::string > ParameterValueType;
typedef std::map< ParameterKeyType, ParameterValueType > ParameterMapType; typedef std::map< ParameterKeyType, ParameterValueType > ParameterMapType;
// Component parameter map that sits on a node in the graph
// and holds component configuration settings
struct ComponentPropertyType { struct ComponentPropertyType {
ParameterMapType parameterMap; ParameterMapType parameterMap;
}; };
// Component parameter map that sits on an edge in the graph
// and holds component configuration settings
struct ConnectionPropertyType { struct ConnectionPropertyType {
ParameterMapType parameterMap; ParameterMapType parameterMap;
}; };
...@@ -33,24 +37,39 @@ public: ...@@ -33,24 +37,39 @@ public:
boost::vecS, boost::vecS,
boost::directedS, boost::directedS,
ComponentPropertyType, ComponentPropertyType,
ConnectionPropertyType > GraphType; ConnectionPropertyType > GraphType;
typedef boost::graph_traits< GraphType >::vertex_descriptor ComponentIndexType; typedef boost::graph_traits< GraphType >::vertex_descriptor ComponentIndexType;
typedef boost::graph_traits< GraphType >::vertex_iterator ComponentIterator, ComponentIteratorEnd; typedef boost::graph_traits< GraphType >::vertex_iterator ComponentIteratorType;
typedef std::pair< ComponentIteratorType, ComponentIteratorType > ComponentIteratorPairType;
typedef boost::graph_traits< GraphType >::edge_descriptor ConnectionIndexType; typedef boost::graph_traits< GraphType >::edge_descriptor ConnectionIndexType;
typedef boost::graph_traits< GraphType >::edge_iterator ConnectionIterator, ConnectionIteratorEnd; typedef boost::graph_traits< GraphType >::edge_iterator ConnectionIteratorType;
typedef std::pair< ConnectionIteratorType, ConnectionIteratorType > ConnectionIteratorPairType;
typedef boost::graph_traits< GraphType >::in_edge_iterator InputIterator, InputIteratorEnd; typedef boost::graph_traits< GraphType >::in_edge_iterator InputIteratorType;
typedef boost::graph_traits< GraphType >::out_edge_iterator OutputIterator, OutputIteratorEnd; typedef std::pair< InputIteratorType, InputIteratorType > InputIteratorPairType;
typedef boost::graph_traits< GraphType >::out_edge_iterator OutputIteratorType;
typedef std::pair< OutputIteratorType, OutputIteratorType > OutputIteratorPairType;
// Interface for managing components
ComponentIndexType AddComponent( void ); ComponentIndexType AddComponent( void );
ComponentIndexType AddComponent( ParameterMapType parameterMap ); ComponentIndexType AddComponent( ParameterMapType parameterMap );
ParameterMapType GetComponent( ComponentIndexType componentDescriptor ); ParameterMapType GetComponent( ComponentIndexType index );
void SetComponent( ComponentIndexType, ParameterMapType parameterMap ); bool SetComponent( ComponentIndexType, ParameterMapType parameterMap );
void DeleteComponent( ComponentIndexType );
bool ComponentExist( ComponentIndexType index );
ComponentIteratorPairType GetComponentIterator( void ) {
return boost::vertices(this->m_Graph);
}
const ParameterMapType& operator[]( ComponentIndexType index ) { // Returns the outgoing connections from a component in the graph,
return this->GetComponent( index ); // i.e. all components that reads data from given component
OutputIteratorPairType GetOuptutIterator( const ComponentIndexType index ) {
return boost::out_edges(index, this->m_Graph);
} }
private: private:
......
...@@ -13,7 +13,6 @@ Blueprint ...@@ -13,7 +13,6 @@ Blueprint
{ {
this->Modified(); this->Modified();
// Create vertex
ComponentIndexType index = boost::add_vertex( this->m_Graph ); ComponentIndexType index = boost::add_vertex( this->m_Graph );
// Return component index so component can retrieved at a later time // Return component index so component can retrieved at a later time
...@@ -26,10 +25,7 @@ Blueprint ...@@ -26,10 +25,7 @@ Blueprint
{ {
this->Modified(); this->Modified();
// Create vertex
ComponentIndexType index = boost::add_vertex( this->m_Graph ); ComponentIndexType index = boost::add_vertex( this->m_Graph );
// Add parameter map to vertex
this->m_Graph[index].parameterMap = parameterMap; this->m_Graph[index].parameterMap = parameterMap;
// Return component index so component can retrieved at a later time // Return component index so component can retrieved at a later time
...@@ -41,56 +37,47 @@ Blueprint ...@@ -41,56 +37,47 @@ Blueprint
::GetComponent( ComponentIndexType index ) ::GetComponent( ComponentIndexType index )
{ {
this->Modified(); this->Modified();
return this->m_Graph[index].parameterMap;
if( this->ComponentExist( index ) ) {
return this->m_Graph[index].parameterMap;
} else {
itkExceptionMacro( "Blueprint does not contain component with index " << index );
}
} }
void bool
Blueprint Blueprint
::SetComponent( ComponentIndexType index, ParameterMapType parameterMap ) ::SetComponent( ComponentIndexType index, ParameterMapType parameterMap )
{ {
this->Modified(); this->Modified();
this->m_Graph[index].parameterMap = parameterMap;
}
/* if( this->ComponentExist( index ) )
void {
Blueprint this->m_Graph[index].parameterMap = parameterMap;
::RemoveComponent( ComponentIndexType component ) } else {
{ itkExceptionMacro( "Blueprint does not contain component with index " << index )
this->Modified(); }
clear_vertex(u, this->m_Graph);
remove_vertex(u, this->m_Graph);
} }
/*
void void
Blueprint Blueprint
::SetConnection( ComponentDescriptor upstream, ComponentDescriptor downstream ) ::DeleteComponent( const ComponentIndexType index )
{ {
this->Modified(); this->Modified();
}
void if( this->ComponentExist( index ) ) {
Blueprint clear_vertex( index, this->m_Graph );
::GetConnection( ConnectionDescriptorType Connection ) remove_vertex( index, this->m_Graph );
{ }
this->Modified();
} }
void bool
Blueprint Blueprint
::RemoveConnection( ConnectionDescriptorType connection ) ::ComponentExist( ComponentIndexType index )
{ {
this->Modified(); return boost::vertex( index, this->m_Graph ) == boost::graph_traits< GraphType >::null_vertex();
} }
*/
// Blueprint::ComponentDescriptorType
// Blueprint
// ::GetComponentDescriptor( ComponentIndexType componentIndex )
// {
// }
// void // void
// Blueprint // Blueprint
......
...@@ -2,29 +2,62 @@ ...@@ -2,29 +2,62 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "itkImage.h"
namespace elx { namespace elx {
TEST( Blueprint, Instantiation ) class BlueprintTest : public ::testing::Test {
public:
typedef Blueprint::Pointer BlueprintPointerType;
typedef Blueprint::ComponentIndexType ComponentIndexType;
typedef Blueprint::ParameterMapType ParameterMapType;
typedef Blueprint::ParameterValueType ParameterValueType;
virtual void SetUp() {
parameterMap["ComponentName"] = ParameterValueType(1, "TestName");
}
ParameterMapType parameterMap;
};
TEST_F( BlueprintTest, Add )
{ {
typedef Blueprint BlueprintType; BlueprintPointerType blueprint;
BlueprintType::Pointer blueprint; EXPECT_NO_THROW( blueprint = Blueprint::New() );
EXPECT_NO_THROW( blueprint = BlueprintType::New() );
ComponentIndexType index0;
BlueprintType::ParameterMapType parameterMap; EXPECT_NO_THROW( index0 = blueprint->AddComponent() );
EXPECT_NO_THROW( parameterMap["ComponentName"] = BlueprintType::ParameterValueType(1, "AdvancedMeanSquares") ); EXPECT_EQ( Blueprint::ComponentIndexType(0), index0 );
BlueprintType::ComponentIndexType index; ComponentIndexType index1;
EXPECT_NO_THROW( index = blueprint->AddComponent() ); EXPECT_NO_THROW( index1 = blueprint->AddComponent( parameterMap ) );
EXPECT_EQ( BlueprintType::ComponentIndexType(0), index ); EXPECT_EQ( Blueprint::ComponentIndexType(1), index1 );
Blueprint::ComponentIteratorPairType componentIterator = blueprint->GetComponentIterator();
}
EXPECT_NO_THROW( index = blueprint->AddComponent( parameterMap ) ); TEST_F( BlueprintTest, Get )
EXPECT_EQ( BlueprintType::ComponentIndexType(1), index ); {
BlueprintPointerType blueprint = Blueprint::New();
ComponentIndexType index = blueprint->AddComponent( parameterMap );
ParameterMapType parameterMapTest;
EXPECT_NO_THROW( parameterMapTest = blueprint->GetComponent( index ) );
EXPECT_EQ( parameterMap["ComponentName"], parameterMapTest["ComponentName"] );
}
TEST_F( BlueprintTest, Delete )
{
BlueprintPointerType blueprint = Blueprint::New();
ComponentIndexType index = blueprint->AddComponent( parameterMap );
BlueprintType::ParameterMapType parameterMapTest; ParameterMapType parameterMapTest;
EXPECT_NO_THROW( parameterMapTest = blueprint->GetComponent( index ) ); EXPECT_NO_THROW( parameterMapTest = blueprint->GetComponent( index ) );
EXPECT_EQ( parameterMap["ComponentName"], parameterMapTest["ComponentName"] ); EXPECT_EQ( parameterMap["ComponentName"], parameterMapTest["ComponentName"] );
blueprint[index]; EXPECT_NO_THROW( blueprint->DeleteComponent( index ) );
parameterMapTest = blueprint->GetComponent( index );
} }
} // namespace elx } // namespace elx
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment