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