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 |
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, arrow = Arrow.TWO_D, |
32 |
color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST, |
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 arrow: L{Arrow <constant.Arrow>} constant |
49 |
@param arrow: Type of arrow (two dimensional or three dimensional) |
50 |
@type color_mode: L{ColorMode <constant.ColorMode>} constant |
51 |
@param color_mode: Type of color mode |
52 |
@type viewport: L{Viewport <constant.Viewport>} constant |
53 |
@param viewport: Viewport in which objects are to be rendered on |
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 |
self.__data_collector = data_collector |
63 |
self.__arrow = arrow |
64 |
self.__color_mode = color_mode |
65 |
self.__viewport = viewport |
66 |
self.__lut = lut |
67 |
self.__cell_to_point = cell_to_point |
68 |
self.__outline = outline |
69 |
|
70 |
self.__modified = True # Keeps track whether Velocity has been modified. |
71 |
MaskPoints.__init__(self) |
72 |
Glyph3D.__init__(self) |
73 |
DataSetMapper.__init__(self) |
74 |
Actor3D.__init__(self) |
75 |
scene._addVisualizationModules(self) |
76 |
|
77 |
# ----- Outline ----- |
78 |
|
79 |
# NOTE: Changes cannot be made to the Outline's properties from the |
80 |
# driver. |
81 |
if(self.__outline == True): |
82 |
outline = Outline(self.__data_collector._getDataCollectorOutput()) |
83 |
mapper = DataSetMapper() |
84 |
mapper._setupDataSetMapper(outline._getOutlineOutput()) |
85 |
|
86 |
actor3D = Actor3D() |
87 |
actor3D._setupActor3D(mapper._getDataSetMapper()) |
88 |
# Default outline color is black. |
89 |
actor3D.setColor(Color.BLACK) |
90 |
|
91 |
# Default line width is 1. |
92 |
actor3D._setLineWidth(1) |
93 |
scene._addActor3D(self.__viewport, actor3D._getActor3D()) |
94 |
|
95 |
# ----- Velocity ----- |
96 |
|
97 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
98 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
99 |
# will take place. |
100 |
if(self.__lut == Lut.COLOR): # Colored lookup table. |
101 |
lookup_table = LookupTable() |
102 |
lookup_table._setTableValue() |
103 |
elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
104 |
lookup_table = LookupTable() |
105 |
lookup_table._setLookupTableToGreyScale() |
106 |
|
107 |
if(self.__cell_to_point == True): # Converts cell data to point data. |
108 |
c2p = CellDataToPointData( |
109 |
self.__data_collector._getDataCollectorOutput()) |
110 |
self._setupMaskPoints(c2p._getCellToPointOutput()) |
111 |
elif(self.__cell_to_point == False): # No conversion happens. |
112 |
self._setupMaskPoints(data_collector._getDataCollectorOutput()) |
113 |
|
114 |
if(self.__arrow == Arrow.TWO_D): # Use 2D arrows. |
115 |
Arrow2D.__init__(self) |
116 |
self._setupGlyph3D(self._getMaskPointsOutput(), |
117 |
self._getArrow2DOutput()) |
118 |
elif(arrow == Arrow.THREE_D): # Use 3D arrows. |
119 |
Arrow3D.__init__(self) |
120 |
self._setupGlyph3D(self._getMaskPointsOutput(), |
121 |
self._getArrow3DOutput()) |
122 |
|
123 |
self._setupDataSetMapper(self._getGlyph3DOutput(), |
124 |
lookup_table._getLookupTable()) |
125 |
|
126 |
self._setupActor3D(self._getDataSetMapper()) |
127 |
scene._addActor3D(self.__viewport, self._getActor3D()) |
128 |
|
129 |
def _isModified(self): |
130 |
""" |
131 |
Return whether the Velocity or DataCollector has been modified. |
132 |
|
133 |
@rtype: Boolean |
134 |
@return: True or False |
135 |
""" |
136 |
|
137 |
return self.__modified or self.__data_collector._isModified() |
138 |
|
139 |
def _render(self, scene): |
140 |
""" |
141 |
Render the velocity. |
142 |
|
143 |
@type scene: L{Scene <scene.Scene>} object |
144 |
@param scene: Scene in which objects are to be rendered on |
145 |
""" |
146 |
|
147 |
if (self._isModified() == True): |
148 |
if(self.__data_collector._isScalarSet() == True): |
149 |
self.__data_collector._setActiveScalar() |
150 |
if(self.__data_collector._isVectorSet() == True): |
151 |
self.__data_collector._setActiveVector() |
152 |
|
153 |
# Color velocity by vector. |
154 |
if(self.__color_mode == ColorMode.VECTOR): |
155 |
self._setColorModeByVector() |
156 |
self._setRange(self.__data_collector._getVectorRange()) |
157 |
self._setScalarRange(self.__data_collector._getVectorRange()) |
158 |
# Color velocity by scalar. |
159 |
elif(self.__color_mode == ColorMode.SCALAR): |
160 |
self._setColorModeByScalar() |
161 |
self._setRange(self.__data_collector._getScalarRange()) |
162 |
self._setScalarRange(self.__data_collector._getScalarRange()) |
163 |
|
164 |
self.__modified = False |
165 |
|
166 |
|
167 |
############################################################################### |
168 |
|
169 |
|
170 |
from transform import Transform |
171 |
from plane import Plane |
172 |
from cutter import Cutter |
173 |
|
174 |
# NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane, |
175 |
# Cutter and MaskPoints were inherited to allow access to |
176 |
# their public methods from the driver. |
177 |
class VelocityOnPlaneCut(DataSetMapper, Actor3D, Arrow2D, Arrow3D, |
178 |
Glyph3D, Transform, Plane, Cutter, MaskPoints): |
179 |
""" |
180 |
This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>}, |
181 |
except that it shows a vector field using arrows cut using a plane. |
182 |
""" |
183 |
|
184 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
185 |
# This saves the user from specifying the viewport when there is only one. |
186 |
# If no lut is specified, the color scheme willbe used. |
187 |
def __init__(self, scene, data_collector, arrow = Arrow.TWO_D, |
188 |
color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST, |
189 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
190 |
""" |
191 |
Initialise the VelocityOnPlaneCut. |
192 |
|
193 |
@attention: The source can either be point or cell data. If the |
194 |
source is cell data, a conversion to point data may or may not be |
195 |
required, in order for the object to be rendered correctly. |
196 |
If a conversion is needed, the 'cell_to_point' flag must be set to |
197 |
'True', otherwise 'False' (which is the default). |
198 |
|
199 |
@type scene: L{Scene <scene.Scene>} object |
200 |
@param scene: Scene in which objects are to be rendered on |
201 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
202 |
object |
203 |
@param data_collector: Deal with source of data for visualisation |
204 |
@type arrow: L{Arrow <constant.Arrow>} constant |
205 |
@param arrow: Type of arrow (two dimensional or three dimensional) |
206 |
@type color_mode: L{ColorMode <constant.ColorMode>} constant |
207 |
@param color_mode: Type of color mode |
208 |
@type viewport: L{Viewport <constant.Viewport>} constant |
209 |
@param viewport: Viewport in which objects are to be rendered on |
210 |
@type lut : L{Lut <constant.Lut>} constant |
211 |
@param lut: Lookup table color scheme |
212 |
@type cell_to_point: Boolean |
213 |
@param cell_to_point: Converts cell data to point data (by averaging) |
214 |
@type outline: Boolean |
215 |
@param outline: Places an outline around the domain surface |
216 |
""" |
217 |
|
218 |
self.__data_collector = data_collector |
219 |
self.__arrow = arrow |
220 |
self.__color_mode = color_mode |
221 |
self.__viewport = viewport |
222 |
self.__lut = lut |
223 |
self.__cell_to_point = cell_to_point |
224 |
self.__outline = outline |
225 |
|
226 |
# Keeps track whether VelocityOnPlaneCut has been modified. |
227 |
self.__modified = True |
228 |
Transform.__init__(self) |
229 |
Plane.__init__(self) |
230 |
Cutter.__init__(self) |
231 |
MaskPoints.__init__(self) |
232 |
Glyph3D.__init__(self) |
233 |
DataSetMapper.__init__(self) |
234 |
Actor3D.__init__(self) |
235 |
scene._addVisualizationModules(self) |
236 |
|
237 |
# ----- Outline ----- |
238 |
|
239 |
# NOTE: Changes cannot be made to the Outline's properties from the |
240 |
# driver. |
241 |
if(self.__outline == True): |
242 |
outline = Outline(self.__data_collector._getDataCollectorOutput()) |
243 |
mapper = DataSetMapper() |
244 |
mapper._setupDataSetMapper(outline._getOutlineOutput()) |
245 |
|
246 |
actor3D = Actor3D() |
247 |
actor3D._setupActor3D(mapper._getDataSetMapper()) |
248 |
# Default outline color is black. |
249 |
actor3D.setColor(Color.BLACK) |
250 |
|
251 |
# Default line width is 1. |
252 |
actor3D._setLineWidth(1) |
253 |
scene._addActor3D(self.__viewport, actor3D._getActor3D()) |
254 |
|
255 |
# ----- Velocity on a cut plane ----- |
256 |
|
257 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
258 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
259 |
# will take place. |
260 |
if(lut == Lut.COLOR): # Colored lookup table. |
261 |
lookup_table = LookupTable() |
262 |
lookup_table._setTableValue() |
263 |
elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
264 |
lookup_table = LookupTable() |
265 |
lookup_table._setLookupTableToGreyScale() |
266 |
|
267 |
self._setupPlane(self._getTransform()) |
268 |
|
269 |
if(self.__cell_to_point == True): # Converts cell data to point data. |
270 |
c2p = CellDataToPointData( |
271 |
self.__data_collector._getDataCollectorOutput()) |
272 |
self._setupCutter(c2p._getCellToPointOutput(), self._getPlane()) |
273 |
elif(self.__cell_to_point == False): # No conversion happens. |
274 |
self._setupCutter(self.__data_collector._getDataCollectorOutput(), |
275 |
self._getPlane()) |
276 |
|
277 |
self._setupMaskPoints(self._getCutterOutput()) |
278 |
|
279 |
if(self.__arrow == Arrow.TWO_D): # Use 2D arrows. |
280 |
Arrow2D.__init__(self) |
281 |
self._setupGlyph3D(self._getMaskPointsOutput(), |
282 |
self._getActor2DOutput()) |
283 |
elif(self.__arrow == Arrow.THREE_D): # Use 3D arrows. |
284 |
Arrow3D.__init__(self) |
285 |
self._setupGlyph3D(self._getMaskPointsOutput(), |
286 |
self._getArrow3DOutput()) |
287 |
|
288 |
self._setupDataSetMapper(self._getGlyph3DOutput(), |
289 |
lookup_table._getLookupTable()) |
290 |
|
291 |
self._setupActor3D(self._getDataSetMapper()) |
292 |
scene._addActor3D(self.__viewport, self._getActor3D()) |
293 |
|
294 |
def _isModified(self): |
295 |
""" |
296 |
Return whether the VelocityOnPlaneCut or DataCollector has been |
297 |
modified. |
298 |
|
299 |
@rtype: Boolean |
300 |
@return: True or False |
301 |
""" |
302 |
|
303 |
return self.__modified or self.__data_collector._isModified() |
304 |
|
305 |
def _render(self, scene): |
306 |
""" |
307 |
Render the velocity cut using a plane. |
308 |
|
309 |
@type scene: L{Scene <scene.Scene>} object |
310 |
@param scene: Scene in which objects are to be rendered on |
311 |
""" |
312 |
|
313 |
if (self._isModified() == True): |
314 |
if(self.__data_collector._isVectorSet() == True): |
315 |
self.__data_collector._setActiveVector() |
316 |
# Color velocity by vector. |
317 |
if(self.__color_mode == ColorMode.VECTOR): |
318 |
self._setColorModeByVector() |
319 |
self._setRange(self.__data_collector._getVectorRange()) |
320 |
self._setScalarRange(self.__data_collector._getVectorRange()) |
321 |
# Color velocity by scalar. |
322 |
elif(self.__color_mode == ColorMode.SCALAR): |
323 |
self._setColorModeByScalar() |
324 |
self._setRange(self.__data_collector._getScalarRange()) |
325 |
self._setScalarRange(self.__data_collector._getScalarRange()) |
326 |
|
327 |
self.__modified = False |
328 |
|
329 |
|
330 |
############################################################################### |
331 |
|
332 |
|
333 |
from clipper import Clipper |
334 |
|
335 |
# NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane, |
336 |
# Clipper and MaskPoints were inherited to allow access to |
337 |
# their public methods from the driver. |
338 |
class VelocityOnPlaneClip(DataSetMapper, Actor3D, Arrow2D, Arrow3D, |
339 |
Glyph3D, Transform, Plane, Clipper, MaskPoints): |
340 |
""" |
341 |
This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>} |
342 |
, except that it shows a vector field using arrows clipped using a plane. |
343 |
""" |
344 |
|
345 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
346 |
# This saves the user from specifying the viewport when there is only one. |
347 |
# If no lut is specified, the color scheme will be used. |
348 |
def __init__(self, scene, data_collector, arrow = Arrow.TWO_D, |
349 |
color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST, |
350 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
351 |
""" |
352 |
Initialise the VelocityOnPlaneClip. |
353 |
|
354 |
@attention: The source can either be point or cell data. If the |
355 |
source is cell data, a conversion to point data may or may not be |
356 |
required, in order for the object to be rendered correctly. |
357 |
If a conversion is needed, the 'cell_to_point' flag must be set to |
358 |
'True', otherwise 'False' (which is the default). |
359 |
|
360 |
@type scene: L{Scene <scene.Scene>} object |
361 |
@param scene: Scene in which objects are to be rendered on |
362 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
363 |
object |
364 |
@param data_collector: Deal with source of data for visualisation |
365 |
@type arrow: L{Arrow <constant.Arrow>} constant |
366 |
@param arrow: Type of arrow (two dimensional or three dimensional) |
367 |
@type color_mode: L{ColorMode <constant.ColorMode>} constant |
368 |
@param color_mode: Type of color mode |
369 |
@type viewport: L{Viewport <constant.Viewport>} constant |
370 |
@param viewport: Viewport in which objects are to be rendered on |
371 |
@type lut : L{Lut <constant.Lut>} constant |
372 |
@param lut: Lookup table color scheme |
373 |
@type cell_to_point: Boolean |
374 |
@param cell_to_point: Converts cell data to point data (by averaging) |
375 |
@type outline: Boolean |
376 |
@param outline: Places an outline around the domain surface |
377 |
""" |
378 |
|
379 |
self.__data_collector = data_collector |
380 |
self.__arrow = arrow |
381 |
self.__color_mode = color_mode |
382 |
self.__viewport = viewport |
383 |
self.__lut = lut |
384 |
self.__cell_to_point = cell_to_point |
385 |
self.__outline = outline |
386 |
|
387 |
# Keeps track whether VelocityOnPlaneCut has been modified. |
388 |
self.__modified = True |
389 |
Transform.__init__(self) |
390 |
Plane.__init__(self) |
391 |
Clipper.__init__(self) |
392 |
MaskPoints.__init__(self) |
393 |
Glyph3D.__init__(self) |
394 |
DataSetMapper.__init__(self) |
395 |
Actor3D.__init__(self) |
396 |
scene._addVisualizationModules(self) |
397 |
|
398 |
# ----- Outline ----- |
399 |
|
400 |
# NOTE: Changes cannot be made to the Outline's properties from the |
401 |
# driver. |
402 |
if(self.__outline == True): |
403 |
outline = Outline(self.__data_collector._getDataCollectorOutput()) |
404 |
mapper = DataSetMapper() |
405 |
mapper._setupDataSetMapper(outline._getOutlineOutput()) |
406 |
|
407 |
actor3D = Actor3D() |
408 |
actor3D._setupActor3D(mapper._getDataSetMapper()) |
409 |
# Default outline color is black. |
410 |
actor3D.setColor(Color.BLACK) |
411 |
|
412 |
# Default line width is 1. |
413 |
actor3D._setLineWidth(1) |
414 |
scene._addActor3D(self.__viewport, actor3D._getActor3D()) |
415 |
|
416 |
# ----- Velocity on a clipped plane ----- |
417 |
|
418 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
419 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
420 |
# will take place. |
421 |
if(self.__lut == Lut.COLOR): # Colored lookup table. |
422 |
lookup_table = LookupTable() |
423 |
lookup_table._setTableValue() |
424 |
elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
425 |
lookup_table = LookupTable() |
426 |
lookup_table._setLookupTableToGreyScale() |
427 |
|
428 |
self._setupPlane(self._getTransform()) |
429 |
|
430 |
if(self.__cell_to_point == True): # Converts cell data to point data. |
431 |
c2p = CellDataToPointData( |
432 |
self.__data_collector._getDataCollectorOutput()) |
433 |
self._setupMaskPoints(c2p._getCellToPointOutput()) |
434 |
elif(self.__cell_to_point == False): # No conversion happens. |
435 |
self._setupMaskPoints( |
436 |
self.__data_collector._getDataCollectorOutput()) |
437 |
|
438 |
# NOTE: Glyph3D must come before Clipper. Otherwise clipping may not |
439 |
# work correctly. |
440 |
if(self.__arrow == Arrow.TWO_D): # Use 2D arrows. |
441 |
Arrow2D.__init__(self) |
442 |
self._setupGlyph3D(self._getMaskPointsOutput(), |
443 |
self._getArrow2DOutput()) |
444 |
elif(self.__arrow == Arrow.THREE_D): # Use 3D arrows. |
445 |
Arrow3D.__init__(self) |
446 |
self._setupGlyph3D(self._getMaskPointsOutput(), |
447 |
self._getArrow3DOutput()) |
448 |
|
449 |
self._setupClipper(self._getGlyph3DOutput(), self._getPlane()) |
450 |
self._setClipFunction() |
451 |
|
452 |
# NOTE: Clipper must come after Glyph. Otherwise clipping |
453 |
# may not work correctly. |
454 |
self._setupDataSetMapper(self._getClipperOutput(), |
455 |
lookup_table._getLookupTable()) |
456 |
|
457 |
self._setupActor3D(self._getDataSetMapper()) |
458 |
scene._addActor3D(self.__viewport, self._getActor3D()) |
459 |
|
460 |
def _isModified(self): |
461 |
""" |
462 |
Return whether the VelocityOnPlaneClip or DataCollector has been |
463 |
modified. |
464 |
|
465 |
@rtype: Boolean |
466 |
@return: True or False |
467 |
""" |
468 |
|
469 |
return self.__modified or self.__data_collector._isModified() |
470 |
|
471 |
def _render(self, scene): |
472 |
""" |
473 |
Render the velocity clip using a plane.. |
474 |
|
475 |
@type scene: L{Scene <scene.Scene>} object |
476 |
@param scene: Scene in which objects are to be rendered on |
477 |
""" |
478 |
|
479 |
if (self._isModified() == True): |
480 |
if(self.__data_collector._isVectorSet() == True): |
481 |
self.__data_collector._setActiveVector() |
482 |
# Color velocity by vector. |
483 |
if(self.__color_mode == ColorMode.VECTOR): |
484 |
self._setColorModeByVector() |
485 |
self._setRange(self.__data_collector._getVectorRange()) |
486 |
self._setScalarRange(self.__data_collector._getVectorRange()) |
487 |
# Color velocity by scalar. |
488 |
elif(self.__color_mode == ColorMode.SCALAR): |
489 |
self._setColorModeByScalar() |
490 |
self._setRange(self.__data_collector._getScalarRange()) |
491 |
self._setScalarRange(self.__data_collector._getScalarRange()) |
492 |
|
493 |
self.__modified = False |
494 |
|
495 |
|