How to develop an Osirix Plugin - part 3: ITK


You want to use other version of ITK? Here is a solution that worked for me. It is based on a Tutorial by Brian Jensen.

ITK

  1. Get ITK source code. Lets name path of the directory with source <ITK_src> and one with binaries <ITK_bin>.
  2. Run Cmake.
  3. Configure with Unix makefiles.
  4. Change CMAKE_OSX_ARCHITECTURES to i386 (see pic below).
  5. Generate.
  6. Refactor namespace using refactor_namespace.sh from NMSegmentation or PetSpectFusion directory. You have it in your <osirix_plugins_dir> (same where _help/Osirix Plugin Generator.app is). To do so start terminal, go to <osirix_plugins_dir>/NMSegmentation directory and type: sh refactor_namespace.sh <ITK_src> nmITK
    sh refactor_namespace.sh <ITK_bin> nmITK
    or change nmITK to any other namespace name you like.
  7. In terminal go to <ITK_bin> and typemake.
  8. You are going to encounter some errors (see pics below), here is how I dealt with them:

Error1: fatal errror: 'nmITKsys/SystemTools.hxx' file not found
Solution1: Using Sublime text editor I found all files with nmITKsys string and replaced it with itksys.

Error2: error: unterminated /* in <ITK_src>/Module/ThirdParty/GDCM
Solution2: copy whole GDCM folder from <ITK_src> with no refactor namespace

Error3: error: use of undeclared identifier 'itkv3'
Solution3: Replace itkv3:: with nmITKv3:: similarly to Solution1.

Error4: some errors in itkTestDriverAfterTest.inc Solution4: none yet, but not necessary :)

Osirix Plugin

  1. Generate new plugin, copy the code from the botttom of the post (sligtly different from the one in previous post). Remember to change the file to .mm.
  2. In <your_plugin_dir>, using terminal ln -s, create symbolic links to ITK source code (here ITK48_src) and binaries folders (here ITK48_bin).
  3. Go to Build Settings, change Base SDK to Latest OSX.
  4. In Build Settings, change OS X Deployment Targer to Compiler Default.
  5. In Build Settings fill Header search paths with:
    ITK48_bin/Modules/ThirdParty/VNL/src/vxl/vcl
    ITK48_bin/Modules/ThirdParty/VNL/src/vxl/core
    ITK48_bin/Modules/Core/Common/**
    ITK48_src/Modules/ThirdParty/VNL/src/vxl/vcl
    ITK48_src/Modules/ThirdParty/VNL/src/vxl/core
    ITK48_src/Modules/Core/Common/**
    ITK48_src/Modules/Filtering/**
  6. In Build Phases add ITK libraries in Link binary with libraries (see figure below). You can move them to suitable group in XCode navigator.
  7. It complies, you can run it (how to turn on debugging). But the plugin won’t load. I get nmITK10DataObject error:
  8. There is a problem with the linker and dynamic lookup it performes. To solve it:
    • in Build Settings remove -undefined dynamic lookup from other linker flags
    • in Build Settings add Osirix binary path (mine is /Applications/OsiriX Lite.app/Contents/MacOS/OsiriX) in Bundle loader to let the linker know where it should look for the Osirix symbols.

Pics

Code

[top]