/[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 1189 - (hide 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 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 jongui 1189 # 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 jongui 1148 self.__modified = False
150    
151    
152 ksteube 1147 ###############################################################################
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 jongui 1148 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 ksteube 1147
204 jongui 1148 # 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 ksteube 1147 # ----- Outline -----
218    
219 jongui 1148 # 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 ksteube 1147
226 jongui 1148 actor3D = Actor3D()
227     actor3D._setupActor3D(mapper._getDataSetMapper())
228 ksteube 1147 # Default outline color is black.
229 jongui 1148 actor3D.setColor(Color.BLACK)
230 ksteube 1147
231     # Default line width is 1.
232 jongui 1148 actor3D._setLineWidth(1)
233 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
234 ksteube 1147
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 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
241 ksteube 1147 lookup_table = LookupTable()
242     lookup_table._setTableValue()
243 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
244 ksteube 1147 lookup_table = LookupTable()
245     lookup_table._setLookupTableToGreyScale()
246    
247 jongui 1148 self._setupPlane(self._getTransform())
248 ksteube 1147
249 jongui 1148 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 ksteube 1147
257 jongui 1148 self._setupMaskPoints(self._getCutterOutput())
258 ksteube 1147
259 jongui 1148 self._setupTensorGlyph(self._getMaskPointsOutput(),
260     self._getSphereOutput())
261     self._setupNormals(self._getTensorGlyphOutput())
262 ksteube 1147
263 jongui 1148 self._setupDataSetMapper(self._getNormalsOutput(),
264 ksteube 1147 lookup_table._getLookupTable())
265    
266 jongui 1148 self._setupActor3D(self._getDataSetMapper())
267 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
268 ksteube 1147
269 jongui 1148 def _isModified(self):
270     """
271     Return whether the EllipsoidOnPlaneCut or DataCollector has been
272     modified.
273 ksteube 1147
274 jongui 1148 @rtype: Boolean
275     @return: True or False
276     """
277 ksteube 1147
278 jongui 1148 return self.__modified or self.__data_collector._isModified()
279    
280 jongui 1158 def _render(self, scene):
281 jongui 1148 """
282     Render the ellipsoids cut using a plane.
283 jongui 1158
284     @type scene: L{Scene <scene.Scene>} object
285     @param scene: Scene in which objects are to be rendered on
286 jongui 1148 """
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 jongui 1189
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 jongui 1148 self.__modified = False
300    
301    
302 ksteube 1147 ###############################################################################
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 jongui 1148 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 ksteube 1147
352 jongui 1148 # 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 ksteube 1147 # ----- Outline -----
366    
367 jongui 1148 # 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 ksteube 1147
374 jongui 1148 actor3D = Actor3D()
375     actor3D._setupActor3D(mapper._getDataSetMapper())
376 ksteube 1147 # Default outline color is black.
377 jongui 1148 actor3D.setColor(Color.BLACK)
378 ksteube 1147
379     # Default line width is 1.
380 jongui 1148 actor3D._setLineWidth(1)
381 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
382 ksteube 1147
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 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
389 ksteube 1147 lookup_table = LookupTable()
390     lookup_table._setTableValue()
391 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
392 ksteube 1147 lookup_table = LookupTable()
393     lookup_table._setLookupTableToGreyScale()
394    
395 jongui 1148 self._setupPlane(self._getTransform())
396 ksteube 1147
397 jongui 1148 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 ksteube 1147
405     # NOTE: TensorGlyph must come before Clipper. Otherwise clipping
406     # may not work correctly.
407 jongui 1148 self._setupTensorGlyph(self._getMaskPointsOutput(),
408     self._getSphereOutput())
409     self._setupNormals(self._getTensorGlyphOutput())
410 ksteube 1147
411     # NOTE: Clipper must come after TensorGlyph. Otherwise clipping
412     # may not work correctly.
413 jongui 1148 self._setupClipper(self._getNormalsOutput(),
414     self._getPlane())
415     self._setClipFunction()
416 ksteube 1147
417 jongui 1148 self._setupDataSetMapper(self._getClipperOutput(),
418     lookup_table._getLookupTable())
419 ksteube 1147
420 jongui 1148 self._setupActor3D(self._getDataSetMapper())
421 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
422 ksteube 1147
423 jongui 1148 def _isModified(self):
424     """
425     Return whether the EllipsoidOnPlaneClip or DataCollector has been
426     modified.
427 ksteube 1147
428 jongui 1148 @rtype: Boolean
429     @return: True or False
430     """
431    
432     return self.__modified or self.__data_collector._isModified()
433    
434 jongui 1158 def _render(self, scene):
435 jongui 1148 """
436     Render the ellipsoids clip using a plane.
437 jongui 1158
438     @type scene: L{Scene <scene.Scene>} object
439     @param scene: Scene in which objects are to be rendered on
440 jongui 1148 """
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 jongui 1189
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 jongui 1148 self.__modified = False
454    
455    

  ViewVC Help
Powered by ViewVC 1.1.26