# 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

Example Name | Classes Demonstrated | Description | Image
--- | --- | --- | ---
Arrow | vtkArrowSource |  |
Axes | vtkAxesActor |  |
Cell3DDemonstration | vtkHexagonalPrism vtkHexahedron vtkPentagonalPrism vtkPolyhedron vtkPyramid vtkTetra vtkVoxel vtkWedge vtkUnstructuredGrid | Sample objects are generated from the classes derived from vtkCell3D and displayed. |
ColoredLines | vtkCellData vtkLine |  |
Cone | vtkConeSource |  |
Cube | vtkCubeSource |  |
Cylinder | vtkCylinderSource |  |
DataSetSurface | vtkDataSetSurfaceFilter |  |
Disk | vtkDiskSource | A circle with a hole in it. |
Frustum | vtkFrustumSource |  |
GeometricObjectsDemo |  |  |
Hexahedron | vtkHexahedron |  |
LineSource | vtkLineSource |  |
LongLine | vtkLine |  |
OrientedArrow | vtkArrowSource |  |
Plane | vtkPlaneSource |  |
PlanesIntersection | vtkPlanesIntersection |  |
Planes | vtkPlanes vtkHull | We create a convex hull of the planes for display purposes. |
PlatonicSolid | vtkPlatonicSolidSource | All five platonic solids are displayed. |
PointSource | vtkPointSource |  |
Point | vtkPoints |  |
Polyline | vtkPolyLine | This example demonstrates how to create a polygon through several ordered points. |
PolygonIntersection | vtkPolygon | IntersectWithLine() |
Polygon | vtkPolygon |  |
Pyramid | vtkPyramid |  |
Quad | vtkQuad |  |
RegularPolygonSource | vtkRegularPolygonSource |  |
Sphere | vtkSphereSource |  |
Tetrahedron | vtkTetra |  |
TextActor | vtkTextActor | 2D "HUD-type" text |
TriangleStrip | vtkTriangleStrip |  |
Triangle | vtkTriangle |  |
Vertex | vtkVertex |  |

### 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

Example Name | Classes Demonstrated | Description | Image
--- | --- | --- | ---
BooleanOperationPolyDataFilter | vtkBooleanOperationPolyDataFilter | This example performs a boolean operation (Intersection, Union, Difference) of two PolyData |
ColoredTriangle | vtkTriangle | Creates a file TriangleColored.vtp. |
CombinePolyData | vtkAppendPolyData | This example combines Polydata objects, and displays the result to the screen. |
Cube | vtkPolyData |  |
CurvaturesDemo | vtkCurvatures vtkColorTransferFunction | Demonstrates how to get the Gaussian and Mean curvatures of a surface. |
FilledPolygon | vtkCutter |  |
ImplicitPolyDataDistance | vtkImplicitPolyDataDistance |  |
IterativeClosestPoints | vtkIterativeClosestPointTransform |  |
KochSnowflake | vtkPolyData vtkCellArray vtkPoints vtkPolyLine | This example draws a Koch snowflake fractal using recursive functions and some of the convenient tools in the toolkit. |
LineOnMesh | vtkCellLocator vtkParametricSpline |  |
MeshLabelImageColor | vtkDiscreteMarchingCubes |  |
Outline | vtkOutlineFilter |  |
PolyDataContourToImageData | vtkLinearExtrusionFilter vtkPolyDataToImageStencil |  |
PolyDataToImageDataStencil | vtkPolyDataToImageStencil |  |
RotationAroundLine | vtkTransformPolyDataFilter |  |
RuledSurfaceFilter | vtkRuledSurfaceFilter |  |
SmoothMeshGrid | vtkLoopSubdivisionFilter vtkButterflySubdivisionFilter |  |
SolidColoredTriangle | vtkTriangle | Writes out a file TriangleSolidColor.vtp. |
TriangleColoredPoints | vtkUnsignedCharArray |  |
TriangleCornerVertices | vtkCellArray |  |
TriangleCorners | vtkXMLPolyDataWriter |  |
WarpVector | vtkLine vtkDoubleArray vtkPolyData vtkWarpVector | This example warps/deflects a line. |
WriteTriangleToFile | vtkTriangle |  |

## 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. |

## 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. |

## 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 |  |
MultipleViewports | vtkRenderer::SetViewport |  |
NamedColorPatches | vtkNamedColors | Creates a HTML file called VTKNamedColorPatches | Demonstrates how to use the vtkNamedColor class
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 |
TextSource | vtkTextSource |  |
UnstructuredTransientVolumeRendering | vtkUnstructuredGridVolumeRayCastMapper |  |
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
--- | --- | --- | ---
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 |