Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
simeks committed Aug 20, 2019
2 parents 7d429bc + f863d80 commit 5fd8154
Show file tree
Hide file tree
Showing 25 changed files with 331 additions and 228 deletions.
42 changes: 42 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '{branch}-{build}'

image:
- Visual Studio 2017

platform:
- x64

configuration:
- Release

build:
parallel: true
verbosity: minimal

matrix:
fast_finish: true

environment:
matrix:
- PYTHON: "C:\\Python36-x64"

install:
- git submodule update --init --recursive
- set PATH=%PYTHON%;%PYTHON%\Scripts;%PATH%
- pip install -r requirements.txt

before_build:
- mkdir build
- cd build
- cmake .. -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DCMAKE_GENERATOR_PLATFORM=%PLATFORM% -DDF_BUILD_TESTS=1 -DDF_WARNINGS_ARE_ERRORS=1

build_script:
- cmake --build . --config %CONFIGURATION%
- cd ..
- python setup.py install -DCMAKE_GENERATOR_PLATFORM=%PLATFORM%

test_script:
- cd build
- ctest --output-on-failure
- cd ..
- python -m unittest discover test
52 changes: 28 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
language:
- cpp
- python
language: python
python:
- 3.6
compiler:
- gcc
dist: trusty

matrix:
include:
- env: CONFIG=Release
- env: CONFIG=Debug
git:
submodules: false
before_install:
- sed -i 's,git@github.com:,https://github.com/,g' .gitmodules
- git submodule update --init --recursive
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update -qq
- pyenv global 3.6
- name: trusty
os: linux
dist: trusty
- name: xenial
os: linux
dist: xenial
- name: g++8
os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-8
before_install:
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 90
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 90

install:
- sudo apt-get install -qq g++-8
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 90
- pip3 install sphinx m2r numpy SimpleITK sphinx_rtd_theme PyYAML
- pip install -r requirements.txt

script:
- mkdir build
- cd build
- cmake .. -DDF_BUILD_TESTS=1 -DDF_WARNINGS_ARE_ERRORS=1 -DCMAKE_BUILD_TYPE=${CONFIG} -DDF_BUILD_PYTHON_WRAPPER=ON -DDF_BUILD_DOCS=ON
- cmake --build . --config ${CONFIG}
- cmake .. -DCMAKE_BUILD_TYPE=Release -DDF_BUILD_TESTS=1 -DDF_WARNINGS_ARE_ERRORS=1
-DDF_BUILD_PYTHON_WRAPPER=ON -DPYTHON_EXECUTABLE=~/virtualenv/python3.6/bin/python
- cmake --build . --config Release
- ctest --output-on-failure
- cd ..
- python3 setup.py install --user
- python3 -m unittest discover test
- python setup.py install
- python -m unittest discover test

notifications:
slack:
secure: yAgy9xahI0+X1uRxzMKejHuFFPHF7jpkB4cCLrmChyMvpR0CLu91Py4mONpfP9HEAvhd2EL9ffapGkJ47sfEkVlPE5EL+yMnAM+xavnbxasMnK99hGfHDGOZt4BW1exbrUnTL99c9urtHkvwOVJ25qXySJUN5boIxfB2kumc2P40sbCOCx3NALLFgaysrHNq/y6Pa9tP1zG06acibb6FCJ+zOY3+1Ad8PhRDwZAWiIZ2y0Ic8TlwCwvDIABVahuuNgeY2Fkrt++SFT+/0o19YRydSpteMgoM6hRhKMe6tholj1bO9JclvFqa1WW1Ik8571WJXICk6d6AGipJafWbH5L410dIi/oyClW45nEpmna2wTQKL3eSIRd5NO4YZlm/yqaqJpXaTMwLGQDJyBurpOVC4DYny47ph8ep8wZ3ORCNiujBsHWWRKYK3MDXZuCVCmuK4wBH+GcCMee1Ww8m5acrY1bHJyEYYmSt4x2r49BXYYA9p9t6Gmwmmk2wJWsiWR1OkkvC1UW/Y6nyFTBu4uD0CPaXXj1in69U0xocdhmeS5txRqsw0HJxmbr+GKSMGmIttTXgZyDKrUsKYqH8KKlAfxPJKJeTuKM6f96v5Zj05FELx90Y8VbZu9auk6QPSIie10c9yCKIdnrzEN15pBhmgVFqJVRWsBy2rGkFmhY=
on_success: change
on_failure: always

3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ if(DF_STACK_TRACE)
endif()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down Expand Up @@ -124,6 +124,7 @@ if (DF_USE_CUDA)
add_definitions(-DDF_USE_CUDA)
add_definitions(-DSTK_USE_CUDA)
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD 14)

if (DF_ENABLE_FAST_MATH)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --use_fast_math")
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
recursive-include src *
recursive-include third_party *
include cmake/*
include CMakeLists.txt
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@

deform is an implementation of an efficient graph-cut based method for dense deformable image registration. If you find this useful, please cite https://arxiv.org/abs/1810.08427.

## Prerequisites
The method can be used either as a module through Python (recommended) or a standalone executable. Currently no pre-built binaries for the standalone executable are provided, but the Python module (excluding GPU support) can be installed through pip.

## Install

To download and install the pre-compiled Python module from pip:

```
pip install pydeform
```

Note: to enable GPU-supported registration you're currently required to compile the software yourself. See the section below.

## Building

### Prerequisites
* CMake : https://cmake.org/

Optional
* ISPC : https://ispc.github.io/

## Download
### Download

Retrieve the repository and associated dependencies by running

Expand All @@ -18,15 +32,15 @@ $ cd deform
$ git submodule update --init --recursive
```

## Build
### Build

Use CMake (>=3.8) to generate build options of your own choosing.

If CMake cannot find the ISPC executable on your installation, it is possible
to hint the installation directory with `-DISPC_DIR_HINTS`, or to specify the
full path to the executable with `-DISPC_EXECUTABLE`.

### Build options
#### Build options

The build can be configured with the following CMake boolean options:

Expand All @@ -45,7 +59,7 @@ The build can be configured with the following CMake boolean options:
+ `DF_ENABLE_MICROPROFILE`: Enable `microprofile` profiler (default: `OFF`)
+ `DF_ENABLE_NVTOOLSEXT`: Enable `nvtoolsext` profiler (default: `OFF`)

## Build and install Python wrapper
### Build and install Python wrapper
```
# python setup.py install
```
Expand All @@ -58,8 +72,9 @@ Flags accepted by `setup.py`:

Additional flags starting with `-D` are also recognised and forwarded to CMake.

## Run
To perform a registration
# Run
To perform a registration using the standalone executable

`deform registration -p <param file> -f0 <fixed_0> ... -f<i> <fixed_i> -m0 <moving_0> ... -m<i> <moving_i>`

| Argument | |
Expand Down Expand Up @@ -90,6 +105,7 @@ To perform a registration
```yaml
pyramid_levels: 6
pyramid_stop_level: 0
regularize_initial_displacement: false
constraints_weight: 1000.0
landmarks_weight: 1.0
landmarks_decay: 2.0
Expand Down Expand Up @@ -143,6 +159,10 @@ halves the resolution of the input volumes. Setting `pyramid_stop_level` to > 0
specifies that the registration should not be run on the original resolution
(level 0).

`regularize_initial_displacement` controls whether to include the initial
displacement in the regularization. This is disabled by default, meaning the
initial displacement have no effect on the regularization.

`constraints_weight` sets the weight that is applied for constrained voxels. A
really high value means hard constraints while a lower value may allow
constraints to move a certain amount. Cost for constrained voxels are applied
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
numpy
SimpleITK
PyYAML
11 changes: 8 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext

with open("README.md", encoding="utf-8") as f:
readme = f.read()

# Parse command line flags
flags = {k: 'OFF' for k in ['--debug', '--use-cuda', '--use-ispc', '--use-itk']}
for flag in flags.keys():
Expand All @@ -20,7 +23,9 @@
for f in sys.argv:
if f.startswith('-D'):
cmake_cmd_args.append(f)
sys.argv.remove(f)

for f in cmake_cmd_args:
sys.argv.remove(f)


class CMakeExtension(Extension):
Expand Down Expand Up @@ -74,11 +79,11 @@ def build_extension(self, ext):

setup(
name='pydeform',
version='0.0.1',
version='0.4',
author='Simon Ekström',
author_email='',
description='',
long_description=open('README.md').read(),
long_description=readme,
long_description_content_type='text/markdown',
install_requires=['numpy', 'PyYAML'],
packages=['pydeform'],
Expand Down
12 changes: 6 additions & 6 deletions src/deform/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <deform_lib/defer.h>
#include <deform_lib/filters/resample.h>
#include <deform_lib/jacobian.h>
#include <deform_lib/make_unique.h>
#include <deform_lib/profiler/profiler.h>
#include <deform_lib/registration/landmarks.h>
#include <deform_lib/registration/registration.h>
Expand All @@ -26,7 +27,6 @@
#include <iostream>
#include <map>
#include <omp.h>
#include <optional>
#include <sstream>
#include <string>
#include <vector>
Expand Down Expand Up @@ -82,19 +82,19 @@ int main(int argc, char* argv[])

std::unique_ptr<DeformCommand> command;
if (argc >= 2 && std::strcmp(argv[1], "registration") == 0) {
command = std::make_unique<RegistrationCommand>(argc, argv, true);
command = make_unique<RegistrationCommand>(argc, argv, true);
}
else if (argc >= 2 && std::strcmp(argv[1], "transform") == 0) {
command = std::make_unique<TransformCommand>(argc, argv);
command = make_unique<TransformCommand>(argc, argv);
}
else if (argc >= 2 && std::strcmp(argv[1], "regularize") == 0) {
command = std::make_unique<RegularisationCommand>(argc, argv);
command = make_unique<RegularisationCommand>(argc, argv);
}
else if (argc >= 2 && std::strcmp(argv[1], "jacobian") == 0) {
command = std::make_unique<JacobianCommand>(argc, argv);
command = make_unique<JacobianCommand>(argc, argv);
}
else if (argc >= 2 && std::strcmp(argv[1], "divergence") == 0) {
command = std::make_unique<DivergenceCommand>(argc, argv);
command = make_unique<DivergenceCommand>(argc, argv);
}
else {
print_command_help(argv[0]);
Expand Down
33 changes: 25 additions & 8 deletions src/deform/registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ int RegistrationCommand::_execute(void)
LOG(Info) << "Parameters:" << std::endl << param_str.str();

// Print all settings to Verbose
LOG(Verbose) << print_registration_settings(settings).rdbuf();

std::stringstream settings_str;
print_registration_settings(settings, settings_str);

LOG(Verbose) << settings_str.rdbuf();
}
else {
LOG(Info) << "Running with default settings.";
Expand Down Expand Up @@ -115,13 +119,19 @@ int RegistrationCommand::_execute(void)
const std::string fixed_mask_file = _args.get<std::string>("fixed_mask", "");
const std::string moving_mask_file = _args.get<std::string>("moving_mask", "");

std::optional<stk::Volume> fixed_mask;
std::optional<stk::Volume> moving_mask;
stk::Volume fixed_mask;
stk::Volume moving_mask;

if (!fixed_mask_file.empty()) {
fixed_mask = stk::read_volume(fixed_mask_file);
if (!fixed_mask.valid())
return EXIT_FAILURE;
}

if (!moving_mask_file.empty()) {
moving_mask = stk::read_volume(moving_mask_file);
if (!moving_mask.valid())
return EXIT_FAILURE;
}

LOG(Info) << "Fixed mask: '" << fixed_mask_file << "'";
Expand All @@ -131,9 +141,11 @@ int RegistrationCommand::_execute(void)
std::string init_deform_file = _args.get<std::string>("init_deform", "");
LOG(Info) << "Initial displacement: '" << init_deform_file << "'";

std::optional<stk::Volume> initial_displacement;
stk::Volume initial_displacement;
if (!init_deform_file.empty()) {
initial_displacement = stk::read_volume(init_deform_file.c_str());
if (!initial_displacement.valid())
return EXIT_FAILURE;
}

// Constraints
Expand All @@ -143,11 +155,16 @@ int RegistrationCommand::_execute(void)
LOG(Info) << "Constraint mask: '" << constraint_mask_file << "'";
LOG(Info) << "Constraint values: '" << constraint_values_file << "'";

std::optional<stk::Volume> constraint_mask;
std::optional<stk::Volume> constraint_values;
stk::Volume constraint_mask;
stk::Volume constraint_values;
if (!constraint_mask_file.empty() && !constraint_values_file.empty()) {
constraint_mask = stk::read_volume(constraint_mask_file.c_str());
if (!constraint_mask.valid())
return EXIT_FAILURE;

constraint_values = stk::read_volume(constraint_values_file.c_str());
if (!constraint_values.valid())
return EXIT_FAILURE;
}
else if (!constraint_mask_file.empty() || !constraint_values_file.empty()) {
// Just a check to make sure the user didn't forget something
Expand All @@ -162,8 +179,8 @@ int RegistrationCommand::_execute(void)
LOG(Info) << "Fixed landmarks: '" << fixed_landmarks_file << "'";
LOG(Info) << "Moving landmarks: '" << moving_landmarks_file << "'";

std::optional<std::vector<float3>> fixed_landmarks;
std::optional<std::vector<float3>> moving_landmarks;
std::vector<float3> fixed_landmarks;
std::vector<float3> moving_landmarks;
try{
if (!fixed_landmarks_file.empty()) {
fixed_landmarks = parse_landmarks_file(fixed_landmarks_file.c_str());
Expand Down

0 comments on commit 5fd8154

Please sign in to comment.