1 |
gross |
802 |
""" |
2 |
jongui |
839 |
@author: John Ngui |
3 |
|
|
@author: Lutz Gross |
4 |
gross |
802 |
""" |
5 |
|
|
|
6 |
jongui |
827 |
import vtk |
7 |
gross |
802 |
|
8 |
jongui |
828 |
class Common: |
9 |
jongui |
835 |
""" |
10 |
jongui |
839 |
Class that defines the common operations invoked by the components. |
11 |
jongui |
835 |
""" |
12 |
gross |
802 |
|
13 |
jongui |
845 |
def __init__(self, scene, data_collector = None): |
14 |
jongui |
835 |
""" |
15 |
jongui |
845 |
@type scene: L{Scene <scene.Scene>} object |
16 |
jongui |
839 |
@param scene: Scene in which components are to be added to |
17 |
jongui |
835 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
18 |
|
|
object |
19 |
|
|
@param data_collector: Source of data for visualization |
20 |
|
|
""" |
21 |
|
|
|
22 |
jongui |
839 |
self.scene = scene |
23 |
jongui |
828 |
self.data_collector = data_collector |
24 |
jongui |
849 |
self.vtk_mapper = vtk.vtkDataSetMapper() |
25 |
|
|
self.vtk_actor = vtk.vtkActor() |
26 |
gross |
802 |
|
27 |
jongui |
849 |
def setMapperInput(self, component, lut = None): |
28 |
jongui |
835 |
""" |
29 |
jongui |
860 |
Set up the mapper. |
30 |
jongui |
835 |
@type component: String |
31 |
|
|
@param component: Component to be mapped |
32 |
jongui |
839 |
@type lut: L{BlueToRed <colormap.BlueToRed>} or |
33 |
|
|
L{RedToBlue <colormap.RedToBlue>} object |
34 |
jongui |
860 |
@param lut: Lookup table to be used by the mapper |
35 |
jongui |
835 |
""" |
36 |
jongui |
879 |
|
37 |
jongui |
860 |
# Convert unstructured grid data to polygonal data. |
38 |
|
|
vtk_geometry = vtk.vtkGeometryFilter() |
39 |
|
|
vtk_geometry.SetInput(component) |
40 |
|
|
|
41 |
|
|
# Compute normals to ensure consistent orientation across neighbours. |
42 |
|
|
# This results in a better object being rendered. |
43 |
jongui |
879 |
#vtk_normals = vtk.vtkPolyDataNormals() |
44 |
|
|
#vtk_normals.SetInput(vtk_geometry.GetOutput()) |
45 |
jongui |
860 |
|
46 |
jongui |
879 |
#self.vtk_mapper.SetInput(vtk_normals.GetOutput()) |
47 |
|
|
#self.vtk_mapper.SetInput(vtk_geometry.GetOutput()) |
48 |
|
|
self.vtk_mapper.SetInput(component) |
49 |
|
|
|
50 |
jongui |
860 |
|
51 |
|
|
# Mapper uses the customized lookup table only if it is specified. |
52 |
|
|
# Otherwise, the default one is used. |
53 |
jongui |
839 |
if(lut != None): |
54 |
|
|
self.vtk_mapper.SetLookupTable(lut.getLut()) |
55 |
gross |
802 |
|
56 |
jongui |
860 |
def setActorTexture(self, texture): |
57 |
jongui |
835 |
""" |
58 |
jongui |
846 |
Set the texture of the actor. |
59 |
|
|
@type texture: vtkTexture |
60 |
|
|
@param texture: Texture map of the image |
61 |
|
|
""" |
62 |
jongui |
860 |
|
63 |
jongui |
845 |
self.vtk_actor.SetTexture(texture) |
64 |
|
|
|
65 |
jongui |
849 |
def setActorInput(self): |
66 |
|
|
""" |
67 |
jongui |
860 |
Set up the actor. |
68 |
jongui |
849 |
""" |
69 |
jongui |
860 |
|
70 |
jongui |
849 |
self.vtk_actor.SetMapper(self.vtk_mapper) |
71 |
|
|
|
72 |
|
|
|
73 |
jongui |
828 |
def addActor(self): |
74 |
jongui |
835 |
""" |
75 |
|
|
Add the actor to the renderer. |
76 |
|
|
""" |
77 |
|
|
|
78 |
jongui |
839 |
self.scene.getRenderer().AddActor(self.vtk_actor) |
79 |
jongui |
828 |
|
80 |
jongui |
849 |
def setActorOpacity(self, opacity): |
81 |
jongui |
835 |
""" |
82 |
|
|
Set the opacity (transparency) of the actor. |
83 |
|
|
@type opacity: Number |
84 |
|
|
@param opacity: Opacity (transparency) of the actor |
85 |
|
|
""" |
86 |
|
|
|
87 |
jongui |
849 |
self.vtk_actor.GetProperty().SetOpacity(opacity) |
88 |
jongui |
828 |
|
89 |
jongui |
849 |
def setActorColor(self, color): |
90 |
jongui |
860 |
""" |
91 |
|
|
Set the color of the actor. |
92 |
|
|
@type color: RGB list |
93 |
|
|
@param color: Color of the actor |
94 |
|
|
""" |
95 |
|
|
|
96 |
jongui |
849 |
self.vtk_actor.GetProperty().SetColor(color[0], color[1], |
97 |
|
|
color[2]) |
98 |
jongui |
828 |
|
99 |
jongui |
849 |
def setActorRepresentation(self, representation): |
100 |
jongui |
835 |
""" |
101 |
|
|
Set the representation of the actor. |
102 |
|
|
@type representation: String |
103 |
jongui |
860 |
@param representation: Actor representation type (I{i.e. Wireframe}) |
104 |
jongui |
835 |
""" |
105 |
|
|
|
106 |
jongui |
849 |
eval("self.vtk_actor.GetProperty().SetRepresentationTo%s()" % |
107 |
|
|
representation) |
108 |
jongui |
828 |
|
109 |
jongui |
835 |
|
110 |
|
|
class Component: |
111 |
|
|
pass |