diff --git a/Modules/Core/Blueprints/include/elxBlueprint.h b/Modules/Core/Blueprints/include/elxBlueprint.h index 81b2c92a9cc0d25bd473206293ac7e38b8ac1ca3..bf31c28e2c9333f1e391d385ed9cf585241b50bd 100644 --- a/Modules/Core/Blueprints/include/elxBlueprint.h +++ b/Modules/Core/Blueprints/include/elxBlueprint.h @@ -21,10 +21,14 @@ public: typedef std::vector< std::string > ParameterValueType; typedef std::map< ParameterKeyType, ParameterValueType > ParameterMapType; + // Component parameter map that sits on a node in the graph + // and holds component configuration settings struct ComponentPropertyType { ParameterMapType parameterMap; }; + // Component parameter map that sits on an edge in the graph + // and holds component configuration settings struct ConnectionPropertyType { ParameterMapType parameterMap; }; @@ -33,24 +37,39 @@ public: boost::vecS, boost::directedS, ComponentPropertyType, - ConnectionPropertyType > GraphType; + ConnectionPropertyType > GraphType; - typedef boost::graph_traits< GraphType >::vertex_descriptor ComponentIndexType; - typedef boost::graph_traits< GraphType >::vertex_iterator ComponentIterator, ComponentIteratorEnd; + typedef boost::graph_traits< GraphType >::vertex_descriptor ComponentIndexType; + 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_iterator ConnectionIterator, ConnectionIteratorEnd; + typedef boost::graph_traits< GraphType >::edge_descriptor ConnectionIndexType; + 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 >::out_edge_iterator OutputIterator, OutputIteratorEnd; + typedef boost::graph_traits< GraphType >::in_edge_iterator InputIteratorType; + 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( ParameterMapType parameterMap ); - ParameterMapType GetComponent( ComponentIndexType componentDescriptor ); - void SetComponent( ComponentIndexType, ParameterMapType parameterMap ); + ParameterMapType GetComponent( ComponentIndexType index ); + 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 ) { - return this->GetComponent( index ); + // Returns the outgoing connections from a component in the graph, + // i.e. all components that reads data from given component + OutputIteratorPairType GetOuptutIterator( const ComponentIndexType index ) { + return boost::out_edges(index, this->m_Graph); } private: diff --git a/Modules/Core/Blueprints/src/elxBlueprint.cxx b/Modules/Core/Blueprints/src/elxBlueprint.cxx index 26ed00a19dcf8f59d632a0c2d056ef21205abf11..15223014e343439944fad11ec6fa1462f773b7f5 100644 --- a/Modules/Core/Blueprints/src/elxBlueprint.cxx +++ b/Modules/Core/Blueprints/src/elxBlueprint.cxx @@ -13,7 +13,6 @@ Blueprint { this->Modified(); - // Create vertex ComponentIndexType index = boost::add_vertex( this->m_Graph ); // Return component index so component can retrieved at a later time @@ -26,10 +25,7 @@ Blueprint { this->Modified(); - // Create vertex ComponentIndexType index = boost::add_vertex( this->m_Graph ); - - // Add parameter map to vertex this->m_Graph[index].parameterMap = parameterMap; // Return component index so component can retrieved at a later time @@ -41,56 +37,47 @@ Blueprint ::GetComponent( ComponentIndexType index ) { 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 ::SetComponent( ComponentIndexType index, ParameterMapType parameterMap ) { this->Modified(); - this->m_Graph[index].parameterMap = parameterMap; -} -/* -void -Blueprint -::RemoveComponent( ComponentIndexType component ) -{ - this->Modified(); - clear_vertex(u, this->m_Graph); - remove_vertex(u, this->m_Graph); + if( this->ComponentExist( index ) ) + { + this->m_Graph[index].parameterMap = parameterMap; + } else { + itkExceptionMacro( "Blueprint does not contain component with index " << index ) + } } -/* void Blueprint -::SetConnection( ComponentDescriptor upstream, ComponentDescriptor downstream ) +::DeleteComponent( const ComponentIndexType index ) { this->Modified(); -} -void -Blueprint -::GetConnection( ConnectionDescriptorType Connection ) -{ - this->Modified(); + if( this->ComponentExist( index ) ) { + clear_vertex( index, this->m_Graph ); + remove_vertex( index, this->m_Graph ); + } } -void +bool 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 // Blueprint diff --git a/Testing/Unit/elxBluePrintTest.cxx b/Testing/Unit/elxBluePrintTest.cxx index 4f299bc679512ab550d1a9eac669080f19f56501..a84004913e2d322658ad8ed80ab4c10f5e35f09b 100644 --- a/Testing/Unit/elxBluePrintTest.cxx +++ b/Testing/Unit/elxBluePrintTest.cxx @@ -2,29 +2,62 @@ #include "gtest/gtest.h" +#include "itkImage.h" + 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; - BlueprintType::Pointer blueprint; - EXPECT_NO_THROW( blueprint = BlueprintType::New() ); - - BlueprintType::ParameterMapType parameterMap; - EXPECT_NO_THROW( parameterMap["ComponentName"] = BlueprintType::ParameterValueType(1, "AdvancedMeanSquares") ); + BlueprintPointerType blueprint; + EXPECT_NO_THROW( blueprint = Blueprint::New() ); + + ComponentIndexType index0; + EXPECT_NO_THROW( index0 = blueprint->AddComponent() ); + EXPECT_EQ( Blueprint::ComponentIndexType(0), index0 ); - BlueprintType::ComponentIndexType index; - EXPECT_NO_THROW( index = blueprint->AddComponent() ); - EXPECT_EQ( BlueprintType::ComponentIndexType(0), index ); + ComponentIndexType index1; + EXPECT_NO_THROW( index1 = blueprint->AddComponent( parameterMap ) ); + EXPECT_EQ( Blueprint::ComponentIndexType(1), index1 ); + + Blueprint::ComponentIteratorPairType componentIterator = blueprint->GetComponentIterator(); +} - EXPECT_NO_THROW( index = blueprint->AddComponent( parameterMap ) ); - EXPECT_EQ( BlueprintType::ComponentIndexType(1), index ); +TEST_F( BlueprintTest, Get ) +{ + 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_EQ( parameterMap["ComponentName"], parameterMapTest["ComponentName"] ); - blueprint[index]; + EXPECT_NO_THROW( blueprint->DeleteComponent( index ) ); + parameterMapTest = blueprint->GetComponent( index ); } } // namespace elx