Difference between revisions of "SimpleITK/GettingStarted/Visual guide to building on Linux"

From KitwarePublic
Jump to navigationJump to search
Line 10: Line 10:
 
* [http://www.ubuntu.com/download Ubuntu]
 
* [http://www.ubuntu.com/download Ubuntu]
 
* [http://www.linuxmint.com/download.php Linux Mint]
 
* [http://www.linuxmint.com/download.php Linux Mint]
 +
* [http://www.debian.org/ Debian]
 +
 +
And here is a [http://www.makeuseof.com/tag/debian-ubuntu-linux-mint-distribution/ comparison of those distributions].
  
 
There are many online tutorials explaining how to install your chosen Linux distribution:
 
There are many online tutorials explaining how to install your chosen Linux distribution:
Line 17: Line 20:
 
** [https://seogadget.co.uk/the-ubuntu-installation-guide The Ubuntu Installation Guide (with pictures)]
 
** [https://seogadget.co.uk/the-ubuntu-installation-guide The Ubuntu Installation Guide (with pictures)]
 
*Mint
 
*Mint
** [http://ftp.heanet.ie/pub/linuxmint.com/docs/user-guide/english_11.1.pdf Linux Mint User Guide (English)]
+
** [http://www.linuxmint.com/documentation/user-guide/english_15.0.pdf Linux Mint User Guide (English)]
 
** [http://www.howtogeek.com/howto/20079/install-linux-mint-on-your-windows-computer-or-netbook/ Install Linux Mint on your Windows computer (howtogeek)]
 
** [http://www.howtogeek.com/howto/20079/install-linux-mint-on-your-windows-computer-or-netbook/ Install Linux Mint on your Windows computer (howtogeek)]
 
** [http://www.youtube.com/watch?v=7IK35nZuTlk How to Install Linux Mint (youtube)]
 
** [http://www.youtube.com/watch?v=7IK35nZuTlk How to Install Linux Mint (youtube)]
 +
*Debian
 +
** [https://www.youtube.com/watch?v=TIuOFqQ-XTk Debian 7 Installation (youtube)]
 +
** [http://www.wikihow.com/Install-Debian Install Debian]
  
 
If you are a Windows user, you may consider running Linux on a virtual machine. Some popular virtual machine environments are:
 
If you are a Windows user, you may consider running Linux on a virtual machine. Some popular virtual machine environments are:
 
* [https://www.virtualbox.org/ VirtualBox]
 
* [https://www.virtualbox.org/ VirtualBox]
 
* [http://www.vmware.com/ VMWare]
 
* [http://www.vmware.com/ VMWare]
 +
 +
If you are a Mac OS X user, you can run also run Linux in a virtual machine.  Two virtual machine environments for OS X are:
 +
* [http://www.parallels.com/products/desktop/ Parallels]
 +
* [http://www.vmware.com/products/fusion/ VMWare Fusion]
  
 
Again, there are heaps of tutorials:
 
Again, there are heaps of tutorials:
 
* [http://www.psychocats.net/ubuntu/virtualbox Installing Ubuntu inside Windows using VirtualBox]
 
* [http://www.psychocats.net/ubuntu/virtualbox Installing Ubuntu inside Windows using VirtualBox]
 
* [http://www.wikihow.com/Install-Ubuntu-on-VirtualBox How to Install Ubuntu on VirtualBox]
 
* [http://www.wikihow.com/Install-Ubuntu-on-VirtualBox How to Install Ubuntu on VirtualBox]
* [http://www.itworld.com/software/230123/install-linux-mint-12-virtualbox Install Linux Mint 12 in VirutalBox]
+
* [http://www.zealfortechnology.com/2014/03/install-linux-mint-16-on-virtualbox.html Install Mint 16 on VirtualBox]
 
* [http://www.youtube.com/watch?v=D-NYWSoiaTg How to Install Linux Mint in Virtualbox (youtube)]
 
* [http://www.youtube.com/watch?v=D-NYWSoiaTg How to Install Linux Mint in Virtualbox (youtube)]
  
This guide uses Linux Mint 12, but the steps are very similar for other Linux distributions.
+
This guide uses Debian 7, but the steps are very similar for other Linux distributions.
  
 
== Step 2: Install build tools ==
 
== Step 2: Install build tools ==

Revision as of 12:46, 11 March 2014

This guide gives detailed instructions for building SimpleITK on Linux. It is written for beginners getting started with SimpleITK.

Why Linux?

  • Linux is freely available
  • It has all the required tools
  • Did I mention it's free?

Step 1: Get Linux

The first step is to install a Linux distribution. Some popular ones are:

And here is a comparison of those distributions.

There are many online tutorials explaining how to install your chosen Linux distribution:

If you are a Windows user, you may consider running Linux on a virtual machine. Some popular virtual machine environments are:

If you are a Mac OS X user, you can run also run Linux in a virtual machine. Two virtual machine environments for OS X are:

Again, there are heaps of tutorials:

This guide uses Debian 7, but the steps are very similar for other Linux distributions.

Step 2: Install build tools

Install the build tools by opening the terminal

The next step is to install the required build tools.

In the terminal, use apt-get to install the build tools

Open a terminal window (Menu > Terminal) and run the following command:

sudo apt-get install cmake cmake-curses-gui gcc g++ git giggle monodevelop

Confirm that you want to install the packages (press "y"), then wait for the installation to complete.

Build tools could also be installed using the software manager

Alternatively, you could manually select each software package from the Software Manager (Menu > Software Manager).

Step 3: Get SimpleITK source code

The next step is to get the SimpleITK source code using git.

Decide where you want to put the source code. I'm putting mine in home/ITK:

cd ~
mkdir ITK
cd ITK
Create a directory to place the source code using the Terminal or the file manager

Of course you can do this visually via the file manager (Menu > Files).

Get the SimpleITK source code using git

Now download the SimpleITK source code, by entering the following command in the Terminal:

git clone --recursive  http://itk.org/SimpleITK.git

Now change to the SimpleITK directory:

cd SimpleITK

Step 4: Build SimpleITK

The next step is to start building.

The recommended way to build is via the so-called "super build":

mkdir Build
cd Build
sudo cmake ../SuperBuild

If you prefer not to build with elevated privileges (i.e. omit sudo) you can firstly install Python distribute:

sudo apt-get install curl
curl -O http://python-distribute.org/distribute_setup.py
sudo python distribute_setup.py

and then simply execute CMake:

cmake ../SuperBuild

The SuperBuild generates make files which takes care of downloading and building ITK, SWIG, and Lua, as well as SimpleITK. On my system, by default, wrappers were generated for C# and Lua.

To start the (long) build process, type:

make

On my laptop (Acer Aspire 5755G, Intel® Core™ i7-2630QM CPU @ 2.00GHz × 8, 2GB RAM) the build took about 4 hours.

After the build is finished, you need to add SimpleITK to your LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/ITK/SimpleITK/Build/lib

You can now (optionally) check whether the build was successful:

cd SimpleITK-build
ctest

All (or at least most) of the tests should pass.

Step 5: Use SimpleITK

A simple C# program

Open MonoDevelop

This section will describe how to create a simple C# application using SimpleITK from MonoDevelop.

Open MonoDevelop (Menu > Programming > MonoDevelop).

Create Console Project

Select File > New > Solution.

Select C# > Console Project. Enter a suitable name e.g. "SimpleITK" and uncheck "Create directory for directory". Select "Forward" and then "OK".

Edit References

In the Solution explorer, right-click "Selection" and select "Edit References...".

Add SimpleITKCSharpManaged.dll

Select the ".Net Assembly" tab, navigate to "~/ITK/SimpleITK/Build/SimpleITK-build/Wrapping/CSharpBinaries", select "SimpleITKCSharpManaged.dll", click "Add", and then close the window by selecting "OK". This will copy "SimpleITKCSharpManaged.dll" to your build directory e.g. "bin/Debug" or "bin/Release". You must also manually copy "libSimpleITKCSharpNative.so" to your build directories:

mkdir ~/Projects/SimpleITK/bin/Debug
mkdir ~/Projects/SimpleITK/bin/Release
cp ~/ITK/SimpleITK/Build/SimpleITK-build/Wrapping/CSharpBinaries/libSimpleITKCSharpNative.so ~/Projects/SimpleITK/bin/Debug
cp ~/ITK/SimpleITK/Build/SimpleITK-build/Wrapping/CSharpBinaries/libSimpleITKCSharpNative.so ~/Projects/SimpleITK/bin/Release

SimpleITK has now been added as a project reference.

A simple C# program

The following short program reads a file from the SimpleITK testing data, applies a binary threshold, and writes the output to the project binary directory:

using System;
using System.IO;
using ITK = itk.simple.SimpleITK;

namespace SimpleITK {
    class MainClass {
        public static void Main (string[] args) {
            string inputFilename = "/home/dan/ITK/SimpleITK/Testing/Data/Input/cthead1.png";
            if (File.Exists(inputFilename)) {
                var input = ITK.ReadImage(inputFilename);
                var binary = ITK.BinaryThreshold(input, 100, 255, 255, 0);
                ITK.WriteImage(binary, "cthead1-binary.png");
            } else {
                Console.WriteLine("File '{0}' does not exist", inputFilename);
            }
        }
    }
}

To build the project press "F8" or select Build > Build All from the menu.

To debug the project, add a breakpoint at a desired location and press "F5".

A more complex C# program

Using Lua