Blender  V2.93
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 
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);
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 */
_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
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
static T sum(const btAlignedObjectArray< T > &items)
GaussianFilter(float iSigma=1.0f)
static int computeMaskSize(float sigma)
GaussianFilter & operator=(const GaussianFilter &)
float getSmoothedPixel(Map *map, int x, int y)
void setSigma(float sigma)
#define L
inherits from class Rep
Definition: AppCanvas.cpp:32
static unsigned x[3]
Definition: RandGen.cpp:87
__forceinline const avxi abs(const avxi &a)
Definition: util_avxi.h:186