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

Contents of /trunk/pyvisi/py_src/map.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 996 - (show annotations)
Mon Feb 26 03:43:13 2007 UTC (13 years, 9 months ago) by jongui
File MIME type: text/x-python
File size: 12373 byte(s)
Updated the drivers. Setting the active scalar/vector/tensor is now done in the DataCollector. i.e. 
dc = DataCollector(...)
dc.setFileName(...)
dc.setActiveScalar(...)

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

  ViewVC Help
Powered by ViewVC 1.1.26