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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1148 - (show annotations)
Wed May 16 22:45:33 2007 UTC (13 years, 10 months ago) by jongui
File MIME type: text/x-python
File size: 15161 byte(s)
Added the updated files for pyvisi and removed some incorrect reference images.
1 """
2 @author: John NGUI
3 """
4
5 import vtk
6 from mapper import DataSetMapper
7 from lookuptable import LookupTable
8 from actor import Actor3D
9 from constant import Viewport, Color, Lut, ColorMode
10 from sphere import Sphere
11 from normals import Normals
12 from glyph import TensorGlyph
13 from outline import Outline
14 from point import MaskPoints
15 from average import CellDataToPointData
16
17 # NOTE: DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph
18 # and MaskPoints were inherited to allow access to their
19 # public methods from the driver.
20 class Ellipsoid(DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph,
21 MaskPoints):
22 """
23 Class that shows a tensor field using ellipsoids. The ellipsoids can either
24 be colored or grey-scaled, depending on the lookup table used.
25 """
26
27 # The SOUTH_WEST default viewport is used when there is only one viewport.
28 # This saves the user from specifying the viewport when there is only one.
29 # If no lut is specified, the color scheme will be used.
30 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
31 lut = Lut.COLOR, cell_to_point = False, outline = True):
32 """
33 Initialise the Ellipsoid.
34
35 @attention: The source can either be point or cell data. If the
36 source is cell data, a conversion to point data may or may not be
37 required, in order for the object to be rendered correctly.
38 If a conversion is needed, the 'cell_to_point' flag must be set to
39 'True', otherwise 'False' (which is the default).
40
41 @type scene: L{Scene <scene.Scene>} object
42 @param scene: Scene in which objects are to be rendered on
43 @type data_collector: L{DataCollector <datacollector.DataCollector>}
44 object
45 @param data_collector: Deal with source of data for vizualisation
46 @type viewport: L{Viewport <constant.Viewport>} constant
47 @param viewport: Viewport in which objects are to be rendered on
48 @type lut : L{Lut <constant.Lut>} constant
49 @param lut: Lookup table color scheme
50 @type cell_to_point: Boolean
51 @param cell_to_point: Converts cell data to point data (by averaging)
52 @type outline: Boolean
53 @param outline: Places an outline around the domain surface
54 """
55
56 self.__scene = scene
57 self.__data_collector = data_collector
58 self.__viewport = viewport
59 self.__lut = lut
60 self.__cell_to_point = cell_to_point
61 self.__outline = outline
62
63 # Keeps track whether Ellipsoid has been modified.
64 self.__modified = True
65 MaskPoints.__init__(self)
66 Sphere.__init__(self)
67 TensorGlyph.__init__(self)
68 Normals.__init__(self)
69 DataSetMapper.__init__(self)
70 Actor3D.__init__(self)
71 scene._addVisualizationModules(self)
72
73 # ----- Outline -----
74
75 # NOTE: Changes cannot be made to the Outline's properties from the
76 # driver.
77 if(self.__outline == True):
78 outline = Outline(self.__data_collector._getDataCollectorOutput())
79 mapper = DataSetMapper()
80 mapper._setupDataSetMapper(outline._getOutlineOutput())
81
82 actor3D = Actor3D()
83 actor3D._setupActor3D(mapper._getDataSetMapper())
84 # Default outline color is black.
85 actor3D.setColor(Color.BLACK)
86
87 # Default line width is 1.
88 actor3D._setLineWidth(1)
89 self.__scene._addActor3D(self.__viewport, actor3D._getActor3D())
90
91 # ----- Ellipsoid -----
92
93 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
94 # before DataSetMapper. If it is done after DataSetMapper, no effect
95 # will take place.
96 if(self.__lut == Lut.COLOR): # Colored lookup table.
97 lookup_table = LookupTable()
98 lookup_table._setTableValue()
99 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
100 lookup_table = LookupTable()
101 lookup_table._setLookupTableToGreyScale()
102
103 if(self.__cell_to_point == True): # Converts cell data to point data.
104 c2p = CellDataToPointData(
105 self.__data_collector._getDataCollectorOutput())
106 self._setupMaskPoints(c2p._getCellToPointOutput())
107 elif(self.__cell_to_point == False): # No conversion happens.
108 self._setupMaskPoints(
109 self.__data_collector._getDataCollectorOutput())
110
111 self._setupTensorGlyph(self._getMaskPointsOutput(),
112 self._getSphereOutput())
113 self._setupNormals(self._getTensorGlyphOutput())
114
115 self._setupDataSetMapper(self._getNormalsOutput(),
116 lookup_table._getLookupTable())
117
118 self._setupActor3D(self._getDataSetMapper())
119 self.__scene._addActor3D(self.__viewport, self._getActor3D())
120
121 def _isModified(self):
122 """
123 Return whether the Ellipsoid or DataCollector has been modified.
124
125 @rtype: Boolean
126 @return: True or False
127 """
128
129 return self.__modified or self.__data_collector._isModified()
130
131 def _render(self):
132 """
133 Render the ellipsoids.
134 """
135
136 if (self._isModified() == True):
137 if(self.__data_collector._isScalarSet() == True):
138 self.__data_collector._setActiveScalar()
139 if(self.__data_collector._isTensorSet() == True):
140 self.__data_collector._setActiveTensor()
141
142 self._setScalarRange(self.__data_collector._getScalarRange())
143 self.__modified = False
144
145
146 ###############################################################################
147
148
149 from transform import Transform
150 from plane import Plane
151 from cutter import Cutter
152
153 # NOTE: DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph, Transform, Plane,
154 # Cutter and MaskPoints were inherited to allow access to
155 # their public methods from the driver.
156 class EllipsoidOnPlaneCut(DataSetMapper, Actor3D, Sphere, Normals,
157 TensorGlyph, Transform, Plane, Cutter, MaskPoints):
158 """
159 This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
160 except that it shows a tensor field using ellipsoids cut using a plane.
161 """
162
163 # The SOUTH_WEST default viewport is used when there is only one viewport.
164 # This saves the user from specifying the viewport when there is only one.
165 # If no lut is specified, the color scheme will be used.
166 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
167 lut = Lut.COLOR, cell_to_point = False, outline = True):
168 """
169 Initialise the EllipsoidOnPlaneCut.
170
171 @attention: The source can either be point or cell data. If the
172 source is cell data, a conversion to point data may or may not be
173 required, in order for the object to be rendered correctly.
174 If a conversion is needed, the 'cell_to_point' flag must be set to
175 'True', otherwise 'False' (which is the default).
176
177 @type scene: L{Scene <scene.Scene>} object
178 @param scene: Scene in which objects are to be rendered on
179 @type data_collector: L{DataCollector <datacollector.DataCollector>}
180 object
181 @param data_collector: Deal with source of data for vizualisation
182 @type viewport: L{Viewport <constant.Viewport>} constant
183 @param viewport: Viewport in which objects are to be rendered on
184 @type lut : L{Lut <constant.Lut>} constant
185 @param lut: Lookup table color scheme
186 @type cell_to_point: Boolean
187 @param cell_to_point: Converts cell data to point data (by averaging)
188 @type outline: Boolean
189 @param outline: Places an outline around the domain surface
190 """
191
192 self.__scene = scene
193 self.__data_collector = data_collector
194 self.__viewport = viewport
195 self.__lut = lut
196 self.__cell_to_point = cell_to_point
197 self.__outline = outline
198
199 # Keeps track whether EllipsoidOnPlaneCut has been modified.
200 self.__modified = True
201 Transform.__init__(self)
202 Plane.__init__(self)
203 Cutter.__init__(self)
204 MaskPoints.__init__(self)
205 Sphere.__init__(self)
206 TensorGlyph.__init__(self)
207 Normals.__init__(self)
208 DataSetMapper.__init__(self)
209 Actor3D.__init__(self)
210 scene._addVisualizationModules(self)
211
212 # ----- Outline -----
213
214 # NOTE: Changes cannot be made to the Outline's properties from the
215 # driver.
216 if(self.__outline == True):
217 outline = Outline(self.__data_collector._getDataCollectorOutput())
218 mapper = DataSetMapper()
219 mapper._setupDataSetMapper(outline._getOutlineOutput())
220
221 actor3D = Actor3D()
222 actor3D._setupActor3D(mapper._getDataSetMapper())
223 # Default outline color is black.
224 actor3D.setColor(Color.BLACK)
225
226 # Default line width is 1.
227 actor3D._setLineWidth(1)
228 self.__scene._addActor3D(self.__viewport, actor3D._getActor3D())
229
230 # ----- Ellipsoid on a cut plane -----
231
232 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
233 # before DataSetMapper. If it is done after DataSetMapper, no effect
234 # will take place.
235 if(self.__lut == Lut.COLOR): # Colored lookup table.
236 lookup_table = LookupTable()
237 lookup_table._setTableValue()
238 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
239 lookup_table = LookupTable()
240 lookup_table._setLookupTableToGreyScale()
241
242 self._setupPlane(self._getTransform())
243
244 if(self.__cell_to_point == True): # Converts cell data to point data.
245 c2p = CellDataToPointData(
246 self.__data_collector._getDataCollectorOutput())
247 self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())
248 elif(self.__cell_to_point == False): # No conversion happens.
249 self._setupCutter(self.__data_collector._getDataCollectorOutput(),
250 self._getPlane())
251
252 self._setupMaskPoints(self._getCutterOutput())
253
254 self._setupTensorGlyph(self._getMaskPointsOutput(),
255 self._getSphereOutput())
256 self._setupNormals(self._getTensorGlyphOutput())
257
258 self._setupDataSetMapper(self._getNormalsOutput(),
259 lookup_table._getLookupTable())
260
261 self._setupActor3D(self._getDataSetMapper())
262 self.__scene._addActor3D(self.__viewport, self._getActor3D())
263
264 def _isModified(self):
265 """
266 Return whether the EllipsoidOnPlaneCut or DataCollector has been
267 modified.
268
269 @rtype: Boolean
270 @return: True or False
271 """
272
273 return self.__modified or self.__data_collector._isModified()
274
275 def _render(self):
276 """
277 Render the ellipsoids cut using a plane.
278 """
279
280 if (self._isModified() == True):
281 if(self.__data_collector._isScalarSet() == True):
282 self.__data_collector._setActiveScalar()
283 if(self.__data_collector._isTensorSet() == True):
284 self.__data_collector._setActiveTensor()
285 self._setScalarRange(self.__data_collector._getScalarRange())
286 self.__modified = False
287
288
289 ###############################################################################
290
291
292 from clipper import Clipper
293
294 # NOTE: DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph, Transform, Plane,
295 # Clipper and MaskPoints were inherited to allow access to
296 # their public methods from the driver.
297 class EllipsoidOnPlaneClip(DataSetMapper, Actor3D, Sphere, Normals,
298 TensorGlyph, Transform, Plane, Clipper, MaskPoints):
299 """
300 This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>},
301 except that it shows a tensor field using ellipsoids clipped using a plane.
302 """
303
304 # The SOUTH_WEST default viewport is used when there is only one viewport.
305 # This saves the user from specifying the viewport when there is only one.
306 # If no lut is specified, the color scheme will be used.
307 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
308 lut = Lut.COLOR, cell_to_point = False, outline = True):
309 """
310 Initialise the EllipsoidOnPlaneClip.
311
312 @attention: The source can either be point or cell data. If the
313 source is cell data, a conversion to point data may or may not be
314 required, in order for the object to be rendered correctly.
315 If a conversion is needed, the 'cell_to_point' flag must be set to
316 'True', otherwise 'False' (which is the default).
317
318 @type scene: L{Scene <scene.Scene>} object
319 @param scene: Scene in which objects are to be rendered on
320 @type data_collector: L{DataCollector <datacollector.DataCollector>}
321 object
322 @param data_collector: Deal with source of data for visualisation
323 @type viewport: L{Viewport <constant.Viewport>} constant
324 @param viewport: Viewport in which object are to be rendered on
325 @type lut : L{Lut <constant.Lut>} constant
326 @param lut: Lookup table color scheme
327 @type cell_to_point: Boolean
328 @param cell_to_point: Converts cell data to point data (by averaging)
329 @type outline: Boolean
330 @param outline: Places an outline around the domain surface
331 """
332
333 self.__scene = scene
334 self.__data_collector = data_collector
335 self.__viewport = viewport
336 self.__lut = lut
337 self.__cell_to_point = cell_to_point
338 self.__outline = outline
339
340 # Keeps track whether EllipsoidOnPlaneClip has been modified.
341 self.__modified = True
342 Transform.__init__(self)
343 Plane.__init__(self)
344 Clipper.__init__(self)
345 MaskPoints.__init__(self)
346 Sphere.__init__(self)
347 TensorGlyph.__init__(self)
348 Normals.__init__(self)
349 DataSetMapper.__init__(self)
350 Actor3D.__init__(self)
351 scene._addVisualizationModules(self)
352
353 # ----- Outline -----
354
355 # NOTE: Changes cannot be made to the Outline's properties from the
356 # driver.
357 if(self.__outline == True):
358 outline = Outline(self.__data_collector._getDataCollectorOutput())
359 mapper = DataSetMapper()
360 mapper._setupDataSetMapper(outline._getOutlineOutput())
361
362 actor3D = Actor3D()
363 actor3D._setupActor3D(mapper._getDataSetMapper())
364 # Default outline color is black.
365 actor3D.setColor(Color.BLACK)
366
367 # Default line width is 1.
368 actor3D._setLineWidth(1)
369 self.__scene._addActor3D(self.__viewport, actor3D._getActor3D())
370
371 # ----- Ellipsoid on a clipped plane -----
372
373 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
374 # before DataSetMapper. If it is done after DataSetMapper, no effect
375 # will take place.
376 if(self.__lut == Lut.COLOR): # Colored lookup table.
377 lookup_table = LookupTable()
378 lookup_table._setTableValue()
379 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
380 lookup_table = LookupTable()
381 lookup_table._setLookupTableToGreyScale()
382
383 self._setupPlane(self._getTransform())
384
385 if(self.__cell_to_point == True): # Converts cell data to point data.
386 c2p = CellDataToPointData(
387 self.__data_collector._getDataCollectorOutput())
388 self._setupMaskPoints(c2p._getCellToPointOutput())
389 elif(self.__cell_to_point == False): # No conversion happens.
390 self._setupMaskPoints(
391 self.__data_collector._getDataCollectorOutput())
392
393 # NOTE: TensorGlyph must come before Clipper. Otherwise clipping
394 # may not work correctly.
395 self._setupTensorGlyph(self._getMaskPointsOutput(),
396 self._getSphereOutput())
397 self._setupNormals(self._getTensorGlyphOutput())
398
399 # NOTE: Clipper must come after TensorGlyph. Otherwise clipping
400 # may not work correctly.
401 self._setupClipper(self._getNormalsOutput(),
402 self._getPlane())
403 self._setClipFunction()
404
405 self._setupDataSetMapper(self._getClipperOutput(),
406 lookup_table._getLookupTable())
407
408 self._setupActor3D(self._getDataSetMapper())
409 self.__scene._addActor3D(self.__viewport, self._getActor3D())
410
411 def _isModified(self):
412 """
413 Return whether the EllipsoidOnPlaneClip or DataCollector has been
414 modified.
415
416 @rtype: Boolean
417 @return: True or False
418 """
419
420 return self.__modified or self.__data_collector._isModified()
421
422 def _render(self):
423 """
424 Render the ellipsoids clip using a plane.
425 """
426
427 if (self._isModified() == True):
428 if(self.__data_collector._isScalarSet() == True):
429 self.__data_collector._setActiveScalar()
430 if(self.__data_collector._isTensorSet() == True):
431 self.__data_collector._setActiveTensor()
432 self._setScalarRange(self.__data_collector._getScalarRange())
433 self.__modified = False
434
435

  ViewVC Help
Powered by ViewVC 1.1.26