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

  ViewVC Help
Powered by ViewVC 1.1.26