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

  ViewVC Help
Powered by ViewVC 1.1.26