/[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 1043 - (hide annotations)
Mon Mar 19 06:46:34 2007 UTC (13 years, 10 months ago) by jongui
File MIME type: text/x-python
File size: 12382 byte(s)
Map and Contour now able to display cell data correctly. At this stage, it appears that the probe filter cannot be applied on cell data as a segmentation fault will be thrown.
1 jongui 1037 """
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     from constant import Viewport, Color, Lut, VizType, ColorMode
11     from contourmodule import ContourModule
12 jongui 1043 from average import CellDataToPointData
13 jongui 1037
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 jongui 1043 lut = Lut.COLOR, cell_to_point = False, outline = True):
28 jongui 1037 """
29     @type scene: L{Scene <scene.Scene>} object
30     @param scene: Scene in which objects are to be rendered on
31     @type data_collector: L{DataCollector <datacollector.DataCollector>}
32     object
33     @param data_collector: Deal with source of data for visualisation
34     @type viewport: L{Viewport <constant.Viewport>} constant
35     @param viewport: Viewport in which objects are to be rendered on
36     @type lut : L{Lut <constant.Lut>} constant
37     @param lut: Lookup table color scheme
38 jongui 1043 @type cell_to_point: Boolean
39     @param cell_to_point: Converts cell data to point data (by averaging)
40 jongui 1037 @type outline: Boolean
41     @param outline: Places an outline around the domain surface
42     """
43    
44     # NOTE: Actor3D is inherited and there are two instances declared here.
45     # As a result, when methods from Actor3D is invoked from the driver,
46     # only the methods associated with the latest instance (which in this
47     # case is the Actor3D for the contour) can be executed. Actor3D
48     # methods associated with Outline cannot be invoked from the driver.
49     # They can only be called within here, which is why Outline must
50     # be place before the contour as there is unlikely to be any changes
51     # made to the Outline's Actor3D.
52    
53     # ----- Outline -----
54    
55     if(outline == True):
56     outline = Outline(data_collector._getOutput())
57     DataSetMapper.__init__(self, outline._getOutput())
58    
59     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
60     # Default outline color is black.
61     Actor3D.setColor(self, Color.BLACK)
62    
63     # Default line width is 1.
64     Actor3D._setLineWidth(self, 1)
65     scene._addActor3D(viewport, Actor3D._getActor3D(self))
66    
67     # ----- Contour -----
68    
69     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
70     # before DataSetMapper. If it is done after DataSetMapper, no effect
71     # will take place.
72     if(lut == Lut.COLOR): # Colored lookup table.
73     lookup_table = LookupTable()
74     lookup_table._setTableValue()
75     elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
76     lookup_table = LookupTable()
77     lookup_table._setLookupTableToGreyScale()
78    
79 jongui 1043 if(cell_to_point == True): # Converts cell data to point data.
80     c2p = CellDataToPointData(data_collector._getOutput())
81     ContourModule.__init__(self, c2p._getOutput())
82     elif(cell_to_point == False): # No conversion happens.
83     ContourModule.__init__(self, data_collector._getOutput())
84    
85 jongui 1037 # By default 10 contours are generated and the scalar range is based
86     # on the scalar data range.
87     ContourModule.generateContours(self, 10,
88     data_collector._getScalarRange()[0],
89     data_collector._getScalarRange()[1])
90    
91     DataSetMapper.__init__(self, ContourModule._getOutput(self),
92     lookup_table._getLookupTable())
93     DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
94    
95     data_collector._paramForUpdatingMultipleSources(VizType.CONTOUR,
96     ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),
97     ContourModule._getContour(self))
98    
99     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
100     scene._addActor3D(viewport, Actor3D._getActor3D(self))
101    
102    
103     ###############################################################################
104    
105    
106     from transform import Transform
107     from plane import Plane
108     from cutter import Cutter
109    
110     # NOTE: DataSetMapper, Actor3D, ContourModule, Transform, Plane and Cutter were
111     # inherited to allow access to their public methods from the driver.
112     class ContourOnPlaneCut(DataSetMapper, Actor3D, ContourModule, Transform,
113     Plane, Cutter):
114     """
115     This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
116     except that it shows a scalar field by contour surfaces on a plane.
117     """
118    
119     # The SOUTH_WEST default viewport is used when there is only one viewport.
120     # This saves the user from specifying the viewport when there is only one.
121     # If no lut is specified, the color scheme will be used.
122     def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
123 jongui 1043 lut = Lut.COLOR, cell_to_point = False, outline = True):
124 jongui 1037
125     """
126     @type scene: L{Scene <scene.Scene>} object
127     @param scene: Scene in which objects are to be rendered on
128     @type data_collector: L{DataCollector <datacollector.DataCollector>}
129     object
130     @param data_collector: Deal with source of data for visualisation
131     @type viewport: L{Viewport <constant.Viewport>} constant
132     @param viewport: Viewport in which objects are to be rendered on
133     @type lut : L{Lut <constant.Lut>} constant
134     @param lut: Lookup table color scheme
135 jongui 1043 @type cell_to_point: Boolean
136     @param cell_to_point: Converts cell data to point data (by averaging)
137 jongui 1037 @type outline: Boolean
138     @param outline: Places an outline around the domain surface
139     """
140    
141     # NOTE: Actor3D is inherited and there are two instances declared here.
142     # As a result, when methods from Actor3D is invoked from the driver,
143     # only the methods associated with the latest instance (which in this
144     # case is the Actor3D for the contour) can be executed. Actor3D
145     # methods associated with Outline cannot be invoked from the driver.
146     # They can only be called within here, which is why Outline must
147     # be place before the contour as there is unlikely to be any changes
148     # made to the Outline's Actor3D.
149    
150     # ----- Outline -----
151    
152     if(outline == True):
153     outline = Outline(data_collector._getOutput())
154     DataSetMapper.__init__(self, outline._getOutput())
155    
156     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
157     # Default outline color is black.
158     Actor3D.setColor(self, Color.BLACK)
159    
160     # Default line width is 1.
161     Actor3D._setLineWidth(self, 1)
162     scene._addActor3D(viewport, Actor3D._getActor3D(self))
163    
164     # ----- Contour on a cut plane -----
165    
166     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
167     # before DataSetMapper. If it is done after DataSetMapper, no effect
168     # will take place.
169     if(lut == Lut.COLOR): # Colored lookup table.
170     lookup_table = LookupTable()
171     lookup_table._setTableValue()
172     elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
173     lookup_table = LookupTable()
174     lookup_table._setLookupTableToGreyScale()
175    
176     Transform.__init__(self)
177     Plane.__init__(self, Transform._getTransform(self))
178    
179 jongui 1043 if(cell_to_point == True): # Converts cell data to point data.
180     c2p = CellDataToPointData(data_collector._getOutput())
181     Cutter.__init__(self, c2p._getOutput(), Plane._getPlane(self))
182     elif(cell_to_point == False): # No conversion happens.
183     Cutter.__init__(self, data_collector._getOutput(),
184     Plane._getPlane(self))
185    
186 jongui 1037 ContourModule.__init__(self, Cutter._getOutput(self))
187    
188     # By default 10 contours are generated and the scalar range is based
189     # on the scalar data range.
190     ContourModule.generateContours(self, 10,
191     data_collector._getScalarRange()[0],
192     data_collector._getScalarRange()[1])
193    
194     DataSetMapper.__init__(self, ContourModule._getOutput(self),
195     lookup_table._getLookupTable())
196     DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
197    
198 jongui 1043 data_collector._paramForUpdatingMultipleSources(VizType.CONTOUR,
199     ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),
200     ContourModule._getContour(self))
201    
202 jongui 1037 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
203     scene._addActor3D(viewport, Actor3D._getActor3D(self))
204    
205    
206     ###############################################################################
207    
208    
209     from clipper import Clipper
210    
211     # NOTE: DataSetMapper, Actor3D, ContourModule, Transform, Plane and Clipper
212     # were inherited to allow access to their public methods from the driver.
213     class ContourOnPlaneClip(DataSetMapper, Actor3D, ContourModule, Transform,
214     Plane, Clipper):
215     """
216     This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>}
217     , except that it shows a scalar field by contour surfaces clipped using
218     a plane.
219     """
220    
221     # The SOUTH_WEST default viewport is used when there is only one viewport.
222     # This saves the user from specifying the viewport when there is only one.
223     # If no lut is specified, the color scheme will be used.
224     def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
225 jongui 1043 lut = Lut.COLOR, cell_to_point = False, outline = True):
226 jongui 1037
227     """
228     @type scene: L{Scene <scene.Scene>} object
229     @param scene: Scene in which objects are to be rendered on
230     @type data_collector: L{DataCollector <datacollector.DataCollector>}
231     object
232     @param data_collector: Deal with source of data for visualisation
233     @type viewport: L{Viewport <constant.Viewport>} constant
234     @param viewport: Viewport in which objects are to be rendered on
235     @type lut : L{Lut <constant.Lut>} constant
236     @param lut: Lookup table color scheme
237 jongui 1043 @type cell_to_point: Boolean
238     @param cell_to_point: Converts cell data to point data (by averaging)
239 jongui 1037 @type outline: Boolean
240     @param outline: Places an outline around the domain surface
241     """
242    
243     # NOTE: Actor3D is inherited and there are two instances declared here.
244     # As a result, when methods from Actor3D is invoked from the driver,
245     # only the methods associated with the latest instance (which in this
246     # case is the Actor3D for the contour) can be executed. Actor3D
247     # methods associated with Outline cannot be invoked from the driver.
248     # They can only be called within here, which is why Outline must
249     # be place before the contour as there is unlikely to be any changes
250     # made to the Outline's Actor3D.
251    
252     # ----- Outline -----
253    
254     if(outline == True):
255     outline = Outline(data_collector._getOutput())
256     DataSetMapper.__init__(self, outline._getOutput())
257    
258     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
259     # Default outline color is black.
260     Actor3D.setColor(self, Color.BLACK)
261    
262     # Default line width is 1.
263     Actor3D._setLineWidth(self, 1)
264     scene._addActor3D(viewport, Actor3D._getActor3D(self))
265    
266     # ----- Contour on a clipped plane -----
267    
268     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
269     # before DataSetMapper. If it is done after DataSetMapper, no effect
270     # will take place.
271     if(lut == Lut.COLOR): # Colored lookup table.
272     lookup_table = LookupTable()
273     lookup_table._setTableValue()
274     elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
275     lookup_table = LookupTable()
276     lookup_table._setLookupTableToGreyScale()
277    
278     Transform.__init__(self)
279     Plane.__init__(self, Transform._getTransform(self))
280    
281 jongui 1043 if(cell_to_point == True): # Converts cell data to point data.
282     c2p = CellDataToPointData(data_collector._getOutput())
283     Clipper.__init__(self, c2p._getOutput(), Plane._getPlane(self))
284     elif(cell_to_point == False): # No conversion happens.
285     Clipper.__init__(self, data_collector._getOutput(),
286     Plane._getPlane(self))
287    
288 jongui 1037 Clipper._setClipFunction(self)
289    
290     ContourModule.__init__(self, Clipper._getOutput(self))
291     # By default 10 contours are generated and the scalar range is based
292     # on the scalar data range.
293     ContourModule.generateContours(self, 10,
294     data_collector._getScalarRange()[0],
295     data_collector._getScalarRange()[1])
296    
297     DataSetMapper.__init__(self, ContourModule._getOutput(self),
298     lookup_table._getLookupTable())
299     DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
300    
301 jongui 1043 data_collector._paramForUpdatingMultipleSources(VizType.CONTOUR,
302     ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),
303     ContourModule._getContour(self))
304    
305 jongui 1037 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
306     scene._addActor3D(viewport, Actor3D._getActor3D(self))
307    

  ViewVC Help
Powered by ViewVC 1.1.26