This is an archival dump of old wiki content --- see scipy.org for current material.
Please see http://scipy-cookbook.readthedocs.org/

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

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.

attachment:vis_quad.png

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.

attachment:ivtk_example.png

For creating the viewer there are different options:

For viewers with Crust you can use the python command line window to modify the pipeline.


CategoryCookbook

SciPy: Cookbook/MayaVi/tvtk (last edited 2015-10-24 17:48:23 by anonymous)