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

  ViewVC Help
Powered by ViewVC 1.1.26