Emittance.h

Go to the documentation of this file.
00001 /* $Id:$ */
00002 
00003 #ifndef __EMITTANCE_H
00004 #define __EMITTANCE_H
00005 
00006 #include <esg/Definitions.h>
00007 #include <esg/ESGObject.h>
00008 #include <esg/Export>
00009 
00010 /*
00011  * Emission of energy in given direction (point)
00012  *
00013  * The _fadeDistance is used to specify the distance at which the full light
00014  * intensity arrives. The actual attenuation is described by the _fadePower,
00015  * which determines the falloff rate. For example linear or quadratic falloff
00016  * can be used by setting _fadePower to 1 or 2 respectively.
00017  * The complete formula to calculate the factor by which the light is
00018  * attenuated is:
00019  *
00020  * attenuation = 1.0 if _fadeDistance <= 0 or _fadePower <= 0
00021  *             = 1.0 if actual distance is less then _fadeDistance
00022  *             = 2/(1+(dist/_fadeDisstance)^_fadePower) otherwise
00023  *
00024  * You should note two important facts: First, for _fadeDistance larger than
00025  * one the light intensity at distances smaller than _fadeDistance actually
00026  * increases. This is necessary to get the light source color if the distance
00027  * traveled equals the _fadeDistance.
00028  *
00029  * Energy source can be either fixed, i.e. emitting photons according to
00030  * its fixed location/direction, or it can be transformed to fit the geometry
00031  * of light source.
00032  */
00033 
00034 namespace esg {
00035 
00036 class OGSCENE_EXPORT Emittance : public ESGObject {
00037 protected:
00038     Vector3 _location;  
00039     bool    _haveLocation;
00040     Vector3 _direction; 
00041     bool    _haveDirection;
00042     Color3f _intensity;
00043     double  _fadeDistance;  // distance w/o attenuation
00044     double  _fadePower;     // attenuation speed (0=off, 1=linear, 2=quadratic)
00045     bool    _attenuate;     // whether to attenuate or not
00046     bool    _fitToGeometry; 
00047 
00048 protected:
00049     virtual void _duplicate_attributes (const Emittance& src) {
00050         _intensity.set(((Emittance&)src)._intensity);
00051         _direction.set(((Emittance&)src)._direction);
00052         _location.set(((Emittance&)src)._location);
00053         _haveLocation  = ((Emittance&)src)._haveLocation;
00054         _haveDirection = ((Emittance&)src)._haveDirection;
00055         _fadeDistance  = ((Emittance&)src)._fadeDistance;
00056         _fadePower     = ((Emittance&)src)._fadePower;
00057         _attenuate     = ((Emittance&)src)._attenuate;
00058     }
00059 
00060     Emittance () {}
00061 
00062 public:
00063     Emittance (const Vector3&  loc,
00064                bool            haveLoc,
00065                const Vector3&  dir,
00066                bool            haveDir,
00067                const Color3f&  inten = Color3f(1,1,1),
00068                double          fadeDist  = .0,
00069                double          fadePower = .0,
00070                bool            fitToGeom = true)
00071         : _location(loc), _haveLocation(haveLoc),
00072           _direction(dir), _haveDirection(haveDir),
00073           _intensity(inten),
00074           _fadeDistance(fadeDist),
00075           _fadePower(fadePower),
00076           _attenuate((_fadeDistance >= .0 && _fadePower > .0) ? true : false),
00077           _fitToGeometry(fitToGeom) {}
00078 
00079     virtual ~Emittance () {}
00080 
00081     virtual Emittance* clone () const = 0;
00082 
00083             bool intensity (Color3f& c) const {c.set(_intensity); return true;}
00084     virtual bool intensity (const Vector3& /* view point */,
00085                             Color3f&       /* intensity  */) const = 0;
00086     virtual bool intensity (const Vector3& /* emittance direction */,
00087                             float          /* emittance distance  */,
00088                             Color3f&       /* intensity           */) const=0;
00089 
00090     virtual bool stochasticEmission (Vector3& /* stochastic dir. */) = 0;
00091 
00092 
00093     bool beamDirection (Vector3& d) const {
00094         if (_haveDirection) d.set(_direction);
00095         return _haveDirection;
00096     }
00097 
00098     bool setBeamDirection (const Vector3& d) {
00099         if (_haveDirection) _direction.set(d);
00100         return _haveDirection;
00101     }
00102 
00103     bool sourceLocation (Vector3& v) const {
00104         if (_haveLocation) v.set(_location);
00105         return _haveLocation;
00106     }
00107 
00108     bool setSourceLocation (const Vector3& v) {
00109         if (_haveLocation) _location.set(v);
00110         return _haveLocation;
00111     }
00112 
00113     bool haveLocation  (void) const { return _haveLocation;  }
00114     bool haveDirection (void) const { return _haveDirection; }
00115     bool fitToGeometry (void) const { return _fitToGeometry; }
00116 
00117     double fadeDistance (void) const { return _fadeDistance; }
00118     double fadePower    (void) const { return _fadePower;    }
00119 };
00120 
00121 
00122 #define ESG_ATTENUATION(__d, __c) { \
00123    if (_attenuate && (__d > _fadeDistance)) \
00124       (__c).scale(2.0 / (1.0 + pow(((_fadeDistance > 0.) ? (__d) / _fadeDistance : (__d)), _fadePower))); }
00125     
00126 }; // namespace
00127 
00128 #endif // __EMITTANCE_H

Generated on Wed Jun 28 12:24:28 2006 for esg by  doxygen 1.4.6