/[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 2881 - (show annotations)
Thu Jan 28 02:03:15 2010 UTC (11 years, 1 month ago) by jfenwick
File MIME type: text/x-python
File size: 4754 byte(s)
Don't panic.
Updating copyright stamps

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2010 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-2010 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: `Scene` object
58 :param scene: Scene in which objects are to be rendered on
59 :type data_collector: `DataCollector` object
60 :param data_collector: Deal with source of data for vizualisation
61 :type viewport: `Viewport` constant
62 :param viewport: Viewport in which objects are to be rendered on
63 :type lut: `Lut` constant
64 :param lut: Lookup table color scheme
65 :type legend: `Lut` constant
66 :param legend: Type of legend
67 """
68
69 self.__data_collector = data_collector
70 self.__viewport = viewport
71 self.__lut = lut
72 self.__legend = legend
73
74 self.__modified = True # Keeps track whether Legend has been modified.
75 ScalarBar.__init__(self)
76
77 # NOTE: DataSetMapper and Actor3D were required in order for the
78 # scalar bar to be colored. If the mapper and actor were not used,
79 # the scalar bar will be black in color.
80 DataSetMapper.__init__(self)
81 Actor3D.__init__(self)
82 scene._addVisualizationModules(self)
83
84 # ----- Scalar Bar -----
85
86 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
87 # before DataSetMapper. If it is done after DataSetMapper, no effect
88 # will take place.
89 if(self.__lut == Lut.COLOR): # Colored lookup table.
90 lookup_table = LookupTable()
91 lookup_table._setTableValue()
92 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
93 lookup_table = LookupTable()
94 lookup_table._setLookupTableToGreyScale()
95
96 self._setupDataSetMapper(\
97 self.__data_collector._getDataCollectorOutput(), \
98 lookup_table._getLookupTable())
99 self._setScalarBarLookupTable(self._getDataSetMapperLookupTable())
100 self.setOrientationToHorizontal()
101 self._setupActor3D(self._getDataSetMapper())
102 self.setOpacity(0)
103 scene._addActor3D(self.__viewport, self._getActor3D())
104 scene._addActor3D(self.__viewport, self._getScalarBar())
105
106 def _isModified(self):
107 """
108 Return whether the Legend or DataCollector has been modified.
109
110 :rtype: Boolean
111 :return: True or False
112 """
113
114 return self.__modified or self.__data_collector._isModified()
115
116 def _render(self, scene):
117 """
118 Render the legend.
119
120 :type scene: `Scene` object
121 :param scene: Scene in which objects are to be rendered on
122 """
123
124 if (self._isModified() == True):
125 if(self.__data_collector._isScalarSet() == True):
126 self.__data_collector._setActiveScalar()
127
128 # self._isScalarRangeSet checks whether the scalar range has been
129 # specified by the user. If it has, then the scalar range
130 # read from the source will be ignored.
131 if(self.__legend == LegendType.SCALAR and \
132 (not(self._isScalarRangeSet()))):
133 self._setScalarRange(self.__data_collector._getScalarRange())
134 elif(self.__legend == LegendType.VECTOR and \
135 (not(self._isScalarRangeSet()))):
136 self._setScalarRange(self.__data_collector._getVectorRange())
137 self.__modified = False
138
139

  ViewVC Help
Powered by ViewVC 1.1.26