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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1384 - (show annotations)
Fri Jan 11 02:29:38 2008 UTC (11 years, 9 months ago) by phornby
Original Path: temp_trunk_copy/pyvisi/py_src/legend.py
File MIME type: text/x-python
File size: 4425 byte(s)
Make a temp copy of the trunk before checking in the windows changes


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 actor import Actor2D, Actor3D
24 from lookuptable import LookupTable
25 from constant import Viewport, Color, Lut, LegendType
26 from scalarbar import ScalarBar
27
28 # NOTE: ScalarBarModule, DataSetMapper and Actor3D were inherited to allow
29 # access to their public methods from the driver.
30 class Legend(ScalarBar, DataSetMapper, Actor3D):
31 """
32 Class that shows a scalar field on a domain surface. The domain surface
33 can either be colored or grey-scaled, depending on the lookup table used.
34 """
35
36 # The SOUTH_WEST default viewport is used when there is only one viewport.
37 # This saves the user from specifying the viewport when there is only one.
38 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,\
39 lut = Lut.COLOR, legend = LegendType.SCALAR):
40 """
41 Initialise the Legend.
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 vizualisation
48 @type viewport: L{Viewport <constant.Viewport>} constant
49 @param viewport: Viewport in which objects are to be rendered on
50 @type lut : L{Lut <constant.Lut>} constant
51 @param lut: Lookup table color scheme
52 @type legend: L{Lut <constant.LegendType>} constant
53 @param legend: Type of legend
54 """
55
56 self.__data_collector = data_collector
57 self.__viewport = viewport
58 self.__lut = lut
59 self.__legend = legend
60
61 self.__modified = True # Keeps track whether Legend has been modified.
62 ScalarBar.__init__(self)
63
64 # NOTE: DataSetMapper and Actor3D were required in order for the
65 # scalar bar to be colored. If the mapper and actor were not used,
66 # the scalar bar will be black in color.
67 DataSetMapper.__init__(self)
68 Actor3D.__init__(self)
69 scene._addVisualizationModules(self)
70
71 # ----- Scalar Bar -----
72
73 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
74 # before DataSetMapper. If it is done after DataSetMapper, no effect
75 # will take place.
76 if(self.__lut == Lut.COLOR): # Colored lookup table.
77 lookup_table = LookupTable()
78 lookup_table._setTableValue()
79 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
80 lookup_table = LookupTable()
81 lookup_table._setLookupTableToGreyScale()
82
83 self._setupDataSetMapper(\
84 self.__data_collector._getDataCollectorOutput(), \
85 lookup_table._getLookupTable())
86 self._setScalarBarLookupTable(self._getDataSetMapperLookupTable())
87 self.setOrientationToHorizontal()
88 self._setupActor3D(self._getDataSetMapper())
89 self.setOpacity(0)
90 scene._addActor3D(self.__viewport, self._getActor3D())
91 scene._addActor3D(self.__viewport, self._getScalarBar())
92
93 def _isModified(self):
94 """
95 Return whether the Legend or DataCollector has been modified.
96
97 @rtype: Boolean
98 @return: True or False
99 """
100
101 return self.__modified or self.__data_collector._isModified()
102
103 def _render(self, scene):
104 """
105 Render the legend.
106
107 @type scene: L{Scene <scene.Scene>} object
108 @param scene: Scene in which objects are to be rendered on
109 """
110
111 if (self._isModified() == True):
112 if(self.__data_collector._isScalarSet() == True):
113 self.__data_collector._setActiveScalar()
114
115 # self._isScalarRangeSet checks whether the scalar range has been
116 # specified by the user. If it has, then the scalar range
117 # read from the source will be ignored.
118 if(self.__legend == LegendType.SCALAR and \
119 (not(self._isScalarRangeSet()))):
120 self._setScalarRange(self.__data_collector._getScalarRange())
121 elif(self.__legend == LegendType.VECTOR and \
122 (not(self._isScalarRangeSet()))):
123 self._setScalarRange(self.__data_collector._getVectorRange())
124 self.__modified = False
125
126

  ViewVC Help
Powered by ViewVC 1.1.26