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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (show annotations)
Tue May 22 04:24:01 2007 UTC (13 years, 9 months ago) by jongui
File MIME type: text/x-python
File size: 6029 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 """
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, ColorMode
10 from streamlinemodule import StreamLineModule
11 from tube import Tube
12 from point import PointSource
13 from outline import Outline
14 from average import CellDataToPointData
15 from position import GlobalPosition
16
17 # NOTE: DataSetMapper, Actor3D, PointSource, StreamLineModule and Tube were
18 # inherited to allow access to their public methods from the driver.
19 class StreamLine(DataSetMapper, Actor3D, PointSource, StreamLineModule, Tube):
20 """
21 Class that shows the direction of particles of a vector field using
22 streamlines.The streamlines can either be colored or grey-scaled,
23 depending on the lookup table used. If the streamlines are colored,
24 there are two possible coloring modes: (1) using vector data or (2)
25 using scalar data.
26 """
27
28 # The SOUTH_WEST default viewport is used when there is only one viewport.
29 # This saves the user from specifying the viewport when there is only one.
30 # If no lut is specified, the color scheme will be used.
31 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
32 color_mode = ColorMode.VECTOR, lut = Lut.COLOR, cell_to_point = False,
33 outline = True):
34 """
35 Initialise the StreamLine.
36
37 @attention: The source can either be point or cell data. If the
38 source is cell data, a conversion to point data may or may not be
39 required, in order for the object to be rendered correctly.
40 If a conversion is needed, the 'cell_to_point' flag must be set to
41 'True', otherwise 'False' (which is the default).
42
43 @type scene: L{Scene <scene.Scene>} object
44 @param scene: Scene in which objects are to be rendered on
45 @type data_collector: L{DataCollector <datacollector.DataCollector>}
46 object
47 @param data_collector: Deal with source of data for visualisation
48 @type viewport: L{Viewport <constant.Viewport>} constant
49 @param viewport: Viewport in which the object is to be rendered on
50 @type color_mode: L{ColorMode <constant.ColorMode>} constant
51 @param color_mode: Type of color mode
52 @type lut : L{Lut <constant.Lut>} constant
53 @param lut: Lookup table color scheme
54 @type cell_to_point: Boolean
55 @param cell_to_point: Converts cell data to point data (by averaging)
56 @type outline: Boolean
57 @param outline: Places an outline around the domain surface
58 """
59
60 self.__data_collector = data_collector
61 self.__viewport = viewport
62 self.__color_mode = color_mode
63 self.__lut = lut
64 self.__cell_to_point = cell_to_point
65 self.__outline = outline
66
67 # Keeps track whether Streamline has been modified.
68 self.__modified = True
69 PointSource.__init__(self)
70 StreamLineModule.__init__(self)
71 Tube.__init__(self)
72 DataSetMapper.__init__(self)
73 Actor3D.__init__(self)
74 scene._addVisualizationModules(self)
75
76 # ----- Outline -----
77
78 # NOTE: Changes cannot be made to the Outline's properties from the
79 # driver.
80 if(self.__outline == True):
81 outline = Outline(self.__data_collector._getDataCollectorOutput())
82 mapper = DataSetMapper()
83 mapper._setupDataSetMapper(outline._getOutlineOutput())
84
85 actor3D = Actor3D()
86 actor3D._setupActor3D(mapper._getDataSetMapper())
87 # Default outline color is black.
88 actor3D.setColor(Color.BLACK)
89
90 # Default line width is 1.
91 actor3D._setLineWidth(1)
92 scene._addActor3D(self.__viewport, actor3D._getActor3D())
93
94 # ----- Streamline -----
95
96 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
97 # before DataSetMapper. If it is done after DataSetMapper, no effect
98 # will take place.
99 if(self.__lut == Lut.COLOR): # Colored lookup table.
100 lookup_table = LookupTable()
101 lookup_table._setTableValue()
102 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
103 lookup_table = LookupTable()
104 lookup_table._setLookupTableToGreyScale()
105
106 if(self.__cell_to_point == True): # Converts cell data to point data.
107 c2p = CellDataToPointData(
108 self.__data_collector._getDataCollectorOutput())
109 self._setupPointSource(c2p._getCellToPointOutput())
110 self._setupStreamLineModule(c2p._getCellToPointOutput(),
111 self._getPointSourceOutput())
112 elif(self.__cell_to_point == False): # No conversion happens.
113 self._setupPointSource(
114 self.__data_collector._getDataCollectorOutput())
115 self._setupStreamLineModule(
116 self.__data_collector._getDataCollectorOutput(),
117 self._getPointSourceOutput())
118
119 self._setupTube(self._getStreamLineModuleOutput())
120 self._setupDataSetMapper(self._getTubeOutput(),
121 lookup_table._getLookupTable())
122
123 self._setupActor3D(self._getDataSetMapper())
124 scene._addActor3D(self.__viewport, self._getActor3D())
125
126 def _isModified(self):
127 """
128 Return whether the StreamLine or DataCollector has been modified.
129
130 @rtype: Boolean
131 @return: True or False
132 """
133
134 return self.__modified or self.__data_collector._isModified()
135
136 def _render(self, scene):
137 """
138 Render the streamline.
139
140 @type scene: L{Scene <scene.Scene>} object
141 @param scene: Scene in which objects are to be rendered on
142 """
143
144 if (self._isModified() == True):
145 if(self._isPointSourceCenterSet() != True):
146 center = self.__data_collector._getCenter()
147 center = GlobalPosition(center[0], center[1], center[2])
148 self.setPointSourceCenter(center)
149
150 self._setPointSourceCenter()
151
152 if(self.__data_collector._isScalarSet() == True):
153 self.__data_collector._setActiveScalar()
154 if(self.__data_collector._isVectorSet() == True):
155 self.__data_collector._setActiveVector()
156
157 # Color streamline by vector.
158 if(self.__color_mode == ColorMode.VECTOR):
159 self._setScalarVisibilityOn()
160 self._setSpeedScalarsOn()
161 self._setScalarRange(self.__data_collector._getVectorRange())
162 # Color streamline by scalar.
163 elif(self.__color_mode == ColorMode.SCALAR):
164 self._setScalarVisibilityOn()
165 self._setSpeedScalarsOff()
166 self._setScalarRange(self.__data_collector._getScalarRange())
167
168 self.__modified = False
169
170

  ViewVC Help
Powered by ViewVC 1.1.26