diff --git a/filters/PMFFilter.cpp b/filters/PMFFilter.cpp index 3b25383352..6fcd13df79 100644 --- a/filters/PMFFilter.cpp +++ b/filters/PMFFilter.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -202,11 +203,8 @@ std::vector PMFFilter::processGroundApprox(PointViewPtr view) BOX2D bounds; view->calculateBounds(bounds); - double extent_x = floor(bounds.maxx) - ceil(bounds.minx); - double extent_y = floor(bounds.maxy) - ceil(bounds.miny); - - int cols = static_cast(ceil(extent_x/m_cellSize)) + 1; - int rows = static_cast(ceil(extent_y/m_cellSize)) + 1; + size_t cols = ((bounds.maxx - bounds.minx)/m_cellSize) + 1; + size_t rows = ((bounds.maxy - bounds.miny)/m_cellSize) + 1; // Compute the series of window sizes and height thresholds std::vector htvec; @@ -263,8 +261,8 @@ std::vector PMFFilter::processGroundApprox(PointViewPtr view) double y = view->getFieldAs(Dimension::Id::Y, p_idx); double z = view->getFieldAs(Dimension::Id::Z, p_idx); - int r = static_cast(std::floor((y-bounds.miny) / m_cellSize)); - int c = static_cast(std::floor((x-bounds.minx) / m_cellSize)); + int c = Utils::clamp(static_cast(floor((x - bounds.minx) / m_cellSize)), 0, static_cast(cols-1)); + int r = Utils::clamp(static_cast(floor((y - bounds.miny) / m_cellSize)), 0, static_cast(rows-1)); float diff = z - mo(r, c); if (diff < htvec[j])