Nori

include/nori/sampler.h

Go to the documentation of this file.
00001 /*
00002     This file is part of Nori, a simple educational ray tracer
00003 
00004     Copyright (c) 2012 by Wenzel Jakob and Steve Marschner.
00005 
00006     Nori is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License Version 3
00008     as published by the Free Software Foundation.
00009 
00010     Nori is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 #if !defined(__SAMPLER_H)
00020 #define __SAMPLER_H
00021 
00022 #include <nori/object.h>
00023 
00024 NORI_NAMESPACE_BEGIN
00025 
00026 /**
00027  * \brief Abstract sample generator
00028  *
00029  * A sample generator is responsible for generating the random number stream
00030  * that will be passed an \ref Integrator implementation as it computes the
00031  * radiance incident along a specified ray.
00032  *
00033  * The most simple conceivable sample generator is just a wrapper around the
00034  * Mersenne-Twister random number generator and is implemented in
00035  * <tt>independent.cpp</tt> (it is named this way because it generates 
00036  * statistically independent random numbers).
00037  *
00038  * Fancier samplers might use stratification or low-discrepancy sequences
00039  * (e.g. Halton, Hammersley, or Sobol point sets) for improved convergence.
00040  * Another use of this class is in producing intentionally correlated
00041  * random numbers, e.g. as part of a Metropolis-Hastings integration scheme.
00042  *
00043  * The general interface between a sampler and a rendering algorithm is as 
00044  * follows: Before beginning to render a pixel, the rendering algorithm calls 
00045  * \ref generate(). The first pixel sample can now be computed, after which
00046  * \ref advance() needs to be invoked. This repeats until all pixel samples have
00047  * been exhausted.  While computing a pixel sample, the rendering 
00048  * algorithm requests (pseudo-) random numbers using the \ref next1D() and
00049  * \ref next2D() functions.
00050  *
00051  * Conceptually, the right way of thinking of this goes as follows:
00052  * For each sample in a pixel, a sample generator produces a (hypothetical)
00053  * point in an infinite dimensional random number hypercube. A rendering 
00054  * algorithm can then request subsequent 1D or 2D components of this point 
00055  * using the \ref next1D() and \ref next2D() functions. Fancy implementations
00056  * of this class make certain guarantees about the stratification of the 
00057  * first n components with respect to the other points that are sampled 
00058  * within a pixel.
00059  */
00060 class Sampler : public NoriObject {
00061 public:
00062         /// Release all memory
00063         virtual ~Sampler() { }
00064 
00065         /**
00066          * \brief Clone the current instance
00067          *
00068          * This is used to create a separate sampler for each thread when rendering
00069          * with multiple cores. The clone is expected to be different to some 
00070          * extent, e.g. a pseudorandom generator should be based on a different random 
00071          * seed compared to the original. Other parameters (e.g. those that 
00072          * influence the stratification quality) should be copied exactly.
00073          */
00074         virtual Sampler *clone() = 0;
00075 
00076         /**
00077          * \brief Prepare to generate new samples
00078          * 
00079          * This function is called initially and every time the 
00080          * integrator starts rendering a new pixel.
00081          */
00082         virtual void generate() = 0;
00083 
00084         /// Advance to the next sample
00085         virtual void advance() = 0;
00086 
00087         /// Retrieve the next component value from the current sample
00088         virtual float next1D() = 0;
00089 
00090         /// Retrieve the next two component values from the current sample
00091         virtual Point2f next2D() = 0;
00092 
00093         /// Return the number of configured pixel samples
00094         virtual inline size_t getSampleCount() const { return m_sampleCount; }
00095 
00096         /**
00097          * \brief Return the type of object (i.e. Mesh/Sampler/etc.) 
00098          * provided by this instance
00099          * */
00100         EClassType getClassType() const { return ESampler; }
00101 protected:
00102         size_t m_sampleCount;
00103 };
00104 
00105 NORI_NAMESPACE_END
00106 
00107 #endif /* __SAMPLER_H */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines