/[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 1115 - (show annotations)
Sun Apr 22 07:18:30 2007 UTC (12 years ago) by jongui
File MIME type: text/x-python
File size: 16657 byte(s)
The problem regarding the increasing use of memory when Map is instantiated is partially fixed. Some problems still persists when the Map instance invoke methods.

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

  ViewVC Help
Powered by ViewVC 1.1.26