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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1161 - (show annotations)
Wed May 23 04:17:52 2007 UTC (12 years ago) by jongui
File MIME type: text/x-python
File size: 4376 byte(s)
Made some minor updates to the test.
1 from esys.pyvisi import DataCollector, Scene, StreamLine, GlobalPosition
2 from esys.pyvisi.constant import *
3 import unittest, os
4 from stat import ST_SIZE
5
6 try:
7 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
8 except KeyError:
9 PYVISI_WORKDIR='.'
10 try:
11 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
12 except KeyError:
13 PYVISI_TEST_DATA_ROOT='.'
14
15 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
16 PYVISI_TEST_STREAMLINE_REFERENCE_IMAGES_PATH = \
17 os.path.join(PYVISI_TEST_DATA_ROOT, \
18 "data_reference_images", "streamline")
19 PYVISI_TEST_STREAMLINE_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
20 "data_sample_images", "streamline")
21
22 MIN_IMAGE_SIZE = 100
23 FILE_3D = "interior_3D.xml"
24 X_SIZE = 400
25 Y_SIZE = 400
26 JPG_RENDERER = Renderer.OFFLINE_JPG
27
28 class TestStreamLine:
29 def render(self, file):
30 self.scene.render(image_name = \
31 os.path.join(PYVISI_TEST_STREAMLINE_IMAGES_PATH, file))
32
33 self.failUnless(os.stat(os.path.join(\
34 PYVISI_TEST_STREAMLINE_IMAGES_PATH, file))[ST_SIZE] > \
35 MIN_IMAGE_SIZE)
36
37 class TestStreamLinePointSource(unittest.TestCase, TestStreamLine):
38 def setUp(self):
39 self.scene = \
40 Scene(renderer = JPG_RENDERER, num_viewport = 1,
41 x_size = X_SIZE, y_size = Y_SIZE)
42
43 self.data_collector = DataCollector(source = Source.XML)
44 self.data_collector.setFileName(file_name = \
45 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
46
47 self.streamline = StreamLine(scene = self.scene,
48 data_collector = self.data_collector,
49 viewport = Viewport.SOUTH_WEST, color_mode = ColorMode.VECTOR,
50 lut = Lut.COLOR, cell_to_point = False, outline = True)
51
52 def tearDown(self):
53 del self.scene
54 del self.data_collector
55 del self.streamline
56
57 def testPointSource(self):
58 self.streamline.setPointSourceRadius(0.1)
59 self.streamline.setPointSourceCenter(GlobalPosition(1.3, 1.3, 0.4))
60 self.streamline.setPointSourceNumberOfPoints(2)
61 self.render("TestStreamLinePointSource.jpg")
62
63 class TestStreamLineModule(unittest.TestCase, TestStreamLine):
64 def setUp(self):
65 self.scene = \
66 Scene(renderer = JPG_RENDERER, num_viewport = 1,
67 x_size = X_SIZE, y_size = Y_SIZE)
68
69 self.data_collector = DataCollector(source = Source.XML)
70 self.data_collector.setFileName(file_name = \
71 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
72
73 self.streamline = StreamLine(scene = self.scene,
74 data_collector = self.data_collector,
75 viewport = Viewport.SOUTH_WEST, color_mode = ColorMode.VECTOR,
76 lut = Lut.COLOR, cell_to_point = False, outline = True)
77
78 def tearDown(self):
79 del self.scene
80 del self.data_collector
81 del self.streamline
82
83 def testStreamLineModule(self):
84 self.streamline.setMaximumPropagationTime(20)
85 self.streamline.setStepLength(0.1)
86 self.streamline.setIntegrationStepLength(0.1)
87 self.streamline.setIntegrationToBothDirections()
88 self.render("TestStreamLineModule.jpg")
89
90 class TestStreamLineTube(unittest.TestCase, TestStreamLine):
91 def setUp(self):
92 self.scene = \
93 Scene(renderer = JPG_RENDERER, num_viewport = 1,
94 x_size = X_SIZE, y_size = Y_SIZE)
95
96 self.data_collector = DataCollector(source = Source.XML)
97 self.data_collector.setFileName(file_name = \
98 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
99
100 self.streamline = StreamLine(scene = self.scene,
101 data_collector = self.data_collector,
102 viewport = Viewport.SOUTH_WEST, color_mode = ColorMode.SCALAR,
103 lut = Lut.COLOR, cell_to_point = False, outline = True)
104
105 def tearDown(self):
106 del self.scene
107 del self.data_collector
108 del self.streamline
109
110 def testSetTubeRadiusToVaryByVector(self):
111 self.streamline.setTubeRadius(0.02)
112 self.streamline.setTubeNumberOfSides(3)
113 self.streamline.setTubeRadiusToVaryByVector()
114 self.render("TestStreamLineTube_testSetTubeRadiusToVaryByVector.jpg")
115
116 def testSetTubeRadiusToVaryByScalar(self):
117 self.streamline.setTubeRadiusToVaryByScalar()
118 self.render("TestStreamLineTube_testSetTubeRadiusToVaryByScalar.jpg")
119
120
121 ##############################################################################
122
123
124 if __name__ == '__main__':
125 suite = unittest.TestSuite()
126 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestStreamLinePointSource))
127 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestStreamLineModule))
128 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestStreamLineTube))
129 unittest.TextTestRunner(verbosity=2).run(suite)
130

  ViewVC Help
Powered by ViewVC 1.1.26