/[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 996 - (show annotations)
Mon Feb 26 03:43:13 2007 UTC (13 years, 9 months ago) by jongui
File MIME type: text/x-python
File size: 10362 byte(s)
Updated the drivers. Setting the active scalar/vector/tensor is now done in the DataCollector. i.e. 
dc = DataCollector(...)
dc.setFileName(...)
dc.setActiveScalar(...)

The use of setActiveScalar / setActiveVector / setActiveTensor have to be done after the setFileName.
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
11 from contourmodule import ContourModule
12
13 # NOTE: DataSetMapper, Actor3D and ContourModule were inherited to allow
14 # access to their public methods from the driver.
15 class Contour(DataSetMapper, Actor3D, ContourModule):
16 """
17 Class that shows a scalar field by contour surfaces.
18 """
19
20 # The SOUTH_WEST default viewport is used when there is only one viewport.
21 # This saves the user from specifying the viewport when there is only one.
22 # If no lut is specified, the color scheme will be used.
23 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
24 lut = Lut.COLOR, outline = True):
25 """
26 @type scene: L{Scene <scene.Scene>} object
27 @param scene: Scene in which objects are to be rendered on
28 @type data_collector: L{DataCollector <datacollector.DataCollector>}
29 object
30 @param data_collector: Deal with source of data for visualisation
31 @type viewport: L{Viewport <constant.Viewport>} constant
32 @param viewport: Viewport in which objects are to be rendered on
33 @type lut : L{Lut <constant.Lut>} constant
34 @param lut: Lookup table color scheme
35 @type outline: Boolean
36 @param outline: Places an outline around the domain surface
37 """
38
39 # NOTE: Actor3D is inherited and there are two instances declared here.
40 # As a result, when methods from Actor3D is invoked from the driver,
41 # only the methods associated with the latest instance (which in this
42 # case is the Actor3D for the contour) can be executed. Actor3D
43 # methods associated with Outline cannot be invoked from the driver.
44 # They can only be called within here, which is why Outline must
45 # be place before the contour as there is unlikely to be any changes
46 # made to the Outline's Actor3D.
47
48 # ----- Outline -----
49
50 if(outline == True):
51 outline = Outline(data_collector._getOutput())
52 DataSetMapper.__init__(self, outline._getOutput())
53
54 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
55 # Default outline color is black.
56 Actor3D.setColor(self, Color.BLACK)
57
58 # Default line width is 1.
59 Actor3D._setLineWidth(self, 1)
60 scene._addActor3D(viewport, Actor3D._getActor3D(self))
61
62 # ----- Contour -----
63
64 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
65 # before DataSetMapper. If it is done after DataSetMapper, no effect
66 # will take place.
67 if(lut == Lut.COLOR): # Colored lookup table.
68 lookup_table = LookupTable()
69 lookup_table._setTableValue()
70 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
71 lookup_table = LookupTable()
72 lookup_table._setLookupTableToGreyScale()
73
74
75 ContourModule.__init__(self, data_collector._getOutput())
76 # By default 10 contours are generated and the scalar range is based
77 # on the scalar data.
78 ContourModule.generateContours(self, 10,
79 data_collector._getScalarRange()[0],
80 data_collector._getScalarRange()[1])
81
82 DataSetMapper.__init__(self, ContourModule._getOutput(self),
83 lookup_table._getLookupTable())
84 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
85
86 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
87 scene._addActor3D(viewport, Actor3D._getActor3D(self))
88
89
90 ###############################################################################
91
92
93 from transform import Transform
94 from plane import Plane
95 from cutter import Cutter
96
97 # NOTE: DataSetMapper, Actor3D, ContourModule, Transform, Plane and Cutter were
98 # inherited to allow access to their public methods from the driver.
99 class ContourOnPlaneCut(DataSetMapper, Actor3D, ContourModule, Transform,
100 Plane, Cutter):
101 """
102 Class that show a scalar field contoured on a cut plane.
103 """
104
105 # The SOUTH_WEST default viewport is used when there is only one viewport.
106 # This saves the user from specifying the viewport when there is only one.
107 # If no lut is specified, the color scheme will be used.
108 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
109 lut = Lut.COLOR, outline = True):
110
111 """
112 @type scene: L{Scene <scene.Scene>} object
113 @param scene: Scene in which objects are to be rendered on
114 @type data_collector: L{DataCollector <datacollector.DataCollector>}
115 object
116 @param data_collector: Deal with source of data for visualisation
117 @type viewport: L{Viewport <constant.Viewport>} constant
118 @param viewport: Viewport in which objects are to be rendered on
119 @type lut : L{Lut <constant.Lut>} constant
120 @param lut: Lookup table color scheme
121 @type outline: Boolean
122 @param outline: Places an outline around the domain surface
123 """
124
125 # NOTE: Actor3D is inherited and there are two instances declared here.
126 # As a result, when methods from Actor3D is invoked from the driver,
127 # only the methods associated with the latest instance (which in this
128 # case is the Actor3D for the contour) can be executed. Actor3D
129 # methods associated with Outline cannot be invoked from the driver.
130 # They can only be called within here, which is why Outline must
131 # be place before the contour as there is unlikely to be any changes
132 # made to the Outline's Actor3D.
133
134 # ----- Outline -----
135
136 if(outline == True):
137 outline = Outline(data_collector._getOutput())
138 DataSetMapper.__init__(self, outline._getOutput())
139
140 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
141 # Default outline color is black.
142 Actor3D.setColor(self, Color.BLACK)
143
144 # Default line width is 1.
145 Actor3D._setLineWidth(self, 1)
146 scene._addActor3D(viewport, Actor3D._getActor3D(self))
147
148 # ----- Contour on a cut plane -----
149
150 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
151 # before DataSetMapper. If it is done after DataSetMapper, no effect
152 # will take place.
153 if(lut == Lut.COLOR): # Colored lookup table.
154 lookup_table = LookupTable()
155 lookup_table._setTableValue()
156 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
157 lookup_table = LookupTable()
158 lookup_table._setLookupTableToGreyScale()
159
160 Transform.__init__(self)
161 Plane.__init__(self, Transform._getTransform(self))
162
163 Cutter.__init__(self, data_collector._getOutput(),
164 Plane._getPlane(self))
165 ContourModule.__init__(self, Cutter._getOutput(self))
166
167 # By default 10 contours are generated and the scalar range is based
168 # on the scalar data.
169 ContourModule.generateContours(self, 10,
170 data_collector._getScalarRange()[0],
171 data_collector._getScalarRange()[1])
172
173 DataSetMapper.__init__(self, ContourModule._getOutput(self),
174 lookup_table._getLookupTable())
175 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
176
177 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
178 scene._addActor3D(viewport, Actor3D._getActor3D(self))
179
180
181 ###############################################################################
182
183
184 from clipper import Clipper
185
186 # NOTE: DataSetMapper, Actor3D, ContourModule, Transform, Plane and Clipper
187 # were inherited to allow access to their public methods from the driver.
188 class ContourOnPlaneClip(DataSetMapper, Actor3D, ContourModule, Transform,
189 Plane, Clipper):
190 """
191 Class that show a scalar field contoured on a clipped plane.
192 """
193
194 # The SOUTH_WEST default viewport is used when there is only one viewport.
195 # This saves the user from specifying the viewport when there is only one.
196 # If no lut is specified, the color scheme will be used.
197 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
198 lut = Lut.COLOR, outline = True):
199
200 """
201 @type scene: L{Scene <scene.Scene>} object
202 @param scene: Scene in which objects are to be rendered on
203 @type data_collector: L{DataCollector <datacollector.DataCollector>}
204 object
205 @param data_collector: Deal with source of data for visualisation
206 @type viewport: L{Viewport <constant.Viewport>} constant
207 @param viewport: Viewport in which objects are to be rendered on
208 @type lut : L{Lut <constant.Lut>} constant
209 @param lut: Lookup table color scheme
210 @type outline: Boolean
211 @param outline: Places an outline around the domain surface
212 """
213
214 # NOTE: Actor3D is inherited and there are two instances declared here.
215 # As a result, when methods from Actor3D is invoked from the driver,
216 # only the methods associated with the latest instance (which in this
217 # case is the Actor3D for the contour) can be executed. Actor3D
218 # methods associated with Outline cannot be invoked from the driver.
219 # They can only be called within here, which is why Outline must
220 # be place before the contour as there is unlikely to be any changes
221 # made to the Outline's Actor3D.
222
223 # ----- Outline -----
224
225 if(outline == True):
226 outline = Outline(data_collector._getOutput())
227 DataSetMapper.__init__(self, outline._getOutput())
228
229 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
230 # Default outline color is black.
231 Actor3D.setColor(self, Color.BLACK)
232
233 # Default line width is 1.
234 Actor3D._setLineWidth(self, 1)
235 scene._addActor3D(viewport, Actor3D._getActor3D(self))
236
237 # ----- Contour on a clipped plane -----
238
239 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
240 # before DataSetMapper. If it is done after DataSetMapper, no effect
241 # will take place.
242 if(lut == Lut.COLOR): # Colored lookup table.
243 lookup_table = LookupTable()
244 lookup_table._setTableValue()
245 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
246 lookup_table = LookupTable()
247 lookup_table._setLookupTableToGreyScale()
248
249 Transform.__init__(self)
250 Plane.__init__(self, Transform._getTransform(self))
251
252 Clipper.__init__(self, data_collector._getOutput(),
253 Plane._getPlane(self))
254 Clipper._setClipFunction(self)
255
256 ContourModule.__init__(self, Clipper._getOutput(self))
257 # By default 10 contours are generated and the scalar range is based
258 # on the scalar data.
259 ContourModule.generateContours(self, 10,
260 data_collector._getScalarRange()[0],
261 data_collector._getScalarRange()[1])
262
263 DataSetMapper.__init__(self, ContourModule._getOutput(self),
264 lookup_table._getLookupTable())
265 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
266
267 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
268 scene._addActor3D(viewport, Actor3D._getActor3D(self))
269

  ViewVC Help
Powered by ViewVC 1.1.26