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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (hide annotations)
Thu Jan 28 02:03:15 2010 UTC (11 years, 2 months ago) by jfenwick
File MIME type: text/x-python
File size: 4733 byte(s)
Don't panic.
Updating copyright stamps

1 ksteube 1809
2     ########################################################
3     #
4 jfenwick 2881 # Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1809 # 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 jfenwick 2881 __copyright__="""Copyright (c) 2003-2010 by University of Queensland
15 ksteube 1809 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 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
21 ksteube 1809
22 ksteube 1147 """
23 jfenwick 2625 :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 ksteube 1147 """
30    
31 jongui 1197 __author__="John Ngui, john.ngui@uq.edu.au"
32    
33    
34 ksteube 1147 from position import GlobalPosition
35     from constant import Viewport
36 gross 2313 from esys.escript import getMPISizeWorld
37 gross 2365 if getMPISizeWorld()==1: import vtk
38 ksteube 1147
39     class Light:
40     """
41     Class that defines a light. A light controls the lighting for the
42 jfenwick 2625 rendered object and works in a similar way to `Camera`.
43 ksteube 1147 """
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 jongui 1148 def __init__(self, scene, viewport = Viewport.SOUTH_WEST):
48 ksteube 1147 """
49     Initialise the light.
50    
51 jfenwick 2625 :type scene: `Scene` object
52     :param scene: Scene in which components are to be added to
53     :type viewport: `Viewport` constant
54     :param viewport: Viewport in which objects are to be rendered on
55 ksteube 1147 """
56 gross 2313 if getMPISizeWorld()>1:
57     raise ValueError,"pyvisi.Light is not running on more than one processor."
58 ksteube 1147
59     self.__viewport = viewport
60     self.__vtk_light = vtk.vtkLight()
61    
62 jongui 1148 # 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 jongui 1158 scene._addVisualizationModules(self)
68 ksteube 1147
69 jongui 1158 def __setupLight(self, scene):
70 ksteube 1147 """
71     Set up the light and associate it with the renderer.
72 jongui 1158
73 jfenwick 2625 :type scene: `Scene` object
74     :param scene: Scene in which objects are to be rendered on
75 ksteube 1147 """
76    
77 jongui 1158 scene._addLight(self.__viewport, self.__vtk_light)
78 ksteube 1147
79     def setColor(self, color):
80     """
81     Set the light color.
82    
83 jfenwick 2625 :type color: `Color` constant
84     :param color: Light color
85 ksteube 1147 """
86    
87     self.__vtk_light.SetColor(color)
88 jongui 1148 self.__modified = True
89 ksteube 1147
90     def setFocalPoint(self, position):
91     """
92     Set the focal point of the light.
93    
94 jfenwick 2625 :type position: `GlobalPosition` object
95     :param position: Light focal point
96 ksteube 1147 """
97    
98     self.__vtk_light.SetFocalPoint(position._getGlobalPosition())
99 jongui 1148 self.__modified = True
100 ksteube 1147
101     def setPosition(self, position):
102     """
103     Set the position of the light.
104    
105 jfenwick 2625 :type position: `GlobalPosition` object
106     :param position: Light position
107 ksteube 1147 """
108    
109     self.__vtk_light.SetPosition(position._getGlobalPosition())
110 jongui 1148 self.__modified = True
111 ksteube 1147
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 jfenwick 2625 :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 ksteube 1147 """
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 jongui 1148 self.__modified = True
130 ksteube 1147
131     def setIntensity(self, intensity):
132     """
133     Set the intensity (brightness) of the light.
134    
135 jfenwick 2625 :type intensity: Number
136     :param intensity: Intensity (brightness) of the light
137 ksteube 1147 """
138    
139     self.__vtk_light.SetIntensity(intensity)
140 jongui 1148 self.__modified = True
141 ksteube 1147
142 jongui 1148 def _isModified(self):
143     """
144     Return whether the Light has been modified.
145    
146 jfenwick 2625 :rtype: Boolean
147     :return: True or False
148 jongui 1148 """
149    
150     if (self.__modified == True):
151     return True
152     else:
153     return False
154    
155 jongui 1158 def _render(self, scene):
156 jongui 1148 """
157     Render the light.
158 jongui 1158
159 jfenwick 2625 :type scene: `Scene` object
160     :param scene: Scene in which objects are to be rendered on
161 jongui 1148 """
162    
163     if(self._isModified() == True):
164     # Will only be true once only when the light is instantiated.
165     if(self.__initialization == True):
166 jongui 1158 self.__setupLight(scene)
167 jongui 1148 self.__initialization == False
168    
169 jongui 1194 self.__modified = False
170 jongui 1148
171    

  ViewVC Help
Powered by ViewVC 1.1.26