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 |
|---|---|---|---|
| Cylinder | 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 | |
| VTPsReader |
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¶
| 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.
| 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. | |
Miscellaneous¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| BackgroundImage | vtkJPEGReader vtkImageCanvasSource2D vtkImageActor vtkSuperquadricSource | ||
| Cutter | vtkCutter | ||
| ImplicitDataSet | vtkImplicitDataSet | vtkIdType n/a. This is just a typedef, Python, you can use a python "int" or "long" for vtkIdType. | |
| Screenshot | vtkWindowToImageFilter | ||
| Variant | vtkVariant | ||
| vtkVersion |
Rendering¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| 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. | |
Visualization¶
Working with vtkImageData¶
| Example Name | Classes Demonstrated | Description | Image |
|---|---|---|---|
| ImageWeightedSum | vtkImageWeightedSum | ||
| 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 |
|---|---|---|---|
| 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. |
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 | |