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: mayavi.core.base.Base

The Mayavi scene class.

Traits:

scene : Instance(TVTKScene)

children : List(Source)

name : Str(‘TVTK Scene’)

icon : Str(‘scene.ico’)

type : Str(‘ scene’)

view : View(Group(Item()))

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: mayavi.core.pipeline_base.PipelineBase

Base class for the sources objects in the pipeline.

Traits:

children : List(Base)

icon : ‘source.ico’

type : Str(‘ data source’)

input_info : PipelineInfo()

output_info : PipelineInfo()

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(*args, **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: mayavi.core.source.Source

Base class for all the Mayavi filters.

Traits:

inputs : List(PipelineBase)

icon : Str(‘filter.ico’)

type : Str(‘ filter’)

input_info : PipelineInfo()

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: mayavi.core.base.Base

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

Traits:

source : Instance(Base)

children : List(Module)

lut_data_mode : Trait(‘auto’, TraitPrefixList(LUT_DATA_MODE_TYPES))

scalar_lut_manager : Instance(LUTManager)

vector_lut_manager : Instance(LUTManager)

name : Str(‘Colors and legends’)

icon : Str(‘modulemanager.ico’)

type : Str(‘ colors and legends’)

input_info : PipelineInfo()

output_info : PipelineInfo()

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: mayavi.core.pipeline_base.PipelineBase

Base class for the Mayavi modules.

Traits:

module_manager : Instance(‘mayavi.core.module_manager.ModuleManager’)

components : List()

icon : Str(‘module.ico’)

type : Str(‘ module’)

input_info : PipelineInfo()

output_info : PipelineInfo()

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: mayavi.core.base.Base

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

Traits:

outputs : List()

actors : List()

widgets : List()

input_info : Instance(PipelineInfo)

output_info : Instance(PipelineInfo)

pipeline_changed : Event()

data_changed : Event()

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: traits.has_traits.HasStrictTraits

The Mayavi engine base class.

Traits:

scenes : List(Scene)

children_ui_list : Property()

name : Str(‘Mayavi Engine’)

current_scene : Property(Instance(Scene))

current_object : Property()

current_selection : Property()

started : Event()

scene_factory : Callable(viewer_factory)

running : Bool(False)

closed : Event()

recorder : Instance(Recorder)

current_selection_view : View(Item())

add_filter(*args, **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(*args, **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.

add_source(*args, **kw)

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

close_scene(*args, **kw)

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

dialog_view()

Default dialog view for Engine objects.

get_viewer(scene)

Return the viewer associated with a given scene.

load_visualization(*args, **kw)

Given a file/file name this loads the visualization.

new_scene(*args, **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.

open(*args, **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(*args, **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.

save_visualization(*args, **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.