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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 978 - (hide annotations)
Fri Feb 16 07:02:18 2007 UTC (13 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 13578 byte(s)
Corrected some minor bugs. However, another bug was discover in relation to specifying the active scalar/vector/tensor. At this stage it appears that with one XML Reader, only one active scalar can be specified. If more than one is specified with only one XML reader, the rendered objects maybe incorrect. However, more test on this problem is required/
1 jongui 943 """
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
11    
12     # NOTE: DataSetMapper and Actor3D were inherited to allow access to their
13     # public methods from the driver.
14     class Map(DataSetMapper, Actor3D):
15     """
16 jongui 948 Class that shows a scalar field on a domain surface.
17 jongui 943 """
18    
19     # The SOUTH_WEST default viewport is used when there is only one viewport.
20     # This saves the user from specifying the viewport when there is only one.
21     # If no scalar field is specified, the first encountered in the file will
22 jongui 948 # be loaded automatically. If no lut is specified, the color scheme will
23     # be used.
24 jongui 943 def __init__(self, scene, data_collector, scalar = None,
25     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
26     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 scalar: String
34     @param scalar: Scalar field to load from the source file
35     @type viewport: L{Viewport <constant.Viewport>} constant
36 jongui 948 @param viewport: Viewport in which objects are to be rendered on
37 jongui 943 @type lut : L{Lut <constant.Lut>} constant
38     @param lut: Lookup table color scheme
39     @type outline: Boolean
40     @param outline: Places an outline around the domain surface
41     """
42    
43     # NOTE: Actor3D is inherited and there are two instances declared here.
44     # As a result, when methods from Actor3D is invoked from the driver,
45     # only the methods associated with the latest instance (which in this
46 jongui 948 # case is the Actor3D for the map) can be executed. Actor3D
47 jongui 943 # methods associated with Outline cannot be invoked from the driver.
48     # They can only be called within here, which is why Outline must
49 jongui 948 # be place before map as there is unlikely to be any changes
50 jongui 943 # made to the Outline's Actor3D.
51    
52     # ----- Outline -----
53    
54     if(outline == True):
55     outline = Outline(data_collector._getOutput())
56     DataSetMapper.__init__(self, outline._getOutput())
57    
58     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
59     # Default outline color is black.
60     Actor3D.setColor(self, Color.BLACK)
61 jongui 948
62 jongui 943 # Default line width is 1.
63     Actor3D._setLineWidth(self, 1)
64     scene._addActor3D(viewport, Actor3D._getActor3D(self))
65    
66 jongui 948 # ----- Map -----
67 jongui 943
68     if(scalar != None): # True only if a scalar field was specified.
69     data_collector._setActiveScalar(scalar)
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 jongui 978 #print ("dir ", dir(lookup_table))
81 jongui 943
82     DataSetMapper.__init__(self, data_collector._getOutput(),
83     lookup_table._getLookupTable())
84     DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
85 jongui 978 #print("range ", data_collector._getScalarRange())
86 jongui 943
87     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
88     scene._addActor3D(viewport, Actor3D._getActor3D(self))
89    
90    
91 jongui 948 ###############################################################################
92 jongui 943
93 jongui 948
94 jongui 943 from transform import Transform
95     from plane import Plane
96     from cutter import Cutter
97    
98     # NOTE: DataSetMapper, Actor3D, Transform, Plane and Cutter were inherited
99     # to allow access to their public methods from the driver.
100     class MapOnPlaneCut(DataSetMapper, Actor3D, Transform, Plane, Cutter):
101     """
102 jongui 948 Class that show a scalar field on a plane.
103 jongui 943 """
104    
105     # The SOUTH_WEST default viewport is used when there is only one viewport.
106     # This saves the user from specifying the viewport when there is only one.
107     # If no scalar field is specified, the first encountered in the file will
108 jongui 948 # be loaded automatically. If no lut is specified, the color scheme will
109     # be used.
110 jongui 943 def __init__(self, scene, data_collector, scalar = None,
111     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
112    
113     """
114     @type scene: L{Scene <scene.Scene>} object
115     @param scene: Scene in which objects are to be rendered on
116     @type data_collector: L{DataCollector <datacollector.DataCollector>}
117     object
118     @param data_collector: Deal with source of data for visualisation
119     @type scalar: String
120     @param scalar: Scalar field to load from the source file
121     @type viewport: L{Viewport <constant.Viewport>} constant
122 jongui 948 @param viewport: Viewport in which objects are to be rendered on
123 jongui 943 @type lut : L{Lut <constant.Lut>} constant
124     @param lut: Lookup table color scheme
125     @type outline: Boolean
126     @param outline: Places an outline around the domain surface
127     """
128    
129     # NOTE: Actor3D is inherited and there are two instances declared here.
130     # As a result, when methods from Actor3D is invoked from the driver,
131     # only the methods associated with the latest instance (which in this
132     # case is the Actor3D for the map) can be executed. Actor3D
133     # methods associated with Outline cannot be invoked from the driver.
134     # They can only be called within here, which is why Outline must
135     # be place before the map as there is unlikely to be any changes
136     # made to the Outline's Actor3D.
137    
138     # ----- Outline -----
139    
140     if(outline == True):
141     outline = Outline(data_collector._getOutput())
142     DataSetMapper.__init__(self, outline._getOutput())
143    
144     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
145     # Default outline color is black.
146     Actor3D.setColor(self, Color.BLACK)
147     # Default line width is 1.
148 jongui 948
149 jongui 943 Actor3D._setLineWidth(self, 1)
150     scene._addActor3D(viewport, Actor3D._getActor3D(self))
151    
152     # ----- Map on a plane -----
153    
154     if(scalar != None):
155     data_collector._setActiveScalar(scalar)
156    
157     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
158     # before DataSetMapper. If it is done after DataSetMapper, no effect
159     # will take place.
160     if(lut == Lut.COLOR): # Colored lookup table.
161     lookup_table = LookupTable()
162     lookup_table._setTableValue()
163     elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
164     lookup_table = LookupTable()
165     lookup_table._setLookupTableToGreyScale()
166    
167     Transform.__init__(self)
168     Plane.__init__(self, Transform._getTransform(self))
169    
170     Cutter.__init__(self, data_collector._getOutput(),
171     Plane._getPlane(self))
172    
173     DataSetMapper.__init__(self, Cutter._getOutput(self),
174     lookup_table._getLookupTable())
175     DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
176    
177     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
178     scene._addActor3D(viewport, Actor3D._getActor3D(self))
179    
180    
181     ###########################################################################
182    
183    
184     from clipper import Clipper
185    
186     # NOTE: DataSetMapper, Actor3D, Transform, Plane and Clipper were inherited
187     # to allow access to their public methods from the driver.
188     class MapOnPlaneClip(DataSetMapper, Actor3D, Transform, Plane, Clipper):
189     """
190 jongui 961 Class that show a scalar field on a clipped plane.
191 jongui 943 """
192    
193     # The SOUTH_WEST default viewport is used when there is only one viewport.
194     # This saves the user from specifying the viewport when there is only one.
195     # If no scalar field is specified, the first encountered in the file will
196 jongui 948 # be loaded automatically. If no lut is specified, the color scheme will
197     # be used.
198 jongui 943 def __init__(self, scene, data_collector, scalar = None,
199     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
200    
201     """
202     @type scene: L{Scene <scene.Scene>} object
203     @param scene: Scene in which objects are to be rendered on
204     @type data_collector: L{DataCollector <datacollector.DataCollector>}
205     object
206     @param data_collector: Deal with source of data for visualisation
207     @type scalar: String
208     @param scalar: Scalar field to load from the source file
209     @type viewport: L{Viewport <constant.Viewport>} constant
210 jongui 948 @param viewport: Viewport in which objects are to be rendered on
211 jongui 943 @type lut : L{Lut <constant.Lut>} constant
212     @param lut: Lookup table color scheme
213     @type outline: Boolean
214     @param outline: Places an outline around the domain surface
215     """
216    
217     # NOTE: Actor3D is inherited and there are two instances declared here.
218     # As a result, when methods from Actor3D is invoked from the driver,
219     # only the methods associated with the latest instance (which in this
220     # case is the Actor3D for the map) can be executed. Actor3D
221     # methods associated with Outline cannot be invoked from the driver.
222     # They can only be called within here, which is why Outline must
223     # be place before the map as there is unlikely to be any changes
224     # made to the Outline's Actor3D.
225    
226     # ----- Outline -----
227    
228     if(outline == True):
229     outline = Outline(data_collector._getOutput())
230     DataSetMapper.__init__(self, outline._getOutput())
231    
232     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
233     # Default outline color is black.
234     Actor3D.setColor(self, Color.BLACK)
235 jongui 948
236 jongui 943 # Default line width is 1.
237     Actor3D._setLineWidth(self, 1)
238     scene._addActor3D(viewport, Actor3D._getActor3D(self))
239    
240     # ----- Map on a clipped plane -----
241    
242     if(scalar != None):
243     data_collector._setActiveScalar(scalar)
244    
245     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
246     # before DataSetMapper. If it is done after DataSetMapper, no effect
247     # will take place.
248     if(lut == Lut.COLOR): # Colored lookup table.
249     lookup_table = LookupTable()
250     lookup_table._setTableValue()
251     elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
252     lookup_table = LookupTable()
253     lookup_table._setLookupTableToGreyScale()
254    
255     Transform.__init__(self)
256     Plane.__init__(self, Transform._getTransform(self))
257    
258     Clipper.__init__(self, data_collector._getOutput(),
259     Plane._getPlane(self))
260     Clipper._setClipFunction(self)
261    
262     DataSetMapper.__init__(self, Clipper._getOutput(self),
263     lookup_table._getLookupTable())
264     DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
265    
266     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
267     scene._addActor3D(viewport, Actor3D._getActor3D(self))
268    
269    
270     #############################################################################
271    
272    
273     # NOTE: DataSetMapper, Actor3D and Clipper were inherited
274     # to allow access to their public methods from the driver.
275     class MapOnScalarClip(DataSetMapper, Actor3D, Clipper):
276     """
277     Class that show a scalar field clipped using a scalar value.
278     """
279    
280     # The SOUTH_WEST default viewport is used when there is only one viewport.
281     # This saves the user from specifying the viewport when there is only one.
282     # If no scalar field is specified, the first encountered in the file will
283 jongui 948 # be loaded automatically. If no lut is specified, the color scheme will
284     # be used.
285    
286 jongui 943 def __init__(self, scene, data_collector, scalar = None,
287     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
288    
289     """
290     @type scene: L{Scene <scene.Scene>} object
291     @param scene: Scene in which objects are to be rendered on
292     @type data_collector: L{DataCollector <datacollector.DataCollector>}
293     object
294     @param data_collector: Deal with source of data for visualisation
295     @type scalar: String
296     @param scalar: Scalar field to load from the source file
297     @type viewport: L{Viewport <constant.Viewport>} constant
298 jongui 948 @param viewport: Viewport in which objects are to be rendered on
299 jongui 943 @type lut : L{Lut <constant.Lut>} constant
300     @param lut: Lookup table color scheme
301     @type outline: Boolean
302     @param outline: Places an outline around the domain surface
303     """
304    
305     # NOTE: Actor3D is inherited and there are two instances declared here.
306     # As a result, when methods from Actor3D is invoked from the driver,
307     # only the methods associated with the latest instance (which in this
308     # case is the Actor3D for the map) can be executed. Actor3D
309     # methods associated with Outline cannot be invoked from the driver.
310     # They can only be called within here, which is why Outline must
311     # be place before the map as there is unlikely to be any changes
312     # made to the Outline's Actor3D.
313    
314     # ----- Outline -----
315    
316     if(outline == True):
317     outline = Outline(data_collector._getOutput())
318     DataSetMapper.__init__(self, outline._getOutput())
319    
320     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
321     # Default outline color is black.
322     Actor3D.setColor(self, Color.BLACK)
323 jongui 948
324 jongui 943 # Default line width is 1.
325     Actor3D._setLineWidth(self, 1)
326     scene._addActor3D(viewport, Actor3D._getActor3D(self))
327    
328     # ----- Map clipped using a scalar value -----
329    
330     if(scalar != None):
331     data_collector._setActiveScalar(scalar)
332    
333     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
334     # before DataSetMapper. If it is done after DataSetMapper, no effect
335     # will take place.
336     if(lut == Lut.COLOR): # Colored lookup table.
337     lookup_table = LookupTable()
338     lookup_table._setTableValue()
339     elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
340     lookup_table = LookupTable()
341     lookup_table._setLookupTableToGreyScale()
342    
343 jongui 948 # None is used because a plane is not required when a scalar value is
344 jongui 947 # used to perform the clipping.
345     Clipper.__init__(self, data_collector._getOutput(), None)
346 jongui 943
347     DataSetMapper.__init__(self, Clipper._getOutput(self),
348     lookup_table._getLookupTable())
349     DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
350    
351     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
352     scene._addActor3D(viewport, Actor3D._getActor3D(self))
353    
354    

  ViewVC Help
Powered by ViewVC 1.1.26