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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 994 - (show annotations)
Fri Feb 23 07:00:54 2007 UTC (13 years, 6 months ago) by jongui
File MIME type: text/x-python
File size: 3919 byte(s)
Modified the way setActiveScalar, setActiveVector and setActiveTensor are specified. It appears that the attributes have to be set each time a new file is read.
1 """
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, WarpMode
10 from warp import Warp
11 from outline import Outline
12 from transform import Transform
13 from plane import Plane
14 from cutter import Cutter
15
16 # NOTE: DataSetMapper, Actor3D, Warp, Transform, Plane and Cutter were
17 # inherited to allow access to their public methods from the driver.
18 class Carpet(DataSetMapper, Actor3D, Warp, Transform, Plane, Cutter):
19 """
20 Class that shows a scalar field on a plane deformated along the normal.
21 """
22
23 # The SOUTH_WEST default viewport is used when there is only one viewport.
24 # This saves the user from specifying the viewport when there is only one.
25 # If no warp_mode is specified, the data will be deformated using scalar
26 # data. If no scalar field is specified, the first encountered in the
27 # file will be loaded automatically. If no lut is specified, the
28 # color scheme will be used.
29 def __init__(self, scene, data_collector, scalar = None, vector = None,
30 warp_mode = WarpMode.SCALAR, viewport = Viewport.SOUTH_WEST,
31 lut = Lut.COLOR, outline = True):
32 """
33 @type scene: L{Scene <scene.Scene>} object
34 @param scene: Scene in which objects are to be rendered on
35 @type data_collector: L{DataCollector <datacollector.DataCollector>}
36 object
37 @param data_collector: Deal with source of data for visualisation
38 @type scalar: String
39 @param scalar: Scalar field to load from the source file
40 @param warp_mode: L{WarpMode <constant.WarpMode>} constant
41 @type warp_mode: Mode in which to deform the scalar data
42 @type viewport: L{Viewport <constant.Viewport>} constant
43 @param viewport: Viewport in which objects are to be rendered on
44 @type lut : L{Lut <constant.Lut>} constant
45 @param lut: Lookup table color scheme
46 @type outline: Boolean
47 @param outline: Places an outline around the domain surface
48 """
49
50 # NOTE: Actor3D is inherited and there are two instances declared here.
51 # As a result, when methods from Actor3D is invoked from the driver,
52 # only the methods associated with the latest instance (which in this
53 # case is the Actor3D for the carpet) can be executed. Actor3D
54 # methods associated with Outline cannot be invoked from the driver.
55 # They can only be called within here, which is why Outline must
56 # be place before the carpet as there is unlikely to be any changes
57 # made to the Outline's Actor3D.
58
59 # ----- Outline -----
60
61 if(outline == True):
62 outline = Outline(data_collector._getOutput())
63 DataSetMapper.__init__(self, outline._getOutput())
64
65 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
66 # Default outline color is black.
67 Actor3D.setColor(self, Color.BLACK)
68
69 # Default line width is 1.
70 Actor3D._setLineWidth(self, 1)
71 scene._addActor3D(viewport, Actor3D._getActor3D(self))
72
73 # ----- Carpet -----
74
75 #if(scalar != None):
76 # data_collector._setActiveScalar(scalar)
77
78 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
79 # before DataSetMapper. If it is done after DataSetMapper, no effect
80 # will take place.
81 if(lut == Lut.COLOR): # Colored lookup table.
82 lookup_table = LookupTable()
83 lookup_table._setTableValue()
84 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
85 lookup_table = LookupTable()
86 lookup_table._setLookupTableToGreyScale()
87
88 Transform.__init__(self)
89 Plane.__init__(self, Transform._getTransform(self))
90
91 Cutter.__init__(self, data_collector._getOutput(),
92 Plane._getPlane(self))
93 Warp.__init__(self, Cutter._getOutput(self), warp_mode)
94
95 DataSetMapper.__init__(self, Warp._getOutput(self),
96 lookup_table._getLookupTable())
97 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
98
99 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
100 scene._addActor3D(viewport, Actor3D._getActor3D(self))
101

  ViewVC Help
Powered by ViewVC 1.1.26