PICCANTE  0.4
The hottest HDR imaging library!
filter_warp_2d.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_GL_FILTER_WARP_2D_HPP
19 #define PIC_GL_FILTERING_GL_FILTER_WARP_2D_HPP
20 
21 #include "../../base.hpp"
22 
23 #include "../../util/gl/fbo.hpp"
24 
25 #include "../../util/matrix_3_x_3.hpp"
26 #include "../../filtering/filter_warp_2d.hpp"
27 #include "../../gl/filtering/filter.hpp"
28 
29 namespace pic {
30 
34 class FilterGLWarp2D: public FilterGL
35 {
36 protected:
37 
38  int bmin[2], bmax[2];
39 
42 
46  void initShaders();
47 
48 public:
49 
57 
64  void update(Matrix3x3 h, bool bSameSize, bool bCentroid);
65 
74  void OutputSize(ImageGLVec imgIn, int &width, int &height, int &channels, int &frames)
75  {
76  if(!bSameSize) {
77  FilterWarp2D::computeBoundingBox(h, bCentroid, imgIn[0]->widthf, imgIn[0]->heightf, bmin, bmax);
78  } else {
79  bmin[0] = 0;
80  bmin[1] = 0;
81 
82  bmax[0] = imgIn[0]->width;
83  bmax[1] = imgIn[0]->height;
84  }
85 
86  width = bmax[0] - bmin[0];
87  height = bmax[1] - bmin[1];
88  channels = imgIn[0]->channels;
89  frames = imgIn[0]->frames;
90  }
91 
99  {
100  imgOut = allocateOutputMemory(imgIn, imgOut, false);
101 
102  //update the technique
103  float mid[2];
104 
105  if(bCentroid) {
106  mid[0] = imgIn[0]->widthf * 0.5f;
107  mid[1] = imgIn[0]->heightf * 0.5f;
108  } else {
109  mid[0] = 0.0f;
110  mid[1] = 0.0f;
111  }
112 
113  technique.bind();
114  technique.setUniform2f("mid", mid[0], mid[1]);
115  technique.setUniform2f("inv_tSize", 1.0f / imgIn[0]->widthf, 1.0f / imgIn[0]->heightf);
116  technique.unbind();
117 
118  return imgOut;
119  }
120 };
121 
123 {
124  initShaders();
125 
126  Matrix3x3 h;
127  update(h, false, false);
128 }
129 
130 PIC_INLINE void FilterGLWarp2D::update(Matrix3x3 h, bool bSameSize = false, bool bCentroid = false)
131 {
132  this->bSameSize = bSameSize;
133  this->bCentroid = bCentroid;
134 
135  this->h = h;
136  h.inverse(&h_inv);
137 
138  technique.bind();
139  technique.setUniform3x3("h_inv", h_inv.data, true);
140  technique.unbind();
141 }
142 
144 {
145  //fragment program
147  (
148  uniform sampler2D u_tex; \n
149  uniform mat3 h_inv; \n
150  uniform vec2 mid; \n
151  uniform vec2 inv_tSize; \n
152  out vec4 f_color; \n
153  \n
154  void main(void) {
155  vec2 coords = gl_FragCoord.xy - mid;\n
156  vec3 point_proj = h_inv * vec3(coords, 1.0);
157  point_proj /= point_proj.z;
158  point_proj.xy += mid;
159  point_proj.xy *= inv_tSize;
160  vec3 color = vec3(0.0);
161  if(point_proj.x >= 0.0 && point_proj.x <= 1.0 &&
162  point_proj.y >= 0.0 && point_proj.y <= 1.0) {
163  color = texture(u_tex, point_proj.xy).xyz;\n
164  } \n
165  f_color = vec4(color, 1.0); \n
166  }
167  );
168 
169  technique.initStandard("330", vertex_source, fragment_source, "FilterGLWarp2D");
170 
171  technique.bind();
172  technique.setUniform1i("u_tex", 0);
173  technique.unbind();
174 }
175 
176 } // end namespace pic
177 
178 #endif /* PIC_GL_FILTERING_FILTER_WARP_2D_HPP */
179 
float data[9]
Definition: matrix_3_x_3.hpp:37
TechniqueGL technique
Definition: display.hpp:45
void OutputSize(ImageGLVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_warp_2d.hpp:74
bool bSameSize
Definition: filter_warp_2d.hpp:41
ImageGL * setupAux(ImageGLVec imgIn, ImageGL *imgOut)
setupAux
Definition: filter_warp_2d.hpp:98
Matrix3x3 h
Definition: filter_warp_2d.hpp:40
void setUniform2f(const char *name_uniform, float value0, float value1)
setUniform
Definition: display.hpp:259
ImageGL * allocateOutputMemory(ImageGLVec imgIn, ImageGL *imgOut, bool bDelete)
allocateOutputMemory
Definition: display.hpp:217
The Matrix3x3 class provides methods for managing a 3 by 3 matrix.
Definition: matrix_3_x_3.hpp:29
void bind()
bind
Definition: display.hpp:189
#define MAKE_STRING(input_string)
Matrix3x3 h_inv
Definition: filter_warp_2d.hpp:40
int bmin[2]
Definition: filter_warp_2d.hpp:38
The FilterGLWarp2D class.
Definition: filter_warp_2d.hpp:34
Matrix3x3 * inverse(Matrix3x3 *ret)
inverse computes the inverse of the matrix.
Definition: matrix_3_x_3.hpp:257
The ImageGL class.
Definition: image.hpp:42
FilterGLWarp2D()
FilterGLWarp2D.
void update(Matrix3x3 h, bool bSameSize, bool bCentroid)
update
The FilterGL class.
Definition: filter.hpp:35
void initShaders()
initShaders
The FilterGL class.
Definition: display.hpp:35
#define PIC_INLINE
Definition: base.hpp:33
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
std::string vertex_source
Definition: display.hpp:57
Definition: bilateral_separation.hpp:25
static void computeBoundingBox(Matrix3x3 &h, bool bCentroid, float width, float height, int *bmin, int *bmax)
computeBoundingBox
Definition: filter_warp_2d.hpp:122
std::string fragment_source
Definition: display.hpp:57
The Matrix3x3 class provides methods for managing a 3 by 3 matrix.
Definition: display.hpp:30
void setUniform3x3(const char *name_uniform, const float *matrix, bool bTranspose)
setUniform3x3
Definition: display.hpp:304
bool bCentroid
Definition: filter_warp_2d.hpp:41
int bmax[2]
Definition: filter_warp_2d.hpp:38
std::vector< ImageGL * > ImageGLVec
ImageGLVec an std::vector of pic::ImageGL.
Definition: image_vec.hpp:32
void setUniform1i(const char *name_uniform, int value0)
SetUniform.
Definition: display.hpp:236