/[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 1197 - (hide annotations)
Mon Jun 18 02:08:34 2007 UTC (13 years, 9 months ago) by jongui
File MIME type: text/x-python
File size: 16638 byte(s)
Update the way movies are generated. Please refer to the examples. 

The user can now either specify the image range(first and last images inclusive):
mov.imageRange(input_directory = PYVISI_EXAMPLE_IMAGES_PATH,
        first_image = IMAGE_NAME + "000938.jpg",
		last_image = IMAGE_NAME + "000948.jpg")
mov.makeMovie(os.path.join(PYVISI_EXAMPLE_IMAGES_PATH, "movie.mpg"))

or the user can specify a list of images:

lst = ['image1.jpg', 'image5.jpg', 'image7.jpg]
mov.imageList(input_directory = PYVISI_EXAMPLE_IMAGES_PATH, image_list = lst)
mov.makeMovie(os.path.join(PYVISI_EXAMPLE_IMAGES_PATH, "movie.mpg"))


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

  ViewVC Help
Powered by ViewVC 1.1.26