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