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

Contents of /trunk/pyvisi/test/python/run_light.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: 3981 byte(s)
Change __url__ to launchpad site

1
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 __url__="https://launchpad.net/escript-finley"
21
22 from esys.pyvisi import DataCollector, Scene, Light, GlobalPosition, Map
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_LIGHT_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
39 "data_sample_images", "light")
40
41 MIN_IMAGE_SIZE = 100
42 FILE_2D = "interior_2D.xml"
43 FILE_3D = "interior_3D.xml"
44 X_SIZE = 400
45 Y_SIZE = 400
46 JPG_RENDERER = Renderer.OFFLINE_JPG
47
48 class TestLight:
49 def render(self, file):
50 self.scene.render(image_name = \
51 os.path.join(PYVISI_TEST_LIGHT_IMAGES_PATH, file))
52
53 self.failUnless(os.stat(os.path.join(PYVISI_TEST_LIGHT_IMAGES_PATH, \
54 file))[ST_SIZE] > MIN_IMAGE_SIZE)
55
56 class TestLight2D(unittest.TestCase, TestLight):
57 def setUp(self):
58 self.scene = \
59 Scene(renderer = JPG_RENDERER, num_viewport = 1,
60 x_size = X_SIZE, y_size = Y_SIZE)
61
62 self.data_collector = DataCollector(source = Source.XML)
63 self.data_collector.setFileName(file_name = \
64 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D))
65
66 self.map = Map(scene = self.scene,
67 data_collector = self.data_collector,
68 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
69 cell_to_point = False, outline = True)
70
71 self.light = Light(scene = self.scene,
72 viewport = Viewport.SOUTH_WEST)
73
74 def tearDown(self):
75 del self.scene
76 del self.data_collector
77 del self.map
78 del self.light
79
80 def test2D(self):
81 self.light.setColor(Color.BLUE)
82 self.light.setFocalPoint(GlobalPosition(0.2, 1, 0.4))
83 self.light.setPosition(GlobalPosition(0.2, 1, 5))
84 self.light.setIntensity(2)
85 self.render("TestLight2D_test2D.jpg")
86
87 class TestLight3D(unittest.TestCase, TestLight):
88 def setUp(self):
89 self.scene = \
90 Scene(renderer = JPG_RENDERER, num_viewport = 1,
91 x_size = X_SIZE, y_size = Y_SIZE)
92
93 self.data_collector = DataCollector(source = Source.XML)
94 self.data_collector.setFileName(file_name = \
95 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
96
97 self.map = Map(scene = self.scene,
98 data_collector = self.data_collector,
99 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
100 cell_to_point = False, outline = True)
101
102 self.light = Light(scene = self.scene,
103 viewport = Viewport.SOUTH_WEST)
104
105 def tearDown(self):
106 del self.scene
107 del self.data_collector
108 del self.map
109 del self.light
110
111 def test3D(self):
112 self.light.setColor(Color.RED)
113 self.light.setAngle(20, 50)
114 self.light.setIntensity(1)
115 self.render("TestLight3D_test3D.jpg")
116
117
118 ##############################################################################
119
120
121 if __name__ == '__main__':
122 if getMPISizeWorld() == 1:
123 suite = unittest.TestSuite()
124 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestLight2D))
125 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestLight3D))
126 s=unittest.TextTestRunner(verbosity=2).run(suite)
127 if not s.wasSuccessful(): sys.exit(1)
128 else:
129 print "run_light.py is not executed as more than one processor is used."
130

  ViewVC Help
Powered by ViewVC 1.1.26