stereo_camera_model.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2013, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Suat Gedikli */
36 
39 
40 using namespace std;
41 
43  float near_clipping_plane_distance,
44  float far_clipping_plane_distance, float fx, float fy, float cx,
45  float cy, float base_line, float disparity_resolution)
46  : SensorModel::Parameters(width, height, near_clipping_plane_distance, far_clipping_plane_distance)
47  , fx_(fx)
48  , fy_(fy)
49  , cx_(cx)
50  , cy_(cy)
51  , base_line_(base_line)
52  , disparity_resolution_(disparity_resolution)
53  , padding_coefficients_(Eigen::Vector3f(disparity_resolution_ / (fx_ * base_line_), 0, 0))
54 {
55 }
56 
58 {
59 }
60 
62 {
65 }
66 
67 void mesh_filter::StereoCameraModel::Parameters::setCameraParameters(float fx, float fy, float cx, float cy)
68 {
69  fx_ = fx;
70  fy_ = fy;
71  cx_ = cx;
72  cy_ = cy;
73 }
74 
76 {
77  base_line_ = base_line;
78 }
79 
81 {
82  disparity_resolution_ = disparity_resolution;
83 }
84 
86 {
88  renderer.setBufferSize(width_, height_);
89  renderer.setCameraParameters(fx_, fy_, cx_, cy_);
90  // GLuint padding_coefficients_id = glGetUniformLocation (renderer.getProgramID (), "padding_coefficients");
91 
92  // // set device dependent padding coefficients
93  // glUniform3f (padding_coefficients_id, padding_coefficients_1_ * padding_scale_,
94  // padding_coefficients_2_ * padding_scale_,
95  // padding_coefficients_3_ * padding_scale_ + padding_offset_ );
96 }
97 
99 {
100  return padding_coefficients_;
101 }
102 
104 {
105  glUniform1f(glGetUniformLocation(renderer.getProgramID(), "near"), near_clipping_plane_distance_);
106  glUniform1f(glGetUniformLocation(renderer.getProgramID(), "far"), far_clipping_plane_distance_);
107 
109  renderer.setBufferSize(width_, height_);
110  renderer.setCameraParameters(fx_, fy_, cx_, cy_);
111 }
112 
114  mesh_filter::StereoCameraModel::Parameters(640, 480, 0.4, 10.0, 525, 525, 319.5, 239.5, 0.075, 0.125);
115 
117  "#version 120\n"
118  "uniform vec3 padding_coefficients;"
119  "void main()"
120  "{"
121  " gl_FrontColor = gl_Color;"
122  " gl_BackColor = gl_Color;"
123  " vec4 vertex = gl_ModelViewMatrix * gl_Vertex;"
124  " vec3 normal = normalize(gl_NormalMatrix * gl_Normal);"
125  " float lambda = padding_coefficients.x * vertex.z * vertex.z + padding_coefficients.y * vertex.z + "
126  "padding_coefficients.z;"
127  " gl_Position = gl_ProjectionMatrix * (vertex + lambda * vec4(normal,0) );"
128  " gl_Position.y = -gl_Position.y;"
129  "}";
130 
132  "void main()"
133  "{"
134  " gl_FragColor = gl_Color;"
135  "}";
136 
137 const string mesh_filter::StereoCameraModel::filterVertexShaderSource = "#version 120\n"
138  "void main ()"
139  "{"
140  " gl_FrontColor = gl_Color;"
141  " gl_TexCoord[0] = gl_MultiTexCoord0;"
142  " gl_Position = gl_Vertex;"
143  " gl_Position.w = 1.0;"
144  "}";
145 
147  "#version 120\n"
148  "uniform sampler2D sensor;"
149  "uniform sampler2D depth;"
150  "uniform sampler2D label;"
151  "uniform float near;"
152  "uniform float far;"
153  "uniform float shadow_threshold;"
154  "const float shadowLabel = 1.0 / 255.0;"
155  "const float nearLabel = 2.0 / 255.0;"
156  "const float farLabel = 3.0 / 255.0;"
157  "float f_n = far - near;"
158  "float threshold = shadow_threshold / f_n;"
159  "void main()"
160  "{"
161  " float sValue = float(texture2D(sensor, gl_TexCoord[0].st));"
162  " if (sValue <= 0) {"
163  " gl_FragColor = vec4 (nearLabel, 0, 0, 0);"
164  " gl_FragDepth = 0;"
165  " }"
166  " else {"
167  " float dValue = float(texture2D(depth, gl_TexCoord[0].st));"
168  " float zValue = dValue * near / (far - dValue * f_n);"
169  " float diff = sValue - zValue;"
170  " if (diff < 0 && sValue < 1) {"
171  " gl_FragColor = vec4 (0, 0, 0, 0);"
172  " gl_FragDepth = float(texture2D(sensor, gl_TexCoord[0].st));"
173  " } else if (diff > threshold) {"
174  " gl_FragColor = vec4 (shadowLabel, 0, 0, 0);"
175  " gl_FragDepth = float(texture2D(sensor, gl_TexCoord[0].st));"
176  " } else if (sValue == 1) {"
177  " gl_FragColor = vec4 (farLabel, 0, 0, 0);"
178  " gl_FragDepth = float(texture2D(sensor, gl_TexCoord[0].st));"
179  " } else {"
180  " gl_FragColor = texture2D(label, gl_TexCoord[0].st);"
181  " gl_FragDepth = 0;"
182  " }"
183  " }"
184  "}";
Parameters(unsigned width, unsigned height, float near_clipping_plane_distance, float far_clipping_plane_distance, float fx, float fy, float cx, float cy, float base_line, float disparity_resolution)
Constructor.
const Eigen::Vector3f padding_coefficients_
padding coefficients
const GLuint & getProgramID() const
float cx_
x component of principal point
void setFilterParameters(GLRenderer &renderer) const
set the shader parameters required for the mesh filtering
float base_line_
distance of the two projective devices that are used to determine the disparities ...
void setCameraParameters(float fx, float fy, float cx, float cy)
set the camera parameters
float fy_
focal length in y-direction
static const std::string filterVertexShaderSource
source code of the vertex shader used to filter the depth map
unsigned width_
width of depth maps generated by the sensor
Definition: sensor_model.h:155
float far_clipping_plane_distance_
distance of far clipping plane
Definition: sensor_model.h:161
void setDisparityResolution(float disparity_resolution)
the quantization of disparity values in pixels. Usually 1/16th or 1/8th for OpenNI compatible devices...
void setBaseline(float base_line)
sets the base line = distance of the two projective devices (camera, projector-camera) ...
Abstracts the OpenGL frame buffer objects, and provides an interface to render meshes, and retrieve the color and depth ap from opengl.
Definition: gl_renderer.h:58
float fx_
focal length in x-direction
static const StereoCameraModel::Parameters & RegisteredPSDKParams
predefined sensor model for OpenNI compatible devices (e.g., PrimeSense, Kinect, Asus Xtion) ...
Parameters for Stereo-like devices.
float near_clipping_plane_distance_
distance of near clipping plane
Definition: sensor_model.h:164
float disparity_resolution_
resolution/quantization of disparity values
Abstract Interface defining Sensor Parameters.
Definition: sensor_model.h:61
static const std::string renderFragmentShaderSource
source code of the fragment shader used to render the meshes
static const std::string filterFragmentShaderSource
source code of the fragment shader used to filter the depth map
void setCameraParameters(float fx, float fy, float cx, float cy)
sets the camera parameters of the pinhole camera where the disparities were obtained. Usually the left camera
void setBufferSize(unsigned width, unsigned height)
set the size of fram buffers
Definition: gl_renderer.cpp:84
const Eigen::Vector3f & getPaddingCoefficients() const
returns the coefficients that are required for obtaining the padding for meshes
static const std::string renderVertexShaderSource
source code of the vertex shader used to render the meshes
void setRenderParameters(GLRenderer &renderer) const
set the shader parameters required for the model rendering
SensorModel::Parameters * clone() const
polymorphic clone method
void setClippingRange(float near, float far)
sets the near and far clipping plane distances in meters
Definition: gl_renderer.cpp:95
unsigned height_
height of depth maps generated by the sensor
Definition: sensor_model.h:158
float cy_
y component of principal point
Abstract Interface defining a sensor model for mesh filtering.
Definition: sensor_model.h:52


perception
Author(s): Ioan Sucan , Jon Binney , Suat Gedikli
autogenerated on Wed Jul 10 2019 04:03:27