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

  ViewVC Help
Powered by ViewVC 1.1.26