/[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 948 - (show annotations)
Thu Feb 1 07:23:34 2007 UTC (13 years, 6 months ago) by jongui
File MIME type: text/x-python
File size: 2725 byte(s)
fixed some bugs in pyvisi and added more epydocs.
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.
12 """
13
14 # The SOUTH_WEST default viewport is used when there is only one viewport.
15 # This saves the user from specifying the viewport when there is only one.
16 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST):
17 """
18 Initialise the light.
19
20 @type scene: L{Scene <scene.Scene>} object
21 @param scene: Scene in which components are to be added to
22 @type data_collector: L{DataCollector <datacollector.DataCollector>}
23 object
24 @param data_collector: Source of data for visualization
25 @type viewport: L{Viewport <constant.Viewport>} constant
26 @param viewport: Viewport in which objects are to be rendered on
27 """
28
29 self.__scene = scene
30 self.__data_collector = data_collector
31 self.__viewport = viewport
32 self.__vtk_light = vtk.vtkLight()
33
34 self.__setupLight()
35
36 def __setupLight(self):
37 """
38 Set up the light and associate it with the renderer.
39 """
40
41 self.__scene._addLight(self.__viewport, self.__vtk_light)
42
43 def setColor(self, color):
44 """
45 Set the light color.
46
47 @type color: L{Color <constant.Color>} constant
48 @param color: Light color
49 """
50
51 self.__vtk_light.SetColor(color)
52
53 def setFocalPoint(self, position):
54 """
55 Set the focal point of the light.
56
57 @type position: L{GlobalPosition <position.GlobalPosition>} object
58 @param position: Light focal point
59 """
60
61 self.__vtk_light.SetFocalPoint(position._getGlobalPosition())
62
63 def setPosition(self, position):
64 """
65 Set the position of the light.
66
67 @type position: L{GlobalPosition <position.GlobalPosition>} object
68 @param position: Light position
69 """
70
71 self.__vtk_light.SetPosition(position._getGlobalPosition())
72
73 # Elevation and azimuth was set to zero so that users do not necessarily
74 # need to always change both at the same time.
75 def setAngle(self, elevation = 0, azimuth = 0):
76 """
77 Set the position and focal point of the light based on the specified
78 elevation and azimuth degrees.
79
80 @type elevation: Number
81 @param elevation: Degree to rotate the light to the top and bottom
82 @type azimuth: Number
83 @param azimuth: Degree to rotate the light to the left and right
84 """
85
86 # NOTE: The elevation angle of light does not seem to suffer the same
87 # constraint as the elevation angle of camera where the elevation
88 # angle is constraint between 90/-90.
89 self.__vtk_light.SetDirectionAngle(elevation, azimuth)
90
91 def setIntensity(self, intensity):
92 """
93 Set the intensity (brightness) of the light.
94
95 @type intensity: Number
96 @param intensity: Intensity (brightness) of the light
97 """
98
99 self.__vtk_light.SetIntensity(intensity)
100

  ViewVC Help
Powered by ViewVC 1.1.26