VTK Basics
Description
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 available on all of the Linux and Katana Cluster machines. For non compute-intensive tasks such as code editing and development, you can use cootie.bu.edu or katana.bu.edu. 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 SCV web pages for information on how to run interactive jobs on the Linux Cluster or the Katana Cluster.
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 skate 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:
skate:% cd /usr/local/vtk/Examples/Rendering/Tcl
skate:% 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 your VTK_DATA_ROOT environment variables. For Example:
skate:% setenv LD_LIBRARY_PATH {$LD_LIBRARY_PATH}:/usr/local/vtk/lib
skate:% setenv VTK_DATA_ROOT /usr/local/vtk/VTKData
skate:% 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:
skate:% 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:
skate:% cd /usr/local/vtk/Examples/Rendering/Python
skate:% python Cylinder.py
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
LOCAL =
INCLUDE = -I${VTKINCDIR} -I/usr/X11R6/include
OPTIM = -O2 -g -Wno-deprecated
CFLAGS = ${INCLUDE}
LIBS = -L${VTKLIBDIR} -L/usr/X11R6/lib
GLIBS = -lXm -lGL -lm -lvtkImaging -lvtkGraphics -lvtkCommon -lvtkRendering
.cxx:
$(CPP) $(CFLAGS) ${OPTIM} $< ${LIBS} ${GLIBS} -o $@
To compile your c++ application using this Makefile you would do the following:
skate:% 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:
skate% setenv LD_LIBRARY_PATH {$LD_LIBRARY_PATH}:/usr/local/vtk/lib
Additional Help/Documentation
For more informations on VTK, visit the VTK web site 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.
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:
- How to Create Visualizatio Applications with VTK
- An introduction to Programming for Medical Image Analysis With the Visualization Toolkit
- Visualizing with VTK: A Tutorial (PDF)
Document Name: vtk
Author/Maintainer: Aaron D. Fuegi (aarondf@bu.edu), Ray Gasser (rayg@bu.edu)
Executable: /usr/local/vtk/bin/vtk
Keywords: vtk, visualization
Machines List: Katana Cluster, Linux Cluster
Related Help Pages: VTK Examples
Created September 15, 2004; Last Revised September 15, 2004 Last Modified March 2, 2010
URL of this document: http://scv.bu.edu/documentation/software-help/scivis/vtk.html
Go up to SCV Software Packages
|