Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
SampleGenerator.h
Go to the documentation of this file.
1#pragma once
2
3#include "Core/Sample.h"
4#include "Math/TVector2.h"
12
13#include <Common/assertion.h>
14#include <Common/primitive_type.h>
15
16#include <cstddef>
17#include <utility>
18#include <vector>
19#include <memory>
20#include <utility>
21
22namespace ph
23{
24
25class Scene;
26class SampleContext;
27
35{
36public:
37 SampleGenerator(std::size_t numSampleBatches, std::size_t maxCachedBatches);
38 explicit SampleGenerator(std::size_t numSampleBatches);
39 virtual ~SampleGenerator() = default;
40
44 virtual std::unique_ptr<SampleGenerator> makeNewborn(std::size_t numSampleBatches) const = 0;
45
53 virtual void rebirth();
54
55 void genSplitted(
56 std::size_t numSplits,
57 std::vector<std::unique_ptr<SampleGenerator>>& out_sgs) const;
58
64 bool prepareSampleBatch();
65
68 SamplesNDHandle declareStageND(std::size_t numDims, std::size_t numSamples);
69
77 std::size_t numDims,
78 std::size_t numSamples,
79 std::vector<std::size_t> dimSizeHints);
80
85 SamplesNDStream getSamplesND(const SamplesNDHandle& handle) const;
86
87 std::size_t numSampleBatches() const;
88 std::size_t maxCachedBatches() const;
89 std::size_t numRemainingBatches() const;
90
96 bool hasMoreBatches() const;
97
98private:
101 virtual void onRebirth() = 0;
102
103 virtual void genSamples1D(
104 const SampleContext& context,
105 const SampleStage& stage,
106 SamplesND out_samples) = 0;
107
108 virtual void genSamples2D(
109 const SampleContext& context,
110 const SampleStage& stage,
111 SamplesND out_samples) = 0;
112
113 virtual bool isSamplesGE3DSupported() const;
114
115 virtual void genSamplesGE3D(
116 const SampleContext& context,
117 const SampleStage& stage,
118 SamplesND out_samples);
119
120 virtual void reviseSampleStage(SampleStageReviser reviser);
121
122private:
123 void allocSampleBuffer();
124 void genSampleBatch(std::size_t cachedBatchIndex);
125 void reset();
126
127 std::size_t m_numSampleBatches;
128 std::size_t m_maxCachedBatches;
129
130 std::size_t m_numUsedBatches;
131 std::size_t m_numUsedCaches;
132 std::size_t m_numDeclaredDims;
133 std::size_t m_totalBufferSize;
134 std::vector<real> m_sampleBuffer;
135 std::vector<SampleStage> m_stages;
136#if PH_DEBUG
137 bool m_isSampleBatchPrepared;
138#endif
139};
140
141// In-header Implementations:
142
143inline std::size_t SampleGenerator::numSampleBatches() const
144{
145 return m_numSampleBatches;
146}
147
148inline std::size_t SampleGenerator::maxCachedBatches() const
149{
150 return m_maxCachedBatches;
151}
152
153inline std::size_t SampleGenerator::numRemainingBatches() const
154{
155 PH_ASSERT_LE(m_numUsedBatches, m_numSampleBatches);
156
157 return m_numSampleBatches - m_numUsedBatches;
158}
159
161{
162 return m_numUsedBatches < m_numSampleBatches;
163}
164
165}// end namespace ph
Definition SampleContext.h:9
Generates samples in [0, 1]. Generators of different types produces samples with different properties...
Definition SampleGenerator.h:35
virtual void rebirth()
Reset this generator to its initial state, reviving it from dead state. Calling this method starts a ...
Definition SampleGenerator.cpp:175
SamplesNDHandle declareStageND(std::size_t numDims, std::size_t numSamples)
Similar to declareStageND(), with default size hints.
Definition SampleGenerator.cpp:76
bool prepareSampleBatch()
Generates sample values for current sample batch. Advances all sample values in all stages to the nex...
Definition SampleGenerator.cpp:38
std::size_t numSampleBatches() const
Definition SampleGenerator.h:143
virtual std::unique_ptr< SampleGenerator > makeNewborn(std::size_t numSampleBatches) const =0
Make a new generator.
SampleGenerator(std::size_t numSampleBatches, std::size_t maxCachedBatches)
Definition SampleGenerator.cpp:11
SamplesNDStream getSamplesND(const SamplesNDHandle &handle) const
Gets generated N-dimensional sample values in a stage. This method can only be called after sample ba...
Definition SampleGenerator.cpp:152
bool hasMoreBatches() const
Definition SampleGenerator.h:160
void genSplitted(std::size_t numSplits, std::vector< std::unique_ptr< SampleGenerator > > &out_sgs) const
Definition SampleGenerator.cpp:182
std::size_t maxCachedBatches() const
Definition SampleGenerator.h:148
virtual ~SampleGenerator()=default
std::size_t numRemainingBatches() const
Definition SampleGenerator.h:153
Definition SampleStage.h:14
Definition SampleStageReviser.h:12
Definition SamplesNDHandle.h:14
Definition SamplesND.h:16
Definition SamplesNDStream.h:17
The root for all renderer implementations.
Definition EEngineProject.h:6