Blender
V2.93
source
blender
freestyle
intern
image
GaussianFilter.h
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
17
#pragma once
18
24
#include <cstdlib>
// for abs
25
#include <string.h>
// for memcpy
26
27
#include "../system/FreestyleConfig.h"
28
29
#include "
BLI_math.h
"
30
31
#ifdef WITH_CXX_GUARDEDALLOC
32
# include "
MEM_guardedalloc.h
"
33
#endif
34
35
namespace
Freestyle
{
36
37
class
GaussianFilter
{
38
protected
:
39
/* The mask is a symmetrical 2d array (with respect to the middle point).
40
* Thus, M(i,j) = M(-i,j) = M(i,-j) = M(-i,-j).
41
* For this reason, to represent a NxN array (N odd), we only store a ((N+1)/2)x((N+1)/2) array.
42
*/
43
float
_sigma
;
44
float
*
_mask
;
45
int
_bound
;
46
// the real mask size (must be odd)(the size of the mask we store is
47
// ((_maskSize+1)/2)*((_maskSize+1)/2))
48
int
_maskSize
;
49
int
_storedMaskSize
;
// (_maskSize+1)/2)
50
51
public
:
52
GaussianFilter
(
float
iSigma = 1.0f);
53
GaussianFilter
(
const
GaussianFilter
&);
54
GaussianFilter
&
operator=
(
const
GaussianFilter
&);
55
virtual
~GaussianFilter
();
56
71
template
<
class
Map>
float
getSmoothedPixel
(Map *map,
int
x
,
int
y
);
72
76
static
int
computeMaskSize
(
float
sigma
);
77
79
inline
float
sigma
()
const
80
{
81
return
_sigma
;
82
}
83
84
inline
int
maskSize
()
const
85
{
86
return
_maskSize
;
87
}
88
89
inline
int
getBound
()
90
{
91
return
_bound
;
92
}
93
95
void
setSigma
(
float
sigma
);
96
#if 0
97
void
SetMaskSize(
int
size
)
98
{
99
_maskSize
=
size
;
100
_storedMaskSize
= (
_maskSize
+ 1) >> 1;
101
}
102
#endif
103
104
protected
:
105
void
computeMask
();
106
107
#ifdef WITH_CXX_GUARDEDALLOC
108
MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:GaussianFilter"
)
109
#endif
110
};
111
112
/*
113
* #############################################
114
* #############################################
115
* #############################################
116
* ###### ######
117
* ###### I M P L E M E N T A T I O N ######
118
* ###### ######
119
* #############################################
120
* #############################################
121
* #############################################
122
*/
123
124
template
<
class
Map>
float
GaussianFilter::getSmoothedPixel
(Map *map,
int
x
,
int
y
)
125
{
126
float
sum
= 0.0f;
127
float
L
= 0.0f;
128
int
w
= (int)map->width();
// soc
129
int
h = (int)map->height();
// soc
130
131
// Current pixel is x,y
132
// Sum surrounding pixels L value:
133
for
(
int
i = -
_bound
; i <=
_bound
; ++i) {
134
if
((
y
+ i < 0) || (
y
+ i >= h)) {
135
continue
;
136
}
137
for
(
int
j = -
_bound
; j <=
_bound
; ++j) {
138
if
((
x
+ j < 0) || (
x
+ j >=
w
)) {
139
continue
;
140
}
141
142
float
tmpL = map->pixel(
x
+ j,
y
+ i);
143
float
m =
_mask
[
abs
(i) *
_storedMaskSize
+
abs
(j)];
144
L
+= m * tmpL;
145
sum
+= m;
146
}
147
}
148
// L /= sum;
149
return
L
;
150
}
151
152
}
/* namespace Freestyle */
BLI_math.h
y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
Definition:
GPU_legacy_stubs.h:206
MEM_guardedalloc.h
Read Guarded memory(de)allocation.
size
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition:
btDbvt.cpp:52
w
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition:
btQuadWord.h:119
sum
static T sum(const btAlignedObjectArray< T > &items)
Definition:
btSoftBodyHelpers.cpp:94
Freestyle::GaussianFilter
Definition:
GaussianFilter.h:37
Freestyle::GaussianFilter::_mask
float * _mask
Definition:
GaussianFilter.h:44
Freestyle::GaussianFilter::~GaussianFilter
virtual ~GaussianFilter()
Definition:
GaussianFilter.cpp:56
Freestyle::GaussianFilter::GaussianFilter
GaussianFilter(float iSigma=1.0f)
Definition:
GaussianFilter.cpp:28
Freestyle::GaussianFilter::maskSize
int maskSize() const
Definition:
GaussianFilter.h:84
Freestyle::GaussianFilter::computeMaskSize
static int computeMaskSize(float sigma)
Definition:
GaussianFilter.cpp:61
Freestyle::GaussianFilter::getBound
int getBound()
Definition:
GaussianFilter.h:89
Freestyle::GaussianFilter::computeMask
void computeMask()
Definition:
GaussianFilter.cpp:77
Freestyle::GaussianFilter::operator=
GaussianFilter & operator=(const GaussianFilter &)
Definition:
GaussianFilter.cpp:45
Freestyle::GaussianFilter::_bound
int _bound
Definition:
GaussianFilter.h:45
Freestyle::GaussianFilter::_maskSize
int _maskSize
Definition:
GaussianFilter.h:48
Freestyle::GaussianFilter::sigma
float sigma() const
Definition:
GaussianFilter.h:79
Freestyle::GaussianFilter::_storedMaskSize
int _storedMaskSize
Definition:
GaussianFilter.h:49
Freestyle::GaussianFilter::_sigma
float _sigma
Definition:
GaussianFilter.h:43
Freestyle::GaussianFilter::getSmoothedPixel
float getSmoothedPixel(Map *map, int x, int y)
Definition:
GaussianFilter.h:124
Freestyle::GaussianFilter::setSigma
void setSigma(float sigma)
Definition:
GaussianFilter.cpp:71
L
#define L
Definition:
mball_tessellate.c:275
Freestyle
inherits from class Rep
Definition:
AppCanvas.cpp:32
Freestyle::x
static unsigned x[3]
Definition:
RandGen.cpp:87
abs
__forceinline const avxi abs(const avxi &a)
Definition:
util_avxi.h:186
Generated on Tue Jan 31 2023 14:37:24 for Blender by
doxygen
1.9.1