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

  ViewVC Help
Powered by ViewVC 1.1.26