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:
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:
......
......@@ -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
......
......@@ -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
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