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