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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (hide annotations)
Tue May 22 04:24:01 2007 UTC (13 years, 10 months ago) by jongui
File MIME type: text/x-python
File size: 5029 byte(s)
Made some changes to fix the memory leak problem. However, the problem still persists for run_escript_with_lazy_evaluation.py, run_streamline.py and run_streamline_with_lazy_evaluation.py.

1 ksteube 1147 """
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 jongui 1148 from constant import Viewport, Color, Lut, WarpMode, ColorMode
10 ksteube 1147 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 jongui 1148 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 ksteube 1147
74     # ----- Outline -----
75    
76 jongui 1148 # 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 ksteube 1147
83 jongui 1148 actor3D = Actor3D()
84     actor3D._setupActor3D(mapper._getDataSetMapper())
85 ksteube 1147 # Default outline color is black.
86 jongui 1148 actor3D.setColor(Color.BLACK)
87 ksteube 1147
88     # Default line width is 1.
89 jongui 1148 actor3D._setLineWidth(1)
90 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
91 ksteube 1147
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 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
98 ksteube 1147 lookup_table = LookupTable()
99     lookup_table._setTableValue()
100 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
101 ksteube 1147 lookup_table = LookupTable()
102     lookup_table._setLookupTableToGreyScale()
103    
104 jongui 1148 self._setupPlane(self._getTransform())
105 ksteube 1147
106 jongui 1148 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 ksteube 1147
114 jongui 1148 self._setupWarp(self._getCutterOutput())
115     self._setupDataSetMapper(self._getWarpOutput(),
116 ksteube 1147 lookup_table._getLookupTable())
117    
118 jongui 1148 self._setupActor3D(self._getDataSetMapper())
119 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
120 ksteube 1147
121 jongui 1148 def _isModified(self):
122     """
123     Return whether the Carpet or DataCollector has been modified.
124 ksteube 1147
125 jongui 1148 @rtype: Boolean
126     @return: True or False
127     """
128    
129     return self.__modified or self.__data_collector._isModified()
130    
131 jongui 1158 def _render(self, scene):
132 jongui 1148 """
133     Render the carpet.
134 jongui 1158
135     @type scene: L{Scene <scene.Scene>} object
136     @param scene: Scene in which objects are to be rendered on
137 jongui 1148 """
138    
139     if (self._isModified() == True):
140     if(self.__data_collector._isScalarSet() == True):
141     self.__data_collector._setActiveScalar()
142     self._setScalarRange(self.__data_collector._getScalarRange())
143     self.__modified = False
144    
145    

  ViewVC Help
Powered by ViewVC 1.1.26