Blender  V2.93
util_math_cdf.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2015 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __UTIL_MATH_CDF_H__
18 #define __UTIL_MATH_CDF_H__
19 
20 #include "util/util_algorithm.h"
21 #include "util/util_math.h"
22 #include "util/util_vector.h"
23 
25 
26 /* Evaluate CDF of a given functor with given range and resolution. */
27 template<typename Functor>
29  const int resolution, const float from, const float to, Functor functor, vector<float> &cdf)
30 {
31  const int cdf_count = resolution + 1;
32  const float range = to - from;
33  cdf.resize(cdf_count);
34  cdf[0] = 0.0f;
35  /* Actual CDF evaluation. */
36  for (int i = 0; i < resolution; ++i) {
37  float x = from + range * (float)i / (resolution - 1);
38  float y = functor(x);
39  cdf[i + 1] = cdf[i] + fabsf(y);
40  }
41  /* Normalize the CDF. */
42  for (int i = 0; i <= resolution; i++) {
43  cdf[i] /= cdf[resolution];
44  }
45 }
46 
47 /* Invert pre-calculated CDF function. */
48 void util_cdf_invert(const int resolution,
49  const float from,
50  const float to,
51  const vector<float> &cdf,
52  const bool make_symmetric,
53  vector<float> &inv_cdf);
54 
55 /* Evaluate inverted CDF of a given functor with given range and resolution. */
56 template<typename Functor>
57 void util_cdf_inverted(const int resolution,
58  const float from,
59  const float to,
60  Functor functor,
61  const bool make_symmetric,
62  vector<float> &inv_cdf)
63 {
64  vector<float> cdf;
65  /* There is no much smartness going around lower resolution for the CDF table,
66  * this just to match the old code from pixel filter so it all stays exactly
67  * the same and no regression tests are failed.
68  */
69  util_cdf_evaluate(resolution - 1, from, to, functor, cdf);
70  util_cdf_invert(resolution, from, to, cdf, make_symmetric, inv_cdf);
71 }
72 
74 
75 #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
StackEntry * from
#define CCL_NAMESPACE_END
#define fabsf(x)
CCL_NAMESPACE_BEGIN void util_cdf_evaluate(const int resolution, const float from, const float to, Functor functor, vector< float > &cdf)
Definition: util_math_cdf.h:28
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)
void util_cdf_inverted(const int resolution, const float from, const float to, Functor functor, const bool make_symmetric, vector< float > &inv_cdf)
Definition: util_math_cdf.h:57