diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f8add9d1a7234d12336d0a83aa682e1ac8ba748..e07eb5ed5be40447c5e655d1d3130757baf61166 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,11 @@ find_package( ITK REQUIRED ) include( ${ITK_USE_FILE} ) include( "${CMAKE_CURRENT_SOURCE_DIR}/CMake/elxITKRequiredModules.cmake" ) +# --------------------------------------------------------------------- +# Boost Graph Library +find_package( Boost REQUIRED graph ) +include_directories(${Boost_INCLUDE_DIRS}) + # --------------------------------------------------------------------- # Build Elastix diff --git a/Modules/Core/Blueprints/CMakeLists.txt b/Modules/Core/Blueprints/CMakeLists.txt index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b83cfce3b85bc48c4c713194051c1e70655c7a95 100644 --- a/Modules/Core/Blueprints/CMakeLists.txt +++ b/Modules/Core/Blueprints/CMakeLists.txt @@ -0,0 +1 @@ +include_directories( include ) diff --git a/Modules/Core/Blueprints/include/elxBlueprint.h b/Modules/Core/Blueprints/include/elxBlueprint.h new file mode 100644 index 0000000000000000000000000000000000000000..0272082103ed9ec4a0fff5b08b673652f74a2e4b --- /dev/null +++ b/Modules/Core/Blueprints/include/elxBlueprint.h @@ -0,0 +1,55 @@ +#ifndef __Blueprint_h +#define __Blueprint_h + +#include "itkObjectFactory.h" +#include "itkDataObject.h" + +#include "elxMacro.h" +#include "elxComponentDescriptor.h" + +#include "boost/graph/graph_traits.hpp" +#include "boost/graph/directed_graph.hpp" + +namespace elx { + +template< class TComponentDescriptor > +class Blueprint : public itk::DataObject +{ +public: + + elxNewMacro( Blueprint, itk::DataObject ); + + typedef TComponentDescriptor ComponentDescriptorType; + + typedef boost::adjacency_list< boost::listS, + boost::listS, + boost::directedS, + ComponentDescriptorType > GraphType; + + 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 >::edge_descriptor ConnectionDescriptorType; + typedef typename boost::graph_traits< GraphType >::edge_iterator ConnectionIterator, ConnectionIteratorEnd; + + typedef typename boost::graph_traits< GraphType >::in_edge_iterator InputIterator, InputIteratorEnd; + typedef typename boost::graph_traits< GraphType >::out_edge_iterator OutputIterator, OutputIteratorEnd; + + void SetGraph( GraphType graph ) { this->m_Graph = graph; }; + GraphType GetGraph( void ) const { return m_Graph; }; + + void AddComponent( ComponentDescriptorType component ); + void RemoveComponent( ComponentDescriptorType component ); + + void AddConnection( ComponentDescriptorType upstream, ComponentDescriptorType downstream ); + void RemoveConnection( ConnectionDescriptorType connection ); + +private: + + GraphType m_Graph; + +}; + +} + +#endif // #define __Blueprint_h \ No newline at end of file diff --git a/Modules/Core/Blueprints/include/elxComponentDescriptor.h b/Modules/Core/Blueprints/include/elxComponentDescriptor.h new file mode 100644 index 0000000000000000000000000000000000000000..c6ace2d9145d0b5d0e21cebcc025c50b4f47fae7 --- /dev/null +++ b/Modules/Core/Blueprints/include/elxComponentDescriptor.h @@ -0,0 +1,30 @@ +#ifndef __ComponentDescriptor_h +#define __ComponentDescriptor_h + +#include "elxMacro.h" +#include "itkLightObject.h" + +namespace elx { + +class ComponentDescriptor : public itk::LightObject +{ +public: + + elxNewMacro( ComponentDescriptor, itk::LightObject ); + + typedef std::string ComponentNameType; + typedef std::map< std::string, std::vector< std::string > > ParameterMapType; + + void SetComponentName( ComponentNameType componentName ) { this->m_ComponentName = componentName; }; + ComponentNameType GetComponentName( void ) { return this->m_ComponentName; }; + +private: + + ComponentNameType m_ComponentName; + ParameterMapType m_ParameterMap; + +}; + +} + +#endif // __ComponentDescriptor_h \ No newline at end of file diff --git a/Modules/Core/Blueprints/src/elxBlueprint.hxx b/Modules/Core/Blueprints/src/elxBlueprint.hxx new file mode 100644 index 0000000000000000000000000000000000000000..b37fe4d645a030c696709ebdedd8715161bd1022 --- /dev/null +++ b/Modules/Core/Blueprints/src/elxBlueprint.hxx @@ -0,0 +1,57 @@ +#ifndef __Blueprint_hxx +#define __Blueprint_hxx + +#include <boost/graph/graphviz.hpp> + +#include "elxBlueprint.h" + +namespace elastix { + +void +Blueprint< ComponentDescriptor > +::Blueprint( void ) +{ + this->m_Graph = GraphType; +} + +ComponentDescriptorType +Blueprint< ComponentDescriptor > +::AddComponent( ComponentDescriptorType component ) +{ + this->Modified(); + return this->m_Graph->add_vertex( component ); +} + +void +Blueprint< ComponentDescriptor > +::RemoveComponent( ComponentDescriptorType component ) +{ + this->Modified(); + this->m_Graph->remove_vertex( connection ); +} + +void +Blueprint< ComponentDescriptor > +::AddConnection( ComponentDescriptorType upsteam, ComponentDescriptorType downstream ) +{ + this->Modified(); + this->m_Graph->add_edge( upstream, downstream ); +} + +void +Blueprint< ComponentDescriptor > +::RemoveConnection( ConnectionType connection ) +{ + this->Modified(); + this->m_Graph->remove_edge( connection ); +} + +void Blueprint< ComponentDescriptor > +::PrintSelf( void ) +{ + boost::write_graphviz(std::cout, this->m_Graph); +} + +} + +#endif // __Blueprint_hxx \ No newline at end of file diff --git a/Modules/Core/CMakeLists.txt b/Modules/Core/CMakeLists.txt index 84c12fcb3aba7189c16706bc6a7affdded2175ca..e8a5c06069dab934d29f6f749d0ff1a22c355a36 100644 --- a/Modules/Core/CMakeLists.txt +++ b/Modules/Core/CMakeLists.txt @@ -1,2 +1,2 @@ add_subdirectory( Common ) -add_subdirectory( Blueprints ) +add_subdirectory( BluePrints ) diff --git a/SuperBuild/CMakeLists.txt b/SuperBuild/CMakeLists.txt index cff7bb5aec197b58bc119bf198014d2991bd6f36..8ba451e154ff21cad658c0e9ff3686e296d7cee5 100644 --- a/SuperBuild/CMakeLists.txt +++ b/SuperBuild/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required( VERSION 2.8 ) -#--------------------------------------------------------------------- +# --------------------------------------------------------------------- project( ElastixSuperBuild ) find_package( Git REQUIRED ) @@ -15,7 +15,7 @@ set( CMAKE_MODULE_PATH set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH "SuperBuild install directory" FORCE) -#--------------------------------------------------------------------- +# --------------------------------------------------------------------- # Elastix SuperBuild configuration # Build release by default @@ -29,13 +29,16 @@ option( ELASTIX_BUILD_EXAMPLES "Enable building examples." ON ) # Build tests by default option( ELASTIX_BUILD_TESTING "Enable building tests." ON ) - if( ELASTIX_BUILD_TESTING ) option( ELASTIX_BUILD_BENCHMARKING "Enable building benchmarks." ON ) option( ELASTIX_BUILD_DASHBOARD "Enable building benchmarks." ON ) endif() -#--------------------------------------------------------------------- +# Do not build dashboard by default +option( ELASTIX_BUILD_DASHBOARD "Enable building dashboard." OFF ) + + +# --------------------------------------------------------------------- # Build ITK set( ITK_VERSION_MAJOR "4" ) @@ -54,7 +57,18 @@ else() list( APPEND ELASTIX_DEPENDENCIES ITK ) endif() -#--------------------------------------------------------------------- +# --------------------------------------------------------------------- +# Boost Graph Library + +mark_as_advanced( USE_SYSTEM_BOOST ) +option( USE_SYSTEM_BOOST "Use an installed version of BOOST" ON ) +if( USE_SYSTEM_BOOST ) + find_package( BOOST REQUIRED graph ) +else() + message( FATAL_ERROR "BOOST is not yet integrated with the SuperBuild. Install BOOST on your system, set USE_SYSTEM_BOOST to ON and re-run CMake." ) +endif() + +# --------------------------------------------------------------------- # Build Elastix include( Elastix ) diff --git a/SuperBuild/Elastix.cmake b/SuperBuild/Elastix.cmake index d6bf55178d1d5674f14c9a5bd3f3fc7a93dcb3bd..1f1d739399df9111afa2df1d2577b2b4e6e91472 100644 --- a/SuperBuild/Elastix.cmake +++ b/SuperBuild/Elastix.cmake @@ -6,10 +6,12 @@ ExternalProject_Add( ${proj} BINARY_DIR ${proj}-build CMAKE_ARGS --no-warn-unused-cli + -DELASTIX_BUILD_EXAMPLES:BOOL=${ELASTIX_BUILD_EXAMPLES} -DELASTIX_BUILD_TESTING:BOOL=${ELASTIX_BUILD_TESTING} -DELASTIX_BUILD_BENCHMARKING:BOOL=${ELASTIX_BUILD_BENCHMARKING} -DELASTIX_BUILD_DASHBOARD:BOOL=${ELASTIX_BUILD_DASHBOARD} -DITK_DIR:PATH=${ITK_DIR} + -DBOOST_ROOT:PATH=${BOOST_ROOT} DEPENDS ${ELASTIX_DEPENDENCIES} INSTALL_COMMAND "" -) \ No newline at end of file +) diff --git a/Testing/Unit/elxBluePrintTest.cxx b/Testing/Unit/elxBluePrintTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d3cc27feb14fb9118b9c068071dcd9965bb849e5 --- /dev/null +++ b/Testing/Unit/elxBluePrintTest.cxx @@ -0,0 +1,28 @@ +#include "elxBlueprint.h" +#include "elxComponentDescriptor.h" +#include "gtest/gtest.h" + +namespace elx { + +TEST( Blueprint, Instantiation ) +{ + typedef Blueprint< ComponentDescriptor > BlueprintType; + BlueprintType::Pointer blueprint = BlueprintType::New(); + + typedef BlueprintType::ComponentDescriptorType ComponentDescriptorType; + ComponentDescriptorType::Pointer componentDescriptor = ComponentDescriptorType::New(); + + typedef ComponentDescriptorType::ComponentNameType ComponentNameType; + ComponentNameType componentName = ComponentNameType("Metric"); + componentDescriptor->SetComponentName( componentName ); + + // We would like to save all data in the graph itself, but the following is + // not possible because the component (of type itk::LightObject has private copy + // constructor. How do we save data in graph and make this as itk-like as possible? + // Ideally when a component descriptor is changed the blueprint calls Modified() on itself + // blueprint->AddComponent( (*componentDescriptor) ); + + ASSERT_TRUE( true ); +} + +} // namespace elx \ No newline at end of file