/[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 1138 - (show annotations)
Mon May 14 04:15:04 2007 UTC (13 years, 6 months ago) by gross
File MIME type: text/x-python
File size: 2808 byte(s)
 * some of the sys.exit calls removed.
 * some modifications on the test (and more work needs to be done, use test/python/run_carpet.py as an example) to get them going with scons 

-> things seems to run on windows XP.
1 from esys.pyvisi import DataCollector, Scene, Camera, 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
11 PYVISI_TEST_MESHES_PATH = s.path.join(PYVISI_WORKDIR,"data_meshes")
12 PYVISI_TEST_CAMERA_IMAGES_PATH = os.path.join(PYVISI_WORKDIR,"data_sample_images","camera")
13 MIN_IMAGE_SIZE = 100
14 FILE_2D = "interior_2D.xml"
15 FILE_3D = "interior_3D.xml"
16
17 X_SIZE = 400
18 Y_SIZE = 400
19
20 JPG_RENDERER = Renderer.OFFLINE_JPG
21
22 class TestCamera:
23 def tearDown(self):
24 self.scene
25 self.data_collector
26 self.map
27 self.camera
28
29 def render(self, file):
30 self.scene.render(image_name = \
31 PYVISI_TEST_CAMERA_IMAGES_PATH + file)
32
33 self.failUnless(os.stat(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 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,
52 data_collector = self.data_collector,
53 viewport = Viewport.SOUTH_WEST)
54
55 def test2D(self):
56 self.camera.azimuth(20)
57 self.camera.elevation(40)
58 self.camera.roll(30)
59 self.camera.dolly(1.5)
60 self.render("TestCamera2D_test2D.jpg")
61
62 class TestCamera3D(unittest.TestCase, TestCamera):
63 def setUp(self):
64 self.scene = \
65 Scene(renderer = JPG_RENDERER, num_viewport = 1,
66 x_size = X_SIZE, y_size = Y_SIZE)
67
68 self.data_collector = DataCollector(source = Source.XML)
69 self.data_collector.setFileName(file_name = \
70 PYVISI_TEST_MESHES_PATH + FILE_3D)
71
72 self.map = Map(scene = self.scene,
73 data_collector = self.data_collector,
74 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
75 cell_to_point = False, outline = True)
76
77 self.camera = Camera(scene = self.scene,
78 data_collector = self.data_collector,
79 viewport = Viewport.SOUTH_WEST)
80
81 def test3D(self):
82 self.camera.setFocalPoint(GlobalPosition(1, 1, 0.3))
83 self.camera.setPosition(GlobalPosition(1, 1, 7))
84 self.camera.isometricView()
85 self.render("TestCamera3D_test3D.jpg")
86
87
88 ##############################################################################
89
90
91 if __name__ == '__main__':
92 suite = unittest.TestSuite()
93 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestCamera2D))
94 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestCamera3D))
95 unittest.TextTestRunner(verbosity=2).run(suite)
96

  ViewVC Help
Powered by ViewVC 1.1.26