Skip to content
Snippets Groups Projects
Python.md 31.46 KiB

Please see [this](http://www.vtk.org/Wiki/VTK/Tutorials/PythonEnvironmentSetup 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 Classes Demonstrated Description
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
DistanceBetweenPoints vtkMath::Distance2BetweenPoints

#Input and Output ##Output

Example Name Classes Demonstrated Description
PLYWriter vtkPLYWriter
STLWriter vtkSTLWriter

##Input

Example Name Classes Demonstrated Description
STLReader vtkSTLReader
UnstructuredGridReader vtkUnstructuredGridReader Using vtkUnstructuredGridReader to read a (legacy) *.vtk file
VTPReader vtkXMLPolyDataReader

#Working with Arrays

Example Name Classes Demonstrated Description
GetValues GetTuple3
RenameArray SetName

#Geometric Objects ##Display

Example Name Classes Demonstrated Description
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
ParametricObjectsDemo vtkParametricBoy, vtkParametricConicSpiral, vtkParametricCrossCap, vtkParametricDini, vtkParametricEllipsoid, vtkParametricEnneper, vtkParametricFigure8Klein, vtkParametricKlein, vtkParametricMobius, vtkParametricRandomHills, vtkParametricRoman, vtkParametricSpline, vtkParametricSuperEllipsoid, vtkParametricSuperToroid, vtkParametricTorus 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
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
BooleanOperationPolyDataFilter vtkBooleanOperationPolyDataFilter This example performs a boolean operation (Intersection, Union, Difference) of two PolyData
ColoredTriangle vtkTriangle
CombinePolyData vtkAppendPolyData This example combines Polydata objects, and displays the result to the screen.
CurvaturesDemo vtkCurvatures, vtkColorTransferFunction Demonstrates how to get the Gaussian and Mean curvatures of a surface.
DottedLine vtkActor::GetProperty::SetLineStipplePattern
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
MeshLabelImage vtkDiscreteMarchingCubes
Outline vtkOutlineFilter
PolyDataContourToImageData vtkLinearExtrusionFilter,vtkPolyDataToImageStencil
PolyDataToImageDataStencil vtkPolyDataToImageStencil
RotationAroundLine vtkTransformPolyDataFilter
RuledSurfaceFilter vtkRuledSurfaceFilter
SolidColoredTriangle vtkTriangle
SubdivisionFilters vtkLoopSubdivisionFilter vtkButterflySubdivisionFilter
TriangleColoredPoints vtkUnsignedCharArray
TriangleCornerVertices vtkCellArray
TriangleCorners vtkXMLPolyDataWriter
WarpVectorpy vtkLine, vtkDoubleArray, vtkPolyData, vtkWarpVector This example warps/deflects a line.
WriteTriangleToFile vtkTriangle
py vtkPolyData

#Working with 3D Data

Example Name Classes Demonstrated Description
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
RectilinearGrid vtkRectilinearGrid create a rectilinear grid

##Working with Meshes This section includes examples of manipulating meshes.

Example Name Classes Demonstrated Description
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
BackgroundImage vtkJPEGReader, vtkImageCanvasSource2D, vtkImageActor, vtkSuperquadricSource
Cutter vtkCutter
[ImplicitDataSet](ImplicitDataSet](http://www.vtk.org/doc/nightly/html/classvtkImplicitDataSet.html)]( vtkIdType n/a This is just a typedef, Python, you can use a python "int" or "long" for vtkIdType.
Screenshot vtkWindowToImageFilter
Variant vtkVariant
vtkVersion vtkVersion

#Visualization

Example Name Classes Demonstrated Description
Animation vtkTimerCallback
AssignCellColorsFromLUT vtkNamedColors, vtkPlaneSource, vtkLookupTable, vtkColorTransferFunction Demonstrates how to assign colors to cells in a vtkPolyData structure using lookup tables.
Camera vtkCamera
ClampGlyphSizes vtkGlyph3D Use vtkGlyph3D with ClampingOn to limit glyph sizes
ColorActor vtkActor::GetProperty()::SetColor
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.
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
HardwareSelector vtkHardwareSelector
InteractorStyleTrackballActor vtkInteractorStyleTrackBallActor
InteractorStyleTrackballCamera vtkInteractorStyleTrackBallCamera
MultipleViewports vtkRenderer::SetViewport
NamedColorPatches vtkNamedColors Creates a HTML file called VTKNamedColorPatches.html showing the available colors in the vtkNamedColors class.
NamedColors vtkNamedColors Demonstrates how to use the vtkNamedColor class
PointSize vtkActor::GetProperty()::SetPointSize
ProgGlyph vtkProgrammableGlyphFilter 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
WindowTitle vtkRenderWindow::SetWindowName

#Working with vtkImageData

Example Name Classes Demonstrated Description
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
weights.

#Working with ExodusII Data

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

#Graphs

Example Name Classes Demonstrated Description
EdgeWeights vtkMutableDirectedGraph, vtkGraphLayoutView
NOVCAGraph vtkUnstructuredGrid, vtkXMLUnstructuredGridWriter
SelectedVerticesAndEdges vtkAnnotationLink, vtkGraphLayoutView
VisualizeGraph vtkMutableDirectedGraph, vtkGraphLayoutView

#User Interaction

Example Name Classes Demonstrated Description
HighlightAPickedActor 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
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
GeoAssignCoordinates vtkGeoAssignCoordinates, vtkMutableDirectedGraph, vtkGraphMapper Draws a sphere, based on longituds and latitudes.

#Widgets

Example Name Classes Demonstrated Description
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
Delaunay2D vtkDelaunay2D
LUTUtilities vtkLookupTable vtkColorSeries A utility class for vtkLookupTable allowing you to output the table contents or to compare tables.

#Web

Example Name Classes Demonstrated Description
RemoteRenderer Web/Python Use vtk to show an interactive visualization on a web page. Remote rendering.

#PyQt

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