Commit c7ce1871 authored by Marc Modat's avatar Marc Modat

Added the Eigen library, used for the svd in aladin and the DTI tensor...

Added the Eigen library, used for the svd in aladin and the DTI tensor exponentation and log. Reformated f3d_sym and f3d2 to use a mid-space to define the grid space
parent 78f9a7fa
......@@ -7,6 +7,24 @@ else("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" MATC
mark_as_advanced(CLEAR CMAKE_BACKWARDS_COMPATIBILITY)
endif("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" MATCHES "^2\\.8\\.0$")
#-----------------------------------------------------------------------------
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message("In-source builds not allowed by NiftyReg police.")
message("Please make a new directory (called a build directory) and run CMake from there.")
message(FATAL_ERROR "You may need to remove CMakeCache.txt.")
endif(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
#-----------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif(NOT CMAKE_BUILD_TYPE)
#-----------------------------------------------------------------------------
string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
if(NOT cmake_build_type_tolower STREQUAL "debug"
AND NOT cmake_build_type_tolower STREQUAL "release"
AND NOT cmake_build_type_tolower STREQUAL "relwithdebinfo")
message("Unknown build type \"${CMAKE_BUILD_TYPE}\".")
message(FATAL_ERROR "Allowed values are Debug, Release, RelWithDebInfo (case-insensitive).")
endif()
#-----------------------------------------------------------------------------
set(NiftyReg_VERSION_MAJOR 1)
set(NiftyReg_VERSION_MINOR 3)
set(NiftyReg_VERSION_PATCH 9)
......@@ -51,6 +69,7 @@ endif(NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
include_directories(${CMAKE_SOURCE_DIR}/reg-lib)
include_directories(${CMAKE_SOURCE_DIR}/reg-io)
include_directories(${CMAKE_SOURCE_DIR}/reg-io/nifti)
include_directories(${CMAKE_SOURCE_DIR}/third-party)
#-----------------------------------------------------------------------------
# Z library
# Try first to find the z library on the system and built is from the sources if it can not be find
......@@ -200,6 +219,7 @@ endif(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.svn)
subdirs(reg-io)
subdirs(reg-lib)
subdirs(reg-apps)
subdirs(third-party)
if(BUILD_TESTING)
enable_testing()
include(${CMAKE_ROOT}/Modules/Dart.cmake)
......
#-----------------------------------------------------------------------------
add_executable(reg_average reg_average.cpp)
target_link_libraries(reg_average _reg_globalTransformation _reg_maths _reg_tools _reg_ReadWriteImage)
target_link_libraries(reg_average _reg_resampling _reg_globalTransformation _reg_localTransformation _reg_maths _reg_tools _reg_ReadWriteImage)
#-----------------------------------------------------------------------------
add_executable(reg_tools reg_tools.cpp)
target_link_libraries(reg_tools _reg_resampling _reg_localTransformation _reg_tools _reg_globalTransformation _reg_ReadWriteImage)
......@@ -18,64 +18,64 @@ add_executable(reg_jacobian reg_jacobian.cpp)
target_link_libraries(reg_jacobian _reg_resampling _reg_localTransformation _reg_tools _reg_globalTransformation _reg_ReadWriteImage)
#-----------------------------------------------------------------------------
if(USE_CUDA)
cuda_add_executable(reg_f3d reg_f3d.cpp)
cuda_add_executable(reg_f3d reg_f3d.cpp)
else(USE_CUDA)
add_executable(reg_f3d reg_f3d.cpp)
add_executable(reg_f3d reg_f3d.cpp)
endif(USE_CUDA)
target_link_libraries(reg_f3d _reg_f3d)
#-----------------------------------------------------------------------------
if(USE_CUDA)
cuda_add_executable(reg_aladin reg_aladin.cpp)
cuda_add_executable(reg_aladin reg_aladin.cpp)
else(USE_CUDA)
add_executable(reg_aladin reg_aladin.cpp)
add_executable(reg_aladin reg_aladin.cpp)
endif(USE_CUDA)
target_link_libraries(reg_aladin _reg_aladin)
#-----------------------------------------------------------------------------
set(MODULE_LIST
reg_resample
reg_jacobian
reg_aladin
reg_f3d
)
reg_resample
reg_jacobian
reg_aladin
reg_f3d
)
#-----------------------------------------------------------------------------
if(BUILD_NR_SLICER_EXT)
set(EXTENSION_NAME "NiftyRegExtension")
set(EXTENSION_HOMEPAGE "https://sourceforge.net/projects/niftyreg")
set(EXTENSION_CATEGORY "Registration")
set(EXTENSION_CONTRIBUTORS "Marc Modat, Pankaj Daga, David Cash, Sebastien Ourselin (UCL)")
set(EXTENSION_DESCRIPTION "NiftyReg meets slicer, integration of a NiftyReg module within 3DSlicer")
set(EXTENSION_ICONURL "https://dl.dropbox.com/u/2962833/nifty_reg_logo_128.png")
set(EXTENSION_SCREENSHOTURLS "http://www.na-mic.org/Wiki/images/4/4c/Nifty_reg_logo.png")
set(EXTENSION_ACKNOWLEDGEMENTS "This work is partially funded through CBRC grant 168 (UK)")
set(EXTENSION_MAJOR_VERSION ${NiftyReg_VERSION_MAJOR})
set(EXTENSION_MINOR_VERSION ${NiftyReg_VERSION_MINOR})
set(EXTENSION_PATCH_VERSION ${NiftyReg_VERSION_PATCH})
set(EXTENSION_NAME "NiftyRegExtension")
set(EXTENSION_HOMEPAGE "https://sourceforge.net/projects/niftyreg")
set(EXTENSION_CATEGORY "Registration")
set(EXTENSION_CONTRIBUTORS "Marc Modat, Pankaj Daga, David Cash, Sebastien Ourselin (UCL)")
set(EXTENSION_DESCRIPTION "NiftyReg meets slicer, integration of a NiftyReg module within 3DSlicer")
set(EXTENSION_ICONURL "https://dl.dropbox.com/u/2962833/nifty_reg_logo_128.png")
set(EXTENSION_SCREENSHOTURLS "http://www.na-mic.org/Wiki/images/4/4c/Nifty_reg_logo.png")
set(EXTENSION_ACKNOWLEDGEMENTS "This work is partially funded through CBRC grant 168 (UK)")
set(EXTENSION_MAJOR_VERSION ${NiftyReg_VERSION_MAJOR})
set(EXTENSION_MINOR_VERSION ${NiftyReg_VERSION_MINOR})
set(EXTENSION_PATCH_VERSION ${NiftyReg_VERSION_PATCH})
find_package(Slicer REQUIRED)
include(${Slicer_USE_FILE})
find_package(Slicer REQUIRED)
include(${Slicer_USE_FILE})
foreach(MODULE_NAME ${MODULE_LIST})
install(TARGETS ${MODULE_NAME}
RUNTIME DESTINATION ${Slicer_INSTALL_CLIMODULES_BIN_DIR} COMPONENT Runtime
LIBRARY DESTINATION ${Slicer_INSTALL_CLIMODULES_LIB_DIR} COMPONENT Runtime
ARCHIVE DESTINATION ${Slicer_INSTALL_CLIMODULES_LIB_DIR} COMPONENT Runtime
)
endforeach(MODULE_NAME)
include(${Slicer_EXTENSION_CPACK})
foreach(MODULE_NAME ${MODULE_LIST})
install(TARGETS ${MODULE_NAME}
RUNTIME DESTINATION ${Slicer_INSTALL_CLIMODULES_BIN_DIR} COMPONENT Runtime
LIBRARY DESTINATION ${Slicer_INSTALL_CLIMODULES_LIB_DIR} COMPONENT Runtime
ARCHIVE DESTINATION ${Slicer_INSTALL_CLIMODULES_LIB_DIR} COMPONENT Runtime
)
endforeach(MODULE_NAME)
include(${Slicer_EXTENSION_CPACK})
else(BUILD_NR_SLICER_EXT)
set(MODULE_LIST
${MODULE_LIST}
reg_average
reg_tools
reg_transform
)
set(MODULE_LIST
${MODULE_LIST}
reg_average
reg_tools
reg_transform
)
endif(BUILD_NR_SLICER_EXT)
#-----------------------------------------------------------------------------
foreach(MODULE_NAME ${MODULE_LIST})
install(TARGETS ${MODULE_NAME}
RUNTIME DESTINATION bin COMPONENT Runtime
LIBRARY DESTINATION lib COMPONENT Runtime
ARCHIVE DESTINATION lib COMPONENT Runtime
)
install(TARGETS ${MODULE_NAME}
RUNTIME DESTINATION bin COMPONENT Runtime
LIBRARY DESTINATION lib COMPONENT Runtime
ARCHIVE DESTINATION lib COMPONENT Runtime
)
endforeach(MODULE_NAME)
#-----------------------------------------------------------------------------
#!/bin/sh
############################################################################
###################### PARAMETERS THAT CAN BE CHANGED ######################
############################################################################
# Array that contains the input images to create the atlas
export IMG_INPUT=(`ls /path/to/all/your/images_*.nii`)
export IMG_INPUT_MASK= # leave empty to not use floating masks
# template image to use to initialise the atlas creation
export TEMPLATE=`ls ${IMG_INPUT[0]}`
export TEMPLATE_MASK= # leave empty to not use a reference mask
# folder where the result images will be saved
export RES_FOLDER="/path/to/a/folder/to/store/all/result"
# argument to use for the affine (reg_aladin)
export AFFINE_args=""
# argument to use for the non-rigid registration (reg_f3d)
export NRR_args=""
# number of affine loop to perform
export AFF_IT_NUM=10
# number of non-rigid loop to perform
export NRR_IT_NUM=10
# grid engine arguments
export QSUB_CMD="qsub -l h_rt=05:00:00 -l tmem=3.5G -l h_vmem=3.5G -l vf=3.5G -l s_stack=10240 -j y -S /bin/csh -b y -cwd -V"
############################################################################
\ No newline at end of file
#!/bin/sh
#### What could be done ##################################################################
# - add a preprocessing step in order to intensity normalise all the input images ???
# - Any other ?
##########################################################################################
if [ $# -lt 1 ]
then
echo ""
echo "*******************************************************************************"
echo "One argument is expected to run this script:"
echo "- File with contains the altas creation parameters"
echo "example: $0 param_groupwise_niftyreg.sh "
echo "*******************************************************************************"
echo ""
exit
fi
#############################################################################
# read the input parameters
. $1
#############################################################################
## the argument value are checked
if [ ${#IMG_INPUT[@]} -lt 2 ]
then
echo "Less than 2 images have been specified"
echo "Exit ..."
exit
fi
if [ ! -e ${TEMPLATE} ]
then
echo "The template image (${TEMPLATE}) does not exist"
echo "Exit ..."
exit
fi
if [ "${TEMPLATE_MASK}" != "" ] && [ ! -f ${TEMPLATE_MASK} ]
then
echo "The template image mask (${TEMPLATE_MASK}) does not exist"
echo "Exit ..."
fi
IMG_NUMBER=${#IMG_INPUT[@]}
MASK_NUMBER=${#IMG_INPUT_MASK[@]}
if [ ${MASK_NUMBER} -gt 0 ] && [ ! -f ${IMG_INPUT_MASK[0]} ] \
&& [ ${MASK_NUMBER} != ${IMG_NUMBER} ]
then
echo "The number of images is different from the number of floating masks"
echo "Exit ..."
exit
fi
#############################################################################
## SET UP THE NIFTYREG EXECUTABLES
AFFINE=reg_aladin
NRR=reg_f3d
RES=reg_resample
AVERAGE=reg_average
TRANS=reg_transform
TOOLS=reg_tools
#############################################################################
echo ""
echo "************************************************************"
echo ">>> There are ${IMG_NUMBER} input images to groupwise register <<<"
echo ">>> The template image to initialise the registration is ${TEMPLATE} <<<"
echo "************************************************************"
echo ""
#############################################################################
# CREATE THE RESULT FOLDER
if [ ! -d ${RES_FOLDER} ]
then
echo "The output image folder (${RES_FOLDER}) does not exist"
mkdir ${RES_FOLDER}
if [ ! -d ${RES_FOLDER} ]
then
echo "Unable to create the ${RES_FOLDER} folder"
echo "Exit ..."
exit
else
echo "The output image folder (${RES_FOLDER}) has been created"
fi
fi
#############################################################################
#############################################################################
# PERFORM THE RIGID/AFFINE REGISTRATION
# The initial average image is as specified by the user
averageImage=${TEMPLATE}
# Loop over all iterations
for (( CUR_IT=1; CUR_IT<=${AFF_IT_NUM}; CUR_IT++ ))
do
# Check if the iteration has already been performed
if [ ! -f ${RES_FOLDER}/aff_${CUR_IT}/average_affine_it_${CUR_IT}.nii.gz ]
then
#############################
# Create a folder to store the result
if [ ! -d ${RES_FOLDER}/aff_${CUR_IT} ]
then
mkdir ${RES_FOLDER}/aff_${CUR_IT}
fi
#############################
# Run the rigid or affine registration
if [ "`which qsub 2> /dev/null`" == "" ]
then
# All registration are performed serially
for (( i=0 ; i<${IMG_NUMBER}; i++ ))
do
name=`basename ${IMG_INPUT[${i}]} .gz`
name=`basename ${name} .nii`
name=`basename ${name} .hdr`
name=`basename ${name} .img`
# Check if the registration has already been performed
if [ ! -f ${RES_FOLDER}/aff_${CUR_IT}/aff_mat_${name}_it${CUR_IT}.txt ]
then
aladin_args=""
# Registration is forced to be rigid for the first step
if [ ${CUR_IT} == 1 ]
then
aladin_args="-rigOnly"
else
# Check if a previous affine can be use for initialisation
if [ -f ${RES_FOLDER}/aff_`expr ${CUR_IT} - 1`/aff_mat_${name}_it`expr ${CUR_IT} - 1`.txt ]
then
aladin_args="-inaff \
${RES_FOLDER}/aff_`expr ${CUR_IT} - 1`/aff_mat_${name}_it`expr ${CUR_IT} - 1`.txt"
fi
fi
# Check if a mask has been specified for the reference image
if [ "${TEMPLATE_MASK}" != "" ]
then
aladin_args="${aladin_args} -rmask ${TEMPLATE_MASK}"
fi
# Check if a mask has been specified for the floating image
if [ ${MASK_NUMBER} == ${IMG_NUMBER} ]
then
aladin_args="${aladin_args} -fmask ${IMG_INPUT_MASK[${i}]}"
fi
result="/dev/null"
if [ "${CUR_IT}" == "${AFF_IT_NUM}" ]
then
result="${RES_FOLDER}/aff_${CUR_IT}/aff_res_${name}_it${CUR_IT}.nii.gz"
fi
# Perform the registration
reg_aladin ${AFFINE_args} ${aladin_args} \
-ref ${averageImage} \
-flo ${IMG_INPUT[${i}]} \
-aff ${RES_FOLDER}/aff_${CUR_IT}/aff_mat_${name}_it${CUR_IT}.txt \
-res ${result} > ${RES_FOLDER}/aff_${CUR_IT}/aff_log_${name}_it${CUR_IT}.txt
if [ ! -f ${RES_FOLDER}/aff_${CUR_IT}/aff_mat_${name}_it${CUR_IT}.txt ]
then
echo "Error when creating \
${RES_FOLDER}/aff_${CUR_IT}/aff_mat_${name}_it${CUR_IT}.txt"
exit
fi
fi
done
else
# Create shell script to run all jobs in an array
echo \#\!/bin/sh > ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
# Define the current image index
echo "img_number=\`expr \$SGE_TASK_ID - 1\`" \
>> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
echo ". `readlink -f $1`" \
>> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
# Extract the name of the file without the path and the extension
echo "name=\`basename \${IMG_INPUT[\$img_number]} .gz\`" \
>> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
echo "name=\`basename \$name .nii\`" \
>> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
echo "name=\`basename \$name .hdr\`" \
>> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
echo "name=\`basename \$name .img\`" \
>> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
# Check that the registration has not already been performed
echo "if [ ! -e ${RES_FOLDER}/aff_${CUR_IT}/aff_mat_\${name}_it${CUR_IT}.txt ]" >> \
${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
echo "then" >> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
# Check if an input affine is available
echo "trans_affine=${RES_FOLDER}/aff_`expr ${CUR_IT} - 1`/aff_mat_\${name}.txt" >> \
${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
# Set up the registration argument
echo "${AFFINE} ${AFFINE_args} \\" \
>> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
echo "-ref ${averageImage} \\" \
>> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
echo "-flo \${IMG_INPUT[img_number]} \\"
>> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
echo "-aff ${RES_FOLDER}/aff_${CUR_IT}/aff_mat_\${name}_it${CUR_IT}.txt \\" >> \
${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
echo "-result /dev/null \\" \
>> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
if [ "${TEMPLATE_MASK}" != "" ]; then
echo "-rmask ${TEMPLATE_MASK} \\" \
>> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
fi
if [ ${MASK_NUMBER} == ${IMG_NUMBER} ]; then
echo "-fmask \${IMG_INPUT_MASK[\$img_number]} \\" \
>> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
fi
# If this is the first iteration. The registration is forced to be rigid
# Otherwise the previous affine is used for initialisation
if [ ${CUR_IT} == 1 ]
then
echo "-rigOnly" \
>> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
else
echo "-inaff \${trans_affine}" \
>> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
fi
echo "fi" >> ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
## Run the rigid/affine registration - Submit the job array
# Wait to see if the previous iteration average has been created
${QSUB_CMD} \
-hold_jid avg_aff_`expr ${CUR_IT} - 1`_${$} \
-o ${RES_FOLDER}/aff_${CUR_IT} \
-N aladin_${CUR_IT}_${$} \
-t 1-${IMG_NUMBER} \
sh ${RES_FOLDER}/aff_${CUR_IT}/run_gw_niftyReg_aladin_${CUR_IT}_${$}.sh
fi
#############################
if [ "${CUR_IT}" != "${AFF_IT_NUM}" ]
then
# The transformation are demean'ed to create the average image
# Note that this is not done for the last iteration step
list_average=""
for img in ${IMG_INPUT[@]}
do
name=`basename ${img} .gz`
name=`basename ${name} .nii`
name=`basename ${name} .hdr`
name=`basename ${name} .img`
list_average="${list_average} \
${RES_FOLDER}/aff_${CUR_IT}/aff_mat_${name}_it${CUR_IT}.txt ${img}"
done
if [ "`which qsub 2> /dev/null`" == "" ]
then
# The average is created on the host
reg_average \
${RES_FOLDER}/aff_${CUR_IT}/average_affine_it_${CUR_IT}.nii.gz \
-demean1 ${averageImage} \
${list_average}
if [ ! -f ${RES_FOLDER}/aff_${CUR_IT}/average_affine_it_${CUR_IT}.nii.gz ]
then
echo "Error when creating \
${RES_FOLDER}/aff_${CUR_IT}/average_affine_it_${CUR_IT}.nii.gz"
exit