diff --git a/CMakeLists.txt b/CMakeLists.txt index e71921fe3..dac479907 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,10 @@ cmake_policy(SET CMP0042 NEW) # "MACOSX_RPATH is enabled by default." #--------------------------------------------------------------------- include(CTest) +#--------------------------------------------------------------------- +# Allow specifying whether or not the executables are built. +option( ELASTIX_BUILD_EXECUTABLE "Build elastix and transformix as executable? (The libraries are always built as well anyway.)" ON ) + # The following may make smaller and quicker loading libraries, # that hides unnecessary symbols. Available from CMake 3.0.0. #set(CMAKE_C_VISIBILITY_PRESET hidden) diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 0778c20a9..73e6bf6e1 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -179,20 +179,23 @@ endif() #--------------------------------------------------------------------- # Create the elastix executable and library. -add_executable(elastix_exe - Main/elastix.cxx - Main/elastix.h - Main/elxMainExeUtilities.cxx - Main/elxMainExeUtilities.h - Kernel/elxMainBase.cxx - Kernel/elxMainBase.h - Kernel/elxElastixMain.cxx - Kernel/elxElastixMain.h - ${InstallFilesForExecutables} -) -set_target_properties(elastix_exe PROPERTIES OUTPUT_NAME elastix) -target_compile_definitions(elastix_exe PRIVATE ELX_CMAKE_VERSION="${CMAKE_VERSION}") -target_link_libraries(elastix_exe ${ELASTIX_TARGET_LINK_LIBRARIES}) + +if(ELASTIX_BUILD_EXECUTABLE) + add_executable(elastix_exe + Main/elastix.cxx + Main/elastix.h + Main/elxMainExeUtilities.cxx + Main/elxMainExeUtilities.h + Kernel/elxMainBase.cxx + Kernel/elxMainBase.h + Kernel/elxElastixMain.cxx + Kernel/elxElastixMain.h + ${InstallFilesForExecutables} + ) + set_target_properties(elastix_exe PROPERTIES OUTPUT_NAME elastix) + target_compile_definitions(elastix_exe PRIVATE ELX_CMAKE_VERSION="${CMAKE_VERSION}") + target_link_libraries(elastix_exe ${ELASTIX_TARGET_LINK_LIBRARIES}) +endif() # The library type (STATIC or SHARED) is determined by the parameter # BUILD_SHARED_LIBS. @@ -216,20 +219,22 @@ target_link_libraries(elastix_lib ${ELASTIX_TARGET_LINK_LIBRARIES}) #--------------------------------------------------------------------- # Create the transformix executable. -add_executable(transformix_exe - Main/transformix.cxx - Main/elastix.h - Main/elxMainExeUtilities.cxx - Main/elxMainExeUtilities.h - Kernel/elxMainBase.cxx - Kernel/elxMainBase.h - Kernel/elxTransformixMain.cxx - Kernel/elxTransformixMain.h - ${InstallFilesForExecutables} -) -set_target_properties(transformix_exe PROPERTIES OUTPUT_NAME transformix) -target_compile_definitions(transformix_exe PRIVATE ELX_CMAKE_VERSION="${CMAKE_VERSION}") -target_link_libraries(transformix_exe ${ELASTIX_TARGET_LINK_LIBRARIES}) +if(ELASTIX_BUILD_EXECUTABLE) + add_executable(transformix_exe + Main/transformix.cxx + Main/elastix.h + Main/elxMainExeUtilities.cxx + Main/elxMainExeUtilities.h + Kernel/elxMainBase.cxx + Kernel/elxMainBase.h + Kernel/elxTransformixMain.cxx + Kernel/elxTransformixMain.h + ${InstallFilesForExecutables} + ) + set_target_properties(transformix_exe PROPERTIES OUTPUT_NAME transformix) + target_compile_definitions(transformix_exe PRIVATE ELX_CMAKE_VERSION="${CMAKE_VERSION}") + target_link_libraries(transformix_exe ${ELASTIX_TARGET_LINK_LIBRARIES}) +endif() # The library type (STATIC or SHARED) is determined by the parameter # BUILD_SHARED_LIBS. @@ -254,13 +259,13 @@ set(ELASTIX_LIBRARIES elastix_lib transformix_lib PARENT_SCOPE) #--------------------------------------------------------------------- # Define the install directory for elastix and transformix. -if(NOT WIN32) +if(ELASTIX_BUILD_EXECUTABLE AND NOT WIN32) # Tell the executables where to find the required .so files. set_target_properties(elastix_exe transformix_exe PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${ITK_DIR}") endif() -if(NOT ELASTIX_NO_INSTALL_EXECUTABLES) +if(ELASTIX_BUILD_EXECUTABLE AND NOT ELASTIX_NO_INSTALL_EXECUTABLES) install(TARGETS elastix_exe transformix_exe ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR} LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR} diff --git a/ElastixConfig.cmake.in b/ElastixConfig.cmake.in index 1fd0957e1..3b084d4cd 100644 --- a/ElastixConfig.cmake.in +++ b/ElastixConfig.cmake.in @@ -36,6 +36,7 @@ endif() # Set some variables that the user might want to use +set( ELASTIX_BUILD_EXECUTABLE @ELASTIX_BUILD_EXECUTABLE@ ) set( ELASTIX_USE_OPENMP @ELASTIX_USE_OPENMP@ ) set( ELASTIX_USE_OPENCL @ELASTIX_USE_OPENCL@ ) set( ELASTIX_USE_MEVISDICOMTIFF @ELASTIX_USE_MEVISDICOMTIFF@ ) diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 2922ca2be..808d6d222 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -278,145 +278,147 @@ endmacro() # Main elastix_run add_test macro macro(elx_add_run_test testbasename howtocompare) - # Create output directory - set(testname elastix_run_${testbasename}) - set(output_dir ${TestOutputDir}/${testname}) - file(MAKE_DIRECTORY ${output_dir}) - - # ${ARGN} may be the elastix command line arguments, but also - # an optional baseline value followed by those arguments. - set(baseline ${ARGV2}) - set(elastixargs ${ARGN}) - string(SUBSTRING ${baseline} 0 1 firstelement) - string(COMPARE EQUAL ${firstelement} "-" firstelementisdash) - if(NOT ${firstelementisdash}) - list(REMOVE_AT elastixargs 0) - endif() + if(ELASTIX_BUILD_EXECUTABLE) + # Create output directory + set(testname elastix_run_${testbasename}) + set(output_dir ${TestOutputDir}/${testname}) + file(MAKE_DIRECTORY ${output_dir}) + + # ${ARGN} may be the elastix command line arguments, but also + # an optional baseline value followed by those arguments. + set(baseline ${ARGV2}) + set(elastixargs ${ARGN}) + string(SUBSTRING ${baseline} 0 1 firstelement) + string(COMPARE EQUAL ${firstelement} "-" firstelementisdash) + if(NOT ${firstelementisdash}) + list(REMOVE_AT elastixargs 0) + endif() - # Number of -p's to deduce result.?.mhd - list_count("${ARGN}" "-p" countp) - math(EXPR countp "${countp} - 1") + # Number of -p's to deduce result.?.mhd + list_count("${ARGN}" "-p" countp) + math(EXPR countp "${countp} - 1") - # Run elastix, but only in release mode - # Set maximum test length to 10 minutes - add_test(NAME ${testname}_OUTPUT - CONFIGURATIONS Release - COMMAND ${EXECUTABLE_OUTPUT_PATH}/elastix - ${elastixargs} -out ${output_dir}) - set_tests_properties(${testname}_OUTPUT - PROPERTIES TIMEOUT 600) - - # To compare against a baseline TransformParameters file - # Baselines have been generated on LKEB, PCMarius, Win10, 64 bit, VS2015 - set(baselineTP ${TestOutputDir}/TransformParameters_${testbasename}.txt) - set(testTP ${output_dir}/TransformParameters.${countp}.txt) - - # Temporary hack to get some failing tests working - # These three tests give different results on different platforms - # They all seem to be using ASGD and B-splines and (N)MI - if(specializedTransformParameterSystem) - if(( SITE STREQUAL "LKEB-ELDB91") OR (SITE STREQUAL "LKEB.MacMini") OR (SITE STREQUAL "BIGR.cluster") OR (SITE STREQUAL "BIGR.PCStefan")) - if(${testbasename} STREQUAL "3DCT_lung.MI.bspline.ASGD.001" - OR ${testbasename} STREQUAL "3DCT_lung.NMI.bspline.ASGD.001") - set(baselineTP ${TestOutputDir}/TransformParameters_${SITE}_${testbasename}.txt) + # Run elastix, but only in release mode + # Set maximum test length to 10 minutes + add_test(NAME ${testname}_OUTPUT + CONFIGURATIONS Release + COMMAND ${EXECUTABLE_OUTPUT_PATH}/elastix + ${elastixargs} -out ${output_dir}) + set_tests_properties(${testname}_OUTPUT + PROPERTIES TIMEOUT 600) + + # To compare against a baseline TransformParameters file + # Baselines have been generated on LKEB, PCMarius, Win10, 64 bit, VS2015 + set(baselineTP ${TestOutputDir}/TransformParameters_${testbasename}.txt) + set(testTP ${output_dir}/TransformParameters.${countp}.txt) + + # Temporary hack to get some failing tests working + # These three tests give different results on different platforms + # They all seem to be using ASGD and B-splines and (N)MI + if(specializedTransformParameterSystem) + if(( SITE STREQUAL "LKEB-ELDB91") OR (SITE STREQUAL "LKEB.MacMini") OR (SITE STREQUAL "BIGR.cluster") OR (SITE STREQUAL "BIGR.PCStefan")) + if(${testbasename} STREQUAL "3DCT_lung.MI.bspline.ASGD.001" + OR ${testbasename} STREQUAL "3DCT_lung.NMI.bspline.ASGD.001") + set(baselineTP ${TestOutputDir}/TransformParameters_${SITE}_${testbasename}.txt) + endif() endif() endif() - endif() - # Thread tests should use the original TransformParameters file as a baseline - string(FIND ${testbasename} "Threads" found) - if(NOT found EQUAL -1) - string(REGEX REPLACE "(-Threads[0-9]+)" "" baselineTP ${baselineTP}) - endif() - - # Check which tests have to be run - string(REGEX MATCHALL "[a-zA-Z]+;|[a-zA-Z]+$" compareaslist "${howtocompare}") - list(FIND compareaslist "IMAGE" compare_image) - list(FIND compareaslist "METRICVALUE" compare_metricvalue) - list(FIND compareaslist "PARAMETERS" compare_tp) - list(FIND compareaslist "CHECKSUM" compare_checksum) - list(FIND compareaslist "OVERLAP" compare_overlap) - list(FIND compareaslist "LANDMARKS" compare_landmarks) - - # Compare elastix output image with baseline image - if(NOT ${compare_image} EQUAL -1) - add_test(NAME ${testname}_COMPARE_IM - CONFIGURATIONS Release - COMMAND elxImageCompare - -base ${baseline} - -test ${output_dir}/result.${countp}.mhd - -t 5 -a 50) - set_tests_properties(${testname}_COMPARE_IM - PROPERTIES DEPENDS ${testname}_OUTPUT) - endif() + # Thread tests should use the original TransformParameters file as a baseline + string(FIND ${testbasename} "Threads" found) + if(NOT found EQUAL -1) + string(REGEX REPLACE "(-Threads[0-9]+)" "" baselineTP ${baselineTP}) + endif() - # Compare elastix output from IterationInfo with a baseline string - if(NOT ${compare_metricvalue} EQUAL -1) - # Only run when python was found - if(python_executable) - # Add comparison test, checking the final metric value and more - add_test(NAME ${testname}_COMPARE_METRIC + # Check which tests have to be run + string(REGEX MATCHALL "[a-zA-Z]+;|[a-zA-Z]+$" compareaslist "${howtocompare}") + list(FIND compareaslist "IMAGE" compare_image) + list(FIND compareaslist "METRICVALUE" compare_metricvalue) + list(FIND compareaslist "PARAMETERS" compare_tp) + list(FIND compareaslist "CHECKSUM" compare_checksum) + list(FIND compareaslist "OVERLAP" compare_overlap) + list(FIND compareaslist "LANDMARKS" compare_landmarks) + + # Compare elastix output image with baseline image + if(NOT ${compare_image} EQUAL -1) + add_test(NAME ${testname}_COMPARE_IM CONFIGURATIONS Release - COMMAND ${python_executable} ${pythonfinalmetric} - -b ${baseline} -d ${output_dir}) - set_tests_properties(${testname}_COMPARE_METRIC + COMMAND elxImageCompare + -base ${baseline} + -test ${output_dir}/result.${countp}.mhd + -t 5 -a 50) + set_tests_properties(${testname}_COMPARE_IM PROPERTIES DEPENDS ${testname}_OUTPUT) endif() - endif() - # Compare elastix output using checksum - if(NOT ${compare_checksum} EQUAL -1) - # Only run when python was found and if this is a known system - if(python_executable AND knownChecksumSystem) - # Add comparison test, checking the registration checksum - add_test(NAME ${testname}_COMPARE_CHECKSUM - CONFIGURATIONS Release - COMMAND ${python_executable} ${pythonchecksum} - -f ${checksumBaselineFile} -d ${output_dir} -v) - set_tests_properties(${testname}_COMPARE_CHECKSUM - PROPERTIES DEPENDS ${testname}_OUTPUT) + # Compare elastix output from IterationInfo with a baseline string + if(NOT ${compare_metricvalue} EQUAL -1) + # Only run when python was found + if(python_executable) + # Add comparison test, checking the final metric value and more + add_test(NAME ${testname}_COMPARE_METRIC + CONFIGURATIONS Release + COMMAND ${python_executable} ${pythonfinalmetric} + -b ${baseline} -d ${output_dir}) + set_tests_properties(${testname}_COMPARE_METRIC + PROPERTIES DEPENDS ${testname}_OUTPUT) + endif() endif() - endif() - # Compare elastix output using segmentation overlap - if(NOT ${compare_overlap} EQUAL -1) - # Only run when python was found - if(python_executable) - add_test(NAME ${testname}_COMPARE_OVERLAP - CONFIGURATIONS Release - COMMAND ${python_executable} ${pythonoverlap} - -b ${baselineTP} -d ${output_dir} -m ${TestDataDir}/3DCT_lung_followup_mask.mha - -p $) - set_tests_properties(${testname}_COMPARE_OVERLAP - PROPERTIES DEPENDS ${testname}_OUTPUT) + # Compare elastix output using checksum + if(NOT ${compare_checksum} EQUAL -1) + # Only run when python was found and if this is a known system + if(python_executable AND knownChecksumSystem) + # Add comparison test, checking the registration checksum + add_test(NAME ${testname}_COMPARE_CHECKSUM + CONFIGURATIONS Release + COMMAND ${python_executable} ${pythonchecksum} + -f ${checksumBaselineFile} -d ${output_dir} -v) + set_tests_properties(${testname}_COMPARE_CHECKSUM + PROPERTIES DEPENDS ${testname}_OUTPUT) + endif() endif() - endif() - # Compare elastix output using landmark distance - if(NOT ${compare_landmarks} EQUAL -1) - # Only run when python was found - if(python_executable) - add_test(NAME ${testname}_COMPARE_LANDMARKS + # Compare elastix output using segmentation overlap + if(NOT ${compare_overlap} EQUAL -1) + # Only run when python was found + if(python_executable) + add_test(NAME ${testname}_COMPARE_OVERLAP + CONFIGURATIONS Release + COMMAND ${python_executable} ${pythonoverlap} + -b ${baselineTP} -d ${output_dir} -m ${TestDataDir}/3DCT_lung_followup_mask.mha + -p $) + set_tests_properties(${testname}_COMPARE_OVERLAP + PROPERTIES DEPENDS ${testname}_OUTPUT) + endif() + endif() + + # Compare elastix output using landmark distance + if(NOT ${compare_landmarks} EQUAL -1) + # Only run when python was found + if(python_executable) + add_test(NAME ${testname}_COMPARE_LANDMARKS + CONFIGURATIONS Release + COMMAND ${python_executable} ${pythonlandmarks} + -b ${baselineTP} -d ${output_dir} -f ${TestDataDir}/3DCT_lung_baseline_landmarks.txt -t 1.0 + -p $) + set_tests_properties(${testname}_COMPARE_LANDMARKS + PROPERTIES DEPENDS ${testname}_OUTPUT) + endif() + endif() + + # Compare elastix output using transform parameters comparison + if(NOT ${compare_tp} EQUAL -1) + add_test(NAME ${testname}_COMPARE_TP CONFIGURATIONS Release - COMMAND ${python_executable} ${pythonlandmarks} - -b ${baselineTP} -d ${output_dir} -f ${TestDataDir}/3DCT_lung_baseline_landmarks.txt -t 1.0 - -p $) - set_tests_properties(${testname}_COMPARE_LANDMARKS + COMMAND elxTransformParametersCompare + -base ${baselineTP} + -test ${testTP} + -a 1e-3) + set_tests_properties(${testname}_COMPARE_TP PROPERTIES DEPENDS ${testname}_OUTPUT) endif() endif() - - # Compare elastix output using transform parameters comparison - if(NOT ${compare_tp} EQUAL -1) - add_test(NAME ${testname}_COMPARE_TP - CONFIGURATIONS Release - COMMAND elxTransformParametersCompare - -base ${baselineTP} - -test ${testTP} - -a 1e-3) - set_tests_properties(${testname}_COMPARE_TP - PROPERTIES DEPENDS ${testname}_OUTPUT) - endif() endmacro() #--------------------------------------------------------------------- @@ -445,15 +447,17 @@ set_property(TARGET elxInvertTransform PROPERTY FOLDER "tests/Executable") # Add tests # Add a test, having spaces in the output directory path. -file(MAKE_DIRECTORY "${TestOutputDir}/OutputDirectoryPathContainingSpacesTest") -file(MAKE_DIRECTORY "${TestOutputDir}/OutputDirectoryPathContainingSpacesTest/path with spaces") -file(MAKE_DIRECTORY "${TestOutputDir}/OutputDirectoryPathContainingSpacesTest/path with spaces/name with spaces") -add_test(NAME OutputDirectoryPathContainingSpacesTest - COMMAND ${EXECUTABLE_OUTPUT_PATH}/elastix - -f "${TestDataDir}/2D_2x2_square_object_at_(1,3).mhd" - -m "${TestDataDir}/2D_2x2_square_object_at_(2,1).mhd" - -p "${TestDataDir}/parameters.2D.NC.translation.ASGD.txt" - -out "${TestOutputDir}/OutputDirectoryPathContainingSpacesTest/path with spaces/name with spaces") +if(ELASTIX_BUILD_EXECUTABLE) + file(MAKE_DIRECTORY "${TestOutputDir}/OutputDirectoryPathContainingSpacesTest") + file(MAKE_DIRECTORY "${TestOutputDir}/OutputDirectoryPathContainingSpacesTest/path with spaces") + file(MAKE_DIRECTORY "${TestOutputDir}/OutputDirectoryPathContainingSpacesTest/path with spaces/name with spaces") + add_test(NAME OutputDirectoryPathContainingSpacesTest + COMMAND ${EXECUTABLE_OUTPUT_PATH}/elastix + -f "${TestDataDir}/2D_2x2_square_object_at_(1,3).mhd" + -m "${TestDataDir}/2D_2x2_square_object_at_(2,1).mhd" + -p "${TestDataDir}/parameters.2D.NC.translation.ASGD.txt" + -out "${TestOutputDir}/OutputDirectoryPathContainingSpacesTest/path with spaces/name with spaces") +endif() # Add a test for inverting an affine transform # Add a test for comparing the inverse against the ground truth @@ -990,10 +994,12 @@ elx_add_run_test(3DCT_lung.NC.bspline.ASGD.001d # manual estimation and no adapt -t0 ${TestDataDir}/transformparameters.3DCT_lung.affine.txt -p ${TestDataDir}/parameters.3D.NC.bspline.ASGD.001d.txt) -# Test transformix to check memory problem -trx_add_test(TransformixMemoryTest - -in ${TestDataDir}/3DCT_lung_baseline_small.mha - -tp ${TestDataDir}/transformparameters.3DCT_lung.affine.txt) +if(${ELASTIX_BUILD_EXECUTABLE}) + # Test transformix to check memory problem + trx_add_test(TransformixMemoryTest + -in ${TestDataDir}/3DCT_lung_baseline_small.mha + -tp ${TestDataDir}/transformparameters.3DCT_lung.affine.txt) +endif() elx_add_test(TransformixFilterTest "" "Transformix" ${TestDataDir}/3DCT_lung_baseline_small.mha diff --git a/Testing/PythonTests/CMakeLists.txt b/Testing/PythonTests/CMakeLists.txt index 317b164b1..13b91f312 100644 --- a/Testing/PythonTests/CMakeLists.txt +++ b/Testing/PythonTests/CMakeLists.txt @@ -16,7 +16,7 @@ # # ========================================================================= -if(python_executable) +if(python_executable AND ELASTIX_BUILD_EXECUTABLE) add_test(NAME TransformixTest COMMAND ${python_executable} "${CMAKE_CURRENT_LIST_DIR}/transformix_test.py") set_tests_properties(TransformixTest PROPERTIES ENVIRONMENT