Pipeline base objects

This is an API reference of the base classes of the pipeline objects. Please refer to section Advanced use of Mayavi for instructions on how to use them.

Scene

class mayavi.core.api.Scene

Bases: Base

The Mayavi scene class.

add_child(child)

This method intelligently adds a child to this object in the MayaVi pipeline.

on_mouse_pick(callback, type='point', button='Left', remove=False)

Add a picking callback on mouse click.

When the mouse button is press, object picking is called, and the given callback is invoked with the resulting pick as an argument.

Keyword arguments

Type:

‘point’, ‘cell’, or ‘world’ The picker type used for picking.

Button:

‘Left’, ‘Middle’, or ‘Right’ The mouse button triggering the picking event.

Remove:

boolean If remove is True, the callback is removed from the list of callbacks.

Returns picker: a tvtk picker

The picker that will be used to do the picking.

Notes

The callback must accept one argument: the TVTK picker.

The same callback can be added multiple times.

remove()

Remove ourselves from the mayavi pipeline.

remove_child(child)

Remove specified child from our children.

start()

This is invoked when this object is added to the mayavi pipeline.

stop()

Invoked when this object is removed from the mayavi pipeline.

tno_can_add(node, add_object)

Returns whether a given object is droppable on the node.

tno_drop_object(node, dropped_object)

Returns a droppable version of a specified object.

Source

class mayavi.core.api.Source

Bases: PipelineBase

Base class for the sources objects in the pipeline.

add_child(child)

This method intelligently adds a child to this object in the MayaVi pipeline.

add_module(module)

Adds a module smartly. If no ModuleManager instances are children, it first creates a new ModuleManager and then adds the module to it. If not it adds the module to the first available ModuleManager instance.

remove_child(child)

Remove specified child from our children.

save_output(**kw)

Save our output (by default the first of our outputs) to the specified filename as a VTK file. Both old style and new style XML files are supported.

start()

This is invoked when this object is added to the mayavi pipeline.

stop()

Invoked when this object is removed from the mayavi pipeline.

tno_can_add(node, add_object)

Returns whether a given object is droppable on the node.

tno_drop_object(node, dropped_object)

Returns a droppable version of a specified object.

Filter

class mayavi.core.api.Filter(**traits)

Bases: Source

Base class for all the Mayavi filters.

setup_pipeline()

Override this method so that it creates its tvtk pipeline.

This method is invoked when the object is initialized via __init__. Note that at the time this method is called, the tvtk data pipeline will not yet be setup. So upstream data will not be available. The idea is that you simply create the basic objects and setup those parts of the pipeline not dependent on upstream sources and filters.

start()

This is invoked when this object is added to the mayavi pipeline. Note that when start is invoked, all the other information for the pipeline should be already set.

stop()

Invoked when this object is removed from the mayavi pipeline. This is where you remove your actors from the scene.

update_data()

Override this method to do what is necessary when upstream data changes.

This method is invoked (automatically) when any of the inputs sends a data_changed event.

update_pipeline()

Override this method so that it updates the tvtk pipeline when data upstream is known to have changed.

This method is invoked (automatically) when the input fires a pipeline_changed event.

ModuleManager

class mayavi.core.api.ModuleManager

Bases: Base

The module manager node (represented as ‘Colors and Legends’).

add_child(child)

This method intelligently adds a child to this object in the MayaVi pipeline.

remove_child(child)

Remove specified child from our children.

start()

This is invoked when this object is added to the mayavi pipeline.

stop()

Invoked when this object is removed from the mayavi pipeline.

tno_can_add(node, add_object)

Returns whether a given object is droppable on the node.

tno_drop_object(node, dropped_object)

Returns a droppable version of a specified object.

update()

Update any internal data.

This is invoked when the source changes or when there are pipeline/data changes upstream.

Module

class mayavi.core.api.Module(**traits)

Bases: PipelineBase

Base class for the Mayavi modules.

add_child(child)

This method intelligently adds a child to this object in the MayaVi pipeline.

setup_pipeline()

Override this method so that it creates the tvtk pipeline.

This method is invoked when the object is initialized via __init__. Note that at the time this method is called, the tvtk data pipeline will not yet be setup. So upstream data will not be available. The idea is that you simply create the basic objects and setup those parts of the pipeline not dependent on upstream sources and filters. You should also set the actors attribute up at this point.

start()

This is invoked when this object is added to the mayavi pipeline. Note that when start is invoked, all the other information for the pipeline should be already set.

stop()

Invoked when this object is removed from the mayavi pipeline.

tno_allows_children(node)

Returns whether chidren of this object are allowed or not.

tno_get_children(node)

Gets the object’s children.

tno_has_children(node)

Returns whether or not the object has children.

update_data()

Override this method so that it flushes the vtk pipeline if that is necessary.

This method is invoked (automatically) when any of the inputs sends a data_changed event.

update_pipeline()

Override this method so that it updates the tvtk pipeline when data upstream is known to have changed.

This method is invoked (automatically) when the input fires a pipeline_changed event.

PipelineBase

class mayavi.core.api.PipelineBase

Bases: Base

Base class for all the Source, Filters and Modules in the pipeline.

add_actors()

Adds self.actors to the scene.

This is typically called when start is invoked. You should avoid calling this unless you know what you are doing.

configure_connection(obj, inp)

Configure topology for vtk pipeline obj.

configure_input(inp, op)

Configure the inp using op.

configure_input_data(obj, data)

Configure the input data for vtk pipeline object obj.

configure_source_data(obj, data)

Configure the source data for vtk pipeline object obj.

get_output_dataset()

Return the output dataset of this object.

get_output_object()

We assume the old pipeline topology. As such we return the first output.

has_output_port()

We assume the old pipeline topology. As such we assume no output_port exists.

remove_actors()

Removes self.actors from the scene.

This is typically called when stop is invoked. You should avoid calling this unless you know what you are doing.

render()

Invokes render on the scene, this in turn invokes Render on the VTK pipeline.

start()

This is invoked when this object is added to the mayavi pipeline. Note that when start is invoked, all the other information for the pipeline should be already set.

stop()

Invoked when this object is removed from the mayavi pipeline.

Engine

class mayavi.core.api.Engine(**traits)

Bases: HasStrictTraits

The Mayavi engine base class.

add_filter(**kw)

Adds a filter to the pipeline at an appropriate point. Adds it to the selected object, or to an object passed as the kwarg obj.

add_module(**kw)

Adds a module to the pipeline at an appropriate point. Adds it to the selected object, or to an object passed through the kwarg obj.

add_scene(scene, name=None)

Add given scene (a pyface.tvtk.scene.Scene instance) to the mayavi engine so that mayavi can manage the scene. This is used when the user creates a scene. Note that for the EnvisageEngine this is automatically taken care of when you create a new scene using the TVTK scene plugin.

Parameters:

scene - pyface.tvtk.scene.Scene

The scene that needs to be managed from mayavi.

name - str

The name assigned to the scene. It tries to determine the name of the scene from the passed scene instance. If this is not possible it defaults to ‘Mayavi Scene’.

add_source(**kw)

Adds a source to the pipeline. Uses the current scene unless a scene is given in the scene keyword argument.

close_scene(**kw)

Given a scene created from new_scene, this method closes it and removes the scene from the list of scenes we manage.

Parameters:

scene - pyface.tvtk.scene.Scene or an object that holds a reference to a pyface.tvtk.scene.Scene in a scene attribute.

dialog_view()

Default dialog view for Engine objects.

get_viewer(scene)

Return the viewer associated with a given scene.

Parameters:

scene - An mayavi.core.scene.Scene instance.

load_visualization(**kw)

Given a file/file name this loads the visualization.

new_scene(**kw)

Create or manage a new VTK scene window. If no viewer argument is provided, the method creates a new viewer using self.scene_factory. If self.scene_factory is None then it creates an ivtk viewer. This code requires that the viewer has a scene attribute/trait that is a pyface.tvtk.scene.Scene. It also works best if the viewer supports closing and activated events.

The method returns the created viewer.

Parameters:

viewer - The viewer object, if None, one is created for you.

name - The name attribute of the viewer

**kwargs - The extra keyword arguments are passed along to the scene factory.

open(**kw)

Open a file given a filename if possible in either the current scene or the passed scene.

record(msg)

This is merely a convenience method to record messages to the script recorder.

remove_scene(**kw)

Remove a given scene (a pyface.tvtk.scene.Scene instance) from the mayavi engine if it is already being managed by mayavi. Note that for the EnvisageEngine this is automatically taken care of when you close a scene started using the TVTK scene plugin.

Parameters:

scene - pyface.tvtk.scene.Scene

The scene that needs to be removed from mayavi.

save_visualization(**kw)

Given a file or a file name, this saves the current visualization to the file.

start()

This is called by the plugin when the plugin actually starts.