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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1029 - (show annotations)
Wed Mar 14 05:01:13 2007 UTC (12 years, 4 months ago) by jongui
File MIME type: text/x-python
File size: 10711 byte(s)
Fixed problems in relation to updates propagating when multiple files/sources are read.
1 """
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 # NOTE: DataSetMapper, Actor3D and ContourModule were inherited to allow
14 # access to their public methods from the driver.
15 class Contour(DataSetMapper, Actor3D, ContourModule):
16 """
17 Class that shows a scalar field by contour surfaces. The contour surfaces
18 can either be colored or grey-scaled, depending on the lookup table used.
19 This class can also be used to generate iso 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 lut is specified, the color scheme will be used.
25 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
26 lut = Lut.COLOR, 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 viewport: L{Viewport <constant.Viewport>} constant
34 @param viewport: Viewport in which objects are to be rendered on
35 @type lut : L{Lut <constant.Lut>} constant
36 @param lut: Lookup table color scheme
37 @type outline: Boolean
38 @param outline: Places an outline around the domain surface
39 """
40
41 # NOTE: Actor3D is inherited and there are two instances declared here.
42 # As a result, when methods from Actor3D is invoked from the driver,
43 # only the methods associated with the latest instance (which in this
44 # case is the Actor3D for the contour) can be executed. Actor3D
45 # methods associated with Outline cannot be invoked from the driver.
46 # They can only be called within here, which is why Outline must
47 # be place before the contour as there is unlikely to be any changes
48 # made to the Outline's Actor3D.
49
50 # ----- Outline -----
51
52 if(outline == True):
53 outline = Outline(data_collector._getOutput())
54 DataSetMapper.__init__(self, outline._getOutput())
55
56 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
57 # Default outline color is black.
58 Actor3D.setColor(self, Color.BLACK)
59
60 # Default line width is 1.
61 Actor3D._setLineWidth(self, 1)
62 scene._addActor3D(viewport, Actor3D._getActor3D(self))
63
64 # ----- Contour -----
65
66 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
67 # before DataSetMapper. If it is done after DataSetMapper, no effect
68 # will take place.
69 if(lut == Lut.COLOR): # Colored lookup table.
70 lookup_table = LookupTable()
71 lookup_table._setTableValue()
72 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
73 lookup_table = LookupTable()
74 lookup_table._setLookupTableToGreyScale()
75
76 ContourModule.__init__(self, data_collector._getOutput())
77 # By default 10 contours are generated and the scalar range is based
78 # on the scalar data range.
79 ContourModule.generateContours(self, 10,
80 data_collector._getScalarRange()[0],
81 data_collector._getScalarRange()[1])
82
83 DataSetMapper.__init__(self, ContourModule._getOutput(self),
84 lookup_table._getLookupTable())
85 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
86
87 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
88 scene._addActor3D(viewport, Actor3D._getActor3D(self))
89
90
91 ###############################################################################
92
93
94 from transform import Transform
95 from plane import Plane
96 from cutter import Cutter
97
98 # NOTE: DataSetMapper, Actor3D, ContourModule, Transform, Plane and Cutter were
99 # inherited to allow access to their public methods from the driver.
100 class ContourOnPlaneCut(DataSetMapper, Actor3D, ContourModule, Transform,
101 Plane, Cutter):
102 """
103 This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
104 except that it shows a scalar field by contour surfaces on a plane.
105 """
106
107 # The SOUTH_WEST default viewport is used when there is only one viewport.
108 # This saves the user from specifying the viewport when there is only one.
109 # If no lut is specified, the color scheme will be used.
110 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
111 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 viewport: L{Viewport <constant.Viewport>} constant
120 @param viewport: Viewport in which objects are to be rendered on
121 @type lut : L{Lut <constant.Lut>} constant
122 @param lut: Lookup table color scheme
123 @type outline: Boolean
124 @param outline: Places an outline around the domain surface
125 """
126
127 # NOTE: Actor3D is inherited and there are two instances declared here.
128 # As a result, when methods from Actor3D is invoked from the driver,
129 # only the methods associated with the latest instance (which in this
130 # case is the Actor3D for the contour) can be executed. Actor3D
131 # methods associated with Outline cannot be invoked from the driver.
132 # They can only be called within here, which is why Outline must
133 # be place before the contour as there is unlikely to be any changes
134 # made to the Outline's Actor3D.
135
136 # ----- Outline -----
137
138 if(outline == True):
139 outline = Outline(data_collector._getOutput())
140 DataSetMapper.__init__(self, outline._getOutput())
141
142 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
143 # Default outline color is black.
144 Actor3D.setColor(self, Color.BLACK)
145
146 # Default line width is 1.
147 Actor3D._setLineWidth(self, 1)
148 scene._addActor3D(viewport, Actor3D._getActor3D(self))
149
150 # ----- Contour on a cut plane -----
151
152 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
153 # before DataSetMapper. If it is done after DataSetMapper, no effect
154 # will take place.
155 if(lut == Lut.COLOR): # Colored lookup table.
156 lookup_table = LookupTable()
157 lookup_table._setTableValue()
158 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
159 lookup_table = LookupTable()
160 lookup_table._setLookupTableToGreyScale()
161
162 Transform.__init__(self)
163 Plane.__init__(self, Transform._getTransform(self))
164
165 Cutter.__init__(self, data_collector._getOutput(),
166 Plane._getPlane(self))
167 ContourModule.__init__(self, Cutter._getOutput(self))
168
169 # By default 10 contours are generated and the scalar range is based
170 # on the scalar data range.
171 ContourModule.generateContours(self, 10,
172 data_collector._getScalarRange()[0],
173 data_collector._getScalarRange()[1])
174
175 DataSetMapper.__init__(self, ContourModule._getOutput(self),
176 lookup_table._getLookupTable())
177 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
178
179 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
180 scene._addActor3D(viewport, Actor3D._getActor3D(self))
181
182
183 ###############################################################################
184
185
186 from clipper import Clipper
187
188 # NOTE: DataSetMapper, Actor3D, ContourModule, Transform, Plane and Clipper
189 # were inherited to allow access to their public methods from the driver.
190 class ContourOnPlaneClip(DataSetMapper, Actor3D, ContourModule, Transform,
191 Plane, Clipper):
192 """
193 This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>}
194 , except that it shows a scalar field by contour surfaces clipped using
195 a plane.
196 """
197
198 # The SOUTH_WEST default viewport is used when there is only one viewport.
199 # This saves the user from specifying the viewport when there is only one.
200 # If no lut is specified, the color scheme will be used.
201 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
202 lut = Lut.COLOR, outline = True):
203
204 """
205 @type scene: L{Scene <scene.Scene>} object
206 @param scene: Scene in which objects are to be rendered on
207 @type data_collector: L{DataCollector <datacollector.DataCollector>}
208 object
209 @param data_collector: Deal with source of data for visualisation
210 @type viewport: L{Viewport <constant.Viewport>} constant
211 @param viewport: Viewport in which objects are to be rendered on
212 @type lut : L{Lut <constant.Lut>} constant
213 @param lut: Lookup table color scheme
214 @type outline: Boolean
215 @param outline: Places an outline around the domain surface
216 """
217
218 # NOTE: Actor3D is inherited and there are two instances declared here.
219 # As a result, when methods from Actor3D is invoked from the driver,
220 # only the methods associated with the latest instance (which in this
221 # case is the Actor3D for the contour) can be executed. Actor3D
222 # methods associated with Outline cannot be invoked from the driver.
223 # They can only be called within here, which is why Outline must
224 # be place before the contour as there is unlikely to be any changes
225 # made to the Outline's Actor3D.
226
227 # ----- Outline -----
228
229 if(outline == True):
230 outline = Outline(data_collector._getOutput())
231 DataSetMapper.__init__(self, outline._getOutput())
232
233 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
234 # Default outline color is black.
235 Actor3D.setColor(self, Color.BLACK)
236
237 # Default line width is 1.
238 Actor3D._setLineWidth(self, 1)
239 scene._addActor3D(viewport, Actor3D._getActor3D(self))
240
241 # ----- Contour on a clipped plane -----
242
243 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
244 # before DataSetMapper. If it is done after DataSetMapper, no effect
245 # will take place.
246 if(lut == Lut.COLOR): # Colored lookup table.
247 lookup_table = LookupTable()
248 lookup_table._setTableValue()
249 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
250 lookup_table = LookupTable()
251 lookup_table._setLookupTableToGreyScale()
252
253 Transform.__init__(self)
254 Plane.__init__(self, Transform._getTransform(self))
255
256 Clipper.__init__(self, data_collector._getOutput(),
257 Plane._getPlane(self))
258 Clipper._setClipFunction(self)
259
260 ContourModule.__init__(self, Clipper._getOutput(self))
261 # By default 10 contours are generated and the scalar range is based
262 # on the scalar data range.
263 ContourModule.generateContours(self, 10,
264 data_collector._getScalarRange()[0],
265 data_collector._getScalarRange()[1])
266
267 DataSetMapper.__init__(self, ContourModule._getOutput(self),
268 lookup_table._getLookupTable())
269 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
270
271 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
272 scene._addActor3D(viewport, Actor3D._getActor3D(self))
273

  ViewVC Help
Powered by ViewVC 1.1.26