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

Contents of /trunk/pyvisi/test/python/run_map_with_lazy_evaluation.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: 8107 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 # Import the necessary modules
23 from esys.pyvisi import DataCollector, Scene, Map, MapOnPlaneCut, MapOnPlaneClip
24 from esys.pyvisi import Camera, MapOnScalarClip, MapOnScalarClipWithRotation
25 from esys.pyvisi.constant import *
26 import unittest, os, sys
27 from stat import ST_SIZE
28 from esys.escript import getMPISizeWorld
29
30 try:
31 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
32 except KeyError:
33 PYVISI_WORKDIR='.'
34 try:
35 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
36 except KeyError:
37 PYVISI_TEST_DATA_ROOT='.'
38
39 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
40 PYVISI_TEST_MAP_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
41 "data_sample_images", "map")
42
43 MIN_IMAGE_SIZE = 100
44 FILE_3D_1 = "results.xml"
45 FILE_3D_2 = "interior_3D.xml"
46 FILE_2D_ROTATION = "without_st.0700.xml"
47 X_SIZE = 400
48 Y_SIZE = 400
49
50 JPG_RENDERER = Renderer.OFFLINE_JPG
51 SCALAR_FIELD_POINT_DATA_1 = "scalar1"
52 SCALAR_FIELD_POINT_DATA_2 = "scalar2"
53
54 class TestMapWithLazyEvaluation:
55 def render(self, file):
56 self.scene.render(image_name = \
57 os.path.join(PYVISI_TEST_MAP_IMAGES_PATH, file))
58
59 self.failUnless(os.stat(os.path.join(PYVISI_TEST_MAP_IMAGES_PATH, \
60 file))[ST_SIZE] > MIN_IMAGE_SIZE)
61
62 class TestMapLazy(unittest.TestCase, TestMapWithLazyEvaluation):
63 def tearDown(self):
64 del self.scene
65
66 def testMapLazy(self):
67
68 # Create a scene with four viewports.
69 s = Scene(renderer = JPG_RENDERER, num_viewport = 4, x_size = X_SIZE,
70 y_size = Y_SIZE)
71 self.scene = s
72
73 dc1 = DataCollector(source = Source.XML)
74 dc1.setActiveScalar(scalar = SCALAR_FIELD_POINT_DATA_1)
75
76 dc2 = DataCollector(source = Source.XML)
77 dc2.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
78 FILE_3D_1))
79 dc2.setActiveScalar(scalar = SCALAR_FIELD_POINT_DATA_2)
80
81 # Create a map instance for the first viewport.
82 m1 = Map(scene = s, data_collector = dc1,
83 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True)
84
85 # Create a map instance for the second viewport.
86 m2 = Map(scene = s, data_collector = dc2,
87 viewport = Viewport.NORTH_WEST, lut = Lut.COLOR, outline = True)
88 m2.setColor(color = Color.BLUE)
89
90 # Create a map instance for the third viewport.
91 m3 = Map(scene = s, data_collector = dc1,
92 viewport = Viewport.NORTH_EAST, lut = Lut.COLOR, outline = True)
93
94 # Create a map instance the fourth viewport.
95 m4 = Map(scene = s, data_collector = dc2,
96 viewport = Viewport.SOUTH_EAST, lut = Lut.COLOR, outline = True)
97
98 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
99 FILE_3D_1))
100 m1.setRepresentationToWireframe()
101 m4.setOpacity(opacity = 0.5)
102
103 self.render("TestMapWithLazyEvaluation.jpg")
104
105 class TestMapOnPlaneCutLazy(unittest.TestCase, TestMapWithLazyEvaluation):
106 def tearDown(self):
107 del self.scene
108
109 def testMapOnPlaneCutLazy(self):
110 s = Scene(renderer = JPG_RENDERER, num_viewport = 4, x_size = X_SIZE,
111 y_size = Y_SIZE)
112 self.scene = s
113
114 # Create two data collector instances for two different sources.
115 dc1 = DataCollector(source = Source.XML)
116
117 # Create a map on plane cut instance for the first viewport.
118 mopc1 = MapOnPlaneCut(scene = s, data_collector = dc1,
119 viewport = Viewport.SOUTH_WEST)
120 mopc1.setPlaneToYZ(offset = 1.5)
121
122 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
123 c1.isometricView()
124
125 # Create three map on plane cut instances for the second viewport.
126 mopc2_1 = MapOnPlaneCut(scene = s, data_collector = dc1,
127 viewport = Viewport.NORTH_WEST)
128
129 mopc2_2 = MapOnPlaneCut(scene = s, data_collector = dc1,
130 viewport = Viewport.NORTH_WEST)
131
132 mopc2_3 = MapOnPlaneCut(scene = s, data_collector = dc1,
133 viewport = Viewport.NORTH_WEST)
134 mopc2_3.setPlaneToXY()
135 mopc2_3.translate(0,0,0.5)
136
137 c2 = Camera(scene = s, viewport = Viewport.NORTH_WEST)
138 c2.isometricView()
139
140 mopc2_1.setPlaneToYZ(offset = 1.5)
141 mopc2_2.setPlaneToXZ(offset = 1.5)
142 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
143 FILE_3D_2))
144
145 self.render("TestMapOnPlaneCutWithLazyEvaluation.jpg")
146
147
148 class TestMapOnPlaneClipLazy(unittest.TestCase, TestMapWithLazyEvaluation):
149 def tearDown(self):
150 del self.scene
151
152 def testMapOnPlaneClipLazy(self):
153 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
154 y_size = Y_SIZE)
155 self.scene = s
156
157 dc1 = DataCollector(source = Source.XML)
158
159 # Create three map on clip instances.
160 mopc1_1 = MapOnPlaneClip(scene = s, data_collector = dc1,
161 viewport = Viewport.SOUTH_WEST)
162 mopc1_1.setPlaneToXY()
163 mopc1_1.rotateX(angle = 5)
164
165 mopc1_2 = MapOnPlaneClip(scene = s, data_collector = dc1,
166 viewport = Viewport.SOUTH_WEST)
167
168 mopc1_3 = MapOnPlaneClip(scene = s, data_collector = dc1,
169 viewport = Viewport.SOUTH_WEST)
170 mopc1_3.setPlaneToXZ()
171 mopc1_3.rotateX(angle = -40)
172 mopc1_3.translate(x_offset = 0, y_offset = 2.2, z_offset = 0)
173
174 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
175 c1.isometricView()
176
177 mopc1_2.setPlaneToYZ(offset = 2.5)
178 mopc1_2.setOpacity(opacity = 0.5)
179 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
180 FILE_3D_2))
181
182 self.render("TestMapOnPlaneClipWithLazyEvaluation.jpg")
183
184
185 class TestMapOnScalarClipLazy(unittest.TestCase, TestMapWithLazyEvaluation):
186 def tearDown(self):
187 del self.scene
188
189 def testMapOnScalarClipLazy(self):
190 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
191 y_size = Y_SIZE)
192 self.scene = s
193
194 dc1 = DataCollector(source = Source.XML)
195
196 # Create a map on scalar clip instance.
197 mosc1_1 = MapOnScalarClip(scene = s, data_collector = dc1,
198 lut = Lut.GREY_SCALE)
199
200 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
201 c1.isometricView()
202
203 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
204 FILE_3D_2))
205 self.render("TestMapOnScalarClipWithLazyEvaluation.jpg")
206
207 class TestMapOnScalarClipWithRotationLazy(unittest.TestCase,
208 TestMapWithLazyEvaluation):
209
210 def tearDown(self):
211 del self.scene
212
213 def testMapOnScalarClipWithRotationLazy(self):
214 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
215 y_size = Y_SIZE)
216 self.scene = s
217
218 dc1 = DataCollector(source = Source.XML)
219
220 # Create a map on scalar clip instance.
221 mosc1_1 = MapOnScalarClipWithRotation(scene = s, data_collector = dc1,
222 lut = Lut.GREY_SCALE)
223 mosc1_1.setAngle(200)
224
225 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
226 c1.isometricView()
227
228 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
229 FILE_2D_ROTATION))
230 self.render("TestMapOnScalarClipWithRotationWithLazyEvaluation.jpg")
231
232
233
234
235
236 ##############################################################################
237 if __name__ == '__main__':
238 if getMPISizeWorld() == 1:
239 suite = unittest.TestSuite()
240 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapLazy))
241 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnPlaneCutLazy))
242 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnPlaneClipLazy))
243 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnScalarClipLazy))
244 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnScalarClipWithRotationLazy))
245 s=unittest.TextTestRunner(verbosity=2).run(suite)
246 if not s.wasSuccessful(): sys.exit(1)
247 else:
248 print "run_map_with_lazy_evaluation.py is not executed as more than one processor is used."
249

  ViewVC Help
Powered by ViewVC 1.1.26