File: mayavi_objects.rst

package info (click to toggle)
mayavi2 4.8.3-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 21,892 kB
  • sloc: python: 49,447; javascript: 32,885; makefile: 129; fortran: 60
file content (349 lines) | stat: -rw-r--r-- 12,464 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349

Objects populating the Mayavi pipeline
========================================

.. currentmodule:: mayavi.core.api

Here we give a brief description of the key objects in the Mayavi pipeline.

.. image:: images/pipeline_and_scene.jpg
    :align: center


.. note::

    Given a Mayavi object, a simple way to see what important attribute
    is, display it to call it's ``print_traits()``. Note that, for
    certain objects, when used in IPython, this can cause a segfault, due
    to threading problems in IPython.

Scene
------

====================== ========================================================
Key attributes
====================== ========================================================
``scene``		a ``TVTKScene`` (``tvtk.pyface.tvtk_scene``) 
			object which is where all the rendering occurs.

 ``children``		a list of ``Source`` objects.
====================== ========================================================

The ``Scene`` class is defined in the ``mayavi.core.scene`` module.

.. seealso:: 

    API reference for the :class:`Scene` class. 

Source
--------

All the data sources, file readers, Parametric surface etc. are
subclasses of the ``Source`` class.

====================== ========================================================
Key attributes
====================== ========================================================
``children``		a list of either ``Modules`` or ``Filters``

``outputs``		``List`` of outputs produced by the source. These are 
			TVTK datasets, that are explained in 
			the section :ref:`data-structures-used-by-mayavi`.
====================== ========================================================

The ``Source`` class is defined in the ``mayavi.core.source`` 
module.  

.. seealso:: 

    API reference for the :class:`Source` class.

Filter
--------

All the ``Filters`` described in the :ref:`filters` section are
subclasses of this class.

====================== ========================================================
Key attributes
====================== ========================================================
``children``		a list of either ``Modules`` or other ``Filters``.

``inputs``		a ``List`` of input TVTK dataset objects that feed into 
			the filter.

``outputs``		a list of outputs produced by the filter. These are 
			TVTK datasets, that are explained in 
			the section :ref:`data-structures-used-by-mayavi`.
====================== ========================================================
  

====================== ========================================================
Key methods
====================== ========================================================
``setup_pipeline()``	used to create the underlying TVTK pipeline objects if 
			needed.

``update_pipeline()``   called when the upstream pipeline 
			has been changed, i.e. an upstream object fires a 
			``pipeline_changed`` event.

``update_data()``	called when the upstream pipeline 
			has **not** been changed but the data in the
			pipeline has been changed.  This happens when the 
			upstream object fires a ``data_changed`` event.
====================== ========================================================

The filter class is defined in the ``mayavi.core.filter`` module.

.. seealso:: 

    API reference for the :class:`Filter` class.

ModuleManager: Colors and legends node
---------------------------------------

This object is the one called *Colors and legends* in the tree view on
the UI.  The main purpose of this object is to control how data is turned
in colors in the ``Modules`` it manages.  All modules typically will use
a lookup table (LUT) in order to produce a meaningful visualization.
This lookup table is managed by the module manager.

====================== ========================================================
Key attributes
====================== ========================================================
``source``		the ``Source`` or ``Filter`` object that is the input
			of this object.

``children``		a list of the ``Modules`` it manages.

``scalar_lut_manager``  an instance of a ``LUTManager`` which 
			basically manages the color mapping from
			scalar values to colors on the visualizations.  
			This is basically a mapping from scalars to colors.

``vector_lut_manager`` an instance of a ``LUTManager`` which manages the 
		       color mapping from vector values to colors on the 
		       visualizations.

``lut_data_mode``      'auto', 'point data' and 'cell data'.
			Specifies the data type to use for the LUTs.  This can 
			be changed inbetween .  Changing this setting will 
			change the data range and name of the lookup
			table/legend bar.  If set to 'auto' (the default), 
			it automatically looks for cell and point data with 
			point data being preferred over cell data and 
			chooses the one available. If set to 'point data' it 
			uses the input point data for the LUT and if set to 
			'cell data' it uses the input cell data.
====================== ========================================================

This class is defined in the ``mayavi.core.module_manager``
module.

.. seealso:: 

    API reference for the :class:`ModuleManager` class.

Module
-------

These objects are the ones that typically produce a visualization on the
scene.  All the modules defined in the :ref:`modules` section are
subclasses of this.

A module is typically returned by the mlab 
:ref:`3D plotting functions <mlab_plotting_functions>`.

====================== ========================================================
Key attributes
====================== ========================================================
``module_manager``	The ``ModuleManager`` instance that controls the 
			colormaps and the legends of this ``Module``

``actor``		The TVTK actor of the modules, in other words
			the object displayed in the scene. This is where
			you will have the properties such as scaling, or
			GL material properties.

``components``		a list of various reusable components that are used 
			by the module.  These usually are never used directly 
			by the user.  However, they are extremely useful 
			when creating new modules.  A ``Component`` is
			basically a reusable piece of code that is used by 
			various other objects.  For example, almost every 
			``Module`` uses a TVTK actor, mapper and property.  
			These are all "componentized" into a reusable 
			`Actor` component that the modules use.  Thus,
			components are a means to promote reuse between 
			mayavi pipeline objects.
====================== ========================================================

====================== ========================================================
Key methods
====================== ========================================================
``setup_pipeline()``	used to create the underlying TVTK pipeline objects if 
			needed.

``update_pipeline()``   called when the upstream pipeline 
			has been changed, i.e. an upstream object fires a 
			``pipeline_changed`` event.

``update_data()``	called when the upstream pipeline 
			has **not** been changed but the data in the
			pipeline has been changed.  This happens when the 
			upstream object fires a ``data_changed`` event.
====================== ========================================================


Defined in the ``mayavi.core.module`` module.

.. seealso:: 

    API reference for the :class:`Module` class.

Engine
--------

The Mayavi engine is the central object dealing with life-cycle of
visualization objects and scene, as well as connecting and updating the
pipeline. It is at the root of the pipeline and is not displayed in the
pipeline view.

For contextual operation, the engine has the notion of a 'current object'
and a 'current scene' and features several methods that let one add a
``Filter/Source/Module`` instance to it. The contextual operations are
important in a menu-driven graphical user interface. 

It allows one to create new scenes and delete them.  Also has methods to
load and save the entire visualization.

.. currentmodule:: mayavi

When using mlab, the engine used by mlab can be retrieved using
:func:`mlab.get_engine`.

.. currentmodule:: mayavi.core.api

====================== ========================================================
Key attributes
====================== ========================================================
``scenes``		a list of ``Scene`` objects.

``current_object``	the object on which contextual operations, such
			as ``add_module`` will apply.

``current_scene``	the scene in which data sources will be added by
			default.

``current_selection``  The object selected in the pipeline view.
====================== ========================================================

====================== ========================================================
Key methods
====================== ========================================================
``new_scene()``		this is the method called to create a new scene.
			Subclasses override this method.
====================== ========================================================


====================== ========================================================
Important sub-classes
====================== ========================================================
``EnvisageEngine``	defined in the 
			``mayavi.plugins.envisage_engine``
			module. It is the subclass of
			used in the ``mayavi2`` application.

``OffScreenEngine``	defined in the
			``mayavi.core.off_screen_engine`` module. 
			It creates scenes that are not displayed on
			screen by default.

``NullEngine``		defined in the
			``mayavi.core.null_engine`` module.
			With this engine, visualization objects are
			not added to a scene, and thus cannot be rendered. 
			This engine is useful for testing and pure-data 
			handling use of Mayavi's data structures.
====================== ========================================================

.. image:: images/design2c.jpg
   :alt: The ``Engine`` object.
   :align: center

The `Engine` base class is defined in the ``mayavi.engine`` module.

.. seealso:: 

    API reference for the :class:`Engine` class.

Base class: PipelineBase
--------------------------

The ``PipelineBase`` is the base class for all
objects in the mayavi pipeline except the ``Scene`` and ``Engine``
(which really isn't *in* the pipeline but contains the pipeline).
Defined in the ``mayavi.core.pipeline_base`` module.
Derives from ``Base`` which merely abstracts out common
functionality.  

====================== ========================================================
Key attributes
====================== ========================================================
``pipeline_changed``	This is an ``Event`` Trait: it can only be
			assigned to and determines when the pipeline has
			been changed. Therefore, if one does::

				object.pipeline_changed = True 

			then the ``pipeline_changed`` event is fired.
			Objects downstream of ``object`` in the pipeline
			are automatically setup to listen to events from
			an upstream object and will call their
			``update_pipeline`` method.  

``data_changed``	Similarly, if the ``data_changed`` event is fired 
			then downstream objects will automatically call 
			their ``update_data`` methods.

``outputs``		a list of outputs produced by the object.

``scene``		the scene to which the object is attached.

``visible``		a boolean that toggle the Hide/Show status of the
			object and its downstream pipeline.
====================== ========================================================

====================== ========================================================
Key methods
====================== ========================================================
``remove()``		can be used to remove the object (if added)
			from the mayavi pipeline.
====================== ========================================================

.. seealso:: 

    API reference for the :class:`PipelineBase` class.

Class hierarchy
---------------------

The following figures show the class hierarchy of the various objects
involved.

.. image:: images/design2a.jpg
   :alt: Basic object hierarchy
   :align: center

*This hierarchy depicts the ``Base`` object, the ``Scene``,
``PipelineBase`` and the ``ModuleManager``.*

.. image:: images/design2b.png
   :alt: More object hierarchy
   :align: center

*This hierarchy depicts the ``PipelineBase`` object, the ``Source``,
``Filter``, ``Module`` and the ``Component``.*