1 |
""" |
2 |
@author: John Ngui |
3 |
@author: Lutz Gross |
4 |
""" |
5 |
|
6 |
import vtk |
7 |
from common import Common |
8 |
|
9 |
class Image(Common): |
10 |
""" |
11 |
Class that displays an image. |
12 |
""" |
13 |
|
14 |
def __init__(self, scene, format): |
15 |
""" |
16 |
@type scene: L{Scene <scene.Scene>} object |
17 |
@param scene: Scene in which components are to be added to |
18 |
@type format: String |
19 |
@param format: Format of the image (i.e. jpeg) |
20 |
""" |
21 |
|
22 |
Common.__init__(self, scene) |
23 |
self.vtk_image_reader = self.getImageReader(format) |
24 |
self.vtk_texture = vtk.vtkTexture() |
25 |
|
26 |
def getImageReader(self, format): |
27 |
""" |
28 |
Determine the image format and return the corresponding image reader. |
29 |
@type format: String |
30 |
@param format: Format of the image |
31 |
@rtype: vtkImageReader2 (i.e. vtkJPEGReader) |
32 |
@return: VTK image reader that is used to read an image |
33 |
""" |
34 |
|
35 |
if(format == "jpeg"): |
36 |
return vtk.vtkJPEGReader() |
37 |
elif(format == "bmp"): |
38 |
return vtk.vtkBMPReader() |
39 |
elif(format == "pnm"): |
40 |
return vtk.vtkPNMReader() |
41 |
elif(format == "png"): |
42 |
return vtk.vtkPNGReader() |
43 |
elif(format == "tiff"): |
44 |
return vtk.vtkTIFFReader() |
45 |
|
46 |
def setFileName(self, file_name): |
47 |
""" |
48 |
Set the file name, setup the mapper and the actor. |
49 |
@type file_name: String |
50 |
@param file_name: Image file name from which data is to be read |
51 |
""" |
52 |
|
53 |
vtk_plane = vtk.vtkPlaneSource() |
54 |
self.vtk_image_reader.SetFileName(file_name) |
55 |
self.setTexture() |
56 |
|
57 |
Common.setMapperInput(self, vtk_plane.GetOutput()) |
58 |
Common.setActorTexture(self, self.vtk_texture) |
59 |
Common.setActorInput(self) |
60 |
Common.addActor(self) |
61 |
|
62 |
def setTexture(self): |
63 |
""" |
64 |
Set the texture map. |
65 |
""" |
66 |
|
67 |
self.vtk_texture.SetInput(self.vtk_image_reader.GetOutput()) |
68 |
|
69 |
|