/[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 1029 - (show annotations)
Wed Mar 14 05:01:13 2007 UTC (12 years, 5 months ago) by jongui
File MIME type: text/x-python
File size: 11293 byte(s)
Fixed problems in relation to updates propagating when multiple files/sources are read.
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
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 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
95 scene._addActor3D(viewport, Actor3D._getActor3D(self))
96
97
98 ###############################################################################
99
100
101 from transform import Transform
102 from plane import Plane
103 from cutter import Cutter
104
105 # NOTE: DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph, Transform, Plane,
106 # Cutter, StructuredPoints and Probe were inherited to allow access to
107 # their public methods from the driver.
108 class EllipsoidOnPlaneCut(DataSetMapper, Actor3D, Sphere, Normals,
109 TensorGlyph, Transform, Plane, Cutter, StructuredPoints, Probe):
110 """
111 This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
112 except that it shows a tensor field using ellipsoids cut using a plane.
113 """
114
115 # The SOUTH_WEST default viewport is used when there is only one viewport.
116 # This saves the user from specifying the viewport when there is only one.
117 # If no lut is specified, the color scheme will be used.
118 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
119 lut = Lut.COLOR, outline = True):
120 """
121 @type scene: L{Scene <scene.Scene>} object
122 @param scene: Scene in which objects are to be rendered on
123 @type data_collector: L{DataCollector <datacollector.DataCollector>}
124 object
125 @param data_collector: Deal with source of data for visualisation
126 @type viewport: L{Viewport <constant.Viewport>} constant
127 @param viewport: Viewport in which objects are to be rendered on
128 @type lut : L{Lut <constant.Lut>} constant
129 @param lut: Lookup table color scheme
130 @type outline: Boolean
131 @param outline: Places an outline around the domain surface
132 """
133
134 # NOTE: Actor3D is inherited and there are two instances declared here.
135 # As a result, when methods from Actor3D is invoked from the driver,
136 # only the methods associated with the latest instance (which in this
137 # case is the Actor3D for the Ellipsoid) can be executed. Actor3D
138 # methods associated with Outline cannot be invoked from the driver.
139 # They can only be called within here, which is why Outline must be
140 # place before Ellipsoid as there is unlikely to be any changes
141 # made to the Outline's Actor3D.
142
143 # ----- Outline -----
144
145 if(outline == True):
146 outline = Outline(data_collector._getOutput())
147 DataSetMapper.__init__(self, outline._getOutput())
148
149 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
150 # Default outline color is black.
151 Actor3D.setColor(self, Color.BLACK)
152
153 # Default line width is 1.
154 Actor3D._setLineWidth(self, 1)
155 scene._addActor3D(viewport, Actor3D._getActor3D(self))
156
157 # ----- Ellipsoid on a cut plane -----
158
159 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
160 # before DataSetMapper. If it is done after DataSetMapper, no effect
161 # will take place.
162 if(lut == Lut.COLOR): # Colored lookup table.
163 lookup_table = LookupTable()
164 lookup_table._setTableValue()
165 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
166 lookup_table = LookupTable()
167 lookup_table._setLookupTableToGreyScale()
168
169 Transform.__init__(self)
170 Plane.__init__(self, Transform._getTransform(self))
171
172 StructuredPoints.__init__(self, data_collector._getOutput())
173 Probe.__init__(self, data_collector._getOutput(),
174 StructuredPoints._getStructuredPoints(self))
175
176 Cutter.__init__(self, Probe._getOutput(self),
177 Plane._getPlane(self))
178 Sphere.__init__(self)
179
180 TensorGlyph.__init__(self, Cutter._getOutput(self),
181 Sphere._getOutput(self))
182 Normals.__init__(self, TensorGlyph._getOutput(self))
183
184 DataSetMapper.__init__(self, Normals._getOutput(self),
185 lookup_table._getLookupTable())
186 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
187
188 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
189 scene._addActor3D(viewport, Actor3D._getActor3D(self))
190
191
192 ###############################################################################
193
194
195 from clipper import Clipper
196
197 # NOTE: DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph, Transform, Plane,
198 # Clipper, StructuredPoints and Probe were inherited to allow access to
199 # their public methods from the driver.
200 class EllipsoidOnPlaneClip(DataSetMapper, Actor3D, Sphere, Normals,
201 TensorGlyph, Transform, Plane, Clipper, StructuredPoints, Probe):
202 """
203 This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>},
204 except that it shows a tensor field using ellipsoids clipped using a plane.
205 """
206
207 # The SOUTH_WEST default viewport is used when there is only one viewport.
208 # This saves the user from specifying the viewport when there is only one.
209 # If no lut is specified, the color scheme will be used.
210 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
211 lut = Lut.COLOR, outline = True):
212 """
213 @type scene: L{Scene <scene.Scene>} object
214 @param scene: Scene in which objects are to be rendered on
215 @type data_collector: L{DataCollector <datacollector.DataCollector>}
216 object
217 @param data_collector: Deal with source of data for visualisation
218 @type viewport: L{Viewport <constant.Viewport>} constant
219 @param viewport: Viewport in which object are to be rendered on
220 @type lut : L{Lut <constant.Lut>} constant
221 @param lut: Lookup table color scheme
222 @type outline: Boolean
223 @param outline: Places an outline around the domain surface
224 """
225
226 # NOTE: Actor3D is inherited and there are two instances declared here.
227 # As a result, when methods from Actor3D is invoked from the driver,
228 # only the methods associated with the latest instance (which in this
229 # case is the Actor3D for the Ellipsoid) can be executed. Actor3D
230 # methods associated with Outline cannot be invoked from the driver.
231 # They can only be called within here, which is why Outline must be
232 # place before Ellipsoid as there is unlikely to be any changes
233 # made to the Outline's Actor3D.
234
235 # ----- Outline -----
236
237 if(outline == True):
238 outline = Outline(data_collector._getOutput())
239 DataSetMapper.__init__(self, outline._getOutput())
240
241 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
242 # Default outline color is black.
243 Actor3D.setColor(self, Color.BLACK)
244
245 # Default line width is 1.
246 Actor3D._setLineWidth(self, 1)
247 scene._addActor3D(viewport, Actor3D._getActor3D(self))
248
249 # ----- Ellipsoid on a clipped plane -----
250
251 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
252 # before DataSetMapper. If it is done after DataSetMapper, no effect
253 # will take place.
254 if(lut == Lut.COLOR): # Colored lookup table.
255 lookup_table = LookupTable()
256 lookup_table._setTableValue()
257 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
258 lookup_table = LookupTable()
259 lookup_table._setLookupTableToGreyScale()
260
261 Transform.__init__(self)
262 Plane.__init__(self, Transform._getTransform(self))
263
264 StructuredPoints.__init__(self, data_collector._getOutput())
265 Probe.__init__(self, data_collector._getOutput(),
266 StructuredPoints._getStructuredPoints(self))
267
268 # NOTE: TensorGlyph must come before Clipper. Otherwise the output
269 # will be incorrect.
270 Sphere.__init__(self)
271 TensorGlyph.__init__(self, Probe._getOutput(self),
272 Sphere._getOutput(self))
273
274 Normals.__init__(self, TensorGlyph._getOutput(self))
275 # NOTE: Clipper must come after TensorGlyph. Otherwise the output
276 # will be incorrect.
277 Clipper.__init__(self, Normals._getOutput(self),
278 Plane._getPlane(self))
279 Clipper._setClipFunction(self)
280
281 DataSetMapper.__init__(self, Clipper._getOutput(self),
282 lookup_table._getLookupTable())
283 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
284
285 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
286 scene._addActor3D(viewport, Actor3D._getActor3D(self))
287

  ViewVC Help
Powered by ViewVC 1.1.26