1 |
""" |
2 |
@author: John Ngui |
3 |
@author: Lutz Gross |
4 |
""" |
5 |
|
6 |
import vtk |
7 |
|
8 |
class Common: |
9 |
""" |
10 |
Class that defines the common operations invoked by the components. |
11 |
""" |
12 |
|
13 |
def __init__(self, scene, data_collector = None): |
14 |
""" |
15 |
Initialize all the instance variables. |
16 |
|
17 |
@type scene: L{Scene <scene.Scene>} object |
18 |
@param scene: Scene in which components are to be added to |
19 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
20 |
object |
21 |
@param data_collector: Source of data for visualization |
22 |
""" |
23 |
|
24 |
self.scene = scene |
25 |
self.data_collector = data_collector |
26 |
self.vtk_mapper = vtk.vtkDataSetMapper() |
27 |
self.vtk_actor = vtk.vtkActor() |
28 |
|
29 |
def setMapperInput(self, component, lut = None): |
30 |
""" |
31 |
Set up the mapper and its input. |
32 |
|
33 |
@type component: String |
34 |
@param component: Component to be mapped |
35 |
@type lut: L{BlueToRed <colormap.BlueToRed>} or |
36 |
L{RedToBlue <colormap.RedToBlue>} object |
37 |
@param lut: Color lookup table to be used by the mapper |
38 |
""" |
39 |
|
40 |
self.vtk_mapper.SetInput(component) |
41 |
#eval("self.vtk_mapper.SetInput(%s)" % component) |
42 |
|
43 |
if(lut != None): |
44 |
self.vtk_mapper.SetLookupTable(lut.getLut()) |
45 |
|
46 |
def setMapperTexture(self, texture): |
47 |
""" |
48 |
Set the texture of the actor. |
49 |
|
50 |
@type texture: vtkTexture |
51 |
@param texture: Texture map of the image |
52 |
""" |
53 |
self.vtk_actor.SetTexture(texture) |
54 |
|
55 |
def setActorInput(self): |
56 |
""" |
57 |
Set up the actor and its mapper. |
58 |
""" |
59 |
self.vtk_actor.SetMapper(self.vtk_mapper) |
60 |
|
61 |
|
62 |
def addActor(self): |
63 |
""" |
64 |
Add the actor to the renderer. |
65 |
""" |
66 |
|
67 |
self.scene.getRenderer().AddActor(self.vtk_actor) |
68 |
|
69 |
def setActorOpacity(self, opacity): |
70 |
""" |
71 |
Set the opacity (transparency) of the actor. |
72 |
|
73 |
@type opacity: Number |
74 |
@param opacity: Opacity (transparency) of the actor |
75 |
""" |
76 |
|
77 |
self.vtk_actor.GetProperty().SetOpacity(opacity) |
78 |
|
79 |
def setActorColor(self, color): |
80 |
self.vtk_actor.GetProperty().SetColor(color[0], color[1], |
81 |
color[2]) |
82 |
|
83 |
def setActorRepresentation(self, representation): |
84 |
""" |
85 |
Set the representation of the actor. |
86 |
|
87 |
@type representation: String |
88 |
@param representation: Representation type (I{i.e. Wireframe}) |
89 |
""" |
90 |
|
91 |
eval("self.vtk_actor.GetProperty().SetRepresentationTo%s()" % |
92 |
representation) |
93 |
|
94 |
|
95 |
class Component: |
96 |
pass |