Blender V4.3
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
12#include <cstdlib> // for abs
13#include <string.h> // for memcpy
14
16
17#ifdef WITH_CXX_GUARDEDALLOC
18# include "MEM_guardedalloc.h"
19#endif
20
21namespace Freestyle {
22
24 protected:
25 /* The mask is a symmetrical 2d array (with respect to the middle point).
26 * Thus: `M(i,j) = M(-i,j) = M(i,-j) = M(-i,-j)`.
27 * For this reason, to represent a NxN array (N odd),
28 * we only store a `((N+1)/2)x((N+1)/2)` array. */
29
31 float _sigma;
32 float *_mask;
33 int _bound;
34 /* the real mask size (must be odd)(the size of the mask we store is:
35 * `((_maskSize+1)/2)*((_maskSize+1)/2))`. */
37 int _storedMaskSize; // (_maskSize+1)/2)
38
39 public:
40 GaussianFilter(float iSigma = 1.0f);
43 virtual ~GaussianFilter();
44
57 template<class Map> float getSmoothedPixel(Map *map, int x, int y);
58
62 static int computeMaskSize(float sigma);
63
65 inline float sigma() const
66 {
67 return _sigma;
68 }
69
70 inline int maskSize() const
71 {
72 return _maskSize;
73 }
74
75 inline int getBound()
76 {
77 return _bound;
78 }
79
81 void setSigma(float sigma);
82#if 0
83 void SetMaskSize(int size)
84 {
86 _storedMaskSize = (_maskSize + 1) >> 1;
87 }
88#endif
89
90 protected:
91 void computeMask();
92
93#ifdef WITH_CXX_GUARDEDALLOC
94 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GaussianFilter")
95#endif
96};
97
98/*
99 * #############################################
100 * #############################################
101 * #############################################
102 * ###### ######
103 * ###### I M P L E M E N T A T I O N ######
104 * ###### ######
105 * #############################################
106 * #############################################
107 * #############################################
108 */
109
110template<class Map> float GaussianFilter::getSmoothedPixel(Map *map, int x, int y)
111{
112 // float sum = 0.0f;
113 float L = 0.0f;
114 int w = (int)map->width(); // soc
115 int h = (int)map->height(); // soc
116
117 // Current pixel is x,y
118 // Sum surrounding pixels L value:
119 for (int i = -_bound; i <= _bound; ++i) {
120 if ((y + i < 0) || (y + i >= h)) {
121 continue;
122 }
123 for (int j = -_bound; j <= _bound; ++j) {
124 if ((x + j < 0) || (x + j >= w)) {
125 continue;
126 }
127
128 float tmpL = map->pixel(x + j, y + i);
129 float m = _mask[abs(i) * _storedMaskSize + abs(j)];
130 L += m * tmpL;
131 // sum += m;
132 }
133 }
134 // L /= sum;
135 return L;
136}
137
138} /* 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)
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
#define L
inherits from class Rep
Definition AppCanvas.cpp:20
ccl_device_inline int abs(int x)
Definition util/math.h:120