MCPcopy Create free account
hub / github.com/RenderKit/embree / init

Method init

tutorials/convert/distribution1d.cpp:16–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14 }
15
16 void Distribution1D::init(const float* f, const size_t size_in)
17 {
18 /*! create arrays */
19 size = size_in;
20 PDF.resize(size);
21 CDF.resize(size+1);
22
23 /*! accumulate the function f */
24 CDF[0] = 0.0f;
25 for (size_t i=1; i<size+1; i++)
26 CDF[i] = CDF[i-1] + f[i-1];
27
28 /*! compute reciprocal sum */
29 float rcpSum = CDF[size] == 0.0f ? 0.0f : rcp(CDF[size]);
30
31 /*! normalize the probability distribution and cumulative distribution */
32 for (size_t i = 1; i<size+1; i++) {
33 PDF[i-1] = f[i-1] * rcpSum * size;
34 CDF[i] *= rcpSum;
35 }
36 CDF[size] = 1.0f;
37 }
38
39 float Distribution1D::sample(const float u) const
40 {

Callers

nothing calls this directly

Calls 2

rcpFunction · 0.50
resizeMethod · 0.45

Tested by

no test coverage detected