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

Contents of /trunk/pyvisi/test/python/run_movie_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, 1 month ago) by jongui
File MIME type: text/x-python
File size: 3631 byte(s)
- Updated the epydocs and guide.
Deleted redundant files and methods.
Tidied up the codes.
1 from esys.pyvisi import Scene, DataCollector, Map, Camera, Velocity, Legend
2 from esys.pyvisi import Movie, LocalPosition
3 from esys.pyvisi.constant import *
4 import unittest, os
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_MOVIE_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
18 "data_sample_images", "movie")
19
20 MIN_IMAGE_SIZE = 100
21 X_SIZE = 400
22 Y_SIZE = 400
23
24 SCALAR_FIELD_POINT_DATA = "temp"
25 FILE_2D = "tempvel-"
26 IMAGE_NAME = "TestMovie"
27 JPG_RENDERER = Renderer.OFFLINE_JPG
28
29 class TestMovie:
30 def render(self, file):
31 self.scene.render(image_name = \
32 os.path.join(PYVISI_TEST_MOVIE_IMAGES_PATH, file))
33
34 self.failUnless(os.stat(os.path.join(PYVISI_TEST_MOVIE_IMAGES_PATH,\
35 file))[ST_SIZE] > MIN_IMAGE_SIZE)
36
37 class TestGenerateMovie(unittest.TestCase, TestMovie):
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.setActiveScalar(scalar = SCALAR_FIELD_POINT_DATA)
45
46
47 # Create a Contour.
48 self.map = Map(scene = self.scene,
49 data_collector = self.data_collector,
50 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
51 cell_to_point = False, outline = True)
52
53 self.velocity = Velocity(scene = self.scene,
54 data_collector = self.data_collector,
55 viewport = Viewport.SOUTH_WEST, arrow = Arrow.TWO_D,
56 color_mode = ColorMode.VECTOR, lut = Lut.COLOR,
57 cell_to_point = False, outline = True)
58
59 self.velocity.setScaleFactor(scale_factor = 0.07)
60 self.velocity.setRatio(ratio = 8)
61 self.velocity.setColor(color = Color.BLACK)
62
63 self.mov = Movie()
64 self.lst = []
65 self.cam = Camera(scene = self.scene, viewport = Viewport.SOUTH_WEST)
66
67 def tearDown(self):
68 del self.scene
69 del self.data_collector
70 del self.velocity
71 del self.map
72 del self.cam
73 del self.mov
74 del self.lst
75
76 def testMovieRange(self):
77
78 for i in range(938, 949):
79 self.data_collector.setFileName(file_name = \
80 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D + "%06d.vtu")
81 % i)
82
83 self.render(IMAGE_NAME + "%06d.jpg" % i)
84
85 self.mov.imageRange(input_directory = PYVISI_TEST_MOVIE_IMAGES_PATH,
86 first_image = IMAGE_NAME + "000938.jpg",
87 last_image = IMAGE_NAME + "000948.jpg")
88
89 self.mov.makeMovie(os.path.join(PYVISI_TEST_MOVIE_IMAGES_PATH, \
90 "movie_testMovieRange.mpg"))
91
92 self.failUnless(os.stat(os.path.join(PYVISI_TEST_MOVIE_IMAGES_PATH,\
93 "movie_testMovieRange.mpg"))[ST_SIZE] > MIN_IMAGE_SIZE)
94
95
96 def testMovieList(self):
97
98 for i in range(938, 949):
99 self.data_collector.setFileName(file_name = \
100 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D + "%06d.vtu")
101 % i)
102
103 self.render(IMAGE_NAME + "%06d.jpg" % i)
104 self.lst.append(IMAGE_NAME + "%06d.jpg" % i)
105
106 self.mov.imageList(input_directory = PYVISI_TEST_MOVIE_IMAGES_PATH,
107 image_list = self.lst)
108
109 self.mov.makeMovie(os.path.join(PYVISI_TEST_MOVIE_IMAGES_PATH, \
110 "movie_testMovieList.mpg"))
111
112 self.failUnless(os.stat(os.path.join(PYVISI_TEST_MOVIE_IMAGES_PATH,\
113 "movie_testMovieList.mpg"))[ST_SIZE] > MIN_IMAGE_SIZE)
114
115
116 ###############################################################################
117
118
119 if __name__ == '__main__':
120 suite = unittest.TestSuite()
121 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestGenerateMovie))
122 unittest.TextTestRunner(verbosity=2).run(suite)

  ViewVC Help
Powered by ViewVC 1.1.26