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

  ViewVC Help
Powered by ViewVC 1.1.26