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

  ViewVC Help
Powered by ViewVC 1.1.26