Commit bcda98fa authored by Kasper Marstal's avatar Kasper Marstal
Browse files

ENH: Use SuperBuild via find_package(); ENH: Add logger to all components via factory

parents 0fe3b0bf d967936d
......@@ -47,11 +47,15 @@ if (OPENMP_FOUND)
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" )
endif()
find_package( SuperElastixSuperBuild )
include( ${SUPERELASTIXSUPERBUILD_USE_FILE} )
find_package( SuperElastix )
include( ${SUPERELASTIX_USE_FILE} )
find_package( ITK )
include( ${ITK_USE_FILE} )
include( ${ELASTIX_USE_FILE} )
add_subdirectory( CommandLineInterface )
......@@ -29,7 +29,6 @@ set( ${APPLICATION}_SOURCE_FILES
set( ${APPLICATION}_LINK_LIBRARIES
${ITK_LIBRARIES}
elastix transformix
${Boost_LIBRARIES}
)
......
......@@ -46,10 +46,10 @@ include_directories( ${Boost_INCLUDE_DIR} )
# Compile executable
include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/include" )
add_executable( SuperElastix ${COMMANDLINE_SOURCE_FILES} ${COMMANDLINE_HEADER_FILES} )
target_link_libraries( SuperElastix ${SUPERELASTIX_LIBRARIES} ${Boost_LIBRARIES})
target_link_libraries( SuperElastix ${SUPERELASTIX_LIBRARIES} ${Boost_LIBRARIES} ${ITK_LIBRARIES} )
# InstallDemo copies SuperElastix executable, image data, configuration files and bat/bash scripts to the INSTALLDEMO_PREFIX directory
set( INSTALLDEMO_PREFIX ${PROJECT_BINARY_DIR}/Demo CACHE PATH "Demo files will be copied to this directory" )
# demo copies SuperElastix executable, image data, configuration files and bat/bash scripts to the DEMO_PREFIX directory
set( DEMO_PREFIX ${PROJECT_BINARY_DIR}/Demo CACHE PATH "Demo files will be copied to this directory" )
# Download demo data
include( ExternalData )
......@@ -64,30 +64,30 @@ list( APPEND ExternalData_URL_TEMPLATES
file( GLOB_RECURSE DemoDataContentLinks "*.md5" )
foreach( DemoDataContentLink ${DemoDataContentLinks} )
string( REGEX REPLACE "\\.md5$" "" DemoDataContentLink ${DemoDataContentLink} )
ExternalData_Expand_Arguments( InstallDemo
InstallDemoFileName
ExternalData_Expand_Arguments( demo
demoFileName
DATA{${DemoDataContentLink}}
)
list( APPEND InstallDemoFileNames ${InstallDemoFileName} )
list( APPEND demoFileNames ${demoFileName} )
endforeach()
# Create target and reference the external data
ExternalData_Add_Target( InstallDemo )
add_dependencies( InstallDemo SuperElastix )
set_target_properties( InstallDemo PROPERTIES EXCLUDE_FROM_ALL TRUE )
ExternalData_Add_Target( demo )
add_dependencies( demo SuperElastix )
set_target_properties( demo PROPERTIES EXCLUDE_FROM_ALL TRUE )
foreach(InstallDemoFileName ${InstallDemoFileNames})
foreach(demoFileName ${demoFileNames})
add_custom_command(
TARGET InstallDemo POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${INSTALLDEMO_PREFIX}/Data
COMMAND ${CMAKE_COMMAND} -E copy ${InstallDemoFileName} ${INSTALLDEMO_PREFIX}/Data/
TARGET demo POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${DEMO_PREFIX}/Data
COMMAND ${CMAKE_COMMAND} -E copy ${demoFileName} ${DEMO_PREFIX}/Data/
)
endforeach()
# Copy executable
add_custom_command(
TARGET InstallDemo POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:SuperElastix> ${INSTALLDEMO_PREFIX}/$<TARGET_FILE_NAME:SuperElastix>
TARGET demo POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:SuperElastix> ${DEMO_PREFIX}/$<TARGET_FILE_NAME:SuperElastix>
)
# Copy Configuration files
......@@ -100,9 +100,9 @@ set( ConfigFiles
foreach( ConfigFile ${ConfigFiles} )
add_custom_command(
TARGET InstallDemo POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${INSTALLDEMO_PREFIX}/Configuration
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/../Testing/Data/Configuration/${ConfigFile}" ${INSTALLDEMO_PREFIX}/Configuration/${ConfigFile}
TARGET demo POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${DEMO_PREFIX}/Configuration
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/../Testing/Data/Configuration/${ConfigFile}" ${DEMO_PREFIX}/Configuration/${ConfigFile}
)
endforeach()
......@@ -117,15 +117,15 @@ set( ScriptFiles
if(WIN32)
foreach( ScriptFile ${ScriptFiles} )
add_custom_command(
TARGET InstallDemo POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${INSTALLDEMO_PREFIX}/Scripts
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/Demo/Scripts_Windows/${ScriptFile}.bat" "${INSTALLDEMO_PREFIX}/Scripts/${ScriptFile}.bat")
TARGET demo POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${DEMO_PREFIX}/Scripts
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/Demo/Scripts_Windows/${ScriptFile}.bat" "${DEMO_PREFIX}/Scripts/${ScriptFile}.bat")
endforeach()
else( WIN32 )
foreach( ScriptFile ${ScriptFiles} )
add_custom_command(
TARGET InstallDemo PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${INSTALLDEMO_PREFIX}/Scripts
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/Demo/Scripts_Linux/${ScriptFile}.sh" "${INSTALLDEMO_PREFIX}/Scripts/${ScriptFile}.sh")
TARGET demo PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${DEMO_PREFIX}/Scripts
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/Demo/Scripts_Linux/${ScriptFile}.sh" "${DEMO_PREFIX}/Scripts/${ScriptFile}.sh")
endforeach()
endif(WIN32)
......@@ -22,6 +22,7 @@
#include "selxConfigurationReader.h"
#include "selxAnyFileReader.h"
#include "selxAnyFileWriter.h"
#include "selxLogger.h"
#include <boost/algorithm/string.hpp>
......@@ -56,6 +57,11 @@ main( int ac, char * av[] )
// instantiate a SuperElastixFilter that is loaded with default components
selx::SuperElastixFilter::Pointer superElastixFilter = selx::SuperElastixFilter::New();
// add logger
selx::SuperElastixFilter::LoggerPointer itkLogger = selx::SuperElastixFilter::LoggerType::New();
itkLogger->Get()->AddConsole();
superElastixFilter->SetLogger( itkLogger );
fs::path configurationPath;
VectorOfStringsType inputPairs;
VectorOfStringsType outputPairs;
......
......@@ -84,6 +84,7 @@ macro( _selxapplication_enable APPLICATION UPSTREAM )
include( ${${APPLICATION}_CMAKE_FILE} )
if( ${APPLICATION}_MODULE_DEPENDENCIES )
# TODO: If we are building as a standalone directory we should just check if enabled instead of enabling
_selxmodule_enable_dependencies( ${APPLICATION}_MODULE_DEPENDENCIES ${APPLICATION} )
endif()
......
......@@ -41,6 +41,7 @@ macro( _selxmodules_initialize )
set( SUPERELASTIX_MODULES )
set( SUPERELASTIX_INCLUDE_DIRS )
set( SUPERELASTIX_LIBRARIES )
set( SUPERELASTIX_LIBRARY_DIRS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} )
set( SUPERELASTIX_TEST_SOURCE_FILES )
set( SUPERELASTIX_INTERFACE_DIRS )
......@@ -58,9 +59,9 @@ macro( _selxmodules_initialize )
option( USE_${MODULE} OFF )
set( ${MODULE}_IS_ENABLED FALSE )
set( ${MODULE}_CMAKE_FILE ${CMAKE_SOURCE_DIR}/${${MODULE}_PATH}/${MODULE}.cmake )
set( ${MODULE}_SOURCE_DIR ${CMAKE_SOURCE_DIR}/${${MODULE}_PATH} )
set( ${MODULE}_BINARY_DIR ${CMAKE_BINARY_DIR}/${${MODULE}_PATH} )
set( ${MODULE}_CMAKE_FILE ${PROJECT_SOURCE_DIR}/${${MODULE}_PATH}/${MODULE}.cmake )
set( ${MODULE}_SOURCE_DIR ${PROJECT_SOURCE_DIR}/${${MODULE}_PATH} )
set( ${MODULE}_BINARY_DIR ${PROJECT_BINARY_DIR}/${${MODULE}_PATH} )
# Collect header files for Visual Studio
# http://stackoverflow.com/questions/8316104/specify-how-cmake-creates-visual-studio-project
......@@ -74,7 +75,6 @@ macro( _selxmodules_initialize )
set( ${MODULE}_SOURCE_FILES )
set( ${MODULE}_TEST_SOURCE_FILES )
set( ${MODULE}_MODULE_DEPENDENCIES )
set( ${MODULE}_LIBRARY_DIRS )
set( ${MODULE}_LIBRARIES )
list( APPEND SUPERELASTIX_MODULES ${MODULE} )
......@@ -109,6 +109,11 @@ macro( _selxmodule_enable MODULE UPSTREAM )
list( APPEND SUPERELASTIX_TEST_SOURCE_FILES ${${MODULE}_TEST_SOURCE_FILES} )
endif()
# Header-only modules should not be compiled
if( ${MODULE}_SOURCE_FILES )
add_library( ${MODULE} ${${MODULE}_HEADER_FILES} ${${MODULE}_SOURCE_FILES} )
endif()
if( ${MODULE}_LIBRARIES )
list( APPEND SUPERELASTIX_LIBRARIES ${${MODULE}_LIBRARIES} )
endif()
......@@ -132,6 +137,8 @@ macro( _selxmodule_enable MODULE UPSTREAM )
# Aggregate all interface headers in a separate target for Visual Studio IDE.
if( ${MODULE}_INTERFACE_FILES )
target_sources( Interfaces PUBLIC ${${MODULE}_INTERFACE_FILES} )
if( ${MODULE}_LIBRARY_DIRS )
list( APPEND SUPERELASTIX_LIBRARY_DIRS ${${MODULE}_LIBRARY_DIRS} )
endif()
message( STATUS "${MODULE} enabled." )
......@@ -146,6 +153,12 @@ macro( _selxmodule_enable_dependencies UPSTREAM MODULES )
endforeach()
endmacro()
macro( _selxmodule_target_file TARGETS )
foreach( TARGET ${${TARGETS}} )
set( ${TARGET}_FILE $<TARGET_FILE:TARGET> )
endforeach()
endmacro()
macro( _selxmodule_disable MODULE )
set( USE_${MODULE} FALSE )
list( FILTER SUPERELASTIX_INCLUDE_DIRS MATCHES EXCLUDE REGEX "(.*)${MODULE}(.*)" )
......
......@@ -19,13 +19,14 @@
cmake_minimum_required( VERSION 3.0.2 )
# Explicitly add INCREMENTAL linking option to command lines.
# http://www.cmake.org/pipermail/cmake/2010-February/035174.html
#set( MSVC_INCREMENTAL_DEFAULT ON )
# ---------------------------------------------------------------------
project( SuperElastix )
set( SUPERELASTIX_MAJOR_VERSION 0)
set( SUPERELASTIX_MINOR_VERSION 1)
set( SUPERELASTIX_PATCH_VERSION 0)
set( SUPERELASTIX_VERSION ${SUPERELASTIX_MAJOR_VERSION}.${SUPERELASTIX_MINOR_VERSION}.${SUPERELASTIX_PATCH_VERSION})
# Place executables in the bin directory
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" )
......@@ -82,32 +83,47 @@ if( ${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC )
# set( MSVC_INCREMENTAL_DEFAULT ON )
endif()
if( NOT CMAKE_BUILD_TYPE )
set( CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
FORCE )
endif()
# ---------------------------------------------------------------------
# Use SuperBuild.
# The SuperBuild is typically used to build dependencies. Should
# you wish to build them yourself (e.g. if you need a specific
# version of ITK), set USE_SUPERBUILD to OFF _and_ USE_SYSTEM_ITK to ON,
# USE_SYSTEM_BOOST to ON, USE_SYSTEM_GTEST to ON or USE_SYSTEM_ELASTIX
# to ON. The find_package() command will then load your system libraries
# instead.
option( USE_SUPERBUILD "Use dependencies built by SuperBuild." ON )
mark_as_advanced( USE_SUPERBUILD )
if( USE_SUPERBUILD )
find_package( SuperElastixSuperBuild REQUIRED )
include( ${SUPERELASTIXSUPERBUILD_USE_FILE} )
endif()
# ---------------------------------------------------------------------
# ITK
find_package( ITK REQUIRED )
include( ${ITK_USE_FILE} )
list( APPEND RequiredITKModules
ITKReview
)
foreach( ITKModule ${RequiredITKModules} )
if( NOT ${ITKModule}_LOADED )
message( FATAL_ERROR "elastix requires that ITK is build with ${ITKModule}. Please rebuild ITK with Module_${ITKModule} set to ON." )
endif()
endforeach()
# ---------------------------------------------------------------------
# Boost Library
set(Boost_USE_STATIC_LIBS ON) # only find static libs
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
#set( Boost_DEBUG ON )
set(BOOST_INCLUDEDIR "${BOOST_ROOT}/BOOST-prefix/src/Boost/boost/" )
set(BOOST_LIBRARYDIR "${BOOST_ROOT}/BOOST-prefix/src/Boost/stage/lib/" )
set(BOOST_ROOT "${BOOST_ROOT}/BOOST-prefix/src/Boost/" )
set( Boost_USE_STATIC_LIBS ON ) # only find static libs
set( Boost_USE_MULTITHREADED ON )
set( Boost_USE_STATIC_RUNTIME OFF )
# TODO: These are hardcoded for the SuperBuild
set( BOOST_INCLUDEDIR "${BOOST_ROOT}/BOOST-prefix/src/Boost/boost/" )
set( BOOST_LIBRARYDIR "${BOOST_ROOT}/BOOST-prefix/src/Boost/stage/lib/" )
set( BOOST_ROOT "${BOOST_ROOT}/BOOST-prefix/src/Boost/" )
find_package( Boost COMPONENTS filesystem system log date_time thread regex REQUIRED QUIET ) # graph ?
include_directories( ${Boost_INCLUDE_DIRS} )
......@@ -144,10 +160,10 @@ endif()
# ---------------------------------------------------------------------
# Testing
set( SUPERELASTIX_INPUT_DATA_DIR ${CMAKE_CURRENT_BINARY_DIR}/Testing/Data/Input )
set( SUPERELASTIX_OUTPUT_DATA_DIR ${CMAKE_CURRENT_BINARY_DIR}/Testing/Data/Output )
set( SUPERELASTIX_BASELINE_DATA_DIR ${CMAKE_CURRENT_BINARY_DIR}/Testing/Data/Baseline )
set( SUPERELASTIX_CONFIGURATION_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Testing/Data/Configuration )
set( SUPERELASTIX_INPUT_DATA_DIR ${PROJECT_BINARY_DIR}/Testing/Data/Input )
set( SUPERELASTIX_OUTPUT_DATA_DIR ${PROJECT_BINARY_DIR}/Testing/Data/Output )
set( SUPERELASTIX_BASELINE_DATA_DIR ${PROJECT_BINARY_DIR}/Testing/Data/Baseline )
set( SUPERELASTIX_CONFIGURATION_DATA_DIR ${PROJECT_BINARY_DIR}/Testing/Data/Configuration )
if( NOT EXISTS ${SUPERELASTIX_OUTPUT_DATA_DIR} )
file( MAKE_DIRECTORY ${SUPERELASTIX_OUTPUT_DATA_DIR} )
......@@ -180,11 +196,53 @@ mark_as_advanced( BUILD_READTHEDOCS )
option( BUILD_READTHEDOCS "Enable building readthedocs.org documentation." OFF )
# ---------------------------------------------------------------------
# Enable other projects to use SuperElastix via CMake's find_packge() and a use-file
# Installation
set( SUPERELASTIX_CONFIG_DIR ${CMAKE_CURRENT_BINARY_DIR} )
set( SUPERELASTIX_BINARY_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} )
get_directory_property( SUPERELASTIX_INCLUDE_DIRS INCLUDE_DIRECTORIES )
configure_file( SuperElastixConfig.cmake.in SuperElastixConfig.cmake @ONLY IMMEDIATE )
configure_file( UseSuperElastix.cmake.in UseSuperElastix.cmake COPYONLY IMMEDIATE )
\ No newline at end of file
set( CMAKE_INSTALL_DIR "" )
if( WIN32 AND NOT CYGWIN )
set( CMAKE_INSTALL_DIR CMake )
else()
set( CMAKE_INSTALL_DIR lib/CMake/SuperElastix )
endif()
# Register the build-tree with a global CMake-registry
export( PACKAGE SuperElastix )
# Create the SuperElastix.cmake files
# ... for the build tree
set( SUPERELASTIX_INSTALL_INCLUDE_DIRS ${SUPERELASTIX_INCLUDE_DIRS} )
set( SUPERELASTIX_INSTALL_LIBRARY_DIRS ${SUPERELASTIX_LIBRARY_DIRS} )
set( SUPERELASTIX_INSTALL_LIBRARIES ${SUPERELASTIX_LIBRARIES} )
set( SUPERELASTIX_INSTALL_USE_FILE "${PROJECT_BINARY_DIR}/UseSuperElastix.cmake" )
configure_file( SuperElastixConfig.cmake.in "${PROJECT_BINARY_DIR}/SuperElastixConfig.cmake" @ONLY)
configure_file( SuperElastixConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/SuperElastixConfigVersion.cmake" @ONLY)
configure_file( UseSuperElastix.cmake.in "${SUPERELASTIX_INSTALL_USE_FILE}" @ONLY )
# ... for the install tree
set( SUPERELASTIX_INSTALL_INCLUDE_DIRS include )
set( SUPERELASTIX_INSTALL_LIBRARY_DIRS lib )
set( SUPERELASTIX_INSTALL_LIBRARIES ModuleFilter ModuleBlueprints ModuleLogger )
set( SUPERELASTIX_INSTALL_USE_FILE ${CMAKE_INSTALL_DIR}/UseSuperElastix.cmake )
configure_file( SuperElastixConfig.cmake.in install/SuperElastixConfig.cmake @ONLY)
configure_file( SuperElastixConfigVersion.cmake.in install/SuperElastixConfigVersion.cmake @ONLY)
configure_file( UseSuperElastix.cmake.in install/UseSuperElastix.cmake @ONLY )
install( FILES
${PROJECT_BINARY_DIR}/install/SuperElastixConfig.cmake
${PROJECT_BINARY_DIR}/install/SuperElastixConfigVersion.cmake
${PROJECT_BINARY_DIR}/install/UseSuperElastix.cmake
DESTINATION ${CMAKE_INSTALL_DIR} )
install( FILES
Modules/Filter/include/selxSuperElastixFilter.h
Modules/Filter/include/selxSuperElastixFilterCustomComponents.h
Modules/Filter/include/itkUniquePointerDataObjectDecorator.h
Modules/Filter/include/itkUniquePointerDataObjectDecorator.hxx
Modules/Blueprints/include/selxBlueprint.h
Modules/Logger/include/selxLogger.h
Modules/FileIO/include/selxAnyFileReader.h
Modules/FileIO/include/selxAnyFileWriter.h
DESTINATION include )
install( TARGETS ModuleFilter ModuleBlueprints ModuleLogger ModuleComponentInterface
DESTINATION lib )
......@@ -37,7 +37,3 @@ set( ${MODULE}_LIBRARIES
${Boost_LIBRARIES} # graph?
${MODULE}
)
set( ${MODULE}_MODULE_DEPENDENCIES
)
......@@ -38,10 +38,12 @@ public:
return InterfaceStatus::noaccepter;
}
//Empty RestInterfaces does 0 successful connects ;
int ConnectFromImpl( ComponentBase::Pointer ) { return 0; }
int ConnectFromImpl( ComponentBase::Pointer ) { return 0; }
bool AreAllAccepted() { return true; }
protected:
};
......@@ -60,6 +62,7 @@ public:
// Helper function by which a component can check if all its Accepting interfaces have been set after the handshakes
bool AreAllAccepted();
protected:
};
} //end namespace selx
......
......@@ -109,24 +109,24 @@ Accepting< FirstInterface, RestInterfaces ... >::CountMeetsCriteria( const Compo
return Count< FirstInterface, RestInterfaces ... >::MeetsCriteria( interfaceCriteria );
}
template< typename FirstInterface, typename ... RestInterfaces >
bool
Accepting< FirstInterface, RestInterfaces ... >::AreAllAccepted()
{
InterfaceAcceptor< FirstInterface > * acceptIF = (this);
if (acceptIF->isSet() == false)
InterfaceAcceptor< FirstInterface > * acceptIF = ( this );
if( acceptIF->isSet() == false )
{
auto const & properties = Properties<FirstInterface>::Get();
for (auto const & keyvalue : properties)
auto const & properties = Properties< FirstInterface >::Get();
for( auto const & keyvalue : properties )
{
std::cout << "{ """ << keyvalue.first << """: """ << keyvalue.second << """}" << std::endl;
std::cout << "{ " "" << keyvalue.first << "" ": " "" << keyvalue.second << "" "}" << std::endl;
}
//std::cout << std::endl;
return false;
}
return Accepting<RestInterfaces ...>::AreAllAccepted();
}
return Accepting< RestInterfaces ... >::AreAllAccepted();
}
} //end namespace selx
#endif // Accepting_hxx
......@@ -29,6 +29,7 @@
#include <map>
#include <vector>
#include <memory>
#include "selxLogger.h"
namespace selx
{
......@@ -38,7 +39,7 @@ public:
//ComponentBase() = delete;
ComponentBase();
ComponentBase( const std::string & name );
ComponentBase( const std::string & name, const LoggerInterface & logger );
virtual ~ComponentBase() {}
typedef std::shared_ptr< ComponentBase > Pointer;
......@@ -68,8 +69,10 @@ public:
// Each component is checked if its required connections are made after all handshakes.
// SuperElastixComponent provides a default implementation which may be overridden by the component developer
virtual bool ConnectionsSatisfied() = 0 ;
const std::string m_Name;
virtual bool ConnectionsSatisfied() = 0;
const std::string m_Name;
const LoggerInterface & m_Logger;
};
} // end namespace selx
......
......@@ -50,7 +50,7 @@ public:
typedef ComponentListType::size_type NumberOfComponentsType;
/** set selection criteria for possibleComponents*/
ComponentSelector( const std::string & name );
ComponentSelector( const std::string & name, const LoggerInterface & logger );
/** Narrow selection criteria*/
void AddCriterion( const CriterionType & criterion );
......
......@@ -26,7 +26,9 @@ namespace selx
template< >
struct ContructComponentsFromTypeList< TypeList< >>
{
static std::list< ComponentBase::Pointer > fill( std::list< ComponentBase::Pointer > & components, const std::string & name )
static std::list< ComponentBase::Pointer > fill( std::list< ComponentBase::Pointer > & components,
const std::string & name,
const LoggerInterface & logger )
{
return components;
}
......@@ -35,18 +37,20 @@ struct ContructComponentsFromTypeList< TypeList< >>
template< typename ComponentType, typename ... Rest >
struct ContructComponentsFromTypeList< TypeList< ComponentType, Rest ... >>
{
static std::list< ComponentBase::Pointer > fill( std::list< ComponentBase::Pointer > & components, const std::string & name )
static std::list< ComponentBase::Pointer > fill( std::list< ComponentBase::Pointer > & components,
const std::string & name,
const LoggerInterface & logger )
{
components.push_back( std::make_shared< ComponentType >( name ) );
return ContructComponentsFromTypeList< TypeList< Rest ... >>::fill( components, name );
components.push_back( std::make_shared< ComponentType >( name, logger ) );
return ContructComponentsFromTypeList< TypeList< Rest ... >>::fill( components, name, logger );
}
};
template< class ComponentList >
ComponentSelector< ComponentList >::ComponentSelector( const std::string & name )
ComponentSelector< ComponentList >::ComponentSelector( const std::string & name, const LoggerInterface & logger )
{
m_PossibleComponents = std::list< ComponentBase::Pointer >();
m_PossibleComponents = ContructComponentsFromTypeList< ComponentList >::fill( m_PossibleComponents, name );
m_PossibleComponents = ContructComponentsFromTypeList< ComponentList >::fill( m_PossibleComponents, name, logger );
}
......
......@@ -46,8 +46,11 @@ public:
bool isSet()
{
return m_isSet;
};
}
private:
bool m_isSet = false;
};
} //end namespace selx
......
......@@ -57,11 +57,9 @@ public:
typedef std::map<
std::string, RegistrationControllerStartInterface::Pointer > RegistrationControllerStartInterfaceMapType;
NetworkBuilder();
NetworkBuilder( const Logger & logger );
virtual ~NetworkBuilder() {}
virtual std::unique_ptr< NetworkBuilderBase > ConstructNewDerivedInstance( void );
virtual bool AddBlueprint( const std::unique_ptr< Blueprint > & blueprint );
/** Read configuration at the blueprints nodes and edges and return true if all components could be uniquely selected*/
......@@ -117,6 +115,7 @@ protected:
// A selector for each node, that each can hold multiple instantiated components. Ultimately is should be 1 component each.
ComponentSelectorContainerType m_ComponentSelectorContainer;
bool m_isConfigured;
const Logger & m_Logger;
private:
};
......
......@@ -20,23 +20,16 @@
#include "selxNetworkBuilder.h"
#include "selxKeys.h"
#include "selxSuperElastixComponent.h"
#include "selxLogger.h"
namespace selx
{
template< typename ComponentList >
NetworkBuilder< ComponentList >::NetworkBuilder() : m_isConfigured( false ), m_Blueprint( new Blueprint )
NetworkBuilder< ComponentList >::NetworkBuilder( const Logger & logger ) : m_Logger(logger), m_isConfigured( false ), m_Blueprint( new Blueprint )
{
}
template< typename ComponentList >
std::unique_ptr< NetworkBuilderBase >
NetworkBuilder< ComponentList >::ConstructNewDerivedInstance( void )
{
return std::unique_ptr< NetworkBuilderBase >( new NetworkBuilder< ComponentList > );
}
template< typename ComponentList >
bool
NetworkBuilder< ComponentList >::AddBlueprint( const std::unique_ptr< Blueprint > & blueprint )
......@@ -159,7 +152,7 @@ NetworkBuilder< ComponentList >::ApplyComponentConfiguration()
for( auto const & name : componentNames )
{
std::cout << " Blueprint Node: " << name << std::endl;
ComponentSelectorPointer currentComponentSelector = std::make_shared< ComponentSelectorType >( name );
ComponentSelectorPointer currentComponentSelector = std::make_shared< ComponentSelectorType >( name, this->m_Logger );
Blueprint::ParameterMapType currentProperty = this->m_Blueprint->GetComponent( name );
for( auto const & criterion : currentProperty )
......@@ -386,6 +379,7 @@ NetworkBuilder< ComponentList >::ConnectComponents()
return isAllSuccess;
}
template< typename ComponentList >
bool
NetworkBuilder< ComponentList >::CheckConnectionsSatisfied()
......@@ -393,11 +387,11 @@ NetworkBuilder< ComponentList >::CheckConnectionsSatisfied()
bool isAllSatisfied = true;
Blueprint::ComponentNamesType componentNames = this->m_Blueprint->GetComponentNames();
for (auto const & name : componentNames)
for( auto const & name : componentNames )
{
ComponentBase::Pointer component = this->m_ComponentSelectorContainer[name]->GetComponent();
bool isSatisfied = component->ConnectionsSatisfied();
if (isSatisfied == false)
ComponentBase::Pointer component = this->m_ComponentSelectorContainer[ name ]->GetComponent();
bool isSatisfied = component->ConnectionsSatisfied();
if( isSatisfied == false )
{
isAllSatisfied = false;
std::cout << "Component " << name << " has unsatisfied connections" << std::endl;
......@@ -406,6 +400,7 @@ NetworkBuilder< ComponentList >::CheckConnectionsSatisfied()