The VTK User’s Guide
11th Edition
Contributors:
Lisa S. Avila, Kitware
Utkarsh Ayachit, Kitware
Sébastien Barré, Kitware
Jeff Baumes, Kitware
Francois Bertel, Kitware
Rusty Blue, Kitware
David Cole, Kitware
David DeMarle, Kitware
Berk Geveci, Kitware
William A. Hoffman, Kitware
Brad King, Kitware
Karthik Krishnan, Kitware
C. Charles Law, Kitware
Kenneth M. Martin, Kitware
William McLendon, Sandia National Laboratories
Philippe Pebay, Sandia National Laboratories
Niki Russell, Kitware
William J. Schroeder, Kitware
Timothy Shead, Sandia National Laboratories
Jason Shepherd, Sandia National Laboratories
Andrew Wilson, Sandia National Laboratories
Brian Wylie, Sandia National Laboratories
The VTK User’s Guide
11th Edition
Published by Kitware, Inc.
Join the VTK Community at http://www.vtk.org.
Commercial support and consulting is available for this software from Kitware, Inc.
Please visit http://www.kitware.com for more information
or send email to kitware@kitware.com.
© 2010 Kitware, Inc.
http://www.kitware.com
All rights reserved. No part of this book may be reproduced, in any form or by any means,
without the express written permission of the publisher.
The publisher Kitware, Inc. offers discounts on this book when ordered in bulk quantities.
Kitware also publishes a companion text, The Visualization Toolkit An Object-Oriented
Kitware, Inc. at sales@kitware.com.
Approach to 3D Graphics by Schroeder, Martin and Lorensen, and provides
commercial training, support and consulting for VTK. For more information contact
All product names mentioned herein are the trademarks of their respective owners.
Printed in Columbia.
ISBN 978-1-930934-23-8
Contents
Part I
An Introduction to VTK
Chapter 1 Welcome
Chapter 2
Chapter 3
1.1
1.2
1.3
1.4
2.4
3.2
3.3
User Guide Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4
How to Learn VTK. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4
Software Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4
Obtaining The Software. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5
Directory Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5
Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6
Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6
Additional Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6
Installation
2.1
2.2
2.3
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9
CMake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10
Installing VTK on Windows XP, Vista or later . . . . . . . . . . . . . . . . . . . .10
Binary Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
Source Code Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12
Installing VTK on Unix Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14
Source Code Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15
CMake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15
Compiling the Source Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Building VTK On Multiple Platforms. . . . . . . . . . . . . . . . . . . . . . . .17
Installing VTK. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
System Overview
3.1
System Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19
Low-Level Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
The Rendering Engine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21
The Visualization Pipeline. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
Create An Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
User Methods, Observers, and Commands . . . . . . . . . . . . . . . . . . . .29
Tcl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30
C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30
Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36
Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36
Conversion Between Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37
3
9
19
41
Part II
Learn VTK By Example
Chapter 4
The Basics
4.1
Creating Simple Models. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42
Procedural Source Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42
Reader Source Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44
Using VTK Interactors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45
4.2
vi
Chapter 5
4.5
4.6
4.3
4.4
4.7
4.8
vtkRenderWindowInteractor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Interactor Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Filtering Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Controlling The Camera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Instantiating The Camera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Simple Manipulation Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Controlling The View Direction. . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Perspective Versus Orthogonal Views. . . . . . . . . . . . . . . . . . . . . . . 50
Saving/Restoring Camera State . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Controlling Lights . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Positional Lights. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Controlling 3D Props . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Specifying the Position of a vtkProp3D. . . . . . . . . . . . . . . . . . . . . . 52
Actors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Level-Of-Detail Actors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Assemblies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Volumes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
vtkLODProp3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Using Texture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Picking. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
vtkAssemblyPath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
vtkCoordinate and Coordinate Systems . . . . . . . . . . . . . . . . . . . . . . . . . 62
4.9
4.10 Controlling vtkActor2D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
4.11 Text Annotation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
2DText Annotation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3D Text Annotation and vtkFollower . . . . . . . . . . . . . . . . . . . . . . . 65
4.12 Special Plotting Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Scalar Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
X-Y Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Bounding Box Axes (vtkCubeAxesActor2D) . . . . . . . . . . . . . . . . . 68
Labeling Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
4.13 Transforming Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Advanced Transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
3D Widgets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
4.14 Antialiasing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Per-primitive type antialiasing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Multisampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
4.15 Translucent polygonal geometry. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
4.16 Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Animation Scene (vtkAnimationScene). . . . . . . . . . . . . . . . . . . . . . 83
Visualization Techniques
5.1
Visualizing vtkDataSet (and Subclasses) . . . . . . . . . . . . . . . . . . . . . . . . 89
Working With Data Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Color Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Contouring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Glyphing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Streamlines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Stream Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Cutting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
89
vii
Merging Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .99
Appending Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .100
Probing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Color An Isosurface With Another Scalar . . . . . . . . . . . . . . . . . . .102
Extract Subset of Cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103
Extract Cells as Polygonal Data . . . . . . . . . . . . . . . . . . . . . . . . . . .104
Visualizing Polygonal Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105
Manually Create vtkPolyData . . . . . . . . . . . . . . . . . . . . . . . . . . . . .106
Generate Surface Normals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107
Decimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107
Smooth Mesh. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .109
Clip Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .110
Generate Texture Coordinates. . . . . . . . . . . . . . . . . . . . . . . . . . . . .111
Visualizing Structured Grids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112
Manually Create vtkStructuredGrid . . . . . . . . . . . . . . . . . . . . . . . .112
Extract Computational Plane. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112
Subsampling Structured Grids. . . . . . . . . . . . . . . . . . . . . . . . . . . . .113
Visualizing Rectilinear Grids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .114
Manually Create vtkRectilinearGrid . . . . . . . . . . . . . . . . . . . . . . . .114
Extract Computational Plane. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .114
Visualizing Unstructured Grids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115
Manually Create vtkUnstructuredGrid . . . . . . . . . . . . . . . . . . . . . .115
Extract Portions of the Mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115
Contour Unstructured Grids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .117
5.2
5.3
5.4
5.5
Chapter 6
119
6.5
Image Processing & Visualization
6.1 Manually Creating vtkImageData . . . . . . . . . . . . . . . . . . . . . . . . . . . . .120
6.2
Subsampling Image Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .121
6.3 Warp Based On Scalar Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .122
Image Display. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .123
6.4
Image Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .123
Image Actor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .124
vtkImagePlaneWidget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .125
Image Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .125
ImageCanvasSource2D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .126
ImageEllipsoidSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .126
ImageGaussianSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .127
ImageGridSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .127
ImageNoiseSource. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .127
ImageSinusoidSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .128
Image Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .128
Convert Scalar Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .128
Change Spacing, Origin, or Extent . . . . . . . . . . . . . . . . . . . . . . . . .129
Append Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .129
Map Image to Color. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131
Image Luminance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132
Histogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132
Image Logic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132
Gradient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .133
Gaussian Smoothing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .133
Image Flip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .134
6.6
viii
Chapter 7
Chapter 8
Image Permute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Image Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Image Reslice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Iterating through an image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
139
Volume Rendering
Historical Note on Supported Data Types. . . . . . . . . . . . . . . . . . . . . . . 140
7.1
7.2
A Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
7.3 Why Multiple Volume Rendering Techniques? . . . . . . . . . . . . . . . . . . 142
Creating a vtkVolume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
7.4
Using vtkPiecewiseFunction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
7.5
Using vtkColorTransferFunction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
7.6
Controlling Color / Opacity with a vtkVolumeProperty. . . . . . . . . . . . 145
7.7
7.8
Controlling Shading with a vtkVolumeProperty. . . . . . . . . . . . . . . . . . 147
7.9
Creating a Volume Mapper. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
7.10 Cropping a Volume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
7.11 Clipping a Volume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
7.12 Controlling the Normal Encoding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
7.13 Volumetric Ray Casting for vtkImageData. . . . . . . . . . . . . . . . . . . . . . 153
7.14 Fixed Point Ray Casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
7.15 2D Texture Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
7.16 3D Texture Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
7.17 Volumetric Ray Casting for vtkUnstructuredGrid . . . . . . . . . . . . . . . . 157
7.18 ZSweep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
7.19 Projected Tetrahedra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
7.20 Speed vs. Accuracy Trade-offs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
7.21 Using a vtkLODProp3D to Improve Performance . . . . . . . . . . . . . . . . 161
Information Visualization
8.1
163
8.2
8.3
8.4
8.5
Exploring Relationships in Tabular Data . . . . . . . . . . . . . . . . . . . . . . . 164
Converting a Table to a Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Converting a Table to a Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Graph Visualization Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Vertex Layout. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Edge Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Converting Layouts to Geometry. . . . . . . . . . . . . . . . . . . . . . . . . . 173
Area Layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Views and Representations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Selections in Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Graph Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Boost Graph Library Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Creating Graph Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
The Parallel Boost Graph Library . . . . . . . . . . . . . . . . . . . . . . . . . 186
Multithreaded Graph Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Databases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Connecting to a Database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Executing Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Queries and Threads. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Reading Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Writing Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Table Schemata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190