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

ENH: Add elastix module api

parent 8db4df61
No related branches found
No related tags found
No related merge requests found
Showing
with 165 additions and 29 deletions
macro( ElastixComponent COMPONENT )
ElastixModuleCheckName( ${COMPONENT} )
set( ELASTIX_COMPONENT_{$COMPONENT}_DEFINED TRUE )
endmacro()
macro( ElastixComponentCheckName COMPONENT )
if( NOT "${_name}" MATCHES "^[a-zA-Z][a-zA-Z0-9]*$" )
message( FATAL_ERROR "Invalid component name: ${COMPONENT}" )
endif()
endmacro()
\ No newline at end of file
# ---------------------------------------------------------------------
# Private helper macros
macro( _elxmodule_check_name MODULE )
if( NOT "${_name}" MATCHES "^[a-zA-Z_]*$" )
message( FATAL_ERROR "Invalid module name: ${MODULE}" )
endif()
list( FIND ELXMODULE_ALL "${MODULE}" MODULE_FOUND )
if( ${MODULE_FOUND} EQUAL -1 )
message( FATAL_ERROR "Module not found: ${MODULE}")
endif()
endmacro()
macro( _elxmodule_enable MODULE )
_elxmodule_check_name( ${MODULE} )
if( NOT ${MODULE}_ENABLED )
set( "${MODULE}_ENABLED" ON )
add_subdirectory( "${${MODULE}_SOURCE_DIR}" )
if( ${MODULE}_INCLUDE_DIRS )
include_directories( ${${MODULE}_INCLUDE_DIRS} )
endif()
if( ${MODULE}_LIBRARIES )
link_directories( ${${MODULE}_LIBRARY_DIR} )
endif()
if( ${${MODULE}_LIBRARIES} )
list( APPEND ELASTIX_LIBRARIES
${${MODULE}_LIBRARIES}
)
endif()
# TODO: Add recursive dependency walk
# foreach( DEPENDENCY IN LISTS ${MODULE}_DEPENDS )
# _elxmodule_enable( ${DEPENDENCY} )
# endforeach()
endif()
endmacro()
macro( _elxmodule_disable MODULE )
# TODO
endmacro()
macro( _elxmodules_initialize )
set( ELXMODULE_ALL )
file( GLOB MODULE_FILES RELATIVE "${CMAKE_SOURCE_DIR}"
"${CMAKE_SOURCE_DIR}/Modules/*/ELXMODULE_*.cmake"
)
message( STATUS "Found the following elastix modules:")
foreach( MODULE_FILE ${MODULE_FILES})
get_filename_component( MODULE_PATH ${MODULE_FILE} PATH )
get_filename_component( MODULE ${MODULE_FILE} NAME_WE )
message( STATUS " ${MODULE}" )
option( "USE_${MODULE}" OFF )
set( "${MODULE}_ENABLED" OFF )
set( ${MODULE}_SOURCE_DIR ${CMAKE_SOURCE_DIR}/${MODULE_PATH} )
set( ${MODULE}_BINARY_DIR ${CMAKE_BINARY_DIR}/${MODULE_PATH} )
set( ${MODULE}_LIBRARIES )
list(APPEND ELXMODULE_ALL ${MODULE} )
endforeach()
endmacro()
_elxmodules_initialize()
# ---------------------------------------------------------------------
# Public interface
macro( elxmodule_enable MODULE )
option( USE_${MODULE} ON )
_elxmodule_enable( ${MODULE} )
endmacro()
add_subdirectory(
Core
)
include_directories( include ) include_directories( include )
add_subdirectory( src )
...@@ -22,19 +22,14 @@ public: ...@@ -22,19 +22,14 @@ public:
typedef TComponentDescriptor ComponentDescriptorType; typedef TComponentDescriptor ComponentDescriptorType;
typedef typename TComponentDescriptor::ComponentNameType ComponentNameType; typedef typename TComponentDescriptor::ComponentNameType ComponentNameType;
typedef boost::adjacency_list< boost::listS, typedef boost::adjacency_list< boost::vecS,
boost::listS, boost::vecS,
boost::directedS, boost::directedS,
ComponentDescriptorType > GraphType; ComponentDescriptorType > GraphType;
typedef typename boost::graph_traits< GraphType >::vertex_descriptor ComponentType; typedef typename boost::graph_traits< GraphType >::vertex_descriptor ComponentType;
typedef typename boost::graph_traits< GraphType >::vertex_iterator ComponentIterator, ComponentIteratorEnd; typedef typename boost::graph_traits< GraphType >::vertex_iterator ComponentIterator, ComponentIteratorEnd;
// TODO: Why can't we get the vertex index map type like they show in
// http://www.boost.org/doc/libs/1_38_0/libs/graph/doc/quick_tour.html
// under "Access Vertex Set"?
typedef boost::vertex_index_t ComponentIndexType; typedef boost::vertex_index_t ComponentIndexType;
typedef typename boost::property_map< GraphType, ComponentIndexType >::type ComponentIndexMapType; typedef typename boost::property_map< GraphType, ComponentIndexType >::type ComponentIndexMapType;
...@@ -44,12 +39,17 @@ public: ...@@ -44,12 +39,17 @@ public:
typedef typename boost::graph_traits< GraphType >::in_edge_iterator InputIterator, InputIteratorEnd; typedef typename boost::graph_traits< GraphType >::in_edge_iterator InputIterator, InputIteratorEnd;
typedef typename boost::graph_traits< GraphType >::out_edge_iterator OutputIterator, OutputIteratorEnd; typedef typename boost::graph_traits< GraphType >::out_edge_iterator OutputIterator, OutputIteratorEnd;
int TestFunction( void );
bool AddComponent( ComponentDescriptorType component ); bool AddComponent( ComponentDescriptorType component );
// bool SetComponent( ComponentIndexType componentIndex, ComponentDescriptorType component ); bool SetComponent( ComponentIndexType componentIndex, ComponentDescriptorType component );
// ComponentDescriptorType GetComponent( ComponentIndexType componentIndex ); ComponentDescriptorType GetComponent( ComponentIndexType componentIndex );
bool RemoveComponent( ComponentDescriptorType component );
// bool SetConnection( ComponentIndexType upstream, ComponentIndexType downstream ); bool SetConnection( ComponentIndexType upstream, ComponentIndexType downstream );
ConnectionDescriptorType GetConnection( ConnectionDescriptorType Connection ); ConnectionDescriptorType GetConnection( ConnectionDescriptorType Connection );
bool RemoveConnection( ConnectionDescriptorType connection );
void PrintGraph( void );
private: private:
......
message( STATUS "In directory ${CMAKE_CURRENT_LIST_DIR}" )
add_library( Blueprints
elxComponentDescriptor.cxx
elxBlueprint.cxx
)
\ No newline at end of file
...@@ -18,25 +18,40 @@ ComponentDescriptorType ...@@ -18,25 +18,40 @@ ComponentDescriptorType
Blueprint< ComponentDescriptor > Blueprint< ComponentDescriptor >
::AddComponent( ComponentDescriptorType component ) ::AddComponent( ComponentDescriptorType component )
{ {
// TODO: Check that the component is in the component::ComponentName is in the ComponentDatabase // TODO: Check that the component is in the ComponentDatabase
this->Modified(); this->Modified();
return this->m_Graph->add_vertex( component ); return this->m_Graph->add_vertex( component );
} }
void bool
Blueprint< ComponentDescriptor >
::SetComponent( ComponentDescriptorType component )
{
this->Modified();
return this->m_Graph->remove_vertex( connection );
}
bool
Blueprint< ComponentDescriptor > Blueprint< ComponentDescriptor >
::RemoveComponent( ComponentDescriptorType component ) ::RemoveComponent( ComponentDescriptorType component )
{ {
this->Modified(); this->Modified();
this->m_Graph->remove_vertex( connection ); return this->m_Graph->remove_vertex( connection );
} }
void bool
Blueprint< ComponentDescriptor > Blueprint< ComponentDescriptor >
::AddConnection( ComponentDescriptorType upsteam, ComponentDescriptorType downstream ) ::AddConnection( ComponentDescriptorType upsteam, ComponentDescriptorType downstream )
{ {
this->Modified(); this->Modified();
this->m_Graph->add_edge( upstream, downstream ); return this->m_Graph->add_edge( upstream, downstream );
}
ConnectionDescriptorType
Blueprint< ComponentDescriptor >
::GetConnection( ConnectionDescriptorType Connection )
{
this->Modified();
} }
void void
...@@ -47,11 +62,18 @@ Blueprint< ComponentDescriptor > ...@@ -47,11 +62,18 @@ Blueprint< ComponentDescriptor >
this->m_Graph->remove_edge( connection ); this->m_Graph->remove_edge( connection );
} }
void Blueprint< ComponentDescriptor > void
::PrintSelf( void ) Blueprint< ComponentDescriptor >
::PrintGraph( void )
{ {
boost::write_graphviz(std::cout, this->m_Graph); // TODO: Link to graphviz library
// boost::write_graphviz(std::cout, this->m_Graph);
std::cout << "Printed graph" << std::endl;
} }
void
Blueprint< ComponentDescriptor >
::TestFunction( void )
{ return 0; }
} }
......
project( ELXMODULE_CORE )
# TODO: Include directures using the module API
include_directories(
Common/include
Blueprints/include
)
add_subdirectory( Common ) add_subdirectory( Common )
add_subdirectory( BluePrints ) add_subdirectory( Blueprints )
set( "${PROJECT_NAME}_LIBRARIES"
Blueprints
)
set( DOCUMENTATION
"This module contains the core components of elastix library such as the component database and component pipeline instantiation functionality."
)
elxmodule_enable( ELXMODULE_CORE
DEPENDS
ELXMODULE_COMMON
DESCRIPTION
"${DOCUMENTATION}"
)
include_directories( include )
#ifndef __ElastixFilter_h
#define __ElastixFilter_h
#endif // #define __ElastixFilter_h
\ No newline at end of file
...@@ -34,7 +34,6 @@ configure_file( ...@@ -34,7 +34,6 @@ configure_file(
) )
include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
add_library( DataManager elxDataManager.cxx ) add_library( DataManager elxDataManager.cxx )
list( APPEND TEST_LIBRARIES list( APPEND TEST_LIBRARIES
......
...@@ -19,6 +19,8 @@ TEST( Blueprint, Instantiation ) ...@@ -19,6 +19,8 @@ TEST( Blueprint, Instantiation )
EXPECT_NO_THROW( componentName = ComponentNameType("Metric") ); EXPECT_NO_THROW( componentName = ComponentNameType("Metric") );
EXPECT_NO_THROW( componentDescriptor->SetComponentName( componentName ) ); EXPECT_NO_THROW( componentDescriptor->SetComponentName( componentName ) );
EXPECT_NO_THROW( blueprint->TestFunction() );
ASSERT_TRUE( true ); ASSERT_TRUE( true );
} }
......
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