1 #include <GLviewer/OutputAttachments/OutputLensDistortion.hh>
2 #include <Base/Image/Image.hh>
3 #include <Base/Image/ImageIO.hh>
23 " gl_TexCoord[0] = gl_MultiTexCoord0;\r\n"
24 " gl_Position = ftransform();\r\n"
27 "uniform sampler2D tex;\r\n"
28 "uniform sampler2D dep;\r\n"
29 "uniform float w;\r\n"
30 "uniform float h;\r\n"
31 "uniform sampler2D lookup;\r\n"
35 " vec2 indirect = texture2D(lookup, gl_TexCoord[0].st).st;\r\n"
36 " gl_FragColor = texture2D(tex, indirect);\r\n"
37 " gl_FragDepth = texture2D(dep, indirect).r;\r\n"
47 BIASERR(
"lens distortion only works on ProjectionParametersPerspective");
54 unsigned int width, height;
61 for (
unsigned int y=0; y<height; y++) {
62 for (
unsigned int x=0; x<width; x++) {
66 source = idealK * Kinv * source;
84 distortionMap_.
UploadImage(lookupTexture, GL_RGB32F_ARB);
91 BIASWARN(
"Target is NULL, not drawing anything.");
96 glGetIntegerv(GL_VIEWPORT, vp.
GetData());
98 unsigned int imgWidth = vp[2] - vp[0];
99 unsigned int imgHeight = vp[3] - vp[1];
112 glMatrixMode(GL_PROJECTION);
115 gluOrtho2D(0, imgWidth, 0, imgHeight);
116 glMatrixMode(GL_MODELVIEW);
121 glPushAttrib(GL_ENABLE_BIT);
122 glEnable(GL_TEXTURE_2D);
127 glColor3f(1.0, 0.0, 0.0);
128 glTexCoord2f(0.0, 0.0);
129 glVertex2f(0.0, 0.0);
131 glColor3f(0.0, 1.0, 0.0);
132 glTexCoord2f(0.0, 1.0);
133 glVertex2f(0.0, imgHeight);
135 glColor3f(0.0, 0.0, 1.0);
136 glTexCoord2f(1.0, 1.0);
137 glVertex2f(imgWidth, imgHeight);
139 glColor3f(1.0, 1.0, 1.0);
140 glTexCoord2f(1.0, 0.0);
141 glVertex2f(imgWidth, 0.0);
145 glMatrixMode(GL_MODELVIEW);
147 glMatrixMode(GL_PROJECTION);
151 GLF_THROW_ON_OPENGL_ERROR
void SetUniform(const std::string &varName, float value)
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
int InitShader_()
creates strings with shader code and calls InitShader(vertex, fragment) from superclass ...
void Create()
Creates the texture but does not upload any data yet.
int Draw_()
main draw function
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
void SetWrapS(GLenum wrapS)
Sets the wrapping mode for the 1st texture coordinate.
void UploadImage(const BIAS::ImageBase &image, GLenum internalFormat=0, int mipmap=0)
Uploads a BIAS::Image to a mipmap of the texture.
int InitShader(std::string vertexCode, std::string fragmentCode)
can be called to create output attachment without having to derive new subclass will also create FBO ...
int GetTextureNrInUniformFormat()
Returns the OpenGL texture number in uniform format or -1 for error.
BIAS::glfRenderTarget * target_
void BindTU() const
Binds the texture.
void SetMinFilter(GLenum minFilter)
Sets the minifying function.
void Bind() const
Binds the shader program.
virtual void Bind() const =0
Makes this render target the currently used render target.
BIAS::Vector4< float > ClearColor_
void SetWrapT(GLenum wrapT)
Sets the wrapping mode for the 2nd texture coordinate.
BIAS::glfTexture2D specialDisplayTex_
void GetIdealK(KMatrix &K) const
void ClearDepthBuffer(float depth=1.0f)
Clears the depth buffer of the render target with the given value.
virtual ~OutputLensDistortion()
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
virtual bool Undistort(BIAS::HomgPoint2D &point2d) const
Using the Matlab camera calibration toolbox parameters for an undistortion of distorted coordinates...
virtual BIAS::KMatrix GetK() const
const T * GetData() const
get the data pointer the member function itself is const (before {..}) because it doesn't change the...
BIAS::glfShaderProgram shaderProg_
void CreateLookupTable(BIAS::ProjectionParametersBase *pp)
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
void SetTextureNr(GLint textureNr)
Sets the OpenGL texture number (GL_TEXTURE0 - GL_TEXTURE[MaxTextureUnit-1]).
void ClearColorBuffer(float red=0.0f, float green=0.0f, float blue=0.0f, float alpha=0.0f)
Clears the color buffer of the render target with the given color.
Class for extra rendering pass in GLProjection (for now only used in glutGLviewer) ...
BIAS::glfTexture2D specialDisplayDepth_
KMatrix Invert() const
returns analyticaly inverted matrix
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
Interface for render targets.
void SetMagFilter(GLenum magFilter)
Sets the magnification function.