/[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 1158 - (show annotations)
Tue May 22 04:24:01 2007 UTC (13 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 3120 byte(s)
Made some changes to fix the memory leak problem. However, the problem still persists for run_escript_with_lazy_evaluation.py, run_streamline.py and run_streamline_with_lazy_evaluation.py.

1 from esys.pyvisi import DataCollector, Scene, Light, GlobalPosition, Map
2 from esys.pyvisi.constant import *
3 import unittest, os
4 from stat import ST_SIZE
5
6 try:
7 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
8 except KeyError:
9 PYVISI_WORKDIR='.'
10 try:
11 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
12 except KeyError:
13 PYVISI_TEST_DATA_ROOT='.'
14
15 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
16 PYVISI_TEST_LIGHT_REFERENCE_IMAGES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, \
17 "data_reference_images", "light")
18 PYVISI_TEST_LIGHT_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
19 "data_sample_images", "light")
20
21 MIN_IMAGE_SIZE = 100
22 FILE_2D = "interior_2D.xml"
23 FILE_3D = "interior_3D.xml"
24 X_SIZE = 400
25 Y_SIZE = 400
26 JPG_RENDERER = Renderer.OFFLINE_JPG
27
28 class TestLight:
29 def render(self, file):
30 self.scene.render(image_name = \
31 os.path.join(PYVISI_TEST_LIGHT_IMAGES_PATH, file))
32
33 self.failUnless(os.stat(os.path.join(PYVISI_TEST_LIGHT_IMAGES_PATH, \
34 file))[ST_SIZE] > MIN_IMAGE_SIZE)
35
36 class TestLight2D(unittest.TestCase, TestLight):
37 def setUp(self):
38 self.scene = \
39 Scene(renderer = JPG_RENDERER, num_viewport = 1,
40 x_size = X_SIZE, y_size = Y_SIZE)
41
42 self.data_collector = DataCollector(source = Source.XML)
43 self.data_collector.setFileName(file_name = \
44 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D))
45
46 self.map = Map(scene = self.scene,
47 data_collector = self.data_collector,
48 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
49 cell_to_point = False, outline = True)
50
51 self.light = Light(scene = self.scene,
52 viewport = Viewport.SOUTH_WEST)
53
54 def tearDown(self):
55 del self.scene
56 del self.data_collector
57 del self.map
58 del self.light
59
60 def test2D(self):
61 self.light.setColor(Color.BLUE)
62 self.light.setFocalPoint(GlobalPosition(0.2, 1, 0.4))
63 self.light.setPosition(GlobalPosition(0.2, 1, 5))
64 self.light.setIntensity(2)
65 self.render("TestLight2D_test2D.jpg")
66
67 class TestLight3D(unittest.TestCase, TestLight):
68 def setUp(self):
69 self.scene = \
70 Scene(renderer = JPG_RENDERER, num_viewport = 1,
71 x_size = X_SIZE, y_size = Y_SIZE)
72
73 self.data_collector = DataCollector(source = Source.XML)
74 self.data_collector.setFileName(file_name = \
75 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
76
77 self.map = Map(scene = self.scene,
78 data_collector = self.data_collector,
79 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
80 cell_to_point = False, outline = True)
81
82 self.light = Light(scene = self.scene,
83 viewport = Viewport.SOUTH_WEST)
84
85 def tearDown(self):
86 del self.scene
87 del self.data_collector
88 del self.map
89 del self.light
90
91 def test3D(self):
92 self.light.setColor(Color.RED)
93 self.light.setAngle(20, 50)
94 self.light.setIntensity(1)
95 self.render("TestLight3D_test3D.jpg")
96
97
98 ##############################################################################
99
100
101 if __name__ == '__main__':
102 suite = unittest.TestSuite()
103 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestLight2D))
104 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestLight3D))
105 unittest.TextTestRunner(verbosity=2).run(suite)
106

  ViewVC Help
Powered by ViewVC 1.1.26