The Visualization ToolKit (VTK) is an open source, freely available software system for 3D computer graphics, image processing, and visualization used by thousands of researchers and developers around the world. VTK consists of a C++ class library, and several interpreted interface layers including Tcl/Tk, Java, and Python. VTK supports a wide variety of visualization algorithms including scalar, vector, tensor, texture, and volumetric methods; and advanced modeling techniques such as implicit modeling, polygon reduction, mesh smoothing, cutting, contouring, and Delaunay triangulation. In addition, dozens of imaging algorithms have been directly integrated to allow the user to mix 2D imaging / 3D graphics algorithms and data. The design and implementation of the library has been strongly influenced by object-oriented principles.

Availability and Setup

VTK is not installed by default on the SCC but you can accesss it by loading the appropriate module as explained here.

For non compute-intensive tasks such as code editing and development, you can use For production visualization runs on large data sets, you should either run your VTK application in one of the batch queues (saving the results as an image file) or run your application in one of the interactive batch queues. See the RCS web pages for information on how to run interactive jobs on the SCC.

VTK consists of two basic subsystems: a compiled C++ class library and a wrapper layer for interpreted languages such as Tcl and Python. When building VTK applications you can either write a C++ program using the VTK C++ class library directly or you can write a Tcl or Python script using the “wrapped” compiled VTK C++ class library. Set things up so that you can run your VTK application as an X application on scc1 or another appropriate machine and have it display to your local machine/terminal.

Using VTK

Tcl: Tcl is one of the easiest languages with which to learn VTK. To execute a VTK Tcl script type: vtk followed by the path of the Tcl script at the shell prompt. For example:

scc1% cd /usr/local/vtk/Examples/Rendering/Tcl
scc1% vtk Cylinder.tcl

This should invoke the VTK executable which is essentially a Tcl interpreter with the wrapped VTK C++ class library.

Python: Python is another excellent language for learning VTK. However, before running Python you will need to modify your LD_LIBRARY_PATH, your PYTHONPATH, and your VTK_DATA_ROOT environment variables. These environment variables are used by Python to find additional modules and libraries such as the VTK libraries. You should add /usr/local/vtk/lib to your LD_LIBRARY_PATH, add /usr/local/vtk/python to your PYTHONPATH, and set /usr/local/vtk/VTKData to be your VTK_DATA_ROOT environment variables. For Example:

scc1% setenv LD_LIBRARY_PATH {$LD_LIBRARY_PATH}:/usr/local/vtk/lib
scc1% setenv VTK_DATA_ROOT /usr/local/vtk/VTKData
scc1% setenv PYTHONPATH {$PYTHONPATH}:/usr/local/vtk/python

If you get the error: PYTHONPATH: Undefined variable just set the PYTHONPATH directly to /usr/local/vtk/python rather than adding it:

scc1% setenv PYTHONPATH /usr/local/vtk/python

Once you have setup your environment variables, you can then execute a VTK Python script by typing: python followed by the path of the Python script at the shell prompt. For example:

scc1% cd /usr/local/vtk/Examples/Rendering/Python
scc1% python

C++: Writing a VTK application using C++ is the most flexible approach but also the most involved. Using C++ as your development language will typically result in smaller and faster applications than Tcl or Python scipts. To get you started here is an example C++ Makefile:

CPP     = g++
VTKLIBDIR = /usr/local/vtk/lib
VTKINCDIR  =  /usr/local/vtk/include
.SUFFIXES : .cxx

INCLUDE = -I${VTKINCDIR} -I/usr/X11R6/include
OPTIM   = -O2 -g -Wno-deprecated
LIBS    = -L${VTKLIBDIR} -L/usr/X11R6/lib

GLIBS   = -lXm -lGL -lm -lvtkImaging -lvtkGraphics -lvtkCommon -lvtkRendering

        $(CPP) $(CFLAGS) ${OPTIM} $< ${LIBS} ${GLIBS} -o $@

To compile your c++ application using this Makefile you would do the following:

scc1% make Mywork.cxx

Depending on which VTK libraries you use in your application, you will have to either add or subtract VTK libraries on the GLIBS line of the Makefile. The ones listed are typical libraries used in many VTK applications. The libraries which you list may include calls to other VTK libraries, etc. A shortcut to include these ‘secondary’ libraries is to set LD_LIBRARY_PATH (as described below) before compiling.

Your VTK program will look for shared libraries at run-time, so before running it, you will need to set the LD_LIBRARY_PATH environment variable:

scc1% setenv LD_LIBRARY_PATH {$LD_LIBRARY_PATH}:/usr/local/vtk/lib

Additional Help/Documentation

For more informations on VTK, visit the VTK website or the VTK Wiki. The manual for version 5.2 of VTK is available online, along with an overview of the package. If you are just starting to learn VTK, we recommend that you get the VTK User’s Guide which is available from Kitware.

Our Introduction to VTK tutorial is also available and has more in depth information on using VTK than this help page provides. Our installation of VTK comes with many VTK demo programs which are described on the VTK Examples web page. We also have some of our own VTK example programs associated with the live version of a VTK tutorial we have offered in the past (the PowerPoint slides for this are also available).

As part of our 2008 Workshop on Scientific Visualization, a talk on VTK and ParaView (a GUI-based visualization application built on top of VTK) was presented which you might find useful.

An updated talk on Scientific Visualization using VTK was presented in February, 2010. Demos and data used in the tutorial are also available.

There are also several VTK tutorials available online:

  1. How to Create Visualizatio Applications with VTK
  2. An introduction to Programming for Medical Image Analysis With the Visualization Toolkit
  3. Visualizing with VTK: A Tutorial (PDF)