@@ -43,7 +43,7 @@ struct DepthImageProjector::Impl
4343 const float minDepth_;
4444 const float maxDepth_;
4545 const float depthHitThreshold_;
46- const float unknownDepthColor_;
46+ const int unknownDepthColor_;
4747
4848 // first path
4949 std::array<cgs::gl::Shader, 3 > shaders_;
@@ -73,7 +73,7 @@ struct DepthImageProjector::Impl
7373 int depthWidth, int depthHeight,
7474 int gridMapWidth, int gridMapHeight, float gridMapResolution,
7575 float gridMapLayerHeight, float gridMapAccumulationWeight,
76- float minDepth, float maxDepth, float depthHitThreshold, float unknownDepthColor,
76+ float minDepth, float maxDepth, float depthHitThreshold, int unknownDepthColor,
7777 const std::string& vertexShader, const std::string& geometryShader, const std::string& fragmentShader,
7878 const std::string& vertexScalingShader, const std::string& fragmentScalingShader);
7979
@@ -92,7 +92,7 @@ DepthImageProjector::Impl::Impl(
9292 int depthWidth, int depthHeight,
9393 int gridMapWidth, int gridMapHeight, float gridMapResolution,
9494 float gridMapLayerHeight, float gridMapAccumulationWeight,
95- float minDepth, float maxDepth, float depthHitThreshold, float unknownDepthColor,
95+ float minDepth, float maxDepth, float depthHitThreshold, int unknownDepthColor,
9696 const std::string& vertexShader, const std::string& geometryShader, const std::string& fragmentShader,
9797 const std::string& vertexScalingShader, const std::string& fragmentScalingShader) :
9898 context_(true ),
@@ -130,7 +130,7 @@ DepthImageProjector::Impl::Impl(
130130 programScaling_(shaderScaling_),
131131 vboScaling_(SQUARE_VERTICIES, GL_STATIC_DRAW),
132132 eboScaling_(SQUARE_INDICIES, GL_STATIC_DRAW),
133- textureOut_(GL_R8UI , gridMapWidth, gridMapHeight),
133+ textureOut_(GL_R8 , gridMapWidth, gridMapHeight),
134134 intermediateSampler_(GL_NEAREST, GL_NEAREST, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE),
135135 fboScaling_(textureOut_)
136136{
@@ -156,15 +156,15 @@ void DepthImageProjector::Impl::updateProjectionMatrix(
156156
157157void DepthImageProjector::Impl::project (cv::Mat& dest, const cv::Mat& color, const cv::Mat& depth)
158158{
159- if (gridMapWidth_ != dest.cols || gridMapHeight_ != dest.rows || CV_8UC3 != dest.type ())
159+ if (gridMapWidth_ != dest.cols || gridMapHeight_ != dest.rows || CV_8UC1 != dest.type ())
160160 {
161161 ROS_ERROR_STREAM (
162162 " Destination image resolution does not match." << std::endl <<
163163 " width: texture=" << gridMapWidth_ << " , input=" << dest.cols << std::endl <<
164164 " height: texture=" << gridMapHeight_ << " , input=" << dest.rows << std::endl <<
165- " channel: texture=" << 3 << " , input=" << dest.channels () << std::endl <<
165+ " channel: texture=" << 1 << " , input=" << dest.channels () << std::endl <<
166166 " elemSize1: texture=" << 1 << " , input=" << dest.elemSize1 () << std::endl <<
167- " type: texture=" << CV_8UC3 << " , input=" << dest.type ());
167+ " type: texture=" << CV_8UC1 << " , input=" << dest.type ());
168168 return ;
169169 }
170170
@@ -239,45 +239,44 @@ void DepthImageProjector::Impl::project(cv::Mat& dest, const cv::Mat& color, con
239239 glDrawArrays (GL_POINTS, 0 , verticies_.size ());
240240 }
241241
242- // // second path
243- // {
244- // //Shaders setup
245- // program_ .use();
246- // glUniform2f(glGetUniformLocation(program_ .get(), "resolution"), width_, height_ );
247- // glUniform1i(glGetUniformLocation(program_ .get(), "texture"), 0);
248- // glUniform1f (glGetUniformLocation(program_ .get() , "unknownDepthColor"), unknownDepthColor_);
242+ // second path
243+ {
244+ // Shaders setup
245+ programScaling_ .use ();
246+ glUniform2f (glGetUniformLocation (programScaling_ .get (), " resolution" ), gridMapWidth_, gridMapHeight_ );
247+ glUniform1i (glGetUniformLocation (programScaling_ .get (), " texture" ), 0 );
248+ glUniform1i (glGetUniformLocation (programScaling_ .get (), " unknownDepthColor" ), unknownDepthColor_);
249249
250- // //Verticies setup
251- // vaoScaling_.mapVariable(vboScaling_, glGetAttribLocation(program_ .get(), "position"), 3, GL_FLOAT, 0);
252- // vaoScaling_.mapVariable(eboScaling_);
250+ // Verticies setup
251+ vaoScaling_.mapVariable (vboScaling_, glGetAttribLocation (programScaling_ .get (), " position" ), 3 , GL_FLOAT, 0 );
252+ vaoScaling_.mapVariable (eboScaling_);
253253
254- // //Disable flags
255- // glDisable(GL_DEPTH_CLAMP);
256- // glDisable(GL_BLEND);
254+ // Disable flags
255+ glDisable (GL_DEPTH_CLAMP);
256+ glDisable (GL_BLEND);
257257
258- // textureIntermediate_.bindToUnit(0);
259- // samplerIntermediate_ .bindToUnit(0);
258+ textureIntermediate_.bindToUnit (0 );
259+ intermediateSampler_ .bindToUnit (0 );
260260
261- // fboScaling_.bind();
262- // glViewport(0, 0, width_, height_ );
261+ fboScaling_.bind ();
262+ glViewport (0 , 0 , gridMapWidth_, gridMapHeight_ );
263263
264- // vaoScaling_.bind();
265- // glDrawElements(GL_TRIANGLES, INDICIES .size(), GL_UNSIGNED_INT, nullptr);
266- // }
264+ vaoScaling_.bind ();
265+ glDrawElements (GL_TRIANGLES, SQUARE_INDICIES .size (), GL_UNSIGNED_INT, nullptr );
266+ }
267267
268268 glFinish ();
269269
270270 // Read result
271- // textureOut_.read(GL_RED, GL_UNSIGNED_BYTE, dest.data, dest.rows * dest.cols * dest.channels());
272- textureIntermediate_.read (GL_RGB, GL_UNSIGNED_BYTE, dest.data , dest.rows * dest.cols * dest.channels ());
271+ textureOut_.read (GL_RED, GL_UNSIGNED_BYTE, dest.data , dest.rows * dest.cols * dest.channels ());
273272}
274273
275274DepthImageProjector::DepthImageProjector (
276275 int colorWidth, int colorHeight,
277276 int depthWidth, int depthHeight,
278277 int gridMapWidth, int gridMapHeight, float gridMapResolution,
279278 float gridMapLayerHeight, float gridMapAccumulationWeight,
280- float minDepth, float maxDepth, float depthHitThreshold, float unknownDepthColor,
279+ float minDepth, float maxDepth, float depthHitThreshold, int unknownDepthColor,
281280 const std::string& vertexShader, const std::string& geometryShader, const std::string& fragmentShader,
282281 const std::string& vertexScalingShader, const std::string& fragmentScalingShader)
283282try
0 commit comments