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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2365 - (show annotations)
Mon Apr 6 01:25:25 2009 UTC (10 years, 4 months ago) by gross
File MIME type: text/x-python
File size: 4888 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 position import GlobalPosition
35 from constant import Viewport
36 from esys.escript import getMPISizeWorld
37 if getMPISizeWorld()==1: import vtk
38
39 class Light:
40 """
41 Class that defines a light. A light controls the lighting for the
42 rendered object and works in a similar way to L{Camera <camera.Camera>}.
43 """
44
45 # The SOUTH_WEST default viewport is used when there is only one viewport.
46 # This saves the user from specifying the viewport when there is only one.
47 def __init__(self, scene, viewport = Viewport.SOUTH_WEST):
48 """
49 Initialise the light.
50
51 @type scene: L{Scene <scene.Scene>} object
52 @param scene: Scene in which components are to be added to
53 @type viewport: L{Viewport <constant.Viewport>} constant
54 @param viewport: Viewport in which objects are to be rendered on
55 """
56 if getMPISizeWorld()>1:
57 raise ValueError,"pyvisi.Light is not running on more than one processor."
58
59 self.__viewport = viewport
60 self.__vtk_light = vtk.vtkLight()
61
62 # Keeps track whether light has been modified.
63 self.__modified = True
64 # Keeps track whether the modification to the light was due to the
65 # instantiation. If it is, then __setupLight() method is called.
66 self.__initialization = True
67 scene._addVisualizationModules(self)
68
69 def __setupLight(self, scene):
70 """
71 Set up the light and associate it with the renderer.
72
73 @type scene: L{Scene <scene.Scene>} object
74 @param scene: Scene in which objects are to be rendered on
75 """
76
77 scene._addLight(self.__viewport, self.__vtk_light)
78
79 def setColor(self, color):
80 """
81 Set the light color.
82
83 @type color: L{Color <constant.Color>} constant
84 @param color: Light color
85 """
86
87 self.__vtk_light.SetColor(color)
88 self.__modified = True
89
90 def setFocalPoint(self, position):
91 """
92 Set the focal point of the light.
93
94 @type position: L{GlobalPosition <position.GlobalPosition>} object
95 @param position: Light focal point
96 """
97
98 self.__vtk_light.SetFocalPoint(position._getGlobalPosition())
99 self.__modified = True
100
101 def setPosition(self, position):
102 """
103 Set the position of the light.
104
105 @type position: L{GlobalPosition <position.GlobalPosition>} object
106 @param position: Light position
107 """
108
109 self.__vtk_light.SetPosition(position._getGlobalPosition())
110 self.__modified = True
111
112 # Elevation and azimuth is set to zero so that users do not
113 # have to change both at the same time.
114 def setAngle(self, elevation = 0, azimuth = 0):
115 """
116 An alternative to set the position and focal point of the light
117 by using the elevation and azimuth.
118
119 @type elevation: Number
120 @param elevation: Degree to rotate the light to the top and bottom
121 @type azimuth: Number
122 @param azimuth: Degree to rotate the light to the left and right
123 """
124
125 # NOTE: The elevation angle of light does not appear to suffer the same
126 # constraint as the elevation angle of camera where the elevation
127 # angle is constraint between 90/-90.
128 self.__vtk_light.SetDirectionAngle(elevation, azimuth)
129 self.__modified = True
130
131 def setIntensity(self, intensity):
132 """
133 Set the intensity (brightness) of the light.
134
135 @type intensity: Number
136 @param intensity: Intensity (brightness) of the light
137 """
138
139 self.__vtk_light.SetIntensity(intensity)
140 self.__modified = True
141
142 def _isModified(self):
143 """
144 Return whether the Light has been modified.
145
146 @rtype: Boolean
147 @return: True or False
148 """
149
150 if (self.__modified == True):
151 return True
152 else:
153 return False
154
155 def _render(self, scene):
156 """
157 Render the light.
158
159 @type scene: L{Scene <scene.Scene>} object
160 @param scene: Scene in which objects are to be rendered on
161 """
162
163 if(self._isModified() == True):
164 # Will only be true once only when the light is instantiated.
165 if(self.__initialization == True):
166 self.__setupLight(scene)
167 self.__initialization == False
168
169 self.__modified = False
170
171

  ViewVC Help
Powered by ViewVC 1.1.26