Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rsampler.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #if !defined(__MITSUBA_BIDIR_RSAMPLER_H_)
21 #define __MITSUBA_BIDIR_RSAMPLER_H_
22 
23 #include <mitsuba/render/sampler.h>
24 
26 
27 /**
28  * \brief Specialized sampler implementation used to seed MLT-style algorithm.
29  *
30  * Allows to query for the current sample index, which can later be used to rewind
31  * back to this state. In the case of MLT, this makes it possible to sample paths
32  * approximately proportional to their contribution without actually having
33  * to store millions of path. Note that `rewinding' is naive -- it just
34  * resets & regenerates the whole random number sequence, which might be slow.
35  *
36  * \ingroup libbidir
37  */
39 public:
40  /// Construct a new sampler
42 
43  /// Unserialize a sampler
44  ReplayableSampler(Stream *stream, InstanceManager *manager);
45 
46  /**
47  * Create a clone of this sampler. The clone is allowed to be different
48  * to some extent, e.g. a pseudorandom generator should be based on a
49  * different random seed compared to the original. All other parameters,
50  * are copied exactly.
51  */
52  virtual ref<Sampler> clone();
53 
54  /* Does nothing in this implementation */
55  virtual void advance();
56  virtual void generate(const Point2i &pos);
57 
58  /// Manually set the current sample index
59  virtual void setSampleIndex(size_t sampleIndex);
60 
61  /// Retrieve the next component value from the current sample
62  virtual Float next1D();
63 
64  /// Retrieve the next two component values from the current sample
65  virtual Point2 next2D();
66 
67  /* Unsupported by this implementation */
68  virtual void request2DArray(size_t size);
69  virtual void request1DArray(size_t size);
70 
71  /// Serialize this sampler to disk
72  virtual void serialize(Stream *stream, InstanceManager *manager) const;
73 
74  /// Return a string description
75  virtual std::string toString() const;
76 
77  /// Return the underlying random number generator
78  inline Random *getRandom() { return m_random; }
79 
80  /**
81  * Update the current sample index, but without
82  * changing the RNG state. This is useful if the
83  * underlying random number generator has been used
84  * outside of this class
85  */
86  inline void updateSampleIndex(size_t index) { m_sampleIndex = index; }
87 
89 protected:
90  /// Virtual destructor
91  virtual ~ReplayableSampler();
92 protected:
93  ref<Random> m_initial, m_random;
94 };
95 
97 
98 #endif /* __MITSUBA_BIDIR_RSAMPLER_H_ */
virtual Float next1D()=0
Retrieve the next component value from the current sample.
#define MTS_EXPORT_BIDIR
Definition: platform.h:119
virtual Point2 next2D()=0
Retrieve the next two component values from the current sample.
Random number generator based on SIMD-oriented Fast Mersenne Twister
Definition: random.h:88
virtual void setSampleIndex(size_t sampleIndex)
Manually set the current sample index.
Base class of all sample generators.
Definition: sampler.h:66
virtual void request1DArray(size_t size)
Same as request2DArray(), but in 1D.
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
void updateSampleIndex(size_t index)
Definition: rsampler.h:86
virtual void generate(const Point2i &offset)
Generate new samples.
virtual void request2DArray(size_t size)
Request that a 2D array will be made available for later consumption by next2DArray().
virtual ref< Sampler > clone()
Create a clone of this sampler.
Abstract seekable stream class.
Definition: stream.h:58
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
Definition: fwd.h:99
Reference counting helper.
Definition: ref.h:40
Coordinates the serialization and unserialization of object graphs.
Definition: serialization.h:65
virtual void serialize(Stream *stream, InstanceManager *manager) const
Serialize this sampler to a binary data stream.
Specialized sampler implementation used to seed MLT-style algorithm.
Definition: rsampler.h:38
Random * getRandom()
Return the underlying random number generator.
Definition: rsampler.h:78
virtual std::string toString() const
Return a human-readable string representation of the object&#39;s contents.
virtual void advance()
Advance to the next sample.
#define MTS_NAMESPACE_END
Definition: platform.h:138