PICCANTE  0.4
The hottest HDR imaging library!
filter_non_linear_1d.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_GL_FILTERING_FILTER_NON_LINEAR_1D_HPP
19 #define PIC_GL_FILTERING_FILTER_NON_LINEAR_1D_HPP
20 
21 #include "../../gl/filtering/filter_1d.hpp"
22 
23 namespace pic {
24 
29 {
30 protected:
32  std::string acc_operator;
33 
40  void FragmentShader(ImageGL *weights, int direction, GLenum target)
41  {
42  std::string fragment_source_2D = MAKE_STRING
43  (
44  uniform sampler2D u_tex;
45  uniform int iX;
46  uniform int iY;
47  uniform int halfKernelSize;
48  uniform int kernelSize;
49  out vec4 f_color;
50 
51  void main(void) {
52  ivec2 coordsFrag = ivec2(gl_FragCoord.xy);
53  vec4 tmpCol;
54 
55  //Texture fetch
56  ivec2 coords = ivec2(-halfKernelSize * iX, -halfKernelSize * iY);
57  vec4 color = texelFetch(u_tex, coordsFrag.xy + coords.xy, 0);
58 
59  for(int i = 1; i < kernelSize; i++) {
60  //Coordinates
61  int j = i - halfKernelSize;
62  ivec2 coords = ivec2(j * iX, j * iY);
63  //Texture fetch
64  tmpCol = texelFetch(u_tex, coordsFrag.xy + coords.xy, 0);
65  color = _ACC_FUNCTION(color, tmpCol);
66  }
67 
68  f_color = color;
69  }
70  );
71 
72  std::string fragment_source_3D = MAKE_STRING
73  (
74  uniform sampler3D u_tex;
75  uniform int slice;
76  uniform int iX;
77  uniform int iY;
78  uniform int iZ;
79  uniform int halfKernelSize;
80  uniform int kernelSize;
81  out vec4 f_color;
82 
83  void main(void) {
84  vec4 color = vec4(0.0);
85  ivec3 coordsFrag = ivec3(ivec2(gl_FragCoord.xy), slice);
86  vec4 tmpCol;
87 
88  for(int i = 0; i < kernelSize; i++) {
89  //Coordinates
90  int j = i - halfKernelSize;
91  ivec3 coords = coordsFrag.xyz + ivec3(j * iX, j * iY, j * iZ);
92  //Texture fetch
93  tmpCol = texelFetch(u_tex, coords.xyz, 0);
94  color = _ACC_FUNCTION(color, tmpCol);
95  }
96 
97  f_color = color;
98  }
99  );
100 
101  switch(target) {
102  case GL_TEXTURE_2D: {
103  fragment_source = fragment_source_2D;
104  }
105  break;
106 
107  case GL_TEXTURE_3D: {
108  fragment_source = fragment_source_3D;
109  }
110  break;
111  }
112 
113  size_t I_found = fragment_source.find("_ACC_FUNCTION");
114 
115  if(I_found != std::string::npos) {
116  fragment_source.replace(I_found, 13, acc_operator);
117  }
118  }
119 
120 public:
121 
126  {
127  this->acc_operator = acc_operator;
128 
130 
131  FragmentShader(NULL, 0, GL_TEXTURE_2D);
132  initShaders();
133  }
134 
136  {
137  release();
138  }
139 
144  {
145  technique.setUniform1i("halfKernelSize", halfKernelSize);
146  technique.setUniform1i("kernelSize", kernelSize);
147  }
148 
153  void update(int kernelSize)
154  {
155  kernelSize = (kernelSize > 0) ? kernelSize : 3;
156 
157  if((kernelSize % 2) == 0) {
158  kernelSize++;
159  }
160 
161  this->kernelSize = kernelSize;
162  this->halfKernelSize = kernelSize >> 1;
163  }
164 };
165 
166 
167 } // end namespace pic
168 
169 #endif /* PIC_GL_FILTERING_FILTER_NON_LINEAR_1D_HPP */
170 
TechniqueGL technique
Definition: display.hpp:45
ImageGL * weights
Definition: display.hpp:35
int slice
Definition: display.hpp:37
The FilterGL1D class.
Definition: filter_1d.hpp:32
The FilterGLNonLinear1D class.
Definition: filter_non_linear_1d.hpp:28
FilterGLNonLinear1D(int kernelSize, std::string acc_operator, GLenum target)
FilterGLNonLinear1D.
Definition: filter_non_linear_1d.hpp:125
virtual void initShaders()
initShaders
Definition: filter_1d.hpp:175
GLenum target
Definition: display.hpp:47
#define MAKE_STRING(input_string)
The ImageGL class.
Definition: image.hpp:42
void FragmentShader(ImageGL *weights, int direction, GLenum target)
FragmentShader.
Definition: filter_non_linear_1d.hpp:40
void update(int kernelSize)
update
Definition: filter_non_linear_1d.hpp:153
void setUniformAux()
setUniformAux
Definition: filter_non_linear_1d.hpp:143
int kernelSize
Definition: filter_non_linear_1d.hpp:31
int halfKernelSize
Definition: filter_non_linear_1d.hpp:31
virtual void FragmentShader()
FragmentShader.
Definition: display.hpp:47
std::string acc_operator
Definition: filter_non_linear_1d.hpp:32
Definition: bilateral_separation.hpp:25
~FilterGLNonLinear1D()
Definition: filter_non_linear_1d.hpp:135
std::string fragment_source
Definition: display.hpp:57
void release()
release
Definition: display.hpp:85
void setUniform1i(const char *name_uniform, int value0)
SetUniform.
Definition: display.hpp:236