/[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 1070 - (show annotations)
Thu Mar 29 04:20:50 2007 UTC (13 years, 5 months ago) by jongui
File MIME type: text/x-python
File size: 2657 byte(s)
Added tests for the camera, carpet, contouir, ellipsoid, light, streamline and velocity modules.
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 PYVISI_TEST_MESHES_PATH = "data_meshes/"
7 PYVISI_TEST_LIGHT_IMAGES_PATH = "data_sample_images/light/"
8 MIN_IMAGE_SIZE = 100
9 FILE_2D = "interior_2D.xml"
10 FILE_3D = "interior_3D.xml"
11
12 X_SIZE = 400
13 Y_SIZE = 400
14
15 JPG_RENDERER = Renderer.OFFLINE_JPG
16
17 class TestLight:
18 def tearDown(self):
19 self.scene
20 self.data_collector
21 self.map
22 self.light
23
24 def render(self, file):
25 self.scene.render(image_name = \
26 PYVISI_TEST_LIGHT_IMAGES_PATH + file)
27
28 self.failUnless(os.stat(PYVISI_TEST_LIGHT_IMAGES_PATH + \
29 file)[ST_SIZE] > MIN_IMAGE_SIZE)
30
31 class TestLight2D(unittest.TestCase, TestLight):
32 def setUp(self):
33 self.scene = \
34 Scene(renderer = JPG_RENDERER, num_viewport = 1,
35 x_size = X_SIZE, y_size = Y_SIZE)
36
37 self.data_collector = DataCollector(source = Source.XML)
38 self.data_collector.setFileName(file_name = \
39 PYVISI_TEST_MESHES_PATH + FILE_2D)
40
41 self.map = Map(scene = self.scene,
42 data_collector = self.data_collector,
43 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
44 cell_to_point = False, outline = True)
45
46 self.light = Light(scene = self.scene,
47 data_collector = self.data_collector,
48 viewport = Viewport.SOUTH_WEST)
49
50 def test2D(self):
51 self.light.setColor(Color.BLUE)
52 self.light.setFocalPoint(GlobalPosition(0.2, 1, 0.4))
53 self.light.setPosition(GlobalPosition(0.2, 1, 5))
54 self.light.setIntensity(2)
55 self.render("TestLight2D_test2D.jpg")
56
57
58 class TestLight3D(unittest.TestCase, TestLight):
59 def setUp(self):
60 self.scene = \
61 Scene(renderer = JPG_RENDERER, num_viewport = 1,
62 x_size = X_SIZE, y_size = Y_SIZE)
63
64 self.data_collector = DataCollector(source = Source.XML)
65 self.data_collector.setFileName(file_name = \
66 PYVISI_TEST_MESHES_PATH + FILE_3D)
67
68 self.map = Map(scene = self.scene,
69 data_collector = self.data_collector,
70 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
71 cell_to_point = False, outline = True)
72
73 self.light = Light(scene = self.scene,
74 data_collector = self.data_collector,
75 viewport = Viewport.SOUTH_WEST)
76
77 def test3D(self):
78 self.light.setColor(Color.RED)
79 self.light.setAngle(20, 50)
80 self.light.setIntensity(1)
81 self.render("TestLight3D_test3D.jpg")
82
83
84 ##############################################################################
85
86
87 if __name__ == '__main__':
88 suite = unittest.TestSuite()
89 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestLight2D))
90 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestLight3D))
91 unittest.TextTestRunner(verbosity=2).run(suite)
92

  ViewVC Help
Powered by ViewVC 1.1.26