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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 337 - (show annotations)
Mon Dec 12 01:57:07 2005 UTC (14 years, 5 months ago) by cochrane
File MIME type: text/x-python
File size: 3951 byte(s)
Initial merge of pyvisi into esys repository.
1 # Copyright (C) 2004 Paul Cochrane
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 # $Id: imageLoadExample.py,v 1.9 2005/04/29 00:32:57 paultcochrane Exp $
18
19 ## @file imageLoadExample.py
20
21 """
22 Example of loading and viewing an image using pyvisi
23
24 Will hopefully help me write a decent interface.
25 """
26
27 method = 'pyvisi'
28 format = 'pnm'
29
30 if method == 'pyvisi':
31 ## this is the pyvisi code
32 import sys
33
34 # import the python visualisation interface
35 from pyvisi import *
36 # this is now where the renderer is specified
37 from pyvisi.renderers.vtk import *
38
39 # set up a scene
40 scene = Scene()
41
42 if format == 'jpeg':
43 # add a jpeg image to the scene, and then load the file
44 jpegImage = JpegImage(scene)
45 jpegImage.load(fname="Flinders_eval.jpg")
46 jpegImage.render() # this should be done at the scene.render step
47
48 elif format == 'png':
49 # add png image to the scene, and then load the file
50 pngImage = PngImage(scene)
51 pngImage.load(fname="Flinders_eval.png")
52 pngImage.render()
53
54 elif format == 'bmp':
55 # add bmp image to the scene, and then load the file
56 bmpImage = BmpImage(scene)
57 bmpImage.load(fname="Flinders_eval.bmp")
58 bmpImage.render()
59
60 elif format == 'tiff':
61 # add tiff image to the scene, and then load the file
62 tiffImage = TiffImage(scene)
63 tiffImage.load(fname="Flinders_eval.tiff")
64 tiffImage.render()
65
66 elif format == 'pnm':
67 # add pnm (ppm, pgm, pbm) image to the scene, and then load the file
68 pnmImage = PnmImage(scene)
69 pnmImage.load(fname="Flinders_eval.pnm")
70 pnmImage.render()
71
72 else:
73 raise ValueError, "Unknown format: %s" % format
74
75 # render the scene, pausing so that the opengl window doesn't disappear
76 scene.render(pause=True,interactive=True)
77
78 elif method == 'vtk':
79 ## this is the original vtk code
80
81 import vtk
82 _ren = vtk.vtkRenderer()
83 _renWin = vtk.vtkRenderWindow()
84 _renWin.AddRenderer(_ren)
85
86 _imgActor = vtk.vtkImageActor()
87
88 if format == 'jpeg':
89 _jpegReader = vtk.vtkJPEGReader()
90 _jpegReader.SetFileName("Flinders_eval.jpg")
91 _imgActor.SetInput(_jpegReader.GetOutput())
92
93 elif format == 'png':
94 _pngReader = vtk.vtkPNGReader()
95 _pngReader.SetFileName("Flinders_eval.png")
96 _imgActor.SetInput(_pngReader.GetOutput())
97
98 elif format == 'bmp':
99 _bmpReader = vtk.vtkBMPReader()
100 _bmpReader.SetFileName("Flinders_eval.bmp")
101 _imgActor.SetInput(_bmpReader.GetOutput())
102
103 elif format == 'tiff':
104 _tiffReader = vtk.vtkTIFFReader()
105 _tiffReader.SetFileName("Flinders_eval.tiff")
106 _imgActor.SetInput(_tiffReader.GetOutput())
107
108 elif format == 'pnm':
109 _pnmReader = vtk.vtkPNMReader()
110 _pnmReader.SetFileName("Flinders_eval.pnm")
111 _imgActor.SetInput(_pnmReader.GetOutput())
112
113 else:
114 raise ValueError, "Unknown format: %s" % format
115
116 _ren.AddActor(_imgActor)
117 _renWin.SetSize(400,400)
118 _ren.SetBackground(0.1,0.2,0.4)
119 _renWin.Render()
120 raw_input("Press any key to continue")
121
122 else:
123 print "Eeek! What plotting method am I supposed to use???"
124
125 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26