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
Cylinder 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
DistanceBetweenPoints Distance between two points vtkMath::Distance2BetweenPoints

Input and Output

Output

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

Input

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

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

vtkFLUENTReader 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
GetValues Get a value from an array GetTuple3
RenameArray Rename an array SetName

Geometric Objects

Display

Example Name VTK Classes Demonstrated Description
Cell3DDemonstration 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.
PolygonIntersection Compute the intersection of a line segment with a polygon vtkPolygon IntersectWithLine()
GeometricObjectsDemo A demonstration of all geometric objects that work the same way
Arrow Arrow vtkArrowSource
Axes Axes vtkAxesActor
ColoredLines Colored Lines vtkCellData vtkLine
Cone Cone vtkConeSource
Cube Cube vtkCubeSource
Cylinder Cylinder vtkCylinderSource
Disk Disk vtkDiskSource A circle with a hole in it.
Frustum Frustum vtkFrustumSource
LineSource Line vtkLineSource
LongLine Manually create a polyline vtkLine
Hexahedron Hexahedron vtkHexahedron
OrientedArrow Oriented Arrow vtkArrowSource
Plane Plane vtkPlaneSource
Planes Planes vtkPlanes, vtkHull We create a convex hull of the planes for display purposes.
PlanesIntersection PlanesIntersection vtkPlanesIntersection
PlatonicSolid PlatonicSolid vtkPlatonicSolidSource All five platonic solids are displayed.
Point Point vtkPoints
Polygon Polygon vtkPolygon
Pyramid Pyramid vtkPyramid
PolyLine PolyLine vtkPolyLine This example demonstrates how to create a polygon through several ordered points.
Quad Quad vtkQuad
RegularPolygonSource Regular Polygon vtkRegularPolygonSource
Sphere Sphere vtkSphereSource
Triangle Triangle vtkTriangle
TriangleStrip Triangle strip vtkTriangleStrip
Tetrahedron Tetrahedron vtkTetra
Vertex Vertex vtkVertex
PointSource Display vtkPointSource vtkPointSource
TextActor Display text with vtkTextActor vtkTextActor 2D "HUD-type" text
DataSetSurface vtkDataSetSurfaceFilter vtkDataSetSurfaceFilter

Parametric Objects

Example Name VTK Classes Demonstrated Description
ParametricObjects Create and display a parametric object Uncomment the object that you wish to be displayed.
ParametricObjectsDemo 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
Sphere Create a sphere vtkSphere Demonstrate sampling of a sphere implicit function
Quadric Create an ellipsoid vtkQuadric Create an ellipsoid using an implicit quadric
Boolean Boolean two implicit functions vtkImplicitBoolean Demonstrate booleans of two different implicit functions

Working with PolyData

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

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

Outline Draw an outline box around an object vtkOutlineFilter
RotationAroundLine Rotation around a line with RotateWXYZ vtkTransformPolyDataFilter
TriangleCorners Write the corners of a triangle to a file vtkXMLPolyDataWriter
TriangleCornerVertices Write the corners of a triangle to a file (+vertices) vtkCellArray
TriangleColoredPoints Write a triangle with colored points vtkUnsignedCharArray
ColoredTriangle Write a colored triangle vtkTriangle
SolidColoredTriangle Write a solid colored triangle vtkTriangle
WriteTriangleToFile Write a triangle to a file vtkTriangle
IterativeClosestPoints Iterative Closest Points (ICP) vtkIterativeClosestPointTransform
MeshLabelImage Mesh a label image and write cell info to file vtkDiscreteMarchingCubes
MeshLabelImageColor Mesh a label image, smooth it and colour it according to the smoothing error vtkDiscreteMarchingCubes
FilledPolygon Get a filled polygon from vtkCutter vtkCutter
DottedLine Create a dotted line vtkActor::GetProperty::SetLineStipplePattern
RuledSurfaceFilter Create a surface between lines vtkRuledSurfaceFilter
SubdivisionFilters Smooth meshgrid vtkLoopSubdivisionFilter vtkButterflySubdivisionFilter
py Manually construct a cube vtkPolyData
LineOnMesh Draw a line along a meshgrid vtkCellLocator, vtkParametricSpline
PolyDataContourToImageData Generate a binarized image from a closed contour vtkLinearExtrusionFilter,vtkPolyDataToImageStencil
PolyDataToImageDataStencil Convert polydata to imagedata and mask imagedata vtkPolyDataToImageStencil
py WarpVector vtkLine, vtkDoubleArray, vtkPolyData, vtkWarpVector This example warps/deflects a line.
CombinePolyData Combine multiple PolyData vtkAppendPolyData This example combines Polydata objects, and displays the result to the screen.
BooleanOperationPolyDataFilter Computes boolean operation of two spheres vtkBooleanOperationPolyDataFilter This example performs a boolean operation (Intersection, Union, Difference) of two PolyData
py 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 vtkImplicitPolyDataDistance

Working with 3D Data

Example Name VTK Classes Demonstrated Description
ExtractSelection Extract selection points vtkExtractSelection
ExtractSelectionCells 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
vtkRectilinearGrid rectilinear grid vtkRectilinearGrid create a rectilinear grid

Working with Meshes

This section includes examples of manipulating meshes.

Example Name VTK Classes Demonstrated Description
vtkClipDataSetWithPolydata 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 Screenshot vtkWindowToImageFilter
vtkVersion Check VTK version vtkVersion
vtkCutter vtkCutter vtkCutter
vtkImplicitDataSet vtkImplicitDataSet vtkImplicitDataSet Clip one data set with another
vtkWithNumpy Using Numpy n/a
Variant vtkVariant vtkVariant
BackgroundImage Background Image vtkJPEGReader, vtkImageCanvasSource2D, vtkImageActor, vtkSuperquadricSource

Visualization

Example Name VTK Classes Demonstrated Description
AssignColorsFromLUT 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.
ElevationBandsWithGlyphs 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.
CurvatureBandsWithGlyphs 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.
HardwareSelector Get a list of the visible triangles vtkHardwareSelector
QuadraticSurface Display a quadratic surface vtkQuadric
PointSize PointSize vtkActor::GetProperty()::SetPointSize
ColorActor Color an Actor vtkActor::GetProperty()::SetColor
UnstructuredTransientVolumeRendering Unstructured Transient Volume Rendering vtkUnstructuredGridVolumeRayCastMapper
WindowTitle Change the title of the render window vtkRenderWindow::SetWindowName
Animation Animation vtkTimerCallback
MultipleViewports Create a single render window with muliple viewports vtkRenderer::SetViewport
InteractorStyleTrackballCamera InteractorStyleTrackBallCamera vtkInteractorStyleTrackBallCamera
InteractorStyleTrackballActor InteractorStyleTrackBallActor vtkInteractorStyleTrackBallActor
Camera Camera vtkCamera
vtkTextSource Create Text vtkTextSource
ClampGlyphSizes Clamp glyph sizes vtkGlyph3D Use vtkGlyph3D with ClampingOn to limit glyph sizes
GlyphTable Use a glyph table vtkGlyph3D Vary the shapes of glyphed points using a glyph table
NamedColors Named colors vtkNamedColors Demonstrates how to use the vtkNamedColor class
NamedColorPatches Named color patches vtkNamedColors Creates a HTML file called VTKNamedColorPatches.html showing the available colors in vtkNamedColors.
ProgGlyph Programmable glyphs vtkProgrammableGlyphFilter Vary the shapes of glyphed points using a programmable glyph filter
SphereTexture Apply a texture to a sphere vtkTextureMapToSphere Apply an ImageData texture to an sphere
CubeAxesActor Display three orthogonal axes with labels vtkCubeAxesActor
Streamlines Stream Lines vtkStreamLine Seed streamlines with vectors from a structured grid

Working with vtkImageData

Example Name VTK Classes Demonstrated Description
WriteReadVtkImageData Write and read vtkImageData vtkImageData, vtkXMLImageDataReader, vtkXMLImageDataWriter
ImageWeightedSum Summing images vtkImageWeightedSum
SumVTKImages 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 Read an ExodusII file vtkExodusIIReader A simple script for reading and viewing ExodusII data interactively.

Graphs

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

User Interaction

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

Infovis

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

Geovis

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

Widgets

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