VTK/Examples/Python

From KitwarePublic
< VTK‎ | Examples
Jump to: navigation, search

Please try the new VTKExamples website.

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!

Hello World

Example Name VTK Classes Demonstrated Description
A hello world example vtkPolyDataMapper vtkActor vtkRenderer vtkRenderWindow vtkRenderWindowInteractor Cylinder example from the VTK Textbook and source code.

Simple Operations

Example Name VTK Classes Demonstrated Description
Distance between two points vtkMath::Distance2BetweenPoints
Random numbers n/a Random numbers can be generated with Python's random module

Input and Output

Output

Example Name VTK Classes Demonstrated Description
Using STLWriter to write a STL file vtkSTLWriter
Write PLY (.ply) files vtkPLYWriter

Input

Example Name VTK Classes Demonstrated Description
Using STLReader to read a STL file vtkSTLReader
Using vtkVTPReader to read a VTP file vtkXMLPolyDataReader
UnstructuredGridReader.py vtkUnstructuredGridReader

Using vtkUnstructuredGridReader to read a (legacy) *.vtk file

Using vtkFLUENTReader to read a Fluent case file vtkFLUENTReader

Using vtkFLUENTReader to read a Fluent case file and extract the unstructured grid.

Working with Arrays

Example Name VTK Classes Demonstrated Description
Get a value from an array GetTuple3
Rename an array SetName

Geometric Objects

Display

Example Name VTK Classes Demonstrated Description
Demonstrate the use of vtkCell3D to construct geometric objects. vtkHexagonalPrism vtkHexahedron vtkPentagonalPrism vtkPolyhedron vtkPyramid vtkTetra vtkVoxel vtkWedge vtkUnstructuredGrid Sample objects are generated from the classes derived from vtkCell3D and displayed.
Compute the intersection of a line segment with a polygon vtkPolygon IntersectWithLine()
A demonstration of all geometric objects that work the same way
Arrow vtkArrowSource
Axes vtkAxesActor
Colored Lines vtkCellData vtkLine
Cone vtkConeSource
Cube vtkCubeSource
Cylinder vtkCylinderSource
Disk vtkDiskSource A circle with a hole in it.
Frustum vtkFrustumSource
Line vtkLineSource
Manually create a polyline vtkLine
Hexahedron vtkHexahedron
Oriented Arrow vtkArrowSource
Plane vtkPlaneSource
Planes vtkPlanes, vtkHull We create a convex hull of the planes for display purposes.
PlanesIntersection vtkPlanesIntersection
PlatonicSolid vtkPlatonicSolidSource All five platonic solids are displayed.
Point vtkPoints
Polygon vtkPolygon
Pyramid vtkPyramid
PolyLine vtkPolyLine This example demonstrates how to create a polygon through several ordered points.
Quad vtkQuad
Regular Polygon vtkRegularPolygonSource
Sphere vtkSphereSource
Triangle vtkTriangle
Triangle strip vtkTriangleStrip
Tetrahedron vtkTetra
Vertex vtkVertex
Display vtkPointSource vtkPointSource
Display text with vtkTextActor vtkTextActor 2D "HUD-type" text
vtkDataSetSurfaceFilter vtkDataSetSurfaceFilter

Parametric Objects

Example Name VTK Classes Demonstrated Description
Create and display a parametric object Uncomment the object that you wish to be displayed.
Demonstration of all of the vtkParametric* classes vtkParametricBoy, vtkParametricConicSpiral, vtkParametricCrossCap, vtkParametricDini, vtkParametricEllipsoid, vtkParametricEnneper, vtkParametricFigure8Klein, vtkParametricKlein, vtkParametricMobius, vtkParametricRandomHills, vtkParametricRoman, vtkParametricSpline, vtkParametricSuperEllipsoid, vtkParametricSuperToroid, vtkParametricTorus All the objects are displayed in a 4X4 array.

Implicit Functions

Example Name VTK Classes Demonstrated Description
Create a sphere vtkSphere Demonstrate sampling of a sphere implicit function
Create an ellipsoid vtkQuadric Create an ellipsoid using an implicit quadric
Boolean two implicit functions vtkImplicitBoolean Demonstrate booleans of two different implicit functions

Working with PolyData

Example Name VTK Classes Demonstrated Description
A demonstration of curvatures on a surface vtkCurvatures, vtkColorTransferFunction

Demonstrates how to get the Gaussian and Mean curvatures of a surface.

Draw an outline box around an object vtkOutlineFilter
Rotation around a line with RotateWXYZ vtkTransformPolyDataFilter
Write the corners of a triangle to a file vtkXMLPolyDataWriter
Write the corners of a triangle to a file (+vertices) vtkCellArray
Write a triangle with colored points vtkUnsignedCharArray
Write a colored triangle vtkTriangle
Write a solid colored triangle vtkTriangle
Write a triangle to a file vtkTriangle
Iterative Closest Points (ICP) vtkIterativeClosestPointTransform
Mesh a label image and write cell info to file vtkDiscreteMarchingCubes
Mesh a label image, smooth it and colour it according to the smoothing error vtkDiscreteMarchingCubes
Get a filled polygon from vtkCutter vtkCutter
Create a dotted line vtkActor::GetProperty::SetLineStipplePattern
Create a surface between lines vtkRuledSurfaceFilter
Smooth meshgrid vtkLoopSubdivisionFilter vtkButterflySubdivisionFilter
Manually construct a cube vtkPolyData
Draw a line along a meshgrid vtkCellLocator, vtkParametricSpline
Generate a binarized image from a closed contour vtkLinearExtrusionFilter,vtkPolyDataToImageStencil
Convert polydata to imagedata and mask imagedata vtkPolyDataToImageStencil
WarpVector vtkLine, vtkDoubleArray, vtkPolyData, vtkWarpVector This example warps/deflects a line.
Combine multiple PolyData vtkAppendPolyData This example combines Polydata objects, and displays the result to the screen.
Computes boolean operation of two spheres vtkBooleanOperationPolyDataFilter This example performs a boolean operation (Intersection, Union, Difference) of two PolyData
KochSnowflake vtkPolyData, vtkCellArray, vtkPoints, vtkPolyLine This example draws a Koch snowflake fractal using recursive functions and some of the convenient tools in the toolkit.
vtkImplicitPolyDataDistance vtkImplicitPolyDataDistance

Working with 3D Data

Example Name VTK Classes Demonstrated Description
Extract selection points vtkExtractSelection
Extract selection cells vtkExtractSelection extract cell, select cell

Working with Structured 3D Data

This section includes vtkImageData, vtkStructuredGrid, and vtkRectilinearGrid.

Example Name VTK Classes Demonstrated Description
rectilinear grid vtkRectilinearGrid create a rectilinear grid

Working with Meshes

This section includes examples of manipulating meshes.

Example Name VTK Classes Demonstrated Description
clip grid with polydata 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 VTK Classes Demonstrated Description
Screenshot vtkWindowToImageFilter
Check VTK version vtkVersion
vtkCutter vtkCutter
vtkImplicitDataSet vtkImplicitDataSet Clip one data set with another
vtkIdType n/a This is just a typedef, so in Python, you can use a python "int" or "long" for vtkIdType.
Using Numpy n/a
vtkVariant vtkVariant
Background Image vtkJPEGReader, vtkImageCanvasSource2D, vtkImageActor, vtkSuperquadricSource

Visualization

Example Name VTK Classes Demonstrated Description
Assign colors to cells in a vtkPolyData structure using lookup tables. vtkNamedColors, vtkPlaneSource, vtkLookupTable, vtkColorTransferFunction Demonstrates how to assign colors to cells in a vtkPolyData structure using lookup tables.
Generate a surface and color by elevation bands using arrows for glyphing normals. 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.
Generate a surface and color by curvature bands using arrows for glyphing normals. 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.
Get a list of the visible triangles vtkHardwareSelector
Display a quadratic surface vtkQuadric
PointSize vtkActor::GetProperty()::SetPointSize
Color an Actor vtkActor::GetProperty()::SetColor
Unstructured Transient Volume Rendering vtkUnstructuredGridVolumeRayCastMapper
Change the title of the render window vtkRenderWindow::SetWindowName
Animation vtkTimerCallback
Create a single render window with muliple viewports vtkRenderer::SetViewport
InteractorStyleTrackBallCamera vtkInteractorStyleTrackBallCamera
InteractorStyleTrackBallActor vtkInteractorStyleTrackBallActor
Camera vtkCamera
Create Text vtkTextSource
Clamp glyph sizes vtkGlyph3D Use vtkGlyph3D with ClampingOn to limit glyph sizes
Use a glyph table vtkGlyph3D Vary the shapes of glyphed points using a glyph table
Named colors vtkNamedColors Demonstrates how to use the vtkNamedColor class
Named color patches vtkNamedColors Creates a HTML file called VTKNamedColorPatches.html showing the available colors in vtkNamedColors.
Programmable glyphs vtkProgrammableGlyphFilter Vary the shapes of glyphed points using a programmable glyph filter
Apply a texture to a sphere vtkTextureMapToSphere Apply an ImageData texture to an sphere
Display three orthogonal axes with labels vtkCubeAxesActor
Stream Lines vtkStreamLine Seed streamlines with vectors from a structured grid

Working with vtkImageData

Example Name VTK Classes Demonstrated Description
Write and read vtkImageData vtkImageData, vtkXMLImageDataReader, vtkXMLImageDataWriter
Summing images vtkImageWeightedSum
Summing images vtkImageWeightedSum A function to simplify the summing of images, where you can pass a list of images and

weights.

Working with ExodusII Data

Example Name VTK Classes Demonstrated Description
Read an ExodusII file vtkExodusIIReader A simple script for reading and viewing ExodusII data interactively.

Graphs

Example Name VTK Classes Demonstrated Description
Create and visualize a graph vtkMutableDirectedGraph, vtkGraphLayoutView
Add edge weights to a graph vtkMutableDirectedGraph, vtkGraphLayoutView
Get a list of the selected vertices and edges vtkAnnotationLink, vtkGraphLayoutView
Dump a graph to visualize it in VisIt/ParaView vtkUnstructuredGrid, vtkXMLUnstructuredGridWriter

User Interaction

Example Name VTK Classes Demonstrated Description
Handle mouse events vtkInteractorStyleTrackballCamera Subclass the interactor style.
Handle mouse events (light weight) vtkCallbackCommand Use an observer.
Highlight a picked actor vtkPropPicker, vtkInteractorStyleTrackballCamera Pick and highlight an actor based on mouse clicks.

Infovis

Example Name VTK Classes Demonstrated Description
View Selected Graph IDs vtkAnnotationLink, vtkRandomGraphSource, vtkGraphLayoutView Callback on vtkAnnotationLink in a Graph Layout View when selection is changed
Parallel Coordinates View vtkRTAnalyticSource, vtkParallelCoordinatesView, vtkParallelCoordinatesRepresentation Plotting data attributes in a Parallel Coordinates View
Parallel Coordinates Extraction vtkExtractSelection, vtkAnnotationLink Extract data based on a selection in a Parallel Coordinates View
Scatter plot vtkChartXY
SpiderPlot vtkSpiderPlotActor

Geovis

Example Name VTK Classes Demonstrated Description
vtkGeoAssignCoordinates vtkGeoAssignCoordinates, vtkMutableDirectedGraph, vtkGraphMapper Draws a sphere, based on longituds and latitudes.

Widgets

Example Name VTK Classes Demonstrated Description
Balloon widget vtkBalloonWidget, vtkBalloonRepresentation Uses a vtkBalloonWidget to draw labels when the mouse stays above an actor.
Annotated cube with vtkOrientationWidget 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.
Compass widget vtkCompassWidget, vtkCompassRepresentation Draws an interactive compass.
Contour widget vtkContourWidget, vtkOrientedGlyphContourRepresentation Draw a contour (line) which can be deformed by the user
Text widget vtkTextWidget Annotate a VTK image with movable text
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
Sphere Widget vtkSphereWidget This 3D widget defines a sphere that can be interactively placed in a scene.
Box Widget 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.

Utilities

Example Name VTK Classes Demonstrated Description
vtkDelaunay2D vtkDelaunay2D
Lookup Table Utilities vtkLookupTable vtkColorSeries A utility class for vtkLookupTable allowing you to output the table contents or to compare tables.

Web

Example Name VTK Classes Demonstrated Description
Remote Renderer Web/Python Use vtk to show an interactive visualization on a web page. Remote rendering.
vtk.js A growing sub-set vtk.js is VTK implemented in JavaScript, running in your browser.

PyQt

Example Name VTK Classes Demonstrated Description
Embed in PyQt 1 vtkRenderWindowInteractor Shows how to easily embed VTK in PyQt with QVTKRenderWindowInteractor, first example
Embed in PyQt 2 vtkRenderWindowInteractor Shows how to embed VTK in PyQt with QVTKRenderWindowInteractor, second example

Broken/Missing Examples

Broken/Missing Python Functionality

Example Name VTK Classes Demonstrated Description
FrustumSource vtkFrustumSource Fixed
PointInPolygon not available in Python ?
method FindClosestPoint (and others) of vtkCellLocator not available in Python