Java VTK Examples

The Visualization ToolKit (VTK) is an open source, freely available software system for 3D computer graphics, image processing, and visualization. VTK consists of a C++ class library, and several interpreted interface layers including Tcl/Tk, Java, and Python.

Most of the examples in the official VTK distribution are either in Tcl or Python with user interface written in Tk. There are only few examples of using VTK from Java.

The VTK-Examples package aims to demonstrate how to use VTK from Java, in particular how to combine VTK and Swing GUIs. Currently many examples are translation of original Tcl examples. They retain original names and are organized in similar directory structure.

Most of the Java examples in this package are deliberately written to utilize Swing GUI components as this helps in providing illustration how VTK can be a part of larger Java applications. Java and Swing programming style is preferred to original Tcl/Tk. For the record, there are also some examples that demonstrate how simple applications can be written using "pure" VTK (no Swing involved). For instance, Flamingo2 and ProcrustesAlignment2.

The directory structure used by VTK-Examples is the same as one used by VTK. Subdirectory Examples contains all examples. Directory Wrapping contains support classes used by examples. Example called ExampleTree (Examples/Java/GUI) can be used to lunch all the other examples (except the "pure" VTK examples).

For examples how VTK can be integrated into existing Java application see the VTK Filter plugins for ImageJ, currently part of the 3D-Toolkit plugin bundle.

Java VTK Examples were tested with Java 1.4.* and VTK 4.2 and newer on Linux and Windows. Help in testing the examples on Mac OS X and other platforms is greatly appreciated.

Compiling and Running Examples

  1. Compile VTK from source using recent CVS trunk (nightly?) rather than release brunches. When compiling enable Java wrapping (VTK_WRAP_JAVA=ON), vtkHybrid kit (VTK_USE_HYBRID=ON), and vtkRendering kit (VTK_USE_RENDERING=ON).

    Release version of VTK do not include classes vtk.vtkPanel and vtk.vtkCanvas in the vtk.jar library needed by most of the examples (last checked with release version 4.2.5).

  2. Install VTK Data, optionally setup environment variable VTK_DATA that contains path to where VTK Data were unpacked.

  3. Install Ant (

  4. Edit file in the VTK-Examples root directory and set properties vtk.classpath and vtk.src.path to values corresponding to your VTK installation.

  5. Using command prompt, change directory to the VTK-Examples root directory (directory containing the files and build.xml)

  6. To compile examples and run the ExampleTree example, at the command prompt type

    $ ant


    $ ant run

    assuming that you added ANT_HOME/bin directory to your path.

Testing Example Renderings versus Baseline

VTK-Examples subdirectory 'data/baseline' contains images showing expected rendering output for each of the Java VTK Examples (it can also be viewed here). The Ant build script can be used to verify that rendering on you systems are the same as the baseline.

  1. To perform testing, you will need to download JUnit (

  2. Copy junit.jar (contained in JUnit ZIP file) to Ant's lib directory.

  3. Tests are performed executing Ant's test target. To do that, at the command prompt type 'ant test'

A web page containing information about passed and failed test will be generated in subdirectory 'build/test/report' (The main file is 'index.html').