Mayavi and VTK pipelines
Mayavi uses VTK for all its visualization needs. A pipeline concept underlies all the visualization in VTK. However, it is important to note that the pipeline used by Mayavi does not correspond to the VTK pipeline creating the visualization: the layout is different, the objects are not the same, and there are more nodes in a VTK pipeline. The two pipelines share some similarities, but in this section, we are only concerned by the Mayavi pipeline.
Every visualization created in Mayavi is constructed with a pipeline, although the construction of the pipeline may be hidden from the user:
Let us study the pipeline created by the mlab.plot3d function to represent lines:
import numpy as np
phi = np.linspace(0., 2*np.pi, 1000)
x = np.cos(6*phi)*(1 + .5*np.cos(11*phi))
y = np.sin(6*phi)*(1 + .5*np.cos(11*phi))
z = .5*np.sin(11*phi)
from mayavi import mlab
surface = mlab.plot3d(x, y, z, np.sin(6*phi), tube_radius=0.025, colormap='Spectral', opacity=.5)
The mlab.plot3d function first creates a source made of points connected by lines. Then it applies the Stripper filter, which transforms this succession of lines in a ‘strip’. Second, a Stripper filter is applied: from the ‘strip’ it creates tubes with a given radius. Finally, the Surface module is applied to display the surface of the tubes. The surface object returned by the mlab.plot3d function is that final Surface module.
Let us have a look at the data in the pipeline before the tube filter was applied. First we retrive the Stripper filter:
stripper = surface.parent.parent.parent
Then we apply on it a Surface module to represent the strip:
lines = mlab.pipeline.surface(stripper, color=(0, 0, 0))
All the properties of the different steps can be adjusted in the pipeline view. In addition, they correspond to attributes on the various objects:
>>> tubes = surface.parent.parent
>>> tubes.filter.radius
0.025000000000000001
The names in the dialogs of the various properties gives hints to which attributes in the objects they correspond to. However, it can be fairly challenging to find this correspondance. We suggest to use the record feature for this purpose.