From KitwarePublic
Revision as of 09:36, 11 August 2010 by Daviddoria (Talk | contribs)

Jump to: navigation, search

About the Examples

VTK is a large and powerful toolkit for visualization and modelling. New users can be overwhelmed by the size and what appears to be the complexity of the toolkit. There are several resources to help the new user:

In addition to these compilations of information, hundreds of tests are distributed with the toolkit source. The tests reside in Kit/Testing directories in the source distribution. However, these tests are meant to exercise the toolkit rather than illustrate how to use it. For the most part, the tests are not good educational resources.

The VTK source distribution also includes a sizeable number of examples. The goal of the VTK examples is to illustrate specific VTK concepts in a consistent and simple format. Some have been there since the inception of the toolkit. These examples have been subject to peer review and revision over the years. However, these examples only cover a small part of the capabilities of VTK.

Recently (February 7, 2009), spurred by a new user, David Doria, we are using the VTK Wiki to provide examples that will help new VTK and experienced VTK users. Users seeking solutions can use the wiki to find examples that answer questions like, "How do I extract normals from a filter's output?", "How do I generate models from segmented data?", "How do I compute the area of a triangle?", "How do I generate a foo model from bar input?". Over time we hope that the examples will answer many of the users' questions. Some questions won't have a solution in the current example repertoire. For those questions, we encourage the user to create a simple example that illustrates either a dilemma or a new solution.


Information for Wiki Examples Users

If you just want to use the Wiki Examples, go here. You will learn how to search for examples, build a few examples and build all of the examples.

Information for Wiki Examples Developers

If you want to contribute examples go here. You will learn how to add a new example and the guidelines for writing an example.

Information for Wiki Examples Administrators

If you are a Wiki Example Administrator or want to learn more about the process go here. You will learn how the Wiki Examples repository is organized, how the repository is synced to the wiki and how to add new topics, tests and regression baselines.

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!

Input and Output


VTK Formats

Example Name VTK Classes Demonstrated Description
Read an unstructured grid (.vtu) file vtkXMLUnstructuredGridReader
Read a polygonal data (.vtp) file vtkXMLPolyDataReader
Read a image data (.vti) file vtkXMLImageDataReader
Read a structured grid (.vts) file vtkXMLStructuredGridReader
Read a rectilinear grid (.vtr) file vtkXMLRectilinearGridGreader
Read an XML file and later decide what kind it is vtkXMLGenericDataObjectReader

Legacy Formats

Example Name VTK Classes Demonstrated Description
Read any type of legacy .vtk file vtkGenericDataObjectReader
Read a structured grid (.vtk) file vtkStructuredGridReader
StructuredPointsReader vtkStructuredPointsReader

External Formats

Example Name VTK Classes Demonstrated Description
Read a simple "xyz" file of points vtkSimplePointsReader
Read an "xyza" file vtkParticleReader
Read a plain text file into a polydata vtkPolyData Manually read a file using getline()
Read a delimited file into a polydata vtkDelimitedTextReader
Read an OBJ (.obj) File vtkOBJReader
Convert a series of DICOM files into a VTI File vtkDICOMImageReader
Read a VRML (WRL) file vtkVRMLImporter
Read DICOM file vtkDICOMImageReader
Report the contents of a VTK XML or legacy file vtkDataSetReader
Read DEM (elevation map) files vtkDEMReader
Read TIFF (.tif) files vtkTIFFReader
Read BMP (.bmp) files vtkBMPReader
Read stereo lithography STL (.stl) files vtkSTLReader
Read PLY (.ply) files vtkPLYReader
Read PNM (.pnm) files vtkPNMReader
Read PLOT3D (.bin) files vtkPLOT3DReader Read CFD (computational fluid dynamics) data produced by PLOT3D.


Example Name VTK Classes Demonstrated Description
Write a .vtu file vtkXMLUnstructuredGridWriter VTU is an "Unstructured Grid". This format allows for 3D data to be stored.
Write a .vtp file vtkXMLPolyDataWriter VTP is a "PolyData". This format allows for the most complex geometric objects to be stored.
Write a TIFF (.tif) file vtkTIFFWriter
Write a BMP (.bmp) file vtkBMPWriter
Write stereo lithography STL (.stl) files vtkSTLWriter
Write PLY (.ply) files vtkPLYWriter
Write PNM (.pnm) files vtkPNMWriter
Write an ExodusII file vtkExodusIIWriter Write a time varying file
Write a Quadratic Surface to a VTP file vtkQuadric
Write data to a delimited file vtkDelimitedTextWriter

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.

Example Name VTK Classes Demonstrated Description
Colored Lines vtkCellData vtkLine
Cube vtkCubeSource
Disk vtkDiskSource A circle with a hole in it.
Frustum vtkFrustumSource
Line vtkLine
Hexahedron vtkHexahedron
Plane vtkPlaneSource
PlatonicSolid vtkPlatonicSolidSource
Point vtkPoints
Polygon vtkPolygon
Quad vtkQuad
Sphere vtkSphereSource
Triangle (self contained) vtkTriangle
Triangle (on large point array) vtkTriangle

Display on screen

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

Example Name VTK Classes Demonstrated Description
Display Arrow vtkArrowSource
Display 3D axes vtkAxesActor
Display Colored Lines vtkLineSource
Display Cone vtkConeSource
Display Cube vtkCubeSource
Display Cylinder vtkCylinderSource
Display long line vtkLineSource
Display Frustum vtkFrustumSource
Display Line, set line width vtkLineSource
Display Oriented Arrow vtkArrowSource
Display Plane vtkPlaneSource
Display Point vtkPointSource
Display a PolyLine vtkPolyLine
Display Pyramid vtkPyramid
Display Regular Polygon vtkRegularPolygonSource
Display Sphere vtkSphereSource
Display Triangle vtkTriangle
Display Polygon vtkPolygon
Display Quad vtkQuad

Implicit Functions

Example Name VTK Classes Demonstrated Description
Sample and visualize an implicit function vtkSampleFunction

Working with 3D Data

Example Name VTK Classes Demonstrated Description
Find the shortest path between two points on a mesh vtkPolygonalSurfaceContourLineInterpolator
Create a surface between lines vtkRuledSurfaceFilter
Select a region of a mesh vtkSelectPolyData
Remove coincident points vtkCleanPolyData
Determine which cells share a single point with a specific cell vtkPolyData::GetCellNeighbors
Determine which cells share an edge with a specific cell vtkPolyData::GetCellNeighbors
Iso lines on the surface of a polydata vtkBandedPolyDataContourFilter
Laplacian smoothing vtkSmoothPolyDataFilter
Check if a surface is closed vtkFeatureEdges
KMeans Clustering vtkKMeansStatistics
Move vertices along normals vtkWarpScalar
Get a list of vertices attached (through an edge) to a vertex vtkPolyData::GetCellPoints Vertex connectivity
DeletePoint vtkPoints, vtkPolyData
Compute Gaussian, Mean, Min, and Max Curvatures vtkCurvatures
ThinPlateSplineTransform vtkThinPlateSplineTransform
Generate point and cell id arrays vtkIdFilter
Mirror a DataSet vtkReflectionFilter
Apply a perspective transformation to a point vtkPerspectiveTransform
Compute points at the center of every cell vtkCellCenters
Combine the points of multiple PolyData datasets vtkAppendPoints
Extract selection points vtkExtractSelection
Extract selection cells vtkExtractSelection
Extract points but bring cells that are still complete with them vtkExtractSelection, vtkSelection, vtkSelectionNode
Merge selections vtkSelection
Snap (quantize) points to a grid vtkQuantizePolyDataPoints
Flip normals vtkReverseSense
Convex hull of points projected onto the coordinate planes vtkPointsProjectedHull
Create an SCurve spline on a set of points vtkSCurveSpline
Create an Kochanek spline on a set of points vtkKochanekSpline
Create a Cardinal spline on a set of points vtkCardinalSpline, vtkParametricSpline, vtkParametricFunctionSource
Select visible points vtkSelectVisiblePoints
Convert triangles to triangle strips vtkStripper
Convert vtkUnstructuredGrid to vtkPolyData vtkDataSetSurfaceFilter
Convert vtkUnstructuredGrid to vtkPolyData (another way) vtkGeometryFilter
Compute the distance from an object to every point on a uniform grid vtkImplicitModeller
Find all points within a radius of a specified point vtkPointLocator
Transform a data set vtkTransformFilter
Interpolate terrain vtkProbeFilter
Sample a PolyData vtkPolyDataPointSampler Sample the edges or surfaces of a polydata.
Visualization of the tree of a vtkCellLocator vtkCellLocator
Visualization of the tree of a vtkPointLocator vtkPointLocator
Efficient 3D point query vtkPointLocator
Efficient 3D cell query vtkCellLocator
Select a subset (mask) of a point set vtkMaskPoints
Generate a random point cloud vtkPointSource
Linear Extrusion vtkLinearExtrusionFilter
Rotation around a line vtkTransform, vtkTransformPolyDataFilter
Extract the largest connected region in a polydata vtkPolyDataConnectivityFilter
Extract a specific (specified) connected region in a polydata vtkPolyDataConnectivityFilter
Extract the outer surface of a multiple surface polydata vtkPolyDataConnectivityFilter
vtkVoxelContoursToSurfaceFilter vtkVoxelContoursToSurfaceFilter
vtkTubeFilter vtkTubeFilter Give lines a thickness (produce a cylinder around lines.
vtkRibbonFilter vtkRibbonFilter
Convex hull using shrink wrapping vtkSmoothPolyDataFilter
Convex hull using vtkDelaunay3D vtkDelaunay3D
Convex hull using vtkDelaunay3D and real data vtkDelaunay3D
Convex hull using vtkHull vtkHull
Check if a point is inside an object vtkSelectEnclosedPoints
Check if a point is inside an object (alternate method) vtkDelaunay3D, vtkPolyData::FindCell This uses a Delaunay triangulation to compute a volume. This gives more of an "is inside convex hull" effect than an "is inside object".
Data Bounds vtkPolyData::GetBounds Get the minimum and maximum value in each dimension.
Demonstrate how the order of applying transforms affects the result vtkTransformPolyDataFilter
Outline vtkOutlineFilter Draw the bounding box of the data
Triangle Area vtkTriangle::TriangleArea Compute the area of all triangles in a polydata.
Silhouette vtkPolyDataSilhouette
Mesh Quality vtkMeshQuality
Highlight Bad Cells vtkMeshQuality
Thresholding Points vtkThresholdPoints
Thresholding Cells vtkThreshold
Align point sets vtkProcrustesAlignmentFilter
Compute the gradient of a scalar field on a data set vtkGradientFilter
Generate a binarized volume from a closed surface vtkPolyDataToImageStencil
Generate a binarized image from a closed contour vtkLinearExtrusionFilter,vtkPolyDataToImageStencil
Extract polylines from polydata vtkPolyData
Fit a spline to cutter output vtkKochanekSpline, vtkSplineFilter, vtkSpline
Remove duplicate (merge) points vtkMergePoints
Decimate polyline vtkDecimatePolylineFilter

Adding Colors to Polydata

Example Name VTK Classes Demonstrated Description
Colored Points vtkUnsignedCharArray Add three points to a polydata and associate a color with each of them.
Triangle - Colored Points vtkUnsignedCharArray Set the color of each point of a triangle. You will be able to interpolate the colors across the triangle.
Triangle - Solid Color vtkUnsignedCharArray Create a solid colored triangle.
Color Cells vtkLookupTable Color individual cells of a polydata

Adding Normals to Polydata

Example Name VTK Classes Demonstrated Description
Add/Get Normals to/from cells in a Polydata vtkCellData
Add/Get Normals to/from points in a Polydata vtkPointData
Add a line to a PolyData vtkLine, vtkPolyData

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

Example Name VTK Classes Demonstrated Description
Add Miscellaneous Data to Points in a Polydata vtkPointData, vtkFloatArray
Get Miscellaneous Data from Points in a Polydata vtkDoubleArray
Add Miscellaneous Data to Cells in a Polydata vtkCellData
Get Miscellaneous Data from Cells in a Polydata vtkCellData

Point cloud operations

Example Name VTK Classes Demonstrated Description
Downsample a point cloud vtkCleanPolyData Remove points so that there are no points within a tolerance of any point.

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.

Example Name VTK Classes Demonstrated Description
Add Global Miscellaneous Data (FieldData) to a Polydata vtkFieldData

Global Operations on PolyData

Example Name VTK Classes Demonstrated Description
Extract Normals from a Polydata vtkPolyDataNormals
Get the names of all of the data arrays vtkPolyData
Determine data types of arrays vtkPolyData
Embed points into a volume vtkGaussianSplatter
Copy all arrays from one vtkPolyData to another vtkPolyData

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.


Example Name VTK Classes Demonstrated Description
Iterating over a vtkImageData vtkImageData Set and access locations in a 3D image.
Normalize an image vtkImageNormalize
Extract a volume of interest (subvolume) vtkExtractVOI
Add two or more images vtkImageWeightedSum
Convert a vtkImageData to a vtkPolyData vtkImageDataGeometryFilter


Example Name VTK Classes Demonstrated Description
Structured Grid vtkStructuredGrid
Visualize the points of a structured grid vtkStructuredGridGeometryFilter
Visualize the outline of a structured grid vtkStructuredGridOutlineFilter
Visualize the cells of a structured grid vtkShrinkFilter


Example Name VTK Classes Demonstrated Description
Convert a vtkStructuredPoints to a vtkUnstructuredGrid vtkStructuredPoints, vtkUnstructuredGrid


Example Name VTK Classes Demonstrated Description
Rectilinear grid vtkRectilinearGrid
Visualize the cells of a rectilinear grid vtkRectilinearGrid, vtkShrinkFilter
Convert a vtkRectilinearGrid to a vtkUnstructuredGrid mesh vtkRectilinearGridToTetrahedra


Example Name VTK Classes Demonstrated Description
Produce a random vector at each point in a dataset vtkBrownianPoints
Mathematical vector class vtkVector
Compute Principle Component Analysis (PCA) values vtkPCAStatistics
Pass input along to output vtkPassThrough
Convert a vtkDenseArray to a vtkTable vtkArrayToTable
Filter progress report vtkCommand::ProgressEvent Get the progress of a filter.
Cardinal spline Interpolation vtkCardinalSpline
Shepard method interpolation vtkShepardMethod
Timer log vtkTimerLog
Time stamp vtkTimeStamp
File Output Window vtkFileOutputWindow
Subclass vtkCommand vtkCommand Instead of using a callback function, it is more powerful to subclass vtkCommand.
Interpolation using a piecewise function vtkPiecewiseFunction
Convert between data types vtkVariant
Coordinate system conversions vtkCoordinate
Check VTK Version vtkVersion vtkVersion and some #define's
Color Lookup Table vtkLookupTable
Color Transfer Function vtkColorTransferFunction
Discretizable Color Transfer Function vtkDiscretizableColorTransferFunction
Construct a Table vtkTable A table is a 2D array of any type of elements. They do not all have to be the same type. This is achieved using vtkVariant.
Delaunay Triangulation (2D) vtkDelaunay2D Perform a 2D Delaunay triangulation on a point set.
Constrained Delaunay Triangulation (2D) vtkDelaunay2D Perform a 2D Delaunay triangulation on a point set respecting a specified boundary.
Known Length Array vtkFloatArray
Unknown Length Array vtkFloatArray
Array of Vectors (Known Length) vtkFloatArray
Array of Vectors (Unknown Length) vtkFloatArray
Get the bounds of a vtkDenseArray vtkDenseArray, vtkArrayRange
Get the bounds (min,max) of a vtk array vtkFloatArray::GetRange
2D Array vtkDenseArray
3D Array vtkDenseArray
Custom type 2D Array vtkDenseArray
Determine the type of a VTK variable GetClassName()
Determine the type of an actor vtkActor, vtkActorCollection
Screenshot vtkWindowToImageFilter
Directory File Extensions vtkDirectory, vtksys/SystemTools
FilenameFunctions vtkDirectory, vtksys/SystemTools Do things like get the file extension, strip the file extension, etc.
Timer vtkRenderWindowInteractor::CreateRepeatingTimer
Animation vtkRenderWindowInteractor::CreateRepeatingTimer Move a sphere across a scene.
Data Animation vtkCallbackCommand, vtkProgrammableFilter Update points in a dataset every specified interval.
Data Animation (subclass) vtkCommand, vtkProgrammableFilter Update points in a dataset every specified interval (using a vtkCommand subclass instead of a callback function.
Off Screen Rendering vtkImagingFactory, vtkGraphicsFactory
String function parser vtkFunctionParser
Catch the window modified event vtkRenderWindow

Math Operations

Example Name VTK Classes Demonstrated Description
Least Squares vtkMath::SolveLeastSquares
Homogeneous Least Squares vtkMath::SolveHomogeneousLeastSquares
Compute eigenvalues and eigenvectors of a symmetric matrix vtkMath::Jacobi
Matrix transpose vtkMatrix3x3
Matrix inverse vtkMatrix3x3
Get a vector perpendicular to another vector vtkMath::Perpendiculars
Get the lengths of an array of vectors vtkVectorNorm


Example Name VTK Classes Demonstrated Description
Get all vertices connected to a specified vertex vtkAdjacentVertexIterator
Extract a subgraph vtkExtractSelectedGraph
Edge weights vtkGraph::GetEdgeData::AddArray
Iterate over edges vtkEdgeListIterator, vtkInEdgeIterator
Breadth first search tree vtkBoostBreadthFirstSearchTree
Distance from origin vtkBoostBreadthFirstSearch
Color vertices vtkGraphLayoutView
Construct a graph vtkMutableUndirectedGraph
Construct a tree vtkTree, vtkMutableDirectedGraph
Minimum spanning tree of a graph vtkBoostPrimMinimumSpanningTree
Depth First Search iterator vtkTreeDFSIterator
Breadth First Search iterator vtkTreeBFSIterator
Visualize a graph vtkGraphLayoutView, vtkGraphLayoutStrategy, vtkSimple2DLayoutStrategy
Label vertices and edges vtkGraphLayoutView::SetEdgeLabelArrayName, vtkGraphLayoutView::SetVertexLabelArrayName
Find Connected Components vtkBoostConnectedComponents
Convert a graph to a PolyData vtkGraphToPolyData
Visualize Directed Graph vtkGlyphSource2D
Create a random graph vtkRandomGraphSource
Depth First Search Animation vtkTreeDFSIterator
Remove vertices of degree 0 from a vtkGraph vtkRemoveIsolatedVertices

Graph Conversions

Example Name VTK Classes Demonstrated Description
vtkMutableDirectedGraph to vtkDirectedGraph vtkMutableDirectedGraph, vtkDirectedGraph
vtkDirectedGraph to vtkMutableDirectedGraph vtkMutableDirectedGraph, vtkDirectedGraph
vtkTree to vtkMutableDirectedGraph vtkMutableDirectedGraph, vtkTree

Graph Conversions That Don't Work

Example Name VTK Classes Demonstrated Description
vtkMutableDirectedGraph to vtkMutableUndirectedGraph vtkMutableDirectedGraph, vtkMutableUndirectedGraph
vtkMutableUndirectedGraph to vtkMutableDirectedGraph vtkMutableDirectedGraph, vtkMutableUndirectedGraph
vtkTree to vtkMutableUndirectedGraph vtkTree, vtkMutableUndirectedGraph

Data Structures


Example Name VTK Classes Demonstrated Description
vtkKdTree_BuildLocatorFromPoints vtkKdTree
vtkKdTree_BuildLocatorFromPoints_ClosestKPoints vtkKdTree
Access the points of a KDTree vtkKdTree
Find the closest point to a query point vtkKDTreePointLocator
Find the closest N points to a query point vtkKDTreePointLocator
Generate a mesh of each level of a KDTree vtkKDTreePointLocator
Find points within a specified radius of a query point vtkKdTreePointLocator

Oriented Bounding Box Tree

Example Name VTK Classes Demonstrated Description
OBBTree vtkOBBTree Oriented Bounding Box Tree
Generate a mesh of each level of an OBBTree vtkOBBTree


Example Name VTK Classes Demonstrated Description
Create an octree vtkOctreePointLocator
Find the closest point to a query point vtkOctreePointLocator
Find the K closest points to a query point vtkOctreePointLocator
Find the points within a sphere of specified radius to a query point vtkOctreePointLocator
Generate a mesh of each level of an octree vtkOctreePointLocator

Modified BSP Tree

Example Name VTK Classes Demonstrated Description
Create a modified BSP Tree vtkModifiedBSPTree
Generate a mesh of each level of an modified BSP tree vtkModifiedBSPTree


Example Name VTK Classes Demonstrated Description
Append different types of data vtkAppendFilter
Perlin Noise vtkPerlinNoise
Create a circle vtkCutter Create a circle by cutting through a sphere.
Combine/Append PolyData vtkAppendPolydata
Create a surface from Unorganized Points (Gaussian Splat) vtkGaussianSplatter
Iterative Closest Points (ICP) Transform vtkIterativeClosestPointTransform Input data.
Iterative Closest Points (ICP) Transform vtkIterativeClosestPointTransform Generated data.
Landmark Transform vtkLandmarkTransform
Create a custom filter without subclassing vtkProgrammableFilter
Create a surface from Unorganized Points (with post processing) vtkSurfaceReconstructionFilter
Create a surface from Unorganized Points vtkSurfaceReconstructionFilter
Apply a Transformation to a PolyData vtkTransformPolyDataFilter
Triangulate a Terrain Map vtkDelaunay2D
vtkGlyph2D vtkGlyph2D
vtkGlyph3D vtkGlyph3D
Add a vertex to each point vtkVertexGlyphFilter
Create cubes from labeled volume data vtkMetaImageReader, vtkMaskFields
Create models from labeled volume data (Discrete MarchingCubes) vtkDiscreteMarchingCubes
Create a solid mesh from Unorganized Points (Delaunay3D with Alpha) vtkDelaunay3D
Create a solid mesh from Unorganized Points (Delaunay3D) vtkDelaunay3D
Extract largest isosurface vtkPolyDataConnectivityFilter
BandedPolyDataContourFilter vtkBandedPolyDataContourFilter
Create filled contours (vtkClipPolyData) vtkContourFilter
Create tubes with varying radius and colors vtkTubeFilter


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

Example Name VTK Classes Demonstrated Description
Order cells from a viewing direction vtkKdTree
Backface culling vtkActor::GetProperty::BackfaceCullingOn
Background color vtkRenderer::SetBackground
Background gradient vtkRenderer::GradientBackgroundOn, vtkRenderer::Setbackground2
CameraActor vtkCameraActor Visualize a camera (frustum) in a scene.
Generate 3D clip art from an image vtkTextureMapToPlane
Close a render window vtkRenderWindowInteractor::TerminateApp, vtkRenderWindow::Finalize
Color an Actor vtkActor::GetProperty::SetColor
Color the edges of an Actor vtkActor::GetProperty::SetEdgeColor
Color glyphs vtkGlyph3D vtkGlyph3D::SetColorModeToColorByScalar
Corner annotation vtkCornerAnnotation Write text in the corners of a window.
Correctly Rendering Translucent Geometry vtkDepthSortPolyData
Display three orthogonal axes with labels vtkCubeAxesActor
vtkCursor3D vtkCursor3D
Display coordinate axes vtkOrientationMarkerWidget
Display Text vtkTextActor, vtkTextProperty
A little bit easier rendering vtkRenderView
FlatShading vtkActor::GetProperty::SetInterpolationToFlat
Draw text that stays right side up vtkFollower
Hide an actor vtkPropCollection, vtkProp::VisibilityOff
Hide all actors vtkRenderer::RemoveAllViewProps
Level of detail rendering vtkLODProp3D
Label Contours vtkLabeledDataMapper
Display the point ID at each point vtkLabeledDataMapper
Legend vtkLegendBoxActor
Display the scale of a scene vtkLegendScaleActor
Movable axes vtkFollower, vtkAxesActor, vtkAssembly
Moving an Actor vtkInteractorStyleTrackballActor
Moving the Camera vtkInteractorStyleTrackballCamera
Multiple Actors vtkActor
NoShading vtkActor::GetProperty::SetAmbient, vtkActor::GetProperty::SetDiffuse, vtkActor::GetProperty::SetSpecular
Opacity vtkActor::GetProperty::SetOpacity
PointSize vtkActor::GetProperty::SetPointSize
Poly Data Depth Sorting vtkDepthSortPolyData
Automatic level of detail adjustment vtkQuadricLODActor Level of detail adjustment.
Render a large image, larger than a window vtkRenderLargeImage
Rotate an Actor vtkActor::GetMatrix
ScalarBarActor vtkScalarBarActor Display a color bar.
Scale glyphs vtkGlyph3D vtkGlyph3D::SetScaleModeToScaleByScalar
Select a region of a window vtkInteractorStyleRubberBand2D
Stream Lines vtkStreamLine
Display text vtkTextSource
Texture map an ImageData vtkImageCanvasSource2D
Texture map a plane vtkTextureMapToPlane
Texture map a quad vtkPolygon, vtkPolyData::GetPointData::SetTCoords
Transform an Actor vtkActor::SetUserTransform
Multiple Actors in a Vector vtkActor
Display high resolution text vtkVectorText
Visualize a 2D Set of Points vtkPolyDataMapper2D, vtkProperty2D
Visualize the points of an ImageData vtkDataSetMapper
Visualize a VTP File vtkXMLPolyDataReader, vtkPolyDataMapper
Change the size of a window vtkRenderWindow:SetSize
Change the title of a window vtkRenderWindow::SetWindowName
Wireframe vtkActor::GetProperty::SetRepresentationToWireframe
Positioning and aiming the camera vtkCamera
Display Quadratic Surfaces vtkQuadric, vtkSampleFunction, vtkContourFilter
Glyph3DMapper vtkGlyph3DMapper

Volume Rendering

Example Name VTK Classes Demonstrated Description
HAVS vtkHAVSVolumeMapper
Smart volume mapper vtkSmartVolumeMapper
Min intensity rendering vtkFixedPointVolumeRayCastMapper

User Interaction

Example Name VTK Classes Demonstrated Description
Assembly vtkAssembly Combine actors into an assembly.
Get world coordinates of mouse click vtkCoordinate
Catch a double click vtkInteractorStyleTrackballCamera
vtkImageClip vtkImageClip Demonstrates how to interactively select and display a region of an image.
Select a region of an image vtkCommand
Terrain mode vtkInteractorStyleTerrain
Handle keypress events vtkInteractorStyleTrackballCamera
Handle keypress events (lightweight) vtkCallbackCommand This uses a callback function rather than a derived interactor class.
Handle mouse events vtkInteractorStyleTrackballCamera Subclass the interactor style.
Handle mouse events (light weight) vtkCallbackCommand Use an observer.
Get the coordinates of the closest point in the data set to the mouse click vtkPointPicker
RubberBand2D Observer vtkInteractorStyleRubberBand2D
RubberBand2D vtkInteractorStyleRubberBand2D
RubberBand3D vtkInteractorStyleRubberBand3D
RubberBandPick vtkInteractorStyleRubberBandPick
RubberBandZoom vtkInteractorStyleRubberBandZoom
Select an actor vtkPropPicker
Check if shift or control is being held vtkRenderWindowInteractor::GetControlKey()
Choose between multiple interaction modes vtkInteractorStyleSwitch
Trackball actor mode vtkInteractorStyleTrackballActor
Trackball camera mode vtkInteractorStyleTrackballCamera
Get world coordinates of mouse click vtkWorldPointPicker

Selecting in 3D (Picking)

Example Name VTK Classes Demonstrated Description
Cell Picking vtkCellPicker
Area Picking vtkAreaPicker
Highlight Selected Points vtkExtractGeometry

Working with Images

Example Name VTK Classes Demonstrated Description
Display an image as the background of a scene vvtkImageCanvasSource2D
Blending 2D images with different color maps vtkImageMapToColors
Center an image vtkImageChangeInformation
Combine two images vtkImageBlend
Combine layers into an RGB image vtkImageAppendComponents
Convert RGB image to greyscale vtkImageMagnitude
Display a static image vvtkImageViewer2 This will display the image, but not allow you to interact with it.
Image dot product vtkImageDotProduct Compute the pixel-wise dot product of two vector images.
Drawing on an image vtkImageCanvasSource2D
Drawing shapes in an image vtkImageCanvasSource2D
Compute the difference image of two images vtkImageDifference
Convert RGB image to greyscale (luminance) vtkImageLuminance
Mask a region of an image vtkImageMask
Perform mathematical operations on an image vtkImageMathematics
vtkImageMirrorPad vtkImageMirrorPad Pad the edges of an extended image by mirror existing pixels.
Draw text in an image vtkVectorText
Visualize and interact with an image vtkImageActor, vtkInteractorStyleImage
Negative Indices vtkImageData A very powerful feature of vtkImageData is that you can use negative indices.
Picking a pixel 2 - modified version for exact pixel values vtkPropPicker
Picking a pixel vtkPropPicker
Visually Compare Two Images vtkImageCheckerboard Visually compare two images.

Image Processing

Example Name VTK Classes Demonstrated Description
Read/Write JPG vtkJPEGReader, vtkJPEGWriter
Read/Write PNG vtkPNGReader, vtkPNGWriter
Cast an image to a different type vtkImageCast
Extract components of an image vtkImageExtractComponents This can be used to get, for example, the red channel of an image.
Flip an image vtkImageFlip
Image gradient vtkImageGradient Compute the gradient vector at every pixel.
Display a histogram vtkImageAccumulate, vtkBarChartActor
Display a histogram vtkImageAccumulate, XYPlotActor
Dilate an image vtkImageContinuousDilate3D
Erode an image vtkImageContinuousErode3D
Convolve an image with a kernel vtkImageConvolve
Correlate two images vtkImageCorrelation
Divergence of a vector field vtkImageDivergence
Create an image of an ellipsoid vtkImageEllipsoidSource
Compute the FFT of an image vtkImageFFT
Smooth an image vtkImageGaussianSmooth
Compute the magnitude of the gradient at each pixel of an image vtkImageGradientMagnitude
High pass filter an image vtkImageIdealHighPass
Low pass filter an image vtkImageIdealLowPass
Remove small patches from an image vtkImageIslandRemoval2D
Compute the Laplacian of an image vtkImageLaplacian
Median filter a 3d or 2d image vtkImageMedian3D
Create an image of noise vtkImageNoiseSource
Switch axes of an image vtkImagePermute
Shift and scale an image vtkImageShiftScale
Resample an image vtkImageShrink3D
Sobel edge detection 2D vtkImageSobel2D
Sobel edge detection 3D vtkImageSobel3D
Threshold an image vtkImageThreshold
Variance of a 3D image vtkImageVariance3D Construct a new image consisting of the variance of the input image at each pixel.
Convert RGB to HSV vtkImageRGBToHSV

Working with Meshes

Example Name VTK Classes Demonstrated Description
Matrix math filter vtkMatrixMathFilter Compute various quantities on cell and points in a mesh.
Decimation vtkDecimatePro Reduce the number of triangles in a mesh.
Subdivision vtkButterflySubdivisionFilter, vtkLoopSubdivisionFilter, vtkLinearSubdivisionFilter Increase the number of triangles in a mesh.
Finding Boundary Edges vtkFeatureEdges Find the edges that are used by only one face.
Fill Holes vtkFillHolesFilter Close holes in a mesh.
Windowed Sinc PolyData Filter|Smooth a mesh (windowed sinc filter) vtkWindowedSincPolyDataFilter Smooth a mesh.
Color a mesh by height vtkLookupTable
Color a mesh by height vtkElevationFilter
Triangulate a mesh vtkTriangleFilter Convert all polygons in a mesh to triangles.
Extract Edges vtkExtractEdges
Get edges of cells vtkCell
Create a "solid" clip vtkClipPolyData
Cap a clipped polydata with a polygon vtkClipPolyData


Example Name VTK Classes Demonstrated Description
Apply an affine transformation interactively vtkAffineWidget
vtkPolygonalSurfacePointPlacer vtkPolygonalSurfacePointPlacer Used in conjuntion with vtkContourWidget to draw curves on a surface.
Sphere widget events vtkSphereWidget
Draw movable text vtkTextWidget
Seed widget vtkSeedWidget
Sphere widget vtkSphereWidget
vtkSphereWidget2 vtkSphereWidget2
vtkSplineWidget vtkSplineWidget
vtkBorderWidget vtkBorderWidget 2D selection, 2D box.
vtkContourWidget vtkContourWidget
vtkAngleWidget vtkAngleWidget
vtkAngleWidget + vtkAngleRepresentation2D vtkAngleWidget, vtkAngleRepresentation2D
vtkCaptionWidget vtkCaptionWidget
3D Slider vtkSliderWidget, vtkSliderRepresentation3D
2D Slider vtkSliderWidget, vtkSliderRepresentation2D
Balloon vtkBalloonWidget
Contour Widget vtkContourWidget Create a contour from a set of points and dynamically change the contour using the points as control points.
vtkDistanceWidget vtkDistanceWidget
vtkImplicitPlaneWidget2 vtkImplicitPlaneWidget2 Clip polydata with an implicit plane.
vtkBoxWidget vtkBoxWidget
vtkBoxWidget2 vtkBoxWidget2
vtkLineWidget2 vtkLineWidget2
vtkBiDimensionalWidget vtkBiDimensionalWidget When would you use this?
vtkImagePlaneWidget vtkImagePlaneWidget
vtkImageTracerWidget vtkImageTracerWidget Scribble on an image.
Draw on a non-planar surface vtkImageTracerWidget
vtkHoverWidget vtkHoverWidget How to detect a hover?
Logo widget vtkLogoWidget
Orientation Marker widget vtkOrientationMarkerWidget Display a polydata as an orientation icon.
Rectilinear Wipe widget vtkImageRectilinearWipe, vtkRectilinearWipeWidget, vtkRectilinearWipeRepresentation Compare two images.
Checkerboard widget vtkCheckerboardWidget, vtkCheckerboardRepresentation Compare two images using a checkerboard.
vtkCursor2D vtkCursor2D


Example Name VTK Classes Demonstrated Description
vtkCutter vtkCutter
Multiple Viewports vtkRenderer::SetViewPort
Side by side viewports vtkRenderer::SetViewPort
MultipleRenderWindows vtkRenderWindow
Casting VTK objects vtkObject::SafeDownCast


Example Name VTK Classes Demonstrated Description
Line plot vtkChartXY
Scatter plot vtkPlotPoints
Bar chart vtkChartXY
Pie chart vtkChartPie, vtkPlotPie
Stacked plot vtkPlotStacked
Parallel coordinates vtkChartParallelCoordinates
Plot data (Legacy method) vtkXYPlotActor


Geographic Visualization (Geovis)

Example Name VTK Classes Demonstrated Description
Compass Widget
Earth source Create the Earth.

Information Visualization (Infovis)

Example Name VTK Classes Demonstrated Description
Parallel coordinates vtkParallelCoordinatesView



Click here for a tutorial on how to setup Qt.

Example Name VTK Classes Demonstrated Description
Render window QVTKWidget This is a very basic example that shows how to create a Qt window. Typically, one would want to design a form in the QtDesigner (this is shown in RenderWindowUi)
Render window UI QMainWindow
Side by side render windows QApplication
vtkQtBarChart vtkQtBarChart
Border Widget vtkBorderWidget, QApplication


You must turn on VTK_USE_MATLAB_MEX to use these.

Example Name VTK Classes Demonstrated Description
vtkMatlabEngineFilter vtkMatlabEngineFilter



Example Name VTK Classes Demonstrated Description
Connect to and read a MySQL database vtkMySQLDatabase, vtkSQLQuery
Create a MySQL database vtkMySQLDatabase

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!

Testing Needed

Example Name VTK Classes Demonstrated Description
AVI (Windows only) vtkAVIWriter Someone please test this.
OggTheora vtkOggTheoraWriter Can't find lvtkoggtheora
MPEG2 vtkMPEG2Writer CMake won't find MPEG2 include?
FFMPEG vtkFFMPEGWriter CMake won't find FFMPEG include?

Small Problems

Example Name VTK Classes Demonstrated Description
vtkImageIterator vtkImageIterator
Extract points based on a criterion function vtkExtractSelectedThresholds
Clip using an implicit data set vtkImplicitDataSet
RTAnalyticSource vtkRTAnalyticSource Output seems to be the wrong type?
vtkVectorDot vtkVectorDot All return values are -1?
2D actor and mapper vtkActor2D vtkMapper2D Nothing is displayed?
Get connected cells vtkCellLinks How to use vtkCellLinks::Links class? How to know how many cells GetCells returns?
Convert data from an object into a vtkTable vtkDataObjectToTable How to get the point coordinates into the table?
SeedWidgetImage vtkImageViewer2, vtkSeedWidget How to start the interaction?
vtkImageViewer2 vtkImageViewer2 How to start the interaction?
Convert a polydata to an implicit function vtkImplicitDataSet The error is: "Can't evaluate dataset!"
vtkGenericClip vtkGenericClip The input is vtkPolyData, but a vtkGenericDataSet is required.
Display non-overlapping labels vtkLabelPlacementMapper, vtkLabelHierarchy, vtkPointSetToLabelHierarchy no labels are displayed?
Perform in-place operations on arrays vtkArrayCalculator Currently MyArray does not change.
Marching cubes vtkMarchingCubes The output is empty?
vtkCameraWidget vtkCameraWidget How to use this?
vtkFrustumCoverageCuller vtkFrustumCoverageCuller When would you use this?
Compute occupancy of an object on a grid vtkVoxelModeller VTK_BIT is not supported - convert it?
vtkImageToStructuredPoints vtkImageToStructuredPoints Doesn't seem to produce a vtkStructuredPoints?
Divide a point cloud into uniform cubic voxels vtkCellLocator We can determine which cell a point is in, but how to determine which points are in a particular cell?
Flight vtkInteractorStyleFlight linux keypresses not handled. I submitted a patch to the devel list - we'll see if they respond.
vtkPointHandleRepresentation2D vtkPointHandleRepresentation2D
RecordEvents vtkInteractorEventRecorder How to exit?
PlayBackEvents vtkInteractorEventRecorder How to slow down?
vtkDistanceToCamera vtkDistanceToCamera How to trigger the DistanceToCamera computation?
Quadric Surface Fitting vtkQuadric
LU Factorization vtkMath::LUFactorLinearSystem how do you get the resulting L and U?
Rectangular button source vtkRectangularButtonSource is this the intended usage?
ApplyColors vtkApplyColors How is this different from just adding a Colors array to a vtkDataSet?
vtkSelectionSource vtkSelectionSource The output currently has 50 points when it should only have 10.
vtkPCAAnalysisFilter vtkPCAAnalysisFilter What is the difference between this and vtkPCAStatistics? The eigenvalues vector doesn't seem to be valid. It seems like the eigenvector corresponding to the smallest value is stored as the normal of the cell in the output - how do you get the other two eigen vectors?

Big Problems

Example Name VTK Classes Demonstrated Description
vtkTensorProbeWidget vtkTensorProbeWidget How is this used?
vtkTensorGlyph vtkTensorGlyph
SpherePuzzle vtkSpherePuzzle
GeoGlobeSource vtkGeoGlobeSource
GeoView vtkGeoView


Example Name VTK Classes Demonstrated Description
An implicit representation of a sphere vtkSphere
vtkFrustumCoverageCuller vtkFrustumCoverageCuller Doesn't seem to have a property to specify a frustum? What is it for? How to use it?
vtkKdTreeSelector vtkKdTreeSelector What is this used for?
vtkRungeKutta4 vtkRungeKutta4
vtkCoincidentPoints vtkCoincidentPoints What is this for?
Get the frame rate of the rendering
Threaded/Parallel example
Assign an array to a particular field vtkAssignAttribute
vtkTransposeMatrix vtkTransposeMatrix What is this supposed to operate on? There is no vtkMatrix class.
vtkHyperOctree vtkHyperOctree What does this do?
vtkWarpVector vtkWarpVector What is this?
vtkTextExtraction vtkTextExtraction
vtkQtChartView vtkQtChartView
vtkQtChartWidget vtkQtChartWidget
vtkQtTreeView vtkQtTreeView
vtkQtTableView vtkQtTableView
vtkQtListView vtkQtListView
vtkQtChartArea vtkQtChartArea

Developer Examples


Errors and Warnings

Filters and Sources

Standard classes

Example Name VTK Classes Demonstrated Description
PolyDataAlgorithm Reader vtkPolyDataAlgorithm Nothing in, PolyData out.
PolyDataAlgorithm Filter vtkPolyDataAlgorithm PolyData in, PolyData out.
vtkGraphAlgorithm Source vtkGraphAlgorithm Nothing in, Graph out.
vtkGraphAlgorithm Filter vtkGraphAlgorithm Graph in, Graph out.
vtkImageAlgorithm Filter vtkImageAlgorithm Image in, Image out.
vtkImageAlgorithm Source vtkImageAlgorithm Nothing in, Image out.

Custom classes

Example Name VTK Classes Demonstrated Description
vtkAlgorithm Source vtkAlgorithm Nothing in, custom class out.
vtkAlgorithm Filter vtkAlgorithm vtkDataObject Custom class in, custom class out.
vtkAlgorithm Filter Multiple Output Ports vtkAlgorithm Nothing in, 2 custom classes out.

Multiple Connections on a Single Port

Example Name VTK Classes Demonstrated Description
Multiple Connections Two PolyDatas in, 1 PolyData out.

Multiple Input Ports

Example Name VTK Classes Demonstrated Description
Multiple Input Ports - Two PolyDatas in, 1 PolyData out.

Needed/Missing Developer Examples