1
# Author: Suyog Dutt Jain <suyog.jain@aero.iitb.ac.in>
2
# Copyright (c) 2009, Enthought, Inc.
5
# Standard library imports.
10
from common import get_example_data
12
# Enthought library imports
13
from enthought.mayavi.core.engine import Engine
14
from enthought.mayavi.core.null_engine import NullEngine
15
from enthought.mayavi.sources.image_reader import ImageReader
16
from enthought.mayavi.tests.data_reader_test_base import DataReaderTestBase
17
from enthought.mayavi.modules.outline import Outline
19
class TestDEMImageReader(DataReaderTestBase):
21
def setup_reader(self):
23
""""Setup the reader in here. This is called after the engine
24
has been created and started. The engine is available as
25
self.e. This method is called by setUp().
27
# Read a DEM Image file.
29
r.initialize(get_example_data('example.dem'))
31
self.bounds =(557945.0, 567725.0, 5107991.5, 5121971.5, 682.0, 682.0)
33
def check(self, scene, bounds, error = 1.01e-02):
34
"""Do the actual testing."""
36
src = scene.children[0]
37
ot = src.children[0].children[0]
38
ot.render() # Flush the pipeline.
40
# Check the outline bounds
41
self.assertEqual(numpy.allclose(ot.outline_filter.output.bounds,bounds,
43
self.assertEqual(src.reader.spatial_resolution, (30.0, 30.0, 1.0))
44
self.assertEqual(src.reader.elevation_bounds, (682.0, 2543.0))
46
def test_dem_image_data_reader(self):
47
"Test if the test fixture works"
50
self.check(self.scene, self.bounds)
52
def test_save_and_restore(self):
53
"""Test if saving a visualization and restoring it works."""
55
self.check_saving(self.e, self.scene, self.bounds)
57
def test_deepcopied(self):
58
"""Test if the MayaVi2 visualization can be deep-copied."""
59
############################################################
60
# Test if the MayaVi2 visualization can be deep-copied.
62
self.check_deepcopying(self.scene, self.bounds)
64
class TestMHAImageReader(DataReaderTestBase):
66
def setup_reader(self):
68
""""Setup the reader in here. This is called after the engine
69
has been created and started. The engine is available as
70
self.e. This method is called by setUp().
72
# Read a Meta Image file.
74
r.initialize(get_example_data('foot.mha'))
76
self.bounds =(0.0, 255.0, 0.0, 255.0, 0.0, 0.0)
78
def check(self, scene, bounds, error = 1.01e-02):
79
"""Do the actual testing."""
81
src = scene.children[0]
82
ot = src.children[0].children[0]
83
ot.render() # Flush the pipeline.
85
# Check the outline bounds
86
self.assertEqual(numpy.allclose(ot.outline_filter.output.bounds,bounds,
88
self.assertEqual(numpy.allclose(src.reader.data_spacing,(1., 1., 1.)),True)
90
def test_mha_image_data_reader(self):
91
"Test if the test fixture works"
94
self.check(self.scene, self.bounds)
96
def test_save_and_restore(self):
97
"""Test if saving a visualization and restoring it works."""
99
self.check_saving(self.e, self.scene, self.bounds)
101
def test_deepcopied(self):
102
"""Test if the MayaVi2 visualization can be deep-copied."""
103
############################################################
104
# Test if the MayaVi2 visualization can be deep-copied.
106
self.check_deepcopying(self.scene, self.bounds)
108
if __name__ == '__main__':