From 54a1c805cb615fdcd38cb9c4ccda1a22f3c87fbc Mon Sep 17 00:00:00 2001 From: Kasper Marstal <kaspermarstal@gmail.com> Date: Fri, 2 Oct 2015 16:02:25 +0200 Subject: [PATCH] ENH: Add elastix module api --- CMake/elxComponent.cmake | 10 +++ CMake/elxModules.cmake | 82 +++++++++++++++++++ Modules/CMakeLists.txt | 3 - Modules/Core/Blueprints/CMakeLists.txt | 1 + .../Core/Blueprints/include/elxBlueprint.h | 20 ++--- Modules/Core/Blueprints/src/CMakeLists.txt | 6 ++ .../{elxBlueprint.hxx => elxBlueprint.cxx} | 38 +++++++-- ...criptor.hxx => elxComponentDescriptor.cxx} | 0 Modules/Core/CMakeLists.txt | 15 +++- Modules/Core/ELXMODULE_CORE.cmake | 10 +++ Modules/Core/ElastixFilter/CMakeLists.txt | 1 - .../ElastixFilter/include/elxElastixFilter.h | 5 -- Testing/Unit/CMakeLists.txt | 1 - Testing/Unit/elxBluePrintTest.cxx | 2 + 14 files changed, 165 insertions(+), 29 deletions(-) create mode 100644 CMake/elxComponent.cmake create mode 100644 CMake/elxModules.cmake delete mode 100644 Modules/CMakeLists.txt create mode 100644 Modules/Core/Blueprints/src/CMakeLists.txt rename Modules/Core/Blueprints/src/{elxBlueprint.hxx => elxBlueprint.cxx} (53%) rename Modules/Core/Blueprints/src/{elxComponentDescriptor.hxx => elxComponentDescriptor.cxx} (100%) create mode 100644 Modules/Core/ELXMODULE_CORE.cmake delete mode 100644 Modules/Core/ElastixFilter/CMakeLists.txt delete mode 100644 Modules/Core/ElastixFilter/include/elxElastixFilter.h diff --git a/CMake/elxComponent.cmake b/CMake/elxComponent.cmake new file mode 100644 index 00000000..4fd04dfb --- /dev/null +++ b/CMake/elxComponent.cmake @@ -0,0 +1,10 @@ +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 diff --git a/CMake/elxModules.cmake b/CMake/elxModules.cmake new file mode 100644 index 00000000..1e4955cb --- /dev/null +++ b/CMake/elxModules.cmake @@ -0,0 +1,82 @@ +# --------------------------------------------------------------------- +# 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() + + diff --git a/Modules/CMakeLists.txt b/Modules/CMakeLists.txt deleted file mode 100644 index 3c6212d3..00000000 --- a/Modules/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_subdirectory( - Core -) diff --git a/Modules/Core/Blueprints/CMakeLists.txt b/Modules/Core/Blueprints/CMakeLists.txt index b83cfce3..88e196eb 100644 --- a/Modules/Core/Blueprints/CMakeLists.txt +++ b/Modules/Core/Blueprints/CMakeLists.txt @@ -1 +1,2 @@ include_directories( include ) +add_subdirectory( src ) diff --git a/Modules/Core/Blueprints/include/elxBlueprint.h b/Modules/Core/Blueprints/include/elxBlueprint.h index 9531a695..8b42694b 100644 --- a/Modules/Core/Blueprints/include/elxBlueprint.h +++ b/Modules/Core/Blueprints/include/elxBlueprint.h @@ -22,19 +22,14 @@ public: typedef TComponentDescriptor ComponentDescriptorType; typedef typename TComponentDescriptor::ComponentNameType ComponentNameType; - typedef boost::adjacency_list< boost::listS, - boost::listS, + typedef boost::adjacency_list< boost::vecS, + boost::vecS, boost::directedS, ComponentDescriptorType > GraphType; typedef typename boost::graph_traits< GraphType >::vertex_descriptor ComponentType; 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 typename boost::property_map< GraphType, ComponentIndexType >::type ComponentIndexMapType; @@ -44,12 +39,17 @@ public: typedef typename boost::graph_traits< GraphType >::in_edge_iterator InputIterator, InputIteratorEnd; typedef typename boost::graph_traits< GraphType >::out_edge_iterator OutputIterator, OutputIteratorEnd; + int TestFunction( void ); bool AddComponent( ComponentDescriptorType component ); - // bool SetComponent( ComponentIndexType componentIndex, ComponentDescriptorType component ); - // ComponentDescriptorType GetComponent( ComponentIndexType componentIndex ); + bool SetComponent( ComponentIndexType componentIndex, ComponentDescriptorType component ); + ComponentDescriptorType GetComponent( ComponentIndexType componentIndex ); + bool RemoveComponent( ComponentDescriptorType component ); - // bool SetConnection( ComponentIndexType upstream, ComponentIndexType downstream ); + bool SetConnection( ComponentIndexType upstream, ComponentIndexType downstream ); ConnectionDescriptorType GetConnection( ConnectionDescriptorType Connection ); + bool RemoveConnection( ConnectionDescriptorType connection ); + + void PrintGraph( void ); private: diff --git a/Modules/Core/Blueprints/src/CMakeLists.txt b/Modules/Core/Blueprints/src/CMakeLists.txt new file mode 100644 index 00000000..28d535fe --- /dev/null +++ b/Modules/Core/Blueprints/src/CMakeLists.txt @@ -0,0 +1,6 @@ +message( STATUS "In directory ${CMAKE_CURRENT_LIST_DIR}" ) + +add_library( Blueprints + elxComponentDescriptor.cxx + elxBlueprint.cxx +) \ No newline at end of file diff --git a/Modules/Core/Blueprints/src/elxBlueprint.hxx b/Modules/Core/Blueprints/src/elxBlueprint.cxx similarity index 53% rename from Modules/Core/Blueprints/src/elxBlueprint.hxx rename to Modules/Core/Blueprints/src/elxBlueprint.cxx index d5be04e6..2c7e3d32 100644 --- a/Modules/Core/Blueprints/src/elxBlueprint.hxx +++ b/Modules/Core/Blueprints/src/elxBlueprint.cxx @@ -18,25 +18,40 @@ ComponentDescriptorType Blueprint< ComponentDescriptor > ::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(); 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 > ::RemoveComponent( ComponentDescriptorType component ) { this->Modified(); - this->m_Graph->remove_vertex( connection ); + return this->m_Graph->remove_vertex( connection ); } -void +bool Blueprint< ComponentDescriptor > ::AddConnection( ComponentDescriptorType upsteam, ComponentDescriptorType downstream ) { 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 @@ -47,11 +62,18 @@ Blueprint< ComponentDescriptor > this->m_Graph->remove_edge( connection ); } -void Blueprint< ComponentDescriptor > -::PrintSelf( void ) +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; } } diff --git a/Modules/Core/Blueprints/src/elxComponentDescriptor.hxx b/Modules/Core/Blueprints/src/elxComponentDescriptor.cxx similarity index 100% rename from Modules/Core/Blueprints/src/elxComponentDescriptor.hxx rename to Modules/Core/Blueprints/src/elxComponentDescriptor.cxx diff --git a/Modules/Core/CMakeLists.txt b/Modules/Core/CMakeLists.txt index e8a5c060..d45d6001 100644 --- a/Modules/Core/CMakeLists.txt +++ b/Modules/Core/CMakeLists.txt @@ -1,2 +1,15 @@ +project( ELXMODULE_CORE ) + +# TODO: Include directures using the module API +include_directories( + Common/include + Blueprints/include +) + add_subdirectory( Common ) -add_subdirectory( BluePrints ) +add_subdirectory( Blueprints ) + +set( "${PROJECT_NAME}_LIBRARIES" + Blueprints +) + diff --git a/Modules/Core/ELXMODULE_CORE.cmake b/Modules/Core/ELXMODULE_CORE.cmake new file mode 100644 index 00000000..f0ed9132 --- /dev/null +++ b/Modules/Core/ELXMODULE_CORE.cmake @@ -0,0 +1,10 @@ +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}" +) diff --git a/Modules/Core/ElastixFilter/CMakeLists.txt b/Modules/Core/ElastixFilter/CMakeLists.txt deleted file mode 100644 index b83cfce3..00000000 --- a/Modules/Core/ElastixFilter/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -include_directories( include ) diff --git a/Modules/Core/ElastixFilter/include/elxElastixFilter.h b/Modules/Core/ElastixFilter/include/elxElastixFilter.h deleted file mode 100644 index 99dc4e66..00000000 --- a/Modules/Core/ElastixFilter/include/elxElastixFilter.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef __ElastixFilter_h -#define __ElastixFilter_h - - -#endif // #define __ElastixFilter_h \ No newline at end of file diff --git a/Testing/Unit/CMakeLists.txt b/Testing/Unit/CMakeLists.txt index b7bd9cc7..1ed2189d 100644 --- a/Testing/Unit/CMakeLists.txt +++ b/Testing/Unit/CMakeLists.txt @@ -34,7 +34,6 @@ configure_file( ) include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) - add_library( DataManager elxDataManager.cxx ) list( APPEND TEST_LIBRARIES diff --git a/Testing/Unit/elxBluePrintTest.cxx b/Testing/Unit/elxBluePrintTest.cxx index 5451c97b..31dc1d8e 100644 --- a/Testing/Unit/elxBluePrintTest.cxx +++ b/Testing/Unit/elxBluePrintTest.cxx @@ -19,6 +19,8 @@ TEST( Blueprint, Instantiation ) EXPECT_NO_THROW( componentName = ComponentNameType("Metric") ); EXPECT_NO_THROW( componentDescriptor->SetComponentName( componentName ) ); + EXPECT_NO_THROW( blueprint->TestFunction() ); + ASSERT_TRUE( true ); } -- GitLab