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

  ViewVC Help
Powered by ViewVC 1.1.26