Visualizing With VTK: A Tutorial: IEEE Computer Graphics and Applications September 2000
Visualizing With VTK: A Tutorial: IEEE Computer Graphics and Applications September 2000
net/publication/220518491
CITATIONS READS
156 2,307
3 authors, including:
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Lisa Avila on 03 July 2014.
20 September/October 2000 0272-1716/00/$10.00 © 2000 IEEE IEEE Computer Graphics and Applications 21
Tutorial
Render window and renderers be used. Otherwise, vtkDataSetMapper must be used. vtkSLCReader negReader ren2 AddProp posActor
To visualize your data, you first need to open a win- The following fragment of Tcl code can be used to cre- negReader SetFileName “neghip.slc” renWin Render
dow on the computer screen. vtkRenderWindow is an ate a polygonal cube and place it in the scene. In this
abstract superclass representing the object into which code segment and others following, note that lines of vtkVolumeTextureMapper2D negMapper The combined VTK rendering process has a few lim-
one or more renderers draw. Like most graphics objects, code ending with a backslash (\) indicate a carryover negMapper SetInput \ itations. VTK doesn’t support translucency of geomet-
it automatically instantiates the correct device-depen- of code that didn’t fit onto one line. The indented line [negReader GetOutput] ric data because the primitives aren’t sorted into a
dent subclass for your platform. The vtkRenderWindow following belongs with the preceding line. Simply delete back-to-front ordering before rendering. Multiple vol-
is a container class for vtkRenderer objects, and multi- the \ and type in a single line of code. The hardest step in volume visualization is often umes can be rendered in the same scene only if the
ple renderers can be tiled within a single render win- defining the transfer functions that map the scalar data bounds of the volumes don’t overlap. Opaque geometry
dow to create complex visualizations. In this example vtkCubeSource cubeData values into color and opacity. In this example we’ll use can overlap volumes using the ray casting and texture
we’ll place two renderers with different background col- a simple ramp from 0.0 to 0.2 for opacity, with the color mapping approaches, but not if a vtkVolumeProMapper
ors side by side within the render window. The place- vtkPolyDataMapper cubeMapper function ranging through red, blue, and green. is used because of limitations with this hardware.
ment location is specified using normalized (0, 1) cubeMapper SetInput \
viewport coordinates in the render window: [cubeData GetOutput] vtkPiecewiseFunction negOpacity Rendering 2D data
negOpacity AddPoint 0 0.0 In addition to 3D geometric and volumetric data, VTK
vtkRenderWindow renWin vtkActor cubeActor negOpacity AddPoint 255 0.2 visualizes 2D data such as geometry, images, and text.
renWin SetSize 600 300 cubeActor SetMapper cubeMapper In the examples given here we’ll render 2D data into a
vtkColorTransferFunction negColor 3D renderer to intermix 2D and 3D data. Alternatively,
vtkRenderer ren1 ren1 AddProp cubeActor negColor AddRGBPoint 64 1.0 0.0 0.0 if we only have 2D data, we can use an image viewer for
ren1 SetViewport 0.0 0.0 0.5 1.0 ren1 ResetCamera negColor AddRGBPoint 128 0.0 0.0 1.0 visualization.
ren1 SetBackground 0.8 0.4 0.2 renWin Render negColor AddRGBPoint 196 0.0 1.0 0.0 The concept of actors, mappers, and properties
renWin AddRenderer ren1 applies to both 2D and 3D data, although some of the
Since the output of the vtkCubeSource object is polyg- The first value defined when adding a point into a specific parameters change. In the code fragment below,
vtkRenderer ren2 onal data, an instance of vtkPolyDataMapper renders transfer function is always the scalar value, with one we add annotation to the renderer that displays the
ren2 SetViewport 0.5 0.0 1.0 1.0 the data. The ResetCamera() method centers the cam- value following it for a vtkPiecewiseFunction or an RGB cube. A vtkActor2D represents the title in the scene, a
ren2 SetBackground 0.1 0.2 0.4 era on the data. triple following it for a vtkColorTransferFunction. Since vtkTextMapper holds and renders the data (which in
renWin AddRenderer ren2 The following fragment of Tcl code rotates the cube we’re visualizing 8-bit data, the scalar values in this this case is a string), and the vtkActor2D automatically
and changes the color to pink: example range from 0 to 255. creates a vtkProperty2D. Note, here and in code seg-
renWin Render Now that we’ve defined the two required transfer ments following, some long individual code words
cubeActor RotateX 30.0 functions, we can create the volume property and the include hyphens because they didn’t fit onto one line. A
The vtkRenderWindow object manages the render cubeActor RotateY 20.0 volume. hyphen, like a \, also indicates a carryover, but of a sin-
process, so a single Render() call will cause the window [cubeActor GetProperty] \ gle word. When typing in the code, delete the hyphens
to map onto the screen and the renderers to update their SetColor 1.0 0.7 0.7 vtkVolumeProperty negProperty to recreate a single word.
display. At this point in the example only solid back- negProperty SetColor negColor
ground color will appear because we haven’t defined renWin Render negProperty SetScalarOpacity \ vtkTextMapper titleMapper
any props. negOpacity titleMapper SetInput \
Use the GetProperty() method of the actor to access “This is a Pink Cube”
Props, mappers, and properties the automatically created property object. vtkVolume negVolume titleMapper \
Props are the objects added to the renderer to create negVolume SetMapper negMapper SetJustificationToCentered
a scene. The class vtkProp is an abstract superclass for all Rendering 3D volumetric data negVolume SetProperty negProperty
2D and 3D props and contains information about visi- The vtkImageData object can be used to represent vtkActor2D titleActor
bility, orientation, size, and position. Props associate one-, two-, and three-dimensional image data. As a sub- ren2 AddProp negVolume titleActor SetMapper titleMapper
with a mapper and a property object. The mapper refers class of vtkDataSet, vtkImageData can be represented ren2 ResetCamera [titleActor GetProperty] \
to an input data object (described in the section on the by a vtkActor and rendered with a vtkDataSetMapper. In renWin Render SetColor 1 1 0
visualization pipeline), and it knows how to render the 3D this data can be considered a volume. Alternatively, set pc [titleActor \
data object. The property object contains rendering it can be represented by a vtkVolume and rendered with Intermixing geometry and volumes GetPositionCoordinate]
parameters such as color and material properties. In the a subclass of vtkVolumeMapper. Since some subclasses The VTK rendering process can combine multiple $pc SetCoordinateSystemToNormalized-
next three sections we’ll cover some concrete subclass- of vtkVolumeMapper use geometric techniques to ren- actors and volumes in the same scene. In the following Viewport
es for props, mappers, and properties that can be used der the volume data, the distinction between volumes example, a polygonal surface is displayed intermixed $pc SetValue 0.5 0.92
for rendering 3D surface geometric data, 3D volumet- and actors mostly arises from the different terminology with the volume.
ric data, and 2D geometry, text, and images. and parameters used in volumetric rendering as ren1 AddProp titleActor
opposed to the underlying rendering method. vtkPolyDataReader posReader renWin Render
Rendering 3D geometric data VTK currently supports three types of volume ren- posReader SetFileName \
One specific subclass of vtkProp that can be used to dering—ray tracing, 2D texture mapping, and a method “poshipsurface.vtk” The code required to change the color of the text
represent 3D geometric data in a scene is vtkActor. The that uses the VolumePro graphics board.5 Although the resembles the code used to change the cube’s color.
actor object will automatically create a default vtkProp- example in this section uses the 2D texture mapping vtkPolyDataMapper posMapper However, 3D actors are positioned using world coordi-
erty object, but requires the user to specify a subclass of approach, you could change it to use an alternative posMapper SetInput \ nates, whereas we chose to position this 2D actor in a
vtkMapper. Depending on the nature of the geometry method with only minor modifications. [posReader GetOutput] normalized viewport coordinate system.
referred to by the mapper, either the subclasses vtk- To begin our volume-rendering example, we’ll load a Since 2D data is often used for annotation, VTK offers
DataSetMapper or vtkPolyDataMapper must be used. If 3D structured data set of unsigned char values and use vtkActor posActor several objects that combine multiple 2D actors and
the data contains points, lines, and polygons represent- this as input for the volume mapper vtkVolumeTex- posActor SetMapper posMapper mappers into one 2D actor. For example, the vtkScalar-
ed using a vtkPolyData, then a vtkPolyDataMapper can tureMapper2D. BarActor object combines text and 2D polygons to
transformF SetInput [cone GetOutput] 5. H. Pfister et al., “The VolumePro Real-Time Ray-Casting
transformF SetTransform transform System,” Proc. Siggraph 99, ACM Press, New York, Aug. Additional Resources for VTK
1999, pp. 251-260. Visit http://www.visualizationtoolkit.org to access the VTK
vtkGlyph3D glyph community Web site. Here you’ll find information including
glyph SetInput [ptMask GetOutput] instructions for obtaining the software, online documentation, the
glyph SetSource [transformF \ results of the quality testing process for the nightly release, and
GetOutput] pointers to academic and commercial sites that use VTK.
5 This figure glyph SetVectorModeToUseNormal William J. Schroeder is first
shows a polygo- glyph SetScaleModeToScaleByVector author of The Visualization Toolkit Obtaining the software
nal mesh glyph SetScaleFactor 0.004 textbook and is currently president VTK is available as an official release version and as a nightly
acquired from a and co-founder of Kitware. He is also release. The source code for either of these versions, along with
laser scanner vtkPolyDataMapper spikeMapper a research faculty member at Rens- data sets and test images may be downloaded from the VTK Web
that has been spikeMapper SetInput [glyph selaer Polytechnic Institute. His site or obtained via anonymous CVS (a source code, revision
decimated, GetOutput] research interests include visualiza- control system). Precompiled binaries are available on the Web site
smoothed, and tion, computational geometry, and numerical analysis. for Windows and Linux. A CD with the latest official release may be
glyphed to vtkActor spikeActor He received a BS in mechanical engineering from the Uni- purchased from Kitware.
indicate surface spikeActor SetMapper spikeMapper versity of Maryland College Park in 1980 and a PhD in If you plan to use VTK as a tool by developing applications with it
normals. [spikeActor GetProperty] \ applied mathematics from RPI in 1991. using C++ or one of the scripting interfaces, then you’ll probably
SetColor 0 .79 .34 want to download the latest official release.
If you plan to modify and extend the VTK source code, then
We then add the two actors to the renderer and you’ll probably want to work with the nightly release. Users can
render the scene: examine the Web-based quality dashboard (http://public.kitware
Lisa Sobierajski Avila is a tech- .com/vtk/quality/MostRecentResults/) and decide whether the
vtkRenderer ren3 nical contributor and vice president system is stable enough on any given day to obtain a periodic
of Kitware, where she is involved in update. The dashboard generates every night after extensive
vtkRenderWindow renWin2 the development of volume rendering testing across a variety of platforms.
renWin2 AddRenderer ren3 software for medical and scientific
applications. Her research interests Help
normals SetInput [smoother \ vtkRenderWindowInteractor iren2 include volume visualization, haptic In addition to the testing described above, VTK is supported
GetOutput] iren2 SetRenderWindow renWin2 interaction, and level-of-detail rendering. She received her through books, training courses, and support contracts by Kitware.
normals SetFeatureAngle 60 BS, MS, and PhD in computer science from State Univer- Commercial products such as Principia, Mathematica’s graphical
ren3 AddActor fran sity of New York at Stony Brook in 1989, 1990, and 1994, pipeline editor, can aid in the development of VTK applications (see
vtkPolyDataMapper mapper ren3 AddActor spikeActor respectively. http://www.principiamathematica.com).
mapper SetInput [normals GetOutput] renWin2 Render Descriptions of the underlying work are available from two
sources. The textbook1 describes many of the algorithms and data
vtkActor fran Figure 5 shows the final image. structures in VTK. The User’s Guide (http://www.kitware.com)
fran SetMapper mapper describes how to install, use, and extend VTK.
[fran GetProperty] \ Extending VTK William A. Hoffman is currently In addition to commercial products and services, the VTK
SetColor 1 0.49 0.25 The object-oriented design of VTK lets users add their vice president and a technical lead at community provides many free resources. The vtkusers mailing list
own data objects and filters. For example, vtkDataSet is Kitware. His research interests is a resource for beginners and developers alike. Approximately 900
The next leg of the network is interesting because it an abstract class that defines an application program- include development of object-ori- subscribers answer questions, post bug fixes, and help VTK users
uses a filter that takes two inputs. The first input is a data ming interface (API) that all data sets must follow. By ented toolkits and systems for visu- get the most out of the software. Instructions for joining the list can
set containing some points; the second defines a glyph subclassing from vtkDataSet, the user can create a data alization and computer vision be found on the VTK Web site. A searchable archive lets you find
represented with polygonal data. (Here we use a cone, object that all filters accepting vtkDataSet as input can software. He holds a BS in computer and follow interesting technical threads.
rotated by a transform to face in the direction expected process (such as contouring). Such extensibility is true science from the University of Central Florida in 1990 and Members of the VTK community have developed resources that
by the vtkGlyph3D class.) We use the filter vtkMask- of almost every subsystem found in VTK, including the an MS in computer science from Rensselaer Polytechnic the general community can use. Sebastian Barre maintains an
Points to randomly select the points to glyph (to avoid graphics subsystem. For further resources, see the “Addi- Institute in 1992. extensive list of Web links at http://www.hds.utc.fr/~barre/vtk/
visual clutter): tional Resources for VTK” sidebar. ■ links.html to resources such as the source code for pipeline and
object browsers, a VTK benchmark program and results from many
vtkMaskPoints ptMask platforms, and a description of the process used by Jan Sifter and
ptMask SetInput [normals GetOutput] References Readers may contact the authors at Kitware, 469 Clifton collaborators to build online VTK documentation using doxygen
ptMask SetOnRatio 10 1. W. Schroeder, K. Martin, and W. Lorensen, The Visualiza- Corporate Parkway, Clifton Park, NY 12065, e-mail (an open-source documentation system; see http://www.stack.nl/
ptMask RandomModeOn tion Toolkit: An Object-Oriented Approach to 3D Graphics, {will.schroeder, lisa.avila, bill.hoffman}@kitware.com. ~dimitri/doxygen/index.html).
2nd ed., Prentice-Hall, Old Tappan, N.J., 1998.
vtkConeSource cone 2. C. Upson et al., “The Application Visualization System: A
cone SetResolution 6 Computational Environment for Scientific Visualization,”
IEEE Computer Graphics and Applications, Vol. 9, No. 40,
vtkTransform transform July 1989, pp. 30-42. View publication stats
transform Translate 0.5 0.0 0.0 3. Data Explorer Reference Manual, IBM, Armonk, New York,
1991.
vtkTransformPolyDataFilter \ 4. IRIS Explorer User’s Guide, Numerical Algorithms Group,
transformF Oxford, UK, 2000.