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

Contents of /trunk/pyvisi/test/python/run_image_with_lazy_evaluation.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2344 - (show annotations)
Mon Mar 30 02:13:58 2009 UTC (10 years, 5 months ago) by jfenwick
File MIME type: text/x-python
File size: 3202 byte(s)
Change __url__ to launchpad site

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

  ViewVC Help
Powered by ViewVC 1.1.26