Commit 42e04927 authored by Nikita Shulga's avatar Nikita Shulga

Do not use VLA in dynafu.cpp

VLA is part of C99, but still not part of C++ standard
Replace float variable-length-arrays with unique_ptr arrays (which are
part of C++14)
parent c9514b80
...@@ -231,27 +231,25 @@ void DynaFuImpl<T>::drawScene(OutputArray depthImage, OutputArray shadedImage) ...@@ -231,27 +231,25 @@ void DynaFuImpl<T>::drawScene(OutputArray depthImage, OutputArray shadedImage)
ogl::render(arr, idx, ogl::TRIANGLES); ogl::render(arr, idx, ogl::TRIANGLES);
float f[params.frameSize.width*params.frameSize.height]; Mat depthData(params.frameSize.height, params.frameSize.width, CV_32F);
float pixels[params.frameSize.width*params.frameSize.height][3]; Mat shadeData(params.frameSize.height, params.frameSize.width, CV_32FC3);
glReadPixels(0, 0, params.frameSize.width, params.frameSize.height, GL_DEPTH_COMPONENT, GL_FLOAT, &f[0]); glReadPixels(0, 0, params.frameSize.width, params.frameSize.height, GL_DEPTH_COMPONENT, GL_FLOAT, depthData.ptr());
glReadPixels(0, 0, params.frameSize.width, params.frameSize.height, GL_RGB, GL_FLOAT, &pixels[0][0]); glReadPixels(0, 0, params.frameSize.width, params.frameSize.height, GL_RGB, GL_FLOAT, shadeData.ptr());
// linearise depth // linearise depth
for(int i = 0; i < params.frameSize.width*params.frameSize.height; i++) for(auto it = depthData.begin<float>(); it != depthData.end<float>(); ++it)
{ {
f[i] = farZ * nearZ / (f[i]*(nearZ - farZ) + farZ); *it = farZ * nearZ / ((*it)*(nearZ - farZ) + farZ);
if(f[i] >= farZ) if(*it >= farZ)
f[i] = std::numeric_limits<float>::quiet_NaN(); *it = std::numeric_limits<float>::quiet_NaN();
} }
if(depthImage.needed()) { if(depthImage.needed()) {
Mat depthData(params.frameSize.height, params.frameSize.width, CV_32F, f);
depthData.copyTo(depthImage); depthData.copyTo(depthImage);
} }
if(shadedImage.needed()) { if(shadedImage.needed()) {
Mat shadeData(params.frameSize.height, params.frameSize.width, CV_32FC3, pixels);
shadeData.copyTo(shadedImage); shadeData.copyTo(shadedImage);
} }
#else #else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment