Compiling ITK on Linux

Install required software

  1. Python 2.5 – http://www.python.org/ftp/python/2.5.2/python-2.5.2.msi

  2. ITK – http://www.itk.org/ITK/resources/software.html.

    • The latest version was ITK 3.10.2 at the time of this writing.

    • Extract contents of zip package. Rename the extracted folder from InsightToolkit-3.10.2 to ITK.

    • In the new ITK folder, make another folder called binaries

  3. CableSwig-ITK – http://www.itk.org/ITK/resources/software.html.

    • Direct download link of corresponding version: CableSwig-ITK 3.10.

    • Extract contents of zip package. Rename the extracted folder from CableSwig-ITK-3.10.0 to just CableSwig. Move this folder into ITK\Utilities.

  4. CMake – http://www.cmake.org/cmake/resources/software.html.

    • The latest version was CMake 2.6.2 at the time of this writing.

    • Download the Windows installer and install CMake
  5. If you don’t already have them, you will also need to install GCC, the C Standard Libraries, and the GNU make utility. If you use a Debian-based Linux system, the build-essentialpackage includes all of these required tools.

Setup build system using CMake

Patch ITK LevelSet CSWIG wrapper

  1. Open the file ITK/Wrapping/CSwig/CommonA/wrap_itkLevelSet.cxx in a text editor

  2. Notice the typedefs in the namespace _LSN_. Copy these typedef lines from namespace _LSN_{} into namespace wrappers{}, which is found below

  3. Save and close the file

Running CMake

  1. Run CMake: ./cmake-2.6.3-Linux-i386/bin/cmake-gui

  2. Set the Where is the source code directory to the ITK folder

  3. Set the Where to build the binaries directory to the binaries folder created earlier

  4. Select Grouped View from the drop down list (it probably says Simple View by default)

  5. Click the Configure button once.

  6. Select Generator prompt should pop up.

    • Select UNIX Makefiles from the drop-down list (if not already selected)

    • Make sure Use default native compilers is selected

    • Click Finish

    • Wait for the configuration process to complete (should take about 5 minutes).
  7. Find and set the following four options in the list of configurable options:
    • Under BUILD group

      BUILD_EXAMPLES

      OFF

       

      Under BUILD group

      BUILD_SHARED_LIBS

      ON

       

      Under BUILD group

      BUILD_TESTING

      OFF

       

      Under CMAKE group

      CMAKE_USE_PTHREADS

      OFF

       

      Under ITK group

      ITK_CSWIG_PYTHON

      ON

  8. Click the Configure button once more and wait for it to complete (about 5 minutes).

  9. Finally, click the Generate button once to create the Makefiles and build system. Then exit the CMake program.

Build ITK

  1. Change working directory to the ITK/binaries folder

  2. Run make. This will take a couple of hours, maybe 2-3 hours.

    • If the build process aborts at around the 76% mark, and the error messages are related to “static linkage” and “pthreads”, then you might need to do the following for a workaround:
      • Find out what version of g++ is on your system by typing g++ --version

      • cd ITK/Utilities/CableSwig/GCC_XML/Support/GCC

      • List the contents by entering ls. Locate the version that matches your g++ version and take note of it.

      • Run the following:
        • cp 3.4/bits/gthr-default.h X.X/bits/

        where X.X should be replaced with your version. Obviously, if your version is 3.4, then this won’t fix the problem.

      • Run make again. It should get back to 76% much quicker than before since everything to that point has already been built, and hopefully continue to 100%.

Test ITK

  1. Place this file in the ITK\binaries\bin folder: ITK.py

  2. Save the following two files into any folder: dm_test.pydm_test.bmp

  3. Run dm_test.py

  4. When this completes, you should have two additional image files DanielssonDistanceMapImageFilterOutput1.png and DanielssonDistanceMapImageFilterOutput1.png that look like the following: