This page is not the main source of documentation. You are invited to refer to the Mayavi2 home page for up-to-date documentation on TVTK. In particular, bear in mind that if you are looking for a high-level Python 3D plotting library, Mayavi also provides the right API, and can be embedded (see the user guide). |
What is tvtk?
tvtk is a traits enabled version of VTK for 3D graphics and visualization.
It provides an exact match to the VTK objects, but with a Pythonic feel, unlike Mayavi which aims to provide new APIs
Most important features are
- All VTK classes are wrapped.
- Support for traits.
- Elementary pickle support.
- Pythonic feel.
- Handles numpy/Numeric/numarray arrays/Python lists transparently.
- Support for a pipeline browser, ivtk
- High-level mlab module.
- Envisage plugins for a tvtk scene and the pipeline browser.
- MayaVi2 is built on top of tvtk
See the enthought TVTK page for more details, in particular the tvtk introduction.
tvtk examples
cone
The following example displays a cone which can be rotated/scaled/... with the mouse. Simple_tvtk_cone.py
quadrics
A more interesting example is the generation of some contour surfaces of an implicit function. Vis_quad.py
This displays the following scene on screen and also saves it to a file.
ivtk
The module tools.ivtk makes VTK/TVTK easier to use from the Python interpreter. For example, start IPython with:
ipython -wthread
(if you have both wxPython 2.4 and wxPython 2.6 installed you will need a recent IPython and do ipython -wthread -wxversion 2.6).
Then you can paste the following lines:
1 from enthought.tvtk.tools import ivtk
2 from enthought.tvtk.api import tvtk
3 # Create a cone:
4 cs = tvtk.ConeSource(resolution=100)
5 mapper = tvtk.PolyDataMapper(input=cs.output)
6 actor = tvtk.Actor(mapper=mapper)
7
8 # Now create the viewer:
9 v = ivtk.IVTKWithCrustAndBrowser(size=(600,600))
10 v.open()
11 v.scene.add_actors(actor) # or v.scene.add_actor(a)
You can then explore the visualization pipeline and modify any settings.
For creating the viewer there are different options:
- v = ivtk.viewer() - this one does not need the v.open() and the size=(600,600)
- v = ivtk.IVTK()
- v = ivtk.IVTKWithCrust()
- v = ivtk.IVTKWithBrowser()
- v = ivtk.IVTKWithCrustAndBrowser)
For viewers with Crust you can use the python command line window to modify the pipeline.