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

  ViewVC Help
Powered by ViewVC 1.1.26