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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1163 - (show annotations)
Wed May 23 23:56:39 2007 UTC (13 years, 11 months ago) by gross
File MIME type: text/x-python
File size: 3129 byte(s)
import of DISPLAY environment variable into scons ENV added. This is required to run pyvisi tests under XGL
1 from esys.pyvisi import DataCollector, Scene, Camera, GlobalPosition, Map
2 from esys.pyvisi.constant import *
3 import unittest, os, gc
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_CAMERA_REFERENCE_IMAGES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, \
17 "data_reference_images", "camera")
18 PYVISI_TEST_CAMERA_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
19 "data_sample_images", "camera")
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 TestCamera:
29 def render(self, file):
30 self.scene.render(image_name = \
31 os.path.join(PYVISI_TEST_CAMERA_IMAGES_PATH, file))
32
33 self.failUnless(os.stat(os.path.join(PYVISI_TEST_CAMERA_IMAGES_PATH,\
34 file))[ST_SIZE] > MIN_IMAGE_SIZE)
35
36 class TestCamera2D(unittest.TestCase, TestCamera):
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.camera = Camera(scene = self.scene, viewport = Viewport.SOUTH_WEST)
52
53 def tearDown(self):
54 del self.scene
55 del self.data_collector
56 del self.map
57 del self.camera
58
59 def test2D(self):
60 self.camera.azimuth(20)
61 self.camera.elevation(40)
62 self.camera.roll(30)
63 self.camera.dolly(1.5)
64 self.render("TestCamera2D_test2D.jpg")
65
66 class TestCamera3D(unittest.TestCase, TestCamera):
67 def setUp(self):
68 self.scene = \
69 Scene(renderer = JPG_RENDERER, num_viewport = 1,
70 x_size = X_SIZE, y_size = Y_SIZE)
71
72 self.data_collector = DataCollector(source = Source.XML)
73 self.data_collector.setFileName(file_name = \
74 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
75
76 self.map = Map(scene = self.scene,
77 data_collector = self.data_collector,
78 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
79 cell_to_point = False, outline = True)
80
81 self.camera = Camera(scene = self.scene,
82 viewport = Viewport.SOUTH_WEST)
83
84 def tearDown(self):
85 del self.scene
86 del self.data_collector
87 del self.map
88 del self.camera
89
90 def test3D(self):
91 self.camera.setFocalPoint(GlobalPosition(1, 1, 0.3))
92 self.camera.setPosition(GlobalPosition(1, 1, 7))
93 self.camera.isometricView()
94 self.render("TestCamera3D_test3D.jpg")
95
96
97 ##############################################################################
98
99
100 if __name__ == '__main__':
101 suite = unittest.TestSuite()
102 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestCamera2D))
103 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestCamera3D))
104 unittest.TextTestRunner(verbosity=2).run(suite)
105

  ViewVC Help
Powered by ViewVC 1.1.26