/[escript]/trunk/pyvisi/examples/imageLoadExample.py
ViewVC logotype

Contents of /trunk/pyvisi/examples/imageLoadExample.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 637 - (show annotations)
Thu Mar 23 10:55:31 2006 UTC (14 years, 2 months ago) by gross
File MIME type: text/x-python
File size: 3724 byte(s)
more copyright statements added
1 """
2 Example of loading and viewing an image using pyvisi
3
4 Will hopefully help me write a decent interface.
5
6 @var __author__: name of author
7 @var __license__: licence agreement
8 @var __copyright__: copyrights
9 @var __url__: url entry point on documentation
10 @var __version__: version
11 @var __date__: date of the version
12 """
13
14 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
15 http://www.access.edu.au
16 Primary Business: Queensland, Australia"""
17 __license__="""Licensed under the Open Software License version 3.0
18 http://www.opensource.org/licenses/osl-3.0.php"""
19 __author__="Paul Cochrane"
20 __url__="http://www.iservo.edu.au/esys"
21 __version__="$Revision$"
22 __date__="$Date$"
23
24
25 method = 'pyvisi'
26 format = 'pnm'
27
28 if method == 'pyvisi':
29 ## this is the pyvisi code
30 import sys
31
32 # import the python visualisation interface
33 from esys.pyvisi import *
34 # this is now where the renderer is specified
35 from esys.pyvisi.renderers.vtk import *
36
37 # set up a scene
38 scene = Scene()
39
40 if format == 'jpeg':
41 # add a jpeg image to the scene, and then load the file
42 jpegImage = JpegImage(scene)
43 jpegImage.load(fname="Flinders_eval.jpg")
44 jpegImage.render() # this should be done at the scene.render step
45
46 elif format == 'png':
47 # add png image to the scene, and then load the file
48 pngImage = PngImage(scene)
49 pngImage.load(fname="Flinders_eval.png")
50 pngImage.render()
51
52 elif format == 'bmp':
53 # add bmp image to the scene, and then load the file
54 bmpImage = BmpImage(scene)
55 bmpImage.load(fname="Flinders_eval.bmp")
56 bmpImage.render()
57
58 elif format == 'tiff':
59 # add tiff image to the scene, and then load the file
60 tiffImage = TiffImage(scene)
61 tiffImage.load(fname="Flinders_eval.tiff")
62 tiffImage.render()
63
64 elif format == 'pnm':
65 # add pnm (ppm, pgm, pbm) image to the scene, and then load the file
66 pnmImage = PnmImage(scene)
67 pnmImage.load(fname="Flinders_eval.pnm")
68 pnmImage.render()
69
70 else:
71 raise ValueError, "Unknown format: %s" % format
72
73 # render the scene, pausing so that the opengl window doesn't disappear
74 scene.render(pause=True,interactive=True)
75
76 elif method == 'vtk':
77 ## this is the original vtk code
78
79 import vtk
80 _ren = vtk.vtkRenderer()
81 _renWin = vtk.vtkRenderWindow()
82 _renWin.AddRenderer(_ren)
83
84 _imgActor = vtk.vtkImageActor()
85
86 if format == 'jpeg':
87 _jpegReader = vtk.vtkJPEGReader()
88 _jpegReader.SetFileName("Flinders_eval.jpg")
89 _imgActor.SetInput(_jpegReader.GetOutput())
90
91 elif format == 'png':
92 _pngReader = vtk.vtkPNGReader()
93 _pngReader.SetFileName("Flinders_eval.png")
94 _imgActor.SetInput(_pngReader.GetOutput())
95
96 elif format == 'bmp':
97 _bmpReader = vtk.vtkBMPReader()
98 _bmpReader.SetFileName("Flinders_eval.bmp")
99 _imgActor.SetInput(_bmpReader.GetOutput())
100
101 elif format == 'tiff':
102 _tiffReader = vtk.vtkTIFFReader()
103 _tiffReader.SetFileName("Flinders_eval.tiff")
104 _imgActor.SetInput(_tiffReader.GetOutput())
105
106 elif format == 'pnm':
107 _pnmReader = vtk.vtkPNMReader()
108 _pnmReader.SetFileName("Flinders_eval.pnm")
109 _imgActor.SetInput(_pnmReader.GetOutput())
110
111 else:
112 raise ValueError, "Unknown format: %s" % format
113
114 _ren.AddActor(_imgActor)
115 _renWin.SetSize(400,400)
116 _ren.SetBackground(0.1,0.2,0.4)
117 _renWin.Render()
118 raw_input("Press any key to continue")
119
120 else:
121 print "Eeek! What plotting method am I supposed to use???"
122
123 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26