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