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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1151 - (hide annotations)
Thu May 17 04:11:18 2007 UTC (15 years, 6 months ago) by jongui
File MIME type: text/x-python
File size: 12093 byte(s)
More update.
1 jongui 1148 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 tearDown(self):
35     self.scene
36     self.data_collector
37     self.map
38    
39     def render(self, file):
40     self.scene.render(image_name = \
41     os.path.join(PYVISI_TEST_MAP_IMAGES_PATH, file))
42    
43     self.failUnless(os.stat(os.path.join(PYVISI_TEST_MAP_IMAGES_PATH, \
44     file))[ST_SIZE] > MIN_IMAGE_SIZE)
45    
46     class TestMapOneViewport(unittest.TestCase, TestMap):
47     def setUp(self):
48     self.scene = \
49     Scene(renderer = JPG_RENDERER, num_viewport = 1,
50     x_size = X_SIZE, y_size = Y_SIZE)
51    
52     self.data_collector = DataCollector(source = Source.XML)
53     self.data_collector.setFileName(file_name = \
54     os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D))
55    
56     self.map = Map(scene = self.scene,
57     data_collector = self.data_collector,
58     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
59     cell_to_point = False, outline = True)
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     self.scene
96     self.data_collector
97     self.map1
98     self.map2
99     self.map3
100     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 test2DCellDataWithCellToPointConversion(self):
136     self.render("TestMap2DCellDataWithCellToPointConversion.jpg")
137    
138     class TestMap2DCellDataWithoutCellToPointConversion(unittest.TestCase, TestMap):
139     def setUp(self):
140     self.scene = \
141     Scene(renderer = JPG_RENDERER, num_viewport = 1,
142     x_size = X_SIZE, y_size = Y_SIZE)
143    
144     self.data_collector = DataCollector(source = Source.XML)
145     self.data_collector.setFileName(file_name = \
146     os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D))
147     self.data_collector.setActiveScalar(SCALAR_FIELD_CELL_DATA)
148    
149     self.map = Map(scene = self.scene,
150     data_collector = self.data_collector,
151     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
152     cell_to_point = False, outline = True)
153    
154     def test2DCellDataWithoutCellToPointConversion(self):
155     self.render("TestMap2DCellDataWithoutCellToPointConversion.jpg")
156    
157     class TestMap3DPointData(unittest.TestCase, TestMap):
158     def setUp(self):
159     self.scene = \
160     Scene(renderer = JPG_RENDERER, num_viewport = 1,
161     x_size = X_SIZE, y_size = Y_SIZE)
162    
163     self.data_collector = DataCollector(source = Source.XML)
164     self.data_collector.setFileName(file_name = \
165     os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
166    
167     self.map = Map(scene = self.scene,
168     data_collector = self.data_collector,
169     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
170     cell_to_point = False, outline = True)
171    
172     def test3DPointData(self):
173     self.render("TestMap3DPointData.jpg")
174    
175     class TestMap3DCellDataWithCellToPointConversion(unittest.TestCase, TestMap):
176     def setUp(self):
177     self.scene = \
178     Scene(renderer = JPG_RENDERER, num_viewport = 1,
179     x_size = X_SIZE, y_size = Y_SIZE)
180    
181     self.data_collector = DataCollector(source = Source.XML)
182     self.data_collector.setFileName(file_name = \
183     os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
184     self.data_collector.setActiveScalar(SCALAR_FIELD_CELL_DATA)
185    
186     self.map = Map(scene = self.scene,
187     data_collector = self.data_collector,
188     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
189     cell_to_point = True, outline = True)
190    
191     def test3DCellDataWithCellToPointConversion(self):
192     self.render("TestMap3DCellDataWithCellToPointConversion.jpg")
193    
194     class TestMap3DCellDataWithoutCellToPointConversion(unittest.TestCase, TestMap):
195     def setUp(self):
196     self.scene = \
197     Scene(renderer = JPG_RENDERER, num_viewport = 1,
198     x_size = X_SIZE, y_size = Y_SIZE)
199    
200     self.data_collector = DataCollector(source = Source.XML)
201     self.data_collector.setFileName(file_name = \
202     os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
203     self.data_collector.setActiveScalar(SCALAR_FIELD_CELL_DATA)
204    
205     self.map = Map(scene = self.scene,
206     data_collector = self.data_collector,
207     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
208     cell_to_point = False, outline = True)
209    
210     def test3DCellDataWithoutCellToPointConversion(self):
211     self.render("TestMap3DCellDataWithoutCellToPointConversion.jpg")
212    
213     class TestMap3DSecondOrder(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_SECOND_ORDER_3D))
222    
223     self.map = Map(scene = self.scene,
224     data_collector = self.data_collector,
225     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
226     cell_to_point = False, outline = True)
227    
228     def test3DSecondOrder(self):
229     self.render("TestMap3DSecondOrder.jpg")
230    
231    
232     class TestMapGreyScaleLut(unittest.TestCase, TestMap):
233     def setUp(self):
234     self.scene = \
235     Scene(renderer = JPG_RENDERER, num_viewport = 1,
236     x_size = X_SIZE, y_size = Y_SIZE)
237    
238     self.data_collector = DataCollector(source = Source.XML)
239     self.data_collector.setFileName(file_name = \
240     os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D))
241     self.data_collector.setActiveScalar(SCALAR_FIELD_CELL_DATA)
242    
243     self.map = Map(scene = self.scene,
244     data_collector = self.data_collector,
245     viewport = Viewport.SOUTH_WEST, lut = Lut.GREY_SCALE,
246     cell_to_point = False, outline = True)
247    
248     def testGreyScaleLut(self):
249     self.render("TestMapGreyScaleLut.jpg")
250    
251    
252     ###############################################################################
253    
254    
255     from esys.pyvisi import MapOnPlaneCut
256    
257     class TestMapOnPlaneCut(unittest.TestCase, TestMap):
258     def setUp(self):
259     self.scene = \
260     Scene(renderer = JPG_RENDERER, num_viewport = 1,
261     x_size = X_SIZE, y_size = Y_SIZE)
262    
263     self.data_collector = DataCollector(source = Source.XML)
264     self.data_collector.setFileName(file_name = \
265     os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
266    
267     self.map = MapOnPlaneCut(scene = self.scene,
268     data_collector = self.data_collector,
269     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
270     cell_to_point = False, outline = True)
271    
272     def testTranslate(self):
273     self.map.setPlaneToXZ()
274     self.map.translate(0, 0.3, 0)
275     self.render("TestMapOnPlaneCut_testTranslate.jpg")
276    
277     def testRotate(self):
278     self.map.setPlaneToXY()
279     self.map.rotateX(20)
280     self.map.rotateY(20)
281     self.render("TestMapOnPlaneCut_testRotate.jpg")
282    
283    
284     ###############################################################################
285    
286    
287     from esys.pyvisi import MapOnPlaneClip
288    
289     class TestMapOnPlaneClip(unittest.TestCase, TestMap):
290     def setUp(self):
291     self.scene = \
292     Scene(renderer = JPG_RENDERER, num_viewport = 1,
293     x_size = X_SIZE, y_size = Y_SIZE)
294    
295     self.data_collector = DataCollector(source = Source.XML)
296     self.data_collector.setFileName(file_name = \
297     os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
298    
299     self.map = MapOnPlaneClip(scene = self.scene,
300     data_collector = self.data_collector,
301     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
302     cell_to_point = False, outline = True)
303    
304     def testSetInsideOutOff(self):
305     self.map.setPlaneToYZ()
306     self.map.rotateZ(20)
307     self.map.setInsideOutOff()
308     self.render("TestMapOnPlaneClip_testSetInsideOutOff.jpg")
309    
310    
311     ###############################################################################
312    
313    
314     from esys.pyvisi import MapOnScalarClip
315    
316     class TestMapOnScalarClip(unittest.TestCase, TestMap):
317     def setUp(self):
318     self.scene = \
319     Scene(renderer = JPG_RENDERER, num_viewport = 1,
320     x_size = X_SIZE, y_size = Y_SIZE)
321    
322     self.data_collector = DataCollector(source = Source.XML)
323     self.data_collector.setFileName(file_name = \
324     os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
325    
326     self.map = MapOnScalarClip(scene = self.scene,
327     data_collector = self.data_collector,
328     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
329     cell_to_point = False, outline = True)
330    
331     def testSetClipValue(self):
332     self.map.setClipValue(0)
333     self.render("TestMapOnScalarClip_testSetClipValue.jpg")
334    
335    
336     ###############################################################################
337    
338    
339     if __name__ == '__main__':
340     suite = unittest.TestSuite()
341     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOneViewport))
342     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapFourViewports))
343     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap2DCellDataWithCellToPointConversion))
344     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap2DCellDataWithoutCellToPointConversion))
345     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap3DPointData))
346     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap3DCellDataWithCellToPointConversion))
347     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap3DCellDataWithoutCellToPointConversion))
348     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapGreyScaleLut))
349     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnPlaneCut))
350     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnPlaneClip))
351     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnScalarClip))
352     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap3DSecondOrder))
353     unittest.TextTestRunner(verbosity=2).run(suite)
354    

  ViewVC Help
Powered by ViewVC 1.1.26