Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
PrimitivePosSampleQuery.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/TVector3.h"
4#include "Core/Ray.h"
6#include "Core/LTA/PDF.h"
7
8#include <Common/assertion.h>
9#include <Common/primitive_type.h>
10#include <Common/logging.h>
11
12#include <optional>
13
14namespace ph { class DirectEnergySampleInput; }
15
16namespace ph
17{
18
22{
23public:
24 void set(
25 const DirectEnergySampleInput& directInput,
26 const math::Vector3R& uvw = {0, 0, 0},
27 const lta::PDF& uvwPdf = {},
28 bool suggestDir = false);
29
30 void set(
31 const Time& time,
32 const std::optional<math::Vector3R>& observationPos = std::nullopt,
33 const math::Vector3R& uvw = {0, 0, 0},
34 const lta::PDF& uvwPdf = {},
35 bool suggestDir = false);
36
37 const Time& getTime() const;
38
47 const std::optional<math::Vector3R>& getObservationPos() const;
48
54 const math::Vector3R& getUvw() const;
55
59 const lta::PDF& getUvwPdf() const;
60
61 bool suggestDir() const;
62
63private:
64 Time m_time;
65 std::optional<math::Vector3R> m_observationPos;
66 math::Vector3R m_uvw;
67 lta::PDF m_uvwPdf;
68 bool m_suggestDir;
69#if PH_DEBUG
70 bool m_hasSet{false};
71#endif
72};
73
77{
78public:
79 void setPos(const math::Vector3R& pos);
80 void setPdfPos(const lta::PDF& pdfPos);
81 void setPdfDir(const lta::PDF& pdfDir);
82 void setObservationRay(const Ray& observationRay);
83
89 const math::Vector3R& getPos() const;
90
96 const math::Vector3R& getDir() const;
97
98 real getPdfA() const;
99 real getPdfW() const;
100 const lta::PDF& getPdfPos() const;
101 const lta::PDF& getPdfDir() const;
102
114 const Ray& getObservationRay() const;
115
120 operator bool () const;
121
122private:
123 math::Vector3R m_pos{0};
124 lta::PDF m_pdfPos{};
125 lta::PDF m_pdfDir{};
126 Ray m_observationRay{};
127};
128
142
143// In-header Implementations:
144
146 const Time& time,
147 const std::optional<math::Vector3R>& observationPos,
148 const math::Vector3R& uvw,
149 const lta::PDF& uvwPdf,
150 const bool suggestDir)
151{
152 m_time = time;
153 m_observationPos = observationPos;
154 m_uvw = uvw;
155 m_uvwPdf = uvwPdf;
156 m_suggestDir = suggestDir;
157
158#if PH_DEBUG
159 m_hasSet = true;
160
161 if(observationPos && suggestDir)
162 {
163 PH_DEFAULT_LOG(WarningOnce,
164 "Requesting suggested direction in `PrimitivePosSampleInput` has no effect when "
165 "observation position is present.");
166 }
167#endif
168}
169
171{
172 PH_ASSERT(m_hasSet);
173 return m_time;
174}
175
176inline const std::optional<math::Vector3R>& PrimitivePosSampleInput::getObservationPos() const
177{
178 PH_ASSERT(m_hasSet);
179 return m_observationPos;
180}
181
183{
184 PH_ASSERT(m_hasSet);
185 return m_uvw;
186}
187
189{
190 PH_ASSERT(m_hasSet);
191 return m_uvwPdf;
192}
193
195{
196 PH_ASSERT(m_hasSet);
197 return m_suggestDir;
198}
199
200inline void PrimitivePosSampleOutput::setObservationRay(const Ray& observationRay)
201{
202 m_observationRay = observationRay;
203}
204
206{
207 m_pos = pos;
208}
209
211{
212 m_pdfPos = pdfPos;
213}
214
216{
217 m_pdfDir = pdfDir;
218}
219
221{
222 PH_ASSERT(*this);
223 return m_observationRay;
224}
225
227{
228 PH_ASSERT(*this);
229 PH_ASSERT(!m_pdfPos.isEmpty());
230 return m_pos;
231}
232
234{
235 PH_ASSERT(!m_pdfDir.isEmpty());
236 return getObservationRay().getDir();
237}
238
240{
241 return getPdfPos().getPdfA();
242}
243
245{
246 return getPdfDir().getPdfW();
247}
248
250{
251 PH_ASSERT(*this);
252 return m_pdfPos;
253}
254
256{
257 PH_ASSERT(*this);
258 return m_pdfDir;
259}
260
261inline PrimitivePosSampleOutput::operator bool () const
262{
263 return m_pdfPos;
264}
265
266}// end namespace ph
Input for DirectEnergySampleQuery.
Definition DirectEnergySampleQuery.h:20
Input for PrimitivePosSampleQuery.
Definition PrimitivePosSampleQuery.h:22
void set(const DirectEnergySampleInput &directInput, const math::Vector3R &uvw={0, 0, 0}, const lta::PDF &uvwPdf={}, bool suggestDir=false)
Definition PrimitivePosSampleQuery.cpp:7
const Time & getTime() const
Definition PrimitivePosSampleQuery.h:170
bool suggestDir() const
Definition PrimitivePosSampleQuery.h:194
const std::optional< math::Vector3R > & getObservationPos() const
Definition PrimitivePosSampleQuery.h:176
const lta::PDF & getUvwPdf() const
Definition PrimitivePosSampleQuery.h:188
const math::Vector3R & getUvw() const
Definition PrimitivePosSampleQuery.h:182
Output for PrimitivePosSampleQuery.
Definition PrimitivePosSampleQuery.h:77
const Ray & getObservationRay() const
Get the ray from observation position to sampled position. If there is no explicitly provided observa...
Definition PrimitivePosSampleQuery.h:220
void setPos(const math::Vector3R &pos)
Definition PrimitivePosSampleQuery.h:205
void setPdfPos(const lta::PDF &pdfPos)
Definition PrimitivePosSampleQuery.h:210
void setPdfDir(const lta::PDF &pdfDir)
Definition PrimitivePosSampleQuery.h:215
const lta::PDF & getPdfPos() const
Definition PrimitivePosSampleQuery.h:249
const math::Vector3R & getDir() const
Get the sampled direction. Some implementation may suggest a sample direction if no observation posit...
Definition PrimitivePosSampleQuery.h:233
const lta::PDF & getPdfDir() const
Definition PrimitivePosSampleQuery.h:255
real getPdfA() const
Definition PrimitivePosSampleQuery.h:239
const math::Vector3R & getPos() const
Get the sampled position.
Definition PrimitivePosSampleQuery.h:226
void setObservationRay(const Ray &observationRay)
Definition PrimitivePosSampleQuery.h:200
real getPdfW() const
Definition PrimitivePosSampleQuery.h:244
Information for generating a sample point on a primitive.
Definition PrimitivePosSampleQuery.h:132
Input inputs
Definition PrimitivePosSampleQuery.h:137
Output outputs
Definition PrimitivePosSampleQuery.h:138
Represents a ray in space.
Definition Ray.h:21
const math::Vector3R & getDir() const
Definition Ray.h:214
Definition Time.h:9
A sample from a Probability Density Function (PDF).
Definition PDF.h:14
real getPdfW() const
Definition PDF.h:87
bool isEmpty() const
Definition PDF.h:105
real getPdfA() const
Definition PDF.h:93
The root for all renderer implementations.
Definition EEngineProject.h:6