/[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 1148 - (hide annotations)
Wed May 16 22:45:33 2007 UTC (13 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 4952 byte(s)
Added the updated files for pyvisi and removed some incorrect reference images.
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.__scene = scene
58     self.__data_collector = data_collector
59     self.__viewport = viewport
60     self.__warp_mode = warp_mode
61     self.__lut = lut
62     self.__cell_to_point = cell_to_point
63     self.__outline = outline
64    
65     # Keeps track whether Carpet has been modified.
66     self.__modified = True
67     Transform.__init__(self)
68     Plane.__init__(self)
69     Cutter.__init__(self)
70     Warp.__init__(self, self.__warp_mode)
71     DataSetMapper.__init__(self)
72     Actor3D.__init__(self)
73     scene._addVisualizationModules(self)
74 ksteube 1147
75     # ----- Outline -----
76    
77 jongui 1148 # NOTE: Changes cannot be made to the Outline's properties from the
78     # driver.
79     if(self.__outline == True):
80     outline = Outline(self.__data_collector._getDataCollectorOutput())
81     mapper = DataSetMapper()
82     mapper._setupDataSetMapper(outline._getOutlineOutput())
83 ksteube 1147
84 jongui 1148 actor3D = Actor3D()
85     actor3D._setupActor3D(mapper._getDataSetMapper())
86 ksteube 1147 # Default outline color is black.
87 jongui 1148 actor3D.setColor(Color.BLACK)
88 ksteube 1147
89     # Default line width is 1.
90 jongui 1148 actor3D._setLineWidth(1)
91     self.__scene._addActor3D(self.__viewport, actor3D._getActor3D())
92 ksteube 1147
93     # ----- Carpet -----
94    
95     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
96     # before DataSetMapper. If it is done after DataSetMapper, no effect
97     # will take place.
98 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
99 ksteube 1147 lookup_table = LookupTable()
100     lookup_table._setTableValue()
101 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
102 ksteube 1147 lookup_table = LookupTable()
103     lookup_table._setLookupTableToGreyScale()
104    
105 jongui 1148 self._setupPlane(self._getTransform())
106 ksteube 1147
107 jongui 1148 if(self.__cell_to_point == True): # Converts cell data to point data.
108     c2p = CellDataToPointData(\
109     self.__data_collector._getDataCollectorOutput())
110     self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())
111     elif(self.__cell_to_point == False): # No conversion happens.
112     self._setupCutter(self.__data_collector._getDataCollectorOutput(),
113     self._getPlane())
114 ksteube 1147
115 jongui 1148 self._setupWarp(self._getCutterOutput())
116     self._setupDataSetMapper(self._getWarpOutput(),
117 ksteube 1147 lookup_table._getLookupTable())
118    
119 jongui 1148 self._setupActor3D(self._getDataSetMapper())
120     self.__scene._addActor3D(self.__viewport, self._getActor3D())
121 ksteube 1147
122 jongui 1148 def _isModified(self):
123     """
124     Return whether the Carpet or DataCollector has been modified.
125 ksteube 1147
126 jongui 1148 @rtype: Boolean
127     @return: True or False
128     """
129    
130     return self.__modified or self.__data_collector._isModified()
131    
132     def _render(self):
133     """
134     Render the carpet.
135     """
136    
137     if (self._isModified() == True):
138     if(self.__data_collector._isScalarSet() == True):
139     self.__data_collector._setActiveScalar()
140     self._setScalarRange(self.__data_collector._getScalarRange())
141     self.__modified = False
142    
143    

  ViewVC Help
Powered by ViewVC 1.1.26