/[escript]/trunk/pyvisi/test/python/run_image.py
ViewVC logotype

Annotation of /trunk/pyvisi/test/python/run_image.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1148 - (hide annotations)
Wed May 16 22:45:33 2007 UTC (12 years, 3 months ago) by jongui
File MIME type: text/x-python
File size: 2376 byte(s)
Added the updated files for pyvisi and removed some incorrect reference images.
1 ksteube 1147 from esys.pyvisi import DataCollector, Scene, Map, Image, Image, ImageReader
2     from esys.pyvisi import GlobalPosition
3     from esys.pyvisi.constant import *
4     import unittest, os
5     from stat import ST_SIZE
6    
7 jongui 1148 try:
8     PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
9     except KeyError:
10     PYVISI_WORKDIR='.'
11     try:
12     PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
13     except KeyError:
14     PYVISI_TEST_DATA_ROOT='.'
15    
16     PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
17     PYVISI_TEST_IMAGE_REFERENCE_IMAGES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, \
18     "data_reference_images", "image")
19     PYVISI_TEST_IMAGE_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
20     "data_sample_images", "image")
21    
22 ksteube 1147 MIN_IMAGE_SIZE = 100
23     FILE_3D = "interior_3D.xml"
24     IMAGE = "flinders.jpg"
25     X_SIZE = 400
26     Y_SIZE = 400
27     JPG_RENDERER = Renderer.OFFLINE_JPG
28    
29     class TestImage:
30     def tearDown(self):
31     self.scene
32     self.data_collector
33     self.map
34     self.image
35     self.image_reader
36    
37     def render(self, file):
38     self.scene.render(image_name = \
39 jongui 1148 os.path.join(PYVISI_TEST_IMAGE_IMAGES_PATH, file))
40 ksteube 1147
41 jongui 1148 self.failUnless(os.stat(os.path.join(PYVISI_TEST_IMAGE_IMAGES_PATH, \
42     file))[ST_SIZE] > MIN_IMAGE_SIZE)
43 ksteube 1147
44     class TestImageOnAMap(unittest.TestCase, TestImage):
45     def setUp(self):
46     self.scene = \
47     Scene(renderer = JPG_RENDERER, num_viewport = 1,
48     x_size = X_SIZE, y_size = Y_SIZE)
49    
50     self.data_collector = DataCollector(source = Source.XML)
51     self.data_collector.setFileName(file_name = \
52 jongui 1148 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
53 ksteube 1147
54     self.map = Map(scene = self.scene,
55     data_collector = self.data_collector,
56     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
57     cell_to_point = False, outline = True)
58    
59     self.image_reader = ImageReader(ImageFormat.JPG)
60 jongui 1148 self.image_reader.setImageName(os.path.join(PYVISI_TEST_MESHES_PATH,\
61     IMAGE))
62 ksteube 1147
63     self.image = Image(scene = self.scene, image_reader = self.image_reader)
64    
65     def testImage(self):
66     self.image.translate(0, 0, -1)
67     self.image.setPoint1(GlobalPosition(2, 0, 0))
68     self.image.setPoint2(GlobalPosition(0, 2, 0))
69     self.image.setOpacity(0.6)
70     self.render("TestImage.jpg")
71    
72    
73     ###############################################################################
74    
75    
76     if __name__ == '__main__':
77     suite = unittest.TestSuite()
78     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestImageOnAMap))
79     unittest.TextTestRunner(verbosity=2).run(suite)
80    

  ViewVC Help
Powered by ViewVC 1.1.26