Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
meanfilter.hpp
Go to the documentation of this file.
1 
23 #ifndef __MEANFILTER__
24 #define __MEANFILTER__
25 
26 #include <tucano/tucano.hpp>
27 
28 
29 namespace Tucano
30 {
31 
32 namespace Effects
33 {
34 
40 class MeanFilter : public Tucano::Effect
41 {
42 public:
48  MeanFilter (void) {}
49 
53  virtual void initialize()
54  {
55  loadShader(shader, "meanfilter");
56  quad.createQuad();
57  }
58 
62  void renderTexture(Tucano::Texture& tex, Eigen::Vector2i viewport)
63  {
64  glViewport(0, 0, viewport[0], viewport[1]);
65  shader.bind();
66 
67  shader.setUniform("imageTexture", tex.bind());
68  shader.setUniform("kernelsize", kernelsize);
69  shader.setUniform("viewportSize", viewport);
70 
71  quad.render();
72 
73  shader.unbind();
74  tex.unbind();
75  }
76 
81  void setKernel (int kernel)
82  {
83  kernelsize = kernel;
84  }
85 
90  int getKernelSize (void)
91  {
92  return kernelsize;
93  }
94 
95 private:
96 
99 
101  int kernelsize = 3;
102 
105 };
106 }
107 
108 }
109 
110 #endif
A simple mean filter for image processing.
Definition: meanfilter.hpp:40
void createQuad(void)
Sets the mesh as Unit Quad.
Definition: mesh.hpp:841
Tucano::Shader shader
The mean filter shader.
Definition: meanfilter.hpp:98
MeanFilter(void)
Default Constructor.
Definition: meanfilter.hpp:48
Definition: bufferobject.hpp:34
void bind(int texture_unit)
Binds the texture to a given unit. Note that if there is another texture already binded to this unit...
Definition: texture.hpp:285
Tucano::Mesh quad
A quad to be rendered forcing one call of the fragment shader per image pixel.
Definition: meanfilter.hpp:104
void setKernel(int kernel)
Set kernel size.
Definition: meanfilter.hpp:81
A Shader object represents one GLSL program.
Definition: shader.hpp:45
void renderTexture(Tucano::Texture &tex, Eigen::Vector2i viewport)
Applies the mean filter to an image.
Definition: meanfilter.hpp:62
int getKernelSize(void)
Returns the current size of the kernel.
Definition: meanfilter.hpp:90
void unbind(void)
Disables the shader program.
Definition: shader.hpp:1184
virtual void initialize()
Initializes the effect, creating and loading the shader.
Definition: meanfilter.hpp:53
virtual Shader * loadShader(string shader_name)
Loads a shader by filename, initializes it, and inserts in shaders list.
Definition: effect.hpp:73
virtual void render(void)
Render the mesh triangles. The method binds the buffers, calls the method to render triangles...
Definition: mesh.hpp:756
An OpenGL texture. It can be a simple texture or an FBO texture.
Definition: texture.hpp:41
void bind(void)
Enables the shader program for usage.
Definition: shader.hpp:1176
A common Mesh, usually containing triagles or points.
Definition: mesh.hpp:194
The Effect class is a holder for Shaders. It is completely optional, but is contains a few methods fo...
Definition: effect.hpp:43
void unbind(void)
Unbinds this texture and frees the texture unit.
Definition: texture.hpp:367
int kernelsize
The size of the mean filter kernel (window size to apply convolution)
Definition: meanfilter.hpp:101
void setUniform(GLint location, GLint a, GLint b, GLint c, GLint d)
Sets an uniform integer 4D vector (ivec4) given a location and the vector values. ...
Definition: shader.hpp:1258