Blender V4.3
GaussianFilter.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#include <cstdlib>
11
12#include "GaussianFilter.h"
13
14#include "BLI_math_base.h"
15
16namespace Freestyle {
17
19{
20 _sigma = iSigma;
21 _mask = nullptr;
23}
24
26{
27 _sigma = iBrother._sigma;
28 _maskSize = iBrother._maskSize;
29 _bound = iBrother._bound;
31 _mask = new float[_maskSize * _maskSize];
32 memcpy(_mask, iBrother._mask, _maskSize * _maskSize * sizeof(float));
33}
34
36{
37 _sigma = iBrother._sigma;
38 _maskSize = iBrother._maskSize;
39 _bound = iBrother._bound;
42 memcpy(_mask, iBrother._mask, _storedMaskSize * _storedMaskSize * sizeof(float));
43 return *this;
44}
45
50
52{
53 int maskSize = int(floor(4 * sigma)) + 1;
54 if (0 == (maskSize % 2)) {
55 ++maskSize;
56 }
57
58 return maskSize;
59}
60
61void GaussianFilter::setSigma(float sigma)
62{
63 _sigma = sigma;
65}
66
68{
69 delete[] _mask;
70
72 _storedMaskSize = (_maskSize + 1) >> 1;
74
75 float norm = _sigma * _sigma * 2.0f * M_PI;
76 float invNorm = 1.0f / norm;
77 _mask = new float[_storedMaskSize * _storedMaskSize * sizeof(float)];
78 for (int i = 0; i < _storedMaskSize; ++i) {
79 for (int j = 0; j < _storedMaskSize; ++j) {
80#if 0
81 _mask[i * _storedMaskSize + j] = exp(-(i * i + j * j) / (2.0 * _sigma * _sigma));
82#else
83 _mask[i * _storedMaskSize + j] = invNorm * exp(-(i * i + j * j) / (2.0 * _sigma * _sigma));
84#endif
85 }
86 }
87}
88
89} /* namespace Freestyle */
#define M_PI
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 &)
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
ccl_device_inline float2 floor(const float2 a)
ccl_device_inline float3 exp(float3 v)
inherits from class Rep
Definition AppCanvas.cpp:20