From KitwarePublic
Jump to navigationJump to search

Searching the Examples

To search explicitly in the examples in the wiki (a very useful operation), you should go to google.com and use a "site" search. For example, to search the examples for "vtkCellLocator", use the string:

vtkCellLocator site:vtk.org/Wiki/VTK/Examples

Guidelines for Writing Examples

Other sources of examples

A good source of examples is the set of regression tests of each VTK Package (Common, Filtering, ...). In the source tree, they are located in VTK/<package>/Testing. Each Testing directory has the following subdirectories: Cxx (for C++ tests), Python and Tcl. The other location for examples is VTK/Examples.

Example Usage (C++)

These are fully independent, compilable examples. There is significant overlap in the examples, but they are each intended to illustrate a different concept and be fully stand alone compilable.

Please add examples in your areas of expertise!

Simple Operations

Input and Output


VTK Formats

External Formats


Geometric Objects

Save to a file In this section, the object is created, added to a polydata object, then written to a .vtp file. The file can be opened in Paraview to see the result.

Display on screen

In this section, the object is created and displayed on the screen.

Working with 3D Data

Adding Colors to Polydata

Adding Normals to Polydata

Non-standard Data These examples show how to attach your own, nonstandard fields to every point or cell in a polydata.

Point cloud operations

Miscellaneous (Field) Data Three types of data can be stored in a polydata object, PointData, CellData, and FieldData. For PointData, there must be a piece of data associated with each point (e.g. a temperature data array with the temperature at each point). For CellData, there must be a piece of data associated with each cell (e.g. the area of each triangle). For data that does not align with either points or cells, FieldData should be used. This is typically data that describes the dataset as a whole. An example could be the name of the dataset, or the center of mass of the points, etc.

Global Operations on PolyData

Working with Stuctured 3D Data

This section includes vtkImageData, vtkStructuredGrid, and vtkRectilinearGrid.

"ImageData" is not the traditional "flat, 2D image" you are used to. It is a special VTK data structure in the collection of 3D data structures provided by VTK. Here is an overview of these data structures: [1]. Image data can represent at typical 2D image, but also, a 3D volume.





Math Operations


Data Structures



See [this] for a brief explanation of the VTK terminology of mappers, actors, etc.

User Interaction

Selecting in 3D (Picking)

Working with Images

Image Processing

Working with Meshes




Geographic Visualization (Geovis)



You must turn on VTK_USE_QT and VTK_USE_GUISUPPORT in the advanced VTK build configuration.

To use QVTKWidget in the QT4 Designer, you must:

sudo cp ~/bin/VTK/bin/libQVTKWidgetPlugin.so /usr/lib/qt4/plugins/designer


You must turn on VTK_USE_MATLAB_MEX to use these.

Broken/Missing Examples (Please write/fix me!)

Some of these are simply shells waiting for a good example. Some of these have a specific problem that is noted. Please help improve them!

Developer Examples



char* Filename;


vtkSetMacro(UseTransform, bool);
vtkGetMacro(UseTransform, bool);
vtkBooleanMacro(UseTransform, bool);

Normal Variable

vtkGetMacro(ZRange, double);
vtkSetMacro(ZRange, double);

Errors and Warnings

Filters and Sources

Standard classes

Custom classes

Multiple Connections on a Single Port

Multiple Input Ports

Using STL

vtkstd namespace

The vtkstd namespace is used for STL.

#include <vtkstd/string>
#include <vtkstd/vector>
#include <vtkstd/set>
#include <vtkstd/map>
#include <vtkstd/deque>
#include <vtkstd/algorithm>

Members of these classes should be prefixed with the vtkstd namespace. For example,

vtkstd::string test;

Global namespace

The global namespace is used for streams.

#include <vtksys/ios/sstream>
#include <vtksys/ios/fstream>

Most members of these classes should not be prefixed with a namespace. For example, simply use

cout << "Hello world!";

An exception is:

std::stringstream ss;


What to do with cmath?

Needed/Missing Developer Examples

Example Usage (Python)

It would be appreciated if there are any Python VTK experts who could convert any of the above c++ examples to Python!

Simple Operations

Input and Output

Geometric Objects

Working with PolyData




Example Usage (Java)

Example Usage (Tcl)