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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1043 - (hide annotations)
Mon Mar 19 06:46:34 2007 UTC (13 years, 6 months ago) by jongui
File MIME type: text/x-python
File size: 11706 byte(s)
Map and Contour now able to display cell data correctly. At this stage, it appears that the probe filter cannot be applied on cell data as a segmentation fault will be thrown.
1 jongui 1037 """
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 jongui 1043 data_collector._paramForUpdatingMultipleSources(VizType.ELLIPSOID,
192     ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))
193    
194 jongui 1037 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
195     scene._addActor3D(viewport, Actor3D._getActor3D(self))
196    
197    
198     ###############################################################################
199    
200    
201     from clipper import Clipper
202    
203     # NOTE: DataSetMapper, Actor3D, Sphere, Normals, TensorGlyph, Transform, Plane,
204     # Clipper, StructuredPoints and Probe were inherited to allow access to
205     # their public methods from the driver.
206     class EllipsoidOnPlaneClip(DataSetMapper, Actor3D, Sphere, Normals,
207     TensorGlyph, Transform, Plane, Clipper, StructuredPoints, Probe):
208     """
209     This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>},
210     except that it shows a tensor field using ellipsoids clipped using a plane.
211     """
212    
213     # The SOUTH_WEST default viewport is used when there is only one viewport.
214     # This saves the user from specifying the viewport when there is only one.
215     # If no lut is specified, the color scheme will be used.
216     def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
217     lut = Lut.COLOR, outline = True):
218     """
219     @type scene: L{Scene <scene.Scene>} object
220     @param scene: Scene in which objects are to be rendered on
221     @type data_collector: L{DataCollector <datacollector.DataCollector>}
222     object
223     @param data_collector: Deal with source of data for visualisation
224     @type viewport: L{Viewport <constant.Viewport>} constant
225     @param viewport: Viewport in which object are to be rendered on
226     @type lut : L{Lut <constant.Lut>} constant
227     @param lut: Lookup table color scheme
228     @type outline: Boolean
229     @param outline: Places an outline around the domain surface
230     """
231    
232     # NOTE: Actor3D is inherited and there are two instances declared here.
233     # As a result, when methods from Actor3D is invoked from the driver,
234     # only the methods associated with the latest instance (which in this
235     # case is the Actor3D for the Ellipsoid) can be executed. Actor3D
236     # methods associated with Outline cannot be invoked from the driver.
237     # They can only be called within here, which is why Outline must be
238     # place before Ellipsoid as there is unlikely to be any changes
239     # made to the Outline's Actor3D.
240    
241     # ----- Outline -----
242    
243     if(outline == True):
244     outline = Outline(data_collector._getOutput())
245     DataSetMapper.__init__(self, outline._getOutput())
246    
247     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
248     # Default outline color is black.
249     Actor3D.setColor(self, Color.BLACK)
250    
251     # Default line width is 1.
252     Actor3D._setLineWidth(self, 1)
253     scene._addActor3D(viewport, Actor3D._getActor3D(self))
254    
255     # ----- Ellipsoid on a clipped plane -----
256    
257     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
258     # before DataSetMapper. If it is done after DataSetMapper, no effect
259     # will take place.
260     if(lut == Lut.COLOR): # Colored lookup table.
261     lookup_table = LookupTable()
262     lookup_table._setTableValue()
263     elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
264     lookup_table = LookupTable()
265     lookup_table._setLookupTableToGreyScale()
266    
267     Transform.__init__(self)
268     Plane.__init__(self, Transform._getTransform(self))
269    
270     StructuredPoints.__init__(self, data_collector._getOutput())
271     Probe.__init__(self, data_collector._getOutput(),
272     StructuredPoints._getStructuredPoints(self))
273    
274     # NOTE: TensorGlyph must come before Clipper. Otherwise the output
275     # will be incorrect.
276     Sphere.__init__(self)
277     TensorGlyph.__init__(self, Probe._getOutput(self),
278     Sphere._getOutput(self))
279    
280     Normals.__init__(self, TensorGlyph._getOutput(self))
281     # NOTE: Clipper must come after TensorGlyph. Otherwise the output
282     # will be incorrect.
283     Clipper.__init__(self, Normals._getOutput(self),
284     Plane._getPlane(self))
285     Clipper._setClipFunction(self)
286    
287     DataSetMapper.__init__(self, Clipper._getOutput(self),
288     lookup_table._getLookupTable())
289     DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
290    
291 jongui 1043 data_collector._paramForUpdatingMultipleSources(VizType.ELLIPSOID,
292     ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))
293    
294 jongui 1037 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
295     scene._addActor3D(viewport, Actor3D._getActor3D(self))
296    

  ViewVC Help
Powered by ViewVC 1.1.26