VTK/Examples
From KitwarePublic
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
- Distance between two points (C++ and Python)
- Random number (uniform distribution)
- Random number (Gaussian distribution)
- Random sequence - This is the preferred way to generate random numbers.
- Project a point onto a plane
Input and Output
Input
VTK Formats
- 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
External Formats
- Read a simple "xyz" file of points - vtkSimplePointsReader
- Read an "xyza" file - vtkParticleReader
- Read a plain text file into a polydata - 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
- Read a VRML (WRL) file
- Read DICOM file
- Report the contents of a VTK XML or legacy file
- 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.
Output
- 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
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.
- Point
- Line
- Disk - A circle with a hole in it.
- Colored Lines
- Plane
- Triangle (on large point array)
- Triangle (self contained)
- Sphere
- Cube
- Polygon
- Quad
- Frustum
Display on screen
In this section, the object is created and displayed on the screen.
- Pyramid - vtkPyramid
- Arrow - vtkArrowSource
- Regular Polygon - vtkRegularPolygonSource
- Display Cylinder - vtkCylinderSource
- Display Point - vtkPointSource
- Display Line - vtkLineSource
- Display a PolyLine - vtkPolyLine
- Display long line - vtkLineSource
- Display Colored Lines - vtkLineSource
- Display Plane - vtkPlaneSource
- Display Triangle
- Display Sphere - vtkSphereSource
- Display Cube - vtkCubeSource (C++ and Python)
- Display Polygon
- Display Quad
- Display Frustum - vtkFrustumSource
- Display 3D axes - vtkAxesActor
- Display Cone - vtkConeSource
Working with 3D Data
- DeletePoint
- Compute Gaussian, Mean, Min, and Max Curvatures - vtkCurvatures
- ThinPlateSplineTransform - vtkThinPlateSplineTransform
- Clip using an implicit data set - vtkImplicitDataSet
- Generate point and cell id arrays - vtkIdFilter
- Find the reflection of 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
- 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
- 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
- Rotation around a line
- vtkPolyDataConnectivityFilter
- vtkVoxelContoursToSurfaceFilter
- vtkTubeFilter - Give lines a thickness (produce a cylinder around lines).
- vtkRibbonFilter
- Convex hull using vtkDelaunay3D
- Convex hull using vtkHull
- Check if a point is inside an object - vtkSelectEnclosedPoints
- Check if a point is inside an object (alternate method) - 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 - Get the minimum and maximum value in each dimension.
- Create a Transform
- Outline - Draw the bounding box of the data (vtkOutlineFilter)
- Triangle Area - Compute the area of all triangles in a polydata.
- Silhouette - vtkPolyDataSilhouette
- Mesh Quality - vtkMeshQuality
- Highlight Bad Cells - vtkMeshQuality
- Thresholding Points - vtkThresholdPoints
- Thresholding Cells - vtkThreshold
Adding Colors to Polydata
- Colored Points - Add three points to a polydata and associate a color with each of them.
- Triangle - Colored Points - Set the color of each point of a triangle. You will be able to interpolate the colors across the triangle.
- Triangle - Solid Color - Create a solid colored triangle.
- Color Cells - Color individual cells of a 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.
- Add Miscellaneous Data to Points in a Polydata
- Get Miscellaneous Data from Points in a Polydata
- Add Miscellaneous Data to Cells in a Polydata
- Get Miscellaneous Data from Cells in a Polydata
Point cloud operations
- Downsample a point cloud - 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.
Global Operations on PolyData
- Extract Normals from a Polydata - vtkPolyDataNormals
- Get the names of all of the data arrays
- Determine data types of arrays
- Embed points into a volume
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.
vtkImageData
- Iterating over a vtkImageData - Set and access locations in a 3D image.
- vtkImageIterator
- Extract a volume of interest (subvolume) - vtkExtractVOI
vtkStructuredGrid
- Structured Grid - vtkStructuredGrid
- Visualize the points of a structured grid
- Visualize the outline of a structured grid
- Visualize the cells of a structured grid
vtkRectilinearGrid
- Rectilinear grid - vtkRectilinearGrid
- Visualize the cells of a rectilinear grid
Utilities
- Subclass 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 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
- Unknown Length Array
- Array of Vectors (Known Length)
- Array of Vectors (Unknown Length)
- 2D Array - vtkDenseArray
- Custom type 2D Array
- Determine the type of a VTK variable
- Determine the type of an actor
- Screenshot
- Directory File Extensions
- FilenameFunctions - Do things like get the file extension, strip the file extension, etc.
- Interpolation
- Timer
- Animation - Move a sphere across a scene
- Data Animation - Update points in a dataset every specified interval.
- Data Animation (subclass) - Update points in a dataset every specified interval (using a vtkCommand subclass instead of a callback function.
- Off Screen Rendering
- String function parser
Math Operations
- Least Squares
- Homogeneous Least Squares
- Compute eigenvalues and eigenvectors of a symmetric matrix
- Matrix transpose
- Matrix inverse
- Get a vector perpendicular to another vector
Graphs
- Construct a graph
- Minimum spanning tree of a graph
- Depth First Search iterator
- Visualize a graph
- Label vertices and edges
- Find Connected Components
- Convert a graph to a PolyData
- Visualize Directed Graph
- Create a random graph - vtkRandomGraphSource
Data Structures
- KDTree
- Create a KDTree
- KDTree - Closest Point
- KDTree - Closest Point (vtkKDTreePointLocator)
- KDTree - Closest N Points
- OBBTree - Oriented Bounding Box Tree
- Generate a mesh of each level of a KDTree
- Generate a mesh of each level of an OBBTree
Filters
- Create a custom filter without subclassing - vtkProgrammableFilter
- Append different types of data - vtkAppendFilter
- vtkGlyph3D
- vtkGlyph2D
- Add a vertex to each point - vtkVertexGlyphFilter
- Combine/Append PolyData - vtkAppendPolydata.
- Create a circle - Create a circle by cutting through a sphere.
- Apply a Transformation to a PolyData - vtkTransformPolyDataFilter
- Landmark Transform
- Iterative Closest Points (ICP) Transform - generated data
- Iterative Closest Points (ICP) Transform - input data
- Triangulate a Terrain Map
- Create a surface from Unorganized Points - vtkSurfaceReconstructionFilter
- Create a surface from Unorganized Points (with post processing)
- Create a surface from Unorganized Points (Gaussian Splat)
- Create a solid mesh from Unorganized Points (Delaunay3D)
- Create a solid mesh from Unorganized Points (Delaunay3D with Alpha)
- Extract largest isosurface
- Create models from labeled volume data (Discrete MarchingCubes)
- Create cubes from labeled volume data
- Create tubes with varying radius and colors (Tube Filter)
- Create filled contours (vtkClipPolyData) - vtkContourFilter
Visualization
See [this] for a brief explanation of the VTK terminology of mappers, actors, etc.
- Draw text that stays right side up - vtkFollower
- Opacity
- Display the scale of a scene - vtkLegendScaleActor
- Scale glyphs
- Wireframe
- Visualize the points of an ImageData
- Display three orthogonal axes with labels - vtkCubeAxesActor
- Display the point ID at each point - vtkLabeledDataMapper
- Backface culling
- Corner annotation - vtkCornerAnnotation - write text in the corners of a window.
- CameraActor - vtkCameraActor - visualize a camera (frustum) in a scene
- PointSize
- NoShading
- FlatShading
- Legend - vtkLegendBoxActor
- Movable axes
- Background color
- Color An Actor
- Rotate an Actor
- Transform an Actor
- Visualize a Sphere
- Visualize a VTP File
- Visualize a 2D Set of Points
- Display coordinate axes - vtkOrientationMarkerWidget
- Display Text
- Display text (vtkTextSource)
- Display high resolution text (vtkVectorText)
- Texture map a plane
- Texture map a quad
- Texture map an ImageData
- Moving an Actor
- Moving the Camera
- Multiple Actors
- Multiple Actors in a Vector
- A little bit easier rendering
- Hide an actor
- Hide all actors
- Change the title of a window
- Change the size of a window
- Poly Data Depth Sorting - vtkDepthSortPolyData
- Correctly Rendering Translucent Geometry
User Interaction
- Catch a double click
- Get the coordinates of the closest point in the data set to the mouse click - vtkPointPicker
- Get world coordinates of mouse click - vtkWorldPointPicker
- Get world coordinates of mouse click
- vtkImageClip - Demonstrates how to interactively select and display a region of an image.
- Assembly - vtkAssembly - Combine actors into an assembly.
- Handle keypress events
- Handle keypress events (lightweight) - This uses a callback function rather than a derived interactor class.
- Handle mouse events - Subclass the interactor style
- Handle mouse events (light weight) - Use an observer
- Trackball camera mode - vtkInteractorStyleTrackballCamera
- Trackball actor mode - vtkInteractorStyleTrackballActor
- Choose between multiple interaction modes - vtkInteractorStyleSwitch
- Check if shift or control is being held
- RubberBand2D - vtkInteractorStyleRubberBand2D
- RubberBand2D Observer - vtkInteractorStyleRubberBand2D
- RubberBandZoom - vtkInteractorStyleRubberBandZoom
- RubberBandPick - vtkInteractorStyleRubberBandPick
- Select a region of an image
Selecting in 3D (Picking)
- Cell Picking - vtkCellPicker
- Area Picking - vtkAreaPicker
- Highlight Selected Points - vtkExtractGeometry
Working with Images
- Convert RGB image to greyscale - vtkImageMagnitude
- Convert RGB image to greyscale (luminance) - vtkImageLuminance
- Display an image as the background of a scene
- Center an image - vtkImageChangeInformation
- Visualize and interact with an image - vtkImageActor, vtkInteractorStyleImage
- Display a static image - this will display the image, but not allow you to interact with it.
- Drawing on an image - vtkImageCanvasSource2D
- Drawing shapes in an image - vtkImageCanvasSource2D
- Combine two images - vtkImageBlend
- Draw text in an image
- Picking a pixel
- Negative Indices - A very powerful feature of vtkImageData is that you can use negative indices.
- Visually Compare Two Images - Visually compare two images using vtkImageCheckerboard.
- Blending 2D images with different color maps - vtkImageMapToColors
Image Processing
- Threshold an image - vtkImageThreshold
- Divergence of a vector field - vtkImageDivergence
- Create an image of an ellipsoid - vtkImageEllipsoidSource
- Compute the FFT of an image - vtkImageFFT
- Compute the magnitude of the gradient at each pixel of an image - vtkImageGradientMagnitude
- Image gradient - vtkImageGradient - compute the gradient vector at every pixel.
- Erode an image - vtkImageContinuousErode3D
- Dilate an image - vtkImageContinuousDilate3D
- Correlate two images - vtkImageCorrelation
- Convolve an image with a kernel - vtkImageConvolve
- Smooth an image - vtkImageGaussianSmooth
- Low pass filter an image - vtkImageIdealLowPass
- High pass filter an image - vtkImageIdealHighPass
- 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
- Variance of a 3D image - vtkImageVariance3D - construct a new image consisting of the variance of the input image at each pixel.
- Switch axes of an image - vtkImagePermute
- Sobel edge detection 3D - vtkImageSobel3D
- Sobel edge detection 2D - vtkImageSobel2D
- Resample an image - vtkImageShrink3D
- Shift and scale an image - vtkImageShiftScale
- Cast an image to a different type - vtkImageCast
- Convert RGB to HSV - vtkImageRGBToHSV
- Extract components of an image - vtkImageExtractComponents - This can be used to get, for example, the red channel of an image.
- Flip an image - vtkImageFlip
- Display a histogram using vtkImageAccumulate and XYPlotActor
- Display a histogram using vtkImageAccumulate and BarChartActor
- Read/Write JPG - vtkJPEGReader, vtkJPEGWriter
- Read/Write PNG - vtkPNGReader, vtkPNGWriter
Working with Meshes
- Decimation - Reduce the number of triangles in a mesh.
- Subdivision - Increase the number of triangles in a mesh.
- Finding Boundary Edges - vtkFeatureEdges - Find the edges that are used by only one face.
- Fill Holes - Close holes in a mesh.
- Windowed Sinc PolyData Filter|Smooth a mesh (windowed sinc filter) - Smooth a mesh.
- Color a mesh by height
- Color a mesh by height (using vtkElevationFilter)
- Triangulate a mesh - Convert all polygons in a mesh to triangles.
- Extract Edges - vtkExtractEdges
Widgets
- vtkPolygonalSurfacePointPlacer - Used in conjuntion with vtkContourWidget to draw curves on a surface.
- Sphere widget events - vtkSphereWidget
- Seed widget - vtkSeedWidget
- Sphere widget - vtkSphereWidget
- vtkSphereWidget2
- vtkSplineWidget
- vtkBorderWidget
- vtkAngleWidget
- vtkCaptionWidget
- 3D Slider
- 2D Slider
- Balloon
- Contour Widget - Create a contour from a set of points and dynamically change the contour using the points as control points.
- vtkDistanceWidget
- vtkImplicitPlaneWidget2 - Clip polydata with an implicit plane
- vtkBoxWidget2
- vtkLineWidget2
- vtkBiDimensionalWidget - When would you use this?
- vtkImagePlaneWidget
- vtkImageTracerWidget - Trace an image (not necessarily planar).
Miscellaneous
Plotting
Geographic Visualization (Geovis)
- Compass Widget
- Earth source - Create the Earth.
KWWidgets
Qt
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
- Render window - 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
- Side by side render windows
- vtkQtBarChart
- Border Widget
Matlab
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!
- File Output Window - vtkFileOutputWindow
- Threaded/Parallel example -
- Display non-overlapping labels - vtkLabelPlacementMapper, vtkLabelHierarchy, vtkPointSetToLabelHierarchy - no labels are displayed?
- Color glyphs - only one cube is displayed?
- Perform in-place operations on arrays - vtkArrayCalculator
- Marching cubes - vtkMarchingCubes
- Assign an array to a particular field - vtkAssignAttribute
- ImageDataGeometryFilter - vtkImageDataGeometryFilter
- Compute the gradient of a scalar field on a data set - vtkGradientFilter
- Automatic level of detail adjustment - vtkQuadricLODActor - doesn't seem to adjust?
- vtkCameraWidget -
- vtkFrustumCoverageCuller
- Level of detail rendering - vtkLODProp3D
- Align point sets - vtkProcrustesAlignmentFilter
- ScalarBarActor - vtkScalarBarActor
- Compute occupancy of an object on a grid - vtkVoxelModeller - vtk_bit is not supported - convert it?
- Image dot product - vtkImageDotProduct
- RubberBand3D - vtkInteractorStyleRubberBand3D
- OggTheora
- MPEG2 - CMake won't find MPEG2 include?
- FFMPEG - CMake won't find FFMPEG include?
- AVI (Windows only) - Someone please test this.
- Compute the difference image of two images - Currently passes the input image straight to the output.
- vtkImageMirrorPad - How would you actually use this?
- vtkImageToStructuredPoints - Doesn't seem to produce a vtkStructuredPoints?
- SpherePuzzle - vtkSpherePuzzle
- Divide a point cloud into uniform cubic voxels - vtkCellLocator
- Remove duplicate (merge) points - vtkMergePoints
- Filter progress report
- GeoGlobeSource - vtkGeoGlobeSource
- GeoView - vtkGeoView
- Stream Lines - vtkStreamLine
- vtkRungeKutta4
- vtkCoincidentPoints - what is this for?
- vtkAffineWidget - What does this do? It doesn't seem to actually change positions?
- Flight - vtkInteractorStyleFlight
- vtkPointHandleRepresentation2D
- RecordEvents - how to exit?
- PlayBackEvents - how to slow down?
- vtkDistanceToCamera - why aren't the points visible? How to trigger the DistanceToCamera computation?
- Quadric Surface Fitting
- LU Factorization - how do you get the resulting L and U?
- StructuredPointsReader
- Rectangular button source - vtkRectangularButtonSource - is this the intended usage?
- KMeans Clustering vtkKMeansStatistics - How to set cluster centers? How to perform clustering? How to get the cluster IDs after clustering? Example in 3D so we can color the clusters to visualize the result.
- display .vti volume in 3d render window?
- ApplyColors - vtkApplyColors - How is this different from just adding a Colors array to a vtkDataSet?
- vtkFrustumCoverageCuller - Doesn't seem to have a property to specify a frustum? What is it for? How to use it?
- vtkKdTreeSelector - What is this used for? How to use it?
- vtkSelectionSource
- vtkPCAStatistics - We need an example that takes a set of N-D data and project it into the best M-D space. We should do an example from 2D to 1D so we can visualize the result.
- vtkPCAAnalysisFilter - What is the difference between this and vtkPCAStatistics? Example?
- vtkTransposeMatrix - What is this supposed to operate on? There is no vtkMatrix class (yet!) - Example?
- What is the difference between vtkKdTreePointLocator and vtkKdTree?
- What does vtkHyperOctree do? Example?
- What is vtkWarpVector?
- Demonstration of vtkPropPicker
- vtkDijkstraGraphGeodesicPath
- vtkTextExtraction
- vtkQtChartView
- vtkQtChartWidget
- vtkQtTreeView
- vtkQtTableView
- vtkQtListView
- vtkQtChartArea
- vtkFrustumSource not available in Python ??
Developer Examples
Macros
String
char* Filename; vtkSetStringMacro(Filename);
Bool
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
- PolyDataAlgorithm Reader - Nothing in, PolyData out.
- PolyDataAlgorithm Filter - PolyData in, PolyData out.
- vtkGraphAlgorithm Source - Nothing in, Graph out.
- vtkGraphAlgorithm Filter - Graph in, Graph out.
- vtkImageAlgorithm Filter - Image in, Image out.
- vtkImageAlgorithm Source - Nothing in, Image out.
Custom classes
- vtkAlgorithm Source - Nothing in, custom class out.
- vtkAlgorithm Filter - Custom class in, custom class out.
- vtkAlgorithm Filter Multiple Output Ports - Nothing in, 2 custom classes out.
Multiple Connections on a Single Port
- Multiple Connections - Two PolyDatas in, 1 PolyData out.
Multiple Input Ports
- Multiple Input Ports - Two PolyDatas in, 1 PolyData out.
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;
Unknown
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
- Distance between two points
- Random numbers can be generated with Python's random module.
Input and Output
- Output
- add here
- Input
Geometric Objects
- Save to file:
- nothing here yet.
- Display on screen:
- Display Triangle
- Display Sphere
- Display Cube
- Display Cone (includes screenshot)
- Display Cylinder (includes screenshot)
- Display vtkPointSource (random points)
- Display a line with vtkLineSource
- Display text with vtkTextActor 2D "HUD-type" text (includes screenshot)
- Display Disk (includes screenshot)
- Display Plane
Working with PolyData
- Draw an outline box around an object with vtkOutlineFilter
- Rotation around a line with RotateWXYZ (includes screenshot)
- Write the corners of a triangle to a file
- Write the corners of a triangle to a file (+vertices)
- Write a triangle with colored points
- Write a colored triangle
- Write a solid colored triangle
- Write a triangle to a file
- Iterative Closest Points (ICP)
- Mesh a label image and write cell info to file
- Mesh a label image, smooth it and colour it according to the smoothing error
Miscellaneous
- Screenshot
- check VTK version
- vtkCutter
- vtkImplicitDataSet - Clip one data set with another
- vtkIdType - This is just a typedef, so in Python, you can use a python "int" or "long" for vtkIdType.
- A simple vtkCompassWidgetExample
- vtkWithNumpy
Visualization
- PointSize
- Color an Actor
- Unstructured Transient Volume Rendering
- Change the title of the render window
- Animation
- Create a single render window with muliple viewports
- InteractorStyleTrackBallCamera - vtkInteractorStyleTrackBallCamera
- InteractorStyleTrackBallActor - vtkInteractorStyleTrackBallActor
Infovis
- Parallel Coordinates View - Plotting data attributes in a Parallel Coordinates View
- Parallel Coordinates Extraction - Extract data based on a selection in a Parallel Coordinates View

