/[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 1189 - (show annotations)
Thu Jun 7 05:31:25 2007 UTC (13 years, 10 months ago) by jongui
File MIME type: text/x-python
File size: 5243 byte(s)
A Scalar Bar can now be displayed by creating an instance of a 'Legend'. The Scalar Bar can either show the scalar data range or vector data range. Corresponding examples and tests have also been added.
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, 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 self.__data_collector = data_collector
58 self.__viewport = viewport
59 self.__warp_mode = warp_mode
60 self.__lut = lut
61 self.__cell_to_point = cell_to_point
62 self.__outline = outline
63
64 # Keeps track whether Carpet has been modified.
65 self.__modified = True
66 Transform.__init__(self)
67 Plane.__init__(self)
68 Cutter.__init__(self)
69 Warp.__init__(self, self.__warp_mode)
70 DataSetMapper.__init__(self)
71 Actor3D.__init__(self)
72 scene._addVisualizationModules(self)
73
74 # ----- Outline -----
75
76 # NOTE: Changes cannot be made to the Outline's properties from the
77 # driver.
78 if(self.__outline == True):
79 outline = Outline(self.__data_collector._getDataCollectorOutput())
80 mapper = DataSetMapper()
81 mapper._setupDataSetMapper(outline._getOutlineOutput())
82
83 actor3D = Actor3D()
84 actor3D._setupActor3D(mapper._getDataSetMapper())
85 # Default outline color is black.
86 actor3D.setColor(Color.BLACK)
87
88 # Default line width is 1.
89 actor3D._setLineWidth(1)
90 scene._addActor3D(self.__viewport, actor3D._getActor3D())
91
92 # ----- Carpet -----
93
94 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
95 # before DataSetMapper. If it is done after DataSetMapper, no effect
96 # will take place.
97 if(self.__lut == Lut.COLOR): # Colored lookup table.
98 lookup_table = LookupTable()
99 lookup_table._setTableValue()
100 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
101 lookup_table = LookupTable()
102 lookup_table._setLookupTableToGreyScale()
103
104 self._setupPlane(self._getTransform())
105
106 if(self.__cell_to_point == True): # Converts cell data to point data.
107 c2p = CellDataToPointData(\
108 self.__data_collector._getDataCollectorOutput())
109 self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())
110 elif(self.__cell_to_point == False): # No conversion happens.
111 self._setupCutter(self.__data_collector._getDataCollectorOutput(),
112 self._getPlane())
113
114 self._setupWarp(self._getCutterOutput())
115 self._setupDataSetMapper(self._getWarpOutput(),
116 lookup_table._getLookupTable())
117
118 self._setupActor3D(self._getDataSetMapper())
119 scene._addActor3D(self.__viewport, self._getActor3D())
120
121 def _isModified(self):
122 """
123 Return whether the Carpet or DataCollector has been modified.
124
125 @rtype: Boolean
126 @return: True or False
127 """
128
129 return self.__modified or self.__data_collector._isModified()
130
131 def _render(self, scene):
132 """
133 Render the carpet.
134
135 @type scene: L{Scene <scene.Scene>} object
136 @param scene: Scene in which objects are to be rendered on
137 """
138
139 if (self._isModified() == True):
140 if(self.__data_collector._isScalarSet() == True):
141 self.__data_collector._setActiveScalar()
142
143 # self._isScalarRangeSet checks whether the scalar range has been
144 # specified by the user. If it has, then the scalar range
145 # read from the source will be ignored.
146 if(not(self._isScalarRangeSet())):
147 self._setScalarRange(self.__data_collector._getScalarRange())
148 self.__modified = False
149
150

  ViewVC Help
Powered by ViewVC 1.1.26