/[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 2344 - (show annotations)
Mon Mar 30 02:13:58 2009 UTC (10 years, 5 months ago) by jfenwick
File MIME type: text/x-python
File size: 4020 byte(s)
Change __url__ to launchpad site

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 from esys.pyvisi import DataCollector, Scene, Camera, GlobalPosition, Map
23 from esys.pyvisi.constant import *
24 from esys.escript import getMPISizeWorld
25 import unittest, os, gc, sys
26 from stat import ST_SIZE
27
28 try:
29 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
30 except KeyError:
31 PYVISI_WORKDIR='.'
32 try:
33 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
34 except KeyError:
35 PYVISI_TEST_DATA_ROOT='.'
36
37 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
38 PYVISI_TEST_CAMERA_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
39 "data_sample_images", "camera")
40
41 MIN_IMAGE_SIZE = 100
42 FILE_2D = "interior_2D.xml"
43 FILE_3D = "interior_3D.xml"
44 X_SIZE = 400
45 Y_SIZE = 400
46 JPG_RENDERER = Renderer.OFFLINE_JPG
47
48 class TestCamera:
49 def render(self, file):
50 self.scene.render(image_name = \
51 os.path.join(PYVISI_TEST_CAMERA_IMAGES_PATH, file))
52
53 self.failUnless(os.stat(os.path.join(PYVISI_TEST_CAMERA_IMAGES_PATH,\
54 file))[ST_SIZE] > MIN_IMAGE_SIZE)
55
56 class TestCamera2D(unittest.TestCase, TestCamera):
57 def setUp(self):
58 self.scene = \
59 Scene(renderer = JPG_RENDERER, num_viewport = 1,
60 x_size = X_SIZE, y_size = Y_SIZE)
61
62 self.data_collector = DataCollector(source = Source.XML)
63 self.data_collector.setFileName(file_name = \
64 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D))
65
66 self.map = Map(scene = self.scene,
67 data_collector = self.data_collector,
68 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
69 cell_to_point = False, outline = True)
70
71 self.camera = Camera(scene = self.scene, viewport = Viewport.SOUTH_WEST)
72
73 def tearDown(self):
74 del self.scene
75 del self.data_collector
76 del self.map
77 del self.camera
78
79 def test2D(self):
80 self.camera.azimuth(20)
81 self.camera.elevation(40)
82 self.camera.roll(30)
83 self.camera.dolly(1.5)
84 self.render("TestCamera2D_test2D.jpg")
85
86 class TestCamera3D(unittest.TestCase, TestCamera):
87 def setUp(self):
88 self.scene = \
89 Scene(renderer = JPG_RENDERER, num_viewport = 1,
90 x_size = X_SIZE, y_size = Y_SIZE)
91
92 self.data_collector = DataCollector(source = Source.XML)
93 self.data_collector.setFileName(file_name = \
94 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
95
96 self.map = Map(scene = self.scene,
97 data_collector = self.data_collector,
98 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
99 cell_to_point = False, outline = True)
100
101 self.camera = Camera(scene = self.scene,
102 viewport = Viewport.SOUTH_WEST)
103
104 def tearDown(self):
105 del self.scene
106 del self.data_collector
107 del self.map
108 del self.camera
109
110 def test3D(self):
111 self.camera.setFocalPoint(GlobalPosition(1, 1, 0.3))
112 self.camera.setPosition(GlobalPosition(1, 1, 7))
113 self.camera.isometricView()
114 self.render("TestCamera3D_test3D.jpg")
115
116
117 ##############################################################################
118
119
120 if __name__ == '__main__':
121 if getMPISizeWorld() == 1:
122 suite = unittest.TestSuite()
123 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestCamera2D))
124 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestCamera3D))
125 s=unittest.TextTestRunner(verbosity=2).run(suite)
126 if not s.wasSuccessful(): sys.exit(1)
127 else:
128 print "run_camera.py is not executed as more than one processor is used."

  ViewVC Help
Powered by ViewVC 1.1.26