~ubuntu-branches/ubuntu/hardy/mayavi2/hardy-backports

« back to all changes in this revision

Viewing changes to enthought.mayavi/enthought/mayavi/tools/modules.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2008-07-25 09:03:34 UTC
  • mfrom: (2.2.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080725090334-1hbb9fn8b3as5qy0
Tags: 2.2.0-1~hardy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
# Copyright (c) 2007, Enthought, Inc. 
11
11
# License: BSD Style.
12
12
 
13
 
from enthought.traits.api import Trait, CArray, Instance, CFloat, Enum, \
14
 
    Any, false, TraitTuple, Range
 
13
from enthought.traits.api import Trait, CArray, Instance, CFloat, \
 
14
    Any, false, TraitTuple, Range, Bool
15
15
from pipe_base import PipeFactory, make_function
16
16
import enthought.mayavi.modules.api as modules
17
17
from enthought.tvtk.api import tvtk
19
19
from enthought.mayavi.core.lut_manager import lut_mode_list
20
20
import tools
21
21
 
 
22
__all__ = [ 'vectors', 'glyph', 'streamline', 'volume', 'surface',
 
23
    'isosurface', 'contoursurface', 'image', 'imageplanewidget',
 
24
    'scalarcutplane', 'contourgridplane', 'customgridplane', 'gridplane',
 
25
    'hyperstreamline', 'sliceunstructuredgrid', 'structuredgridoutline',
 
26
    'tensorglyph', 'vectorcutplane', 'warpvectorcutplane',
 
27
]
 
28
 
22
29
##############################################################################
23
30
# Abstract module classes
24
31
##############################################################################
33
40
    def _color_changed(self):
34
41
        if self.color:
35
42
            self._target.actor.property.color = self.color
36
 
            if hasattr(self._target.actor.mapper, "scalarvisibility"):
 
43
            if hasattr(self._target.actor.mapper, "scalar_visibility"):
37
44
                self._target.actor.mapper.scalar_visibility = False
38
45
            if hasattr(self._target, "property"):
39
46
                self._target.property.color = self.color
 
47
    
 
48
    opacity = CFloat(1.,
 
49
                help="""The overall opacity of the vtk object.""")
40
50
 
 
51
    def _opacity_changed(self):
 
52
        try:
 
53
            self._target.actor.property.opacity = self.opacity
 
54
        except AttributeError:
 
55
            try:
 
56
                self._target.property.opacity = self.opacity
 
57
            except AttributeError:
 
58
                pass
41
59
 
42
60
##############################################################################
43
61
class DataModuleFactory(ModuleFactory):
132
150
        else:
133
151
            assert type(self.contours) == int, \
134
152
                            "The contours argument must be an integer"
135
 
            assert self.contours > 1, "The contours argument must be positiv"
 
153
            assert self.contours > 0, "The contours argument must be positive"
136
154
            self._target.contour.set(auto_contours=True,
137
155
                                number_of_contours=self.contours)
138
156
        if hasattr(self._target, 'enable_contours'):
175
193
 
176
194
    def _mode_changed(self):
177
195
        v = self._target
 
196
        # Workaround for different version of VTK:
 
197
        if hasattr(v.glyph.glyph_source, 'glyph_source'):
 
198
            g = v.glyph.glyph_source
 
199
        else:
 
200
            g = v.glyph
178
201
        if self.mode == 'point':
179
 
            v.glyph.glyph_source = tvtk.PointSource(radius=0,
180
 
                                                    number_of_points=1)
 
202
            g.glyph_source = tvtk.PointSource(radius=0, number_of_points=1)
181
203
        else:
182
 
            v.glyph.glyph_source = v.glyph.glyph_list[self.mode_]
 
204
            g.glyph_source = g.glyph_list[self.mode_]
183
205
        if self.mode_ == 0:
184
 
            v.glyph.glyph_source.glyph_type = self.mode[2:]
 
206
            g.glyph_source.glyph_type = self.mode[2:]
 
207
 
185
208
 
186
209
vectors = make_function(VectorsFactory)
187
210
 
232
255
 
233
256
streamline = make_function(StreamlineFactory)
234
257
 
 
258
##############################################################################
 
259
class VolumeFactory(DataModuleFactory):
 
260
    """Applies the Volume mayavi module to the given VTK data object."""
 
261
 
 
262
    _target = Instance(modules.Volume, ())
 
263
 
 
264
volume = make_function(VolumeFactory)
 
265
 
235
266
 
236
267
##############################################################################
237
268
class SurfaceFactory(DataModuleFactory):
267
298
        self._contours_changed()
268
299
 
269
300
 
270
 
isosurface = make_function(IsoSurfaceFactory)
 
301
contoursurface = make_function(ContourSurfaceFactory)
 
302
 
 
303
##############################################################################
 
304
class ImageActorFactory(DataModuleFactory):
 
305
    """Applies the ImageActor mayavi module to the given VTK data object."""
 
306
    _target = Instance(modules.ImageActor, ())
 
307
 
 
308
    interpolate = Bool(True, adapts='actor.interpolate',
 
309
                       desc="""if the pixels in the image are to be
 
310
                       interpolated or not.""")
 
311
 
 
312
    opacity = Range(0.0, 1.0, 1.0, adapts='actor.opacity',
 
313
                    desc="""the opacity of the image.""")
 
314
 
 
315
 
 
316
image = make_function(ImageActorFactory)
 
317
 
 
318
 
 
319
##############################################################################
 
320
class ImagePlaneWidgetFactory(DataModuleFactory):
 
321
    """Applies the ImagePlaneWidget mayavi module to the given VTK data 
 
322
        object."""
 
323
    _target = Instance(modules.ImagePlaneWidget, ())
 
324
 
 
325
 
 
326
imageplanewidget = make_function(ImagePlaneWidgetFactory)
 
327
 
 
328
 
 
329
##############################################################################
 
330
class ScalarCutPlaneFactory(DataModuleFactory):
 
331
    """Applies the ScalarCutImagePlane mayavi module to the given VTK data 
 
332
        object."""
 
333
    _target = Instance(modules.ScalarCutPlane, ())
 
334
 
 
335
 
 
336
scalarcutplane = make_function(ScalarCutPlaneFactory)
 
337
 
 
338
 
 
339
##############################################################################
 
340
class ContourGridPlaneFactory(ContourModuleFactory):
 
341
    """Applies the ContourGridPlane mayavi module to the given VTK data
 
342
    object."""
 
343
    _target = Instance(modules.ContourGridPlane, ())
 
344
 
 
345
contourgridplane = make_function(ContourGridPlaneFactory)
 
346
 
 
347
 
 
348
##############################################################################
 
349
class CustomGridPlaneFactory(ContourModuleFactory):
 
350
    """Applies the CustomGridPlane mayavi module to the given VTK data
 
351
    object."""
 
352
    _target = Instance(modules.CustomGridPlane, ())
 
353
 
 
354
customgridplane = make_function(CustomGridPlaneFactory)
 
355
 
 
356
 
 
357
##############################################################################
 
358
class GridPlaneFactory(DataModuleFactory):
 
359
    """Applies the GridPlane mayavi module to the given VTK data object."""
 
360
    _target = Instance(modules.GridPlane, ())
 
361
 
 
362
gridplane = make_function(GridPlaneFactory)
 
363
 
 
364
 
 
365
##############################################################################
 
366
class HyperStreamlineFactory(DataModuleFactory):
 
367
    """Applies the HyperStreamline mayavi module to the given VTK data
 
368
    object."""
 
369
    _target = Instance(modules.HyperStreamline, ())
 
370
 
 
371
hyperstreamline = make_function(HyperStreamlineFactory)
 
372
 
 
373
 
 
374
##############################################################################
 
375
class SliceUnstructuredGridFactory(DataModuleFactory):
 
376
    """Applies the SliceUnstructuredGrid mayavi module to the given VTK data
 
377
    object."""
 
378
    _target = Instance(modules.SliceUnstructuredGrid, ())
 
379
 
 
380
sliceunstructuredgrid = make_function(SliceUnstructuredGridFactory)
 
381
 
 
382
 
 
383
##############################################################################
 
384
class StructuredGridOutlineFactory(DataModuleFactory):
 
385
    """Applies the StructuredGridOutline mayavi module to the given VTK data
 
386
    object."""
 
387
    _target = Instance(modules.StructuredGridOutline, ())
 
388
 
 
389
structuredgridoutline = make_function(StructuredGridOutlineFactory)
 
390
 
 
391
 
 
392
##############################################################################
 
393
class TensorGlyphFactory(DataModuleFactory):
 
394
    """Applies the TensorGlyph mayavi module to the given VTK data object."""
 
395
    _target = Instance(modules.TensorGlyph, ())
 
396
 
 
397
tensorglyph = make_function(TensorGlyphFactory)
 
398
 
 
399
 
 
400
##############################################################################
 
401
class VectorCutPlaneFactory(DataModuleFactory):
 
402
    """Applies the VectorCutPlane mayavi module to the given VTK data object."""
 
403
    _target = Instance(modules.VectorCutPlane, ())
 
404
 
 
405
vectorcutplane = make_function(VectorCutPlaneFactory)
 
406
 
 
407
 
 
408
##############################################################################
 
409
class WarpVectorCutPlaneFactory(DataModuleFactory):
 
410
    """Applies the WarpVectorCutPlane mayavi module to the given VTK data
 
411
    object."""
 
412
    _target = Instance(modules.WarpVectorCutPlane, ())
 
413
 
 
414
warpvectorcutplane = make_function(WarpVectorCutPlaneFactory)
 
415
 
271
416