Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MultipleDepthWarp.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 __MULTIPLE_DEPTH_WARP_HH__
26 #define __MULTIPLE_DEPTH_WARP_HH__
27 
28 #include <Geometry/Projection.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/Base/glfFramebufferObject.hh>
35 
36 #include <bias_config.h>
37 
38 namespace BIAS {
39 
40  class BIASOpenGLFramework_EXPORT MultipleDepthWarp {
41  public:
42 
44  NONE = 0, POLYNOM = 1, LINEAR = 2
45  };
46 
47  enum WARPING_TYPE {
48  DISPARITY = 0, DEPTH = 1
49  };
50 
53 
54  /**
55  * @brief
56  * \param targetCam must be a perspective camera
57  * \param sourceCameras must be a vector of cameras
58  * \param createDepthMaps determines whether the depth map textures, which are used for generating the triangle meshes are generated by this object or if you pass pointers to already existent depth maps, in the later case UploadDepthMap will use the specified textures.
59  */
60  int
61  Init(const ProjectionParametersPerspective& targetCam, std::vector<
62  Projection>& sourceCameras, bool createDepthMaps = true);
63 
64  void ChangeTargetCam(const ProjectionParametersPerspective& targetCam);
65  /**
66  * @brief
67  * sets the parameters for the camera for projective texturing
68  * this camera will be used to project the texture on the scene
69  * textureCam must be a perspective camera
70  */
71  int SetProjectiveTextureCam(const ProjectionParametersPerspective& textureCam);
72 
73  /**
74  * @brief
75  * uploads the image which will be used for projective texturing of the scene
76  * to the corresponding texture
77  * projectiveTexture image for projective texturing
78  */
79  void UploadProjectiveTexture(const Image<unsigned char>& projectiveTexture);
80 
81  /**
82  * enable or disables use of projective texturing
83  */
84  void UseProjectiveTexturing(bool enable) {
85  useProjectiveTexturing_ = enable;
86  }
87 
88  /**
89  * @brief
90  * uploads the given depthMap to the gpu as texture
91  * depthMap is a depth map from source camera i
92  */
93  int UploadDepthMap(Image<float>& depthMap, unsigned int index);
94 
95  /**
96  * @brief
97  * sets a texture for depthMap
98  * \attention can only be used if createDepthMaps = false by calling Init
99  */
100  int SetDepthMap(glfTexture2D* depthMap, unsigned int index);
101 
102  /**
103  * @brief
104  * warps the depths maps for all sourceCameras to the target camera
105  * view as disparity / depth map
106  */
107  int Warp();
108 
109  /**
110  * @brief
111  * warps the depths maps for all sourceCameras to the target camera view as disparity map
112  */
113  int Warp(unsigned int index);
114 
115  int SetupNViewsWarp(const double& distToScreen,
116  const double& zoom, const double& shift,
117  unsigned int numberOfViews, unsigned int centralViewIndex, bool separate = true);
118 
119  int WarpNViews();
120 
121  /**
122  * @brief
123  * gives the warped disparity / depth map as a bias image
124  */
125  int GetWarpedDisparity(Image<float>& dispMap);
126 
127  /**
128  * @brief
129  * gives the warped zbuffer as bias image
130  */
131  int GetWarpedZBuffer(Image<float>& zbuffer);
132 
133  int GetProjectedTexture(Image<unsigned char>& texture);
134 
135  /**
136  * @brief
137  * if disparity output is required, then points with the distance
138  * (dist_from_cam) will get disparity (disp)
139  */
140  void SetDispForDistance(const float& dist_from_cam, const float& disp);
141 
142  /** Determines the baseline of the virtual standard stereo setup used for disparity calculation.
143  */
144  void SetBaseline(const float& baseline);
145 
146  /**
147  * @brief
148  * this function sets near and far clipping planes for the target camera
149  * default parameters defined in the constructor are zNear = 100, zFar = 8000
150  */
151  void SetZNearAndZFar(const float& zNear, const float& zFar);
152 
153  void SetDiscardAngle(float degree);
154 
155  void SetDepthScaleBeforeWarping(float scale);
156 
157  void FlopTextureCoordinates(bool flop) {
158  flop_ = flop;
159  }
160 
161  void FlipTextureCoordinates(bool flip) {
162  flip_ = flip;
163  }
164 
166  return resultDispTextures_[current_index_];
167  }
168 
169  int GetTextureAsImage(Image<float>& dispMap, unsigned int index) {
170  if (index < resultDispTextures_.size()) {
171  resultDispTextures_[index]->CopyToImage(dispMap);
172  return 0;
173  } else {
174  return -1;
175  }
176  }
177 
178  glfTexture2D* GetTexture(unsigned int index) {
179  if (index < resultDispTextures_.size()) {
180  return resultDispTextures_[index];
181  } else {
182  return NULL;
183  }
184  }
185 
187  return &renderTarget_;
188  }
189 
191  depthCorType_ = type;
192  }
193 
195  warpType_ = type;
196  }
197 
198  std::vector<glfTexture2D*>* GetResultTexturesFromNViewWarp() {
199  return &resultTexturesForNViews_;
200  }
201 
202  std::vector<glfTexture2D*>* GetResultDepthMapsFromNViewWarp() {
203  return &resultDepthMapsForNViews_;
204  }
205 
206  void SwithToMultiStereoModus(bool stereo) {
207  multiStereoModus_ = stereo;
208  }
209 
210  private:
211 
212  DEPTH_COR_TYPE depthCorType_;
213  WARPING_TYPE warpType_;
214 
215  bool multiStereoModus_, initCalled_, flop_, flip_, createDepthMaps_, useProjectiveTexturing_, separate_, clearColorBuffer_;
216 
217  float zNear_, zFar_, thr_, depthScaleBeforeWarping_;
218  //float dist_from_cam_, disp_; //this is now covered by baseline_ and focallengthContained_
219  /** defines the baseline of the virtual stereo setup used to calculated disprities.
220  this baseline can already contain focallength information.
221  If so focallengthContained will be true.
222  Formula used to calculate the disaprity is:
223  d=targetParam.f * baseline_/z. In the case where baseline information are contrained
224  this becomes d=baseline_/z.
225  */
226  float baseline_;
227  /** Tells whether baseline_ is already containing focallength information.
228  */
229  bool focallengthContained_;
230 
231  float minDepth_, maxDepth_, depthRange_;
232 
233  unsigned numberOfSampForDepthCorr_;
234 
235  double nViewsWarpDistToScreen_, nViewsWarpEyeDist_, nViewsWarpSceneScale_, nViewsWarpShift_;
236 
237  unsigned int current_index_;
238 
239  unsigned int numberOfViews_;
240 
241  Image<float> depthCorrImageLUT_;
242  glfTexture2D* depthCorrTexLUTP_;
243 
244  std::vector<glfTexture2D*> depthMaps_;
245  std::vector<glfTexture2D*> resultDepthMapsForNViews_;
246  std::vector<glfTexture2D*> resultTexturesForNViews_;
247  glfTexture2D resultDispTexture_;
248  std::vector<glfTexture2D*> resultDispTextures_;
249  std::vector<glfTexture2D*> resultColorTextures_;
250  glfTexture2D resultZBufferTexture_;
251  glfTexture2D projectiveTexture_;
252 
253  ProjectionParametersPerspective targetParams_;
254  std::vector<Projection> sourceParams_;
255  std::vector<Vector3<double> > cameraCenters_;
256 
257  glfBatch batch_;
258 
259  glfMatrix modelViewMatrix_;
260  glfMatrix projectionMatrix_;
261  glfMatrix textureMatrix_;
262 
263  std::vector<glfMatrix> modelViewMatricesForNViewWarp_;
264  std::vector<glfMatrix> projectionMatricesForNViewWarp_;
265 
266  glfViewport viewport_;
267 
268  glfVertexBuffer vertices_;//the placeholders for the mesh vertices
269  glfElementBuffer elements_;//indices forming the mesh
270 
271  glfDepthBufferMode depthBufferMode_;
272 
273  glfFramebufferObject renderTarget_;
274 
275  BIAS::glfShaderProgram shaderProgram_;
276  BIAS::glfShader vertexShader_;
277  BIAS::glfShader fragmentShader_;
278  BIAS::glfShader geometryShader_;
279 
280  void SetupPrimitiveRendering_();
281  void SetupShaders_(int shaderType);
282 
283  void CreateDepthCorrectionLUT_(ProjectionParametersPerspectiveDepth& pppd);
284 
285  };
286 }
287 
288 #endif /* __MULTIPLE_DEPTH_WARP_HH__ */
An element buffer contains vertex indices that form primitives.
std::vector< glfTexture2D * > * GetResultDepthMapsFromNViewWarp()
Defines the usage of the depth buffer.
additional depth calibration parameters for a perspective depth camera to be used for ToF-(PMD) camer...
A 2D texture.
Definition: glfTexture2D.hh:40
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
int GetTextureAsImage(Image< float > &dispMap, unsigned int index)
glfFramebufferObject * GetFrameBufferObject()
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
A shader program composed of several shaders.
A GLSL vertex shader or fragment shader, which must be linked in a shader program.
Definition: glfShader.hh:39
This class hides the underlying projection model, like projection matrix, spherical camera...
Definition: Projection.hh:70
void SwithToMultiStereoModus(bool stereo)
class for setting viewports
Definition: glfViewport.hh:37
void FlipTextureCoordinates(bool flip)
void SetWarpType(WARPING_TYPE type)
A 4x4 matrix in native OpenGL format.
Definition: glfMatrix.hh:41
void FlopTextureCoordinates(bool flop)
void UseProjectiveTexturing(bool enable)
enable or disables use of projective texturing
std::vector< glfTexture2D * > * GetResultTexturesFromNViewWarp()
void SetDepthCorType(DEPTH_COR_TYPE type)
glfTexture2D * GetTexture(unsigned int index)
glfTexture2D * GetWarpedDispTexture()