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