Skip to content

Commit

Permalink
Handle the case that too many points were requested in head and tail …
Browse files Browse the repository at this point in the history
…filter
  • Loading branch information
chambbj committed Jun 12, 2017
1 parent 60f1949 commit ad6a625
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions doc/stages/filters.head.rst
Expand Up @@ -6,6 +6,11 @@ filters.head
The HeadFilter returns a specified number of points from the beginning of the
PointView.

.. note::

If the requested number of points exceeds the size of the point cloud, all
points are passed with a warning.


Example #1
----------
Expand Down
7 changes: 6 additions & 1 deletion doc/stages/filters.tail.rst
Expand Up @@ -6,6 +6,11 @@ filters.tail
The TailFilter returns a specified number of points from the end of the
PointView.

.. note::

If the requested number of points exceeds the size of the point cloud, all
points are passed with a warning.


Example #1
----------
Expand All @@ -28,7 +33,7 @@ Sort and extract the 100 lowest intensity points.
}
]
}
.. seealso::

Expand Down
6 changes: 5 additions & 1 deletion filters/HeadFilter.hpp
Expand Up @@ -66,9 +66,13 @@ class PDAL_DLL HeadFilter : public Filter

PointViewSet run(PointViewPtr view)
{
if (m_count > view->size())
log()->get(LogLevel::Warning)
<< "Requested number of points (count=" << m_count
<< ") exceeds number of available points.\n";
PointViewSet viewSet;
PointViewPtr outView = view->makeNew();
for (PointId i = 0; i < m_count; ++i)
for (PointId i = 0; i < std::min(m_count, view->size()); ++i)
outView->appendPoint(*view, i);
viewSet.insert(outView);
return viewSet;
Expand Down
7 changes: 6 additions & 1 deletion filters/TailFilter.hpp
Expand Up @@ -66,9 +66,14 @@ class PDAL_DLL TailFilter : public Filter

PointViewSet run(PointViewPtr view)
{
if (m_count > view->size())
log()->get(LogLevel::Warning)
<< "Requested number of points (count=" << m_count
<< ") exceeds number of available points.\n";
PointViewSet viewSet;
PointViewPtr outView = view->makeNew();
for (PointId i = view->size() - m_count; i < view->size(); ++i)
for (PointId i = view->size() - std::min(m_count, view->size());
i < view->size(); ++i)
outView->appendPoint(*view, i);
viewSet.insert(outView);
return viewSet;
Expand Down

0 comments on commit ad6a625

Please sign in to comment.