Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PMDWarp.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #ifndef __PMDWARP_HH__
26 #define __PMDWARP_HH__
27 
28 #include <Base/Image/Image.hh>
29 #include <Geometry/ProjectionParametersPerspectiveDepth.hh>
30 #include <Geometry/ProjectionParametersPerspective.hh>
31 
32 #include <OpenGLFramework/Base/glfTexture2D.hh>
33 #include <OpenGLFramework/Base/glfBatch.hh>
34 #include <OpenGLFramework/Passive/glfPassiveMatrix.hh>
35 #include <OpenGLFramework/Passive/glfPassiveViewport.hh>
36 #include <OpenGLFramework/Passive/glfPassiveDepthBufferMode.hh>
37 
38 #include <bias_config.h>
39 
40 namespace BIAS {
41 
42 /**
43 * class can be used to warp sequences of pmd depth images into
44 * a second view with different parameters, including a different camera center.
45 *
46 * \attention this a specialized implementation, mind the usage.
47 *
48 * usage:
49 * - establish OpenGL context to be used! Let it be current and valid!
50 * - Call Init()
51 * - if projective texturing has to be used call UseProjectiveTexturing()
52 * for each warping call :
53 * - upload images using Upload* methods.
54 * - set virtual camera params via SetTargetCameraParameters();
55 * - call Draw()
56 *
57 * deliverence of output can be controlled using the SetRenderTarget() method.
58 *
59 * \author bartczak 02/2008
60 **/
61 class BIASOpenGLFramework_EXPORT PMDWarp {
62 public:
63  /**
64  * Initializes all neccessary data in order to render using a batch
65  * \param parametersHaveDistortion is a flag the toggles the use of distortion parameters, if this is
66  * set to false then a shader using idealy perspective camera parameters is used, otherwise vertices are
67  * displaced so that they form a distorted image, uniform params are derived from target parameters
68  * (see SetTargetCameraParameters)!
69  * \attention call this method only if the gl-context
70  * that has to be used is active and valid.
71  **/
72  void Init(const BIAS::ProjectionParametersPerspective& pppd,
73  bool targetParametersHaveDistortion=false);
74 
75  /** Upload the pmd depth image to the graphics card. Do not flip the image!
76  **/
77  void UploadDepthMap(const BIAS::Image<float>& pmdDepthImage);
78 
79  /** Upload the pmd depth image to the graphics card. Do not flip the image!
80  **/
81  void UploadDepthMap(const BIAS::ImageBase& pmdDepthImage);
82 
83  /** ppp extrinsicis have to be in global coordinates of pppd of Init call!
84  * \Attention projective texturing cannot deal with distortion!
85  **/
86  void UseProjectiveTexturing(const BIAS::ProjectionParametersPerspective& ppp);
87 
88  /** Upload the color image to the graphics card. Do not flip the image!
89  * \Attention projective texturing cannot deal with distortion!
90  **/
91  void UploadProjectiveTexture(const BIAS::Image<unsigned char>& projectiveTexture);
92 
93  void SetRenderTarget(const BIAS::glfRenderTarget* renderTarget);
94 
95  /** is also used to determine viewport
96  * \attention relativePpp means extrinsics relative to the pppd param passed
97  * to Init().
98  **/
99  void SetTargetCameraParameters(const BIAS::ProjectionParametersPerspective& relativePpp,
100  double zNear, double zFar);
101 
102  /**
103  * \attention This method should not be used if distortion is used, if distortion parameters are required
104  * and you use this method the result is undefined.
105  */
106  void SetTargetCameraParameters(BIAS::Matrix4x4<double> modelViewMatrix,
107  BIAS::Matrix4x4<double> projectionMatrix,
108  unsigned int width, unsigned int height);
109 
110  void SetTargetCameraParametersToGlobal(bool global);
111 
112  void SetViewportSize(unsigned int width, unsigned int height);
113 
114  /* Use this method to use the viewport currently set in the global opengl state of current context,
115  i.e. that no viewport is set by class!
116  */
117  void SetViewportToGlobal(bool global);
118 
119  void ChangeZClipping(double zNear, double zFar);
120 
121  /** Function is used to assign a hypotheses to the warped depth map.
122  * The result will be pushed to the MRT target identified by output.
123  * The result is a 3D image the first two channels coding the two representants
124  * the warped depth is lying in between, if an exact representant is found, both will be the same.
125  * The third channels is holding the relative distance of the depth to the two representants.
126  * The range between zNear and zFar is equidistantly discretized into N intervalls.
127  *
128  * \attention call after init, use of SetTargetCameraParameters() is not required.
129  **/
130  void ExecuteLinearHypothesesAssignment(const BIAS::ProjectionParametersPerspective& relativePpp,
131  double zNear, double zFar, float N, int output=0);
132 
133  //renders the result into the forseen output
134  void Draw();
135 
136  BIAS::glfBatch& GetBatch();
137  BIAS::glfDepthBufferMode& GetDepthBufferMode();
138 
139  /**
140  * if disparity output is required, then points with the distance
141  * (dist_from_cam) will get disparity (disp)
142  * all disparities will also be scaled with the given scale factor
143  */
144  void SetDispForDistanceAndScale(const float& dist_from_cam,
145  const float& disp, const float& scale);
146 
147 
148  ~PMDWarp();
149  PMDWarp();
150 
151 protected:
152 
155 
159 
162 
163 
164  BIAS::glfVertexBuffer vertices_;//the placeholders for the mesh vertices
165  BIAS::glfElementBuffer elements_;//indices forming the mesh
166 
168 
174 
177 
179  unsigned int depthImageWidth_;
180  unsigned int depthImageHeight_;
181 
183 
184  void SetupDefaultPrimitiveRendering_();
185  void SetupShadersDefault_();
186  void SetupShadersProjectiveTexturing_();
187 
188  bool targetParametersHaveDistortion_;//<!tells whether distortion on target image shall be used
189 
190  float maxSize_;
191 };
192 
193 } //end of namespace MIP
194 
195 
196 #endif
197 
An element buffer contains vertex indices that form primitives.
float maxSize_
Definition: PMDWarp.hh:190
Defines the usage of the depth buffer.
BIAS::glfShader fragmentProgram_
Definition: PMDWarp.hh:172
BIAS::glfPassiveViewport globalViewport_
Definition: PMDWarp.hh:161
A 2D texture.
Definition: glfTexture2D.hh:40
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
bool targetParametersHaveDistortion_
Definition: PMDWarp.hh:188
unsigned int depthImageHeight_
Definition: PMDWarp.hh:180
BIAS::glfMatrix textureMatrix_
Definition: PMDWarp.hh:176
BIAS::glfVertexBuffer vertices_
Definition: PMDWarp.hh:164
A vertex buffer contains an array of vertices that can be used for rendering.
A batch represents a single Draw call including all parameters (render states).
Definition: glfBatch.hh:48
BIAS::glfMatrix modelView_
Definition: PMDWarp.hh:156
A shader program composed of several shaders.
This class allows to use the currently set viewport in the global opengl state!
A GLSL vertex shader or fragment shader, which must be linked in a shader program.
Definition: glfShader.hh:39
BIAS::ProjectionParametersPerspective pmdParams_
Definition: PMDWarp.hh:153
BIAS::glfShader geometryProgram_
Definition: PMDWarp.hh:173
BIAS::glfTexture2D projectiveTexture_
Definition: PMDWarp.hh:175
BIAS::glfViewport viewport_
Definition: PMDWarp.hh:160
class for setting viewports
Definition: glfViewport.hh:37
BIAS::ProjectionParametersPerspective targetParams_
Definition: PMDWarp.hh:154
bool defaultRendering_
Definition: PMDWarp.hh:182
A 4x4 matrix in native OpenGL format.
Definition: glfMatrix.hh:41
BIAS::glfPassiveRenderMatrix globalModelViewNProjection_
Definition: PMDWarp.hh:158
BIAS::glfMatrix Projection_
Definition: PMDWarp.hh:157
BIAS::glfDepthBufferMode depthBufferMode_
Definition: PMDWarp.hh:167
This class allows to use the currently set RenderMatrix in the global opengl state! ...
BIAS::glfShader vertexProgram_
Definition: PMDWarp.hh:171
Interface for render targets.
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
BIAS::glfBatch batch_
Definition: PMDWarp.hh:178
unsigned int depthImageWidth_
Definition: PMDWarp.hh:179
BIAS::glfTexture2D pmdDepthImage_
Definition: PMDWarp.hh:169
BIAS::glfElementBuffer elements_
Definition: PMDWarp.hh:165
class can be used to warp sequences of pmd depth images into a second view with different parameters...
Definition: PMDWarp.hh:61
BIAS::glfShaderProgram shaderProgram_
Definition: PMDWarp.hh:170