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, Lut, ColorMode, VizType |
10 |
from streamlinemodule import StreamLineModule |
11 |
from tube import Tube |
12 |
from point import PointSource |
13 |
from outline import Outline |
14 |
from average import CellDataToPointData |
15 |
|
16 |
# NOTE: DataSetMapper, Actor3D, PointSource, StreamLineModule and Tube were |
17 |
# inherited to allow access to their public methods from the driver. |
18 |
class StreamLine(DataSetMapper, Actor3D, PointSource, StreamLineModule, Tube): |
19 |
""" |
20 |
Class that shows the direction of particles of a vector field using |
21 |
streamlines.The streamlines can either be colored or grey-scaled, |
22 |
depending on the lookup table used. If the streamlines are colored, |
23 |
there are two possible coloring modes: (1) using vector data or (2) |
24 |
using scalar data. |
25 |
""" |
26 |
|
27 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
28 |
# This saves the user from specifying the viewport when there is only one. |
29 |
# If no lut is specified, the color scheme will be used. |
30 |
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, |
31 |
color_mode = ColorMode.VECTOR, lut = Lut.COLOR, cell_to_point = False, |
32 |
outline = True): |
33 |
""" |
34 |
Initialise the StreamLine. |
35 |
|
36 |
@attention: The source can either be point or cell data. If the |
37 |
source is cell data, a conversion to point data may or may not be |
38 |
required, in order for the object to be rendered correctly. |
39 |
If a conversion is needed, the 'cell_to_point' flag must be set to |
40 |
'True', otherwise 'False' (which is the default). |
41 |
|
42 |
@type scene: L{Scene <scene.Scene>} object |
43 |
@param scene: Scene in which objects are to be rendered on |
44 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
45 |
object |
46 |
@param data_collector: Deal with source of data for visualisation |
47 |
@type viewport: L{Viewport <constant.Viewport>} constant |
48 |
@param viewport: Viewport in which the object is to be rendered on |
49 |
@type color_mode: L{ColorMode <constant.ColorMode>} constant |
50 |
@param color_mode: Type of color mode |
51 |
@type lut : L{Lut <constant.Lut>} constant |
52 |
@param lut: Lookup table color scheme |
53 |
@type cell_to_point: Boolean |
54 |
@param cell_to_point: Converts cell data to point data (by averaging) |
55 |
@type outline: Boolean |
56 |
@param outline: Places an outline around the domain surface |
57 |
""" |
58 |
|
59 |
# NOTE: Actor3D is inherited and there are two instances declared here. |
60 |
# As a result, when methods from Actor3D is invoked from the driver, |
61 |
# only the methods associated with the latest instance (which in this |
62 |
# case is the Actor3D for the Tube) can be executed. Actor3D |
63 |
# methods associated with Outline cannot be invoked from the driver. |
64 |
# They can only be called within here, which is why Outline must be |
65 |
# place before Tube as there is unlikely to be any changes |
66 |
# made to the Outline's Actor3D. |
67 |
|
68 |
# ----- Outline ----- |
69 |
|
70 |
if(outline == True): |
71 |
outline = Outline(data_collector._getOutput()) |
72 |
DataSetMapper.__init__(self, outline._getOutput()) |
73 |
|
74 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
75 |
# Default outline color is black. |
76 |
Actor3D.setColor(self, Color.BLACK) |
77 |
# Default line width is 1. |
78 |
Actor3D._setLineWidth(self, 1) |
79 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
80 |
|
81 |
# ----- Streamline ----- |
82 |
|
83 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
84 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
85 |
# will take place. |
86 |
if(lut == Lut.COLOR): # Colored lookup table. |
87 |
lookup_table = LookupTable() |
88 |
lookup_table._setTableValue() |
89 |
elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
90 |
lookup_table = LookupTable() |
91 |
lookup_table._setLookupTableToGreyScale() |
92 |
|
93 |
if(cell_to_point == True): # Converts cell data to point data. |
94 |
c2p = CellDataToPointData(data_collector._getOutput()) |
95 |
PointSource.__init__(self, c2p._getOutput()) |
96 |
StreamLineModule.__init__(self, c2p._getOutput(), |
97 |
PointSource._getOutput(self)) |
98 |
elif(cell_to_point == False): # No conversion happens. |
99 |
PointSource.__init__(self, data_collector._getOutput()) |
100 |
StreamLineModule.__init__(self, data_collector._getOutput(), |
101 |
PointSource._getOutput(self)) |
102 |
|
103 |
Tube.__init__(self, StreamLineModule._getOutput(self)) |
104 |
DataSetMapper.__init__(self, Tube._getOutput(self), |
105 |
lookup_table._getLookupTable()) |
106 |
|
107 |
if(color_mode == ColorMode.VECTOR): # Color velocity by vector. |
108 |
DataSetMapper._setScalarVisibilityOn(self) |
109 |
StreamLineModule._setSpeedScalarsOn(self) |
110 |
DataSetMapper._setScalarRange(self, |
111 |
data_collector._getVectorRange()) |
112 |
|
113 |
data_collector._paramForUpdatingMultipleSources(VizType.STREAMLINE, |
114 |
ColorMode.VECTOR, DataSetMapper._getDataSetMapper(self)) |
115 |
|
116 |
elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar. |
117 |
DataSetMapper._setScalarVisibilityOn(self) |
118 |
StreamLineModule._setSpeedScalarsOff(self) |
119 |
DataSetMapper._setScalarRange(self, |
120 |
data_collector._getScalarRange()) |
121 |
|
122 |
data_collector._paramForUpdatingMultipleSources(VizType.STREAMLINE, |
123 |
ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self)) |
124 |
|
125 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
126 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
127 |
|