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