1 |
""" |
2 |
@author: John NGUI |
3 |
""" |
4 |
|
5 |
import vtk |
6 |
from mapper import DataSetMapper |
7 |
from lookuptable import LookupTable |
8 |
from actor import Actor3D |
9 |
from constant import Viewport, Color, Arrow, ColorMode, Lut, VizType |
10 |
from arrow import Arrow2D, Arrow3D |
11 |
from glyph import Glyph3D |
12 |
from outline import Outline |
13 |
from point import MaskPoints |
14 |
from average import CellDataToPointData |
15 |
|
16 |
# NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D and |
17 |
# MaskPoints were inherited to allow access to their public |
18 |
# methods from the driver. |
19 |
class Velocity(DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, MaskPoints): |
20 |
""" |
21 |
Class that shows a vector field using arrows. The arrows can either be |
22 |
colored or grey-scaled, depending on the lookup table used. If the arrows |
23 |
are colored, there are two possible coloring modes, either using vector data |
24 |
or scalar data. Similarly, there are two possible types of |
25 |
arrows, either using two-dimensional or three-dimensional. |
26 |
""" |
27 |
|
28 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
29 |
# This saves the user from specifying the viewport when there is only one. |
30 |
# If no lut is specified, the color scheme will be used. |
31 |
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, |
32 |
color_mode = ColorMode.VECTOR, arrow = Arrow.TWO_D, |
33 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
34 |
""" |
35 |
Initialise the Velocity. |
36 |
|
37 |
@attention: The source can either be point or cell data. If the |
38 |
source is cell data, a conversion to point data may or may not be |
39 |
required, in order for the object to be rendered correctly. |
40 |
If a conversion is needed, the 'cell_to_point' flag must be set to |
41 |
'True', otherwise 'False' (which is the default). |
42 |
|
43 |
@type scene: L{Scene <scene.Scene>} object |
44 |
@param scene: Scene in which objects are to be rendered on |
45 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
46 |
object |
47 |
@param data_collector: Deal with source of data for visualisation |
48 |
@type viewport: L{Viewport <constant.Viewport>} constant |
49 |
@param viewport: Viewport in which objects are to be rendered on |
50 |
@type color_mode: L{ColorMode <constant.ColorMode>} constant |
51 |
@param color_mode: Type of color mode |
52 |
@type arrow: L{Arrow <constant.Arrow>} constant |
53 |
@param arrow: Type of arrow (two dimensional or three dimensional) |
54 |
@type lut : L{Lut <constant.Lut>} constant |
55 |
@param lut: Lookup table color scheme |
56 |
@type cell_to_point: Boolean |
57 |
@param cell_to_point: Converts cell data to point data (by averaging) |
58 |
@type outline: Boolean |
59 |
@param outline: Places an outline around the domain surface |
60 |
""" |
61 |
|
62 |
# NOTE: Actor3D is inherited and there are two instances declared here. |
63 |
# As a result, when methods from Actor3D is invoked from the driver, |
64 |
# only the methods associated with the latest instance (which in this |
65 |
# case is the Actor3D for the Velocity) can be executed. Actor3D |
66 |
# methods associated with Outline cannot be invoked from the driver. |
67 |
# They can only be called within here, which is why Outline must be |
68 |
# place before Velocity as there is unlikely to be any changes |
69 |
# made to the Outline's Actor3D. |
70 |
|
71 |
# ----- Outline ----- |
72 |
|
73 |
if(outline == True): |
74 |
outline = Outline(data_collector._getOutput()) |
75 |
DataSetMapper.__init__(self, outline._getOutput()) |
76 |
|
77 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
78 |
# Default outline color is black. |
79 |
Actor3D.setColor(self, Color.BLACK) |
80 |
|
81 |
# Default line width is 1. |
82 |
Actor3D._setLineWidth(self, 1) |
83 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
84 |
|
85 |
# ----- Velocity ----- |
86 |
|
87 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
88 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
89 |
# will take place. |
90 |
if(lut == Lut.COLOR): # Colored lookup table. |
91 |
lookup_table = LookupTable() |
92 |
lookup_table._setTableValue() |
93 |
elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
94 |
lookup_table = LookupTable() |
95 |
lookup_table._setLookupTableToGreyScale() |
96 |
|
97 |
if(cell_to_point == True): # Converts cell data to point data. |
98 |
c2p = CellDataToPointData(data_collector._getOutput()) |
99 |
MaskPoints.__init__(self, c2p._getOutput()) |
100 |
elif(cell_to_point == False): # No conversion happens. |
101 |
MaskPoints.__init__(self, data_collector._getOutput()) |
102 |
|
103 |
if(arrow == Arrow.TWO_D): # Use 2D arrows. |
104 |
Arrow2D.__init__(self) |
105 |
Glyph3D.__init__(self, MaskPoints._getOutput(self), |
106 |
Arrow2D._getOutput(self)) |
107 |
elif(arrow == Arrow.THREE_D): # Use 3D arrows. |
108 |
Arrow3D.__init__(self) |
109 |
Glyph3D.__init__(self, MaskPoints._getOutput(self), |
110 |
Arrow3D._getOutput(self)) |
111 |
|
112 |
DataSetMapper.__init__(self, Glyph3D._getOutput(self), |
113 |
lookup_table._getLookupTable()) |
114 |
|
115 |
if(color_mode == ColorMode.VECTOR): # Color velocity by vector. |
116 |
Glyph3D._setColorModeByVector(self) |
117 |
Glyph3D._setRange(self, data_collector._getVectorRange()) |
118 |
DataSetMapper._setScalarRange(self, |
119 |
data_collector._getVectorRange()) |
120 |
data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY, |
121 |
ColorMode.VECTOR, DataSetMapper._getDataSetMapper(self), |
122 |
Glyph3D._getGlyph3D(self)) |
123 |
|
124 |
elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar. |
125 |
Glyph3D._setColorModeByScalar(self) |
126 |
Glyph3D._setRange(self, data_collector._getScalarRange()) |
127 |
DataSetMapper._setScalarRange(self, |
128 |
data_collector._getScalarRange()) |
129 |
data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY, |
130 |
ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self), |
131 |
Glyph3D._getGlyph3D(self)) |
132 |
|
133 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
134 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
135 |
|
136 |
|
137 |
############################################################################### |
138 |
|
139 |
|
140 |
from transform import Transform |
141 |
from plane import Plane |
142 |
from cutter import Cutter |
143 |
|
144 |
# NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane, |
145 |
# Cutter and MaskPoints were inherited to allow access to |
146 |
# their public methods from the driver. |
147 |
class VelocityOnPlaneCut(DataSetMapper, Actor3D, Arrow2D, Arrow3D, |
148 |
Glyph3D, Transform, Plane, Cutter, MaskPoints): |
149 |
""" |
150 |
This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>}, |
151 |
except that it shows a vector field using arrows on a plane. |
152 |
""" |
153 |
|
154 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
155 |
# This saves the user from specifying the viewport when there is only one. |
156 |
# If no lut is specified, the color scheme willbe used. |
157 |
def __init__(self, scene, data_collector, arrow = Arrow.TWO_D, |
158 |
color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST, |
159 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
160 |
""" |
161 |
Initialise the VelocityOnPlaneCut. |
162 |
|
163 |
@attention: The source can either be point or cell data. If the |
164 |
source is cell data, a conversion to point data may or may not be |
165 |
required, in order for the object to be rendered correctly. |
166 |
If a conversion is needed, the 'cell_to_point' flag must be set to |
167 |
'True', otherwise 'False' (which is the default). |
168 |
|
169 |
@type scene: L{Scene <scene.Scene>} object |
170 |
@param scene: Scene in which objects are to be rendered on |
171 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
172 |
object |
173 |
@param data_collector: Deal with source of data for visualisation |
174 |
@type arrow: L{Arrow <constant.Arrow>} constant |
175 |
@param arrow: Type of arrow (two dimensional or three dimensional) |
176 |
@type color_mode: L{ColorMode <constant.ColorMode>} constant |
177 |
@param color_mode: Type of color mode |
178 |
@type viewport: L{Viewport <constant.Viewport>} constant |
179 |
@param viewport: Viewport in which objects are to be rendered on |
180 |
@type lut : L{Lut <constant.Lut>} constant |
181 |
@param lut: Lookup table color scheme |
182 |
@type cell_to_point: Boolean |
183 |
@param cell_to_point: Converts cell data to point data (by averaging) |
184 |
@type outline: Boolean |
185 |
@param outline: Places an outline around the domain surface |
186 |
""" |
187 |
|
188 |
# NOTE: Actor3D is inherited and there are two instances declared here. |
189 |
# As a result, when methods from Actor3D is invoked from the driver, |
190 |
# only the methods associated with the latest instance (which in this |
191 |
# case is the Actor3D for the Velocity) can be executed. Actor3D |
192 |
# methods associated with Outline cannot be invoked from the driver. |
193 |
# They can only be called within here, which is why Outline must be |
194 |
# place before Velocity as there is unlikely to be any changes |
195 |
# made to the Outline's Actor3D. |
196 |
|
197 |
# ----- Outline ----- |
198 |
|
199 |
if(outline == True): |
200 |
outline = Outline(data_collector._getOutput()) |
201 |
DataSetMapper.__init__(self, outline._getOutput()) |
202 |
|
203 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
204 |
# Default outline color is black. |
205 |
Actor3D.setColor(self, Color.BLACK) |
206 |
|
207 |
# Default line width is 1. |
208 |
Actor3D._setLineWidth(self, 1) |
209 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
210 |
|
211 |
# ----- Velocity on a cut plane ----- |
212 |
|
213 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
214 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
215 |
# will take place. |
216 |
if(lut == Lut.COLOR): # Colored lookup table. |
217 |
lookup_table = LookupTable() |
218 |
lookup_table._setTableValue() |
219 |
elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
220 |
lookup_table = LookupTable() |
221 |
lookup_table._setLookupTableToGreyScale() |
222 |
|
223 |
Transform.__init__(self) |
224 |
Plane.__init__(self, Transform._getTransform(self)) |
225 |
|
226 |
if(cell_to_point == True): # Converts cell data to point data. |
227 |
c2p = CellDataToPointData(data_collector._getOutput()) |
228 |
Cutter.__init__(self, c2p._getOutput(), Plane._getPlane(self)) |
229 |
elif(cell_to_point == False): # No conversion happens. |
230 |
Cutter.__init__(self, data_collector._getOutput(), |
231 |
Plane._getPlane(self)) |
232 |
|
233 |
MaskPoints.__init__(self, Cutter._getOutput(self)) |
234 |
|
235 |
if(arrow == Arrow.TWO_D): # Use 2D arrows. |
236 |
Arrow2D.__init__(self) |
237 |
Glyph3D.__init__(self, MaskPoints._getOutput(self), |
238 |
Arrow2D._getOutput(self)) |
239 |
elif(arrow == Arrow.THREE_D): # Use 3D arrows. |
240 |
Arrow3D.__init__(self) |
241 |
Glyph3D.__init__(self, MaskPoints._getOutput(self), |
242 |
Arrow3D._getOutput(self)) |
243 |
|
244 |
DataSetMapper.__init__(self, Glyph3D._getOutput(self), |
245 |
lookup_table._getLookupTable()) |
246 |
|
247 |
if(color_mode == ColorMode.VECTOR): # Color velocity by vector. |
248 |
Glyph3D._setColorModeByVector(self) |
249 |
Glyph3D._setRange(self, data_collector._getVectorRange()) |
250 |
DataSetMapper._setScalarRange(self, |
251 |
data_collector._getVectorRange()) |
252 |
data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY, |
253 |
ColorMode.VECTOR, DataSetMapper._getDataSetMapper(self), |
254 |
Glyph3D._getGlyph3D(self)) |
255 |
|
256 |
elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar. |
257 |
Glyph3D._setColorModeByScalar(self) |
258 |
Glyph3D._setRange(self, data_collector._getScalarRange()) |
259 |
DataSetMapper._setScalarRange(self, |
260 |
data_collector._getScalarRange()) |
261 |
data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY, |
262 |
ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self), |
263 |
Glyph3D._getGlyph3D(self)) |
264 |
|
265 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
266 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
267 |
|
268 |
|
269 |
############################################################################### |
270 |
|
271 |
|
272 |
from clipper import Clipper |
273 |
|
274 |
# NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane, |
275 |
# Clipper and MaskPoints were inherited to allow access to |
276 |
# their public methods from the driver. |
277 |
class VelocityOnPlaneClip(DataSetMapper, Actor3D, Arrow2D, Arrow3D, |
278 |
Glyph3D, Transform, Plane, Clipper, MaskPoints): |
279 |
""" |
280 |
This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>} |
281 |
, except that it shows a vector field using arrows clipped using a plane. |
282 |
""" |
283 |
|
284 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
285 |
# This saves the user from specifying the viewport when there is only one. |
286 |
# If no lut is specified, the color scheme will be used. |
287 |
def __init__(self, scene, data_collector, arrow = Arrow.TWO_D, |
288 |
color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST, |
289 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
290 |
""" |
291 |
Initialise the VelocityOnPlaneClip. |
292 |
|
293 |
@attention: The source can either be point or cell data. If the |
294 |
source is cell data, a conversion to point data may or may not be |
295 |
required, in order for the object to be rendered correctly. |
296 |
If a conversion is needed, the 'cell_to_point' flag must be set to |
297 |
'True', otherwise 'False' (which is the default). |
298 |
|
299 |
@type scene: L{Scene <scene.Scene>} object |
300 |
@param scene: Scene in which objects are to be rendered on |
301 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
302 |
object |
303 |
@param data_collector: Deal with source of data for visualisation |
304 |
@type arrow: L{Arrow <constant.Arrow>} constant |
305 |
@param arrow: Type of arrow (two dimensional or three dimensional) |
306 |
@type color_mode: L{ColorMode <constant.ColorMode>} constant |
307 |
@param color_mode: Type of color mode |
308 |
@type viewport: L{Viewport <constant.Viewport>} constant |
309 |
@param viewport: Viewport in which objects are to be rendered on |
310 |
@type lut : L{Lut <constant.Lut>} constant |
311 |
@param lut: Lookup table color scheme |
312 |
@type cell_to_point: Boolean |
313 |
@param cell_to_point: Converts cell data to point data (by averaging) |
314 |
@type outline: Boolean |
315 |
@param outline: Places an outline around the domain surface |
316 |
""" |
317 |
|
318 |
# NOTE: Actor3D is inherited and there are two instances declared here. |
319 |
# As a result, when methods from Actor3D is invoked from the driver, |
320 |
# only the methods associated with the latest instance (which in this |
321 |
# case is the Actor3D for the Velocity) can be executed. Actor3D |
322 |
# methods associated with Outline cannot be invoked from the driver. |
323 |
# They can only be called within here, which is why Outline must be |
324 |
# place before Velocity as there is unlikely to be any changes |
325 |
# made to the Outline's Actor3D. |
326 |
|
327 |
# ----- Outline ----- |
328 |
|
329 |
if(outline == True): |
330 |
outline = Outline(data_collector._getOutput()) |
331 |
DataSetMapper.__init__(self, outline._getOutput()) |
332 |
|
333 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
334 |
# Default outline color is black. |
335 |
Actor3D.setColor(self, Color.BLACK) |
336 |
|
337 |
# Default line width is 1. |
338 |
Actor3D._setLineWidth(self, 1) |
339 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
340 |
|
341 |
# ----- Velocity on a clipped plane ----- |
342 |
|
343 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
344 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
345 |
# will take place. |
346 |
if(lut == Lut.COLOR): # Colored lookup table. |
347 |
lookup_table = LookupTable() |
348 |
lookup_table._setTableValue() |
349 |
elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
350 |
lookup_table = LookupTable() |
351 |
lookup_table._setLookupTableToGreyScale() |
352 |
|
353 |
Transform.__init__(self) |
354 |
Plane.__init__(self, Transform._getTransform(self)) |
355 |
|
356 |
if(cell_to_point == True): # Converts cell data to point data. |
357 |
c2p = CellDataToPointData(data_collector._getOutput()) |
358 |
MaskPoints.__init__(self, c2p._getOutput()) |
359 |
elif(cell_to_point == False): # No conversion happens. |
360 |
MaskPoints.__init__(self, data_collector._getOutput()) |
361 |
|
362 |
# NOTE: Glyph3D must come before Clipper. Otherwise clipping may not |
363 |
# work correctly. |
364 |
if(arrow == Arrow.TWO_D): # Use 2D arrows. |
365 |
Arrow2D.__init__(self) |
366 |
Glyph3D.__init__(self, MaskPoints._getOutput(self), |
367 |
Arrow2D._getOutput(self)) |
368 |
elif(arrow == Arrow.THREE_D): # Use 3D arrows. |
369 |
Arrow3D.__init__(self) |
370 |
Glyph3D.__init__(self, MaskPoints._getOutput(self), |
371 |
Arrow3D._getOutput(self)) |
372 |
|
373 |
Clipper.__init__(self, Glyph3D._getOutput(self), |
374 |
Plane._getPlane(self)) |
375 |
Clipper._setClipFunction(self) |
376 |
|
377 |
# NOTE: Clipper must come after Glyph. Otherwise clipping |
378 |
# may not work correctly. |
379 |
DataSetMapper.__init__(self, Clipper._getOutput(self), |
380 |
lookup_table._getLookupTable()) |
381 |
|
382 |
if(color_mode == ColorMode.VECTOR): # Color velocity by vector. |
383 |
Glyph3D._setColorModeByVector(self) |
384 |
Glyph3D._setRange(self, data_collector._getVectorRange()) |
385 |
DataSetMapper._setScalarRange(self, |
386 |
data_collector._getVectorRange()) |
387 |
data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY, |
388 |
ColorMode.VECTOR, DataSetMapper._getDataSetMapper(self), |
389 |
Glyph3D._getGlyph3D(self)) |
390 |
|
391 |
elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar. |
392 |
Glyph3D._setColorModeByScalar(self) |
393 |
Glyph3D._setRange(self, data_collector._getScalarRange()) |
394 |
DataSetMapper._setScalarRange(self, |
395 |
data_collector._getScalarRange()) |
396 |
data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY, |
397 |
ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self), |
398 |
Glyph3D._getGlyph3D(self)) |
399 |
|
400 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
401 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |