JointContUniformSampler.cpp

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @file   JointContUniformSampler.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 [min,max)^N ; N > 0, 
00009    which could be used, for example, for choosing a random UV coordinate
00010    (e.g, where N = 2, min = 0, max = 1)
00011    <!-------------------------------------------------------------------->**/
00012 
00013 #include "JointContUniformSampler.h"
00014 
00015 void JointContUniformSampler::init() {
00016    Sampler::init();
00017    m_sampler.init();
00018    
00019    ASSERT(m_dimension > 0);
00020 }
00021 
00022 Event JointContUniformSampler::sample() {
00023    std::vector<real_t> sample;
00024    
00025    for(unsigned i = m_dimension; i--;)
00026       sample.push_back(m_sampler.sample().getValue<real_t>());
00027    
00028    return Event(sample, this);
00029 }
00030 
00031 real_t JointContUniformSampler::getPdf(const Event &event) {
00032    const real_t den = 
00033       pow((m_sampler.getMax() - m_sampler.getMin()), m_dimension);
00034    
00035    return 1.0 / den;
00036 }
00037 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6