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

Contents of /trunk/pyvisi/py_src/contour.py

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26