Skip to content

install

Marc Modat edited this page Jul 10, 2023 · 12 revisions

Table of Content

Requirements


  • CMake is an open-source cross-platform build system. You can download it from here.

  • Compiler.
  • Using MacOS, you can install XCode, downloadable from this page. Note that in order to take advantage of OpenMP, gcc will also have to be installed. One popular way to install it is to use homebrew.
  • For windows, Visual Studio can be used.

  • NiftyReg can use GPU accelerated computing through CUDA or OpenCL from NVIDIA, which can be downloaded from here

Install from source

Download the source

The source files can be downloaded from the Github project page.

git clone https://github.com/KCL-BMEIS/niftyreg.git niftyreg

or

git clone [email protected]:KCL-BMEIS/niftyreg.git niftyreg

Compile and install the source on Windows

  • Create a folder to build the code and another one to install the code, e.g. niftyreg_build and niftyreg_install respectively.

  • Launch CMake-Gui. Set the source path to niftyreg (where you copied/cloned the source files) and the build path to niftyreg-build then hit configure. CMake-Gui will prompt you to select the generator, which means you'll need to select a version of Visual Studio that have been installed on your computer. CMake-Gui will present you with some configuration options. Once you have selected your desired options and set the CMAKE_INSTALL_PREFIX option to the folder where you want to install NiftyReg (e.g. niftyreg_install), press configure and then generate. CMake-gui will generate the Visual Studio project files. Below is an example of selected options:

CMake-gui

  • Go to the niftyreg_build folder. You can see below the files that are generated by CMake-gui in the niftyreg_build folder:

niftyreg_build

Double click on the file NiftyReg.sln and Visual Studio will start up. In Visual Studio select build type, for generic use select Release and build the project (hit F7). Once the build is finished select and run the install task (Right Click on Install > Project Only > Build only Install). This will install NiftyReg to the folder you selected earlier.

  • You could then install the niftyreg_install folder to your system path.

Compile and install the source on Linux or MacOs

  • Create the folders niftyreg_build and niftyreg_install:

mkdir niftyreg_{build,install}

  • In the terminal, change directory to the niftyreg_build folder and run the following command:

ccmake <niftyreg_source_file_path>

  • Press the c key to configure the project. Set CMAKE_INSTALL_PREFIX to niftyreg_install. Below is an example after the option configuration on MacOs:

ccmake-mac

  • Once all the options have been configured, press c to configure and then g to generate.

  • In the terminal run the following commands:

make

make install

  • The code will be installed in niftyreg_install and you can update your ~/.profile or ~/.basrc file with the following lines:
export NIFTYREG_INSTALL=niftyreg_install
PATH=${PATH}:${NIFTYREG_INSTALL}/bin
export PATH
  • After opening a new terminal, you should be able to run:

reg_f3d -h

CMake configuration Niftyreg specific options

Option Description
BUILD_ALL_DEP If set to ON, the z library will be build even if it is available on the computer.
BUILD_DEV If set to ON, some part of the code under development will be build.
BUILD_SHARED_LIBS If set to ON, the NiftyReg libraries will be build as shared. They are built as static by default.
BUILD_TESTING If set to ON, the data for testing as well as the unit tests will be build. It requires matlab to generate the test data.
USE_CUDA If set to ON, the code is compiled using CUDA.
USE_OPENCL If set to ON, the code is compiled using OpenCL
USE_OPENMP If set to ON, the code is compiled using OpenMP. Not that this can not be done with a clang compiler.
USE_SSD If set to ON, the code is compiled using SSE. SSE code is mostly present in the cubic spline deformation field computation.

Building the unit tests

When the BUILD_TESTING flag is CMake is set to ON, the relevant data and executables are generated. The data are generated using Matlab, hence the need to have matlab installed, from one 2D and one 3D image provided by the user. These images are provided through the variables TESTING_2D_FILE and TESTING_3D_FILE to CMake. The Matlab root path can be specified using the Matlab_ROOT_DIR variable if it is not automatically detected.

Compiling with OpenMP and CUDA on MacOs

CUDA on MacOs is not compatible with gcc and requires clang as a compiler while OpenMP is not supported by clang but is supported by gcc. In order to compile NiftyReg with both OpenMP and CUDA, one need to compile the C/C++ code with gcc and the CUDA code with clang. This can be achieved by setting the following variables accordingly:

CMAKE_C_COMPILER and CMAKE_CXX_COMPILER to gcc and g++ respectively and CUDA_HOST_COMPILER to clang.

The following command line can be use to set up all relevant variables directly:

ccmake -DCUDA_HOST_COMPILER=/usr/bin/clang \
-DCMAKE_C_COMPILER=<path-to-gcc> -DCMAKE_CXX_COMPILER=<path-to-g++> \
-DUSE_CUDA=ON -DUSE_OPENMP=ON -DUSE_OPENCL=ON <path-to-niftyreg-source>
Clone this wiki locally