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