Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TableFGD.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <Common/assertion.h>
8#include <Common/primitive_type.h>
9#include <Common/logging.h>
10
11#include <vector>
12
13namespace ph
14{
15
17
18class TableFGD final
19{
20public:
21 explicit TableFGD(const Path& tableFilePath);
22
23 real sample(
24 real cosWi,
25 real alpha,
26 real iorN,
27 real iorK) const;
28
30 real cosWi,
31 real alpha,
32 const math::Spectrum& iorN,
33 const math::Spectrum& iorK) const;
34
35private:
36 std::vector<float> m_table;
37
38 int m_numCosWi;
39 int m_numAlpha;
40 int m_numIorN;
41 int m_numIorK;
42
43 float m_minCosWi, m_maxCosWi;
44 float m_minAlpha, m_maxAlpha;
45 float m_minIorN, m_maxIorN;
46 float m_minIorK, m_maxIorK;
47
48 int calcIndex(int iCosWi, int iAlpha, int iIorN, int iIorK) const;
49 void downSampleHalf();
50};
51
52// In-header Implementations:
53
54inline TableFGD::TableFGD(const Path& tableFilePath) :
55 m_table(),
56
57 m_numCosWi(0),
58 m_numAlpha(0),
59 m_numIorN (0),
60 m_numIorK (0),
61
62 m_minCosWi(0.0f), m_maxCosWi(0.0f),
63 m_minAlpha(0.0f), m_maxAlpha(0.0f),
64 m_minIorN (0.0f), m_maxIorN (0.0f),
65 m_minIorK (0.0f), m_maxIorK (0.0f)
66{
67 PH_LOG(TableFGD, Note, "loading <{}>", tableFilePath.toString());
68
69 BinaryFileReader reader(tableFilePath);
70 if(!reader.open())
71 {
72 return;
73 }
74
75 reader.read(&m_numCosWi);
76 reader.read(&m_numAlpha);
77 reader.read(&m_numIorN);
78 reader.read(&m_numIorK);
79 reader.read(&m_minCosWi); reader.read(&m_maxCosWi);
80 reader.read(&m_minAlpha); reader.read(&m_maxAlpha);
81 reader.read(&m_minIorN); reader.read(&m_maxIorN);
82 reader.read(&m_minIorK); reader.read(&m_maxIorK);
83
84 PH_DEBUG_LOG(TableFGD,
85 "dimension: (cos-w_i = {}, alpha = {}, IOR-n = {}, IOR-k = {})",
86 m_numCosWi, m_numAlpha, m_numIorN, m_numIorK);
87
88 PH_DEBUG_LOG(TableFGD,
89 "range: (cos-w_i = [{}, {}], alpha = [{}, {}], IOR-n = [{}, {}], IOR-k = [{}, {}])",
90 m_minCosWi, m_maxCosWi,
91 m_minAlpha, m_maxAlpha,
92 m_minIorN, m_maxIorN,
93 m_minIorK, m_maxIorK);
94
95 PH_ASSERT(m_numCosWi > 0 && m_numAlpha > 0 && m_numIorN > 0 && m_numIorK > 0);
96
97 const std::size_t tableSize =
98 static_cast<std::size_t>(m_numCosWi) *
99 static_cast<std::size_t>(m_numAlpha) *
100 static_cast<std::size_t>(m_numIorN) *
101 static_cast<std::size_t>(m_numIorK);
102 m_table.resize(tableSize, 0.0f);
103 reader.read(m_table.data(), m_table.size());
104
105 // TEST
106 /*downSampleHalf();
107 downSampleHalf();
108 downSampleHalf();*/
109}
110
112 const real cosWi,
113 const real alpha,
114 const math::Spectrum& iorN,
115 const math::Spectrum& iorK) const
116{
117 math::Spectrum result;
118 for(std::size_t i = 0; i < math::Spectrum::NUM_VALUES; ++i)
119 {
120 result[i] = sample(cosWi, alpha, iorN[i], iorK[i]);
121 }
122 return result;
123}
124
125inline int TableFGD::calcIndex(const int iCosWi, const int iAlpha, const int iIorN, const int iIorK) const
126{
127 // make sure the indices stay in the limits
128 PH_ASSERT(0 <= iCosWi && iCosWi < m_numCosWi);
129 PH_ASSERT(0 <= iAlpha && iAlpha < m_numAlpha);
130 PH_ASSERT(0 <= iIorN && iIorN < m_numIorN);
131 PH_ASSERT(0 <= iIorK && iIorK < m_numIorK);
132
133 return iIorK + m_numIorK * (iIorN + m_numIorN * (iAlpha + m_numAlpha * iCosWi));
134}
135
136}// end namespace ph
Definition BinaryFileReader.h:14
void read(T *out_buffer, std::size_t numElements=1)
Definition BinaryFileReader.h:48
bool open()
Definition BinaryFileReader.cpp:10
General path representation. Does not check whether the target actually exists (e....
Definition Path.h:21
std::string toString() const
Get a string representation of this path in generic format.
Definition Path.cpp:121
Definition TableFGD.h:19
real sample(real cosWi, real alpha, real iorN, real iorK) const
Definition TableFGD.cpp:26
TableFGD(const Path &tableFilePath)
Definition TableFGD.h:54
Definition TTristimulusSpectrum.h:11
The root for all renderer implementations.
Definition EEngineProject.h:6
PH_DEFINE_EXTERNAL_LOG_GROUP(ApiDatabase, Core)