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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1197 - (hide annotations)
Mon Jun 18 02:08:34 2007 UTC (13 years, 10 months ago) by jongui
File MIME type: text/x-python
File size: 7088 byte(s)
Update the way movies are generated. Please refer to the examples. 

The user can now either specify the image range(first and last images inclusive):
mov.imageRange(input_directory = PYVISI_EXAMPLE_IMAGES_PATH,
        first_image = IMAGE_NAME + "000938.jpg",
		last_image = IMAGE_NAME + "000948.jpg")
mov.makeMovie(os.path.join(PYVISI_EXAMPLE_IMAGES_PATH, "movie.mpg"))

or the user can specify a list of images:

lst = ['image1.jpg', 'image5.jpg', 'image7.jpg]
mov.imageList(input_directory = PYVISI_EXAMPLE_IMAGES_PATH, image_list = lst)
mov.makeMovie(os.path.join(PYVISI_EXAMPLE_IMAGES_PATH, "movie.mpg"))


1 ksteube 1147 """
2 jongui 1197 @var __author__: name of author
3     @var __copyright__: copyrights
4     @var __license__: licence agreement
5     @var __url__: url entry point on documentation
6     @var __version__: version
7     @var __date__: date of the version
8 ksteube 1147 """
9    
10 jongui 1197 __author__="John Ngui, john.ngui@uq.edu.au"
11     __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
12     http://www.access.edu.au
13     Primary Business: Queensland, Australia"""
14     __license__="""Licensed under the Open Software License version 3.0
15     http://www.opensource.org/licenses/osl-3.0.php"""
16     __url__="http://www.iservo.edu.au/esys"
17     __version__="$Revision$"
18     __date__="$Date$"
19    
20    
21 ksteube 1147 import vtk
22     from mapper import DataSetMapper
23     from lookuptable import LookupTable
24     from actor import Actor3D
25 jongui 1148 from constant import Viewport, Color, Lut, ColorMode
26 ksteube 1147 from streamlinemodule import StreamLineModule
27     from tube import Tube
28     from point import PointSource
29     from outline import Outline
30     from average import CellDataToPointData
31 jongui 1148 from position import GlobalPosition
32 ksteube 1147
33     # NOTE: DataSetMapper, Actor3D, PointSource, StreamLineModule and Tube were
34     # inherited to allow access to their public methods from the driver.
35     class StreamLine(DataSetMapper, Actor3D, PointSource, StreamLineModule, Tube):
36     """
37     Class that shows the direction of particles of a vector field using
38     streamlines.The streamlines can either be colored or grey-scaled,
39     depending on the lookup table used. If the streamlines are colored,
40     there are two possible coloring modes: (1) using vector data or (2)
41     using scalar data.
42     """
43    
44     # The SOUTH_WEST default viewport is used when there is only one viewport.
45     # This saves the user from specifying the viewport when there is only one.
46     # If no lut is specified, the color scheme will be used.
47     def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
48     color_mode = ColorMode.VECTOR, lut = Lut.COLOR, cell_to_point = False,
49     outline = True):
50     """
51     Initialise the StreamLine.
52    
53     @attention: The source can either be point or cell data. If the
54     source is cell data, a conversion to point data may or may not be
55     required, in order for the object to be rendered correctly.
56     If a conversion is needed, the 'cell_to_point' flag must be set to
57     'True', otherwise 'False' (which is the default).
58    
59     @type scene: L{Scene <scene.Scene>} object
60     @param scene: Scene in which objects are to be rendered on
61     @type data_collector: L{DataCollector <datacollector.DataCollector>}
62     object
63     @param data_collector: Deal with source of data for visualisation
64     @type viewport: L{Viewport <constant.Viewport>} constant
65     @param viewport: Viewport in which the object is to be rendered on
66     @type color_mode: L{ColorMode <constant.ColorMode>} constant
67     @param color_mode: Type of color mode
68     @type lut : L{Lut <constant.Lut>} constant
69     @param lut: Lookup table color scheme
70     @type cell_to_point: Boolean
71     @param cell_to_point: Converts cell data to point data (by averaging)
72     @type outline: Boolean
73     @param outline: Places an outline around the domain surface
74     """
75    
76 jongui 1148 self.__data_collector = data_collector
77     self.__viewport = viewport
78     self.__color_mode = color_mode
79     self.__lut = lut
80     self.__cell_to_point = cell_to_point
81     self.__outline = outline
82 ksteube 1147
83 jongui 1148 # Keeps track whether Streamline has been modified.
84     self.__modified = True
85     PointSource.__init__(self)
86     StreamLineModule.__init__(self)
87     Tube.__init__(self)
88     DataSetMapper.__init__(self)
89     Actor3D.__init__(self)
90     scene._addVisualizationModules(self)
91 ksteube 1147
92 jongui 1148 # ----- Outline -----
93 ksteube 1147
94 jongui 1148 # NOTE: Changes cannot be made to the Outline's properties from the
95     # driver.
96     if(self.__outline == True):
97     outline = Outline(self.__data_collector._getDataCollectorOutput())
98     mapper = DataSetMapper()
99     mapper._setupDataSetMapper(outline._getOutlineOutput())
100    
101     actor3D = Actor3D()
102     actor3D._setupActor3D(mapper._getDataSetMapper())
103 ksteube 1147 # Default outline color is black.
104 jongui 1148 actor3D.setColor(Color.BLACK)
105    
106 ksteube 1147 # Default line width is 1.
107 jongui 1148 actor3D._setLineWidth(1)
108 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
109 ksteube 1147
110     # ----- Streamline -----
111    
112     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
113     # before DataSetMapper. If it is done after DataSetMapper, no effect
114     # will take place.
115 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
116 ksteube 1147 lookup_table = LookupTable()
117     lookup_table._setTableValue()
118 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
119 ksteube 1147 lookup_table = LookupTable()
120     lookup_table._setLookupTableToGreyScale()
121    
122 jongui 1148 if(self.__cell_to_point == True): # Converts cell data to point data.
123     c2p = CellDataToPointData(
124     self.__data_collector._getDataCollectorOutput())
125     self._setupPointSource(c2p._getCellToPointOutput())
126     self._setupStreamLineModule(c2p._getCellToPointOutput(),
127     self._getPointSourceOutput())
128     elif(self.__cell_to_point == False): # No conversion happens.
129     self._setupPointSource(
130     self.__data_collector._getDataCollectorOutput())
131     self._setupStreamLineModule(
132     self.__data_collector._getDataCollectorOutput(),
133     self._getPointSourceOutput())
134 ksteube 1147
135 jongui 1148 self._setupTube(self._getStreamLineModuleOutput())
136     self._setupDataSetMapper(self._getTubeOutput(),
137 ksteube 1147 lookup_table._getLookupTable())
138    
139 jongui 1148 self._setupActor3D(self._getDataSetMapper())
140 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
141 ksteube 1147
142 jongui 1148 def _isModified(self):
143     """
144     Return whether the StreamLine or DataCollector has been modified.
145 ksteube 1147
146 jongui 1148 @rtype: Boolean
147     @return: True or False
148     """
149 ksteube 1147
150 jongui 1148 return self.__modified or self.__data_collector._isModified()
151 ksteube 1147
152 jongui 1158 def _render(self, scene):
153 jongui 1148 """
154     Render the streamline.
155 jongui 1158
156     @type scene: L{Scene <scene.Scene>} object
157     @param scene: Scene in which objects are to be rendered on
158 jongui 1148 """
159    
160     if (self._isModified() == True):
161     if(self._isPointSourceCenterSet() != True):
162     center = self.__data_collector._getCenter()
163     center = GlobalPosition(center[0], center[1], center[2])
164     self.setPointSourceCenter(center)
165    
166     self._setPointSourceCenter()
167    
168     if(self.__data_collector._isScalarSet() == True):
169     self.__data_collector._setActiveScalar()
170     if(self.__data_collector._isVectorSet() == True):
171     self.__data_collector._setActiveVector()
172    
173     # Color streamline by vector.
174     if(self.__color_mode == ColorMode.VECTOR):
175     self._setScalarVisibilityOn()
176     self._setSpeedScalarsOn()
177 jongui 1189
178     # self._isScalarRangeSet checks whether the scalar range has
179     # beenspecified by the user. If it has, then the scalar range
180     # read from the source will be ignored.
181     if(not(self._isScalarRangeSet())):
182     self._setScalarRange(\
183     self.__data_collector._getVectorRange())
184 jongui 1148 # Color streamline by scalar.
185     elif(self.__color_mode == ColorMode.SCALAR):
186     self._setScalarVisibilityOn()
187     self._setSpeedScalarsOff()
188    
189 jongui 1189 # self._isScalarRangeSet checks whether the scalar range has
190     # beenspecified by the user. If it has, then the scalar range
191     # read from the source will be ignored.
192     if(not(self._isScalarRangeSet())):
193     self._setScalarRange(\
194     self.__data_collector._getScalarRange())
195    
196 jongui 1148 self.__modified = False
197    
198    

  ViewVC Help
Powered by ViewVC 1.1.26