/[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 1068 - (hide annotations)
Wed Mar 28 22:26:00 2007 UTC (14 years, 6 months ago) by jongui
File MIME type: text/x-python
File size: 10813 byte(s)
Added test for the velocity module.
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 jongui 1068 def testOneViewport(self):
49     self.render("TestMapOneViewport.jpg")
50 jongui 1067
51     class TestMapFourViewports(unittest.TestCase, TestMap):
52     def setUp(self):
53     self.scene = \
54     Scene(renderer = JPG_RENDERER, num_viewport = 4,
55     x_size = X_SIZE, y_size = Y_SIZE)
56    
57     self.data_collector = DataCollector(source = Source.XML)
58     self.data_collector.setFileName(file_name = \
59     PYVISI_TEST_MESHES_PATH + FILE_2D)
60    
61     self.map1 = Map(scene = self.scene,
62     data_collector = self.data_collector,
63     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
64     cell_to_point = False, outline = True)
65    
66     self.map2 = Map(scene = self.scene,
67     data_collector = self.data_collector,
68     viewport = Viewport.NORTH_WEST, lut = Lut.COLOR,
69     cell_to_point = False, outline = True)
70    
71     self.map3 = Map(scene = self.scene,
72     data_collector = self.data_collector,
73     viewport = Viewport.NORTH_EAST, lut = Lut.COLOR,
74     cell_to_point = False, outline = True)
75    
76     self.map4 = Map(scene = self.scene,
77     data_collector = self.data_collector,
78     viewport = Viewport.SOUTH_EAST, lut = Lut.COLOR,
79     cell_to_point = False, outline = True)
80    
81     def tearDown(self):
82     self.scene
83     self.data_collector
84     self.map1
85     self.map2
86     self.map3
87     self.map4
88    
89     def testSetOpacity(self):
90     self.map1.setOpacity(0.2)
91     self.map2.setOpacity(0.4)
92     self.map3.setOpacity(0.6)
93     self.map4.setOpacity(0.8)
94     self.render("TestMapFourViewports_testSetOpacity.jpg")
95    
96     def testSetColor(self):
97     self.map1.setColor(Color.GREY)
98     self.map3.setColor(Color.YELLOW)
99     self.render("TestMapFourViewports_testSetColor.jpg")
100    
101     def testSetRepresentationToWireframe(self):
102     self.map2.setRepresentationToWireframe()
103     self.map4.setRepresentationToWireframe()
104     self.render("TestMapFourViewports_testSetRepresentationToWireframe.jpg")
105    
106     class TestMap2DCellDataWithCellToPointConversion(unittest.TestCase, TestMap):
107     def setUp(self):
108     self.scene = \
109     Scene(renderer = JPG_RENDERER, num_viewport = 1,
110     x_size = X_SIZE, y_size = Y_SIZE)
111    
112     self.data_collector = DataCollector(source = Source.XML)
113     self.data_collector.setFileName(file_name = \
114     PYVISI_TEST_MESHES_PATH + FILE_2D)
115     self.data_collector.setActiveScalar(SCALAR_FIELD_CELL_DATA)
116    
117     self.map = Map(scene = self.scene,
118     data_collector = self.data_collector,
119     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
120     cell_to_point = True, outline = True)
121    
122     def test2DCellDataWithCellToPointConversion(self):
123     self.render("TestMap2DCellDataWithCellToPointConversion.jpg")
124    
125     class TestMap2DCellDataWithoutCellToPointConversion(unittest.TestCase, TestMap):
126     def setUp(self):
127     self.scene = \
128     Scene(renderer = JPG_RENDERER, num_viewport = 1,
129     x_size = X_SIZE, y_size = Y_SIZE)
130    
131     self.data_collector = DataCollector(source = Source.XML)
132     self.data_collector.setFileName(file_name = \
133     PYVISI_TEST_MESHES_PATH + FILE_2D)
134     self.data_collector.setActiveScalar(SCALAR_FIELD_CELL_DATA)
135    
136     self.map = Map(scene = self.scene,
137     data_collector = self.data_collector,
138     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
139     cell_to_point = False, outline = True)
140    
141     def test2DCellDataWithoutCellToPointConversion(self):
142     self.render("TestMap2DCellDataWithoutCellToPointConversion.jpg")
143    
144     class TestMap3DPointData(unittest.TestCase, TestMap):
145     def setUp(self):
146     self.scene = \
147     Scene(renderer = JPG_RENDERER, num_viewport = 1,
148     x_size = X_SIZE, y_size = Y_SIZE)
149    
150     self.data_collector = DataCollector(source = Source.XML)
151     self.data_collector.setFileName(file_name = \
152     PYVISI_TEST_MESHES_PATH + FILE_3D)
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 test3DPointData(self):
160     self.render("TestMap3DPointData.jpg")
161    
162     class TestMap3DCellDataWithCellToPointConversion(unittest.TestCase, TestMap):
163     def setUp(self):
164     self.scene = \
165     Scene(renderer = JPG_RENDERER, num_viewport = 1,
166     x_size = X_SIZE, y_size = Y_SIZE)
167    
168     self.data_collector = DataCollector(source = Source.XML)
169     self.data_collector.setFileName(file_name = \
170     PYVISI_TEST_MESHES_PATH + FILE_3D)
171     self.data_collector.setActiveScalar(SCALAR_FIELD_CELL_DATA)
172    
173     self.map = Map(scene = self.scene,
174     data_collector = self.data_collector,
175     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
176     cell_to_point = True, outline = True)
177    
178     def test3DCellDataWithCellToPointConversion(self):
179     self.render("TestMap3DCellDataWithCellToPointConversion.jpg")
180    
181     class TestMap3DCellDataWithoutCellToPointConversion(unittest.TestCase, TestMap):
182     def setUp(self):
183     self.scene = \
184     Scene(renderer = JPG_RENDERER, num_viewport = 1,
185     x_size = X_SIZE, y_size = Y_SIZE)
186    
187     self.data_collector = DataCollector(source = Source.XML)
188     self.data_collector.setFileName(file_name = \
189     PYVISI_TEST_MESHES_PATH + FILE_3D)
190     self.data_collector.setActiveScalar(SCALAR_FIELD_CELL_DATA)
191    
192     self.map = Map(scene = self.scene,
193     data_collector = self.data_collector,
194     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
195     cell_to_point = False, outline = True)
196    
197     def test3DCellDataWithoutCellToPointConversion(self):
198     self.render("TestMap3DCellDataWithoutCellToPointConversion.jpg")
199    
200     class TestMapGreyScaleLut(unittest.TestCase, TestMap):
201     def setUp(self):
202     self.scene = \
203     Scene(renderer = JPG_RENDERER, num_viewport = 1,
204     x_size = X_SIZE, y_size = Y_SIZE)
205    
206     self.data_collector = DataCollector(source = Source.XML)
207     self.data_collector.setFileName(file_name = \
208     PYVISI_TEST_MESHES_PATH + FILE_2D)
209     self.data_collector.setActiveScalar(SCALAR_FIELD_CELL_DATA)
210    
211     self.map = Map(scene = self.scene,
212     data_collector = self.data_collector,
213     viewport = Viewport.SOUTH_WEST, lut = Lut.GREY_SCALE,
214     cell_to_point = False, outline = True)
215    
216     def testGreyScaleLut(self):
217     self.render("TestMapGreyScaleLut.jpg")
218    
219    
220     ###############################################################################
221    
222    
223     from esys.pyvisi import MapOnPlaneCut
224    
225     class TestMapOnPlaneCut(unittest.TestCase, TestMap):
226     def setUp(self):
227     self.scene = \
228     Scene(renderer = JPG_RENDERER, num_viewport = 1,
229     x_size = X_SIZE, y_size = Y_SIZE)
230    
231     self.data_collector = DataCollector(source = Source.XML)
232     self.data_collector.setFileName(file_name = \
233     PYVISI_TEST_MESHES_PATH + FILE_3D)
234    
235     self.map = MapOnPlaneCut(scene = self.scene,
236     data_collector = self.data_collector,
237     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
238     cell_to_point = False, outline = True)
239    
240     def testTranslate(self):
241     self.map.setPlaneToXZ()
242     self.map.translate(0, 0.3, 0)
243     self.render("TestMapOnPlaneCut_testTranslate.jpg")
244    
245     def testRotate(self):
246     self.map.setPlaneToXY()
247     self.map.rotateX(20)
248     self.map.rotateY(20)
249     self.render("TestMapOnPlaneCut_testRotate.jpg")
250    
251    
252     ###############################################################################
253    
254    
255     from esys.pyvisi import MapOnPlaneClip
256    
257     class TestMapOnPlaneClip(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     PYVISI_TEST_MESHES_PATH + FILE_3D)
266    
267     self.map = MapOnPlaneClip(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 testSetInsideOutOff(self):
273     self.map.setPlaneToYZ()
274     self.map.rotateZ(20)
275     self.map.setInsideOutOff()
276     self.render("TestMapOnPlaneClip_testSetInsideOutOff.jpg")
277    
278    
279     ###############################################################################
280    
281    
282     from esys.pyvisi import MapOnScalarClip
283    
284     class TestMapOnScalarClip(unittest.TestCase, TestMap):
285     def setUp(self):
286     self.scene = \
287     Scene(renderer = JPG_RENDERER, num_viewport = 1,
288     x_size = X_SIZE, y_size = Y_SIZE)
289    
290     self.data_collector = DataCollector(source = Source.XML)
291     self.data_collector.setFileName(file_name = \
292     PYVISI_TEST_MESHES_PATH + FILE_3D)
293    
294     self.map = MapOnScalarClip(scene = self.scene,
295     data_collector = self.data_collector,
296     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
297     cell_to_point = False, outline = True)
298    
299     def testSetClipValue(self):
300     self.map.setClipValue(0)
301     self.render("TestMapOnScalarClip_testSetClipValue.jpg")
302    
303    
304     ###############################################################################
305    
306    
307     if __name__ == '__main__':
308     suite = unittest.TestSuite()
309     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOneViewport))
310     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapFourViewports))
311     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap2DCellDataWithCellToPointConversion))
312     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap2DCellDataWithoutCellToPointConversion))
313     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap3DPointData))
314     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap3DCellDataWithCellToPointConversion))
315     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMap3DCellDataWithoutCellToPointConversion))
316     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapGreyScaleLut))
317     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnPlaneCut))
318     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnPlaneClip))
319     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnScalarClip))
320    
321     unittest.TextTestRunner(verbosity=2).run(suite)
322    

  ViewVC Help
Powered by ViewVC 1.1.26