FARSIGHT Tutorials/Building Software/Building ITK

From FarsightWiki
Jump to: navigation, search

Contents


Overview

This tutorial describes how to build ITK with the options required for using it along with FARSIGHT. In particular it includes instructions on how to build the Python wrapping using WrapITK.

Requirements

Before you proceed with this step you should have

  • Installed CMake (Click Here for details)
  • Installed Python (Click Here for details)
  • Build Cable Swig (Click Here for details)
  • Available Disk Space of (at least) 1 Gb)

Download ITK

The source code of ITK can be downloaded from

New releases of ITK are posted every three months.

Please use the most recent release of the software.

Configure

Define SOURCE, BINARY and INSTALLATION directories

CMake uses the concept of SOURCE, BINARY and INSTALLATION directories

  • The SOURCE directory, in this case, is the directory where you put the source code of ITK
  • The BINARY directory, in this case, is the directory where you want to compile and build ITK
  • The INSTALLATION directory, in this case, is the directory where you want to install

This is known as "out of source" building and it is strongly recommended as a good practice, as opposed to the "in-source" building where you could mix the binary and source directories into a single one, and generate great confusion and future suffering.

The build process involves reading the source code from the SOURCE directory and compiling it into libraries that are deposited in the BINARY directory, and finally installing the minimal set of components required for run-time into and INSTALLATION directory.


GNU/Linux & Mac

Create Directories

For the sake this tutorial, lets assume that you are using

  • SOURCE directory = $HOME/src/Insight
  • BINARY directory = $HOME/bin/InsightWithPython

That means that you expanded the source code of ITK in the directory "$HOME/src/Insight" and that you manually created the directory "$HOME/bin/InsightWithPython" with a command such as

  cd
  mkdir InsightWithPython


Select Compiler

Select your compiler by setting the environment varialbles CC and CXX

For example, if you are using zsh:

  export CC=/usr/bin/gcc-4.1
  export CXX=/usr/bin/g++-4.1   

or if you are using bash:

  setenv CC  /usr/bin/gcc-4.1
  setenv CXX /usr/bin/g++-4.1   

Please note that you should use the SAME compiler in order to build all the libraries and projects.

You want to use the explicit name of the compiler along with its version (gcc-4.1) as opposed to the generic name of the compiler (gcc). In this way, if you later update your compiler in this computer, your build of ITK will still use the proper compiler consistently.

Run ccmake

Then you should move into the BINARY directory run "ccmake" in order to configure ITK. When you run "ccmake" you provide the SOURCE directory as an argument.

  cd  InsightWithPython
  ccmake   $HOME/src/Insight

This will show an image similar to:


Insight CMake configuration


hit the "c" key in order to "configure". At this point CMake will test the capabilities of your compiler, after a couple of minutes it will show you an image similar to:


Insight CMake configuration


Proceed to do the following:

  • Turn OFF the option BUILD_EXAMPLES
  • Turn OFF the option BUILD_TESTING
  • Turn ON the option BUILD_SHARED
  • Write "Release" in the option CMAKE_BUILD_TYPE
  • In the variable CMAKE_INSTALL_PREFIX write the INSTALLATION directory


Insight CMake configuration


  • Hit the "c" key again in order to configure with these changes

CMake will then show you a screen similar to:


Insight CMake configuration


  • Now pass to the advance variables by hitting the "t" key (for "toggle to advanced") and
  • Hit the "/" key (for "search") and type "REVIEW" in order to jump to the option that can turn ON the use of new packages in ITK
  • Turn ON the option ITK_USE_REVIEW
  • Hit the "/" key (for "search") and type "WRAP_ITK" in order to jump to the option that can turn wrapping ON
  • Turn ON the option USE_WRAP_ITK


Insight CMake configuration
  • Hit the "c" key again to configure with these changes.
  • CMake will indicates that it needs to know the location of CableSwig. If you see the warning message, type "e" to exit from the warning message window.
Insight CMake configuration


  • In the CableSwig_DIR" variable type the directory where you build or installed CableSwig


Insight CMake configuration


  • You may see warning messages similar the image below, simply hit the "e" key to exit from the warning message.


Insight CMake configuration


  • Hit "c" to continue with the configuration


Insight CMake configuration
Insight CMake configuration


  • Hit the "g" key to generate

At this point ccmake will exit.

Windows with Visual Studio

Run CMakeGui

Launch CMake (cmake-gui). Note that this is the new GUI version, based on Qt, that is distributed with CMake 2.6.

Once the GUI application appears you should specify the

  • SOURCE directory at the top of the GUI in the "Where is the source code" field
  • BINARY directory in the field below, marked as "Where to build the binaries".

The CMake window will look similar to:

Initial CMake GUI for building ITK

Hit the Configure button.

If the binary directory doesn't exist yet, CMake will offer to create the directory for you.

Select Windows Compiler

If you have multiple versions of Visual Studio installed, CMake will offer you the option of selecting one of the installed versions.

The the CMake gui will look like:


Initial CMake GUI for building ITK


You MUST use the EXACT SAME compiler that you used for building CableSwig. (See: Building CableSwig)

Once you select the compiler, CMake will analyze the characteristics of your system, including your compiler. The advance of the process will be displayed in the progress bar on the bottom right corner of the CMake interface.


Initial CMake GUI for building ITK

Select Basic Options

When CMake completes analyzing your system, you will see a window similar to:


Initial CMake GUI for building ITK


At this point, you should do the following:

  • Turn OFF the option BUILD_EXAMPLES
  • Turn OFF the option BUILD_TESTING
  • Turn ON the option BUILD_SHARED_LIBS
  • In the variable CMAKE_INSTALL_PREFIX write the INSTALLATION directory (ideally the same directory where you installed CableSwig, See: Building CableSwig))


At this point the CMake window will look like:


Initial CMake GUI for building ITK


Hit the Configure button again in order to configure with these changes.

CMake will then show you a screen similar to:


Initial CMake GUI for building ITK

Select Advanced Options

Now pass to the advance variables by selecting the drop-down menu at the right of the "Search" field.


Initial CMake GUI for building ITK


The default option is "Simple View", select now "Advanced View". You will see then a window similar to:


Initial CMake GUI for building ITK


  • In the "search" field type "REVIEW" in order to jump to the option that can turn ON the use of new packages in ITK
  • Turn ON the option ITK_USE_REVIEW


Initial CMake GUI for building ITK


  • In the "search" field type "WRAP" in order to jump to the option that can turn wrapping ON
  • Turn ON the option USE_WRAP_ITK


Initial CMake GUI for building ITK


  • Hit the Configure button again in order to bring up the options related to Wrapping.
  • The progress of the configuration will be displayed on the bottom right bar


Initial CMake GUI for building ITK


  • In the "search" field type "WRAP_ITK_PYTHON" in order to jump to the option that can turn wrapping ON
  • Turn ON the option WRAP_ITK_PYTON (if it is not ON already).


Initial CMake GUI for building ITK


  • Hit the Configure button again in order to bring up the options related to Wrapping.
  • In the "search" field type "PYTHON" in order to list to the options related to Python.


Initial CMake GUI for building ITK


At this point the following CMake variables should be populated

  • PYTHON_EXECUTABLE
  • PYTHON_INCLUDE_PATH
  • PYTHON_LIBRARY

You do NOT need the PYTHON_DEBUG_LIBRARY, since you should build the wrapping for Release mode.

You may see values such as


CMake Variable Example value
PYTHON_EXECUTABLE C:/Program Files/Python2.5/python.exe
PYTHON_INCLUDE_PATH C:/Program Files/Python2.5/include
PYTHON_LIBRARY C:/Program Files/Python2.5/libs/python25.lib


Of course, your variables may be different, depending on whether you installed Python and what version of Python you are using. If any of these variables is not set, or if they are not consistent, you should double click on them and replace the offending value with the correct one.

  • Hit the "Configure" key

CMake window will look like:

Initial CMake GUI for building ITK


and if no new red variables appear, you can then hit the "Generate" button.

CMake processing window will appear as:


Initial CMake GUI for building ITK


Once the generation process is completed, the CMake interface will look like:


Initial CMake GUI for building ITK


and at this point you can quite by going to the File menu and selecting Exit.

Build

GNU/Linux

Once you quit CMake, after the configuration process has completed, you can start the build process by simply typing

      make


You will see output similar to


ITK-CMake-Linux-11.png


This will build ITK and the Python wrappers generated by CableSwig and WrapITK.

This process may take several hours depending on the capabilities of you computer.

Once the build process finishes, you can install the software in the final destination by typing


      make install

Mac

Windows

Finding the Solution File

A solution file should have been created by CMake in your BINARY directory.

Depending on your version of Visual Studio, look for

  • ITK.dsw or
  • ITK.sln

Open the solution file in your Visual Studio IDE.

Make sure that is the EXACT SAME VERSION of Visual Studio that you selected during the CMake configuration. The interface will look like:


ITK-VisualStudio-Windows-01.png


Selecting Compilation Mode

Toward the top of the IDE you will find a drop-down menu that let you choose between multiple compilation modes (for example: Debug, Release, RelDebInfo...).

  • Select Release in this menu.

as shown in the image below:


ITK-VisualStudio-Windows-02.PNG


Building the Solution

Then start the build by hitting the F7 or by going to the Build menu and selecting Build Solution


The Visual Studio IDE will look similar to:


ITK-VisualStudio-Windows-03.PNG


The build process may take a couple of hours depending on the capabilities of your computer.

This is an excellent time for reading the rest of the Tutorial,

for example the Quick Start (30 minutes)

Once the compilation finishes

  • You should select the "INSTALL" target
  • Right click on it and select "Build"

This will install the libraries in the INSTALLATION directory, as shown below


ITK-VisualStudio-Windows-04.PNG


Optionally you can now also package the libraries so that they can be installed in another computer without having to build them there.

To do this

  • Select the "PACKAGE" target
  • Right click on it and select "Build"


ITK-VisualStudio-Windows-05.PNG


Once the package files are generated the IDE will look like

ITK-VisualStudio-Windows-06.PNG


As an example, the result of the generated INSTALLER is available at:


ITK With Python Wrapping Installer

Setting up the Environment

GNU/Linux & Mac

Set the following environment variables

Here is an example of the setting for a GNU/Linux build where ITK was installed in the "$HOME/local" directory

 export ITKWRAPPEDINSTALLED=$HOME/local/WrapITK/lib/InsightToolkit
 export LD_LIBRARY_PATH=$ITKWRAPPEDINSTALLED:$ITKWRAPPEDINSTALLED/WrapITK/lib:$HOME/local/WrapITK/lib/vtk-5.4
 export PYTHONPATH=$ITKWRAPPEDINSTALLED/WrapITK/lib/:$ITKWRAPPEDINSTALLED/WrapITK/Python/

Windows

You will define several environment variables. Depending on your version of windows this is done in slightly different ways.

In Windows XP you can do

  • In the Start menu, select "My Computer"
  • In the new window that opens, right click and select "Properties"
  • In the new window that opens, select the "Advanced" tab
  • In the Advanced tab, click on the "Environment Variables"
  • Select the PATH variable and add to it the INSTALLATION/bin directory (where you installed ITK). You will use a ";" to separate this directory from others that may already exist in the list.
    • For example
      • I installed ITK in the directory D:\ProgramFiles\InsightToolkit-3.13
      • Then I added to the PATH variable the directory D:\ProgramFiles\InsightToolkit-3.13\bin
      • (note the /bin at the end)
  • Select the PYTHONPATH variable (or create it if it doesn't exist) and add to it the directory
    • INSTALLATION\lib\InsightToolkit\WrapITK\Python
      • For example, in my installation, the PYTHONPATH variable contains:
        • D:\ProgramFiles\InsightToolkit-3.13\lib\InsightToolkit\WrapITK\Python

Testing

In order to verify if your build and installation is working correctly you can do the following

  • Start the Python command line interpreter
    • In GNU/Linux and Mac this is done by simply typing "python"
    • In Windows this is done by launching from the Start menu the program "Python (command line)"
  • Once the command line window appears, type
    • import itk
    • This may take some seconds while the shared libraries are loaded.
  • If you don't get any error messages, then your build and configuration have been successful and you can proceed to start enjoying ITK for your image processing needs.

Continue with the Quick Start (30 minutes) tutorial session.