1 |
|
2 |
######################################################## |
3 |
# |
4 |
# Copyright (c) 2003-2010 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-2010 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__="https://launchpad.net/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 |
from esys.escript import getMPISizeWorld |
35 |
if getMPISizeWorld()==1: import vtk |
36 |
|
37 |
class Glyph3D: |
38 |
""" |
39 |
Class that defines 3D glyphs. |
40 |
""" |
41 |
|
42 |
def __init__(self): |
43 |
""" |
44 |
Initialise the 3D glyph. |
45 |
""" |
46 |
if getMPISizeWorld()>1: |
47 |
raise ValueError,"pyvisi.Glyph3D is not running on more than one processor." |
48 |
self.__vtk_glyph3D = vtk.vtkGlyph3D() |
49 |
|
50 |
def _setupGlyph3D(self, object, source): |
51 |
""" |
52 |
Setup the 3D glyph. |
53 |
|
54 |
:type object: vtkDataSet, etc |
55 |
:param object: Input for the 3D glyph |
56 |
:type source: vtkPolyData |
57 |
:param source: Source for the 3D glyph (i.e. Arrow2D, Arrow3D, etc) |
58 |
""" |
59 |
|
60 |
self.__object = object |
61 |
self.__source = source |
62 |
|
63 |
self.__setInput() |
64 |
self.__setSource() |
65 |
self.setScaleModeByVector() |
66 |
self.__setVectorModeByVector() |
67 |
self.__setClampingOn() |
68 |
|
69 |
self.__setScalingOn() |
70 |
self.__setOrientOn() |
71 |
|
72 |
def __setInput(self): |
73 |
""" |
74 |
Set the input for the 3D glyph. |
75 |
""" |
76 |
|
77 |
self.__vtk_glyph3D.SetInput(self.__object) |
78 |
|
79 |
def __setSource(self): |
80 |
""" |
81 |
Set the source for the 3D glyph. |
82 |
""" |
83 |
|
84 |
self.__vtk_glyph3D.SetSource(self.__source) |
85 |
|
86 |
def setScaleModeByVector(self): |
87 |
""" |
88 |
Set the 3D glyph to scale according to the vector. |
89 |
""" |
90 |
|
91 |
self.__vtk_glyph3D.SetScaleModeToScaleByVector() |
92 |
|
93 |
def setScaleModeByScalar(self): |
94 |
""" |
95 |
Set the 3D glyph to scale according to the scalar. |
96 |
""" |
97 |
|
98 |
self.__vtk_glyph3D.SetScaleModeToScaleByScalar() |
99 |
|
100 |
def _setColorModeByVector(self): |
101 |
""" |
102 |
Set the 3D glyph to color according to the vector. |
103 |
""" |
104 |
|
105 |
self.__vtk_glyph3D.SetColorModeToColorByVector() |
106 |
|
107 |
def _setColorModeByScalar(self): |
108 |
""" |
109 |
Set the 3D glyph to color according to the scalar. |
110 |
""" |
111 |
|
112 |
self.__vtk_glyph3D.SetColorModeToColorByScalar() |
113 |
|
114 |
def __setVectorModeByVector(self): |
115 |
""" |
116 |
Set the 3D glyph vector mode according to the vector. |
117 |
""" |
118 |
|
119 |
self.__vtk_glyph3D.SetVectorModeToUseVector() |
120 |
|
121 |
def setScaleFactor(self, scale_factor): |
122 |
""" |
123 |
Set the 3D glyph scale factor. |
124 |
|
125 |
:type scale_factor: Number |
126 |
:param scale_factor: Scale factor |
127 |
""" |
128 |
|
129 |
self.__vtk_glyph3D.SetScaleFactor(scale_factor) |
130 |
|
131 |
def __setClampingOn(self): |
132 |
""" |
133 |
Enable clamping of "scalar" values to range. |
134 |
""" |
135 |
|
136 |
self.__vtk_glyph3D.SetClamping(1) |
137 |
|
138 |
def __setScalingOn(self): |
139 |
""" |
140 |
Enable the scaling of the rendered object. |
141 |
""" |
142 |
|
143 |
self.__vtk_glyph3D.ScalingOn() |
144 |
|
145 |
def __setOrientOn(self): |
146 |
""" |
147 |
Enable the orientation of the rendered object along the vector/normal. |
148 |
""" |
149 |
|
150 |
self.__vtk_glyph3D.OrientOn() |
151 |
|
152 |
def _setRange(self, range): |
153 |
""" |
154 |
Set the range to map scalar values. |
155 |
|
156 |
:type range: Two column tuple containing numbers |
157 |
:param range: Range to map scalar values |
158 |
""" |
159 |
|
160 |
self.__vtk_glyph3D.SetRange(range) |
161 |
|
162 |
def _getGlyph3DOutput(self): |
163 |
""" |
164 |
Return the output of the 3D glyph. |
165 |
|
166 |
:rtype: vtkPolyData |
167 |
:return: Polygonal data |
168 |
""" |
169 |
|
170 |
return self.__vtk_glyph3D.GetOutput() |
171 |
|
172 |
|
173 |
############################################################################### |
174 |
|
175 |
|
176 |
class TensorGlyph: |
177 |
""" |
178 |
Class that defines tensor glyphs. |
179 |
""" |
180 |
|
181 |
def __init__(self): |
182 |
""" |
183 |
Initialise the tensor glyph. |
184 |
""" |
185 |
if getMPISizeWorld()>1: |
186 |
raise ValueError,"pyvisi.TensorGlyph is not running on more than one processor." |
187 |
self.__vtk_tensor_glyph = vtk.vtkTensorGlyph() |
188 |
|
189 |
def _setupTensorGlyph(self, object, source): |
190 |
""" |
191 |
Setup the tensor glyph. |
192 |
|
193 |
:type object: vtkDataSet, etc |
194 |
:param object: Input for the 3D glyph |
195 |
:type source: vtkPolyData |
196 |
:param source: Source for the 3D glyph (i.e. Sphere, etc) |
197 |
""" |
198 |
|
199 |
self.__object = object |
200 |
self.__source = source |
201 |
|
202 |
self.__setInput() |
203 |
self.__setSource() |
204 |
self.__vtk_tensor_glyph.ClampScalingOn() |
205 |
|
206 |
def __setInput(self): |
207 |
""" |
208 |
Set the input for the tensor glyph. |
209 |
""" |
210 |
|
211 |
self.__vtk_tensor_glyph.SetInput(self.__object) |
212 |
|
213 |
def __setSource(self): |
214 |
""" |
215 |
Set the source for the tensor glyph. |
216 |
""" |
217 |
|
218 |
self.__vtk_tensor_glyph.SetSource(self.__source) |
219 |
|
220 |
def setScaleFactor(self, scale_factor): |
221 |
""" |
222 |
Set the scale factor for the tensor glyph. |
223 |
|
224 |
:type scale_factor: Number |
225 |
:param scale_factor: Scale factor |
226 |
""" |
227 |
|
228 |
self.__vtk_tensor_glyph.SetScaleFactor(scale_factor) |
229 |
|
230 |
def setMaxScaleFactor(self, max_scale_factor): |
231 |
""" |
232 |
Set the maximum allowable scale factor for the tensor glyph. |
233 |
|
234 |
:type max_scale_factor: Number |
235 |
:param max_scale_factor: Maximum allowable scale factor. |
236 |
""" |
237 |
|
238 |
self.__vtk_tensor_glyph.SetMaxScaleFactor(max_scale_factor) |
239 |
|
240 |
def _getTensorGlyphOutput(self): |
241 |
""" |
242 |
Return the output of the tensor glyph. |
243 |
|
244 |
:rtype: vtkPolyData |
245 |
:return: Polygonal data |
246 |
""" |
247 |
|
248 |
return self.__vtk_tensor_glyph.GetOutput() |
249 |
|