Blender  V3.3
GaussianFilter.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #include <cstdlib> // for abs
11 #include <string.h> // for memcpy
12 
13 #include "../system/FreestyleConfig.h"
14 
15 #include "BLI_math.h"
16 
17 #ifdef WITH_CXX_GUARDEDALLOC
18 # include "MEM_guardedalloc.h"
19 #endif
20 
21 namespace 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))`. */
36  int _maskSize;
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  {
85  _maskSize = size;
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 
110 template<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 */
_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.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Map
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)
void setSigma(float sigma)
#define L
inherits from class Rep
Definition: AppCanvas.cpp:18
static unsigned x[3]
Definition: RandGen.cpp:73
T abs(const T &a)
SocketIndexByIdentifierMap * map