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

  ViewVC Help
Powered by ViewVC 1.1.26