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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1189 - (show annotations)
Thu Jun 7 05:31:25 2007 UTC (13 years, 10 months ago) by jongui
File MIME type: text/x-python
File size: 16033 byte(s)
A Scalar Bar can now be displayed by creating an instance of a 'Legend'. The Scalar Bar can either show the scalar data range or vector data range. Corresponding examples and tests have also been added.
1 """
2 @author: John NGUI
3 """
4
5 import vtk
6 from mapper import DataSetMapper
7 from lookuptable import LookupTable
8 from actor import Actor3D
9 from constant import Viewport, Color, Lut, ColorMode
10 from sphere import Sphere
11 from normals import Normals
12 from glyph import TensorGlyph
13 from outline import Outline
14 from point import MaskPoints
15 from average import CellDataToPointData
16
17 # NOTE: DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph
18 # and MaskPoints were inherited to allow access to their
19 # public methods from the driver.
20 class Ellipsoid(DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph,
21 MaskPoints):
22 """
23 Class that shows a tensor field using ellipsoids. The ellipsoids can either
24 be colored or grey-scaled, depending on the lookup table used.
25 """
26
27 # The SOUTH_WEST default viewport is used when there is only one viewport.
28 # This saves the user from specifying the viewport when there is only one.
29 # If no lut is specified, the color scheme will be used.
30 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
31 lut = Lut.COLOR, cell_to_point = False, outline = True):
32 """
33 Initialise the Ellipsoid.
34
35 @attention: The source can either be point or cell data. If the
36 source is cell data, a conversion to point data may or may not be
37 required, in order for the object to be rendered correctly.
38 If a conversion is needed, the 'cell_to_point' flag must be set to
39 'True', otherwise 'False' (which is the default).
40
41 @type scene: L{Scene <scene.Scene>} object
42 @param scene: Scene in which objects are to be rendered on
43 @type data_collector: L{DataCollector <datacollector.DataCollector>}
44 object
45 @param data_collector: Deal with source of data for vizualisation
46 @type viewport: L{Viewport <constant.Viewport>} constant
47 @param viewport: Viewport in which objects are to be rendered on
48 @type lut : L{Lut <constant.Lut>} constant
49 @param lut: Lookup table color scheme
50 @type cell_to_point: Boolean
51 @param cell_to_point: Converts cell data to point data (by averaging)
52 @type outline: Boolean
53 @param outline: Places an outline around the domain surface
54 """
55
56 self.__data_collector = data_collector
57 self.__viewport = viewport
58 self.__lut = lut
59 self.__cell_to_point = cell_to_point
60 self.__outline = outline
61
62 # Keeps track whether Ellipsoid has been modified.
63 self.__modified = True
64 MaskPoints.__init__(self)
65 Sphere.__init__(self)
66 TensorGlyph.__init__(self)
67 Normals.__init__(self)
68 DataSetMapper.__init__(self)
69 Actor3D.__init__(self)
70 scene._addVisualizationModules(self)
71
72 # ----- Outline -----
73
74 # NOTE: Changes cannot be made to the Outline's properties from the
75 # driver.
76 if(self.__outline == True):
77 outline = Outline(self.__data_collector._getDataCollectorOutput())
78 mapper = DataSetMapper()
79 mapper._setupDataSetMapper(outline._getOutlineOutput())
80
81 actor3D = Actor3D()
82 actor3D._setupActor3D(mapper._getDataSetMapper())
83 # Default outline color is black.
84 actor3D.setColor(Color.BLACK)
85
86 # Default line width is 1.
87 actor3D._setLineWidth(1)
88 scene._addActor3D(self.__viewport, actor3D._getActor3D())
89
90 # ----- Ellipsoid -----
91
92 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
93 # before DataSetMapper. If it is done after DataSetMapper, no effect
94 # will take place.
95 if(self.__lut == Lut.COLOR): # Colored lookup table.
96 lookup_table = LookupTable()
97 lookup_table._setTableValue()
98 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
99 lookup_table = LookupTable()
100 lookup_table._setLookupTableToGreyScale()
101
102 if(self.__cell_to_point == True): # Converts cell data to point data.
103 c2p = CellDataToPointData(
104 self.__data_collector._getDataCollectorOutput())
105 self._setupMaskPoints(c2p._getCellToPointOutput())
106 elif(self.__cell_to_point == False): # No conversion happens.
107 self._setupMaskPoints(
108 self.__data_collector._getDataCollectorOutput())
109
110 self._setupTensorGlyph(self._getMaskPointsOutput(),
111 self._getSphereOutput())
112 self._setupNormals(self._getTensorGlyphOutput())
113
114 self._setupDataSetMapper(self._getNormalsOutput(),
115 lookup_table._getLookupTable())
116
117 self._setupActor3D(self._getDataSetMapper())
118 scene._addActor3D(self.__viewport, self._getActor3D())
119
120 def _isModified(self):
121 """
122 Return whether the Ellipsoid or DataCollector has been modified.
123
124 @rtype: Boolean
125 @return: True or False
126 """
127
128 return self.__modified or self.__data_collector._isModified()
129
130 def _render(self, scene):
131 """
132 Render the ellipsoids.
133
134 @type scene: L{Scene <scene.Scene>} object
135 @param scene: Scene in which objects are to be rendered on
136 """
137
138 if (self._isModified() == True):
139 if(self.__data_collector._isScalarSet() == True):
140 self.__data_collector._setActiveScalar()
141 if(self.__data_collector._isTensorSet() == True):
142 self.__data_collector._setActiveTensor()
143
144 # self._isScalarRangeSet checks whether the scalar range has been
145 # specified by the user. If it has, then the scalar range
146 # read from the source will be ignored.
147 if(not(self._isScalarRangeSet())):
148 self._setScalarRange(self.__data_collector._getScalarRange())
149 self.__modified = False
150
151
152 ###############################################################################
153
154
155 from transform import Transform
156 from plane import Plane
157 from cutter import Cutter
158
159 # NOTE: DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph, Transform, Plane,
160 # Cutter and MaskPoints were inherited to allow access to
161 # their public methods from the driver.
162 class EllipsoidOnPlaneCut(DataSetMapper, Actor3D, Sphere, Normals,
163 TensorGlyph, Transform, Plane, Cutter, MaskPoints):
164 """
165 This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
166 except that it shows a tensor field using ellipsoids cut using a plane.
167 """
168
169 # The SOUTH_WEST default viewport is used when there is only one viewport.
170 # This saves the user from specifying the viewport when there is only one.
171 # If no lut is specified, the color scheme will be used.
172 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
173 lut = Lut.COLOR, cell_to_point = False, outline = True):
174 """
175 Initialise the EllipsoidOnPlaneCut.
176
177 @attention: The source can either be point or cell data. If the
178 source is cell data, a conversion to point data may or may not be
179 required, in order for the object to be rendered correctly.
180 If a conversion is needed, the 'cell_to_point' flag must be set to
181 'True', otherwise 'False' (which is the default).
182
183 @type scene: L{Scene <scene.Scene>} object
184 @param scene: Scene in which objects are to be rendered on
185 @type data_collector: L{DataCollector <datacollector.DataCollector>}
186 object
187 @param data_collector: Deal with source of data for vizualisation
188 @type viewport: L{Viewport <constant.Viewport>} constant
189 @param viewport: Viewport in which objects are to be rendered on
190 @type lut : L{Lut <constant.Lut>} constant
191 @param lut: Lookup table color scheme
192 @type cell_to_point: Boolean
193 @param cell_to_point: Converts cell data to point data (by averaging)
194 @type outline: Boolean
195 @param outline: Places an outline around the domain surface
196 """
197
198 self.__data_collector = data_collector
199 self.__viewport = viewport
200 self.__lut = lut
201 self.__cell_to_point = cell_to_point
202 self.__outline = outline
203
204 # Keeps track whether EllipsoidOnPlaneCut has been modified.
205 self.__modified = True
206 Transform.__init__(self)
207 Plane.__init__(self)
208 Cutter.__init__(self)
209 MaskPoints.__init__(self)
210 Sphere.__init__(self)
211 TensorGlyph.__init__(self)
212 Normals.__init__(self)
213 DataSetMapper.__init__(self)
214 Actor3D.__init__(self)
215 scene._addVisualizationModules(self)
216
217 # ----- Outline -----
218
219 # NOTE: Changes cannot be made to the Outline's properties from the
220 # driver.
221 if(self.__outline == True):
222 outline = Outline(self.__data_collector._getDataCollectorOutput())
223 mapper = DataSetMapper()
224 mapper._setupDataSetMapper(outline._getOutlineOutput())
225
226 actor3D = Actor3D()
227 actor3D._setupActor3D(mapper._getDataSetMapper())
228 # Default outline color is black.
229 actor3D.setColor(Color.BLACK)
230
231 # Default line width is 1.
232 actor3D._setLineWidth(1)
233 scene._addActor3D(self.__viewport, actor3D._getActor3D())
234
235 # ----- Ellipsoid on a cut plane -----
236
237 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
238 # before DataSetMapper. If it is done after DataSetMapper, no effect
239 # will take place.
240 if(self.__lut == Lut.COLOR): # Colored lookup table.
241 lookup_table = LookupTable()
242 lookup_table._setTableValue()
243 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
244 lookup_table = LookupTable()
245 lookup_table._setLookupTableToGreyScale()
246
247 self._setupPlane(self._getTransform())
248
249 if(self.__cell_to_point == True): # Converts cell data to point data.
250 c2p = CellDataToPointData(
251 self.__data_collector._getDataCollectorOutput())
252 self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())
253 elif(self.__cell_to_point == False): # No conversion happens.
254 self._setupCutter(self.__data_collector._getDataCollectorOutput(),
255 self._getPlane())
256
257 self._setupMaskPoints(self._getCutterOutput())
258
259 self._setupTensorGlyph(self._getMaskPointsOutput(),
260 self._getSphereOutput())
261 self._setupNormals(self._getTensorGlyphOutput())
262
263 self._setupDataSetMapper(self._getNormalsOutput(),
264 lookup_table._getLookupTable())
265
266 self._setupActor3D(self._getDataSetMapper())
267 scene._addActor3D(self.__viewport, self._getActor3D())
268
269 def _isModified(self):
270 """
271 Return whether the EllipsoidOnPlaneCut or DataCollector has been
272 modified.
273
274 @rtype: Boolean
275 @return: True or False
276 """
277
278 return self.__modified or self.__data_collector._isModified()
279
280 def _render(self, scene):
281 """
282 Render the ellipsoids cut using a plane.
283
284 @type scene: L{Scene <scene.Scene>} object
285 @param scene: Scene in which objects are to be rendered on
286 """
287
288 if (self._isModified() == True):
289 if(self.__data_collector._isScalarSet() == True):
290 self.__data_collector._setActiveScalar()
291 if(self.__data_collector._isTensorSet() == True):
292 self.__data_collector._setActiveTensor()
293
294 # self._isScalarRangeSet checks whether the scalar range has been
295 # specified by the user. If it has, then the scalar range
296 # read from the source will be ignored.
297 if(not(self._isScalarRangeSet())):
298 self._setScalarRange(self.__data_collector._getScalarRange())
299 self.__modified = False
300
301
302 ###############################################################################
303
304
305 from clipper import Clipper
306
307 # NOTE: DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph, Transform, Plane,
308 # Clipper and MaskPoints were inherited to allow access to
309 # their public methods from the driver.
310 class EllipsoidOnPlaneClip(DataSetMapper, Actor3D, Sphere, Normals,
311 TensorGlyph, Transform, Plane, Clipper, MaskPoints):
312 """
313 This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>},
314 except that it shows a tensor field using ellipsoids clipped using a plane.
315 """
316
317 # The SOUTH_WEST default viewport is used when there is only one viewport.
318 # This saves the user from specifying the viewport when there is only one.
319 # If no lut is specified, the color scheme will be used.
320 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
321 lut = Lut.COLOR, cell_to_point = False, outline = True):
322 """
323 Initialise the EllipsoidOnPlaneClip.
324
325 @attention: The source can either be point or cell data. If the
326 source is cell data, a conversion to point data may or may not be
327 required, in order for the object to be rendered correctly.
328 If a conversion is needed, the 'cell_to_point' flag must be set to
329 'True', otherwise 'False' (which is the default).
330
331 @type scene: L{Scene <scene.Scene>} object
332 @param scene: Scene in which objects are to be rendered on
333 @type data_collector: L{DataCollector <datacollector.DataCollector>}
334 object
335 @param data_collector: Deal with source of data for visualisation
336 @type viewport: L{Viewport <constant.Viewport>} constant
337 @param viewport: Viewport in which object are to be rendered on
338 @type lut : L{Lut <constant.Lut>} constant
339 @param lut: Lookup table color scheme
340 @type cell_to_point: Boolean
341 @param cell_to_point: Converts cell data to point data (by averaging)
342 @type outline: Boolean
343 @param outline: Places an outline around the domain surface
344 """
345
346 self.__data_collector = data_collector
347 self.__viewport = viewport
348 self.__lut = lut
349 self.__cell_to_point = cell_to_point
350 self.__outline = outline
351
352 # Keeps track whether EllipsoidOnPlaneClip has been modified.
353 self.__modified = True
354 Transform.__init__(self)
355 Plane.__init__(self)
356 Clipper.__init__(self)
357 MaskPoints.__init__(self)
358 Sphere.__init__(self)
359 TensorGlyph.__init__(self)
360 Normals.__init__(self)
361 DataSetMapper.__init__(self)
362 Actor3D.__init__(self)
363 scene._addVisualizationModules(self)
364
365 # ----- Outline -----
366
367 # NOTE: Changes cannot be made to the Outline's properties from the
368 # driver.
369 if(self.__outline == True):
370 outline = Outline(self.__data_collector._getDataCollectorOutput())
371 mapper = DataSetMapper()
372 mapper._setupDataSetMapper(outline._getOutlineOutput())
373
374 actor3D = Actor3D()
375 actor3D._setupActor3D(mapper._getDataSetMapper())
376 # Default outline color is black.
377 actor3D.setColor(Color.BLACK)
378
379 # Default line width is 1.
380 actor3D._setLineWidth(1)
381 scene._addActor3D(self.__viewport, actor3D._getActor3D())
382
383 # ----- Ellipsoid on a clipped plane -----
384
385 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
386 # before DataSetMapper. If it is done after DataSetMapper, no effect
387 # will take place.
388 if(self.__lut == Lut.COLOR): # Colored lookup table.
389 lookup_table = LookupTable()
390 lookup_table._setTableValue()
391 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
392 lookup_table = LookupTable()
393 lookup_table._setLookupTableToGreyScale()
394
395 self._setupPlane(self._getTransform())
396
397 if(self.__cell_to_point == True): # Converts cell data to point data.
398 c2p = CellDataToPointData(
399 self.__data_collector._getDataCollectorOutput())
400 self._setupMaskPoints(c2p._getCellToPointOutput())
401 elif(self.__cell_to_point == False): # No conversion happens.
402 self._setupMaskPoints(
403 self.__data_collector._getDataCollectorOutput())
404
405 # NOTE: TensorGlyph must come before Clipper. Otherwise clipping
406 # may not work correctly.
407 self._setupTensorGlyph(self._getMaskPointsOutput(),
408 self._getSphereOutput())
409 self._setupNormals(self._getTensorGlyphOutput())
410
411 # NOTE: Clipper must come after TensorGlyph. Otherwise clipping
412 # may not work correctly.
413 self._setupClipper(self._getNormalsOutput(),
414 self._getPlane())
415 self._setClipFunction()
416
417 self._setupDataSetMapper(self._getClipperOutput(),
418 lookup_table._getLookupTable())
419
420 self._setupActor3D(self._getDataSetMapper())
421 scene._addActor3D(self.__viewport, self._getActor3D())
422
423 def _isModified(self):
424 """
425 Return whether the EllipsoidOnPlaneClip or DataCollector has been
426 modified.
427
428 @rtype: Boolean
429 @return: True or False
430 """
431
432 return self.__modified or self.__data_collector._isModified()
433
434 def _render(self, scene):
435 """
436 Render the ellipsoids clip using a plane.
437
438 @type scene: L{Scene <scene.Scene>} object
439 @param scene: Scene in which objects are to be rendered on
440 """
441
442 if (self._isModified() == True):
443 if(self.__data_collector._isScalarSet() == True):
444 self.__data_collector._setActiveScalar()
445 if(self.__data_collector._isTensorSet() == True):
446 self.__data_collector._setActiveTensor()
447
448 # self._isScalarRangeSet checks whether the scalar range has been
449 # specified by the user. If it has, then the scalar range
450 # read from the source will be ignored.
451 if(not(self._isScalarRangeSet())):
452 self._setScalarRange(self.__data_collector._getScalarRange())
453 self.__modified = False
454
455

  ViewVC Help
Powered by ViewVC 1.1.26