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

Contents of /trunk/pyvisi/test/python/run_velocity_with_lazy_evaluation.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1381 - (show annotations)
Wed Jan 9 07:59:15 2008 UTC (11 years, 5 months ago) by gross
File MIME type: text/x-python
File size: 5373 byte(s)
import sys missing
1 from esys.pyvisi import DataCollector, Scene, Velocity, VelocityOnPlaneCut
2 from esys.pyvisi import VelocityOnPlaneClip, Camera
3 from esys.pyvisi.constant import *
4 import unittest, os, sys
5 from stat import ST_SIZE
6
7 try:
8 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
9 except KeyError:
10 PYVISI_WORKDIR='.'
11 try:
12 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
13 except KeyError:
14 PYVISI_TEST_DATA_ROOT='.'
15
16 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
17 PYVISI_TEST_VELOCITY_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
18 "data_sample_images", "velocity")
19
20 MIN_IMAGE_SIZE = 100
21 FILE_3D = "results.xml"
22 X_SIZE = 400
23 Y_SIZE = 400
24
25 JPG_RENDERER = Renderer.OFFLINE_JPG
26 SCALAR_FIELD_POINT_DATA_1 = "scalar1"
27 SCALAR_FIELD_POINT_DATA_2 = "scalar2"
28 VECTOR_FIELD_POINT_DATA_1 = "vector"
29 VECTOR_FIELD_POINT_DATA_2 = "vector2"
30
31 class TestVelocityWithLazyEvaluation:
32 def render(self, file):
33 self.scene.render(image_name = \
34 os.path.join(PYVISI_TEST_VELOCITY_IMAGES_PATH, file))
35
36 self.failUnless(os.stat(os.path.join(PYVISI_TEST_VELOCITY_IMAGES_PATH,\
37 file))[ST_SIZE] > MIN_IMAGE_SIZE)
38
39 class TestVelocity(unittest.TestCase, TestVelocityWithLazyEvaluation):
40 def tearDown(self):
41 del self.scene
42
43 def testVelocity(self):
44
45 s = Scene(renderer = JPG_RENDERER, num_viewport = 4, x_size = X_SIZE,
46 y_size = Y_SIZE)
47 self.scene = s
48
49 dc1 = DataCollector(source = Source.XML)
50 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
51 FILE_3D))
52 dc1.setActiveVector(VECTOR_FIELD_POINT_DATA_1)
53 dc1.setActiveScalar(SCALAR_FIELD_POINT_DATA_2)
54
55 dc2 = DataCollector(source = Source.XML)
56 dc2.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH,\
57 FILE_3D))
58 dc2.setActiveVector(VECTOR_FIELD_POINT_DATA_1)
59 dc2.setActiveScalar(SCALAR_FIELD_POINT_DATA_1)
60
61 dc3 = DataCollector(source = Source.XML)
62 dc3.setActiveVector(VECTOR_FIELD_POINT_DATA_2)
63 dc3.setActiveScalar(SCALAR_FIELD_POINT_DATA_1)
64
65
66 # Create a velocity instance in the first viewport.
67 v1 = Velocity(scene = s, data_collector = dc1,
68 viewport = Viewport.SOUTH_WEST,
69 arrow = Arrow.THREE_D, color_mode = ColorMode.SCALAR,
70 lut = Lut.COLOR, outline = True)
71 v1.setRepresentationToWireframe()
72 v1.setScaleFactor(scale_factor = 0.3)
73 v1.setScaleModeByScalar()
74
75 # Create a velocity instance in the second viewport.
76 v2 = Velocity(scene = s, data_collector = dc2,
77 viewport = Viewport.NORTH_WEST,
78 arrow = Arrow.THREE_D, color_mode = ColorMode.SCALAR,
79 lut = Lut.COLOR, outline = True)
80 v2.setScaleModeByScalar()
81 v2.setScaleFactor(scale_factor = 0.2)
82
83 # Create a velocity instance in the third viewport.
84 v3 = Velocity(scene = s, data_collector = dc2,
85 viewport = Viewport.NORTH_EAST,
86 arrow = Arrow.TWO_D, color_mode = ColorMode.VECTOR,
87 lut = Lut.COLOR, outline = True)
88
89 # Create a velocity instance in the fourth viewport.
90 v4 = Velocity(scene = s, data_collector = dc3,
91 viewport = Viewport.SOUTH_EAST,
92 arrow = Arrow.TWO_D, color_mode = ColorMode.SCALAR,
93 lut = Lut.COLOR, outline = True)
94 v4.setOpacity(opacity = 0.5)
95 v4.setScaleModeByScalar()
96 v4.setScaleFactor(scale_factor = 0.2)
97
98 v3.setScaleFactor(scale_factor = 0.2)
99 v3.setScaleModeByVector()
100 dc3.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
101 FILE_3D))
102
103 self.render("TestVelocityWithLazyEvaluation.jpg")
104
105
106 class TestVelocityOnPlaneCut(unittest.TestCase, TestVelocityWithLazyEvaluation):
107 def tearDown(self):
108 del self.scene
109
110 def testVelocityOnPlaneCut(self):
111 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
112 y_size = Y_SIZE)
113 self.scene = s
114
115 dc1 = DataCollector(source = Source.XML)
116 dc1.setActiveVector(VECTOR_FIELD_POINT_DATA_1)
117
118 # Create a velocity instance.
119 vopc1 = VelocityOnPlaneCut(scene = s, data_collector = dc1,
120 arrow = Arrow.THREE_D, color_mode = ColorMode.VECTOR)
121 vopc1.setScaleFactor(scale_factor = 0.2)
122 vopc1.setPlaneToXY()
123
124 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
125 FILE_3D))
126
127 self.render("TestVelocityOnPlaneCutWithLazyEvaluation.jpg")
128
129
130 class TestVelocityOnPlaneClip(unittest.TestCase, TestVelocityWithLazyEvaluation):
131 def tearDown(self):
132 del self.scene
133
134 def testVelocityOnPlaneClip(self):
135 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
136 y_size = Y_SIZE)
137 self.scene = s
138
139 dc1 = DataCollector(source = Source.XML)
140
141 # Create a velocity on plane clip instance.
142 vopc1 = VelocityOnPlaneClip(scene = s, data_collector = dc1,
143 arrow = Arrow.THREE_D, color_mode = ColorMode.VECTOR)
144 vopc1.setPlaneToXZ()
145
146 c = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
147 c.isometricView()
148
149 vopc1.setScaleFactor(scale_factor = 0.2)
150 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
151 FILE_3D))
152 self.render("TestVelocityOnPlaneClipWithLazyEvaluation.jpg")
153
154
155 ###############################################################################
156
157
158 if __name__ == '__main__':
159 suite = unittest.TestSuite()
160 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVelocity))
161 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVelocityOnPlaneCut))
162 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVelocityOnPlaneClip))
163 s=unittest.TextTestRunner(verbosity=2).run(suite)
164 if not s.wasSuccessful(): sys.exit(1)
165

  ViewVC Help
Powered by ViewVC 1.1.26