/[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 1147 - (show annotations)
Wed May 16 06:39:11 2007 UTC (13 years, 11 months ago) by ksteube
File MIME type: text/x-python
File size: 4550 byte(s)
Added back in some files that were accidentally deleted.

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, VizType, ColorMode
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 from average import CellDataToPointData
16
17 # NOTE: DataSetMapper, Actor3D, Warp, Transform, Plane and Cutter were
18 # inherited to allow access to their public methods from the driver.
19 class Carpet(DataSetMapper, Actor3D, Warp, Transform, Plane, Cutter):
20 """
21 Class that shows a scalar field on a plane deformated along the normal.
22 """
23
24 # The SOUTH_WEST default viewport is used when there is only one viewport.
25 # This saves the user from specifying the viewport when there is only one.
26 # If no warp_mode is specified, the data will be deformated using scalar
27 # data. If no lut is specified, the color scheme will be used.
28 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
29 warp_mode = WarpMode.SCALAR, lut = Lut.COLOR,
30 cell_to_point = False, outline = True):
31 """
32 Initialise the Carpet.
33
34 @attention: The source can either be point or cell data. If the
35 source is cell data, a conversion to point data may or may not be
36 required, in order for the object to be rendered correctly.
37 If a conversion is needed, the 'cell_to_point' flag must be set to
38 'True', otherwise 'False' (which is the default).
39
40 @type scene: L{Scene <scene.Scene>} object
41 @param scene: Scene in which objects are to be rendered on
42 @type data_collector: L{DataCollector <datacollector.DataCollector>}
43 object
44 @param data_collector: Deal with source of data for visualisation
45 @type viewport: L{Viewport <constant.Viewport>} constant
46 @param viewport: Viewport in which objects are to be rendered on
47 @param warp_mode: L{WarpMode <constant.WarpMode>} constant
48 @type warp_mode: Mode in which to deform the scalar field
49 @type lut : L{Lut <constant.Lut>} constant
50 @param lut: Lookup table color scheme
51 @type cell_to_point: Boolean
52 @param cell_to_point: Converts cell data to point data (by averaging)
53 @type outline: Boolean
54 @param outline: Places an outline around the domain surface
55 """
56
57 # NOTE: Actor3D is inherited and there are two instances declared here.
58 # As a result, when methods from Actor3D is invoked from the driver,
59 # only the methods associated with the latest instance (which in this
60 # case is the Actor3D for the carpet) can be executed. Actor3D
61 # methods associated with Outline cannot be invoked from the driver.
62 # They can only be called within here, which is why Outline must
63 # be place before the carpet as there is unlikely to be any changes
64 # made to the Outline's Actor3D.
65
66 # ----- Outline -----
67
68 if(outline == True):
69 outline = Outline(data_collector._getOutput())
70 DataSetMapper.__init__(self, outline._getOutput())
71
72 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
73 # Default outline color is black.
74 Actor3D.setColor(self, Color.BLACK)
75
76 # Default line width is 1.
77 Actor3D._setLineWidth(self, 1)
78 scene._addActor3D(viewport, Actor3D._getActor3D(self))
79
80 # ----- Carpet -----
81
82 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
83 # before DataSetMapper. If it is done after DataSetMapper, no effect
84 # will take place.
85 if(lut == Lut.COLOR): # Colored lookup table.
86 lookup_table = LookupTable()
87 lookup_table._setTableValue()
88 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
89 lookup_table = LookupTable()
90 lookup_table._setLookupTableToGreyScale()
91
92 Transform.__init__(self)
93 Plane.__init__(self, Transform._getTransform(self))
94
95 if(cell_to_point == True): # Converts cell data to point data.
96 c2p = CellDataToPointData(data_collector._getOutput())
97 Cutter.__init__(self, c2p._getOutput(), Plane._getPlane(self))
98 elif(cell_to_point == False): # No conversion happens.
99 Cutter.__init__(self, data_collector._getOutput(),
100 Plane._getPlane(self))
101
102 Warp.__init__(self, Cutter._getOutput(self), warp_mode)
103
104 DataSetMapper.__init__(self, Warp._getOutput(self),
105 lookup_table._getLookupTable())
106 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
107
108 data_collector._paramForUpdatingMultipleSources(VizType.CARPET,
109 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))
110
111 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
112 scene._addActor3D(viewport, Actor3D._getActor3D(self))
113

  ViewVC Help
Powered by ViewVC 1.1.26