/[escript]/trunk/pyvisi/py_src/ellipsoid.py
ViewVC logotype

Contents of /trunk/pyvisi/py_src/ellipsoid.py

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26