Nori  23
independent.cpp
1 /*
2  This file is part of Nori, a simple educational ray tracer
3 
4  Copyright (c) 2015 by Wenzel Jakob
5 
6  Nori 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  Nori 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 #include <nori/sampler.h>
20 #include <nori/block.h>
21 #include <pcg32.h>
22 
23 NORI_NAMESPACE_BEGIN
24 
33 class Independent : public Sampler {
34 public:
35  Independent(const PropertyList &propList) {
36  m_sampleCount = (size_t) propList.getInteger("sampleCount", 1);
37  }
38 
39  virtual ~Independent() { }
40 
41  std::unique_ptr<Sampler> clone() const {
42  std::unique_ptr<Independent> cloned(new Independent());
43  cloned->m_sampleCount = m_sampleCount;
44  cloned->m_random = m_random;
45  return std::move(cloned);
46  }
47 
48  void prepare(const ImageBlock &block) {
49  m_random.seed(
50  block.getOffset().x(),
51  block.getOffset().y()
52  );
53  }
54 
55  void generate() { /* No-op for this sampler */ }
56  void advance() { /* No-op for this sampler */ }
57 
58  float next1D() {
59  return m_random.nextFloat();
60  }
61 
63  return Point2f(
64  m_random.nextFloat(),
65  m_random.nextFloat()
66  );
67  }
68 
69  virtual std::string toString() const override {
70  return tfm::format("Independent[sampleCount=%i]", m_sampleCount);
71  }
72 protected:
73  Independent() { }
74 
75 private:
76  pcg32 m_random;
77 };
78 
79 NORI_REGISTER_CLASS(Independent, "independent");
80 NORI_NAMESPACE_END
Weighted pixel storage for a rectangular subregion of an image.
Definition: block.h:48
const Point2i & getOffset() const
Return the offset of the block within the main image.
Definition: block.h:69
void prepare(const ImageBlock &block)
Prepare to render a new image block.
Definition: independent.cpp:48
virtual std::string toString() const override
Return a brief string summary of the instance (for debugging purposes)
Definition: independent.cpp:69
std::unique_ptr< Sampler > clone() const
Create an exact clone of the current instance.
Definition: independent.cpp:41
Point2f next2D()
Retrieve the next two component values from the current sample.
Definition: independent.cpp:62
void generate()
Prepare to generate new samples.
Definition: independent.cpp:55
float next1D()
Retrieve the next component value from the current sample.
Definition: independent.cpp:58
void advance()
Advance to the next sample.
Definition: independent.cpp:56
This is an associative container used to supply the constructors of NoriObject subclasses with parame...
Definition: proplist.h:32
int getInteger(const std::string &name) const
Get an integer property, and throw an exception if it does not exist.
Abstract sample generator.
Definition: sampler.h:63