Simones Blog

RSS

VTK with Java Wrapper with Ubuntu

As I had some problems to get started with the Visualization Toolkit (VTK)  under Java and Ubuntu, here are some installation instructions:

JAVA

Of course you need JAVA installed: On the command line, type 

sudo apt-get install openjdk-6-jdk

Cmake

You need Cmake to compile VTK. On the command line, type

sudo apt-get install cmake

OpenGL

You need the OpenGL Headers to use VTK. On the command line, type

sudo apt-get install freeglut3-dev libgl1-mesa-dev libglu1-mesa-dev libxt-dev mesa-common-dev xlibmesa-gl-dev libxmu-dev libxmu-headers  liblut3-dev libglut3 libx11-dev xorg-dev libosmesa6-dev

VTK

Download the source code: http://www.vtk.org/VTK/resources/software.html#previous. I tested it with version 5.4.2. Unpack the downloaded archive in any folder you want. I will call this from now on $vtkfolder.

On the command line, move into $vtkfolder, then start Cmake in wizard mode: type

cmake -i

You will be asked if you want to see the advanced options, and you’ll answer with “yes”. 

Cmake will ask a lot of parameters. Basically, you can enter everything as you want/need. I chose all default values except for the following two: 

  1. I switched BUILD_SHARED_LIBS to “ON”
  2. I switched VTK_WRAP_JAVA to “ON”

As soon as Cmake is finished, type: 

sudo make

Then wait. 

If everything worked fine, you’ll find a file vtk.jar in $vtkfolder/bin. 

Running JAVA/VTK applications

Ok, now you’re ready to go. Set up your build path. In eclipse, you can do this by right-clicking on the project, choose “Build path”, then “Add external archive”, and then choose the vtk.jar in $vtkfolder/bin. 

If you now want to run a Java program using VTK, you’ll have to configure your run configurations. In eclipse, you can do this by right-clicking on the class you want to run, click “Run as” and then “Run configurations”. In the following dialogue, choose the tab “Environment” and click “New”. As variable name you enter “LD_LIBRARY_PATH”, as value you enter $vtkfolder/bin (of course you have to substitute $vtkfolder by your installation folder). Click “Apply”, than “Run”. Voila!