/[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 1070 - (show annotations)
Thu Mar 29 04:20:50 2007 UTC (13 years, 6 months ago) by jongui
File MIME type: text/x-python
File size: 2650 byte(s)
Added tests for the camera, carpet, contouir, ellipsoid, light, streamline and velocity modules.
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 PYVISI_TEST_MESHES_PATH = "data_meshes/"
7 PYVISI_TEST_CAMERA_IMAGES_PATH = "data_sample_images/camera/"
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 TestCamera:
18 def tearDown(self):
19 self.scene
20 self.data_collector
21 self.map
22 self.camera
23
24 def render(self, file):
25 self.scene.render(image_name = \
26 PYVISI_TEST_CAMERA_IMAGES_PATH + file)
27
28 self.failUnless(os.stat(PYVISI_TEST_CAMERA_IMAGES_PATH + \
29 file)[ST_SIZE] > MIN_IMAGE_SIZE)
30
31 class TestCamera2D(unittest.TestCase, TestCamera):
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.camera = Camera(scene = self.scene,
47 data_collector = self.data_collector,
48 viewport = Viewport.SOUTH_WEST)
49
50 def test2D(self):
51 self.camera.azimuth(20)
52 self.camera.elevation(40)
53 self.camera.roll(30)
54 self.camera.dolly(1.5)
55 self.render("TestCamera2D_test2D.jpg")
56
57 class TestCamera3D(unittest.TestCase, TestCamera):
58 def setUp(self):
59 self.scene = \
60 Scene(renderer = JPG_RENDERER, num_viewport = 1,
61 x_size = X_SIZE, y_size = Y_SIZE)
62
63 self.data_collector = DataCollector(source = Source.XML)
64 self.data_collector.setFileName(file_name = \
65 PYVISI_TEST_MESHES_PATH + FILE_3D)
66
67 self.map = Map(scene = self.scene,
68 data_collector = self.data_collector,
69 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
70 cell_to_point = False, outline = True)
71
72 self.camera = Camera(scene = self.scene,
73 data_collector = self.data_collector,
74 viewport = Viewport.SOUTH_WEST)
75
76 def test3D(self):
77 self.camera.setFocalPoint(GlobalPosition(1, 1, 0.3))
78 self.camera.setPosition(GlobalPosition(1, 1, 7))
79 self.camera.isometricView()
80 self.render("TestCamera3D_test3D.jpg")
81
82
83 ##############################################################################
84
85
86 if __name__ == '__main__':
87 suite = unittest.TestSuite()
88 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestCamera2D))
89 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestCamera3D))
90 unittest.TextTestRunner(verbosity=2).run(suite)
91

  ViewVC Help
Powered by ViewVC 1.1.26