PythonicAPI Examples
These examples use the improved VTK Python interface. Some information about the improved Python interface can be found here
The examples here are either newly crafted ones or upgraded existing Python examples using the improved VTK Python interface.
See More Pythonic VTK wrapping for the VTK Discourse discussion and Wrap VTK properties to pythonic properties with snake_case names for the merge request.
Upgrading an existing example to use the improved VTK Python interface
- Copy the example from the src/Python folder into the src/PythonicAPI folder maintaining the same path structure. If there is a corresponding markdown file, copy it.
- Copy the corresponding test image from src/Testing/Baseline/Python/ into src/Testing/Baseline/PythonicAPI/
- Edit src/PythonicAPI.md, possibly creating a table and headings to match the original example in src/Python.
- Upgrade the Python example.
- The associated markdown file (if any) may need checking to ensure any links in the document remain valid.
- Check everything is working and do a Merge Request.
Adding a new example
Follow the documented procedure ForDevelopers remembering that the folder to use is PythonicAPI.
VTK Classes Summary
This Python script, SelectExamples, will let you select examples based on a VTK Class and language. It requires Python 3.7 or later. The following tables will produce similar information.
Tutorials
Hello World
Example Name | Description | Image |
A hello world example | Cylinder example from the VTK Textbook and source code. A hello world example. | |
| | |
Simple Operations
Importers
Output
Output
Example Name | Description | Image |
HDRReader | Read a high-dynamic-range imaging file. | |
| | |
Output
Geometric Objects
Example Name | Description | Image |
GeometricObjectsDemo | | |
| | |
PipelineReuse | How to reuse a pipeline. | |
| | |
SourceObjectsDemo | Examples of source objects that procedurally generate polygonal models. These nine images represent just some of the capability of VTK. From upper left in reading order: sphere, cone, cylinder, cube, plane, text, random point cloud, disk (with or without hole), and line source. Other polygonal source objects are available; check subclasses of vtkPolyDataAlgorithm. | |
| | |
Cells
Sources
Non Linear
Parametric Objects
Example Name | Description | Image |
ParametricObjectsDemo | Demonstrates the Parametric classes added by Andrew Maclean and additional classes added by Tim Meehan. The parametric spline is also included. Options are provided to display single objects, add backface, add normals and print out an image. | |
| | |
ParametricKuenDemo | Interactively change the parameters for a Kuen Surface. | |
| | |
Implicit Functions and Iso-surfaces
Working with 3D Data
Data Types
Example Name | Description | Image |
OverlappingAMR | Demonstrates how to create and populate VTK's Overlapping AMR Grid type with data. | |
| | |
Data Type Conversions
Point Cloud Operations
Working with Meshes
This section includes examples of manipulating meshes.
Example Name | Description | Image |
DelaunayMesh | Two-dimensional Delaunay triangulation of a random set of points. Points and edges are shown highlighted with sphere glyphs and tubes. | |
| | |
Clipping
Example Name | Description | Image |
SolidClip | Create a "solid" clip. The "ghost" of the part clipped away is also shown. | |
| | |
Working with Structured 3D Data
vtkImageData
vtkExplicitStructuredGrid
Example Name | Description | Image |
CreateESGrid | Create an explicit structured grid and convert this to an unstructured grid or vice versa. | |
| | |
LoadESGrid | Load a VTU file and convert the dataset to an explicit structured grid. | |
| | |
vtkStructuredGrid
Example Name | Description | Image |
BlankPoint | Blank a point of a vtkStructuredGrid. | |
| | |
SGrid | Creating a structured grid dataset of a semi-cylinder. Vectors are created whose magnitude is proportional to radius and oriented in tangential direction. | |
| | |
vtkStructuredPoints
Example Name | Description | Image |
Vol | Creating a image data dataset. Scalar data is generated from the equation for a sphere. Volume dimensions are 26 x 26 x 26. | |
| | |
vtkRectilinearGrid
Example Name | Description | Image |
RGrid | Creating a rectilinear grid dataset. The coordinates along each axis are defined using an instance of vtkDataArray. | |
| | |
VisualizeRectilinearGrid | Visualize the cells of a rectilinear grid. | |
| | |
Working with Unstructured 3D Data
This section includes vtkUnstructuredGrid.
vtkUnstructuredGrid
Registration
Medical
Example Name | Description | Image |
MedicalDemo1 | Create a skin surface from volume data. | |
| | |
Surface reconstruction
Utilities
Arrays
Events
Math Operations
Graphs
Example Name | Description | Image |
SideBySideGraphs | Display two graphs side by side. | |
| | |
Graph Conversions
Data Structures
Timing Demonstrations
KD-Tree
Oriented Bounding Box (OBB) Tree
Octree
Modified BSP Tree
HyperTreeGrid
VTK Concepts
Rendering
Lighting
Texture Mapping
Example Name | Description | Image |
AnimateVectors | One frame from a vector field animation using texture maps. | |
| | |
TextureCutQuadric | Cut a quadric with boolean textures. | |
| | |
TextureCutSphere | Examples of texture thresholding using a boolean combination of two planes to cut nested spheres. | |
| | |
TexturePlane | Example of texture mapping. | |
| | |
TextureThreshold | Demonstrate the use of scalar thresholds to show values of flow density on three planes. | |
| | |
Tutorial
If you are new to VTK then these tutorials will help to get you started.
Visualization
See this tutorial for a brief explanation of the VTK terminology of mappers, actors, etc.
Working with vtkImageData
Volume Rendering
User Interaction
Working with Images
Example Name | Description | Image |
BackgroundImage | Display an image as the "background" of a scene, and render a superquadric in front of it. | |
| | |
Image Processing
Example Name | Description | Image |
Attenuation | This MRI image illustrates attenuation that can occur due to sensor position. The artifact is removed by dividing by the attenuation profile determined manually. | |
| | |
EnhanceEdges | High-pass filters can extract and enhance edges in an image. Subtraction of the Laplacian (middle) from the original image (left) results in edge enhancement or a sharpening operation (right). | |
| | |
GaussianSmooth | Low-pass filters can be implemented as convolution with a Gaussian kernel. | |
| | |
VTKSpectrum | The discrete Fourier transform changes an image from the spatial domain into the frequency domain, where each pixel represents a sinusoidal function. This figure shows an image and its power spectrum displayed using a logarithmic transfer function. | |
| | |
Plotting
Animation
Example Name | Description | Image |
Animation | Move a sphere across a scene. | |
| | |
Annotation
InfoVis
PyQt