/[escript]/tags/trunk_2172_checkpoint/pyvisi/py_src/ellipsoid.py
ViewVC logotype

Contents of /tags/trunk_2172_checkpoint/pyvisi/py_src/ellipsoid.py

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26