Blender  V3.3
math_cdf.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #ifndef __UTIL_MATH_CDF_H__
5 #define __UTIL_MATH_CDF_H__
6 
7 #include "util/algorithm.h"
8 #include "util/math.h"
9 #include "util/vector.h"
10 
12 
13 /* Evaluate CDF of a given functor with given range and resolution. */
14 template<typename Functor>
16  const int resolution, const float from, const float to, Functor functor, vector<float> &cdf)
17 {
18  const int cdf_count = resolution + 1;
19  const float range = to - from;
20  cdf.resize(cdf_count);
21  cdf[0] = 0.0f;
22  /* Actual CDF evaluation. */
23  for (int i = 0; i < resolution; ++i) {
24  float x = from + range * (float)i / (resolution - 1);
25  float y = functor(x);
26  cdf[i + 1] = cdf[i] + fabsf(y);
27  }
28  /* Normalize the CDF. */
29  for (int i = 0; i <= resolution; i++) {
30  cdf[i] /= cdf[resolution];
31  }
32 }
33 
34 /* Invert pre-calculated CDF function. */
35 void util_cdf_invert(const int resolution,
36  const float from,
37  const float to,
38  const vector<float> &cdf,
39  const bool make_symmetric,
40  vector<float> &inv_cdf);
41 
42 /* Evaluate inverted CDF of a given functor with given range and resolution. */
43 template<typename Functor>
44 void util_cdf_inverted(const int resolution,
45  const float from,
46  const float to,
47  Functor functor,
48  const bool make_symmetric,
49  vector<float> &inv_cdf)
50 {
51  vector<float> cdf;
52  /* There is no much smartness going around lower resolution for the CDF table,
53  * this just to match the old code from pixel filter so it all stays exactly
54  * the same and no regression tests are failed.
55  */
56  util_cdf_evaluate(resolution - 1, from, to, functor, cdf);
57  util_cdf_invert(resolution, from, to, cdf, make_symmetric, inv_cdf);
58 }
59 
61 
62 #endif /* __UTIL_MATH_H_CDF__ */
typedef float(TangentPoint)[2]
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
StackEntry * from
CCL_NAMESPACE_BEGIN void util_cdf_evaluate(const int resolution, const float from, const float to, Functor functor, vector< float > &cdf)
Definition: math_cdf.h:15
void util_cdf_invert(const int resolution, const float from, const float to, const vector< float > &cdf, const bool make_symmetric, vector< float > &inv_cdf)
Definition: math_cdf.cpp:12
void util_cdf_inverted(const int resolution, const float from, const float to, Functor functor, const bool make_symmetric, vector< float > &inv_cdf)
Definition: math_cdf.h:44
#define fabsf(x)
Definition: metal/compat.h:219