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

  ViewVC Help
Powered by ViewVC 1.1.26