Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TPwcDistribution1D.h
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4#include <vector>
5
6namespace ph::math
7{
8
14template<typename T>
16{
17 static_assert(std::is_floating_point_v<T>);
18
19public:
25 TPwcDistribution1D(T min, T max, const T* weights, std::size_t numWeights);
26 TPwcDistribution1D(T min, T max, const std::vector<T>& weights);
28
31 explicit TPwcDistribution1D(const std::vector<T>& weights);
32
34
40 T sampleContinuous(T sample) const;
41 T sampleContinuous(T sample, T* out_pdf) const;
42 T sampleContinuous(T sample, T* out_pdf, std::size_t* out_straddledColumn) const;
44
49 std::size_t sampleDiscrete(T sample) const;
50 // TODO: a sample resued version
51
55 T pdfContinuous(T value) const;
56
60 T pdfContinuous(std::size_t columnIndex) const;
61
65 T pdfDiscrete(std::size_t columnIndex) const;
66
70 std::size_t continuousToDiscrete(T value) const;
71
75 std::size_t numColumns() const;
76
77private:
78 // Range of the distribution
79 T m_min, m_max;
80
81 // Size of each interval
82 T m_delta;
83
84 // Recording first non-zero column index to avoid sampling column with
85 // zero PDF.
86 std::size_t m_firstNonZeroPdfColumn;
87
88 // Piecewise constant weights will result in piecewise linear CDF.
89 // CDF values are stored on all turning points of the function.
90 std::vector<T> m_cdf;
91
92 T continuouslySampleValue(T sample, std::size_t straddledColumn) const;
93};
94
95}// end namespace ph::math
96
A 1-D piecewise constant distribution of floating-point type T. The sample weights can be seen as a h...
Definition TPwcDistribution1D.h:16
std::size_t sampleDiscrete(T sample) const
Generate an index. Given a uniform unit random sample, generate a column index according to the sampl...
Definition TPwcDistribution1D.ipp:99
T sampleContinuous(T sample) const
Generate a continuous sample. Given a uniform unit random sample, generate a continuous sample accord...
Definition TPwcDistribution1D.ipp:110
T pdfDiscrete(std::size_t columnIndex) const
Definition TPwcDistribution1D.ipp:165
T pdfContinuous(T value) const
Definition TPwcDistribution1D.ipp:150
std::size_t numColumns() const
Definition TPwcDistribution1D.ipp:142
std::size_t continuousToDiscrete(T value) const
Calculates the sampled column index given a continuously sampled value.
Definition TPwcDistribution1D.ipp:174
Math functions and utilities.
Definition TransformInfo.h:10