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