Point Cloud Library (PCL)  1.14.1-dev
opennurbs_light.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(OPENNURBS_LIGHT_INC_)
18 #define OPENNURBS_LIGHT_INC_
19 
20 class ON_CLASS ON_Light : public ON_Geometry
21 {
22  ON_OBJECT_DECLARE(ON_Light);
23 
24 public:
27  // C++ defaults work fine
28  //ON_Light& operator=(const ON_Light&);
29  //ON_Light(const ON_Light&);
30 
31  /////////////////////////////////////////////////////////////////
32  //
33  // ON_Object virtual functions
34  //
35 
36  /*
37  Description:
38  Tests an object to see if its data members are correctly
39  initialized.
40  Parameters:
41  text_log - [in] if the object is not valid and text_log
42  is not NULL, then a brief englis description of the
43  reason the object is not valid is appened to the log.
44  The information appended to text_log is suitable for
45  low-level debugging purposes by programmers and is
46  not intended to be useful as a high level user
47  interface tool.
48  Returns:
49  @untitled table
50  true object is valid
51  false object is invalid, uninitialized, etc.
52  Remarks:
53  Overrides virtual ON_Object::IsValid
54  */
55  ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
56 
57  void Dump( ON_TextLog& ) const; // for debugging
58 
59  // Use ON_BinaryArchive::WriteObject() and ON_BinaryArchive::ReadObject()
60  // for top level serialization. These Read()/Write() members should just
61  // write/read specific definitions. In particular, they should not write/
62  // read any chunk typecode or length information. The default
63  // implementations return false and do nothing.
64  ON_BOOL32 Write(
65  ON_BinaryArchive& // serialize definition to binary archive
66  ) const;
67 
68  ON_BOOL32 Read(
69  ON_BinaryArchive& // restore definition from binary archive
70  );
71 
72  ON::object_type ObjectType() const;
73 
74  // virtual
76 
77 
78  /////////////////////////////////////////////////////////////////
79  //
80  // ON_Geometry virtual functions
81  //
82  int Dimension() const;
83 
84  ON_BOOL32 GetBBox( // returns true if successful
85  double*, // boxmin[dim]
86  double*, // boxmax[dim]
87  ON_BOOL32 = false // true means grow box
88  ) const;
89 
90  ON_BOOL32 Transform(
91  const ON_Xform&
92  );
93 
94  /////////////////////////////////////////////////////////
95  //
96  // Interface
97  //
98 
99  void Default(); // make default light
100 
101  /////////////////////////////////////////////////////////
102  //
103  // turn light on/off
104  //
105  ON_BOOL32 Enable( ON_BOOL32 = true ); // returns previous state
106  ON_BOOL32 IsEnabled() const;
107 
108  /////////////////////////////////////////////////////////
109  //
110  // style, location, and direction
111  // direction is ignored for "point" and "ambient" lights
112  // location is ignored for "directional" and "ambient" lights
113  void SetStyle(ON::light_style);
114  ON::light_style Style() const;
115 
116  ON_BOOL32 IsPointLight() const;
117  ON_BOOL32 IsDirectionalLight() const;
118  ON_BOOL32 IsSpotLight() const;
119  ON_BOOL32 IsLinearLight() const;
120  ON_BOOL32 IsRectangularLight() const;
121 
122  ON::coordinate_system CoordinateSystem() const; // determined by style
123 
124  /*
125  Description:
126  A light's location and direction can be defined with respect
127  to world, camera, or view coordinates. GetLightXform gets
128  the transformation from the light's intrinsic coordinate
129  system to the destination coordinate system specified
130  by dest_cs.
131  Parameters:
132  vp - [in] viewport where light is being used
133  dest_cs - [in] destination coordinate system
134  xform - [out] transformation from the light's intrinsic
135  coordinate system to cs.
136  Returns:
137  true if successful.
138  */
139  ON_BOOL32 GetLightXform(
140  const ON_Viewport& vp,
141  ON::coordinate_system dest_cs,
142  ON_Xform& xform
143  ) const;
144 
145  void SetLocation( const ON_3dPoint& );
146  void SetDirection( const ON_3dVector& );
147 
151 
152  double Intensity() const; // 0.0 = 0% 1.0 = 100%
153  void SetIntensity(double);
154 
155  double PowerWatts() const;
156  double PowerLumens() const;
157  double PowerCandela() const;
158 
159  void SetPowerWatts( double );
160  void SetPowerLumens( double );
161  void SetPowerCandela( double );
162 
163  /////////////////////////////////////////////////////////
164  //
165  // colors
166  //
170  ON_Color Ambient() const;
171  ON_Color Diffuse() const;
173 
174  /////////////////////////////////////////////////////////
175  //
176  // attenuation settings (ignored for "directional" and "ambient" lights)
177  // attenuation = 1/(a[0] + d*a[1] + d^2*a[2]) where d = distance to light
178  //
179  void SetAttenuation(double,double,double);
182  double Attenuation(double) const; // computes 1/(a[0] + d*a[1] + d^2*a[2]) where d = argument
183  // returns 0 if a[0] + d*a[1] + d^2*a[2] <= 0
184 
185  /////////////////////////////////////////////////////////
186  //
187  // spot light parameters (ignored for non-spot lights)
188  //
189  // angle = 0 to 90 degrees
190  // exponent = 0 to 128 (0=uniform, 128=high focus)
191  //
192  void SetSpotAngleDegrees( double );
193  double SpotAngleDegrees() const;
194 
195  void SetSpotAngleRadians( double );
196  double SpotAngleRadians() const;
197 
198  //////////
199  // The spot exponent varies from 0.0 to 128.0 and provides
200  // an exponential interface for controling the focus or
201  // concentration of a spotlight (like the
202  // OpenGL GL_SPOT_EXPONENT parameter). The spot exponent
203  // and hot spot parameters are linked; changing one will
204  // change the other.
205  // A hot spot setting of 0.0 corresponds to a spot exponent of 128.
206  // A hot spot setting of 1.0 corresponds to a spot exponent of 0.0.
207  void SetSpotExponent( double );
208  double SpotExponent() const;
209 
210  //////////
211  // The hot spot setting runs from 0.0 to 1.0 and is used to
212  // provides a linear interface for controling the focus or
213  // concentration of a spotlight.
214  // A hot spot setting of 0.0 corresponds to a spot exponent of 128.
215  // A hot spot setting of 1.0 corresponds to a spot exponent of 0.0.
216  void SetHotSpot( double );
217  double HotSpot() const;
218 
219  // The spotlight radii are useful for display UI.
220  bool GetSpotLightRadii( double* inner_radius, double* outer_radius ) const;
221 
222 
223  /////////////////////////////////////////////////////////
224  //
225  // linear and rectangular light parameters
226  // (ignored for non-linear/rectangular lights)
227  //
228  void SetLength( const ON_3dVector& );
230 
231  void SetWidth( const ON_3dVector& );
233 
234  /////////////////////////////////////////////////////////
235  //
236  // shadow parameters (ignored for non-spot lights)
237  //
238  // shadow intensity 0.0 = does not cast any shadows
239  // 1.0 = casts black shadows
240  //
241  void SetShadowIntensity(double);
242  double ShadowIntensity() const;
243 
244 
245  /////////////////////////////////////////////////////////
246  //
247  // light index
248  //
249  void SetLightIndex( int );
250  int LightIndex() const;
251 
252  /////////////////////////////////////////////////////////
253  //
254  // light name
255  //
256  void SetLightName( const char* );
257  void SetLightName( const wchar_t* );
258  const ON_wString& LightName() const;
259 
260 public:
264 
265  ON_BOOL32 m_bOn; // true if light is on
266  ON::light_style m_style; // style of light
267 
271 
272  ON_3dVector m_direction; // ignored for "point" and "ambient" lights
273  ON_3dPoint m_location; // ignored for "directional" and "ambient" lights
274  ON_3dVector m_length; // only for linear and rectangular lights
275  // ends of linear lights are m_location and m_location+m_length
276  ON_3dVector m_width; // only for rectangular lights
277  // corners of rectangular lights are m_location, m_location+m_length,
278  // m_location+m_width, m_location+m_width+m_length
279 
280  double m_intensity; // Linear dimming/brightening factor: 0.0 = off, 1.0 = 100%.
281  // Values < 0.0 and values > 1.0 are permitted but are
282  // not consistently interpreted by various renderers.
283  // Renderers should clamp the range to [0.0, 1.0] if their
284  // lighting model does not support more exotic interpretations
285  // of m_intensity.
286  double m_watts; // Used by lighting models that reference lighting fixtures.
287  // Values < 0.0 are invalid. If m_watts is 0.0, the
288  // value is ignored.
289 
290  // spot settings - ignored for non-spot lights
291  double m_spot_angle; // 0.0 to 90.0
292  double m_spot_exponent; // 0.0 to 128.0
293  // 0.0 = uniform
294  // 128.0 = high focus
295  double m_hotspot; // 0.0 to 1.0 (See SetHotSpot() for details)
296 
297  // attenuation settings - ignored for "directional" and "ambient" lights
298  ON_3dVector m_attenuation; // each entry >= 0.0
299  // att = 1/(a[0] + d*a[1] + d^2*a[2])
300  // where d = distance to light
301 
302  // shawdow casting
303  double m_shadow_intensity; // 0.0 = no shadow casting, 1.0 = full shadow casting
304 };
305 
306 
307 
308 #endif
double SpotExponent() const
ON_3dVector Direction() const
ON::light_style m_style
void SetDirection(const ON_3dVector &)
void SetAmbient(ON_Color)
void SetPowerCandela(double)
double m_spot_exponent
ON::coordinate_system CoordinateSystem() const
ON_3dPoint m_location
ON_3dPoint Location() const
ON_Color m_specular
double Attenuation(double) const
void Dump(ON_TextLog &) const
void SetWidth(const ON_3dVector &)
double m_spot_angle
void SetLength(const ON_3dVector &)
ON_UUID m_light_id
ON_BOOL32 Write(ON_BinaryArchive &) const
double m_watts
void SetLightName(const wchar_t *)
void SetPowerWatts(double)
ON_3dVector m_attenuation
ON_3dVector m_direction
double SpotAngleDegrees() const
void SetShadowIntensity(double)
ON::object_type ObjectType() const
double m_hotspot
double SpotAngleRadians() const
ON_3dVector Width() const
ON_3dVector m_length
void SetHotSpot(double)
ON_BOOL32 Enable(ON_BOOL32=true)
ON_BOOL32 IsDirectionalLight() const
ON_BOOL32 IsEnabled() const
ON_BOOL32 Transform(const ON_Xform &)
ON_Color m_ambient
ON_Color Ambient() const
void SetStyle(ON::light_style)
void SetPowerLumens(double)
double m_shadow_intensity
ON_3dVector PerpindicularDirection() const
double m_intensity
ON_UUID ModelObjectId() const
void SetDiffuse(ON_Color)
ON_BOOL32 GetLightXform(const ON_Viewport &vp, ON::coordinate_system dest_cs, ON_Xform &xform) const
ON_3dVector Length() const
ON_BOOL32 GetBBox(double *, double *, ON_BOOL32=false) const
ON_BOOL32 IsSpotLight() const
ON_3dVector Attenuation() const
void SetSpotAngleDegrees(double)
void SetSpecular(ON_Color)
ON_Color m_diffuse
void SetLocation(const ON_3dPoint &)
ON_BOOL32 IsRectangularLight() const
ON_3dVector m_width
double ShadowIntensity() const
void SetSpotAngleRadians(double)
double PowerLumens() const
void SetAttenuation(double, double, double)
void SetSpotExponent(double)
bool GetSpotLightRadii(double *inner_radius, double *outer_radius) const
ON_Color Diffuse() const
ON_BOOL32 IsPointLight() const
int Dimension() const
int LightIndex() const
double Intensity() const
void SetLightName(const char *)
void Default()
void SetAttenuation(const ON_3dVector &)
void SetLightIndex(int)
ON_BOOL32 Read(ON_BinaryArchive &)
double PowerCandela() const
ON_BOOL32 m_bOn
ON_wString m_light_name
double PowerWatts() const
ON::light_style Style() const
void SetIntensity(double)
const ON_wString & LightName() const
ON_Color Specular() const
ON_BOOL32 IsValid(ON_TextLog *text_log=NULL) const
double HotSpot() const
ON_BOOL32 IsLinearLight() const