EmitterSampler.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  EmitterSampler
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       Sampler which selects a point on an emitter (light source) in the scene 
00009    with probability proportional to radiant exitance.
00010    <!-------------------------------------------------------------------->**/
00011 
00012 #ifndef EMITTER_SAMPLER_H_
00013 #define EMITTER_SAMPLER_H_
00014 
00015 #include <stats/Sampler.h>
00016 
00017 class ShapeSet;
00018 class Scene;
00019 
00020 class EmitterSampler : public Sampler {
00021    
00022    public:
00023       ///@name Constructors
00024       //@{-----------------------------------------------------------------
00025       
00026       inline EmitterSampler(Scene *scene)
00027          : Sampler(), m_scene(scene), m_lights(NULL), m_cdf(NULL), m_n(0)
00028       { }
00029       
00030       inline EmitterSampler(const EmitterSampler &copy)
00031          : Sampler(copy), m_scene(copy.m_scene), m_lights(copy.m_lights), 
00032            m_cdf(NULL), m_n(copy.m_n), m_area(copy.m_area)
00033       {
00034          m_cdf = new real_t[m_n];
00035          memcpy(m_cdf, copy.m_cdf, sizeof(real_t) * m_n);
00036       }
00037       
00038       virtual ~EmitterSampler() {
00039          safeDeleteArray(m_cdf);
00040       }
00041       
00042       
00043       //@}-----------------------------------------------------------------
00044       ///@name Initialization
00045       //@{-----------------------------------------------------------------
00046       
00047       /**
00048        * @brief
00049        *    Should perform any initialization of this random variable which 
00050        * may be necessary to speed or prepare sampling
00051        * 
00052        * @note should be called before calling sample or getPdf
00053        */
00054       virtual void init(ShapeSet *lights);
00055       
00056       
00057       //@}-----------------------------------------------------------------
00058       ///@name Main usage interface
00059       //@{-----------------------------------------------------------------
00060       
00061       /**
00062        * @returns a randomly chosen SurfacePoint, initialized to lie on an 
00063        *    Emitter; the returned event is of type SurfacePoint* and it is 
00064        *    up to the caller to ensure the returned SurfacePoint is deleted
00065        *    appropriately
00066        * @note the returned SurfacePoint is completely initialized, and 
00067        *    the actual light source that the sample lies on can be obtained 
00068        *    via the shape field of the returned SurfacePoint
00069        * @note consecutive calls to sample are expected to return 
00070        *    independent, identically distributed (IID) samples
00071        */
00072       virtual Event sample();
00073       
00074       /**
00075        * @returns the probability density with which the given event would be 
00076        *    sampled according to the underlying probability density function
00077        * @note the given event is assumed to lie within this random variable's
00078        *    sample space
00079        */
00080       virtual real_t getPdf(const Event &event) PURE_FUNCTION;
00081       
00082       
00083       //@}-----------------------------------------------------------------
00084       ///@name Main usage interface
00085       //@{-----------------------------------------------------------------
00086       
00087       /**
00088        * @returns the total surface area of all emitters in the scene
00089        */
00090       inline real_t getTotalSurfaceArea() const {
00091          return m_area;
00092       }
00093       
00094       
00095       //@}-----------------------------------------------------------------
00096       
00097    protected:
00098       Scene    *m_scene;
00099       
00100       // contains all light sources in the scene
00101       ShapeSet *m_lights;
00102       
00103       // normalized array of relative powers of all n light sources
00104       real_t   *m_cdf;
00105       
00106       // total number of emitters
00107       unsigned  m_n;
00108       
00109       // total surface area of all emitters in the scene
00110       real_t    m_area;
00111 };
00112 
00113 #endif // EMITTER_SAMPLER_H_
00114 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6