Blender V5.0
GaussianFilter.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11
12#include <cstdlib> // for abs
13#include <string.h> // for memcpy
14
16
17#include "MEM_guardedalloc.h"
18
19namespace Freestyle {
20
22 protected:
23 /* The mask is a symmetrical 2d array (with respect to the middle point).
24 * Thus: `M(i,j) = M(-i,j) = M(i,-j) = M(-i,-j)`.
25 * For this reason, to represent a NxN array (N odd),
26 * we only store a `((N+1)/2)x((N+1)/2)` array. */
27
29 float _sigma;
30 float *_mask;
31 int _bound;
32 /* the real mask size (must be odd)(the size of the mask we store is:
33 * `((_maskSize+1)/2)*((_maskSize+1)/2))`. */
35 int _storedMaskSize; // (_maskSize+1)/2)
36
37 public:
38 GaussianFilter(float iSigma = 1.0f);
41 virtual ~GaussianFilter();
42
53 template<class Map> float getSmoothedPixel(Map *map, int x, int y);
54
58 static int computeMaskSize(float sigma);
59
61 inline float sigma() const
62 {
63 return _sigma;
64 }
65
66 inline int maskSize() const
67 {
68 return _maskSize;
69 }
70
71 inline int getBound()
72 {
73 return _bound;
74 }
75
77 void setSigma(float sigma);
78#if 0
79 void SetMaskSize(int size)
80 {
82 _storedMaskSize = (_maskSize + 1) >> 1;
83 }
84#endif
85
86 protected:
87 void computeMask();
88
89 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GaussianFilter")
90};
91
92/*
93 * #############################################
94 * #############################################
95 * #############################################
96 * ###### ######
97 * ###### I M P L E M E N T A T I O N ######
98 * ###### ######
99 * #############################################
100 * #############################################
101 * #############################################
102 */
103
104template<class Map> float GaussianFilter::getSmoothedPixel(Map *map, int x, int y)
105{
106 // float sum = 0.0f;
107 float L = 0.0f;
108 int w = (int)map->width(); // soc
109 int h = (int)map->height(); // soc
110
111 // Current pixel is x,y
112 // Sum surrounding pixels L value:
113 for (int i = -_bound; i <= _bound; ++i) {
114 if ((y + i < 0) || (y + i >= h)) {
115 continue;
116 }
117 for (int j = -_bound; j <= _bound; ++j) {
118 if ((x + j < 0) || (x + j >= w)) {
119 continue;
120 }
121
122 float tmpL = map->pixel(x + j, y + i);
123 float m = _mask[abs(i) * _storedMaskSize + abs(j)];
124 L += m * tmpL;
125 // sum += m;
126 }
127 }
128 // L /= sum;
129 return L;
130}
131
132} /* namespace Freestyle */
Configuration definitions.
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
GaussianFilter(float iSigma=1.0f)
static int computeMaskSize(float sigma)
GaussianFilter & operator=(const GaussianFilter &)
float getSmoothedPixel(Map *map, int x, int y)
#define abs
#define L
inherits from class Rep
Definition AppCanvas.cpp:20
static uint x[3]
Definition RandGen.cpp:77
i
Definition text_draw.cc:230