/[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 1158 - (show annotations)
Tue May 22 04:24:01 2007 UTC (13 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 12929 byte(s)
Made some changes to fix the memory leak problem. However, the problem still persists for run_escript_with_lazy_evaluation.py, run_streamline.py and run_streamline_with_lazy_evaluation.py.

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

  ViewVC Help
Powered by ViewVC 1.1.26