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

  ViewVC Help
Powered by ViewVC 1.1.26