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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (hide annotations)
Tue May 22 04:24:01 2007 UTC (13 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 15392 byte(s)
Made some changes to fix the memory leak problem. However, the problem still persists for run_escript_with_lazy_evaluation.py, run_streamline.py and run_streamline_with_lazy_evaluation.py.

1 ksteube 1147 """
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 jongui 1148 from constant import Viewport, Color, Lut, ColorMode
10 ksteube 1147 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 jongui 1148 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 ksteube 1147
62 jongui 1148 # 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 ksteube 1147
72 jongui 1148 # ----- Outline -----
73 ksteube 1147
74 jongui 1148 # 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 ksteube 1147 # Default outline color is black.
84 jongui 1148 actor3D.setColor(Color.BLACK)
85 ksteube 1147
86     # Default line width is 1.
87 jongui 1148 actor3D._setLineWidth(1)
88 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
89 ksteube 1147
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 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
96 ksteube 1147 lookup_table = LookupTable()
97     lookup_table._setTableValue()
98 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
99 ksteube 1147 lookup_table = LookupTable()
100     lookup_table._setLookupTableToGreyScale()
101    
102 jongui 1148 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 ksteube 1147
110 jongui 1148 self._setupTensorGlyph(self._getMaskPointsOutput(),
111     self._getSphereOutput())
112     self._setupNormals(self._getTensorGlyphOutput())
113 ksteube 1147
114 jongui 1148 self._setupDataSetMapper(self._getNormalsOutput(),
115 ksteube 1147 lookup_table._getLookupTable())
116    
117 jongui 1148 self._setupActor3D(self._getDataSetMapper())
118 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
119 ksteube 1147
120 jongui 1148 def _isModified(self):
121     """
122     Return whether the Ellipsoid or DataCollector has been modified.
123 ksteube 1147
124 jongui 1148 @rtype: Boolean
125     @return: True or False
126     """
127 ksteube 1147
128 jongui 1148 return self.__modified or self.__data_collector._isModified()
129    
130 jongui 1158 def _render(self, scene):
131 jongui 1148 """
132     Render the ellipsoids.
133 jongui 1158
134     @type scene: L{Scene <scene.Scene>} object
135     @param scene: Scene in which objects are to be rendered on
136 jongui 1148 """
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._setScalarRange(self.__data_collector._getScalarRange())
145     self.__modified = False
146    
147    
148 ksteube 1147 ###############################################################################
149    
150    
151     from transform import Transform
152     from plane import Plane
153     from cutter import Cutter
154    
155     # NOTE: DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph, Transform, Plane,
156     # Cutter and MaskPoints were inherited to allow access to
157     # their public methods from the driver.
158     class EllipsoidOnPlaneCut(DataSetMapper, Actor3D, Sphere, Normals,
159     TensorGlyph, Transform, Plane, Cutter, MaskPoints):
160     """
161     This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
162     except that it shows a tensor field using ellipsoids cut using a plane.
163     """
164    
165     # The SOUTH_WEST default viewport is used when there is only one viewport.
166     # This saves the user from specifying the viewport when there is only one.
167     # If no lut is specified, the color scheme will be used.
168     def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
169     lut = Lut.COLOR, cell_to_point = False, outline = True):
170     """
171     Initialise the EllipsoidOnPlaneCut.
172    
173     @attention: The source can either be point or cell data. If the
174     source is cell data, a conversion to point data may or may not be
175     required, in order for the object to be rendered correctly.
176     If a conversion is needed, the 'cell_to_point' flag must be set to
177     'True', otherwise 'False' (which is the default).
178    
179     @type scene: L{Scene <scene.Scene>} object
180     @param scene: Scene in which objects are to be rendered on
181     @type data_collector: L{DataCollector <datacollector.DataCollector>}
182     object
183     @param data_collector: Deal with source of data for vizualisation
184     @type viewport: L{Viewport <constant.Viewport>} constant
185     @param viewport: Viewport in which objects are to be rendered on
186     @type lut : L{Lut <constant.Lut>} constant
187     @param lut: Lookup table color scheme
188     @type cell_to_point: Boolean
189     @param cell_to_point: Converts cell data to point data (by averaging)
190     @type outline: Boolean
191     @param outline: Places an outline around the domain surface
192     """
193    
194 jongui 1148 self.__data_collector = data_collector
195     self.__viewport = viewport
196     self.__lut = lut
197     self.__cell_to_point = cell_to_point
198     self.__outline = outline
199 ksteube 1147
200 jongui 1148 # Keeps track whether EllipsoidOnPlaneCut has been modified.
201     self.__modified = True
202     Transform.__init__(self)
203     Plane.__init__(self)
204     Cutter.__init__(self)
205     MaskPoints.__init__(self)
206     Sphere.__init__(self)
207     TensorGlyph.__init__(self)
208     Normals.__init__(self)
209     DataSetMapper.__init__(self)
210     Actor3D.__init__(self)
211     scene._addVisualizationModules(self)
212    
213 ksteube 1147 # ----- Outline -----
214    
215 jongui 1148 # NOTE: Changes cannot be made to the Outline's properties from the
216     # driver.
217     if(self.__outline == True):
218     outline = Outline(self.__data_collector._getDataCollectorOutput())
219     mapper = DataSetMapper()
220     mapper._setupDataSetMapper(outline._getOutlineOutput())
221 ksteube 1147
222 jongui 1148 actor3D = Actor3D()
223     actor3D._setupActor3D(mapper._getDataSetMapper())
224 ksteube 1147 # Default outline color is black.
225 jongui 1148 actor3D.setColor(Color.BLACK)
226 ksteube 1147
227     # Default line width is 1.
228 jongui 1148 actor3D._setLineWidth(1)
229 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
230 ksteube 1147
231     # ----- Ellipsoid on a cut plane -----
232    
233     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
234     # before DataSetMapper. If it is done after DataSetMapper, no effect
235     # will take place.
236 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
237 ksteube 1147 lookup_table = LookupTable()
238     lookup_table._setTableValue()
239 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
240 ksteube 1147 lookup_table = LookupTable()
241     lookup_table._setLookupTableToGreyScale()
242    
243 jongui 1148 self._setupPlane(self._getTransform())
244 ksteube 1147
245 jongui 1148 if(self.__cell_to_point == True): # Converts cell data to point data.
246     c2p = CellDataToPointData(
247     self.__data_collector._getDataCollectorOutput())
248     self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())
249     elif(self.__cell_to_point == False): # No conversion happens.
250     self._setupCutter(self.__data_collector._getDataCollectorOutput(),
251     self._getPlane())
252 ksteube 1147
253 jongui 1148 self._setupMaskPoints(self._getCutterOutput())
254 ksteube 1147
255 jongui 1148 self._setupTensorGlyph(self._getMaskPointsOutput(),
256     self._getSphereOutput())
257     self._setupNormals(self._getTensorGlyphOutput())
258 ksteube 1147
259 jongui 1148 self._setupDataSetMapper(self._getNormalsOutput(),
260 ksteube 1147 lookup_table._getLookupTable())
261    
262 jongui 1148 self._setupActor3D(self._getDataSetMapper())
263 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
264 ksteube 1147
265 jongui 1148 def _isModified(self):
266     """
267     Return whether the EllipsoidOnPlaneCut or DataCollector has been
268     modified.
269 ksteube 1147
270 jongui 1148 @rtype: Boolean
271     @return: True or False
272     """
273 ksteube 1147
274 jongui 1148 return self.__modified or self.__data_collector._isModified()
275    
276 jongui 1158 def _render(self, scene):
277 jongui 1148 """
278     Render the ellipsoids cut using a plane.
279 jongui 1158
280     @type scene: L{Scene <scene.Scene>} object
281     @param scene: Scene in which objects are to be rendered on
282 jongui 1148 """
283    
284     if (self._isModified() == True):
285     if(self.__data_collector._isScalarSet() == True):
286     self.__data_collector._setActiveScalar()
287     if(self.__data_collector._isTensorSet() == True):
288     self.__data_collector._setActiveTensor()
289     self._setScalarRange(self.__data_collector._getScalarRange())
290     self.__modified = False
291    
292    
293 ksteube 1147 ###############################################################################
294    
295    
296     from clipper import Clipper
297    
298     # NOTE: DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph, Transform, Plane,
299     # Clipper and MaskPoints were inherited to allow access to
300     # their public methods from the driver.
301     class EllipsoidOnPlaneClip(DataSetMapper, Actor3D, Sphere, Normals,
302     TensorGlyph, Transform, Plane, Clipper, MaskPoints):
303     """
304     This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>},
305     except that it shows a tensor field using ellipsoids clipped using a plane.
306     """
307    
308     # The SOUTH_WEST default viewport is used when there is only one viewport.
309     # This saves the user from specifying the viewport when there is only one.
310     # If no lut is specified, the color scheme will be used.
311     def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
312     lut = Lut.COLOR, cell_to_point = False, outline = True):
313     """
314     Initialise the EllipsoidOnPlaneClip.
315    
316     @attention: The source can either be point or cell data. If the
317     source is cell data, a conversion to point data may or may not be
318     required, in order for the object to be rendered correctly.
319     If a conversion is needed, the 'cell_to_point' flag must be set to
320     'True', otherwise 'False' (which is the default).
321    
322     @type scene: L{Scene <scene.Scene>} object
323     @param scene: Scene in which objects are to be rendered on
324     @type data_collector: L{DataCollector <datacollector.DataCollector>}
325     object
326     @param data_collector: Deal with source of data for visualisation
327     @type viewport: L{Viewport <constant.Viewport>} constant
328     @param viewport: Viewport in which object are to be rendered on
329     @type lut : L{Lut <constant.Lut>} constant
330     @param lut: Lookup table color scheme
331     @type cell_to_point: Boolean
332     @param cell_to_point: Converts cell data to point data (by averaging)
333     @type outline: Boolean
334     @param outline: Places an outline around the domain surface
335     """
336    
337 jongui 1148 self.__data_collector = data_collector
338     self.__viewport = viewport
339     self.__lut = lut
340     self.__cell_to_point = cell_to_point
341     self.__outline = outline
342 ksteube 1147
343 jongui 1148 # Keeps track whether EllipsoidOnPlaneClip has been modified.
344     self.__modified = True
345     Transform.__init__(self)
346     Plane.__init__(self)
347     Clipper.__init__(self)
348     MaskPoints.__init__(self)
349     Sphere.__init__(self)
350     TensorGlyph.__init__(self)
351     Normals.__init__(self)
352     DataSetMapper.__init__(self)
353     Actor3D.__init__(self)
354     scene._addVisualizationModules(self)
355    
356 ksteube 1147 # ----- Outline -----
357    
358 jongui 1148 # NOTE: Changes cannot be made to the Outline's properties from the
359     # driver.
360     if(self.__outline == True):
361     outline = Outline(self.__data_collector._getDataCollectorOutput())
362     mapper = DataSetMapper()
363     mapper._setupDataSetMapper(outline._getOutlineOutput())
364 ksteube 1147
365 jongui 1148 actor3D = Actor3D()
366     actor3D._setupActor3D(mapper._getDataSetMapper())
367 ksteube 1147 # Default outline color is black.
368 jongui 1148 actor3D.setColor(Color.BLACK)
369 ksteube 1147
370     # Default line width is 1.
371 jongui 1148 actor3D._setLineWidth(1)
372 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
373 ksteube 1147
374     # ----- Ellipsoid on a clipped plane -----
375    
376     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
377     # before DataSetMapper. If it is done after DataSetMapper, no effect
378     # will take place.
379 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
380 ksteube 1147 lookup_table = LookupTable()
381     lookup_table._setTableValue()
382 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
383 ksteube 1147 lookup_table = LookupTable()
384     lookup_table._setLookupTableToGreyScale()
385    
386 jongui 1148 self._setupPlane(self._getTransform())
387 ksteube 1147
388 jongui 1148 if(self.__cell_to_point == True): # Converts cell data to point data.
389     c2p = CellDataToPointData(
390     self.__data_collector._getDataCollectorOutput())
391     self._setupMaskPoints(c2p._getCellToPointOutput())
392     elif(self.__cell_to_point == False): # No conversion happens.
393     self._setupMaskPoints(
394     self.__data_collector._getDataCollectorOutput())
395 ksteube 1147
396     # NOTE: TensorGlyph must come before Clipper. Otherwise clipping
397     # may not work correctly.
398 jongui 1148 self._setupTensorGlyph(self._getMaskPointsOutput(),
399     self._getSphereOutput())
400     self._setupNormals(self._getTensorGlyphOutput())
401 ksteube 1147
402     # NOTE: Clipper must come after TensorGlyph. Otherwise clipping
403     # may not work correctly.
404 jongui 1148 self._setupClipper(self._getNormalsOutput(),
405     self._getPlane())
406     self._setClipFunction()
407 ksteube 1147
408 jongui 1148 self._setupDataSetMapper(self._getClipperOutput(),
409     lookup_table._getLookupTable())
410 ksteube 1147
411 jongui 1148 self._setupActor3D(self._getDataSetMapper())
412 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
413 ksteube 1147
414 jongui 1148 def _isModified(self):
415     """
416     Return whether the EllipsoidOnPlaneClip or DataCollector has been
417     modified.
418 ksteube 1147
419 jongui 1148 @rtype: Boolean
420     @return: True or False
421     """
422    
423     return self.__modified or self.__data_collector._isModified()
424    
425 jongui 1158 def _render(self, scene):
426 jongui 1148 """
427     Render the ellipsoids clip using a plane.
428 jongui 1158
429     @type scene: L{Scene <scene.Scene>} object
430     @param scene: Scene in which objects are to be rendered on
431 jongui 1148 """
432    
433     if (self._isModified() == True):
434     if(self.__data_collector._isScalarSet() == True):
435     self.__data_collector._setActiveScalar()
436     if(self.__data_collector._isTensorSet() == True):
437     self.__data_collector._setActiveTensor()
438     self._setScalarRange(self.__data_collector._getScalarRange())
439     self.__modified = False
440    
441    

  ViewVC Help
Powered by ViewVC 1.1.26