1 |
|
2 |
######################################################## |
3 |
# |
4 |
# Copyright (c) 2003-2008 by University of Queensland |
5 |
# Earth Systems Science Computational Center (ESSCC) |
6 |
# http://www.uq.edu.au/esscc |
7 |
# |
8 |
# Primary Business: Queensland, Australia |
9 |
# Licensed under the Open Software License version 3.0 |
10 |
# http://www.opensource.org/licenses/osl-3.0.php |
11 |
# |
12 |
######################################################## |
13 |
|
14 |
__copyright__="""Copyright (c) 2003-2008 by University of Queensland |
15 |
Earth Systems Science Computational Center (ESSCC) |
16 |
http://www.uq.edu.au/esscc |
17 |
Primary Business: Queensland, Australia""" |
18 |
__license__="""Licensed under the Open Software License version 3.0 |
19 |
http://www.opensource.org/licenses/osl-3.0.php""" |
20 |
__url__="http://www.uq.edu.au/esscc/escript-finley" |
21 |
|
22 |
""" |
23 |
@var __author__: name of author |
24 |
@var __copyright__: copyrights |
25 |
@var __license__: licence agreement |
26 |
@var __url__: url entry point on documentation |
27 |
@var __version__: version |
28 |
@var __date__: date of the version |
29 |
""" |
30 |
|
31 |
__author__="John Ngui, john.ngui@uq.edu.au" |
32 |
|
33 |
|
34 |
import vtk |
35 |
|
36 |
class Glyph3D: |
37 |
""" |
38 |
Class that defines 3D glyphs. |
39 |
""" |
40 |
|
41 |
def __init__(self): |
42 |
""" |
43 |
Initialise the 3D glyph. |
44 |
""" |
45 |
|
46 |
self.__vtk_glyph3D = vtk.vtkGlyph3D() |
47 |
|
48 |
def _setupGlyph3D(self, object, source): |
49 |
""" |
50 |
Setup the 3D glyph. |
51 |
|
52 |
@type object: vtkDataSet, etc |
53 |
@param object: Input for the 3D glyph |
54 |
@type source: vtkPolyData |
55 |
@param source: Source for the 3D glyph (i.e. Arrow2D, Arrow3D, etc) |
56 |
""" |
57 |
|
58 |
self.__object = object |
59 |
self.__source = source |
60 |
|
61 |
self.__setInput() |
62 |
self.__setSource() |
63 |
self.setScaleModeByVector() |
64 |
self.__setVectorModeByVector() |
65 |
self.__setClampingOn() |
66 |
|
67 |
self.__setScalingOn() |
68 |
self.__setOrientOn() |
69 |
|
70 |
def __setInput(self): |
71 |
""" |
72 |
Set the input for the 3D glyph. |
73 |
""" |
74 |
|
75 |
self.__vtk_glyph3D.SetInput(self.__object) |
76 |
|
77 |
def __setSource(self): |
78 |
""" |
79 |
Set the source for the 3D glyph. |
80 |
""" |
81 |
|
82 |
self.__vtk_glyph3D.SetSource(self.__source) |
83 |
|
84 |
def setScaleModeByVector(self): |
85 |
""" |
86 |
Set the 3D glyph to scale according to the vector. |
87 |
""" |
88 |
|
89 |
self.__vtk_glyph3D.SetScaleModeToScaleByVector() |
90 |
|
91 |
def setScaleModeByScalar(self): |
92 |
""" |
93 |
Set the 3D glyph to scale according to the scalar. |
94 |
""" |
95 |
|
96 |
self.__vtk_glyph3D.SetScaleModeToScaleByScalar() |
97 |
|
98 |
def _setColorModeByVector(self): |
99 |
""" |
100 |
Set the 3D glyph to color according to the vector. |
101 |
""" |
102 |
|
103 |
self.__vtk_glyph3D.SetColorModeToColorByVector() |
104 |
|
105 |
def _setColorModeByScalar(self): |
106 |
""" |
107 |
Set the 3D glyph to color according to the scalar. |
108 |
""" |
109 |
|
110 |
self.__vtk_glyph3D.SetColorModeToColorByScalar() |
111 |
|
112 |
def __setVectorModeByVector(self): |
113 |
""" |
114 |
Set the 3D glyph vector mode according to the vector. |
115 |
""" |
116 |
|
117 |
self.__vtk_glyph3D.SetVectorModeToUseVector() |
118 |
|
119 |
def setScaleFactor(self, scale_factor): |
120 |
""" |
121 |
Set the 3D glyph scale factor. |
122 |
|
123 |
@type scale_factor: Number |
124 |
@param scale_factor: Scale factor |
125 |
""" |
126 |
|
127 |
self.__vtk_glyph3D.SetScaleFactor(scale_factor) |
128 |
|
129 |
def __setClampingOn(self): |
130 |
""" |
131 |
Enable clamping of "scalar" values to range. |
132 |
""" |
133 |
|
134 |
self.__vtk_glyph3D.SetClamping(1) |
135 |
|
136 |
def __setScalingOn(self): |
137 |
""" |
138 |
Enable the scaling of the rendered object. |
139 |
""" |
140 |
|
141 |
self.__vtk_glyph3D.ScalingOn() |
142 |
|
143 |
def __setOrientOn(self): |
144 |
""" |
145 |
Enable the orientation of the rendered object along the vector/normal. |
146 |
""" |
147 |
|
148 |
self.__vtk_glyph3D.OrientOn() |
149 |
|
150 |
def _setRange(self, range): |
151 |
""" |
152 |
Set the range to map scalar values. |
153 |
|
154 |
@type range: Two column tuple containing numbers |
155 |
@param range: Range to map scalar values |
156 |
""" |
157 |
|
158 |
self.__vtk_glyph3D.SetRange(range) |
159 |
|
160 |
def _getGlyph3DOutput(self): |
161 |
""" |
162 |
Return the output of the 3D glyph. |
163 |
|
164 |
@rtype: vtkPolyData |
165 |
@return Polygonal data |
166 |
""" |
167 |
|
168 |
return self.__vtk_glyph3D.GetOutput() |
169 |
|
170 |
|
171 |
############################################################################### |
172 |
|
173 |
|
174 |
class TensorGlyph: |
175 |
""" |
176 |
Class that defines tensor glyphs. |
177 |
""" |
178 |
|
179 |
def __init__(self): |
180 |
""" |
181 |
Initialise the tensor glyph. |
182 |
""" |
183 |
|
184 |
self.__vtk_tensor_glyph = vtk.vtkTensorGlyph() |
185 |
|
186 |
def _setupTensorGlyph(self, object, source): |
187 |
""" |
188 |
Setup the tensor glyph. |
189 |
|
190 |
@type object: vtkDataSet, etc |
191 |
@param object: Input for the 3D glyph |
192 |
@type source: vtkPolyData |
193 |
@param source: Source for the 3D glyph (i.e. Sphere, etc) |
194 |
""" |
195 |
|
196 |
self.__object = object |
197 |
self.__source = source |
198 |
|
199 |
self.__setInput() |
200 |
self.__setSource() |
201 |
self.__vtk_tensor_glyph.ClampScalingOn() |
202 |
|
203 |
def __setInput(self): |
204 |
""" |
205 |
Set the input for the tensor glyph. |
206 |
""" |
207 |
|
208 |
self.__vtk_tensor_glyph.SetInput(self.__object) |
209 |
|
210 |
def __setSource(self): |
211 |
""" |
212 |
Set the source for the tensor glyph. |
213 |
""" |
214 |
|
215 |
self.__vtk_tensor_glyph.SetSource(self.__source) |
216 |
|
217 |
def setScaleFactor(self, scale_factor): |
218 |
""" |
219 |
Set the scale factor for the tensor glyph. |
220 |
|
221 |
@type scale_factor: Number |
222 |
@param scale_factor: Scale factor |
223 |
""" |
224 |
|
225 |
self.__vtk_tensor_glyph.SetScaleFactor(scale_factor) |
226 |
|
227 |
def setMaxScaleFactor(self, max_scale_factor): |
228 |
""" |
229 |
Set the maximum allowable scale factor for the tensor glyph. |
230 |
|
231 |
@type max_scale_factor: Number |
232 |
@param max_scale_factor: Maximum allowable scale factor. |
233 |
""" |
234 |
|
235 |
self.__vtk_tensor_glyph.SetMaxScaleFactor(max_scale_factor) |
236 |
|
237 |
def _getTensorGlyphOutput(self): |
238 |
""" |
239 |
Return the output of the tensor glyph. |
240 |
|
241 |
@rtype: vtkPolyData |
242 |
@return: Polygonal data |
243 |
""" |
244 |
|
245 |
return self.__vtk_tensor_glyph.GetOutput() |
246 |
|