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

Contents of /trunk/pyvisi/test/python/run_map_with_lazy_evaluation.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: 6302 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 # Import the necessary modules
2 from esys.pyvisi import DataCollector, Scene, Map, MapOnPlaneCut, MapOnPlaneClip
3 from esys.pyvisi import Camera, MapOnScalarClip
4 from esys.pyvisi.constant import *
5 import unittest, os
6 from stat import ST_SIZE
7
8 try:
9 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
10 except KeyError:
11 PYVISI_WORKDIR='.'
12 try:
13 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
14 except KeyError:
15 PYVISI_TEST_DATA_ROOT='.'
16
17 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
18 PYVISI_TEST_MAP_REFERENCE_IMAGES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, \
19 "data_reference_images", "map")
20 PYVISI_TEST_MAP_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
21 "data_sample_images", "map")
22
23 MIN_IMAGE_SIZE = 100
24 FILE_3D_1 = "results.xml"
25 FILE_3D_2 = "interior_3D.xml"
26 X_SIZE = 400
27 Y_SIZE = 400
28
29 JPG_RENDERER = Renderer.OFFLINE_JPG
30 SCALAR_FIELD_POINT_DATA_1 = "scalar1"
31 SCALAR_FIELD_POINT_DATA_2 = "scalar2"
32
33 class TestMapWithLazyEvaluation:
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 TestMapLazy(unittest.TestCase, TestMapWithLazyEvaluation):
42 def tearDown(self):
43 del self.scene
44
45 def testMapLazy(self):
46
47 # Create a scene with four viewports.
48 s = Scene(renderer = JPG_RENDERER, num_viewport = 4, x_size = X_SIZE,
49 y_size = Y_SIZE)
50 self.scene = s
51
52 dc1 = DataCollector(source = Source.XML)
53 dc1.setActiveScalar(scalar = SCALAR_FIELD_POINT_DATA_1)
54
55 dc2 = DataCollector(source = Source.XML)
56 dc2.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
57 FILE_3D_1))
58 dc2.setActiveScalar(scalar = SCALAR_FIELD_POINT_DATA_2)
59
60 # Create a map instance for the first viewport.
61 m1 = Map(scene = s, data_collector = dc1,
62 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True)
63
64 # Create a map instance for the second viewport.
65 m2 = Map(scene = s, data_collector = dc2,
66 viewport = Viewport.NORTH_WEST, lut = Lut.COLOR, outline = True)
67 m2.setColor(color = Color.BLUE)
68
69 # Create a map instance for the third viewport.
70 m3 = Map(scene = s, data_collector = dc1,
71 viewport = Viewport.NORTH_EAST, lut = Lut.COLOR, outline = True)
72
73 # Create a map instance the fourth viewport.
74 m4 = Map(scene = s, data_collector = dc2,
75 viewport = Viewport.SOUTH_EAST, lut = Lut.COLOR, outline = True)
76
77 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
78 FILE_3D_1))
79 m1.setRepresentationToWireframe()
80 m4.setOpacity(opacity = 0.5)
81
82 self.render("TestMapWithLazyEvaluation.jpg")
83
84 class TestMapOnPlaneCutLazy(unittest.TestCase, TestMapWithLazyEvaluation):
85 def tearDown(self):
86 del self.scene
87
88 def testMapOnPlaneCutLazy(self):
89 s = Scene(renderer = JPG_RENDERER, num_viewport = 4, x_size = X_SIZE,
90 y_size = Y_SIZE)
91 self.scene = s
92
93 # Create two data collector instances for two different sources.
94 dc1 = DataCollector(source = Source.XML)
95
96 # Create a map on plane cut instance for the first viewport.
97 mopc1 = MapOnPlaneCut(scene = s, data_collector = dc1,
98 viewport = Viewport.SOUTH_WEST)
99 mopc1.setPlaneToYZ(offset = 1.5)
100
101 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
102 c1.isometricView()
103
104 # Create three map on plane cut instances for the second viewport.
105 mopc2_1 = MapOnPlaneCut(scene = s, data_collector = dc1,
106 viewport = Viewport.NORTH_WEST)
107
108 mopc2_2 = MapOnPlaneCut(scene = s, data_collector = dc1,
109 viewport = Viewport.NORTH_WEST)
110
111 mopc2_3 = MapOnPlaneCut(scene = s, data_collector = dc1,
112 viewport = Viewport.NORTH_WEST)
113 mopc2_3.setPlaneToXY()
114 mopc2_3.translate(0,0,0.5)
115
116 c2 = Camera(scene = s, viewport = Viewport.NORTH_WEST)
117 c2.isometricView()
118
119 mopc2_1.setPlaneToYZ(offset = 1.5)
120 mopc2_2.setPlaneToXZ(offset = 1.5)
121 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
122 FILE_3D_2))
123
124 self.render("TestMapOnPlaneCutWithLazyEvaluation.jpg")
125
126
127 class TestMapOnPlaneClipLazy(unittest.TestCase, TestMapWithLazyEvaluation):
128 def tearDown(self):
129 del self.scene
130
131 def testMapOnPlaneClipLazy(self):
132 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
133 y_size = Y_SIZE)
134 self.scene = s
135
136 dc1 = DataCollector(source = Source.XML)
137
138 # Create three map on clip instances.
139 mopc1_1 = MapOnPlaneClip(scene = s, data_collector = dc1,
140 viewport = Viewport.SOUTH_WEST)
141 mopc1_1.setPlaneToXY()
142 mopc1_1.rotateX(angle = 5)
143
144 mopc1_2 = MapOnPlaneClip(scene = s, data_collector = dc1,
145 viewport = Viewport.SOUTH_WEST)
146
147 mopc1_3 = MapOnPlaneClip(scene = s, data_collector = dc1,
148 viewport = Viewport.SOUTH_WEST)
149 mopc1_3.setPlaneToXZ()
150 mopc1_3.rotateX(angle = -40)
151 mopc1_3.translate(x_offset = 0, y_offset = 2.2, z_offset = 0)
152
153 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
154 c1.isometricView()
155
156 mopc1_2.setPlaneToYZ(offset = 2.5)
157 mopc1_2.setOpacity(opacity = 0.5)
158 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
159 FILE_3D_2))
160
161 self.render("TestMapOnPlaneClipWithLazyEvaluation.jpg")
162
163
164 class TestMapOnScalarClipLazy(unittest.TestCase, TestMapWithLazyEvaluation):
165 def tearDown(self):
166 del self.scene
167
168 def testMapOnScalarClipLazy(self):
169 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
170 y_size = Y_SIZE)
171 self.scene = s
172
173 dc1 = DataCollector(source = Source.XML)
174
175 # Create a map on scalar clip instance.
176 mosc1_1 = MapOnScalarClip(scene = s, data_collector = dc1,
177 lut = Lut.GREY_SCALE)
178
179 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
180 c1.isometricView()
181
182 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
183 FILE_3D_2))
184 self.render("TestMapOnScalarClipWithLazyEvaluation.jpg")
185
186 ##############################################################################
187 if __name__ == '__main__':
188 suite = unittest.TestSuite()
189 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapLazy))
190 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnPlaneCutLazy))
191 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnPlaneClipLazy))
192 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnScalarClipLazy))
193 unittest.TextTestRunner(verbosity=2).run(suite)

  ViewVC Help
Powered by ViewVC 1.1.26