/[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 1194 - (show annotations)
Thu Jun 14 05:53:49 2007 UTC (13 years, 1 month ago) by jongui
File MIME type: text/x-python
File size: 3692 byte(s)
- Fixed a minor bug in the Camera module.
- Added some extra capability to the Movie module.
- The Camera module now has the capability to perform parallel projection by calling the 'parallelProjectionOn' method.
- The Camera at this stage is only capable of zooming towards the rendered object using 'dolly'. However, it appears that 'dolly' cannot be used to perform zooming out.
1 """
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 def __init__(self, scene, viewport = Viewport.SOUTH_WEST):
18 """
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.__viewport = viewport
28 self.__vtk_light = vtk.vtkLight()
29
30 # Keeps track whether light has been modified.
31 self.__modified = True
32 # Keeps track whether the modification to the light was due to the
33 # instantiation. If it is, then __setupLight() method is called.
34 self.__initialization = True
35 scene._addVisualizationModules(self)
36
37 def __setupLight(self, scene):
38 """
39 Set up the light and associate it with the renderer.
40
41 @type scene: L{Scene <scene.Scene>} object
42 @param scene: Scene in which objects are to be rendered on
43 """
44
45 scene._addLight(self.__viewport, self.__vtk_light)
46
47 def setColor(self, color):
48 """
49 Set the light color.
50
51 @type color: L{Color <constant.Color>} constant
52 @param color: Light color
53 """
54
55 self.__vtk_light.SetColor(color)
56 self.__modified = True
57
58 def setFocalPoint(self, position):
59 """
60 Set the focal point of the light.
61
62 @type position: L{GlobalPosition <position.GlobalPosition>} object
63 @param position: Light focal point
64 """
65
66 self.__vtk_light.SetFocalPoint(position._getGlobalPosition())
67 self.__modified = True
68
69 def setPosition(self, position):
70 """
71 Set the position of the light.
72
73 @type position: L{GlobalPosition <position.GlobalPosition>} object
74 @param position: Light position
75 """
76
77 self.__vtk_light.SetPosition(position._getGlobalPosition())
78 self.__modified = True
79
80 # Elevation and azimuth is set to zero so that users do not
81 # have to change both at the same time.
82 def setAngle(self, elevation = 0, azimuth = 0):
83 """
84 An alternative to set the position and focal point of the light
85 by using the elevation and azimuth.
86
87 @type elevation: Number
88 @param elevation: Degree to rotate the light to the top and bottom
89 @type azimuth: Number
90 @param azimuth: Degree to rotate the light to the left and right
91 """
92
93 # NOTE: The elevation angle of light does not appear to suffer the same
94 # constraint as the elevation angle of camera where the elevation
95 # angle is constraint between 90/-90.
96 self.__vtk_light.SetDirectionAngle(elevation, azimuth)
97 self.__modified = True
98
99 def setIntensity(self, intensity):
100 """
101 Set the intensity (brightness) of the light.
102
103 @type intensity: Number
104 @param intensity: Intensity (brightness) of the light
105 """
106
107 self.__vtk_light.SetIntensity(intensity)
108 self.__modified = True
109
110 def _isModified(self):
111 """
112 Return whether the Light has been modified.
113
114 @rtype: Boolean
115 @return: True or False
116 """
117
118 if (self.__modified == True):
119 return True
120 else:
121 return False
122
123 def _render(self, scene):
124 """
125 Render the light.
126
127 @type scene: L{Scene <scene.Scene>} object
128 @param scene: Scene in which objects are to be rendered on
129 """
130
131 if(self._isModified() == True):
132 # Will only be true once only when the light is instantiated.
133 if(self.__initialization == True):
134 self.__setupLight(scene)
135 self.__initialization == False
136
137 self.__modified = False
138
139

  ViewVC Help
Powered by ViewVC 1.1.26