From 2f26256ff9becedebcf488bf78d164287c92bd4c Mon Sep 17 00:00:00 2001
From: Kasper Marstal <kaspermarstal@gmail.com>
Date: Thu, 12 Nov 2015 16:51:21 +0100
Subject: [PATCH] COMP: Add elastix SuperBuild

---
 CMakeLists.txt                                |  16 +--
 SuperBuild/CMakeLists.txt                     |  30 ++++--
 SuperBuild/ExternalElastix.cmake              | 102 ++++++++++++++++++
 .../{Elastix.cmake => SuperElastix.cmake}     |   3 +-
 4 files changed, 132 insertions(+), 19 deletions(-)
 create mode 100644 SuperBuild/ExternalElastix.cmake
 rename SuperBuild/{Elastix.cmake => SuperElastix.cmake} (87%)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0d48eb59..08ae3185 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,7 +35,7 @@ find_package( Boost REQUIRED graph )
 include_directories( ${Boost_INCLUDE_DIRS} )
 
 # ---------------------------------------------------------------------
-# Build Elastix
+# Build SuperElastix
 # For now we just enable all modules
 include( "${CMAKE_CURRENT_SOURCE_DIR}/CMake/elxModules.cmake" )
 elxmodule_enable( elxModuleCore )
@@ -45,13 +45,13 @@ elxmodule_enable( elxModuleCore )
 
 # Testing requires CMake version 2.8.11 to download test data
 if( CMAKE_VERSION VERSION_LESS 2.8.11 )
-  set( ELASTIX_BUILD_TESTING_DEFAULT OFF )
+  set( SUPERELASTIX_BUILD_TESTING_DEFAULT OFF )
   message( STATUS "ELASTIX_BUILD_TESTING is set to OFF because CMake version is less than 2.8.11" )
 else()
-  set( ELASTIX BUILD_TESTING_DEFAULT ON )
+  set( SUPERELASTIX_BUILD_TESTING_DEFAULT ON )
 endif()
 
-option( ELASTIX_BUILD_TESTING "Enable building tests." ${ELASTIX_BUILD_TESTING_DEFAULT} )
+option( SUPERELASTIX_BUILD_TESTING "Enable building tests." ${ELASTIX_BUILD_TESTING_DEFAULT} )
 if( ${ELASTIX_BUILD_TESTING} )
   enable_testing()
   add_subdirectory( Testing )
@@ -60,9 +60,9 @@ endif()
 # ---------------------------------------------------------------------
 # Build Documentation
 
-mark_as_advanced( ELASTIX_BUILD_DOXYGEN )
-option( ELASTIX_BUILD_DOXYGEN "Enable building Doxygen documentation." OFF )
+mark_as_advanced( SUPERELASTIX_BUILD_DOXYGEN )
+option( SUPERELASTIX_BUILD_DOXYGEN "Enable building Doxygen documentation." OFF )
 
-mark_as_advanced( ELASTIX_BUILD_READTHEDOCS )
-option( ELASTIX_BUILD_READTHEDOCS "Enable building readthedocs.org documentation." OFF )
+mark_as_advanced( SUPERELASTIX_BUILD_READTHEDOCS )
+option( SUPERELASTIX_BUILD_READTHEDOCS "Enable building readthedocs.org documentation." OFF )
 
diff --git a/SuperBuild/CMakeLists.txt b/SuperBuild/CMakeLists.txt
index b9f53783..a703bde7 100644
--- a/SuperBuild/CMakeLists.txt
+++ b/SuperBuild/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required( VERSION 2.8 )
 
 # ---------------------------------------------------------------------
-project( ElastixSuperBuild )
+project( SuperElastixSuperBuild )
 
 find_package( Git REQUIRED )
 
@@ -25,24 +25,24 @@ 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 )
+option( SUPERELASTIX_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 )
+option( SUPERELASTIX_BUILD_TESTING "Enable building tests." ON )
+if( SUPERELASTIX_BUILD_TESTING )
+  option( SUPERELASTIX_BUILD_BENCHMARKING "Enable building benchmarks." ON )
+  option( SUPERELASTIX_BUILD_DASHBOARD "Enable building benchmarks." ON )
 endif()
 
 # Do not build dashboard by default
-option( ELASTIX_BUILD_DASHBOARD "Enable building dashboard." OFF )
+option( SUPERELASTIX_BUILD_DASHBOARD "Enable building dashboard." OFF )
 
 
 # ---------------------------------------------------------------------
 # Build ITK
 
 set( ITK_VERSION_MAJOR "4" )
-set( ITK_VERSION_MINOR "7" )
+set( ITK_VERSION_MINOR "8" )
 set( ITK_VERSION_PATCH "1" )
 set( ITK_VERSION_STRING "${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}.${ITK_VERSION_PATCH}" )
 
@@ -51,7 +51,7 @@ 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" )
+  include( elxRequiredITKModules )
 else()
   include( ExternalITK )
 endif()
@@ -70,7 +70,17 @@ endif()
 # ---------------------------------------------------------------------
 # Build Elastix
 
-include( Elastix )
+# TODO: Add USE_SYSTEM_ELASTICLEGACY option
+mark_as_advanced( SUPERELASTIX_BUILD_ELASTIX )
+option( SUPERELASTIX_BUILD_ELASTIX ON )
+if( SUPERELASTIX_BUILD_ELASTIX )
+  include( ExternalElastix )
+endif()
+
+# ---------------------------------------------------------------------
+# Build SuperElastix
+
+include( SuperElastix )
 
 
 
diff --git a/SuperBuild/ExternalElastix.cmake b/SuperBuild/ExternalElastix.cmake
new file mode 100644
index 00000000..f99860c9
--- /dev/null
+++ b/SuperBuild/ExternalElastix.cmake
@@ -0,0 +1,102 @@
+set( proj Elastix )
+
+set( ELASTIX_REPOSITORY git://github.com/mstaring/elastix.git )
+set( ELASTIX_TAG 6eb6fc7e0d86bafdfdffb1b8bbd125f2a56a486e )
+
+ExternalProject_Add( ${proj} 
+  GIT_REPOSITORY ${ELASTIX_REPOSITORY}
+  GIT_TAG ${ELASTIX_TAG}
+  UPDATE_COMMAND ""
+  SOURCE_DIR ${proj}
+  BINARY_DIR ${proj}-build
+  CMAKE_GENERATOR ${gen}
+  CMAKE_ARGS
+  --no-warn-unused-cli
+  -DELASTIX_BUILD_TESTING:BOOL=OFF
+  -DELASTIX_BUILD_EXECUTABLE:BOOL=OFF
+  -DELASTIX_BUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
+  -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+  -DITK_DIR:PATH=${ITK_DIR}
+  # Elastix components configuration
+  -DUSE_AdaptiveStochasticGradientDescent:BOOL=ON                                           
+  -DUSE_AdvancedAffineTransformElastix:BOOL=ON
+  -DUSE_AdvancedBSplineTransform:BOOL=ON                                           
+  -DUSE_AdvancedKappaStatisticMetric:BOOL=ON                                           
+  -DUSE_AdvancedMattesMutualInformationMetric:BOOL=ON                                           
+  -DUSE_AdvancedMeanSquaresMetric:BOOL=ON                                           
+  -DUSE_AdvancedNormalizedCorrelationMetric:BOOL=ON                                           
+  -DUSE_AffineDTITransformElastix:BOOL=ON                                           
+  -DUSE_BSplineInterpolator:BOOL=ON                                           
+  -DUSE_BSplineInterpolatorFloat:BOOL=ON                                           
+  -DUSE_BSplineResampleInterpolator:BOOL=ON                                           
+  -DUSE_BSplineResampleInterpolatorFloat:BOOL=ON                                           
+  -DUSE_BSplineStackTransform:BOOL=ON                                           
+  -DUSE_BSplineTransformWithDiffusion:BOOL=ON                                           
+  -DUSE_CMAEvolutionStrategy:BOOL=ON                                           
+  -DUSE_CUDAResampler:BOOL=OFF                                          
+  -DUSE_ConjugateGradient:BOOL=ON                                           
+  -DUSE_ConjugateGradientFRPR:BOOL=ON                                           
+  -DUSE_CorrespondingPointsEuclideanDistanceMetric:BOOL=ON
+  -DUSE_DeformationFieldTransform:BOOL=ON                                           
+  -DUSE_DisplacementMagnitudePenalty:BOOL=ON                                           
+  -DUSE_DistancePreservingRigidityPenalty:BOOL=ON                                           
+  -DUSE_EulerTransformElastix:BOOL=ON                                           
+  -DUSE_FiniteDifferenceGradientDescent:BOOL=ON                                           
+  -DUSE_FixedGenericPyramid:BOOL=ON                                           
+  -DUSE_FixedRecursivePyramid:BOOL=ON                                           
+  -DUSE_FixedShrinkingPyramid:BOOL=ON                                           
+  -DUSE_FixedSmoothingPyramid:BOOL=ON                                           
+  -DUSE_FullSampler:BOOL=ON                                           
+  -DUSE_FullSearch:BOOL=ON                                           
+  -DUSE_GradientDifferenceMetric:BOOL=ON                                           
+  -DUSE_GridSampler:BOOL=ON                                           
+  -DUSE_KNNGraphAlphaMutualInformationMetric:BOOL=OFF                                         
+  -DUSE_LinearInterpolator:BOOL=ON                                           
+  -DUSE_LinearResampleInterpolator:BOOL=ON                                           
+  -DUSE_MissingStructurePenalty:BOOL=ON
+  -DUSE_MovingRecursivePyramid:BOOL=ON                                           
+  -DUSE_MovingShrinkingPyramid:BOOL=ON                                           
+  -DUSE_MovingSmoothingPyramid:BOOL=ON                                           
+  -DUSE_MultiBSplineTransformWithNormal:BOOL=ON                                           
+  -DUSE_MultiInputRandomCoordinateSampler:BOOL=ON                                           
+  -DUSE_MultiMetricMultiResolutionRegistration:BOOL=ON                                           
+  -DUSE_MultiResolutionRegistration:BOOL=ON                                           
+  -DUSE_MultiResolutionRegistrationWithFeatures:BOOL=ON                                           
+  -DUSE_MutualInformationHistogramMetric:BOOL=ON                                           
+  -DUSE_MyStandardResampler:BOOL=ON                                           
+  -DUSE_NearestNeighborInterpolator:BOOL=ON                                           
+  -DUSE_NearestNeighborResampleInterpolator:BOOL=ON                                           
+  -DUSE_NormalizedGradientCorrelationMetric:BOOL=ON                                           
+  -DUSE_NormalizedMutualInformationMetric:BOOL=ON                                           
+  -DUSE_PatternIntensityMetric:BOOL=ON                                           
+  -DUSE_PolydataDummyPenalty:BOOL=ON                                           
+  -DUSE_Powell:BOOL=ON
+  -DUSE_QuasiNewtonLBFGS:BOOL=ON                                           
+  -DUSE_RSGDEachParameterApart:BOOL=ON                                           
+  -DUSE_RandomCoordinateSampler:BOOL=ON                                           
+  -DUSE_RandomSampler:BOOL=ON                                           
+  -DUSE_RandomSamplerSparseMask:BOOL=ON                                           
+  -DUSE_RayCastInterpolator:BOOL=ON                                           
+  -DUSE_RayCastResampleInterpolator:BOOL=ON                                           
+  -DUSE_ReducedDimensionBSplineInterpolator:BOOL=ON                                           
+  -DUSE_ReducedDimensionBSplineResampleInterpolator:BOOL=ON                                           
+  -DUSE_RegularStepGradientDescent:BOOL=ON                                           
+  -DUSE_SimilarityTransformElastix:BOOL=ON                                           
+  -DUSE_Simplex:BOOL=ON                                           
+  -DUSE_SimultaneousPerturbation:BOOL=ON                                           
+  -DUSE_SplineKernelTransform:BOOL=ON                                           
+  -DUSE_StandardGradientDescent:BOOL=ON                                           
+  -DUSE_StatisticalShapePenalty:BOOL=ON                                           
+  -DUSE_TransformBendingEnergyPenanalty:BOOL=ON
+  -DUSE_TransformRigidityPenalty:BOOL=ON                                           
+  -DUSE_TranslationTransformElastix:BOOL=ON                                           
+  -DUSE_VarianceOverLastDimensionMetric:BOOL=ON                                           
+  -DUSE_ViolaWellsMutualInformationMetric:BOOL=ON                                           
+  -DUSE_WeightedCombinationTransformElastix:BOOL=ON
+  DEPENDS ITK
+)
+
+ExternalProject_Get_Property( Elastix binary_dir )
+set( ELASTIX_USE_FILE "${binary_dir}/src/UseElastix.cmake" )
+
+list( APPEND ELASTIX_DEPENDENCIES ${proj} )
diff --git a/SuperBuild/Elastix.cmake b/SuperBuild/SuperElastix.cmake
similarity index 87%
rename from SuperBuild/Elastix.cmake
rename to SuperBuild/SuperElastix.cmake
index 1f1d7393..8a1f4e87 100644
--- a/SuperBuild/Elastix.cmake
+++ b/SuperBuild/SuperElastix.cmake
@@ -1,4 +1,4 @@
-set( proj Elastix )
+set( proj SuperElastix )
 
 ExternalProject_Add( ${proj}
   DOWNLOAD_COMMAND ""
@@ -12,6 +12,7 @@ ExternalProject_Add( ${proj}
     -DELASTIX_BUILD_DASHBOARD:BOOL=${ELASTIX_BUILD_DASHBOARD}
     -DITK_DIR:PATH=${ITK_DIR}
     -DBOOST_ROOT:PATH=${BOOST_ROOT}
+    -DELASTIX_USE_FILE:PATH=${ELASTIX_USE_FILE}
   DEPENDS ${ELASTIX_DEPENDENCIES}
   INSTALL_COMMAND ""
 )
-- 
GitLab