Python Examples¶
Please see this page to learn how to setup your environment to use VTK in Python.
It would be appreciated if there are any Python VTK experts who could convert any of the c++ examples to Python!
Info
This table shows the VTK classes covered by the examples.
Info
This table shows VTK classes that do not have an example. Please add examples in your area of expertise!
Hello World¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| CylinderExample | vtkPolyDataMapper vtkActor vtkRenderer vtkRenderWindow vtkRenderWindowInteractor | Cylinder example from the VTK Textbook and source code. A hello world example | |
Simple Operations¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| DistanceBetweenPoints | vtkMath::Distance2BetweenPoints |
Input and Output¶
Output¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| PLYWriter | vtkPLYWriter | ||
| STLWriter | vtkSTLWriter |
Input¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| STLReader | vtkSTLReader | ||
| UnstructuredGridReader | vtkUnstructuredGridReader | Using vtkUnstructuredGridReader to read a (legacy) *.vtk file | |
| VTPReader | vtkXMLPolyDataReader | Needs fixing. |
Working with Arrays¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| GetValues | GetTuple3 | ||
| RenameArray | SetName |
Geometric Objects¶
Display¶
Parametric Objects¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| ParametricObjectsDemo | vtkParametricBoy vtkParametricConicSpiral vtkParametricCrossCap vtkParametricDini vtkParametricEllipsoid vtkParametricEnneper vtkParametricFigure8Klein vtkParametricKlein vtkParametricMobius vtkParametricRandomHills vtkParametricRoman vtkParametricSpline vtkParametricSuperEllipsoid vtkParametricSuperToroid vtkParametricTorus | Demonstration of of the vtkParametric classes added by Andrew Maclean. All the objects are displayed in a 4X4 array. | |
| ParametricObjects | Uncomment the object that you wish to be displayed. | ||
Implicit Functions and Iso-surfaces¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| ImplicitDataSet | vtkImplicitDataSet | vtkIdType n/a. This is just a typedef, Python, you can use a python "int" or "long" for vtkIdType. |
Implicit Functions¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| Boolean | vtkImplicitBoolean | Demonstrate booleans of two different implicit functions | |
| Quadric | vtkQuadric | Create an ellipsoid using an implicit quadric | |
| Sphere | vtkSphere | Demonstrate sampling of a sphere implicit function | |
Working with PolyData¶
Working with 3D Data¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| ExtractSelection | vtkExtractSelection | ||
| ExtractSelectionCells | vtkExtractSelection | Extract cell, select cell. | |
Working with Structured 3D Data¶
This section includes vtkImageData, vtkStructuredGrid, and vtkRectilinearGrid.
vtkImageData¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| ImageWeightedSum | vtkImageWeightedSum | Add two or more images. | |
vtkRectilinearGrid¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| RectilinearGrid | vtkRectilinearGrid | create a rectilinear grid | |
Working with Meshes¶
This section includes examples of manipulating meshes.
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| ClipDataSetWithPolydata | vtkClipDataSet vtkImplicitPolyDataDistance vtkRectilinearGrid | clip a vtkRectilinearGrid with arbitrary polydata. In this example, use a vtkConeSource to generate polydata to slice the grid, resulting in an unstructured grid. | |
| DelaunayMesh | vtkDelaunay2D vtkMinimalStandardRandomSequence vtkExtractEdges vtkGlyph3D vtkTubeFilter | Two-dimensional Delaunay triangulation of a random set of points. Points and edges are shown highlighted with sphere glyphs and tubes. | |
Rendering¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| DottedLine | This needs a re-work, see StippledLine.cxx | ||
| Rotations | vtkActor::RotateX,Y,Z vtkRenderer::EraseOff | Rotations of a cow about her axes. | |
| WalkCow | vtkBYUReader renWin::EraseOff() vtkActor | This generates Figs. 3-31, 3-32, 3-33 found in VTKTextbook.pdf. | |
Texture Mapping¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| TextureThreshold | vtkTexture vtkThresholdTextureCoords vtkStructuredGridGeometryFilter | Demonstrate the use of scalar thresholds to show values of flow density on three planes. | |
Visualization¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| AssignCellColorsFromLUT | vtkNamedColors vtkPlaneSource vtkLookupTable vtkColorTransferFunction | Demonstrates how to assign colors to cells in a vtkPolyData structure using lookup tables. | |
| Camera | vtkCamera | Positioning and aiming the camera. | |
| ClampGlyphSizes | vtkGlyph3D | Use vtkGlyph3D with ClampingOn to limit glyph sizes | |
| ColorActor | vtkActor::GetProperty()::SetColor | Colour the actor. | |
| CubeAxesActor | vtkCubeAxesActor | ||
| CurvatureBandsWithGlyphs | vtkCurvatures vtkBandedPolyDataContourFilter vtkLookupTable vtkColorSeries vtkGlyph3D | Demonstrates the coloring of a surface by partitioning the gaussian curvature of a surface into bands and using arrows to display the normals on the surface. | |
| Cutter | vtkCutter | ||
| DisplacementPlot | vtkColorTransferFunction vtkWarpVector vtkVectorDot | Show modal lines for a vibrating beam. | |
| ElevationBandsWithGlyphs | vtkBandedPolyDataContourFilter vtkLookupTable vtkColorSeries vtkGlyph3D | Demonstrates the coloring of a surface by partitioning the elevation into bands and using arrows to display the normals on the surface. | |
| GlyphTable | vtkGlyph3D | Vary the shapes of glyphed points using a glyph table | |
| Hawaii | vtkElevationFilter vtkColorSeries vtkLookupTable | Visualize elevations by coloring the scalar values with a lookup table. | |
| HardwareSelector | vtkHardwareSelector | ||
| InteractorStyleTrackballActor | vtkInteractorStyleTrackBallActor | ||
| InteractorStyleTrackballCamera | vtkInteractorStyleTrackBallCamera | ||
| Motor | vtkBYUReader vtkStructuredPointsReader vtkTexture vtkImplicitTextureCoords | Texture cut used to reveal internal structure of a motor. Two cut planes are used in combination with transparent texture. | |
| MultipleViewports | vtkRenderer::SetViewport | ||
| NamedColors | vtkNamedColors | Demonstrates how to use the vtkNamedColors class. | |
| NamedColorPatches | vtkNamedColors | Creates a HTML file called VTKNamedColorPatches | |
| Office | vtkPointSource vtkStreamTracer | Using random point seeds to create streamlines. | |
| OfficeTube | vtkStreamTracer vtkTubeFilter | The stream polygon. Sweeping a polygon to form a tube. | |
| OrientedGlyphs | vtkGlyph3D | Create oriented glyphs from vector data. | |
| PlateVibration | vtkWarpVector vtkVectorDot | Demonstrates the motion of a vibrating beam. | |
| PointDataSubdivision | vtkLinearSubdivisionFilter | Vary the shapes of glyphed points using a programmable glyph filter | |
| QuadraticSurface | vtkQuadric | ||
| SphereTexture | vtkTextureMapToSphere | Apply an ImageData texture to an sphere | |
| Streamlines | vtkStreamLine | Seed streamlines with vectors from a structured grid | |
| StreamlinesWithLineWidget | vtkCallbackCommand vtkLineWidget | Using the vtkLineWidget to produce streamlines in the combustor dataset. The StartInteractionEvent turns the visibility of the streamlines on; the InteractionEvent causes the streamlines to regenerate themselves. | |
| TensorAxes | vtkPointLoad vtkTensorGlyph | Display the scaled and oriented principal axes of the stress tensor. | |
| TensorEllipsoids | vtkPointLoad vtkTensorGlyph | Display the scaled and oriented principal axes as tensor ellipsoids representing the stress tensor. | |
| TextSource | vtkTextSource | ||
| UnstructuredTransientVolumeRendering | vtkUnstructuredGridVolumeRayCastMapper | ||
| VelocityProfile | vtkMultiBlockPLOT3DReader vtkStructuredGridGeometryFilter vtkAppendPolyData vtkWarpVector | Warping the geometry of three planes to show flow momentum. | |
| VectorText | vtkVectorText | Display high resolution text. | |
| WindowTitle | vtkRenderWindow::SetWindowName | ||
Working with Images¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| BackgroundImage | vtkJPEGReader vtkImageCanvasSource2D vtkImageActor vtkSuperquadricSource | Display an image as the "background" of a scene, and render a superquadric in front of it. |
Working with vtkImageData¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| SumVTKImages | vtkImageWeightedSum | A function to simplify the summing of images, where you can pass a list of images and | |
| WriteReadVtkImageData | vtkImageData vtkXMLImageDataReader vtkXMLImageDataWriter |
Working with ExodusII Data¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| ReadExodusData | vtkExodusIIReader | A simple script for reading and viewing ExodusII data interactively. |
Graphs¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| EdgeWeights | vtkMutableDirectedGraph vtkGraphLayoutView | ||
| NOVCAGraph | vtkUnstructuredGrid vtkXMLUnstructuredGridWriter | ||
| SelectedVerticesAndEdges | vtkAnnotationLink vtkGraphLayoutView | ||
| VisualizeGraph | vtkMutableDirectedGraph vtkGraphLayoutView | ||
User Interaction¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| CallBack | vtkCallbackCommand vtkOrientationMarkerWidget | Setting up a callback with client data. Two different methods are demonstrated. | |
| HighlightPickedActor | vtkPropPicker vtkInteractorStyleTrackballCamera | Pick and highlight an actor based on mouse clicks. | |
| MouseEventsObserver | vtkCallbackCommand | Use an observer. | |
| MouseEvents | vtkInteractorStyleTrackballCamera | Subclass the interactor style. |
Infovis¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| ParallelCoordinatesExtraction | vtkExtractSelection vtkAnnotationLink | Extract data based on a selection in a Parallel Coordinates View | |
| ParallelCoordinatesView | vtkRTAnalyticSource vtkParallelCoordinatesView vtkParallelCoordinatesRepresentation | Plotting data attributes in a Parallel Coordinates View | |
| ScatterPlot | vtkChartXY | ||
| SelectedGraphIDs | vtkAnnotationLink vtkRandomGraphSource vtkGraphLayoutView | Callback on vtkAnnotationLink in a Graph Layout View when selection is changed | |
| SpiderPlot | vtkSpiderPlotActor | ||
Geovis¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| GeoAssignCoordinates | vtkGeoAssignCoordinates vtkMutableDirectedGraph vtkGraphMapper | Draws a sphere, based on longituds and latitudes. | |
Widgets¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| BalloonWidget | vtkBalloonWidget vtkBalloonRepresentation | Uses a vtkBalloonWidget to draw labels when the mouse stays above an actor. | |
| BoxWidget | vtkBoxWidget | This 3D widget defines a region of interest that is represented by an arbitrarily oriented hexahedron with interior face angles of 90 degrees (orthogonal faces). The object creates 7 handles that can be moused on and manipulated. | |
| CompassWidget | vtkCompassWidget vtkCompassRepresentation | Draws an interactive compass. | |
| ContourWidget | vtkContourWidget vtkOrientedGlyphContourRepresentation | Draw a contour (line) which can be deformed by the user | |
| OrientationMarkerWidget | vtkAnnotatedCubeActor vtkOrientationWidget | Draws two cubes. One of them can be clicked to be rotated, and will rotate the second one. The second one has annotations on it, and can also be moved. | |
| ScalarBarWidget | vtkScalarBarWidget | The ScalarBarWidget displays a scalar bar that is movable and changes orientation automatically when close to the borders of the image. It needs a ScalarBarActor | |
| SphereWidget | vtkSphereWidget | This 3D widget defines a sphere that can be interactively placed in a scene. | |
| TextWidget | vtkTextWidget | Annotate a VTK image with movable text | |
Utilities¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| Delaunay2D | vtkDelaunay2D | ||
| LUTUtilities | vtkLookupTable vtkColorSeries | A utility class for vtkLookupTable allowing you to output the table contents or to compare tables. | |
| Screenshot | vtkWindowToImageFilter | ||
| Variant | vtkVariant | ||
| VTKWithNumpy | vtkImageImport | ||
| VTKVersion | vtkVersion |
Animation¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| Animation | vtkRenderWindowInteractor | Move a sphere across a scene. | |
PyQt¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| EmbedInPyQt | vtkRenderWindowInteractor | Shows how to easily embed VTK in PyQt with QVTKRenderWindowInteractor, first example | |
| EmbedInPyQt2 | vtkRenderWindowInteractor | Shows how to embed VTK in PyQt with QVTKRenderWindowInteractor, second example | |