Blender  V3.3
GaussianFilter.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
8 #include <cstdlib>
9 
10 #include "GaussianFilter.h"
11 
12 namespace Freestyle {
13 
15 {
16  _sigma = iSigma;
17  _mask = nullptr;
18  computeMask();
19 }
20 
22 {
23  _sigma = iBrother._sigma;
24  _maskSize = iBrother._maskSize;
25  _bound = iBrother._bound;
27  _mask = new float[_maskSize * _maskSize];
28  memcpy(_mask, iBrother._mask, _maskSize * _maskSize * sizeof(float));
29 }
30 
32 {
33  _sigma = iBrother._sigma;
34  _maskSize = iBrother._maskSize;
35  _bound = iBrother._bound;
37  _mask = new float[_storedMaskSize * _storedMaskSize];
38  memcpy(_mask, iBrother._mask, _storedMaskSize * _storedMaskSize * sizeof(float));
39  return *this;
40 }
41 
43 {
44  delete[] _mask;
45 }
46 
48 {
49  int maskSize = (int)floor(4 * sigma) + 1;
50  if (0 == (maskSize % 2)) {
51  ++maskSize;
52  }
53 
54  return maskSize;
55 }
56 
57 void GaussianFilter::setSigma(float sigma)
58 {
59  _sigma = sigma;
60  computeMask();
61 }
62 
64 {
65  delete[] _mask;
66 
68  _storedMaskSize = (_maskSize + 1) >> 1;
69  _bound = _storedMaskSize - 1;
70 
71  float norm = _sigma * _sigma * 2.0f * M_PI;
72  float invNorm = 1.0f / norm;
73  _mask = new float[_storedMaskSize * _storedMaskSize * sizeof(float)];
74  for (int i = 0; i < _storedMaskSize; ++i) {
75  for (int j = 0; j < _storedMaskSize; ++j) {
76 #if 0
77  _mask[i * _storedMaskSize + j] = exp(-(i * i + j * j) / (2.0 * _sigma * _sigma));
78 #else
79  _mask[i * _storedMaskSize + j] = invNorm * exp(-(i * i + j * j) / (2.0 * _sigma * _sigma));
80 #endif
81  }
82  }
83 }
84 
85 } /* namespace Freestyle */
typedef float(TangentPoint)[2]
#define M_PI
Definition: BLI_math_base.h:20
Class to perform gaussian filtering operations on an image.
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Definition: btVector3.h:263
GaussianFilter(float iSigma=1.0f)
static int computeMaskSize(float sigma)
GaussianFilter & operator=(const GaussianFilter &)
void setSigma(float sigma)
ccl_device_inline float3 exp(float3 v)
Definition: math_float3.h:392
inherits from class Rep
Definition: AppCanvas.cpp:18
T floor(const T &a)