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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (show annotations)
Tue May 22 04:24:01 2007 UTC (12 years, 4 months ago) by jongui
File MIME type: text/x-python
File size: 3902 byte(s)
Made some changes to fix the memory leak problem. However, the problem still persists for run_escript_with_lazy_evaluation.py, run_streamline.py and run_streamline_with_lazy_evaluation.py.

1 from esys.pyvisi import DataCollector, Scene, Contour, ContourOnPlaneCut
2 from esys.pyvisi import ContourOnPlaneClip, Camera
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_CONTOUR_REFERENCE_IMAGES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT,\
18 "data_reference_images", "contour")
19 PYVISI_TEST_CONTOUR_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
20 "data_sample_images", "contour")
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 TestContourWithLazyEvaluation:
29 def render(self, file):
30 self.scene.render(image_name = \
31 os.path.join(PYVISI_TEST_CONTOUR_IMAGES_PATH, file))
32
33 self.failUnless(os.stat(os.path.join(PYVISI_TEST_CONTOUR_IMAGES_PATH, \
34 file))[ST_SIZE] > MIN_IMAGE_SIZE)
35
36 class TestContourGenerate(unittest.TestCase, TestContourWithLazyEvaluation):
37 def tearDown(self):
38 del self.scene
39
40 def testContourGenerate(self):
41 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
42 y_size = Y_SIZE)
43 self.scene = s
44
45 dc1 = DataCollector(source = Source.XML)
46
47 # Create one contour instance.
48 ctr1 = Contour(scene = s, data_collector = dc1,
49 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True)
50 ctr1.generateContours(contours = 6, lower_range = 0, upper_range = 0.5)
51
52 cam1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
53 cam1.elevation(angle = -40)
54
55 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
56 FILE_3D))
57 self.render("TestContourWithLazyEvaluation.jpg")
58
59
60 class TestContourOnPlaneCut(unittest.TestCase, TestContourWithLazyEvaluation):
61 def tearDown(self):
62 del self.scene
63
64 def testContourOnPlaneCut(self):
65 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
66 y_size = Y_SIZE)
67 self.scene = s
68
69 dc1 = DataCollector(source = Source.XML)
70
71 # Create one contour on plane cut instance.
72 ctropc1 = ContourOnPlaneCut(scene = s, data_collector = dc1,
73 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True)
74 ctropc1.setPlaneToXY(offset = 0.2)
75
76 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
77 c1.elevation(angle = -45)
78
79 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
80 FILE_3D))
81 ctropc1.generateContours(contours = 8)
82
83 self.render("TestContourOnPlaneCutWithLazyEvaluation.jpg")
84
85 class TestContourOnPlaneClip(unittest.TestCase, TestContourWithLazyEvaluation):
86 def tearDown(self):
87 del self.scene
88
89 def testContourOnPlaneClip(self):
90 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
91 y_size = Y_SIZE)
92 self.scene = s
93
94 dc1 = DataCollector(source = Source.XML)
95
96 # Create one contour on plance clip instance.
97 ctropc1 = ContourOnPlaneClip(scene = s, data_collector = dc1,
98 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
99 outline = True)
100 ctropc1.setPlaneToXY()
101 ctropc1.rotateY(angle = 10)
102 ctropc1.generateContours(contours = 8)
103
104 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
105 c1.elevation(angle = -40)
106
107 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH,
108 FILE_3D))
109 self.render("TestContourOnPlaneClipWithLazyEvaluation.jpg")
110
111
112 ##############################################################################
113
114
115 if __name__ == '__main__':
116 suite = unittest.TestSuite()
117 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestContourGenerate))
118 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestContourOnPlaneCut))
119 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestContourOnPlaneClip))
120 unittest.TextTestRunner(verbosity=2).run(suite)
121

  ViewVC Help
Powered by ViewVC 1.1.26