1 |
ksteube |
1147 |
""" |
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 |
jongui |
1148 |
from constant import Viewport, Color, Lut, ColorMode |
10 |
ksteube |
1147 |
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 |
jongui |
1148 |
from position import GlobalPosition |
16 |
ksteube |
1147 |
|
17 |
|
|
# NOTE: DataSetMapper, Actor3D, PointSource, StreamLineModule and Tube were |
18 |
|
|
# inherited to allow access to their public methods from the driver. |
19 |
|
|
class StreamLine(DataSetMapper, Actor3D, PointSource, StreamLineModule, Tube): |
20 |
|
|
""" |
21 |
|
|
Class that shows the direction of particles of a vector field using |
22 |
|
|
streamlines.The streamlines can either be colored or grey-scaled, |
23 |
|
|
depending on the lookup table used. If the streamlines are colored, |
24 |
|
|
there are two possible coloring modes: (1) using vector data or (2) |
25 |
|
|
using scalar data. |
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, lut = Lut.COLOR, cell_to_point = False, |
33 |
|
|
outline = True): |
34 |
|
|
""" |
35 |
|
|
Initialise the StreamLine. |
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 viewport: L{Viewport <constant.Viewport>} constant |
49 |
|
|
@param viewport: Viewport in which the object is to be rendered on |
50 |
|
|
@type color_mode: L{ColorMode <constant.ColorMode>} constant |
51 |
|
|
@param color_mode: Type of color mode |
52 |
|
|
@type lut : L{Lut <constant.Lut>} constant |
53 |
|
|
@param lut: Lookup table color scheme |
54 |
|
|
@type cell_to_point: Boolean |
55 |
|
|
@param cell_to_point: Converts cell data to point data (by averaging) |
56 |
|
|
@type outline: Boolean |
57 |
|
|
@param outline: Places an outline around the domain surface |
58 |
|
|
""" |
59 |
|
|
|
60 |
jongui |
1148 |
self.__data_collector = data_collector |
61 |
|
|
self.__viewport = viewport |
62 |
|
|
self.__color_mode = color_mode |
63 |
|
|
self.__lut = lut |
64 |
|
|
self.__cell_to_point = cell_to_point |
65 |
|
|
self.__outline = outline |
66 |
ksteube |
1147 |
|
67 |
jongui |
1148 |
# Keeps track whether Streamline has been modified. |
68 |
|
|
self.__modified = True |
69 |
|
|
PointSource.__init__(self) |
70 |
|
|
StreamLineModule.__init__(self) |
71 |
|
|
Tube.__init__(self) |
72 |
|
|
DataSetMapper.__init__(self) |
73 |
|
|
Actor3D.__init__(self) |
74 |
|
|
scene._addVisualizationModules(self) |
75 |
ksteube |
1147 |
|
76 |
jongui |
1148 |
# ----- Outline ----- |
77 |
ksteube |
1147 |
|
78 |
jongui |
1148 |
# NOTE: Changes cannot be made to the Outline's properties from the |
79 |
|
|
# driver. |
80 |
|
|
if(self.__outline == True): |
81 |
|
|
outline = Outline(self.__data_collector._getDataCollectorOutput()) |
82 |
|
|
mapper = DataSetMapper() |
83 |
|
|
mapper._setupDataSetMapper(outline._getOutlineOutput()) |
84 |
|
|
|
85 |
|
|
actor3D = Actor3D() |
86 |
|
|
actor3D._setupActor3D(mapper._getDataSetMapper()) |
87 |
ksteube |
1147 |
# Default outline color is black. |
88 |
jongui |
1148 |
actor3D.setColor(Color.BLACK) |
89 |
|
|
|
90 |
ksteube |
1147 |
# Default line width is 1. |
91 |
jongui |
1148 |
actor3D._setLineWidth(1) |
92 |
jongui |
1158 |
scene._addActor3D(self.__viewport, actor3D._getActor3D()) |
93 |
ksteube |
1147 |
|
94 |
|
|
# ----- Streamline ----- |
95 |
|
|
|
96 |
|
|
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
97 |
|
|
# before DataSetMapper. If it is done after DataSetMapper, no effect |
98 |
|
|
# will take place. |
99 |
jongui |
1148 |
if(self.__lut == Lut.COLOR): # Colored lookup table. |
100 |
ksteube |
1147 |
lookup_table = LookupTable() |
101 |
|
|
lookup_table._setTableValue() |
102 |
jongui |
1148 |
elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
103 |
ksteube |
1147 |
lookup_table = LookupTable() |
104 |
|
|
lookup_table._setLookupTableToGreyScale() |
105 |
|
|
|
106 |
jongui |
1148 |
if(self.__cell_to_point == True): # Converts cell data to point data. |
107 |
|
|
c2p = CellDataToPointData( |
108 |
|
|
self.__data_collector._getDataCollectorOutput()) |
109 |
|
|
self._setupPointSource(c2p._getCellToPointOutput()) |
110 |
|
|
self._setupStreamLineModule(c2p._getCellToPointOutput(), |
111 |
|
|
self._getPointSourceOutput()) |
112 |
|
|
elif(self.__cell_to_point == False): # No conversion happens. |
113 |
|
|
self._setupPointSource( |
114 |
|
|
self.__data_collector._getDataCollectorOutput()) |
115 |
|
|
self._setupStreamLineModule( |
116 |
|
|
self.__data_collector._getDataCollectorOutput(), |
117 |
|
|
self._getPointSourceOutput()) |
118 |
ksteube |
1147 |
|
119 |
jongui |
1148 |
self._setupTube(self._getStreamLineModuleOutput()) |
120 |
|
|
self._setupDataSetMapper(self._getTubeOutput(), |
121 |
ksteube |
1147 |
lookup_table._getLookupTable()) |
122 |
|
|
|
123 |
jongui |
1148 |
self._setupActor3D(self._getDataSetMapper()) |
124 |
jongui |
1158 |
scene._addActor3D(self.__viewport, self._getActor3D()) |
125 |
ksteube |
1147 |
|
126 |
jongui |
1148 |
def _isModified(self): |
127 |
|
|
""" |
128 |
|
|
Return whether the StreamLine or DataCollector has been modified. |
129 |
ksteube |
1147 |
|
130 |
jongui |
1148 |
@rtype: Boolean |
131 |
|
|
@return: True or False |
132 |
|
|
""" |
133 |
ksteube |
1147 |
|
134 |
jongui |
1148 |
return self.__modified or self.__data_collector._isModified() |
135 |
ksteube |
1147 |
|
136 |
jongui |
1158 |
def _render(self, scene): |
137 |
jongui |
1148 |
""" |
138 |
|
|
Render the streamline. |
139 |
jongui |
1158 |
|
140 |
|
|
@type scene: L{Scene <scene.Scene>} object |
141 |
|
|
@param scene: Scene in which objects are to be rendered on |
142 |
jongui |
1148 |
""" |
143 |
|
|
|
144 |
|
|
if (self._isModified() == True): |
145 |
|
|
if(self._isPointSourceCenterSet() != True): |
146 |
|
|
center = self.__data_collector._getCenter() |
147 |
|
|
center = GlobalPosition(center[0], center[1], center[2]) |
148 |
|
|
self.setPointSourceCenter(center) |
149 |
|
|
|
150 |
|
|
self._setPointSourceCenter() |
151 |
|
|
|
152 |
|
|
if(self.__data_collector._isScalarSet() == True): |
153 |
|
|
self.__data_collector._setActiveScalar() |
154 |
|
|
if(self.__data_collector._isVectorSet() == True): |
155 |
|
|
self.__data_collector._setActiveVector() |
156 |
|
|
|
157 |
|
|
# Color streamline by vector. |
158 |
|
|
if(self.__color_mode == ColorMode.VECTOR): |
159 |
|
|
self._setScalarVisibilityOn() |
160 |
|
|
self._setSpeedScalarsOn() |
161 |
|
|
self._setScalarRange(self.__data_collector._getVectorRange()) |
162 |
|
|
# Color streamline by scalar. |
163 |
|
|
elif(self.__color_mode == ColorMode.SCALAR): |
164 |
|
|
self._setScalarVisibilityOn() |
165 |
|
|
self._setSpeedScalarsOff() |
166 |
|
|
self._setScalarRange(self.__data_collector._getScalarRange()) |
167 |
|
|
|
168 |
|
|
self.__modified = False |
169 |
|
|
|
170 |
|
|
|