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

Annotation of /trunk/pyvisi/py_src/contour.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: 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 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 actor import Actor3D
24     from lookuptable import LookupTable
25     from outline import Outline
26 jongui 1148 from constant import Viewport, Color, Lut, ColorMode
27 ksteube 1147 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 jongui 1148 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 ksteube 1147
80     # ----- Outline -----
81    
82 jongui 1148 # 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 ksteube 1147
89 jongui 1148 actor3D = Actor3D()
90     actor3D._setupActor3D(mapper._getDataSetMapper())
91 ksteube 1147 # Default outline color is black.
92 jongui 1148 actor3D.setColor(Color.BLACK)
93 ksteube 1147
94     # Default line width is 1.
95 jongui 1148 actor3D._setLineWidth(1)
96 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
97 ksteube 1147
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 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
104 ksteube 1147 lookup_table = LookupTable()
105     lookup_table._setTableValue()
106 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
107 ksteube 1147 lookup_table = LookupTable()
108     lookup_table._setLookupTableToGreyScale()
109    
110 jongui 1148 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 ksteube 1147
118 jongui 1148 self._setupDataSetMapper(self._getContourModuleOutput(),
119 ksteube 1147 lookup_table._getLookupTable())
120    
121 jongui 1148 self._setupActor3D(self._getDataSetMapper())
122 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
123 jongui 1148
124     def _isModified(self):
125     """
126     Return whether the Contour or DataCollector has been modified.
127 ksteube 1147
128 jongui 1148 @rtype: Boolean
129     @return: True or False
130     """
131 ksteube 1147
132 jongui 1148 return self.__modified or self.__data_collector._isModified()
133 ksteube 1147
134 jongui 1158 def _render(self, scene):
135 jongui 1148 """
136     Render the contour.
137 jongui 1158
138     @type scene: L{Scene <scene.Scene>} object
139     @param scene: Scene in which objects are to be rendered on
140 jongui 1148 """
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 jongui 1189 # 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 jongui 1148 self.__modified = False
168    
169    
170 ksteube 1147 ###############################################################################
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 jongui 1148 except that it shows a scalar field by contour surfaces cut using a plane.
184 ksteube 1147 """
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 jongui 1148 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 ksteube 1147
232 jongui 1148 # ----- Outline -----
233 ksteube 1147
234 jongui 1148 # 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 ksteube 1147
241 jongui 1148 actor3D = Actor3D()
242     actor3D._setupActor3D(mapper._getDataSetMapper())
243 ksteube 1147 # Default outline color is black.
244 jongui 1148 actor3D.setColor(Color.BLACK)
245 ksteube 1147
246     # Default line width is 1.
247 jongui 1148 actor3D._setLineWidth(1)
248 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
249 ksteube 1147
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 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
256 ksteube 1147 lookup_table = LookupTable()
257     lookup_table._setTableValue()
258 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
259 ksteube 1147 lookup_table = LookupTable()
260     lookup_table._setLookupTableToGreyScale()
261    
262 jongui 1148 self._setupPlane(self._getTransform())
263 ksteube 1147
264 jongui 1148 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 ksteube 1147
271 jongui 1148 self._setupContourModule(self._getCutterOutput())
272     self._setupDataSetMapper(self._getContourModuleOutput(),
273 ksteube 1147 lookup_table._getLookupTable())
274    
275 jongui 1148 self._setupActor3D(self._getDataSetMapper())
276 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
277 jongui 1148
278     def _isModified(self):
279     """
280     Return whether the ContourOnPlaneCut or DataCollector has been modified.
281 ksteube 1147
282 jongui 1148 @rtype: Boolean
283     @return: True or False
284     """
285 ksteube 1147
286 jongui 1148 return self.__modified or self.__data_collector._isModified()
287 ksteube 1147
288 jongui 1158 def _render(self, scene):
289 jongui 1148 """
290     Render the contour cut using a plane.
291 jongui 1158
292     @type scene: L{Scene <scene.Scene>} object
293     @param scene: Scene in which objects are to be rendered on
294 jongui 1148 """
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 jongui 1189 # 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 jongui 1148 self.__modified = False
322    
323    
324 ksteube 1147 ###############################################################################
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 jongui 1148 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 ksteube 1147
385 jongui 1148 # ----- Outline -----
386 ksteube 1147
387 jongui 1148 # 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 ksteube 1147
394 jongui 1148 actor3D = Actor3D()
395     actor3D._setupActor3D(mapper._getDataSetMapper())
396 ksteube 1147 # Default outline color is black.
397 jongui 1148 actor3D.setColor(Color.BLACK)
398 ksteube 1147
399     # Default line width is 1.
400 jongui 1148 actor3D._setLineWidth(1)
401 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
402 ksteube 1147
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 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
409 ksteube 1147 lookup_table = LookupTable()
410     lookup_table._setTableValue()
411 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
412 ksteube 1147 lookup_table = LookupTable()
413     lookup_table._setLookupTableToGreyScale()
414    
415 jongui 1148 self._setupPlane(self._getTransform())
416 ksteube 1147
417 jongui 1148 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 ksteube 1147
425 jongui 1148 self._setClipFunction()
426     self._setupContourModule(self._getClipperOutput())
427 ksteube 1147
428 jongui 1148 self._setupDataSetMapper(self._getContourModuleOutput(),
429 ksteube 1147 lookup_table._getLookupTable())
430    
431 jongui 1148 self._setupActor3D(self._getDataSetMapper())
432 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
433 jongui 1148
434     def _isModified(self):
435     """
436 jongui 1153 Return whether the ContourOnPlaneClip or DataCollector has been
437     modified.
438 ksteube 1147
439 jongui 1148 @rtype: Boolean
440     @return: True or False
441     """
442 ksteube 1147
443 jongui 1148 return self.__modified or self.__data_collector._isModified()
444    
445 jongui 1158 def _render(self, scene):
446 jongui 1148 """
447     Render the contour clip using a plane.
448 jongui 1158
449     @type scene: L{Scene <scene.Scene>} object
450     @param scene: Scene in which objects are to be rendered on
451 jongui 1148 """
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 jongui 1189 # 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 jongui 1148 self.__modified = False
479    
480    

  ViewVC Help
Powered by ViewVC 1.1.26