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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 943 - (hide annotations)
Mon Jan 29 07:22:43 2007 UTC (13 years, 8 months ago) by jongui
File MIME type: text/x-python
File size: 11237 byte(s)
new pyvisi files
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     from contourmodule import ContourModule
12    
13    
14     # NOTE: DataSetMapper, Actor3D and Contour were inherited to allow access to
15     # their public methods from the driver.
16    
17     class Contour(DataSetMapper, Actor3D, ContourModule):
18     """
19     Class that shows a scalar field by contour surfaces.
20     """
21    
22     # The SOUTH_WEST default viewport is used when there is only one viewport.
23     # This saves the user from specifying the viewport when there is only one.
24     # If no scalar field is specified, the first encountered in the file will
25     # be loaded automatically.
26     def __init__(self, scene, data_collector, scalar = None,
27     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
28     """
29     @type scene: L{Scene <scene.Scene>} object
30     @param scene: Scene in which objects are to be rendered on
31     @type data_collector: L{DataCollector <datacollector.DataCollector>}
32     object
33     @param data_collector: Deal with source of data for visualisation
34     @type scalar: String
35     @param scalar: Scalar field to load from the source file
36     @type viewport: L{Viewport <constant.Viewport>} constant
37     @param viewport: Viewport in which the object is to be rendered on
38     @type lut : L{Lut <constant.Lut>} constant
39     @param lut: Lookup table color scheme
40     @type outline: Boolean
41     @param outline: Places an outline around the domain surface
42     """
43    
44     # NOTE: Actor3D is inherited and there are two instances declared here.
45     # As a result, when methods from Actor3D is invoked from the driver,
46     # only the methods associated with the latest instance (which in this
47     # case is the Actor3D for the contour) can be executed. Actor3D
48     # methods associated with Outline cannot be invoked from the driver.
49     # They can only be called within here, which is why Outline must
50     # be place before the contour as there is unlikely to be any changes
51     # made to the Outline's Actor3D.
52    
53     # ----- Outline -----
54    
55     if(outline == True):
56     outline = Outline(data_collector._getOutput())
57     DataSetMapper.__init__(self, outline._getOutput())
58    
59     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
60     # Default outline color is black.
61     Actor3D.setColor(self, Color.BLACK)
62     # Default line width is 1.
63     Actor3D._setLineWidth(self, 1)
64     scene._addActor3D(viewport, Actor3D._getActor3D(self))
65    
66    
67     # ----- contour -----
68    
69     if(scalar != None): # True only if a scalar field was specified.
70     data_collector._setActiveScalar(scalar)
71    
72     lookup_table = LookupTable()
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    
85     ContourModule.__init__(self, data_collector._getOutput())
86     # By default 10 contours are generated and the scalar range is based
87     # on the scalar data.
88     ContourModule.generateContours(self, 10, data_collector._getScalarRange()[0],
89     data_collector._getScalarRange()[1])
90    
91     DataSetMapper.__init__(self, ContourModule._getOutput(self),
92     lookup_table._getLookupTable())
93    
94     DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
95    
96     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
97     scene._addActor3D(viewport, Actor3D._getActor3D(self))
98    
99    
100     from transform import Transform
101     from plane import Plane
102     from cutter import Cutter
103    
104     # NOTE: DataSetMapper, Actor3D, Contour, Transform, Plane and Cutter were
105     # inherited to allow access to their public methods from the driver.
106     class ContourOnPlaneCut(DataSetMapper, Actor3D, ContourModule, Transform, Plane, Cutter):
107     """
108     Class that show a scalar field contoured on a plane.
109     """
110    
111     # The SOUTH_WEST default viewport is used when there is only one viewport.
112     # This saves the user from specifying the viewport when there is only one.
113     # If no scalar field is specified, the first encountered in the file will
114     # be loaded automatically.
115     def __init__(self, scene, data_collector, scalar = None,
116     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
117    
118     """
119     @type scene: L{Scene <scene.Scene>} object
120     @param scene: Scene in which objects are to be rendered on
121     @type data_collector: L{DataCollector <datacollector.DataCollector>}
122     object
123     @param data_collector: Deal with source of data for visualisation
124     @type scalar: String
125     @param scalar: Scalar field to load from the source file
126     @type viewport: L{Viewport <constant.Viewport>} constant
127     @param viewport: Viewport in which the object is 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 contour) 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
140     # be place before the contour 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(Glyph3D._getOutput(self))
147     outline = Outline(data_collector._getOutput())
148     DataSetMapper.__init__(self, outline._getOutput())
149    
150     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
151     # Default outline color is black.
152     Actor3D.setColor(self, Color.BLACK)
153     # Default line width is 1.
154     Actor3D._setLineWidth(self, 1)
155     scene._addActor3D(viewport, Actor3D._getActor3D(self))
156    
157    
158     # ----- contour on a plane -----
159    
160     if(scalar != None):
161     data_collector._setActiveScalar(scalar)
162    
163     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
164     # before DataSetMapper. If it is done after DataSetMapper, no effect
165     # will take place.
166     if(lut == Lut.COLOR): # Colored lookup table.
167     lookup_table = LookupTable()
168     lookup_table._setTableValue()
169     elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
170     lookup_table = LookupTable()
171     lookup_table._setLookupTableToGreyScale()
172    
173     """
174     Contour.__init__(self, data_collector._getOutput())
175     # By default 10 contours are generated and the scalar range is based
176     # on the scalar data.
177     Contour.generateContours(self, 10, data_collector._getScalarRange()[0],
178     data_collector._getScalarRange()[1])
179     """
180     Transform.__init__(self)
181     Plane.__init__(self, Transform._getTransform(self))
182    
183     Cutter.__init__(self, data_collector._getOutput(),
184     Plane._getPlane(self))
185    
186     ContourModule.__init__(self, Cutter._getOutput(self))
187     # By default 10 contours are generated and the scalar range is based
188     # on the scalar data.
189     ContourModule.generateContours(self, 10, data_collector._getScalarRange()[0],
190     data_collector._getScalarRange()[1])
191    
192     DataSetMapper.__init__(self, ContourModule._getOutput(self),
193     lookup_table._getLookupTable())
194    
195     DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
196    
197     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
198     scene._addActor3D(viewport, Actor3D._getActor3D(self))
199    
200     from clipper import Clipper
201    
202     # NOTE: DataSetMapper, Actor3D, Contour, Transform, Plane and Clipper were
203     # inherited to allow access to their public methods from the driver.
204     class ContourOnPlaneClip(DataSetMapper, Actor3D, ContourModule, Transform,
205     Plane, Clipper):
206     """
207     Class that show a scalar field contoured on a clipped 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 scalar field is specified, the first encountered in the file will
213     # be loaded automatically.
214     def __init__(self, scene, data_collector, scalar = None,
215     viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
216    
217     """
218     @type scene: L{Scene <scene.Scene>} object
219     @param scene: Scene in which objects are to be rendered on
220     @type data_collector: L{DataCollector <datacollector.DataCollector>}
221     object
222     @param data_collector: Deal with source of data for visualisation
223     @type scalar: String
224     @param scalar: Scalar field to load from the source file
225     @type viewport: L{Viewport <constant.Viewport>} constant
226     @param viewport: Viewport in which the object is to be rendered on
227     @type lut : L{Lut <constant.Lut>} constant
228     @param lut: Lookup table color scheme
229     @type outline: Boolean
230     @param outline: Places an outline around the domain surface
231     """
232    
233     # NOTE: Actor3D is inherited and there are two instances declared here.
234     # As a result, when methods from Actor3D is invoked from the driver,
235     # only the methods associated with the latest instance (which in this
236     # case is the Actor3D for the contour) can be executed. Actor3D
237     # methods associated with Outline cannot be invoked from the driver.
238     # They can only be called within here, which is why Outline must
239     # be place before the contour as there is unlikely to be any changes
240     # made to the Outline's Actor3D.
241    
242     # ----- Outline -----
243    
244     if(outline == True):
245     #outline = Outline(Glyph3D._getOutput(self))
246     outline = Outline(data_collector._getOutput())
247     DataSetMapper.__init__(self, outline._getOutput())
248    
249     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
250     # Default outline color is black.
251     Actor3D.setColor(self, Color.BLACK)
252     # Default line width is 1.
253     Actor3D._setLineWidth(self, 1)
254     scene._addActor3D(viewport, Actor3D._getActor3D(self))
255    
256    
257     # ----- contour on a clipped plane -----
258    
259     if(scalar != None):
260     data_collector._setActiveScalar(scalar)
261    
262     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
263     # before DataSetMapper. If it is done after DataSetMapper, no effect
264     # will take place.
265     if(lut == Lut.COLOR): # Colored lookup table.
266     lookup_table = LookupTable()
267     lookup_table._setTableValue()
268     elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
269     lookup_table = LookupTable()
270     lookup_table._setLookupTableToGreyScale()
271    
272     Transform.__init__(self)
273     Plane.__init__(self, Transform._getTransform(self))
274    
275     Clipper.__init__(self, data_collector._getOutput(),
276     Plane._getPlane(self))
277     Clipper._setClipFunction(self)
278    
279     ContourModule.__init__(self, Clipper._getOutput(self))
280     # By default 10 contours are generated and the scalar range is based
281     # on the scalar data.
282     ContourModule.generateContours(self, 10, data_collector._getScalarRange()[0],
283     data_collector._getScalarRange()[1])
284    
285     DataSetMapper.__init__(self, ContourModule._getOutput(self),
286     lookup_table._getLookupTable())
287    
288     DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
289    
290     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
291     scene._addActor3D(viewport, Actor3D._getActor3D(self))
292    
293    
294    

  ViewVC Help
Powered by ViewVC 1.1.26