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