/[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 1148 - (show annotations)
Wed May 16 22:45:33 2007 UTC (13 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 17846 byte(s)
Added the updated files for pyvisi and removed some incorrect reference images.
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, 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 # Keeps track whether Map has been modified.
58 DataSetMapper.__init__(self)
59 Actor3D.__init__(self)
60 scene._addVisualizationModules(self)
61
62 # ----- Outline -----
63
64 # NOTE: Changes cannot be made to the Outline's properties from the
65 # driver.
66 if(self.__outline == True):
67 outline = Outline(self.__data_collector._getDataCollectorOutput())
68 mapper = DataSetMapper()
69 mapper._setupDataSetMapper(outline._getOutlineOutput())
70
71 actor3D = Actor3D()
72 actor3D._setupActor3D(mapper._getDataSetMapper())
73 # Default outline color is black.
74 actor3D.setColor(Color.BLACK)
75
76 # Default line width is 1.
77 actor3D._setLineWidth(1)
78 self.__scene._addActor3D(self.__viewport, actor3D._getActor3D())
79
80 # ----- Map -----
81
82 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
83 # before DataSetMapper. If it is done after DataSetMapper, no effect
84 # will take place.
85 if(self.__lut == Lut.COLOR): # Colored lookup table.
86 lookup_table = LookupTable()
87 lookup_table._setTableValue()
88 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
89 lookup_table = LookupTable()
90 lookup_table._setLookupTableToGreyScale()
91
92 if(self.__cell_to_point == True): # Convert cell data to point data.
93 c2p = CellDataToPointData(
94 self.__data_collector._getDataCollectorOutput())
95 self._setupDataSetMapper(c2p._getCellToPointOutput(),
96 lookup_table._getLookupTable())
97 elif(self.__cell_to_point == False): # No conversion happens.
98 self._setupDataSetMapper(
99 self.__data_collector._getDataCollectorOutput(),
100 lookup_table._getLookupTable())
101
102 self._setupActor3D(self._getDataSetMapper())
103 self.__scene._addActor3D(self.__viewport, self._getActor3D())
104
105 def _isModified(self):
106 """
107 Return whether the Map or DataCollector has been modified.
108
109 @rtype: Boolean
110 @return: True or False
111 """
112
113 return self.__modified or self.__data_collector._isModified()
114
115 def _render(self):
116 """
117 Render the surface map.
118 """
119
120 if (self._isModified() == True):
121 if(self.__data_collector._isScalarSet() == True):
122 self.__data_collector._setActiveScalar()
123 self._setScalarRange(self.__data_collector._getScalarRange())
124 self.__modified = False
125
126
127 ###############################################################################
128
129
130 from transform import Transform
131 from plane import Plane
132 from cutter import Cutter
133
134 # NOTE: DataSetMapper, Actor3D, Transform, Plane and Cutter were inherited
135 # to allow access to their public methods from the driver.
136 class MapOnPlaneCut(DataSetMapper, Actor3D, Transform, Plane, Cutter):
137 """
138 This class works in a similar way to L{Map <map.Map>}, except that it
139 shows a scalar field cut using a plane. The plane can be translated
140 and rotated along the X, Y and Z axes.
141 """
142
143 # The SOUTH_WEST default viewport is used when there is only one viewport.
144 # This saves the user from specifying the viewport when there is only one.
145 # If no lut is specified, the color scheme will be used.
146 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
147 lut = Lut.COLOR, cell_to_point = False, outline = True):
148 """
149 Initialise the MapOnPlanceCut.
150
151 @attention: The source can either be point or cell data. If the
152 source is cell data, a conversion to point data may or may not be
153 required, in order for the object to be rendered correctly.
154 If a conversion is needed, the 'cell_to_point' flag must be set to
155 'True', otherwise 'False' (which is the default).
156
157 @type scene: L{Scene <scene.Scene>} object
158 @param scene: Scene in which objects are to be rendered on
159 @type data_collector: L{DataCollector <datacollector.DataCollector>}
160 object
161 @param data_collector: Deal with source of data for visualisation
162 @type viewport: L{Viewport <constant.Viewport>} constant
163 @param viewport: Viewport in which objects are to be rendered on
164 @type lut : L{Lut <constant.Lut>} constant
165 @param lut: Lookup table color scheme
166 @type cell_to_point: Boolean
167 @param cell_to_point: Converts cell data to point data (by averaging)
168 @type outline: Boolean
169 @param outline: Places an outline around the domain surface
170 """
171
172 self.__scene = scene
173 self.__data_collector = data_collector
174 self.__viewport = viewport
175 self.__lut = lut
176 self.__cell_to_point = cell_to_point
177 self.__outline = outline
178
179 # Keeps track whether MapOnPlaneCut has been modified.
180 self.__modified = True
181 Transform.__init__(self)
182 Plane.__init__(self)
183 Cutter.__init__(self)
184 DataSetMapper.__init__(self)
185 Actor3D.__init__(self)
186 scene._addVisualizationModules(self)
187
188 # ----- Outline -----
189
190 # NOTE: Changes cannot be made to the Outline's properties from the
191 # driver.
192 if(self.__outline == True):
193 outline = Outline(self.__data_collector._getDataCollectorOutput())
194 mapper = DataSetMapper()
195 mapper._setupDataSetMapper(outline._getOutlineOutput())
196
197 actor3D = Actor3D()
198 actor3D._setupActor3D(mapper._getDataSetMapper())
199 # Default outline color is black.
200 actor3D.setColor(Color.BLACK)
201
202 # Default line width is 1.
203 actor3D._setLineWidth(1)
204 self.__scene._addActor3D(self.__viewport, actor3D._getActor3D())
205
206 # ----- Map on a plane -----
207 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
208 # before DataSetMapper. If it is done after DataSetMapper, no effect
209 # will take place.
210 if(self.__lut == Lut.COLOR): # Colored lookup table.
211 lookup_table = LookupTable()
212 lookup_table._setTableValue()
213 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
214 lookup_table = LookupTable()
215 lookup_table._setLookupTableToGreyScale()
216
217 self._setupPlane(self._getTransform())
218
219 if(self.__cell_to_point == True): # Converts cell data to point data.
220 c2p = CellDataToPointData(
221 self.__data_collector._getDataCollectorOutput())
222 self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())
223 elif(self.__cell_to_point == False): # No conversion happens.
224 c2p = CellDataToPointData(
225 self.__data_collector._getDataCollectorOutput())
226 self._setupCutter(self.__data_collector._getDataCollectorOutput(),
227 self._getPlane())
228
229 self._setupDataSetMapper(self._getCutterOutput(),
230 lookup_table._getLookupTable())
231
232 self._setupActor3D(self._getDataSetMapper())
233 self.__scene._addActor3D(self.__viewport, self._getActor3D())
234
235 def _isModified(self):
236 """
237 Return whether the MapOnPlaneCut or DataCollector has been modified.
238
239 @rtype: Boolean
240 @return: True or False
241 """
242
243 return self.__modified or self.__data_collector._isModified()
244
245 def _render(self):
246 """
247 Render the surface map cut using a plane.
248 """
249
250 if (self._isModified() == True):
251 if(self.__data_collector._isScalarSet() == True):
252 self.__data_collector._setActiveScalar()
253 self._setScalarRange(self.__data_collector._getScalarRange())
254 self.__modified = False
255
256
257 ###############################################################################
258
259
260 from clipper import Clipper
261
262 # NOTE: DataSetMapper, Actor3D, Transform, Plane and Clipper were inherited
263 # to allow access to their public methods from the driver.
264 class MapOnPlaneClip(DataSetMapper, Actor3D, Transform, Plane, Clipper):
265 """
266 This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
267 except that it shows a scalar field clipped using a plane.
268 """
269
270 # The SOUTH_WEST default viewport is used when there is only one viewport.
271 # This saves the user from specifying the viewport when there is only one.
272 # If no lut is specified, the color scheme will be used.
273 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
274 lut = Lut.COLOR, cell_to_point = False, outline = True):
275 """
276 Initialise the MapOnPlaneClip.
277
278 @attention: The source can either be point or cell data. If the
279 source is cell data, a conversion to point data may or may not be
280 required, in order for the object to be rendered correctly.
281 If a conversion is needed, the 'cell_to_point' flag must be set to
282 'True', otherwise 'False' (which is the default).
283
284 @type scene: L{Scene <scene.Scene>} object
285 @param scene: Scene in which objects are to be rendered on
286 @type data_collector: L{DataCollector <datacollector.DataCollector>}
287 object
288 @param data_collector: Deal with source of data for visualisation
289 @type viewport: L{Viewport <constant.Viewport>} constant
290 @param viewport: Viewport in which objects are to be rendered on
291 @type lut : L{Lut <constant.Lut>} constant
292 @param lut: Lookup table color scheme
293 @type cell_to_point: Boolean
294 @param cell_to_point: Converts cell data to point data (by averaging)
295 @type outline: Boolean
296 @param outline: Places an outline around the domain surface
297 """
298
299 self.__scene = scene
300 self.__data_collector = data_collector
301 self.__viewport = viewport
302 self.__lut = lut
303 self.__cell_to_point = cell_to_point
304 self.__outline = outline
305
306 # Keeps track whether MapOnPlaneClip has been modified.
307 self.__modified = True
308 Transform.__init__(self)
309 Plane.__init__(self)
310 Clipper.__init__(self)
311 DataSetMapper.__init__(self)
312 Actor3D.__init__(self)
313 scene._addVisualizationModules(self)
314
315 # ----- Outline -----
316
317 # NOTE: Changes cannot be made to the Outline's properties from the
318 # driver.
319 if(self.__outline == True):
320 outline = Outline(self.__data_collector._getDataCollectorOutput())
321 mapper = DataSetMapper()
322 mapper._setupDataSetMapper(outline._getOutlineOutput())
323
324 actor3D = Actor3D()
325 actor3D._setupActor3D(mapper._getDataSetMapper())
326 # Default outline color is black.
327 actor3D.setColor(Color.BLACK)
328
329 # Default line width is 1.
330 actor3D._setLineWidth(1)
331 self.__scene._addActor3D(self.__viewport, actor3D._getActor3D())
332
333 # ----- Map on a clipped plane -----
334
335 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
336 # before DataSetMapper. If it is done after DataSetMapper, no effect
337 # will take place.
338 if(self.__lut == Lut.COLOR): # Colored lookup table.
339 lookup_table = LookupTable()
340 lookup_table._setTableValue()
341 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
342 lookup_table = LookupTable()
343 lookup_table._setLookupTableToGreyScale()
344
345 self._setupPlane(self._getTransform())
346
347 if(self.__cell_to_point == True): # Converts cell data to point data.
348 c2p = CellDataToPointData(data_collector._getDataCollectorOutput())
349 self._setupClipper(c2p._getCellToPointOutput(), self._getPlane())
350 elif(self.__cell_to_point == False): # No conversion happens.
351 self._setupClipper(data_collector._getDataCollectorOutput(),
352 self._getPlane())
353
354 self._setClipFunction()
355 self._setupDataSetMapper(self._getClipperOutput(),
356 lookup_table._getLookupTable())
357
358 self._setupActor3D(self._getDataSetMapper())
359 self.__scene._addActor3D(self.__viewport, self._getActor3D())
360
361 def _isModified(self):
362 """
363 Return whether the MapOnPlaneClip or DataCollector has been modified.
364
365 @rtype: Boolean
366 @return: True or False
367 """
368
369 return self.__modified or self.__data_collector._isModified()
370
371 def _render(self):
372 """
373 Render the surface map clip using a plane.
374 """
375
376 if (self._isModified() == True):
377 if(self.__data_collector._isScalarSet() == True):
378 self.__data_collector._setActiveScalar()
379 self._setScalarRange(self.__data_collector._getScalarRange())
380 self.__modified = False
381
382
383 #############################################################################
384
385
386 # NOTE: DataSetMapper, Actor3D and Clipper were inherited
387 # to allow access to their public methods from the driver.
388 class MapOnScalarClip(DataSetMapper, Actor3D, Clipper):
389 """
390 This class works in a similar way to L{Map <map.Map>}, except that it
391 shows a scalar field clipped using a scalar value.
392 """
393
394 # The SOUTH_WEST default viewport is used when there is only one viewport.
395 # This saves the user from specifying the viewport when there is only one.
396 # If no lut is specified, the color scheme will be used.
397 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
398 lut = Lut.COLOR, cell_to_point = False, outline = True):
399 """
400 Initialise the MapOnScalarClip.
401
402 @attention: The source can either be point or cell data. If the
403 source is cell data, a conversion to point data may or may not be
404 required, in order for the object to be rendered correctly.
405 If a conversion is needed, the 'cell_to_point' flag must be set to
406 'True', otherwise 'False' (which is the default).
407
408 @type scene: L{Scene <scene.Scene>} object
409 @param scene: Scene in which objects are to be rendered on
410 @type data_collector: L{DataCollector <datacollector.DataCollector>}
411 object
412 @param data_collector: Deal with source of data for visualisation
413 @type viewport: L{Viewport <constant.Viewport>} constant
414 @param viewport: Viewport in which objects are to be rendered on
415 @type lut : L{Lut <constant.Lut>} constant
416 @param lut: Lookup table color scheme
417 @type cell_to_point: Boolean
418 @param cell_to_point: Converts cell data to point data (by averaging)
419 @type outline: Boolean
420 @param outline: Places an outline around the domain surface
421 """
422
423 self.__scene = scene
424 self.__data_collector = data_collector
425 self.__viewport = viewport
426 self.__lut = lut
427 self.__cell_to_point = cell_to_point
428 self.__outline = outline
429
430 # Keeps track whether MapOnScalarClip has been modified.
431 self.__modified = True
432 Clipper.__init__(self)
433 DataSetMapper.__init__(self)
434 Actor3D.__init__(self)
435 scene._addVisualizationModules(self)
436
437 # ----- Outline -----
438
439 # NOTE: Changes cannot be made to the Outline's properties from the
440 # driver.
441 if(self.__outline == True):
442 outline = Outline(self.__data_collector._getDataCollectorOutput())
443 mapper = DataSetMapper()
444 mapper._setupDataSetMapper(outline._getOutlineOutput())
445
446 actor3D = Actor3D()
447 actor3D._setupActor3D(mapper._getDataSetMapper())
448 # Default outline color is black.
449 actor3D.setColor(Color.BLACK)
450
451 # Default line width is 1.
452 actor3D._setLineWidth(1)
453 self.__scene._addActor3D(self.__viewport, actor3D._getActor3D())
454
455 # ----- Map clipped using a scalar value -----
456
457 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
458 # before DataSetMapper. If it is done after DataSetMapper, no effect
459 # will take place.
460 if(self.__lut == Lut.COLOR): # Colored lookup table.
461 lookup_table = LookupTable()
462 lookup_table._setTableValue()
463 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
464 lookup_table = LookupTable()
465 lookup_table._setLookupTableToGreyScale()
466
467 if(self.__cell_to_point == True): # Converts cell data to point data.
468 c2p = CellDataToPointData(
469 self.__data_collector._getDataCollectorOutput())
470 # None is used because a plane is not required when a scalar
471 # value is used to perform the clipping.
472 self._setupClipper(c2p._getDataCollectorOutput(), None)
473 elif(self.__cell_to_point == False): # No conversion happens.
474 self._setupClipper(
475 self.__data_collector._getDataCollectorOutput(),None)
476
477 self._setupDataSetMapper(self._getClipperOutput(),
478 lookup_table._getLookupTable())
479
480 self._setupActor3D(self._getDataSetMapper())
481 self.__scene._addActor3D(self.__viewport, self._getActor3D())
482
483 def _isModified(self):
484 """
485 Return whether the MapOnScalarClip or DataCollector has been modified.
486
487 @rtype: Boolean
488 @return: True or False
489 """
490
491 return self.__modified or self.__data_collector._isModified()
492
493 def _render(self):
494 """
495 Render the surface map clip using scalar data.
496 """
497
498 if (self._isModified() == True):
499 if(self.__data_collector._isScalarSet() == True):
500 self.__data_collector._setActiveScalar()
501 self._setScalarRange(self.__data_collector._getScalarRange())
502 self.__modified = False
503
504
505

  ViewVC Help
Powered by ViewVC 1.1.26