PICCANTE  0.4
The hottest HDR imaging library!
filter_grow_cut.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_GROW_CUT_HPP
19 #define PIC_GL_FILTERING_FILTER_GROW_CUT_HPP
20 
21 #include "../../gl/filtering/filter.hpp"
22 
23 namespace pic {
24 
29 {
30 protected:
34  void initShaders()
35  {
37  (
38  uniform sampler2D u_tex; \n
39  uniform sampler2D u_max; \n
40  uniform sampler2D u_state_cur; \n
41  const int dx[8] = int[](-1, 0, 1, -1, 1, -1, 0, 1); \n
42  const int dy[8] = int[]( 1, 1, 1, 0, 0, -1, -1, -1); \n
43  out vec4 f_color; \n
44  \n
45  void main(void) { \n
46  \n
47  ivec2 coords = ivec2(gl_FragCoord.xy); \n
48  vec3 col = texelFetch(u_tex, coords, 0).xyz; \n
49  vec2 cur = texelFetch(u_state_cur, coords, 0).xy; \n
50  vec3 col_max = texelFetch(u_max, coords, 0).xyz; \n
51  float C = dot(col_max, col_max); \n
52  vec2 next = cur; \n
53  \n
54  for(int k = 0; k < 8; k++) {\n
55  ivec2 coords_k = coords + ivec2(dx[k], dy[k]);\n
56 
57  vec2 cur_k = texelFetch(u_state_cur, coords_k, 0).xy; \n
58  vec3 col_k = texelFetch(u_tex, coords_k, 0).xyz; \n
59  vec3 delta_col = col - col_k;\n
60  float g_theta = 1.0 - (dot(delta_col, delta_col) / C);
61  g_theta *= cur_k.y;\n
62  if(g_theta > cur.y) {\n
63  next.x = cur_k.x;\n
64  next.y = g_theta;\n
65  }\n
66  }\n
67  f_color = vec4(next.x, next.y, 0.0, 1.0); \n
68  }
69  );
70 
71  technique.initStandard("330", vertex_source, fragment_source, "FilterGLGrowCut");
72 
73  update();
74  }
75 
76 public:
77 
83  {
84  initShaders();
85  }
86 
88  {
89  release();
90  }
91 
95  void update()
96  {
97  technique.bind();
98  technique.setUniform1i("u_state_cur", 0);
99  technique.setUniform1i("u_tex", 1);
100  technique.setUniform1i("u_max", 2);
101  technique.unbind();
102  }
103 };
104 
105 } // end namespace pic
106 
107 #endif /* PIC_GL_FILTERING_FILTER_GROW_CUT_HPP */
108 
~FilterGLGrowCut()
Definition: filter_grow_cut.hpp:87
TechniqueGL technique
Definition: display.hpp:45
void bind()
bind
Definition: display.hpp:189
#define MAKE_STRING(input_string)
The FilterGLGrowCut class.
Definition: filter_grow_cut.hpp:28
The FilterGL class.
Definition: filter.hpp:35
bool initStandard(std::string version_number, std::string vertex_shader_source, std::string fragment_shader_source, std::string name)
initStandard
Definition: display.hpp:114
void unbind()
unbind
Definition: display.hpp:197
void update()
update
Definition: filter_grow_cut.hpp:95
std::string vertex_source
Definition: display.hpp:57
Definition: bilateral_separation.hpp:25
std::string fragment_source
Definition: display.hpp:57
FilterGLGrowCut()
FilterGLGrowCut.
Definition: filter_grow_cut.hpp:82
void initShaders()
initShaders
Definition: filter_grow_cut.hpp:34
void release()
release
Definition: display.hpp:85
void setUniform1i(const char *name_uniform, int value0)
SetUniform.
Definition: display.hpp:236