/[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 1197 - (show annotations)
Mon Jun 18 02:08:34 2007 UTC (13 years, 10 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 """
2 @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 """
9
10 __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 import vtk
22 from mapper import DataSetMapper
23 from lookuptable import LookupTable
24 from actor import Actor3D
25 from constant import Viewport, Color, Lut, ColorMode
26 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 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
78 # 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
88 # ----- Outline -----
89
90 # 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 # Default outline color is black.
100 actor3D.setColor(Color.BLACK)
101
102 # Default line width is 1.
103 actor3D._setLineWidth(1)
104 scene._addActor3D(self.__viewport, actor3D._getActor3D())
105
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 if(self.__lut == Lut.COLOR): # Colored lookup table.
112 lookup_table = LookupTable()
113 lookup_table._setTableValue()
114 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
115 lookup_table = LookupTable()
116 lookup_table._setLookupTableToGreyScale()
117
118 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
126 self._setupTensorGlyph(self._getMaskPointsOutput(),
127 self._getSphereOutput())
128 self._setupNormals(self._getTensorGlyphOutput())
129
130 self._setupDataSetMapper(self._getNormalsOutput(),
131 lookup_table._getLookupTable())
132
133 self._setupActor3D(self._getDataSetMapper())
134 scene._addActor3D(self.__viewport, self._getActor3D())
135
136 def _isModified(self):
137 """
138 Return whether the Ellipsoid or DataCollector has been modified.
139
140 @rtype: Boolean
141 @return: True or False
142 """
143
144 return self.__modified or self.__data_collector._isModified()
145
146 def _render(self, scene):
147 """
148 Render the ellipsoids.
149
150 @type scene: L{Scene <scene.Scene>} object
151 @param scene: Scene in which objects are to be rendered on
152 """
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 # 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 self.__modified = False
166
167
168 ###############################################################################
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 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
220 # 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 # ----- Outline -----
234
235 # 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
242 actor3D = Actor3D()
243 actor3D._setupActor3D(mapper._getDataSetMapper())
244 # Default outline color is black.
245 actor3D.setColor(Color.BLACK)
246
247 # Default line width is 1.
248 actor3D._setLineWidth(1)
249 scene._addActor3D(self.__viewport, actor3D._getActor3D())
250
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 if(self.__lut == Lut.COLOR): # Colored lookup table.
257 lookup_table = LookupTable()
258 lookup_table._setTableValue()
259 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
260 lookup_table = LookupTable()
261 lookup_table._setLookupTableToGreyScale()
262
263 self._setupPlane(self._getTransform())
264
265 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
273 self._setupMaskPoints(self._getCutterOutput())
274
275 self._setupTensorGlyph(self._getMaskPointsOutput(),
276 self._getSphereOutput())
277 self._setupNormals(self._getTensorGlyphOutput())
278
279 self._setupDataSetMapper(self._getNormalsOutput(),
280 lookup_table._getLookupTable())
281
282 self._setupActor3D(self._getDataSetMapper())
283 scene._addActor3D(self.__viewport, self._getActor3D())
284
285 def _isModified(self):
286 """
287 Return whether the EllipsoidOnPlaneCut or DataCollector has been
288 modified.
289
290 @rtype: Boolean
291 @return: True or False
292 """
293
294 return self.__modified or self.__data_collector._isModified()
295
296 def _render(self, scene):
297 """
298 Render the ellipsoids cut using a plane.
299
300 @type scene: L{Scene <scene.Scene>} object
301 @param scene: Scene in which objects are to be rendered on
302 """
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
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 self.__modified = False
316
317
318 ###############################################################################
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 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
368 # 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 # ----- Outline -----
382
383 # 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
390 actor3D = Actor3D()
391 actor3D._setupActor3D(mapper._getDataSetMapper())
392 # Default outline color is black.
393 actor3D.setColor(Color.BLACK)
394
395 # Default line width is 1.
396 actor3D._setLineWidth(1)
397 scene._addActor3D(self.__viewport, actor3D._getActor3D())
398
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 if(self.__lut == Lut.COLOR): # Colored lookup table.
405 lookup_table = LookupTable()
406 lookup_table._setTableValue()
407 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
408 lookup_table = LookupTable()
409 lookup_table._setLookupTableToGreyScale()
410
411 self._setupPlane(self._getTransform())
412
413 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
421 # NOTE: TensorGlyph must come before Clipper. Otherwise clipping
422 # may not work correctly.
423 self._setupTensorGlyph(self._getMaskPointsOutput(),
424 self._getSphereOutput())
425 self._setupNormals(self._getTensorGlyphOutput())
426
427 # NOTE: Clipper must come after TensorGlyph. Otherwise clipping
428 # may not work correctly.
429 self._setupClipper(self._getNormalsOutput(),
430 self._getPlane())
431 self._setClipFunction()
432
433 self._setupDataSetMapper(self._getClipperOutput(),
434 lookup_table._getLookupTable())
435
436 self._setupActor3D(self._getDataSetMapper())
437 scene._addActor3D(self.__viewport, self._getActor3D())
438
439 def _isModified(self):
440 """
441 Return whether the EllipsoidOnPlaneClip or DataCollector has been
442 modified.
443
444 @rtype: Boolean
445 @return: True or False
446 """
447
448 return self.__modified or self.__data_collector._isModified()
449
450 def _render(self, scene):
451 """
452 Render the ellipsoids clip using a plane.
453
454 @type scene: L{Scene <scene.Scene>} object
455 @param scene: Scene in which objects are to be rendered on
456 """
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
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 self.__modified = False
470
471

  ViewVC Help
Powered by ViewVC 1.1.26