From dde66cb1cb8bc9c0426dc578dd01b018502a7d67 Mon Sep 17 00:00:00 2001 From: Kasper Marstal <kaspermarstal@gmail.com> Date: Mon, 24 Aug 2015 15:44:39 +0200 Subject: [PATCH] ENH: ELASTIX-1 Add test data manager to object factory --- CMakeLists.txt | 54 ++++++++++++++++++-------- Modules/CMakeLists.txt | 3 ++ Modules/Core/CMakeLists.txt | 4 ++ Modules/Core/Common/CMakeLists.txt | 1 + Modules/Core/Common/include/elxMacro.h | 15 +++++++ Testing/Unit/elxDataDirectories.h.in | 4 +- Testing/Unit/elxDataManager.cxx | 12 +++--- Testing/Unit/elxDataManager.h | 29 +++++++++----- 8 files changed, 88 insertions(+), 34 deletions(-) create mode 100644 Modules/CMakeLists.txt create mode 100644 Modules/Core/CMakeLists.txt create mode 100644 Modules/Core/Common/CMakeLists.txt create mode 100644 Modules/Core/Common/include/elxMacro.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c5a3e96f..d9251974 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,46 +1,66 @@ cmake_minimum_required( VERSION 2.8 ) +# Explicitly add INCREMENTAL linking option to command lines. +# http://www.cmake.org/pipermail/cmake/2010-February/035174.html +set( MSVC_INCREMENTAL_DEFAULT ON ) + +# --------------------------------------------------------------------- +project( Elastix ) + # Include SuperElastix CMake scripts -list( APPEND CMAKE_MODULE_PATH - "${CMAKE_CURRENT_SOURCE_DIR}/CMake" +list( APPEND CMAKE_MODULE_PATH + "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ) -if( CMAKE_HOST_WIN32 ) +if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC" ) include( elxWinConfig.cmake ) endif() -#--------------------------------------------------------------------- -project( Elastix ) - -#--------------------------------------------------------------------- +# --------------------------------------------------------------------- # ITK find_package( ITK REQUIRED ) -set( ITK_NO_IO_FACTORY_REGISTER_MANAGER 1 ) include( ${ITK_USE_FILE} ) include( "${CMAKE_CURRENT_SOURCE_DIR}/CMake/elxITKRequiredModules.cmake" ) -#--------------------------------------------------------------------- +# --------------------------------------------------------------------- # Build Elastix -#--------------------------------------------------------------------- -# Testing +set( ELASTIX_COMMON_INCLUDE_DIRECTORIES + ${CMAKE_SOURCE_DIR}/Modules/Core/Common/include +) -# Build tests by default -option( ELASTIX_BUILD_TESTING "Enable building tests." ON ) +set( ELASTIX_CORE_INCLUDE_DIRECTORIES + ${CMAKE_SOURCE_DIR}/Modules/Core/Blueprints/include +) + +set( ELASTIX_INCLUDE_DIRECTORIES + ${ELASTIX_COMMON_INCLUDE_DIRECTORIES} + ${ELASTIX_CORE_INCLUDE_DIRECTORIES} +) + +include_directories( ${ELASTIX_INCLUDE_DIRECTORIES} ) +add_subdirectory( Modules ) -# ExternalData module requires newer CMake versions +# --------------------------------------------------------------------- +# Testing + +# Testing requires CMake version 2.8.11 to download test data if( CMAKE_VERSION VERSION_LESS 2.8.11 ) - set( ELASTIX_BUILD_TESTING OFF FORCE ) - message( STATUS "ELASTIX_BUILD_TESTING was set to OFF because CMake version is less than 2.8.11") + set( ELASTIX_BUILD_TESTING_DEFAULT OFF ) + message( STATUS "ELASTIX_BUILD_TESTING is set to OFF by default because CMake version is less than 2.8.11" ) +else() + set( ELASTIX BUILD_TESTING_DEFAULT ON ) endif() +option( ELASTIX_BUILD_TESTING "Enable building tests." ${ELASTIX_BUILD_TESTING_DEFAULT} ) + if( ELASTIX_BUILD_TESTING ) enable_testing() add_subdirectory( Testing ) endif() -#--------------------------------------------------------------------- +# --------------------------------------------------------------------- # Build Documentation mark_as_advanced( ELASTIX_BUILD_DOXYGEN ) diff --git a/Modules/CMakeLists.txt b/Modules/CMakeLists.txt new file mode 100644 index 00000000..ed8ac28d --- /dev/null +++ b/Modules/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory( + Core +) \ No newline at end of file diff --git a/Modules/Core/CMakeLists.txt b/Modules/Core/CMakeLists.txt new file mode 100644 index 00000000..dac4f721 --- /dev/null +++ b/Modules/Core/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory( + Common + Blueprints +) \ No newline at end of file diff --git a/Modules/Core/Common/CMakeLists.txt b/Modules/Core/Common/CMakeLists.txt new file mode 100644 index 00000000..fc2d9b4b --- /dev/null +++ b/Modules/Core/Common/CMakeLists.txt @@ -0,0 +1 @@ +include_directories( include ) \ No newline at end of file diff --git a/Modules/Core/Common/include/elxMacro.h b/Modules/Core/Common/include/elxMacro.h new file mode 100644 index 00000000..d176d1a5 --- /dev/null +++ b/Modules/Core/Common/include/elxMacro.h @@ -0,0 +1,15 @@ +#ifndef __elxMacro_h +#define __elxMacro_h + +/** + * Register class with the object factory and provide + * associated RTTI (Run-Time Type Information) + */ +#define elxNewMacro( className, superClassName ) \ + typedef className Self; \ + typedef itk::SmartPointer< Self > Pointer; \ + typedef itk::SmartPointer< const Self > ConstPointer; \ + itkNewMacro( Self ); \ + itkTypeMacro( Self, superClassName ); \ + +#endif // __elxMacro_h \ No newline at end of file diff --git a/Testing/Unit/elxDataDirectories.h.in b/Testing/Unit/elxDataDirectories.h.in index 835845d1..20819640 100644 --- a/Testing/Unit/elxDataDirectories.h.in +++ b/Testing/Unit/elxDataDirectories.h.in @@ -1,5 +1,5 @@ -#ifndef __elxTestDataDirectories_h -#define __elxTestDataDirectories_h +#ifndef __elxDataDirectories_h +#define __elxDataDirectories_h #define ELASTIX_UNITTEST_INPUT_DATA_DIR "@ELASTIX_UNITTEST_INPUT_DATA_DIR@" #define ELASTIX_UNITTEST_OUTPUT_DATA_DIR "@ELASTIX_UNITTEST_OUTPUT_DATA_DIR@" diff --git a/Testing/Unit/elxDataManager.cxx b/Testing/Unit/elxDataManager.cxx index e9aa4e4a..d8da3292 100644 --- a/Testing/Unit/elxDataManager.cxx +++ b/Testing/Unit/elxDataManager.cxx @@ -5,25 +5,25 @@ std::string DataManager -::GetInput( const std::string filename ) const +::GetInputFullPath( const std::string filename ) const { - const std::string path = this->GetInputDirectory() + this->GetPathSeparator() + filename; + const std::string path = this->GetInputDirectory() + this->GetFolderSeparator() + filename; return path; } std::string DataManager -::GetOutput( const std::string filename ) const +::GetOutputFullPath( const std::string filename ) const { - const std::string path = this->GetOutputDirectory() + this->GetPathSeparator() + filename; + const std::string path = this->GetOutputDirectory() + this->GetFolderSeparator() + filename; return path; } std::string DataManager -::GetBaseline( const std::string filename ) const +::GetBaselineFullPath( const std::string filename ) const { - const std::string path = this->GetBaselineDirectory() + this->GetPathSeparator() + filename; + const std::string path = this->GetBaselineDirectory() + this->GetFolderSeparator() + filename; return path; } diff --git a/Testing/Unit/elxDataManager.h b/Testing/Unit/elxDataManager.h index 61d4dcad..fb826d04 100644 --- a/Testing/Unit/elxDataManager.h +++ b/Testing/Unit/elxDataManager.h @@ -3,15 +3,17 @@ #include <string> -#include "itkMacro.h" -#include "itkProcessObject.h" - +#include "elxMacro.h" +#include "itkObjectFactory.h" +#include "itkLightObject.h" #include "elxDataDirectories.h" -class DataManager +class DataManager : public itk::LightObject { public: + elxNewMacro( DataManager, itk::LightObject ); + DataManager() { this->m_InputDirectory = ELASTIX_UNITTEST_INPUT_DATA_DIR; @@ -20,12 +22,21 @@ public: } std::string GetInputDirectory( void ) const { return this->m_InputDirectory; }; - std::string GetOutputDirectory( void ) const { return this->m_InputDirectory; }; - std::string GetBaselineDirectory( void ) const { return this->m_InputDirectory; }; + std::string GetOutputDirectory( void ) const { return this->m_OutputDirectory; }; + std::string GetBaselineDirectory( void ) const { return this->m_BaselineDirectory; }; - std::string GetInput( const std::string filename ) const; - std::string GetOutput( const std::string filename ) const; - std::string GetBaseline( const std::string filename ) const; + std::string GetInputFullPath( const std::string filename ) const; + std::string GetOutputFullPath( const std::string filename ) const; + std::string GetBaselineFullPath( const std::string filename ) const; + + std::string GetFolderSeparator() const + { +#ifdef WIN32 + return "\\"; +#else + return "/"; +#endif + } std::string GetPathSeparator () const { -- GitLab