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

  ViewVC Help
Powered by ViewVC 1.1.26