/[escript]/trunk/pyvisi/py_src/common.py
ViewVC logotype

Contents of /trunk/pyvisi/py_src/common.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 860 - (show annotations)
Thu Sep 28 08:17:29 2006 UTC (14 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 2660 byte(s)
- added sample drivers on how to use all of the currently available modules.
- completed the epydocs for all the currently available modules.
- added the rotation feature for camera and plane cutting.


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 @type scene: L{Scene <scene.Scene>} object
16 @param scene: Scene in which components are to be added to
17 @type data_collector: L{DataCollector <datacollector.DataCollector>}
18 object
19 @param data_collector: Source of data for visualization
20 """
21
22 self.scene = scene
23 self.data_collector = data_collector
24 self.vtk_mapper = vtk.vtkDataSetMapper()
25 self.vtk_actor = vtk.vtkActor()
26
27 def setMapperInput(self, component, lut = None):
28 """
29 Set up the mapper.
30 @type component: String
31 @param component: Component to be mapped
32 @type lut: L{BlueToRed <colormap.BlueToRed>} or
33 L{RedToBlue <colormap.RedToBlue>} object
34 @param lut: Lookup table to be used by the mapper
35 """
36
37 # 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 vtk_normals = vtk.vtkPolyDataNormals()
44 vtk_normals.SetInput(vtk_geometry.GetOutput())
45
46 self.vtk_mapper.SetInput(vtk_normals.GetOutput())
47
48 # Mapper uses the customized lookup table only if it is specified.
49 # Otherwise, the default one is used.
50 if(lut != None):
51 self.vtk_mapper.SetLookupTable(lut.getLut())
52
53 def setActorTexture(self, texture):
54 """
55 Set the texture of the actor.
56 @type texture: vtkTexture
57 @param texture: Texture map of the image
58 """
59
60 self.vtk_actor.SetTexture(texture)
61
62 def setActorInput(self):
63 """
64 Set up the actor.
65 """
66
67 self.vtk_actor.SetMapper(self.vtk_mapper)
68
69
70 def addActor(self):
71 """
72 Add the actor to the renderer.
73 """
74
75 self.scene.getRenderer().AddActor(self.vtk_actor)
76
77 def setActorOpacity(self, opacity):
78 """
79 Set the opacity (transparency) of the actor.
80 @type opacity: Number
81 @param opacity: Opacity (transparency) of the actor
82 """
83
84 self.vtk_actor.GetProperty().SetOpacity(opacity)
85
86 def setActorColor(self, color):
87 """
88 Set the color of the actor.
89 @type color: RGB list
90 @param color: Color of the actor
91 """
92
93 self.vtk_actor.GetProperty().SetColor(color[0], color[1],
94 color[2])
95
96 def setActorRepresentation(self, representation):
97 """
98 Set the representation of the actor.
99 @type representation: String
100 @param representation: Actor representation type (I{i.e. Wireframe})
101 """
102
103 eval("self.vtk_actor.GetProperty().SetRepresentationTo%s()" %
104 representation)
105
106
107 class Component:
108 pass

  ViewVC Help
Powered by ViewVC 1.1.26