/[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 943 - (show annotations)
Mon Jan 29 07:22:43 2007 UTC (14 years, 9 months ago) by jongui
File MIME type: text/x-python
File size: 2598 byte(s)
new pyvisi files
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 and its settings.
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 the object is 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 self.__scene._addLight(self.__viewport, self.__vtk_light)
41
42 def setColor(self, color):
43 """
44 Set the light color.
45
46 @type color: L{Color <constant.Color>} constant
47 @param color: Light color
48 """
49
50 self.__vtk_light.SetColor(color)
51
52 def setFocalPoint(self, position):
53 """
54 Set the focal point of the light.
55
56 @type position: L{GlobalPosition <position.GlobalPosition>} object
57 @param position: Light focal point
58 """
59
60 self.__vtk_light.SetFocalPoint(position._getGlobalPosition())
61
62 def setPosition(self, position):
63 """
64 Set the position of the light.
65
66 @type position: L{GlobalPosition <position.GlobalPosition>} object
67 @param position: Light position
68 """
69
70 self.__vtk_light.SetPosition(position._getGlobalPosition())
71
72 def setAngle(self, elevation, azimuth):
73 """
74 Set the position and focal point of the light based on elevation and
75 azimuth degree.
76
77 @type elevation: Number
78 @param elevation: Degree to rotate the light to the top and bottom
79 @type azimuth: Number
80 @param azimuth: Degree to rotate the camera to the left and right
81 """
82
83 # NOTE: The elevation angle of light does not seem to suffer the same
84 # constraint as the elevation angle of camera where the elevation
85 # angle is constraint between 90/-90.
86 self.__vtk_light.SetDirectionAngle(elevation, azimuth)
87
88 def setIntensity(self, intensity):
89 """
90 Set the intensity (brightness) of the light.
91
92 @type intensity: Number
93 @param intensity: Intensity (brightness) of the light
94 """
95
96 self.__vtk_light.SetIntensity(intensity)
97

  ViewVC Help
Powered by ViewVC 1.1.26