/[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 2344 - (hide annotations)
Mon Mar 30 02:13:58 2009 UTC (10 years, 6 months ago) by jfenwick
File MIME type: text/x-python
File size: 3257 byte(s)
Change __url__ to launchpad site

1 ksteube 1811
2     ########################################################
3     #
4     # Copyright (c) 2003-2008 by University of Queensland
5     # Earth Systems Science Computational Center (ESSCC)
6     # http://www.uq.edu.au/esscc
7     #
8     # Primary Business: Queensland, Australia
9     # Licensed under the Open Software License version 3.0
10     # http://www.opensource.org/licenses/osl-3.0.php
11     #
12     ########################################################
13    
14     __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15     Earth Systems Science Computational Center (ESSCC)
16     http://www.uq.edu.au/esscc
17     Primary Business: Queensland, Australia"""
18     __license__="""Licensed under the Open Software License version 3.0
19     http://www.opensource.org/licenses/osl-3.0.php"""
20 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
21 ksteube 1811
22 ksteube 1147 from esys.pyvisi import DataCollector, Scene, Map, Image, Image, ImageReader
23     from esys.pyvisi import GlobalPosition
24     from esys.pyvisi.constant import *
25 gross 1381 import unittest, os, sys
26 ksteube 1147 from stat import ST_SIZE
27 gross 2313 from esys.escript import getMPISizeWorld
28 ksteube 1147
29 jongui 1148 try:
30     PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
31     except KeyError:
32     PYVISI_WORKDIR='.'
33     try:
34     PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
35     except KeyError:
36     PYVISI_TEST_DATA_ROOT='.'
37    
38     PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
39     PYVISI_TEST_IMAGE_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
40     "data_sample_images", "image")
41    
42 ksteube 1147 MIN_IMAGE_SIZE = 100
43     FILE_3D = "interior_3D.xml"
44     IMAGE = "flinders.jpg"
45     X_SIZE = 400
46     Y_SIZE = 400
47     JPG_RENDERER = Renderer.OFFLINE_JPG
48    
49     class TestImage:
50     def render(self, file):
51     self.scene.render(image_name = \
52 jongui 1148 os.path.join(PYVISI_TEST_IMAGE_IMAGES_PATH, file))
53 ksteube 1147
54 jongui 1148 self.failUnless(os.stat(os.path.join(PYVISI_TEST_IMAGE_IMAGES_PATH, \
55     file))[ST_SIZE] > MIN_IMAGE_SIZE)
56 ksteube 1147
57     class TestImageOnAMap(unittest.TestCase, TestImage):
58     def setUp(self):
59     self.scene = \
60     Scene(renderer = JPG_RENDERER, num_viewport = 1,
61     x_size = X_SIZE, y_size = Y_SIZE)
62    
63     self.data_collector = DataCollector(source = Source.XML)
64     self.data_collector.setFileName(file_name = \
65 jongui 1148 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
66 ksteube 1147
67     self.map = Map(scene = self.scene,
68     data_collector = self.data_collector,
69     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
70     cell_to_point = False, outline = True)
71    
72     self.image_reader = ImageReader(ImageFormat.JPG)
73 jongui 1148 self.image_reader.setImageName(os.path.join(PYVISI_TEST_MESHES_PATH,\
74     IMAGE))
75 ksteube 1147
76     self.image = Image(scene = self.scene, image_reader = self.image_reader)
77    
78 jongui 1158 def tearDown(self):
79     del self.scene
80     del self.data_collector
81     del self.map
82     del self.image
83     del self.image_reader
84    
85 ksteube 1147 def testImage(self):
86     self.image.translate(0, 0, -1)
87     self.image.setPoint1(GlobalPosition(2, 0, 0))
88     self.image.setPoint2(GlobalPosition(0, 2, 0))
89     self.image.setOpacity(0.6)
90     self.render("TestImage.jpg")
91    
92    
93     ###############################################################################
94    
95    
96     if __name__ == '__main__':
97 gross 2313 if getMPISizeWorld() == 1:
98 ksteube 1147 suite = unittest.TestSuite()
99     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestImageOnAMap))
100 gross 1376 s=unittest.TextTestRunner(verbosity=2).run(suite)
101     if not s.wasSuccessful(): sys.exit(1)
102 gross 2313 else:
103     print "run_image.py is not executed as more than one processor is used."
104 ksteube 1147

  ViewVC Help
Powered by ViewVC 1.1.26