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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1151 - (hide annotations)
Thu May 17 04:11:18 2007 UTC (13 years, 5 months ago) by jongui
File MIME type: text/x-python
File size: 6181 byte(s)
More update.
1 jongui 1148 # 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 tearDown(self):
35     self.scene
36    
37     def render(self, file):
38     self.scene.render(image_name = \
39     os.path.join(PYVISI_TEST_MAP_IMAGES_PATH, file))
40    
41     self.failUnless(os.stat(os.path.join(PYVISI_TEST_MAP_IMAGES_PATH, \
42     file))[ST_SIZE] > MIN_IMAGE_SIZE)
43    
44 jongui 1151 class TestMapLazy(unittest.TestCase, TestMapWithLazyEvaluation):
45     def testMapLazy(self):
46 jongui 1148
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 jongui 1151 class TestMapOnPlaneCutLazy(unittest.TestCase, TestMapWithLazyEvaluation):
85     def testMapOnPlaneCutLazy(self):
86 jongui 1148 s = Scene(renderer = JPG_RENDERER, num_viewport = 4, x_size = X_SIZE,
87     y_size = Y_SIZE)
88     self.scene = s
89    
90     # Create two data collector instances for two different sources.
91     dc1 = DataCollector(source = Source.XML)
92    
93     # Create a map on plane cut instance for the first viewport.
94     mopc1 = MapOnPlaneCut(scene = s, data_collector = dc1,
95     viewport = Viewport.SOUTH_WEST)
96     mopc1.setPlaneToYZ(offset = 1.5)
97    
98     c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
99     c1.isometricView()
100    
101     # Create three map on plane cut instances for the second viewport.
102     mopc2_1 = MapOnPlaneCut(scene = s, data_collector = dc1,
103     viewport = Viewport.NORTH_WEST)
104    
105     mopc2_2 = MapOnPlaneCut(scene = s, data_collector = dc1,
106     viewport = Viewport.NORTH_WEST)
107    
108     mopc2_3 = MapOnPlaneCut(scene = s, data_collector = dc1,
109     viewport = Viewport.NORTH_WEST)
110     mopc2_3.setPlaneToXY()
111     mopc2_3.translate(0,0,0.5)
112    
113     c2 = Camera(scene = s, viewport = Viewport.NORTH_WEST)
114     c2.isometricView()
115    
116     mopc2_1.setPlaneToYZ(offset = 1.5)
117     mopc2_2.setPlaneToXZ(offset = 1.5)
118     dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
119     FILE_3D_2))
120    
121     self.render("TestMapOnPlaneCutWithLazyEvaluation.jpg")
122    
123    
124 jongui 1151 class TestMapOnPlaneClipLazy(unittest.TestCase, TestMapWithLazyEvaluation):
125     def testMapOnPlaneClipLazy(self):
126 jongui 1148 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
127     y_size = Y_SIZE)
128     self.scene = s
129    
130     dc1 = DataCollector(source = Source.XML)
131    
132     # Create three map on clip instances.
133     mopc1_1 = MapOnPlaneClip(scene = s, data_collector = dc1,
134     viewport = Viewport.SOUTH_WEST)
135     mopc1_1.setPlaneToXY()
136     mopc1_1.rotateX(angle = 5)
137    
138     mopc1_2 = MapOnPlaneClip(scene = s, data_collector = dc1,
139     viewport = Viewport.SOUTH_WEST)
140    
141     mopc1_3 = MapOnPlaneClip(scene = s, data_collector = dc1,
142     viewport = Viewport.SOUTH_WEST)
143     mopc1_3.setPlaneToXZ()
144     mopc1_3.rotateX(angle = -40)
145     mopc1_3.translate(x_offset = 0, y_offset = 2.2, z_offset = 0)
146    
147     c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
148     c1.isometricView()
149    
150     mopc1_2.setPlaneToYZ(offset = 2.5)
151     mopc1_2.setOpacity(opacity = 0.5)
152     dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
153     FILE_3D_2))
154    
155     self.render("TestMapOnPlaneClipWithLazyEvaluation.jpg")
156    
157    
158 jongui 1151 class TestMapOnScalarClipLazy(unittest.TestCase, TestMapWithLazyEvaluation):
159     def testMapOnScalarClipLazy(self):
160 jongui 1148 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
161     y_size = Y_SIZE)
162     self.scene = s
163    
164     dc1 = DataCollector(source = Source.XML)
165    
166     # Create a map on scalar clip instance.
167     mosc1_1 = MapOnScalarClip(scene = s, data_collector = dc1,
168     lut = Lut.GREY_SCALE)
169    
170     c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
171     c1.isometricView()
172    
173     dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
174     FILE_3D_2))
175     self.render("TestMapOnScalarClipWithLazyEvaluation.jpg")
176    
177     ##############################################################################
178     if __name__ == '__main__':
179     suite = unittest.TestSuite()
180 jongui 1151 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapLazy))
181     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnPlaneCutLazy))
182     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnPlaneClipLazy))
183     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestMapOnScalarClipLazy))
184 jongui 1148 unittest.TextTestRunner(verbosity=2).run(suite)

  ViewVC Help
Powered by ViewVC 1.1.26