/[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 1809 - (show annotations)
Thu Sep 25 06:43:44 2008 UTC (12 years, 6 months ago) by ksteube
File MIME type: text/x-python
File size: 4691 byte(s)
Copyright updated in all python files

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

  ViewVC Help
Powered by ViewVC 1.1.26