Introduction

Here's the real stuff

You'll be learned here how you can use the various modules in MayaVi2.

Note: Some modules can't be added for any type of data set. Some work only for StructuredGrid or StructuredPoints for example (see http://www.vtk.org/pdf/file-formats.pdf for more information about VTK data type). It will be specified each time is needed.

Note2: In the MayaVi2 tree view, the "Main Modules" (called "Modules") have been separated from the "Basic Modules" loading the ModuleManager. Of coutse, you can load all your modules and filters without using the ModuleManager.

ImagePlaneWidget/ScalarCutPlane/SliceUnstructuredGrid module

The simpliest (and easiest, but not the most impressive ) way to display 3D data is doubtless to slice it on some planes, normal to Ox, Oy or Oz axis, or oblique.

One of the modules you can use to do this is called ScalarCutPlane. It works for any data.

Another module that slices grid is called SliceUnstructuredGrid. As it is called, it should work only for unstructured grids. But, because it has been tested on a structured grid, even MayaVi2 complains about it with a warning message, it "works" even for structured grid (happily for our example )

In fact, its interest is not really slicing grid, but even more showing the structure of your mesh, i.e. your mesh cells. Thus you can see if there is not any problem (holes, etc.).

GridPlane/StructuredGridOutline module

Using GridPlane module cuts also your grid, but quite differently from ScalarCutPlane module. You can't get normal plane only along Ox, Oy and Oz axis, and it works only for structured grids. But unlike ScalarCutPlane module, which always cuts your mesh in a plane, GridPlane cuts through your mesh: if it's a conformal mesh, the cut won't be a plane, but something following the curvature of your mesh.

The StructuredGridOutline module does the same as Outline module, but for conformal mesh.

To illustrate how can we use these modules, let's consider a example provided in the VTKData directory, combxyz.bin & combq.bin files (Plot3D format) from the tarball vtkdata-5.0.3.tar.gz you can download here.

This yelds the same scene as previous, of course, but now, you can control each isovalue separately.

The funny part is that you can set the minimum/maximum contour for Surface or Contours for IsoSurface in "real-time", moving the slide-bar. This is a very useful feature. And can render very nice "dynamic" scene !

Volume module

It is still quite experimental for me (you can set a lot of parameters), so this section will be very short

Note that the Volume module has a "Color Transfer Function", which is quite different from the LookUp Table used by the others modules.

The rendered scene should look like this (thanks to Prabhu to have made the CTF similar to the LUT) :

Vectors/Glyph/VectorCutPlane/WarpVectorCutPlane module

Until now, we have only dealt with scalar values. You can also display values as vectors. You can use one of the three following modules:

Vectors module: scale and color are set by vectors data, i.e. a 3D array vectors field;

Glyph module: scale and color are set by scalar data;

VectorCutPlane module; in this case, vectors are not diplayed in the whole volume, but only on cutplanes, as ScalarCutPlane module does with scalar values.

You can set several parameters for these modules, in concern with arrows shape, etc.

First, it depends of the number of points in your volume, but you are advised to decimate your data. If you don't, you should see nothing all but a lot of arrows everywhere, and thus loss the pertinent information. You can choose a randomly, or not, decimation.

Second, you can choose the shape of your vectors, amongst the following list: 2D Glyph or Arrow, Cone, Cylinder, Sphere and Cube 3D vector shapes.

Third, you can set some parameters for the choosen shape. For example, using the Arrow shape, you can set the following properties for the shaft and the tip:

the shaft radius;

the shaft resolution (number of polygons);

the tip length;

the tip radius;

the tip resolution;

You can also set the vector position, between "tail", "centered" and "head", the scale mode, the color mode, the scale factor (how big your vectors will be displayed), etc.

Let's see now how one can do this.

First, import the required module.

For Vectors module,

fromenthought.mayavi.modules.vectorsimportVectors

For Glyph module,

fromenthought.mayavi.modules.glyphimportGlyph

For VectorCutPlane module,

fromenthought.mayavi.modules.vector_cut_planeimportVectorCutPlane

In fact, you will see that these three modules use the same objects and methods. Only default values differ.

For instance, for Vectors module, you can type:

v=Vectors()script.add_module(v)v.glyph.mask_input_points=True# we want to decimate our data...v.glyph.mask_points.on_ratio=100# ...by a ratio of 100v.glyph.mask_points.random_mode=True# I want a randomly decimationv.glyph.glyph_source=v.glyph.glyph_list[1]# I like ArrowSource ;-)# following values are the default values: tweak your own !v.glyph.glyph_source.shaft_radius=0.03v.glyph.glyph_source.shaft_resolution=6v.glyph.glyph_source.tip_length=0.35v.glyph.glyph_source.tip_radius=0.1v.glyph.glyph_source.tip_resolution=6v.glyph.glyph.scale_factor=10v.glyph.glyph_position='tail'v.glyph.scale_mode='scale_by_vector'v.glyph.color_mode='color_by_vector'### if you use Glyph module, here are the default values# v.glyph.glyph_position = 'center'# v.glyph.scale_mode = 'scale_by_scalar'# v.glyph.color_mode = 'color_by_scalar'

If we consider, once again ;-), the same 3D data already shown before, but this time, with vectors instead of scalars data, the scene should look like this:

For the VectorCutPlane module, you can set the same properties as above plus the properties of the ScalarCutPlane module such as implicit_plane.normal, implicit_plane.origin, implicit_plane.widget.enabled, etc:

vcp=VectorCutPlane()script.add_module(vcp)vcp.glyph.mask_input_points=Truevcp.glyph.mask_points.on_ratio=5vcp.glyph.mask_points.random_mode=Falsevcp.glyph.glyph_source=vcp.glyph.glyph_list[1]vcp.glyph.glyph_source.shaft_radius=0.03vcp.glyph.glyph_source.shaft_resolution=6vcp.glyph.glyph_source.tip_length=0.35vcp.glyph.glyph_source.tip_radius=0.1vcp.glyph.glyph_source.tip_resolution=6vcp.glyph.glyph.scale_factor=20vcp.glyph.glyph_position='tail'vcp.glyph.scale_mode='scale_by_vector'vcp.glyph.color_mode='color_by_vector'vcp.implicit_plane.normal=(1,0,0)# set normal to Ox axisvcp.implicit_plane.origin=(10,25,25)# set origin to (i=10, j=25, k=25) for a structured gridvcp.implicit_plane.widget.enabled=Truevcp.actor.property.diffuse=0.0# set some color propertiesvcp.actor.property.ambient=1.0# vcp.actor.property.opacity=1.0#vcp.module_manager.vector_lut_manager.data_range=[0,1]

This should render this scene:

You can also warp a cutplane according to the vectors field. To do this, you have to load another module, instead of VectorCutPlane, called WarpVectorCutPlane.

wvcp=WarpVectorCutPlane()script.add_module(wvcp)wvcp.implicit_plane.normal=(1,0,0)# set normal to Ox axiswvcp.implicit_plane.origin=(10,25,25)# set origin to (i=10, j=25, k=25) for a structured gridwvcp.implicit_plane.widget.enabled=Truewvcp.compute_normals=Truewvcp.warp_vector.filter.scale_factor=10

You should get this (compare to the warped surface with ScalarCutPlane module):

Streamline module

Another way to display vectors fields is to use the Streamline module.

We consider here others Plot3D files: postxyz.bin & postq.bin that you can download here. You can find some screenshots using these files on the VTK home page here.

You can set several parameters for this module: for instance, the type of the streamline (tube, ribbon or line) with its properties, and the "seed".