UniformOnSphereSampler.cpp

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @file   UniformOnSphereSampler.cpp
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       Represents a uniform distribution on the surface of an N-dimensional 
00009    unit sphere (with parameter N > 0 and radius = 1)
00010    <!-------------------------------------------------------------------->**/
00011 
00012 #include "UniformOnSphereSampler.h"
00013 #include <Point.h>
00014 
00015 void UniformOnSphereSampler::init() {
00016    Sampler::init();
00017    
00018    ASSERT(m_dimension > 0);
00019 }
00020 
00021 Event UniformOnSphereSampler::sample() {
00022    const Random::UniformOnSphereDist::result_type &s = m_sampler();
00023    ASSERT(s.size() == m_dimension);
00024    
00025    ASSERT(m_dimension == 3);
00026    // TODO: make this not tied to 3 dimensions...
00027    
00028    return Event(Point3(s[0], s[1], s[2]), this);
00029 }
00030 
00031 real_t UniformOnSphereSampler::getPdf(const Event &event) {
00032    return 1;
00033    
00034    // Note by definition, uniform on sphere is uniform w/ pdf 1
00035    /*const unsigned int N = m_dimension;
00036    const real_t surfaceArea = 2.0 * pow(M_PI, N / 2.0) / _factorial(N / 2);
00037    
00038    // above formula is only valid for even dimensions because _factorial 
00039    // assumes it has integer input, and if N is odd, N / 2 will be 
00040    // non-integer, so we'd have to use the gamma function
00041    ASSERT(!(N & 1));
00042    
00043    return 1.0 / surfaceArea;*/
00044 }
00045 
00046 unsigned UniformOnSphereSampler::_factorial(unsigned n) {
00047    const unsigned limit = n + (n > 2);
00048    unsigned fact  = 1;
00049    
00050    for(unsigned i = 2; i < limit; ++i)
00051       fact *= i;
00052    
00053    return fact;
00054 }
00055 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6