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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1168 - (show annotations)
Thu May 24 05:36:42 2007 UTC (13 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 2920 byte(s)
Pyvisi now has the capability to save the rendered objects as VRML (.wrl) and OpenInventor (.iv) file types. Corresponding tests have also been added.
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_EXPORTER_REFERENCE_IMAGES_PATH = \
18 os.path.join(PYVISI_TEST_DATA_ROOT,\
19 "data_reference_images", "exporter")
20 PYVISI_TEST_EXPORTER_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
21 "data_sample_images", "exporter")
22
23 MIN_IMAGE_SIZE = 100
24 FILE_3D = "interior_3D.xml"
25 X_SIZE = 400
26 Y_SIZE = 400
27 VRML_RENDERER = Renderer.OFFLINE_VRML
28 IV_RENDERER = Renderer.OFFLINE_IV
29
30 class TestExporter:
31 def render(self, file):
32 self.scene.render(image_name = \
33 os.path.join(PYVISI_TEST_EXPORTER_IMAGES_PATH, file))
34
35 self.failUnless(os.stat(os.path.join \
36 (PYVISI_TEST_EXPORTER_IMAGES_PATH, \
37 file))[ST_SIZE] > MIN_IMAGE_SIZE)
38
39 class TestVRMLExporter(unittest.TestCase, TestExporter):
40 def tearDown(self):
41 del self.scene
42
43 def testVRMLExporter(self):
44 s = Scene(renderer = VRML_RENDERER, num_viewport = 1, x_size = X_SIZE,
45 y_size = Y_SIZE)
46 self.scene = s
47
48 dc1 = DataCollector(source = Source.XML)
49
50 # Create one contour instance.
51 ctr1 = Contour(scene = s, data_collector = dc1,
52 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True)
53 ctr1.generateContours(contours = 6, lower_range = 0, upper_range = 0.5)
54
55 cam1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
56 cam1.elevation(angle = -40)
57
58 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
59 FILE_3D))
60 self.render("TestVRMLExporter.wrl")
61
62 class TestIVExporter(unittest.TestCase, TestExporter):
63 def tearDown(self): del self.scene
64
65 def testIVExporter(self):
66 s = Scene(renderer = IV_RENDERER, num_viewport = 1, x_size = X_SIZE,
67 y_size = Y_SIZE)
68 self.scene = s
69
70 dc1 = DataCollector(source = Source.XML)
71
72 # Create one contour on plane cut instance.
73 ctropc1 = ContourOnPlaneCut(scene = s, data_collector = dc1,
74 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True)
75 ctropc1.setPlaneToXY(offset = 0.2)
76
77 c1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
78 c1.elevation(angle = -45)
79
80 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
81 FILE_3D))
82 ctropc1.generateContours(contours = 8)
83
84 self.render("TestIVExporter.iv")
85
86
87 ##############################################################################
88
89
90 if __name__ == '__main__':
91 suite = unittest.TestSuite()
92 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVRMLExporter))
93 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestIVExporter))
94 unittest.TextTestRunner(verbosity=2).run(suite)
95

  ViewVC Help
Powered by ViewVC 1.1.26