diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..30944692f3e9965ae406199abc5a3a2bca9196da --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +build diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..f5887d974a6498e3c10a78013c19834fade86a0b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "Testing/GoogleTest"] + path = Testing/GoogleTest + url = https://github.com/kaspermarstal/GoogleTest + tag = release-1.7.0 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000000000000000000000000000000000..eddb5e133ef5f2d616acf59f612603ae4b2ecf79 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,24 @@ +language: cpp + +compiler: + - clang + - gcc + +before_install: + - pwd + - date -u + - uname -a + + # Out-of-source build + - cd .. + - mkdir SuperElastix-build + - cd SuperElastix-build + +before_script: + - export OMP_NUM_THREADS=2 + - echo $OMP_NUM_THREADS + +script: + - cmake ../SuperElastix/SuperBuild + - make --jobs=2 | grep -v '^--' | grep -v '^Installing' + - make test diff --git a/CMake/elxCompilerFlags.cmake b/CMake/elxCompilerFlags.cmake new file mode 100644 index 0000000000000000000000000000000000000000..171a36b1bdafb1f2d1b939e3708e1203f8642dcf --- /dev/null +++ b/CMake/elxCompilerFlags.cmake @@ -0,0 +1,12 @@ +set( CompilerFlags + CMAKE_CXX_FLAGS + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_MINSIZEREL + CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_RELWITHDEBINFO + CMAKE_C_FLAGS + CMAKE_C_FLAGS_DEBUG + CMAKE_C_FLAGS_MINSIZEREL + CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_RELWITHDEBINFO +) diff --git a/CMake/elxGoogleTestWinConfig.cmake b/CMake/elxGoogleTestWinConfig.cmake new file mode 100644 index 0000000000000000000000000000000000000000..e72a8726f26a278eca4fcdee0471de494b67035d --- /dev/null +++ b/CMake/elxGoogleTestWinConfig.cmake @@ -0,0 +1,6 @@ +include( ${CMAKE_SOURCE_DIR}/CMake/elxCompilerFlags.cmake ) + +foreach( CompilerFlag ${CompilerFlags} ) + # GoogleTest needs static linking + string( REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}" ) +endforeach() diff --git a/CMake/elxRequiredITKModules.cmake b/CMake/elxRequiredITKModules.cmake new file mode 100644 index 0000000000000000000000000000000000000000..c9cce4a03c670dab607b646114c1f44a241e44d8 --- /dev/null +++ b/CMake/elxRequiredITKModules.cmake @@ -0,0 +1,9 @@ +list( APPEND ElastixRequiredITKModules + ITKReview +) + +foreach( ITKModule ${ElastixRequiredITKModules} ) + 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() diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ec355d9a9510d0d968a5e95d38296e604f04b1ec --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required( VERSION 2.8 ) + +#--------------------------------------------------------------------- +project( elastix ) + +#--------------------------------------------------------------------- +# ITK + +find_package( ITK REQUIRED ) +include( ${ITK_USE_FILE} ) +include( "${CMAKE_CURRENT_SOURCE_DIR}/CMake/elxRequiredITKModules.cmake" ) + +#--------------------------------------------------------------------- +# Build Elastix + +#--------------------------------------------------------------------- +# Testing + +# Do not build tests by default since this requires GoogleTest submodule +# to be initialized. Otherwise users may see FATAL_ERRORs out of the box. +# The SuperBuild will correctly initialize the GoogleTest submodule and +# build tests by default. +option( ELASTIX_BUILD_TESTING "Enable building tests." OFF ) + +if( ELASTIX_BUILD_TESTING ) + enable_testing() + add_subdirectory( Testing ) +endif() + +#--------------------------------------------------------------------- +# Build Documentation + +mark_as_advanced( ELASTIX_BUILD_DOXYGEN ) +option( ELASTIX_BUILD_DOXYGEN "Enable building Doxygen documentation." OFF ) + +mark_as_advanced( ELASTIX_BUILD_READTHEDOCS ) +option( ELASTX_BUILD_READTHEDOCS "Enable building readthedocs.org documentation." OFF ) + diff --git a/SuperBuild/CMakeLists.txt b/SuperBuild/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..12a9ed5a81673f264179d485fe593116bf538361 --- /dev/null +++ b/SuperBuild/CMakeLists.txt @@ -0,0 +1,61 @@ +cmake_minimum_required( VERSION 2.8 ) + +#--------------------------------------------------------------------- +project( elastixSuperBuild ) + +find_package( Git REQUIRED ) + +include( ExternalProject ) + +set( CMAKE_MODULE_PATH + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../CMake + ${CMAKE_MODULE_PATH} +) + +#--------------------------------------------------------------------- +# Elastix SuperBuild configuration + +# Build release by default +if( NOT DEFINED CMAKE_BUILD_TYPE ) + set( CMAKE_BUILD_TYPE "Release" ) +endif() + +# Build examples by default +# Examples will be build as an external project to verify the installation of elastix +option( ELASTIX_BUILD_EXAMPLES "Enable building examples." ON ) + +# Build tests by default +option( ELASTIX_BUILD_TESTING "Enable building tests." ON ) + +if( ELASTIX_BUILD_TESTING ) + mark_as_advanced( ELASTIX_BUILD_CTESTS ) + option( ELASTIX_BUILD_CTESTS "Enable CTests." OFF ) +endif() + +#--------------------------------------------------------------------- +# Build ITK as external project + +set( ITK_VERSION_MAJOR "4" ) +set( ITK_VERSION_MINOR "7" ) +set( ITK_VERSION_PATCH "1" ) +set( ITK_VERSION_STRING "${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}.${ITK_VERSION_PATCH}" ) + +mark_as_advanced( USE_SYSTEM_ITK ) +option( USE_SYSTEM_ITK "Use an installed version of ITK" OFF ) + +if( USE_SYSTEM_ITK ) + find_package( ITK ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR} REQUIRED ) + include( "${CMAKE_CURRENT_SOURCE_DIR}/../CMake/elxRequiredITKModules.cmake" ) +else() + include( ExternalITK ) + list( APPEND ELASTIX_DEPENDENCIES ITK ) +endif() + +#--------------------------------------------------------------------- +# Build Elastix as an external project + +include( Elastix ) + + + diff --git a/SuperBuild/Elastix.cmake b/SuperBuild/Elastix.cmake new file mode 100644 index 0000000000000000000000000000000000000000..130f5595e11ee400642750827c814c3604e48761 --- /dev/null +++ b/SuperBuild/Elastix.cmake @@ -0,0 +1,15 @@ +set( proj Elastix ) + +ExternalProject_Add( ${proj} + DOWNLOAD_COMMAND "" + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/.. + BINARY_DIR ${proj}-build + INSTALL_DIR ${CMAKE_INSTALL_PREFIX} + CMAKE_ARGS + --no-warn-unused-cli + -DELASTIX_BUILD_TESTING:BOOL=${ELASTIX_BUILD_TESTING} + -DELASTIX_BUILD_CTESTS:BOOL=${ELASTIX_BUILD_CTESTS} + -DITK_DIR:PATH=${ITK_DIR} + DEPENDS ${ELASTIX_DEPENDENCIES} + INSTALL_COMMAND "" +) \ No newline at end of file diff --git a/SuperBuild/ExternalExamples.cmake b/SuperBuild/ExternalExamples.cmake new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/SuperBuild/ExternalITK.cmake b/SuperBuild/ExternalITK.cmake new file mode 100644 index 0000000000000000000000000000000000000000..206e83a60c330e8a067a4dffc9ea3d4f030c0b7f --- /dev/null +++ b/SuperBuild/ExternalITK.cmake @@ -0,0 +1,24 @@ +set( proj ITK ) +set( ITK_REPOSITORY https://github.com/InsightSoftwareConsortium/ITK.git ) +set( ITK_TAG "v${ITK_VERSION_STRING}") + +ExternalProject_Add( ${proj} + GIT_REPOSITORY ${ITK_REPOSITORY} + GIT_TAG ${ITK_TAG} + UPDATE_COMMAND "" + SOURCE_DIR ${proj} + BINARY_DIR ${proj}-build + CMAKE_ARGS + --no-warn-unused-cli + -DBUILD_EXAMPLES:BOOL=OFF + -DBUILD_TESTING:BOOL=OFF + -DITK_BUILD_DEFAULT_MODULES:BOOL=ON + -DModule_ITKReview:BOOL=ON + -DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS} + -DCMAKE_SKIP_RPATH:BOOL=ON + -DITK_LEGACY_REMOVE:BOOL=ON + -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> +) + +ExternalProject_Get_Property( ITK install_dir ) +set( ITK_DIR "${install_dir}/lib/cmake/ITK-${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}" ) \ No newline at end of file diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7343cdc14ac9e8409922e978b081018ef3f539b8 --- /dev/null +++ b/Testing/CMakeLists.txt @@ -0,0 +1,67 @@ +#--------------------------------------------------------------------- +# Setup GoogleTest + +if( NOT EXISTS "${CMAKE_SOURCE_DIR}/Testing/GoogleTest/.git" ) + message( FATAL_ERROR "Could not find GoogleTest submodule. Please run +git submodule update --init in the source directory to compile tests." ) +endif() + +if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC" ) + include( ${CMAKE_SOURCE_DIR}/CMake/elxGoogleTestWinConfig.cmake ) +endif() + +add_subdirectory( GoogleTest ) + +include_directories( + ${gtest_SOURCE_DIR}/include +) + +set( TEST_LIBRARIES + gtest_main +) + +#--------------------------------------------------------------------- +# To add a test to the build system, append it to the list below. +# Any GoogleTests in these files are automatically added to CTest. + +set( ElastixUnitTestSource + elxExampleTest.cxx +) + +#--------------------------------------------------------------------- +# Setup ExternalData + +# ExternalData module was introduced in CMake version 2.8.11 +cmake_minimum_required( VERSION 2.8.11 ) + +include( ExternalData ) + +list( APPEND ExternalData_URL_TEMPLATES + "http://midas3.kitware.com/midas/api/rest?method=midas.bitstream.download&checksum=%(hash)&algorithm=%(algo)" + "https://midas3.kitware.com/midas/api/rest?method=midas.bitstream.download&checksum=%(hash)&algorithm=%(algo)" +) + +#--------------------------------------------------------------------- +# To add data to a tests, create a list "${filename}Data" (without +# the filename extension) and add data to this list. + +set( elxExampleTestData + DATA{Data/Input/BrainProtonDensitySliceR10X13Y17.png} +) + +#--------------------------------------------------------------------- +# Build test executables + +foreach( ElastixUnitTestFilename ${ElastixUnitTestSource} ) + string( REPLACE ".cxx" "" ElastixUnitTest ${ElastixUnitTestFilename} ) + add_executable( ${ElastixUnitTest} ${ElastixUnitTestFilename} ) + target_link_libraries( ${ElastixUnitTest} ${ELASTIX_LIBRARIES} ${ITK_LIBRARIES} ${TEST_LIBRARIES} ) + + ExternalData_Add_Test( "${ElastixUnitTest}ExternalDataTarget" + NAME ${ElastixUnitTest} + COMMAND ${ElastixUnitTest} ${${ElastixUnitTest}Data} + ) + + ExternalData_Add_Target( "${ElastixUnitTest}ExternalDataTarget"} ) +endforeach() + diff --git a/Testing/Data/Input/BrainProtonDensitySliceR10X13Y17.png.md5 b/Testing/Data/Input/BrainProtonDensitySliceR10X13Y17.png.md5 new file mode 100644 index 0000000000000000000000000000000000000000..93f3cd126feb7e33c9878ecf57b35692788d44e1 --- /dev/null +++ b/Testing/Data/Input/BrainProtonDensitySliceR10X13Y17.png.md5 @@ -0,0 +1 @@ +610392a128986d934dfc0a1b0dc27e91 \ No newline at end of file diff --git a/Testing/GoogleTest b/Testing/GoogleTest new file mode 160000 index 0000000000000000000000000000000000000000..7c508e6611f14cbc0da048c0e726870b93b1cc00 --- /dev/null +++ b/Testing/GoogleTest @@ -0,0 +1 @@ +Subproject commit 7c508e6611f14cbc0da048c0e726870b93b1cc00 diff --git a/Testing/elxExampleTest.cxx b/Testing/elxExampleTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..1b3cfafc3e4748e901286b667bf0f3b3d3162ba4 --- /dev/null +++ b/Testing/elxExampleTest.cxx @@ -0,0 +1,19 @@ +#include "itkImage.h" +#include "itkImageFileReader.h" +#include "itkImageFileWriter.h" + +#include "gtest/gtest.h" + +TEST( GoogleTest, GoogleTest ) { + /** + * This example demonstrates the GoogleTest framework. + * + * When the test is built, the ExternalData CMake module + * scans the Testing/Data directory for content links on + * the form "[filename].[ext].md5" (text files with hashes). + * The content links are replaced with files from the file + * repository and checked for hash consistensy. + */ + + ASSERT_TRUE( true ); +} \ No newline at end of file