1 |
ksteube |
1147 |
""" |
2 |
jongui |
1197 |
@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 |
ksteube |
1147 |
""" |
9 |
|
|
|
10 |
jongui |
1197 |
__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 |
ksteube |
1147 |
import vtk |
22 |
|
|
from mapper import DataSetMapper |
23 |
|
|
from lookuptable import LookupTable |
24 |
|
|
from actor import Actor3D |
25 |
jongui |
1148 |
from constant import Viewport, Color, Lut, WarpMode, ColorMode |
26 |
ksteube |
1147 |
from warp import Warp |
27 |
|
|
from outline import Outline |
28 |
|
|
from transform import Transform |
29 |
|
|
from plane import Plane |
30 |
|
|
from cutter import Cutter |
31 |
|
|
from average import CellDataToPointData |
32 |
|
|
|
33 |
|
|
# NOTE: DataSetMapper, Actor3D, Warp, Transform, Plane and Cutter were |
34 |
|
|
# inherited to allow access to their public methods from the driver. |
35 |
|
|
class Carpet(DataSetMapper, Actor3D, Warp, Transform, Plane, Cutter): |
36 |
|
|
""" |
37 |
|
|
Class that shows a scalar field on a plane deformated along the normal. |
38 |
|
|
""" |
39 |
|
|
|
40 |
|
|
# The SOUTH_WEST default viewport is used when there is only one viewport. |
41 |
|
|
# This saves the user from specifying the viewport when there is only one. |
42 |
|
|
# If no warp_mode is specified, the data will be deformated using scalar |
43 |
|
|
# data. If no lut is specified, the color scheme will be used. |
44 |
|
|
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, |
45 |
|
|
warp_mode = WarpMode.SCALAR, lut = Lut.COLOR, |
46 |
|
|
cell_to_point = False, outline = True): |
47 |
|
|
""" |
48 |
|
|
Initialise the Carpet. |
49 |
|
|
|
50 |
|
|
@attention: The source can either be point or cell data. If the |
51 |
|
|
source is cell data, a conversion to point data may or may not be |
52 |
|
|
required, in order for the object to be rendered correctly. |
53 |
|
|
If a conversion is needed, the 'cell_to_point' flag must be set to |
54 |
jongui |
1199 |
'True', otherwise 'False' (which is the default). On occasions, an |
55 |
|
|
inaccurate object may be rendered from cell data even after conversion. |
56 |
ksteube |
1147 |
|
57 |
|
|
@type scene: L{Scene <scene.Scene>} object |
58 |
|
|
@param scene: Scene in which objects are to be rendered on |
59 |
|
|
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
60 |
|
|
object |
61 |
|
|
@param data_collector: Deal with source of data for visualisation |
62 |
|
|
@type viewport: L{Viewport <constant.Viewport>} constant |
63 |
|
|
@param viewport: Viewport in which objects are to be rendered on |
64 |
|
|
@param warp_mode: L{WarpMode <constant.WarpMode>} constant |
65 |
|
|
@type warp_mode: Mode in which to deform the scalar field |
66 |
|
|
@type lut : L{Lut <constant.Lut>} constant |
67 |
|
|
@param lut: Lookup table color scheme |
68 |
|
|
@type cell_to_point: Boolean |
69 |
|
|
@param cell_to_point: Converts cell data to point data (by averaging) |
70 |
|
|
@type outline: Boolean |
71 |
|
|
@param outline: Places an outline around the domain surface |
72 |
|
|
""" |
73 |
|
|
|
74 |
jongui |
1148 |
self.__data_collector = data_collector |
75 |
|
|
self.__viewport = viewport |
76 |
|
|
self.__warp_mode = warp_mode |
77 |
|
|
self.__lut = lut |
78 |
|
|
self.__cell_to_point = cell_to_point |
79 |
|
|
self.__outline = outline |
80 |
|
|
|
81 |
|
|
# Keeps track whether Carpet has been modified. |
82 |
|
|
self.__modified = True |
83 |
|
|
Transform.__init__(self) |
84 |
|
|
Plane.__init__(self) |
85 |
|
|
Cutter.__init__(self) |
86 |
|
|
Warp.__init__(self, self.__warp_mode) |
87 |
|
|
DataSetMapper.__init__(self) |
88 |
|
|
Actor3D.__init__(self) |
89 |
|
|
scene._addVisualizationModules(self) |
90 |
ksteube |
1147 |
|
91 |
|
|
# ----- Outline ----- |
92 |
|
|
|
93 |
jongui |
1148 |
# NOTE: Changes cannot be made to the Outline's properties from the |
94 |
|
|
# driver. |
95 |
|
|
if(self.__outline == True): |
96 |
|
|
outline = Outline(self.__data_collector._getDataCollectorOutput()) |
97 |
|
|
mapper = DataSetMapper() |
98 |
|
|
mapper._setupDataSetMapper(outline._getOutlineOutput()) |
99 |
ksteube |
1147 |
|
100 |
jongui |
1148 |
actor3D = Actor3D() |
101 |
|
|
actor3D._setupActor3D(mapper._getDataSetMapper()) |
102 |
ksteube |
1147 |
# Default outline color is black. |
103 |
jongui |
1148 |
actor3D.setColor(Color.BLACK) |
104 |
ksteube |
1147 |
|
105 |
|
|
# Default line width is 1. |
106 |
jongui |
1148 |
actor3D._setLineWidth(1) |
107 |
jongui |
1158 |
scene._addActor3D(self.__viewport, actor3D._getActor3D()) |
108 |
ksteube |
1147 |
|
109 |
|
|
# ----- Carpet ----- |
110 |
|
|
|
111 |
|
|
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
112 |
|
|
# before DataSetMapper. If it is done after DataSetMapper, no effect |
113 |
|
|
# will take place. |
114 |
jongui |
1148 |
if(self.__lut == Lut.COLOR): # Colored lookup table. |
115 |
ksteube |
1147 |
lookup_table = LookupTable() |
116 |
|
|
lookup_table._setTableValue() |
117 |
jongui |
1148 |
elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
118 |
ksteube |
1147 |
lookup_table = LookupTable() |
119 |
|
|
lookup_table._setLookupTableToGreyScale() |
120 |
|
|
|
121 |
jongui |
1148 |
self._setupPlane(self._getTransform()) |
122 |
ksteube |
1147 |
|
123 |
jongui |
1148 |
if(self.__cell_to_point == True): # Converts cell data to point data. |
124 |
|
|
c2p = CellDataToPointData(\ |
125 |
|
|
self.__data_collector._getDataCollectorOutput()) |
126 |
|
|
self._setupCutter(c2p._getCellToPointOutput(), self._getPlane()) |
127 |
|
|
elif(self.__cell_to_point == False): # No conversion happens. |
128 |
|
|
self._setupCutter(self.__data_collector._getDataCollectorOutput(), |
129 |
|
|
self._getPlane()) |
130 |
ksteube |
1147 |
|
131 |
jongui |
1148 |
self._setupWarp(self._getCutterOutput()) |
132 |
|
|
self._setupDataSetMapper(self._getWarpOutput(), |
133 |
ksteube |
1147 |
lookup_table._getLookupTable()) |
134 |
|
|
|
135 |
jongui |
1148 |
self._setupActor3D(self._getDataSetMapper()) |
136 |
jongui |
1158 |
scene._addActor3D(self.__viewport, self._getActor3D()) |
137 |
ksteube |
1147 |
|
138 |
jongui |
1148 |
def _isModified(self): |
139 |
|
|
""" |
140 |
|
|
Return whether the Carpet or DataCollector has been modified. |
141 |
ksteube |
1147 |
|
142 |
jongui |
1148 |
@rtype: Boolean |
143 |
|
|
@return: True or False |
144 |
|
|
""" |
145 |
|
|
|
146 |
|
|
return self.__modified or self.__data_collector._isModified() |
147 |
|
|
|
148 |
jongui |
1158 |
def _render(self, scene): |
149 |
jongui |
1148 |
""" |
150 |
|
|
Render the carpet. |
151 |
jongui |
1158 |
|
152 |
|
|
@type scene: L{Scene <scene.Scene>} object |
153 |
|
|
@param scene: Scene in which objects are to be rendered on |
154 |
jongui |
1148 |
""" |
155 |
|
|
|
156 |
|
|
if (self._isModified() == True): |
157 |
|
|
if(self.__data_collector._isScalarSet() == True): |
158 |
|
|
self.__data_collector._setActiveScalar() |
159 |
jongui |
1189 |
|
160 |
|
|
# self._isScalarRangeSet checks whether the scalar range has been |
161 |
|
|
# specified by the user. If it has, then the scalar range |
162 |
|
|
# read from the source will be ignored. |
163 |
|
|
if(not(self._isScalarRangeSet())): |
164 |
|
|
self._setScalarRange(self.__data_collector._getScalarRange()) |
165 |
jongui |
1148 |
self.__modified = False |
166 |
|
|
|
167 |
|
|
|