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

  ViewVC Help
Powered by ViewVC 1.1.26