1
# Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in>
2
# Copyright (c) 2008, Enthought, Inc.
5
# Standard library imports.
6
from os.path import abspath
7
from StringIO import StringIO
11
from common import TestCase, get_example_data
14
class TestSetActiveAttribute(TestCase):
16
"""Check if the visualization is OK. Note that this is not an
17
image based check, which is very convenient.
19
e = self.script.engine
20
scene = e.current_scene
21
src = scene.children[0]
22
assert src.point_scalars_name == 'u'
24
sc = c.outputs[0].point_data.scalars
26
# It is an iso-contour!
27
assert sc.range[0] == sc.range[1]
28
aa = c.children[0].children[0]
29
assert aa.point_scalars_name == 't'
30
sc = aa.outputs[0].point_data.scalars
32
assert abs(sc.range[0] - 308) < 1.0
33
assert abs(sc.range[1] - 631) < 1.0
34
s = aa.children[0].children[0]
37
"""Test for the SetActiveAttribute filter.
39
from enthought.mayavi.sources.api import VTKXMLFileReader
40
from enthought.mayavi.filters.contour import Contour
41
from enthought.mayavi.filters.api import PolyDataNormals
42
from enthought.mayavi.filters.set_active_attribute import SetActiveAttribute
43
from enthought.mayavi.modules.api import Surface, Outline
45
mayavi = script = self.script
47
scene = mayavi.new_scene()
48
r = VTKXMLFileReader()
49
r.initialize(get_example_data('fire_ug.vtu'))
51
r.point_scalars_name = 'u'
58
aa = SetActiveAttribute()
60
aa.point_scalars_name = 't'
64
scene.scene.isometric_view()
65
# Check if things are OK.
68
############################################################
69
# Test if saving a visualization and restoring it works.
73
f.name = abspath('test.mv2') # We simulate a file.
74
mayavi.save_visualization(f)
75
f.seek(0) # So we can read this saved data.
77
# Remove existing scene.
78
engine = mayavi.engine
82
mayavi.load_visualization(f)
83
s = engine.current_scene
86
s.scene.isometric_view()
89
############################################################
90
# Test if the Mayavi2 visualization can be deep-copied.
92
# Pop the source object.
93
source = s.children.pop()
94
# Add it back to see if that works without error.
95
s.children.append(source)
99
# Now deepcopy the source and replace the existing one with
100
# the copy. This basically simulates cutting/copying the
101
# object from the UI via the right-click menu on the tree
102
# view, and pasting the copy back.
103
source1 = copy.deepcopy(source)
104
s.children[0] = source1
106
s.scene.isometric_view()
109
# If we have come this far, we are golden!
111
if __name__ == '__main__':
112
t = TestSetActiveAttribute()