/[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 1197 - (show annotations)
Mon Jun 18 02:08:34 2007 UTC (13 years, 10 months ago) by jongui
File MIME type: text/x-python
File size: 5848 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 """
2 @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 """
9
10 __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 import vtk
22 from mapper import DataSetMapper
23 from lookuptable import LookupTable
24 from actor import Actor3D
25 from constant import Viewport, Color, Lut, WarpMode, ColorMode
26 from warp import Warp
27 from outline import Outline
28 from transform import Transform
29 from plane import Plane
30 from cutter import Cutter
31 from average import CellDataToPointData
32
33 # NOTE: DataSetMapper, Actor3D, Warp, Transform, Plane and Cutter were
34 # inherited to allow access to their public methods from the driver.
35 class Carpet(DataSetMapper, Actor3D, Warp, Transform, Plane, Cutter):
36 """
37 Class that shows a scalar field on a plane deformated along the normal.
38 """
39
40 # The SOUTH_WEST default viewport is used when there is only one viewport.
41 # This saves the user from specifying the viewport when there is only one.
42 # If no warp_mode is specified, the data will be deformated using scalar
43 # data. If no lut is specified, the color scheme will be used.
44 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
45 warp_mode = WarpMode.SCALAR, lut = Lut.COLOR,
46 cell_to_point = False, outline = True):
47 """
48 Initialise the Carpet.
49
50 @attention: The source can either be point or cell data. If the
51 source is cell data, a conversion to point data may or may not be
52 required, in order for the object to be rendered correctly.
53 If a conversion is needed, the 'cell_to_point' flag must be set to
54 'True', otherwise 'False' (which is the default).
55
56 @type scene: L{Scene <scene.Scene>} object
57 @param scene: Scene in which objects are to be rendered on
58 @type data_collector: L{DataCollector <datacollector.DataCollector>}
59 object
60 @param data_collector: Deal with source of data for visualisation
61 @type viewport: L{Viewport <constant.Viewport>} constant
62 @param viewport: Viewport in which objects are to be rendered on
63 @param warp_mode: L{WarpMode <constant.WarpMode>} constant
64 @type warp_mode: Mode in which to deform the scalar field
65 @type lut : L{Lut <constant.Lut>} constant
66 @param lut: Lookup table color scheme
67 @type cell_to_point: Boolean
68 @param cell_to_point: Converts cell data to point data (by averaging)
69 @type outline: Boolean
70 @param outline: Places an outline around the domain surface
71 """
72
73 self.__data_collector = data_collector
74 self.__viewport = viewport
75 self.__warp_mode = warp_mode
76 self.__lut = lut
77 self.__cell_to_point = cell_to_point
78 self.__outline = outline
79
80 # Keeps track whether Carpet has been modified.
81 self.__modified = True
82 Transform.__init__(self)
83 Plane.__init__(self)
84 Cutter.__init__(self)
85 Warp.__init__(self, self.__warp_mode)
86 DataSetMapper.__init__(self)
87 Actor3D.__init__(self)
88 scene._addVisualizationModules(self)
89
90 # ----- Outline -----
91
92 # NOTE: Changes cannot be made to the Outline's properties from the
93 # driver.
94 if(self.__outline == True):
95 outline = Outline(self.__data_collector._getDataCollectorOutput())
96 mapper = DataSetMapper()
97 mapper._setupDataSetMapper(outline._getOutlineOutput())
98
99 actor3D = Actor3D()
100 actor3D._setupActor3D(mapper._getDataSetMapper())
101 # Default outline color is black.
102 actor3D.setColor(Color.BLACK)
103
104 # Default line width is 1.
105 actor3D._setLineWidth(1)
106 scene._addActor3D(self.__viewport, actor3D._getActor3D())
107
108 # ----- Carpet -----
109
110 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
111 # before DataSetMapper. If it is done after DataSetMapper, no effect
112 # will take place.
113 if(self.__lut == Lut.COLOR): # Colored lookup table.
114 lookup_table = LookupTable()
115 lookup_table._setTableValue()
116 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
117 lookup_table = LookupTable()
118 lookup_table._setLookupTableToGreyScale()
119
120 self._setupPlane(self._getTransform())
121
122 if(self.__cell_to_point == True): # Converts cell data to point data.
123 c2p = CellDataToPointData(\
124 self.__data_collector._getDataCollectorOutput())
125 self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())
126 elif(self.__cell_to_point == False): # No conversion happens.
127 self._setupCutter(self.__data_collector._getDataCollectorOutput(),
128 self._getPlane())
129
130 self._setupWarp(self._getCutterOutput())
131 self._setupDataSetMapper(self._getWarpOutput(),
132 lookup_table._getLookupTable())
133
134 self._setupActor3D(self._getDataSetMapper())
135 scene._addActor3D(self.__viewport, self._getActor3D())
136
137 def _isModified(self):
138 """
139 Return whether the Carpet or DataCollector has been modified.
140
141 @rtype: Boolean
142 @return: True or False
143 """
144
145 return self.__modified or self.__data_collector._isModified()
146
147 def _render(self, scene):
148 """
149 Render the carpet.
150
151 @type scene: L{Scene <scene.Scene>} object
152 @param scene: Scene in which objects are to be rendered on
153 """
154
155 if (self._isModified() == True):
156 if(self.__data_collector._isScalarSet() == True):
157 self.__data_collector._setActiveScalar()
158
159 # self._isScalarRangeSet checks whether the scalar range has been
160 # specified by the user. If it has, then the scalar range
161 # read from the source will be ignored.
162 if(not(self._isScalarRangeSet())):
163 self._setScalarRange(self.__data_collector._getScalarRange())
164 self.__modified = False
165
166

  ViewVC Help
Powered by ViewVC 1.1.26