Skip to content

Commit 42e0492

Browse files
committed
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)
1 parent c9514b8 commit 42e0492

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

modules/rgbd/src/dynafu.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,27 +231,25 @@ void DynaFuImpl<T>::drawScene(OutputArray depthImage, OutputArray shadedImage)
231231

232232
ogl::render(arr, idx, ogl::TRIANGLES);
233233

234-
float f[params.frameSize.width*params.frameSize.height];
235-
float pixels[params.frameSize.width*params.frameSize.height][3];
236-
glReadPixels(0, 0, params.frameSize.width, params.frameSize.height, GL_DEPTH_COMPONENT, GL_FLOAT, &f[0]);
237-
glReadPixels(0, 0, params.frameSize.width, params.frameSize.height, GL_RGB, GL_FLOAT, &pixels[0][0]);
234+
Mat depthData(params.frameSize.height, params.frameSize.width, CV_32F);
235+
Mat shadeData(params.frameSize.height, params.frameSize.width, CV_32FC3);
236+
glReadPixels(0, 0, params.frameSize.width, params.frameSize.height, GL_DEPTH_COMPONENT, GL_FLOAT, depthData.ptr());
237+
glReadPixels(0, 0, params.frameSize.width, params.frameSize.height, GL_RGB, GL_FLOAT, shadeData.ptr());
238238

239239
// linearise depth
240-
for(int i = 0; i < params.frameSize.width*params.frameSize.height; i++)
240+
for(auto it = depthData.begin<float>(); it != depthData.end<float>(); ++it)
241241
{
242-
f[i] = farZ * nearZ / (f[i]*(nearZ - farZ) + farZ);
242+
*it = farZ * nearZ / ((*it)*(nearZ - farZ) + farZ);
243243

244-
if(f[i] >= farZ)
245-
f[i] = std::numeric_limits<float>::quiet_NaN();
244+
if(*it >= farZ)
245+
*it = std::numeric_limits<float>::quiet_NaN();
246246
}
247247

248248
if(depthImage.needed()) {
249-
Mat depthData(params.frameSize.height, params.frameSize.width, CV_32F, f);
250249
depthData.copyTo(depthImage);
251250
}
252251

253252
if(shadedImage.needed()) {
254-
Mat shadeData(params.frameSize.height, params.frameSize.width, CV_32FC3, pixels);
255253
shadeData.copyTo(shadedImage);
256254
}
257255
#else

0 commit comments

Comments
 (0)