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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 973 - (show annotations)
Thu Feb 15 04:06:23 2007 UTC (12 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 4156 byte(s)
Corrected a bug related to the scalar and vector range in the velocity module.
1 """
2 @author: John NGUI
3 """
4
5 import vtk
6
7 class Glyph3D:
8 """
9 Class that defines 3D glyph.
10 """
11
12 def __init__(self, object, source):
13 """
14 Initialise the 3D glyph.
15
16 @type object: vtkDataSet, etc
17 @param object: Input for the 3D glyph
18 @type source: vtkPolyData
19 @param source: Source for the 3D glyph (i.e. Arrow2D, Arrow3D, etc)
20 """
21
22 self.__object = object
23 self.__source = source
24 self.__vtk_glyph3D = vtk.vtkGlyph3D()
25
26 self.__setInput()
27 self.__setSource()
28 self.setScaleModeByVector()
29 self.__setVectorModeByVector()
30 self.__setClampingOn()
31
32 self.__setScalingOn()
33 self.__setOrientOn()
34
35 def __setInput(self):
36 """
37 Set the input for the 3D glyph.
38 """
39
40 self.__vtk_glyph3D.SetInput(self.__object)
41
42 def __setSource(self):
43 """
44 Set the source for the 3D glyph.
45 """
46
47 self.__vtk_glyph3D.SetSource(self.__source)
48
49 def setScaleModeByVector(self):
50 """
51 Set the 3D glyph to scale according to the vector.
52 """
53
54 self.__vtk_glyph3D.SetScaleModeToScaleByVector()
55
56 def setScaleModeByScalar(self):
57 """
58 Set the 3D glyph to scale according to the scalar.
59 """
60
61 self.__vtk_glyph3D.SetScaleModeToScaleByScalar()
62
63 def _setColorModeByVector(self):
64 """
65 Set the 3D glyph color according to the vector.
66 """
67
68 self.__vtk_glyph3D.SetColorModeToColorByVector()
69
70 def _setColorModeByScalar(self):
71 """
72 Set the 3D glyph color according to the scalar.
73 """
74
75 self.__vtk_glyph3D.SetColorModeToColorByScalar()
76
77 def __setVectorModeByVector(self):
78 """
79 Set the 3D glyph vector mode according to the vector.
80 """
81
82 self.__vtk_glyph3D.SetVectorModeToUseVector()
83
84 def setScaleFactor(self, scale_factor):
85 """
86 Set the 3D glyph scale factor.
87
88 @type scale_factor: Number
89 @param scale_factor: Scale factor
90 """
91
92 self.__vtk_glyph3D.SetScaleFactor(scale_factor)
93
94 def __setClampingOn(self):
95 """
96 Enable clamping of "scalar" values to range.
97 """
98
99 self.__vtk_glyph3D.SetClamping(1)
100
101 def __setScalingOn(self):
102 """
103 Enable the scaling of the rendered object.
104 """
105
106 self.__vtk_glyph3D.ScalingOn()
107
108 def __setOrientOn(self):
109 """
110 Enable the orientation of the rendered object along the vector/normal.
111 """
112
113 self.__vtk_glyph3D.OrientOn()
114
115 def _setRange(self, range):
116 """
117 Set the range to map scalar values.
118
119 @type range: Two column tuple containing numbers
120 @param range: Range to map scalar values
121 """
122
123 self.__vtk_glyph3D.SetRange(range)
124
125 def _getOutput(self):
126 """
127 Return the output of the 3D glyph.
128
129 @rtype: vtkPolyData
130 @return Polygonal data
131 """
132
133 return self.__vtk_glyph3D.GetOutput()
134
135
136 ###############################################################################
137
138
139 class TensorGlyph:
140 """
141 Class that defines tensor glyph.
142 """
143
144 def __init__(self, object, source):
145 """
146 Initialise the tensor glyph.
147
148 @type object: vtkDataSet, etc
149 @param object: Input for the 3D glyph
150 @type source: vtkPolyData
151 @param source: Source for the 3D glyph (i.e. Sphere, etc)
152 """
153
154 self.__object = object
155 self.__source = source
156 self.__vtk_tensor_glyph = vtk.vtkTensorGlyph()
157
158 self.__setupTensorGlyph()
159
160 def __setupTensorGlyph(self):
161 """
162 Setup the tensor glyph.
163 """
164
165 self.__setInput()
166 self.__setSource()
167
168 def __setInput(self):
169 """
170 Set the input for the tensor glyph.
171 """
172
173 self.__vtk_tensor_glyph.SetInput(self.__object)
174
175 def __setSource(self):
176 """
177 Set the source for the tensor glyph.
178 """
179
180 self.__vtk_tensor_glyph.SetSource(self.__source)
181
182 def setScaleFactor(self, scale_factor):
183 """
184 Set the scale factor for the tensor glyph.
185
186 @type scale_factor: Number
187 @param scale_factor: Scale factor
188 """
189
190 self.__vtk_tensor_glyph.SetScaleFactor(scale_factor)
191
192 def setMaxScaleFactor(self, max_scale_factor):
193 """
194 Set the maximum allowable scale factor for the tensor glyph.
195
196 @type max_scale_factor: Number
197 @param max_scale_factor: Maximum allowable scale factor.
198 """
199
200 self.__vtk_tensor_glyph.SetMaxScaleFactor(scale_factor)
201
202 def _getOutput(self):
203 """
204 Return the output of the tensor glyph.
205
206 @rtype: vtkPolyData
207 @return: Polygonal data
208 """
209
210 return self.__vtk_tensor_glyph.GetOutput()
211

  ViewVC Help
Powered by ViewVC 1.1.26