/[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 2344 - (show annotations)
Mon Mar 30 02:13:58 2009 UTC (10 years, 5 months ago) by jfenwick
File MIME type: text/x-python
File size: 17416 byte(s)
Change __url__ to launchpad site

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 """
23 @var __author__: name of author
24 @var __copyright__: copyrights
25 @var __license__: licence agreement
26 @var __url__: url entry point on documentation
27 @var __version__: version
28 @var __date__: date of the version
29 """
30
31 __author__="John Ngui, john.ngui@uq.edu.au"
32
33
34 import vtk
35 from mapper import DataSetMapper
36 from actor import Actor3D
37 from lookuptable import LookupTable
38 from outline import Outline
39 from constant import Viewport, Color, Lut, ColorMode
40 from contourmodule import ContourModule
41 from average import CellDataToPointData
42 from esys.escript import getMPISizeWorld
43
44 # NOTE: DataSetMapper, Actor3D and ContourModule were inherited to allow
45 # access to their public methods from the driver.
46 class Contour(DataSetMapper, Actor3D, ContourModule):
47 """
48 Class that shows a scalar field by contour surfaces. The contour surfaces
49 can either be colored or grey-scaled, depending on the lookup table used.
50 This class can also be used to generate iso surfaces.
51 """
52
53 # The SOUTH_WEST default viewport is used when there is only one viewport.
54 # This saves the user from specifying the viewport when there is only one.
55 # If no lut is specified, the color scheme will be used.
56 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
57 lut = Lut.COLOR, cell_to_point = False, outline = True):
58 """
59 Initialise the Contour.
60
61 @attention: The source can either be point or cell data. If the
62 source is cell data, a conversion to point data may or may not be
63 required, in order for the object to be rendered correctly.
64 If a conversion is needed, the 'cell_to_point' flag must be set to
65 'True', otherwise 'False' (which is the default). On occasions, an
66 inaccurate object may be rendered from cell data even after conversion.
67
68 @type scene: L{Scene <scene.Scene>} object
69 @param scene: Scene in which objects are to be rendered on
70 @type data_collector: L{DataCollector <datacollector.DataCollector>}
71 object
72 @param data_collector: Deal with source of data for visualisation
73 @type viewport: L{Viewport <constant.Viewport>} constant
74 @param viewport: Viewport in which objects are to be rendered on
75 @type lut : L{Lut <constant.Lut>} constant
76 @param lut: Lookup table color scheme
77 @type cell_to_point: Boolean
78 @param cell_to_point: Converts cell data to point data (by averaging)
79 @type outline: Boolean
80 @param outline: Places an outline around the domain surface
81 """
82
83 self.__data_collector = data_collector
84 self.__viewport = viewport
85 self.__lut = lut
86 self.__cell_to_point = cell_to_point
87 self.__outline = outline
88
89 self.__modified = True # Keeps track whether Contour has been modified.
90 ContourModule.__init__(self)
91 DataSetMapper.__init__(self)
92 Actor3D.__init__(self)
93 scene._addVisualizationModules(self)
94
95 # ----- Outline -----
96
97 # NOTE: Changes cannot be made to the Outline's properties from the
98 # driver.
99 if(self.__outline == True):
100 outline = Outline(self.__data_collector._getDataCollectorOutput())
101 mapper = DataSetMapper()
102 mapper._setupDataSetMapper(outline._getOutlineOutput())
103
104 actor3D = Actor3D()
105 actor3D._setupActor3D(mapper._getDataSetMapper())
106 # Default outline color is black.
107 actor3D.setColor(Color.BLACK)
108
109 # Default line width is 1.
110 actor3D._setLineWidth(1)
111 scene._addActor3D(self.__viewport, actor3D._getActor3D())
112
113 # ----- Contour -----
114
115 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
116 # before DataSetMapper. If it is done after DataSetMapper, no effect
117 # will take place.
118 if(self.__lut == Lut.COLOR): # Colored lookup table.
119 lookup_table = LookupTable()
120 lookup_table._setTableValue()
121 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
122 lookup_table = LookupTable()
123 lookup_table._setLookupTableToGreyScale()
124
125 if(self.__cell_to_point == True): # Converts cell data to point data.
126 c2p = CellDataToPointData(
127 self.__data_collector._getDataCollectorOutput())
128 self._setupContourModule(c2p._getCellToPointOutput())
129 elif(self.__cell_to_point == False): # No conversion happens.
130 self._setupContourModule(
131 self.__data_collector._getDataCollectorOutput())
132
133 self._setupDataSetMapper(self._getContourModuleOutput(),
134 lookup_table._getLookupTable())
135
136 self._setupActor3D(self._getDataSetMapper())
137 scene._addActor3D(self.__viewport, self._getActor3D())
138
139 def _isModified(self):
140 """
141 Return whether the Contour or DataCollector has been modified.
142
143 @rtype: Boolean
144 @return: True or False
145 """
146
147 return self.__modified or self.__data_collector._isModified()
148
149 def _render(self, scene):
150 """
151 Render the contour.
152
153 @type scene: L{Scene <scene.Scene>} object
154 @param scene: Scene in which objects are to be rendered on
155 """
156
157 if (self._isModified() == True):
158 if(self.__data_collector._isScalarSet() == True):
159 self.__data_collector._setActiveScalar()
160
161 # By default 10 contours are generated and the scalar range is
162 # based on the scalar data range.
163 contours = 10
164 lower_range = self.__data_collector._getScalarRange()[0]
165 upper_range = self.__data_collector._getScalarRange()[1]
166
167 if(self._isContoursSet() == True):
168 contours = None
169 if(self._isLowerRangeSet() == True):
170 lower_range = None
171 if(self._isUpperRangeSet() == True):
172 upper_range = None
173
174 self.generateContours(contours, lower_range, upper_range)
175 self._generateContours()
176
177 # self._isScalarRangeSet checks whether the scalar range has been
178 # specified by the user. If it has, then the scalar range
179 # read from the source will be ignored.
180 if(not(self._isScalarRangeSet())):
181 self._setScalarRange(self.__data_collector._getScalarRange())
182 self.__modified = False
183
184
185 ###############################################################################
186
187
188 from transform import Transform
189 from plane import Plane
190 from cutter import Cutter
191
192 # NOTE: DataSetMapper, Actor3D, ContourModule, Transform, Plane and Cutter
193 # were inherited to allow access to their public methods from the driver.
194 class ContourOnPlaneCut(DataSetMapper, Actor3D, ContourModule, Transform,
195 Plane, Cutter):
196 """
197 This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
198 except that it shows a scalar field by contour surfaces cut using a plane.
199 """
200
201 # The SOUTH_WEST default viewport is used when there is only one viewport.
202 # This saves the user from specifying the viewport when there is only one.
203 # If no lut is specified, the color scheme will be used.
204 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
205 lut = Lut.COLOR, cell_to_point = False, outline = True):
206
207 """
208 Initialise the ContourOnPlaneCut.
209
210 @attention: The source can either be point or cell data. If the
211 source is cell data, a conversion to point data may or may not be
212 required, in order for the object to be rendered correctly.
213 If a conversion is needed, the 'cell_to_point' flag must be set to
214 'True', otherwise 'False' (which is the default).
215
216 @type scene: L{Scene <scene.Scene>} object
217 @param scene: Scene in which objects are to be rendered on
218 @type data_collector: L{DataCollector <datacollector.DataCollector>}
219 object
220 @param data_collector: Deal with source of data for visualisation
221 @type viewport: L{Viewport <constant.Viewport>} constant
222 @param viewport: Viewport in which objects are to be rendered on
223 @type lut : L{Lut <constant.Lut>} constant
224 @param lut: Lookup table color scheme
225 @type cell_to_point: Boolean
226 @param cell_to_point: Converts cell data to point data (by averaging)
227 @type outline: Boolean
228 @param outline: Places an outline around the domain surface
229 """
230
231 self.__data_collector = data_collector
232 self.__viewport = viewport
233 self.__lut = lut
234 self.__cell_to_point = cell_to_point
235 self.__outline = outline
236
237 # Keeps track whether ContourOnPlaneCut has been modified.
238 self.__modified = True
239 Transform.__init__(self)
240 Plane.__init__(self)
241 Cutter.__init__(self)
242 ContourModule.__init__(self)
243 DataSetMapper.__init__(self)
244 Actor3D.__init__(self)
245 scene._addVisualizationModules(self)
246
247 # ----- Outline -----
248
249 # NOTE: Changes cannot be made to the Outline's properties from the
250 # driver.
251 if(self.__outline == True):
252 outline = Outline(self.__data_collector._getDataCollectorOutput())
253 mapper = DataSetMapper()
254 mapper._setupDataSetMapper(outline._getOutlineOutput())
255
256 actor3D = Actor3D()
257 actor3D._setupActor3D(mapper._getDataSetMapper())
258 # Default outline color is black.
259 actor3D.setColor(Color.BLACK)
260
261 # Default line width is 1.
262 actor3D._setLineWidth(1)
263 scene._addActor3D(self.__viewport, actor3D._getActor3D())
264
265 # ----- Contour on a cut plane -----
266
267 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
268 # before DataSetMapper. If it is done after DataSetMapper, no effect
269 # will take place.
270 if(self.__lut == Lut.COLOR): # Colored lookup table.
271 lookup_table = LookupTable()
272 lookup_table._setTableValue()
273 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
274 lookup_table = LookupTable()
275 lookup_table._setLookupTableToGreyScale()
276
277 self._setupPlane(self._getTransform())
278
279 if(self.__cell_to_point == True): # Converts cell data to point data.
280 c2p = CellDataToPointData(self.__data_collector._getOutput())
281 self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())
282 elif(self.__cell_to_point == False): # No conversion happens.
283 self._setupCutter(self.__data_collector._getDataCollectorOutput(),
284 self._getPlane())
285
286 self._setupContourModule(self._getCutterOutput())
287 self._setupDataSetMapper(self._getContourModuleOutput(),
288 lookup_table._getLookupTable())
289
290 self._setupActor3D(self._getDataSetMapper())
291 scene._addActor3D(self.__viewport, self._getActor3D())
292
293 def _isModified(self):
294 """
295 Return whether the ContourOnPlaneCut or DataCollector has been modified.
296
297 @rtype: Boolean
298 @return: True or False
299 """
300
301 return self.__modified or self.__data_collector._isModified()
302
303 def _render(self, scene):
304 """
305 Render the contour cut using a plane.
306
307 @type scene: L{Scene <scene.Scene>} object
308 @param scene: Scene in which objects are to be rendered on
309 """
310
311 if (self._isModified() == True):
312 if(self.__data_collector._isScalarSet() == True):
313 self.__data_collector._setActiveScalar()
314
315 # By default 10 contours are generated and the scalar range is based
316 # on the scalar data range.
317 contours = 10
318 lower_range = self.__data_collector._getScalarRange()[0]
319 upper_range = self.__data_collector._getScalarRange()[1]
320
321 if(self._isContoursSet() == True):
322 contours = None
323 if(self._isLowerRangeSet() == True):
324 lower_range = None
325 if(self._isUpperRangeSet() == True):
326 upper_range = None
327
328 self.generateContours(contours, lower_range, upper_range)
329 self._generateContours()
330
331 # self._isScalarRangeSet checks whether the scalar range has been
332 # specified by the user. If it has, then the scalar range
333 # read from the source will be ignored.
334 if(not(self._isScalarRangeSet())):
335 self._setScalarRange(self.__data_collector._getScalarRange())
336 self.__modified = False
337
338
339 ###############################################################################
340
341
342 from clipper import Clipper
343
344 # NOTE: DataSetMapper, Actor3D, ContourModule, Transform, Plane and Clipper
345 # were inherited to allow access to their public methods from the driver.
346 class ContourOnPlaneClip(DataSetMapper, Actor3D, ContourModule, Transform,
347 Plane, Clipper):
348 """
349 This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>}
350 , except that it shows a scalar field by contour surfaces clipped using
351 a plane.
352 """
353
354 # The SOUTH_WEST default viewport is used when there is only one viewport.
355 # This saves the user from specifying the viewport when there is only one.
356 # If no lut is specified, the color scheme will be used.
357 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
358 lut = Lut.COLOR, cell_to_point = False, outline = True):
359
360 """
361 Initialise the ContourOnPlaneClip.
362
363 @attention: The source can either be point or cell data. If the
364 source is cell data, a conversion to point data may or may not be
365 required, in order for the object to be rendered correctly.
366 If a conversion is needed, the 'cell_to_point' flag must be set to
367 'True', otherwise 'False' (which is the default).
368
369 @type scene: L{Scene <scene.Scene>} object
370 @param scene: Scene in which objects are to be rendered on
371 @type data_collector: L{DataCollector <datacollector.DataCollector>}
372 object
373 @param data_collector: Deal with source of data for visualisation
374 @type viewport: L{Viewport <constant.Viewport>} constant
375 @param viewport: Viewport in which objects are to be rendered on
376 @type lut : L{Lut <constant.Lut>} constant
377 @param lut: Lookup table color scheme
378 @type cell_to_point: Boolean
379 @param cell_to_point: Converts cell data to point data (by averaging)
380 @type outline: Boolean
381 @param outline: Places an outline around the domain surface
382 """
383
384 self.__data_collector = data_collector
385 self.__viewport = viewport
386 self.__lut = lut
387 self.__cell_to_point = cell_to_point
388 self.__outline = outline
389
390 # Keeps track whether ContourOnPlaneClip has been modified.
391 self.__modified = True
392 Transform.__init__(self)
393 Plane.__init__(self)
394 Clipper.__init__(self)
395 ContourModule.__init__(self)
396 DataSetMapper.__init__(self)
397 Actor3D.__init__(self)
398 scene._addVisualizationModules(self)
399
400 # ----- Outline -----
401
402 # NOTE: Changes cannot be made to the Outline's properties from the
403 # driver.
404 if(self.__outline == True):
405 outline = Outline(self.__data_collector._getDataCollectorOutput())
406 mapper = DataSetMapper()
407 mapper._setupDataSetMapper(outline._getOutlineOutput())
408
409 actor3D = Actor3D()
410 actor3D._setupActor3D(mapper._getDataSetMapper())
411 # Default outline color is black.
412 actor3D.setColor(Color.BLACK)
413
414 # Default line width is 1.
415 actor3D._setLineWidth(1)
416 scene._addActor3D(self.__viewport, actor3D._getActor3D())
417
418 # ----- Contour on a clipped plane -----
419
420 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
421 # before DataSetMapper. If it is done after DataSetMapper, no effect
422 # will take place.
423 if(self.__lut == Lut.COLOR): # Colored lookup table.
424 lookup_table = LookupTable()
425 lookup_table._setTableValue()
426 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
427 lookup_table = LookupTable()
428 lookup_table._setLookupTableToGreyScale()
429
430 self._setupPlane(self._getTransform())
431
432 if(self.__cell_to_point == True): # Converts cell data to point data.
433 c2p = CellDataToPointData(
434 self.__data_collector._getDataCollectorOutput())
435 self._setupClipper(c2p._getCellToPointOutput(), self._getPlane())
436 elif(self.__cell_to_point == False): # No conversion happens.
437 self._setupClipper(self.__data_collector._getDataCollectorOutput(),
438 self._getPlane())
439
440 self._setClipFunction()
441 self._setupContourModule(self._getClipperOutput())
442
443 self._setupDataSetMapper(self._getContourModuleOutput(),
444 lookup_table._getLookupTable())
445
446 self._setupActor3D(self._getDataSetMapper())
447 scene._addActor3D(self.__viewport, self._getActor3D())
448
449 def _isModified(self):
450 """
451 Return whether the ContourOnPlaneClip or DataCollector has been
452 modified.
453
454 @rtype: Boolean
455 @return: True or False
456 """
457
458 return self.__modified or self.__data_collector._isModified()
459
460 def _render(self, scene):
461 """
462 Render the contour clip using a plane.
463
464 @type scene: L{Scene <scene.Scene>} object
465 @param scene: Scene in which objects are to be rendered on
466 """
467
468 if (self._isModified() == True):
469 if(self.__data_collector._isScalarSet() == True):
470 self.__data_collector._setActiveScalar()
471
472 # By default 10 contours are generated and the scalar range is based
473 # on the scalar data range.
474 contours = 10
475 lower_range = self.__data_collector._getScalarRange()[0]
476 upper_range = self.__data_collector._getScalarRange()[1]
477
478 if(self._isContoursSet() == True):
479 contours = None
480 if(self._isLowerRangeSet() == True):
481 lower_range = None
482 if(self._isUpperRangeSet() == True):
483 upper_range = None
484
485 self.generateContours(contours, lower_range, upper_range)
486 self._generateContours()
487
488 # self._isScalarRangeSet checks whether the scalar range has been
489 # specified by the user. If it has, then the scalar range
490 # read from the source will be ignored.
491 if(not(self._isScalarRangeSet())):
492 self._setScalarRange(self.__data_collector._getScalarRange())
493 self.__modified = False
494
495

  ViewVC Help
Powered by ViewVC 1.1.26