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

  ViewVC Help
Powered by ViewVC 1.1.26