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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1148 - (hide annotations)
Wed May 16 22:45:33 2007 UTC (14 years ago) by jongui
Original Path: trunk/pyvisi/py_src/light.py
File MIME type: text/x-python
File size: 3498 byte(s)
Added the updated files for pyvisi and removed some incorrect reference images.
1 ksteube 1147 """
2     @author: John NGUI
3     """
4    
5     import vtk
6     from position import GlobalPosition
7     from constant import Viewport
8    
9     class Light:
10     """
11     Class that defines a light. A light controls the lighting for the
12     rendered object and works in a similar way to L{Camera <camera.Camera>}.
13     """
14    
15     # The SOUTH_WEST default viewport is used when there is only one viewport.
16     # This saves the user from specifying the viewport when there is only one.
17 jongui 1148 def __init__(self, scene, viewport = Viewport.SOUTH_WEST):
18 ksteube 1147 """
19     Initialise the light.
20    
21     @type scene: L{Scene <scene.Scene>} object
22     @param scene: Scene in which components are to be added to
23     @type viewport: L{Viewport <constant.Viewport>} constant
24     @param viewport: Viewport in which objects are to be rendered on
25     """
26    
27     self.__scene = scene
28     self.__viewport = viewport
29     self.__vtk_light = vtk.vtkLight()
30    
31 jongui 1148 # Keeps track whether light has been modified.
32     self.__modified = True
33     # Keeps track whether the modification to the light was due to the
34     # instantiation. If it is, then __setupLight() method is called.
35     self.__initialization = True
36     self.__scene._addVisualizationModules(self)
37 ksteube 1147
38     def __setupLight(self):
39     """
40     Set up the light and associate it with the renderer.
41     """
42    
43     self.__scene._addLight(self.__viewport, self.__vtk_light)
44    
45     def setColor(self, color):
46     """
47     Set the light color.
48    
49     @type color: L{Color <constant.Color>} constant
50     @param color: Light color
51     """
52    
53     self.__vtk_light.SetColor(color)
54 jongui 1148 self.__modified = True
55 ksteube 1147
56     def setFocalPoint(self, position):
57     """
58     Set the focal point of the light.
59    
60     @type position: L{GlobalPosition <position.GlobalPosition>} object
61     @param position: Light focal point
62     """
63    
64     self.__vtk_light.SetFocalPoint(position._getGlobalPosition())
65 jongui 1148 self.__modified = True
66 ksteube 1147
67     def setPosition(self, position):
68     """
69     Set the position of the light.
70    
71     @type position: L{GlobalPosition <position.GlobalPosition>} object
72     @param position: Light position
73     """
74    
75     self.__vtk_light.SetPosition(position._getGlobalPosition())
76 jongui 1148 self.__modified = True
77 ksteube 1147
78     # Elevation and azimuth is set to zero so that users do not
79     # have to change both at the same time.
80     def setAngle(self, elevation = 0, azimuth = 0):
81     """
82     An alternative to set the position and focal point of the light
83     by using the elevation and azimuth.
84    
85     @type elevation: Number
86     @param elevation: Degree to rotate the light to the top and bottom
87     @type azimuth: Number
88     @param azimuth: Degree to rotate the light to the left and right
89     """
90    
91     # NOTE: The elevation angle of light does not appear to suffer the same
92     # constraint as the elevation angle of camera where the elevation
93     # angle is constraint between 90/-90.
94     self.__vtk_light.SetDirectionAngle(elevation, azimuth)
95 jongui 1148 self.__modified = True
96 ksteube 1147
97     def setIntensity(self, intensity):
98     """
99     Set the intensity (brightness) of the light.
100    
101     @type intensity: Number
102     @param intensity: Intensity (brightness) of the light
103     """
104    
105     self.__vtk_light.SetIntensity(intensity)
106 jongui 1148 self.__modified = True
107 ksteube 1147
108 jongui 1148 def _isModified(self):
109     """
110     Return whether the Light has been modified.
111    
112     @rtype: Boolean
113     @return: True or False
114     """
115    
116     if (self.__modified == True):
117     return True
118     else:
119     return False
120    
121     def _render(self):
122     """
123     Render the light.
124     """
125    
126     if(self._isModified() == True):
127     # Will only be true once only when the light is instantiated.
128     if(self.__initialization == True):
129     self.__setupLight()
130     self.__initialization == False
131    
132     self.__isModified = False
133    
134    

  ViewVC Help
Powered by ViewVC 1.1.26