~ubuntu-branches/debian/sid/mayavi2/sid

« back to all changes in this revision

Viewing changes to enthought/mayavi/tests/test_image_data_reader.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2009-03-27 04:34:55 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090327043455-vs6ox32daj6ndw33
Tags: 3.2.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Author: Suyog Dutt Jain <suyog.jain@aero.iitb.ac.in>
 
2
# Copyright (c) 2009,  Enthought, Inc.
 
3
# License: BSD Style.
 
4
 
 
5
# Standard library imports.
 
6
import unittest
 
7
import numpy
 
8
 
 
9
# Local imports.
 
10
from common import get_example_data
 
11
 
 
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
 
18
 
 
19
class TestDEMImageReader(DataReaderTestBase):
 
20
    
 
21
    def setup_reader(self):
 
22
        
 
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().
 
26
        """
 
27
         # Read a DEM Image file.
 
28
        r = ImageReader()
 
29
        r.initialize(get_example_data('example.dem'))
 
30
        self.e.add_source(r)
 
31
        self.bounds =(557945.0, 567725.0, 5107991.5, 5121971.5, 682.0, 682.0)
 
32
        
 
33
    def check(self, scene, bounds, error = 1.01e-02):
 
34
        """Do the actual testing."""      
 
35
        
 
36
        src = scene.children[0] 
 
37
        ot = src.children[0].children[0]
 
38
        ot.render() # Flush the pipeline.
 
39
    
 
40
        # Check the outline bounds
 
41
        self.assertEqual(numpy.allclose(ot.outline_filter.output.bounds,bounds,
 
42
                                    atol=error), True)
 
43
        self.assertEqual(src.reader.spatial_resolution, (30.0, 30.0, 1.0))
 
44
        self.assertEqual(src.reader.elevation_bounds, (682.0, 2543.0))
 
45
      
 
46
    def test_dem_image_data_reader(self): 
 
47
        "Test if the test fixture works"                       
 
48
        #Now test.
 
49
        
 
50
        self.check(self.scene, self.bounds)
 
51
        
 
52
    def test_save_and_restore(self):       
 
53
        """Test if saving a visualization and restoring it works."""
 
54
        
 
55
        self.check_saving(self.e, self.scene, self.bounds)
 
56
        
 
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.        
 
61
        
 
62
        self.check_deepcopying(self.scene, self.bounds)
 
63
 
 
64
class TestMHAImageReader(DataReaderTestBase):
 
65
    
 
66
    def setup_reader(self):
 
67
        
 
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().
 
71
        """
 
72
         # Read a Meta Image file.
 
73
        r = ImageReader()
 
74
        r.initialize(get_example_data('foot.mha'))
 
75
        self.e.add_source(r)
 
76
        self.bounds =(0.0, 255.0, 0.0, 255.0, 0.0, 0.0)
 
77
        
 
78
    def check(self, scene, bounds, error = 1.01e-02):
 
79
        """Do the actual testing."""      
 
80
        
 
81
        src = scene.children[0] 
 
82
        ot = src.children[0].children[0]
 
83
        ot.render() # Flush the pipeline.
 
84
    
 
85
        # Check the outline bounds
 
86
        self.assertEqual(numpy.allclose(ot.outline_filter.output.bounds,bounds,
 
87
                                    atol=error), True)
 
88
        self.assertEqual(numpy.allclose(src.reader.data_spacing,(1., 1., 1.)),True)
 
89
      
 
90
    def test_mha_image_data_reader(self): 
 
91
        "Test if the test fixture works"                       
 
92
        #Now test.
 
93
        
 
94
        self.check(self.scene, self.bounds)
 
95
        
 
96
    def test_save_and_restore(self):       
 
97
        """Test if saving a visualization and restoring it works."""
 
98
        
 
99
        self.check_saving(self.e, self.scene, self.bounds)
 
100
        
 
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.        
 
105
        
 
106
        self.check_deepcopying(self.scene, self.bounds)
 
107
        
 
108
if __name__ == '__main__':
 
109
    unittest.main()