/[escript]/trunk/pyvisi/py_src/map.py
ViewVC logotype

Contents of /trunk/pyvisi/py_src/map.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1114 - (show annotations)
Sun Apr 22 05:16:05 2007 UTC (13 years, 5 months ago) by jongui
File MIME type: text/x-python
File size: 16208 byte(s)
Started doing some changes to the modules due to the problem of the continuous increase in memory usage when reading directly from escript objects.
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, VizType, ColorMode
11 from average import CellDataToPointData
12
13 # NOTE: DataSetMapper and Actor3D were inherited to allow access to their
14 # public methods from the driver.
15 class Map(DataSetMapper, Actor3D):
16 """
17 Class that shows a scalar field on a domain surface. The domain surface
18 can either be colored or grey-scaled, depending on the lookup table used.
19 """
20
21 # The SOUTH_WEST default viewport is used when there is only one viewport.
22 # This saves the user from specifying the viewport when there is only one.
23 # If no lut is specified, the color scheme will be used.
24 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
25 lut = Lut.COLOR, cell_to_point = False, outline = True):
26 """
27 Initialise the Map.
28
29 @attention: The source can either be point or cell data. If the
30 source is cell data, a conversion to point data may or may not be
31 required, in order for the object to be rendered correctly.
32 If a conversion is needed, the 'cell_to_point' flag must be set to
33 'True', otherwise 'False' (which is the default).
34
35 @type scene: L{Scene <scene.Scene>} object
36 @param scene: Scene in which objects are to be rendered on
37 @type data_collector: L{DataCollector <datacollector.DataCollector>}
38 object
39 @param data_collector: Deal with source of data for vizualisation
40 @type viewport: L{Viewport <constant.Viewport>} constant
41 @param viewport: Viewport in which objects are to be rendered on
42 @type lut : L{Lut <constant.Lut>} constant
43 @param lut: Lookup table color scheme
44 @type cell_to_point: Boolean
45 @param cell_to_point: Converts cell data to point data (by averaging)
46 @type outline: Boolean
47 @param outline: Places an outline around the domain surface
48 """
49
50 # NOTE: Actor3D is inherited and there are two instances declared here.
51 # As a result, when methods from Actor3D is invoked from the driver,
52 # only the methods associated with the latest instance (which in this
53 # case is the Actor3D for the map) can be executed. Actor3D
54 # methods associated with Outline cannot be invoked from the driver.
55 # They can only be called within here, which is why Outline must
56 # be place before map as there is unlikely to be any changes
57 # made to the Outline's Actor3D.
58
59 # ----- Outline -----
60
61 if(outline == True):
62 outline = Outline(data_collector._getOutput())
63 DataSetMapper.__init__(self, outline._getOutput())
64
65 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
66 # Default outline color is black.
67 Actor3D.setColor(self, Color.BLACK)
68
69 # Default line width is 1.
70 Actor3D._setLineWidth(self, 1)
71 scene._addActor3D(viewport, Actor3D._getActor3D(self))
72
73 # ----- Map -----
74
75 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
76 # before DataSetMapper. If it is done after DataSetMapper, no effect
77 # will take place.
78 if(lut == Lut.COLOR): # Colored lookup table.
79 lookup_table = LookupTable()
80 lookup_table._setTableValue()
81 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
82 lookup_table = LookupTable()
83 lookup_table._setLookupTableToGreyScale()
84
85 if(cell_to_point == True): # Converts cell data to point data.
86 c2p = CellDataToPointData(data_collector._getOutput())
87 DataSetMapper.__init__(self, c2p._getOutput(),
88 lookup_table._getLookupTable())
89 elif(cell_to_point == False): # No conversion happens.
90 DataSetMapper.__init__(self, data_collector._getOutput(),
91 lookup_table._getLookupTable())
92
93 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
94
95 data_collector._paramForUpdatingMultipleSources(VizType.MAP,
96 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))
97
98 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
99 scene._addActor3D(viewport, Actor3D._getActor3D(self))
100
101 ###############################################################################
102
103
104 from transform import Transform
105 from plane import Plane
106 from cutter import Cutter
107
108 # NOTE: DataSetMapper, Actor3D, Transform, Plane and Cutter were inherited
109 # to allow access to their public methods from the driver.
110 class MapOnPlaneCut(DataSetMapper, Actor3D, Transform, Plane, Cutter):
111 """
112 This class works in a similar way to L{Map <map.Map>}, except that it
113 shows a scalar field on a plane. The plane can be translated and rotated
114 along the X, Y and Z axes.
115 """
116
117 # The SOUTH_WEST default viewport is used when there is only one viewport.
118 # This saves the user from specifying the viewport when there is only one.
119 # If no lut is specified, the color scheme will be used.
120 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
121 lut = Lut.COLOR, cell_to_point = False, outline = True):
122 """
123 Initialise the MapOnPlanceCut.
124
125 @attention: The source can either be point or cell data. If the
126 source is cell data, a conversion to point data may or may not be
127 required, in order for the object to be rendered correctly.
128 If a conversion is needed, the 'cell_to_point' flag must be set to
129 'True', otherwise 'False' (which is the default).
130
131 @type scene: L{Scene <scene.Scene>} object
132 @param scene: Scene in which objects are to be rendered on
133 @type data_collector: L{DataCollector <datacollector.DataCollector>}
134 object
135 @param data_collector: Deal with source of data for visualisation
136 @type viewport: L{Viewport <constant.Viewport>} constant
137 @param viewport: Viewport in which objects are to be rendered on
138 @type lut : L{Lut <constant.Lut>} constant
139 @param lut: Lookup table color scheme
140 @type cell_to_point: Boolean
141 @param cell_to_point: Converts cell data to point data (by averaging)
142 @type outline: Boolean
143 @param outline: Places an outline around the domain surface
144 """
145
146 # NOTE: Actor3D is inherited and there are two instances declared here.
147 # As a result, when methods from Actor3D is invoked from the driver,
148 # only the methods associated with the latest instance (which in this
149 # case is the Actor3D for the map) can be executed. Actor3D
150 # methods associated with Outline cannot be invoked from the driver.
151 # They can only be called within here, which is why Outline must
152 # be place before the map as there is unlikely to be any changes
153 # made to the Outline's Actor3D.
154
155 # ----- Outline -----
156
157 if(outline == True):
158 outline = Outline(data_collector._getOutput())
159 DataSetMapper.__init__(self, outline._getOutput())
160
161 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
162 # Default outline color is black.
163 Actor3D.setColor(self, Color.BLACK)
164 # Default line width is 1.
165
166 Actor3D._setLineWidth(self, 1)
167 scene._addActor3D(viewport, Actor3D._getActor3D(self))
168
169 # ----- Map on a plane -----
170
171 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
172 # before DataSetMapper. If it is done after DataSetMapper, no effect
173 # will take place.
174 if(lut == Lut.COLOR): # Colored lookup table.
175 lookup_table = LookupTable()
176 lookup_table._setTableValue()
177 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
178 lookup_table = LookupTable()
179 lookup_table._setLookupTableToGreyScale()
180
181 Transform.__init__(self)
182 Plane.__init__(self, Transform._getTransform(self))
183
184 if(cell_to_point == True): # Converts cell data to point data.
185 c2p = CellDataToPointData(data_collector._getOutput())
186 Cutter.__init__(self, c2p._getOutput(), Plane._getPlane(self))
187 elif(cell_to_point == False): # No conversion happens.
188 Cutter.__init__(self, data_collector._getOutput(),
189 Plane._getPlane(self))
190
191 DataSetMapper.__init__(self, Cutter._getOutput(self),
192 lookup_table._getLookupTable())
193 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
194
195 data_collector._paramForUpdatingMultipleSources(VizType.MAP,
196 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))
197
198 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
199 scene._addActor3D(viewport, Actor3D._getActor3D(self))
200
201
202 ###############################################################################
203
204
205 from clipper import Clipper
206
207 # NOTE: DataSetMapper, Actor3D, Transform, Plane and Clipper were inherited
208 # to allow access to their public methods from the driver.
209 class MapOnPlaneClip(DataSetMapper, Actor3D, Transform, Plane, Clipper):
210 """
211 This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
212 except that it shows a scalar field clipped using a plane.
213 """
214
215 # The SOUTH_WEST default viewport is used when there is only one viewport.
216 # This saves the user from specifying the viewport when there is only one.
217 # If no lut is specified, the color scheme will be used.
218 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
219 lut = Lut.COLOR, cell_to_point = False, outline = True):
220 """
221 Initialise the MapOnPlaneClip.
222
223 @attention: The source can either be point or cell data. If the
224 source is cell data, a conversion to point data may or may not be
225 required, in order for the object to be rendered correctly.
226 If a conversion is needed, the 'cell_to_point' flag must be set to
227 'True', otherwise 'False' (which is the default).
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 objects are to be rendered on
236 @type lut : L{Lut <constant.Lut>} constant
237 @param lut: Lookup table color scheme
238 @type cell_to_point: Boolean
239 @param cell_to_point: Converts cell data to point data (by averaging)
240 @type outline: Boolean
241 @param outline: Places an outline around the domain surface
242 """
243
244 # NOTE: Actor3D is inherited and there are two instances declared here.
245 # As a result, when methods from Actor3D is invoked from the driver,
246 # only the methods associated with the latest instance (which in this
247 # case is the Actor3D for the map) can be executed. Actor3D
248 # methods associated with Outline cannot be invoked from the driver.
249 # They can only be called within here, which is why Outline must
250 # be place before the map as there is unlikely to be any changes
251 # made to the Outline's Actor3D.
252
253 # ----- Outline -----
254
255 if(outline == True):
256 outline = Outline(data_collector._getOutput())
257 DataSetMapper.__init__(self, outline._getOutput())
258
259 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
260 # Default outline color is black.
261 Actor3D.setColor(self, Color.BLACK)
262
263 # Default line width is 1.
264 Actor3D._setLineWidth(self, 1)
265 scene._addActor3D(viewport, Actor3D._getActor3D(self))
266
267 # ----- Map on a clipped plane -----
268
269 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
270 # before DataSetMapper. If it is done after DataSetMapper, no effect
271 # will take place.
272 if(lut == Lut.COLOR): # Colored lookup table.
273 lookup_table = LookupTable()
274 lookup_table._setTableValue()
275 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
276 lookup_table = LookupTable()
277 lookup_table._setLookupTableToGreyScale()
278
279 Transform.__init__(self)
280 Plane.__init__(self, Transform._getTransform(self))
281
282 if(cell_to_point == True): # Converts cell data to point data.
283 c2p = CellDataToPointData(data_collector._getOutput())
284 Clipper.__init__(self, c2p._getOutput(), Plane._getPlane(self))
285 elif(cell_to_point == False): # No conversion happens.
286 Clipper.__init__(self, data_collector._getOutput(),
287 Plane._getPlane(self))
288
289 Clipper._setClipFunction(self)
290
291 DataSetMapper.__init__(self, Clipper._getOutput(self),
292 lookup_table._getLookupTable())
293 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
294
295 data_collector._paramForUpdatingMultipleSources(VizType.MAP,
296 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))
297
298 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
299 scene._addActor3D(viewport, Actor3D._getActor3D(self))
300
301
302 #############################################################################
303
304
305 # NOTE: DataSetMapper, Actor3D and Clipper were inherited
306 # to allow access to their public methods from the driver.
307 class MapOnScalarClip(DataSetMapper, Actor3D, Clipper):
308 """
309 This class works in a similar way to L{Map <map.Map>}, except that it
310 shows a scalar field clipped using a scalar value.
311 """
312
313 # The SOUTH_WEST default viewport is used when there is only one viewport.
314 # This saves the user from specifying the viewport when there is only one.
315 # If no lut is specified, the color scheme will be used.
316 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
317 lut = Lut.COLOR, cell_to_point = False, outline = True):
318 """
319 Initialise the MapOnScalarClip.
320
321 @attention: The source can either be point or cell data. If the
322 source is cell data, a conversion to point data may or may not be
323 required, in order for the object to be rendered correctly.
324 If a conversion is needed, the 'cell_to_point' flag must be set to
325 'True', otherwise 'False' (which is the default).
326
327 @type scene: L{Scene <scene.Scene>} object
328 @param scene: Scene in which objects are to be rendered on
329 @type data_collector: L{DataCollector <datacollector.DataCollector>}
330 object
331 @param data_collector: Deal with source of data for visualisation
332 @type viewport: L{Viewport <constant.Viewport>} constant
333 @param viewport: Viewport in which objects are to be rendered on
334 @type lut : L{Lut <constant.Lut>} constant
335 @param lut: Lookup table color scheme
336 @type cell_to_point: Boolean
337 @param cell_to_point: Converts cell data to point data (by averaging)
338 @type outline: Boolean
339 @param outline: Places an outline around the domain surface
340 """
341
342 # NOTE: Actor3D is inherited and there are two instances declared here.
343 # As a result, when methods from Actor3D is invoked from the driver,
344 # only the methods associated with the latest instance (which in this
345 # case is the Actor3D for the map) can be executed. Actor3D
346 # methods associated with Outline cannot be invoked from the driver.
347 # They can only be called within here, which is why Outline must
348 # be place before the map as there is unlikely to be any changes
349 # made to the Outline's Actor3D.
350
351 # ----- Outline -----
352
353 if(outline == True):
354 outline = Outline(data_collector._getOutput())
355 DataSetMapper.__init__(self, outline._getOutput())
356
357 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
358 # Default outline color is black.
359 Actor3D.setColor(self, Color.BLACK)
360
361 # Default line width is 1.
362 Actor3D._setLineWidth(self, 1)
363 scene._addActor3D(viewport, Actor3D._getActor3D(self))
364
365 # ----- Map clipped using a scalar value -----
366
367 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
368 # before DataSetMapper. If it is done after DataSetMapper, no effect
369 # will take place.
370 if(lut == Lut.COLOR): # Colored lookup table.
371 lookup_table = LookupTable()
372 lookup_table._setTableValue()
373 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
374 lookup_table = LookupTable()
375 lookup_table._setLookupTableToGreyScale()
376
377
378 if(cell_to_point == True): # Converts cell data to point data.
379 c2p = CellDataToPointData(data_collector._getOutput())
380 # None is used because a plane is not required when a scalar
381 # value is used to perform the clipping.
382 Clipper.__init__(self, c2p._getOutput(), None)
383 elif(cell_to_point == False): # No conversion happens.
384 Clipper.__init__(self, data_collector._getOutput(),None)
385
386 DataSetMapper.__init__(self, Clipper._getOutput(self),
387 lookup_table._getLookupTable())
388 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
389
390 data_collector._paramForUpdatingMultipleSources(VizType.MAP,
391 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))
392
393 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
394 scene._addActor3D(viewport, Actor3D._getActor3D(self))
395
396

  ViewVC Help
Powered by ViewVC 1.1.26