/[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 2365 - (show annotations)
Mon Apr 6 01:25:25 2009 UTC (10 years, 3 months ago) by gross
File MIME type: text/x-python
File size: 4880 byte(s)
all tests passed under scons on 4 mpi processes with  openmpi on shake34
1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 """
23 @var __author__: name of author
24 @var __copyright__: copyrights
25 @var __license__: licence agreement
26 @var __url__: url entry point on documentation
27 @var __version__: version
28 @var __date__: date of the version
29 """
30
31 __author__="John Ngui, john.ngui@uq.edu.au"
32
33
34 from mapper import DataSetMapper
35 from actor import Actor2D, Actor3D
36 from lookuptable import LookupTable
37 from constant import Viewport, Color, Lut, LegendType
38 from scalarbar import ScalarBar
39 from esys.escript import getMPISizeWorld
40 if getMPISizeWorld()==1: import vtk
41
42 # NOTE: ScalarBarModule, DataSetMapper and Actor3D were inherited to allow
43 # access to their public methods from the driver.
44 class Legend(ScalarBar, DataSetMapper, Actor3D):
45 """
46 Class that shows a scalar field on a domain surface. The domain surface
47 can either be colored or grey-scaled, depending on the lookup table used.
48 """
49
50 # The SOUTH_WEST default viewport is used when there is only one viewport.
51 # This saves the user from specifying the viewport when there is only one.
52 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,\
53 lut = Lut.COLOR, legend = LegendType.SCALAR):
54 """
55 Initialise the Legend.
56
57 @type scene: L{Scene <scene.Scene>} object
58 @param scene: Scene in which objects are to be rendered on
59 @type data_collector: L{DataCollector <datacollector.DataCollector>}
60 object
61 @param data_collector: Deal with source of data for vizualisation
62 @type viewport: L{Viewport <constant.Viewport>} constant
63 @param viewport: Viewport in which objects are to be rendered on
64 @type lut : L{Lut <constant.Lut>} constant
65 @param lut: Lookup table color scheme
66 @type legend: L{Lut <constant.LegendType>} constant
67 @param legend: Type of legend
68 """
69
70 self.__data_collector = data_collector
71 self.__viewport = viewport
72 self.__lut = lut
73 self.__legend = legend
74
75 self.__modified = True # Keeps track whether Legend has been modified.
76 ScalarBar.__init__(self)
77
78 # NOTE: DataSetMapper and Actor3D were required in order for the
79 # scalar bar to be colored. If the mapper and actor were not used,
80 # the scalar bar will be black in color.
81 DataSetMapper.__init__(self)
82 Actor3D.__init__(self)
83 scene._addVisualizationModules(self)
84
85 # ----- Scalar Bar -----
86
87 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
88 # before DataSetMapper. If it is done after DataSetMapper, no effect
89 # will take place.
90 if(self.__lut == Lut.COLOR): # Colored lookup table.
91 lookup_table = LookupTable()
92 lookup_table._setTableValue()
93 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
94 lookup_table = LookupTable()
95 lookup_table._setLookupTableToGreyScale()
96
97 self._setupDataSetMapper(\
98 self.__data_collector._getDataCollectorOutput(), \
99 lookup_table._getLookupTable())
100 self._setScalarBarLookupTable(self._getDataSetMapperLookupTable())
101 self.setOrientationToHorizontal()
102 self._setupActor3D(self._getDataSetMapper())
103 self.setOpacity(0)
104 scene._addActor3D(self.__viewport, self._getActor3D())
105 scene._addActor3D(self.__viewport, self._getScalarBar())
106
107 def _isModified(self):
108 """
109 Return whether the Legend or DataCollector has been modified.
110
111 @rtype: Boolean
112 @return: True or False
113 """
114
115 return self.__modified or self.__data_collector._isModified()
116
117 def _render(self, scene):
118 """
119 Render the legend.
120
121 @type scene: L{Scene <scene.Scene>} object
122 @param scene: Scene in which objects are to be rendered on
123 """
124
125 if (self._isModified() == True):
126 if(self.__data_collector._isScalarSet() == True):
127 self.__data_collector._setActiveScalar()
128
129 # self._isScalarRangeSet checks whether the scalar range has been
130 # specified by the user. If it has, then the scalar range
131 # read from the source will be ignored.
132 if(self.__legend == LegendType.SCALAR and \
133 (not(self._isScalarRangeSet()))):
134 self._setScalarRange(self.__data_collector._getScalarRange())
135 elif(self.__legend == LegendType.VECTOR and \
136 (not(self._isScalarRangeSet()))):
137 self._setScalarRange(self.__data_collector._getVectorRange())
138 self.__modified = False
139
140

  ViewVC Help
Powered by ViewVC 1.1.26