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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (show annotations)
Tue May 22 04:24:01 2007 UTC (13 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 4119 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, Ellipsoid, EllipsoidOnPlaneCut
2 from esys.pyvisi import EllipsoidOnPlaneClip, 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_ELLIPSOID_REFERENCE_IMAGES_PATH = \
18 os.path.join(PYVISI_TEST_DATA_ROOT, "data_reference_images", \
19 "ellipsoid")
20 PYVISI_TEST_ELLIPSOID_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
21 "data_sample_images", "ellipsoid")
22
23 MIN_IMAGE_SIZE = 100
24 FILE_3D = "interior_3D.xml"
25 X_SIZE = 400
26 Y_SIZE = 400
27 JPG_RENDERER = Renderer.OFFLINE_JPG
28
29 class TestEllipsoidWithLazyEvaluation:
30 def render(self, file):
31 self.scene.render(image_name = \
32 os.path.join(PYVISI_TEST_ELLIPSOID_IMAGES_PATH, file))
33
34 self.failUnless(os.stat(os.path.join(PYVISI_TEST_ELLIPSOID_IMAGES_PATH,\
35 file))[ST_SIZE] > MIN_IMAGE_SIZE)
36
37 class TestEllipsoidScaleResolution(unittest.TestCase, TestEllipsoidWithLazyEvaluation):
38 def tearDown(self):
39 del self.scene
40
41 def testEllipsoidScaleResolution(self):
42 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
43 y_size = Y_SIZE)
44 self.scene = s
45
46 dc1 = DataCollector(source = Source.XML)
47
48 # Create one ellipsoid instance.
49 e1 = Ellipsoid(scene = s, data_collector = dc1, viewport = Viewport.SOUTH_WEST,
50 lut = Lut.COLOR, outline = True)
51 e1.setScaleFactor(scale_factor = 0.2)
52 e1.setPhiResolution(resolution = 20)
53 e1.setThetaResolution(resolution = 20)
54
55 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
56 c1.isometricView()
57 c1.elevation(angle = -20)
58
59 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
60 FILE_3D))
61 self.render("TestEllipsoidWithLazyEvaluation.jpg")
62
63 class TestEllipsoidOnPlaneCut(unittest.TestCase, TestEllipsoidWithLazyEvaluation):
64 def tearDown(self):
65 del self.scene
66
67 def testEllipsoidOnPlaneCut(self):
68 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
69 y_size = Y_SIZE)
70 self.scene = s
71
72 dc1 = DataCollector(source = Source.XML)
73
74 # Create one ellipsoid on plance cut instance.
75 eopc1 = EllipsoidOnPlaneCut(scene = s, data_collector = dc1,
76 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True)
77 eopc1.setScaleFactor(scale_factor = 0.1)
78 eopc1.setPlaneToXY()
79 eopc1.rotateX(angle = 10)
80
81 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
82 c1.isometricView()
83 c1.elevation(angle = -20)
84
85 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
86 FILE_3D))
87
88 self.render("TestEllipsoidOnPlaneCutWithLazyEvaluation.jpg")
89
90 class TestEllipsoidOnPlaneClip(unittest.TestCase, TestEllipsoidWithLazyEvaluation):
91 def tearDown(self):
92 del self.scene
93
94 def testEllipsoidOnPlaneClip(self):
95 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
96 y_size = Y_SIZE)
97 self.scene = s
98
99 dc1 = DataCollector(source = Source.XML)
100
101 # Create on ellipsoid on plane clip instance.
102 eopc = EllipsoidOnPlaneClip(scene = s, data_collector = dc1,
103 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True)
104 eopc.setScaleFactor(scale_factor = 0.1)
105 eopc.setPlaneToXY()
106 eopc.rotateX(angle = 10)
107
108 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
109 c1.bottomView()
110 c1.azimuth(angle = -90)
111 c1.elevation(angle = 20)
112
113 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
114 FILE_3D))
115
116 self.render("TestEllipsoidOnPlaneClipWithLazyEvaluation.jpg")
117
118
119 ##############################################################################
120
121
122 if __name__ == '__main__':
123 suite = unittest.TestSuite()
124 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestEllipsoidScaleResolution))
125 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestEllipsoidOnPlaneCut))
126 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestEllipsoidOnPlaneClip))
127 unittest.TextTestRunner(verbosity=2).run(suite)
128

  ViewVC Help
Powered by ViewVC 1.1.26