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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1384 - (hide annotations)
Fri Jan 11 02:29:38 2008 UTC (11 years, 9 months ago) by phornby
Original Path: temp_trunk_copy/pyvisi/test/python/run_contour_with_lazy_evaluation.py
File MIME type: text/x-python
File size: 3836 byte(s)
Make a temp copy of the trunk before checking in the windows changes


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

  ViewVC Help
Powered by ViewVC 1.1.26