DirEmittance.h

Go to the documentation of this file.
00001 /* $Id:$ */
00002 
00003 #ifndef __DIR_EMITTANCE_H
00004 #define __DIR_EMITTANCE_H
00005 
00006 #include <esg/emittance/Emittance.h>
00007 #include <esg/geometry/Hemisphere.h>
00008 #include <esg/Definitions.h>
00009 
00010 /*
00011  * Emittance radiating from single point towards half-space defined
00012  * by directional vector and proportionally to the elevation angle.
00013  */
00014 
00015 namespace esg {
00016 
00017 class DirEmittance : public Emittance {
00018 protected:
00019     const Hemisphere _stochasticEmitter;
00020     
00021 protected:
00022     virtual void _duplicate_attributes (const Emittance& src) {
00023         Emittance::_duplicate_attributes(src);
00024     }
00025 
00026     DirEmittance () {}
00027     
00028 public:
00029     DirEmittance (const Vector3&  loc,
00030                   const Vector3&  dir,
00031                   const Color3f&  inten = Color3f(1,1,1),
00032                   double          fadeDist  = .0,
00033                   double          fadePower = .0)
00034         : Emittance(loc, true, dir, true, inten, fadeDist, fadePower),
00035           _stochasticEmitter(Vector3(0.,0.,0.), 1., dir, false) {}
00036 
00037     virtual Emittance* clone () const {
00038         DirEmittance * pRet = new DirEmittance();
00039         pRet->_duplicate_attributes(*this);
00040         return pRet;
00041     }
00042 
00043     virtual bool intensity (const Vector3& v /* view point */,
00044                             Color3f&       c /* intensity  */) const
00045     {
00046         Vector3 dir(v - _location);
00047         float   d = dir.length();
00048         dir.scale(1.0/d);
00049         float cos = _direction.dot(dir);
00050         if (cos <= 0.) return false;
00051         c.set(_intensity);
00052         c.scale(cos);
00053         ESG_ATTENUATION(d,c);
00054         return true;
00055     }
00056 
00057     virtual bool intensity (const Vector3& v /* emittance direction */,
00058                             float          d /* emittance distance  */,
00059                             Color3f&       c /* intensity           */) const
00060     {
00061         float cos = _direction.dot(v);
00062         if (cos <= 0.) return false;
00063         c.set(_intensity);
00064         c.scale(cos);
00065         ESG_ATTENUATION(d,c);
00066         return true;
00067     }
00068 
00069     virtual bool stochasticEmission (Vector3& d) 
00070     {
00071         d.set(_stochasticEmitter.samplePriorToZenith(ESG_DBL_RAND,
00072                                                      ESG_DBL_RAND,
00073                                                      NULL));
00074         return true;
00075     }
00076 };
00077     
00078 }; // namespace
00079 
00080 #endif // __DIR_EMITTANCE_H

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