nburrus/nestk — Issue #6: Rewrite loops so that debug mode gets faster
Author: nburrus
Created: 2011-11-23 09:34:58+00:00
State: open

According to Cristobal Belles:

//=============47 ms en un i7

for_all_rc(m_image->depthMaskRef())
{
float d = m_image->depth()(r,c);
if (d < 1e-5 || ntk::math::isnan(d))
m_image->depthMaskRef()(r,c) = 0;
else
m_image->depthMaskRef()(r,c) = 255;
}

//=============

Equivalent code, faster in debug mode:

//=============3 ms

cv::Mat1b& depth_mask = m_image->depthMaskRef();
const cv::Mat1f& depth = m_image->depth();
for (int r = 0; r < depth_mask.rows; ++r)
{
unsigned char* f_depth_mask = depth_mask.ptr(r);
const float* f_depth = depth.ptr(r);
for (int c = 0; c < depth_mask.cols; ++c)
{
float d = f_depth[c];
if (d < 1e-5 || ntk::math::isnan(d))
f_depth_mask[c] = 0;
else
f_depth_mask[c] = 255;
}
}