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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1381 - (show annotations)
Wed Jan 9 07:59:15 2008 UTC (11 years, 5 months ago) by gross
File MIME type: text/x-python
File size: 13888 byte(s)
import sys missing
1 from esys.pyvisi import DataCollector, Scene, Map
2 from esys.pyvisi.constant import *
3 import unittest, os, sys
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_MAP_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
17 "data_sample_images", "map")
18
19 MIN_IMAGE_SIZE = 100
20 FILE_2D = "interior_2D.xml"
21 FILE_3D = "interior_3D.xml"
22 FILE_2D_ROTATION = "without_st.0700.xml"
23 FILE_SECOND_ORDER_3D = "temp-000585.vtu"
24 X_SIZE = 400
25 Y_SIZE = 400
26
27 JPG_RENDERER = Renderer.OFFLINE_JPG
28 SCALAR_FIELD_CELL_DATA = "temperature_cell"
29 VECTOR_FIELD_CELL_DATA = "velocity_cell"
30 TENSOR_FIELD_CELL_DATA = "stress_cell"
31
32 class TestMap:
33 def render(self, file):
34 self.scene.render(image_name = \
35 os.path.join(PYVISI_TEST_MAP_IMAGES_PATH, file))
36
37 self.failUnless(os.stat(os.path.join(PYVISI_TEST_MAP_IMAGES_PATH, \
38 file))[ST_SIZE] > MIN_IMAGE_SIZE)
39
40 class TestMapOneViewport(unittest.TestCase, TestMap):
41 def setUp(self):
42 self.scene = \
43 Scene(renderer = JPG_RENDERER, num_viewport = 1,
44 x_size = X_SIZE, y_size = Y_SIZE)
45
46 self.data_collector = DataCollector(source = Source.XML)
47 self.data_collector.setFileName(file_name = \
48 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D))
49
50 self.map = Map(scene = self.scene,
51 data_collector = self.data_collector,
52 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
53 cell_to_point = False, outline = True)
54
55 def tearDown(self):
56 del self.scene
57 del self.data_collector
58 del self.map
59
60 def testOneViewport(self):
61 self.render("TestMapOneViewport.jpg")
62
63 class TestMapFourViewports(unittest.TestCase, TestMap):
64 def setUp(self):
65 self.scene = \
66 Scene(renderer = JPG_RENDERER, num_viewport = 4,
67 x_size = X_SIZE, y_size = Y_SIZE)
68
69 self.data_collector = DataCollector(source = Source.XML)
70 self.data_collector.setFileName(file_name = \
71 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D))
72
73 self.map1 = Map(scene = self.scene,
74 data_collector = self.data_collector,
75 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
76 cell_to_point = False, outline = True)
77
78 self.map2 = Map(scene = self.scene,
79 data_collector = self.data_collector,
80 viewport = Viewport.NORTH_WEST, lut = Lut.COLOR,
81 cell_to_point = False, outline = True)
82
83 self.map3 = Map(scene = self.scene,
84 data_collector = self.data_collector,
85 viewport = Viewport.NORTH_EAST, lut = Lut.COLOR,
86 cell_to_point = False, outline = True)
87
88 self.map4 = Map(scene = self.scene,
89 data_collector = self.data_collector,
90 viewport = Viewport.SOUTH_EAST, lut = Lut.COLOR,
91 cell_to_point = False, outline = True)
92
93 def tearDown(self):
94 del self.scene
95 del self.data_collector
96 del self.map1
97 del self.map2
98 del self.map3
99 del self.map4
100
101 def testSetOpacity(self):
102 self.map1.setOpacity(0.2)
103 self.map2.setOpacity(0.4)
104 self.map3.setOpacity(0.6)
105 self.map4.setOpacity(0.8)
106 self.render("TestMapFourViewports_testSetOpacity.jpg")
107
108 def testSetColor(self):
109 self.map1.setColor(Color.GREY)
110 self.map3.setColor(Color.YELLOW)
111 self.render("TestMapFourViewports_testSetColor.jpg")
112
113 def testSetRepresentationToWireframe(self):
114 self.map2.setRepresentationToWireframe()
115 self.map4.setRepresentationToWireframe()
116 self.render("TestMapFourViewports_testSetRepresentationToWireframe.jpg")
117
118 class TestMap2DCellDataWithCellToPointConversion(unittest.TestCase, TestMap):
119 def setUp(self):
120 self.scene = \
121 Scene(renderer = JPG_RENDERER, num_viewport = 1,
122 x_size = X_SIZE, y_size = Y_SIZE)
123
124 self.data_collector = DataCollector(source = Source.XML)
125 self.data_collector.setFileName(file_name = \
126 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D))
127 self.data_collector.setActiveScalar(SCALAR_FIELD_CELL_DATA)
128
129 self.map = Map(scene = self.scene,
130 data_collector = self.data_collector,
131 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
132 cell_to_point = True, outline = True)
133
134 def tearDown(self):
135 del self.scene
136 del self.data_collector
137 del self.map
138
139 def test2DCellDataWithCellToPointConversion(self):
140 self.render("TestMap2DCellDataWithCellToPointConversion.jpg")
141
142 class TestMap2DCellDataWithoutCellToPointConversion(unittest.TestCase, TestMap):
143 def setUp(self):
144 self.scene = \
145 Scene(renderer = JPG_RENDERER, num_viewport = 1,
146 x_size = X_SIZE, y_size = Y_SIZE)
147
148 self.data_collector = DataCollector(source = Source.XML)
149 self.data_collector.setFileName(file_name = \
150 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D))
151 self.data_collector.setActiveScalar(SCALAR_FIELD_CELL_DATA)
152
153 self.map = Map(scene = self.scene,
154 data_collector = self.data_collector,
155 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
156 cell_to_point = False, outline = True)
157
158 def tearDown(self):
159 del self.scene
160 del self.data_collector
161 del self.map
162
163 def test2DCellDataWithoutCellToPointConversion(self):
164 self.render("TestMap2DCellDataWithoutCellToPointConversion.jpg")
165
166 class TestMap3DPointData(unittest.TestCase, TestMap):
167 def setUp(self):
168 self.scene = \
169 Scene(renderer = JPG_RENDERER, num_viewport = 1,
170 x_size = X_SIZE, y_size = Y_SIZE)
171
172 self.data_collector = DataCollector(source = Source.XML)
173 self.data_collector.setFileName(file_name = \
174 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
175
176 self.map = Map(scene = self.scene,
177 data_collector = self.data_collector,
178 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
179 cell_to_point = False, outline = True)
180
181 def tearDown(self):
182 del self.scene
183 del self.data_collector
184 del self.map
185
186 def test3DPointData(self):
187 self.render("TestMap3DPointData.jpg")
188
189 class TestMap3DCellDataWithCellToPointConversion(unittest.TestCase, TestMap):
190 def setUp(self):
191 self.scene = \
192 Scene(renderer = JPG_RENDERER, num_viewport = 1,
193 x_size = X_SIZE, y_size = Y_SIZE)
194
195 self.data_collector = DataCollector(source = Source.XML)
196 self.data_collector.setFileName(file_name = \
197 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
198 self.data_collector.setActiveScalar(SCALAR_FIELD_CELL_DATA)
199
200 self.map = Map(scene = self.scene,
201 data_collector = self.data_collector,
202 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
203 cell_to_point = True, outline = True)
204
205 def tearDown(self):
206 del self.scene
207 del self.data_collector
208 del self.map
209
210 def test3DCellDataWithCellToPointConversion(self):
211 self.render("TestMap3DCellDataWithCellToPointConversion.jpg")
212
213 class TestMap3DCellDataWithoutCellToPointConversion(unittest.TestCase, TestMap):
214 def setUp(self):
215 self.scene = \
216 Scene(renderer = JPG_RENDERER, num_viewport = 1,
217 x_size = X_SIZE, y_size = Y_SIZE)
218
219 self.data_collector = DataCollector(source = Source.XML)
220 self.data_collector.setFileName(file_name = \
221 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
222 self.data_collector.setActiveScalar(SCALAR_FIELD_CELL_DATA)
223
224 self.map = Map(scene = self.scene,
225 data_collector = self.data_collector,
226 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
227 cell_to_point = False, outline = True)
228
229 def tearDown(self):
230 del self.scene
231 del self.data_collector
232 del self.map
233
234 def test3DCellDataWithoutCellToPointConversion(self):
235 self.render("TestMap3DCellDataWithoutCellToPointConversion.jpg")
236
237 class TestMap3DSecondOrder(unittest.TestCase, TestMap):
238 def setUp(self):
239 self.scene = \
240 Scene(renderer = JPG_RENDERER, num_viewport = 1,
241 x_size = X_SIZE, y_size = Y_SIZE)
242
243 self.data_collector = DataCollector(source = Source.XML)
244 self.data_collector.setFileName(file_name = \
245 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_SECOND_ORDER_3D))
246
247 self.map = Map(scene = self.scene,
248 data_collector = self.data_collector,
249 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
250 cell_to_point = False, outline = True)
251
252 def tearDown(self):
253 del self.scene
254 del self.data_collector
255 del self.map
256
257 def test3DSecondOrder(self):
258 self.render("TestMap3DSecondOrder.jpg")
259
260
261 class TestMapGreyScaleLut(unittest.TestCase, TestMap):
262 def setUp(self):
263 self.scene = \
264 Scene(renderer = JPG_RENDERER, num_viewport = 1,
265 x_size = X_SIZE, y_size = Y_SIZE)
266
267 self.data_collector = DataCollector(source = Source.XML)
268 self.data_collector.setFileName(file_name = \
269 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D))
270 self.data_collector.setActiveScalar(SCALAR_FIELD_CELL_DATA)
271
272 self.map = Map(scene = self.scene,
273 data_collector = self.data_collector,
274 viewport = Viewport.SOUTH_WEST, lut = Lut.GREY_SCALE,
275 cell_to_point = False, outline = True)
276
277 def tearDown(self):
278 del self.scene
279 del self.data_collector
280 del self.map
281
282 def testGreyScaleLut(self):
283 self.render("TestMapGreyScaleLut.jpg")
284
285
286 ###############################################################################
287
288
289 from esys.pyvisi import MapOnPlaneCut
290
291 class TestMapOnPlaneCut(unittest.TestCase, TestMap):
292 def setUp(self):
293 self.scene = \
294 Scene(renderer = JPG_RENDERER, num_viewport = 1,
295 x_size = X_SIZE, y_size = Y_SIZE)
296
297 self.data_collector = DataCollector(source = Source.XML)
298 self.data_collector.setFileName(file_name = \
299 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
300
301 self.map = MapOnPlaneCut(scene = self.scene,
302 data_collector = self.data_collector,
303 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
304 cell_to_point = False, outline = True)
305
306 def tearDown(self):
307 del self.scene
308 del self.data_collector
309 del self.map
310
311 def testTranslate(self):
312 self.map.setPlaneToXZ()
313 self.map.translate(0, 0.3, 0)
314 self.render("TestMapOnPlaneCut_testTranslate.jpg")
315
316 def testRotate(self):
317 self.map.setPlaneToXY()
318 self.map.rotateX(20)
319 self.map.rotateY(20)
320 self.render("TestMapOnPlaneCut_testRotate.jpg")
321
322
323 ###############################################################################
324
325
326 from esys.pyvisi import MapOnPlaneClip
327
328 class TestMapOnPlaneClip(unittest.TestCase, TestMap):
329 def setUp(self):
330 self.scene = \
331 Scene(renderer = JPG_RENDERER, num_viewport = 1,
332 x_size = X_SIZE, y_size = Y_SIZE)
333
334 self.data_collector = DataCollector(source = Source.XML)
335 self.data_collector.setFileName(file_name = \
336 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
337
338 self.map = MapOnPlaneClip(scene = self.scene,
339 data_collector = self.data_collector,
340 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
341 cell_to_point = False, outline = True)
342
343 def tearDown(self):
344 del self.scene
345 del self.data_collector
346 del self.map
347
348 def testSetInsideOutOff(self):
349 self.map.setPlaneToYZ()
350 self.map.rotateZ(20)
351 self.map.setInsideOutOff()
352 self.render("TestMapOnPlaneClip_testSetInsideOutOff.jpg")
353
354
355 ###############################################################################
356
357
358 from esys.pyvisi import MapOnScalarClip
359
360 class TestMapOnScalarClip(unittest.TestCase, TestMap):
361 def setUp(self):
362 self.scene = \
363 Scene(renderer = JPG_RENDERER, num_viewport = 1,
364 x_size = X_SIZE, y_size = Y_SIZE)
365
366 self.data_collector = DataCollector(source = Source.XML)
367 self.data_collector.setFileName(file_name = \
368 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
369
370 self.map = MapOnScalarClip(scene = self.scene,
371 data_collector = self.data_collector,
372 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
373 cell_to_point = False, outline = True)
374
375 def tearDown(self):
376 del self.scene
377 del self.data_collector
378 del self.map
379
380 def testSetClipValue(self):
381 self.map.setClipValue(0)
382 self.render("TestMapOnScalarClip_testSetClipValue.jpg")
383
384
385 ###############################################################################
386
387
388 from esys.pyvisi import MapOnScalarClipWithRotation
389
390 class TestMapOnScalarClipWithRotation(unittest.TestCase, TestMap):
391 def setUp(self):
392 self.scene = \
393 Scene(renderer = JPG_RENDERER, num_viewport = 1,
394 x_size = X_SIZE, y_size = Y_SIZE)
395
396 self.data_collector = DataCollector(source = Source.XML)
397 self.data_collector.setFileName(file_name = \
398 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D_ROTATION))
399
400 self.map = MapOnScalarClipWithRotation(scene = self.scene,
401 data_collector = self.data_collector,
402 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
403 cell_to_point = False)
404
405 def tearDown(self):
406 del self.scene
407 del self.data_collector
408 del self.map
409
410 def testSetAngle(self):
411 self.map.setAngle(200)
412 self.render("TestMapOnScalarClipWithRotation_testSetAngle.jpg")
413
414
415 ###############################################################################
416
417
418 if __name__ == '__main__':
419 suite = unittest.TestSuite()
420 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOneViewport))
421 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapFourViewports))
422 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap2DCellDataWithCellToPointConversion))
423 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap2DCellDataWithoutCellToPointConversion))
424 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap3DPointData))
425 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap3DCellDataWithCellToPointConversion))
426 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap3DCellDataWithoutCellToPointConversion))
427 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapGreyScaleLut))
428 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnPlaneCut))
429 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnPlaneClip))
430 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnScalarClip))
431 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnScalarClipWithRotation))
432 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap3DSecondOrder))
433 s=unittest.TextTestRunner(verbosity=2).run(suite)
434 if not s.wasSuccessful(): sys.exit(1)
435

  ViewVC Help
Powered by ViewVC 1.1.26