Blender  V2.93
GaussianFilter.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
22 #include <cstdlib>
23 
24 #include "GaussianFilter.h"
25 
26 namespace Freestyle {
27 
29 {
30  _sigma = iSigma;
31  _mask = nullptr;
32  computeMask();
33 }
34 
36 {
37  _sigma = iBrother._sigma;
38  _maskSize = iBrother._maskSize;
39  _bound = iBrother._bound;
41  _mask = new float[_maskSize * _maskSize];
42  memcpy(_mask, iBrother._mask, _maskSize * _maskSize * sizeof(float));
43 }
44 
46 {
47  _sigma = iBrother._sigma;
48  _maskSize = iBrother._maskSize;
49  _bound = iBrother._bound;
51  _mask = new float[_storedMaskSize * _storedMaskSize];
52  memcpy(_mask, iBrother._mask, _storedMaskSize * _storedMaskSize * sizeof(float));
53  return *this;
54 }
55 
57 {
58  delete[] _mask;
59 }
60 
62 {
63  int maskSize = (int)floor(4 * sigma) + 1;
64  if (0 == (maskSize % 2)) {
65  ++maskSize;
66  }
67 
68  return maskSize;
69 }
70 
71 void GaussianFilter::setSigma(float sigma)
72 {
73  _sigma = sigma;
74  computeMask();
75 }
76 
78 {
79  delete[] _mask;
80 
82  _storedMaskSize = (_maskSize + 1) >> 1;
83  _bound = _storedMaskSize - 1;
84 
85  float norm = _sigma * _sigma * 2.0f * M_PI;
86  float invNorm = 1.0f / norm;
87  _mask = new float[_storedMaskSize * _storedMaskSize * sizeof(float)];
88  for (int i = 0; i < _storedMaskSize; ++i) {
89  for (int j = 0; j < _storedMaskSize; ++j) {
90 #if 0
91  _mask[i * _storedMaskSize + j] = exp(-(i * i + j * j) / (2.0 * _sigma * _sigma));
92 #else
93  _mask[i * _storedMaskSize + j] = invNorm * exp(-(i * i + j * j) / (2.0 * _sigma * _sigma));
94 #endif
95  }
96  }
97 }
98 
99 } /* namespace Freestyle */
typedef float(TangentPoint)[2]
#define M_PI
Definition: BLI_math_base.h:38
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)
inherits from class Rep
Definition: AppCanvas.cpp:32
INLINE Rall1d< T, V, S > exp(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:295
ccl_device_inline float2 floor(const float2 &a)