forked from wjakob/nori
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindependent.cpp
80 lines (64 loc) · 2.18 KB
/
independent.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
This file is part of Nori, a simple educational ray tracer
Copyright (c) 2015 by Wenzel Jakob
Nori is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License Version 3
as published by the Free Software Foundation.
Nori is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <nori/sampler.h>
#include <nori/block.h>
#include <pcg32.h>
NORI_NAMESPACE_BEGIN
/**
* Independent sampling - returns independent uniformly distributed
* random numbers on <tt>[0, 1)x[0, 1)</tt>.
*
* This class is essentially just a wrapper around the pcg32 pseudorandom
* number generator. For more details on what sample generators do in
* general, refer to the \ref Sampler class.
*/
class Independent : public Sampler {
public:
Independent(const PropertyList &propList) {
m_sampleCount = (size_t) propList.getInteger("sampleCount", 1);
}
virtual ~Independent() { }
std::unique_ptr<Sampler> clone() const {
std::unique_ptr<Independent> cloned(new Independent());
cloned->m_sampleCount = m_sampleCount;
cloned->m_random = m_random;
return std::move(cloned);
}
void prepare(const ImageBlock &block) {
m_random.seed(
block.getOffset().x(),
block.getOffset().y()
);
}
void generate() { /* No-op for this sampler */ }
void advance() { /* No-op for this sampler */ }
float next1D() {
return m_random.nextFloat();
}
Point2f next2D() {
return Point2f(
m_random.nextFloat(),
m_random.nextFloat()
);
}
std::string toString() const {
return tfm::format("Independent[sampleCount=%i]", m_sampleCount);
}
protected:
Independent() { }
private:
pcg32 m_random;
};
NORI_REGISTER_CLASS(Independent, "independent");
NORI_NAMESPACE_END