/[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 2344 - (show annotations)
Mon Mar 30 02:13:58 2009 UTC (10 years, 6 months ago) by jfenwick
File MIME type: text/x-python
File size: 4783 byte(s)
Change __url__ to launchpad site

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 from esys.pyvisi import DataCollector, Scene, Contour, ContourOnPlaneCut
23 from esys.pyvisi import ContourOnPlaneClip, Camera
24 from esys.pyvisi.constant import *
25 from esys.escript import getMPISizeWorld
26 import unittest, os, sys
27 from stat import ST_SIZE
28
29 try:
30 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
31 except KeyError:
32 PYVISI_WORKDIR='.'
33 try:
34 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
35 except KeyError:
36 PYVISI_TEST_DATA_ROOT='.'
37
38 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
39 PYVISI_TEST_CONTOUR_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
40 "data_sample_images", "contour")
41
42 MIN_IMAGE_SIZE = 100
43 FILE_3D = "interior_3D.xml"
44 X_SIZE = 400
45 Y_SIZE = 400
46 JPG_RENDERER = Renderer.OFFLINE_JPG
47
48 class TestContourWithLazyEvaluation:
49 def render(self, file):
50 self.scene.render(image_name = \
51 os.path.join(PYVISI_TEST_CONTOUR_IMAGES_PATH, file))
52
53 self.failUnless(os.stat(os.path.join(PYVISI_TEST_CONTOUR_IMAGES_PATH, \
54 file))[ST_SIZE] > MIN_IMAGE_SIZE)
55
56 class TestContourGenerate(unittest.TestCase, TestContourWithLazyEvaluation):
57 def tearDown(self):
58 del self.scene
59
60 def testContourGenerate(self):
61 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
62 y_size = Y_SIZE)
63 self.scene = s
64
65 dc1 = DataCollector(source = Source.XML)
66
67 # Create one contour instance.
68 ctr1 = Contour(scene = s, data_collector = dc1,
69 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True)
70 ctr1.generateContours(contours = 6, lower_range = 0, upper_range = 0.5)
71
72 cam1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
73 cam1.elevation(angle = -40)
74
75 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
76 FILE_3D))
77 self.render("TestContourWithLazyEvaluation.jpg")
78
79
80 class TestContourOnPlaneCut(unittest.TestCase, TestContourWithLazyEvaluation):
81 def tearDown(self):
82 del self.scene
83
84 def testContourOnPlaneCut(self):
85 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
86 y_size = Y_SIZE)
87 self.scene = s
88
89 dc1 = DataCollector(source = Source.XML)
90
91 # Create one contour on plane cut instance.
92 ctropc1 = ContourOnPlaneCut(scene = s, data_collector = dc1,
93 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True)
94 ctropc1.setPlaneToXY(offset = 0.2)
95
96 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
97 c1.elevation(angle = -45)
98
99 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
100 FILE_3D))
101 ctropc1.generateContours(contours = 8)
102
103 self.render("TestContourOnPlaneCutWithLazyEvaluation.jpg")
104
105 class TestContourOnPlaneClip(unittest.TestCase, TestContourWithLazyEvaluation):
106 def tearDown(self):
107 del self.scene
108
109 def testContourOnPlaneClip(self):
110 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
111 y_size = Y_SIZE)
112 self.scene = s
113
114 dc1 = DataCollector(source = Source.XML)
115
116 # Create one contour on plance clip instance.
117 ctropc1 = ContourOnPlaneClip(scene = s, data_collector = dc1,
118 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
119 outline = True)
120 ctropc1.setPlaneToXY()
121 ctropc1.rotateY(angle = 10)
122 ctropc1.generateContours(contours = 8)
123
124 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
125 c1.elevation(angle = -40)
126
127 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH,
128 FILE_3D))
129 self.render("TestContourOnPlaneClipWithLazyEvaluation.jpg")
130
131
132 ##############################################################################
133
134
135 if __name__ == '__main__':
136 if getMPISizeWorld() == 1:
137 suite = unittest.TestSuite()
138 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestContourGenerate))
139 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestContourOnPlaneCut))
140 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestContourOnPlaneClip))
141 s=unittest.TextTestRunner(verbosity=2).run(suite)
142 if not s.wasSuccessful(): sys.exit(1)
143 else:
144 print "run_contour_with_lazy_evaluation.py is not executed as more than one processor is used."
145

  ViewVC Help
Powered by ViewVC 1.1.26