1 |
""" |
2 |
@author: John Ngui |
3 |
@author: Lutz Gross |
4 |
""" |
5 |
|
6 |
import vtk |
7 |
from common import * |
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. jpg) |
20 |
""" |
21 |
|
22 |
Common.__init__(self, scene) |
23 |
self.vtk_image_reader = self.determineReader(format) |
24 |
self.vtk_texture = None |
25 |
self.vtk_plane = None |
26 |
|
27 |
def determineReader(self, format): |
28 |
""" |
29 |
Determines the image format and returns the corresponding image reader. |
30 |
|
31 |
@type format: String |
32 |
@param format: Format of the image (i.e. jpg) |
33 |
@rtype: vtkImageReader2 (i.e. vtkJPEGReader) |
34 |
@return: VTK image reader |
35 |
""" |
36 |
|
37 |
if(format == "jpg"): |
38 |
return vtk.vtkJPEGReader() |
39 |
elif(format == "bmp"): |
40 |
return vtk.vtkBMPReader() |
41 |
|
42 |
def setFileName(self, file_name): |
43 |
""" |
44 |
Set the file name, and setup the mapper as well as the actor. |
45 |
|
46 |
@type file_name: String |
47 |
@param file_name: Image file name |
48 |
""" |
49 |
|
50 |
self.vtk_image_reader.SetFileName(file_name) |
51 |
|
52 |
self.setTexture() |
53 |
self.setPlane() |
54 |
|
55 |
Common.setMapper(self, "self.vtk_plane.GetOutput()") |
56 |
Common.setActor(self) |
57 |
Common.setTexture(self, self.vtk_texture) |
58 |
Common.addActor(self) |
59 |
|
60 |
def setTexture(self): |
61 |
""" |
62 |
Set the texture map. |
63 |
""" |
64 |
|
65 |
self.vtk_texture = vtk.vtkTexture() |
66 |
self.vtk_texture.SetInput(self.vtk_image_reader.GetOutput()) |
67 |
|
68 |
def setPlane(self): |
69 |
""" |
70 |
Set the texture coordinates (generated from the plane), which controls |
71 |
the positioning of the texture on a surface. |
72 |
""" |
73 |
|
74 |
self.vtk_plane = vtk.vtkPlaneSource() |
75 |
|
76 |
|
77 |
|