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