Skip to content

Commit

Permalink
Add appentPoints to PointView, and somewhat simplify the Head/Tail fi…
Browse files Browse the repository at this point in the history
…lter code
  • Loading branch information
chambbj committed May 15, 2019
1 parent b88c039 commit a9c24de
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
16 changes: 8 additions & 8 deletions filters/HeadFilter.hpp
Expand Up @@ -37,6 +37,8 @@
#include <pdal/Filter.hpp>
#include <pdal/PointViewIter.hpp>

#include <numeric>

namespace pdal
{

Expand Down Expand Up @@ -72,20 +74,18 @@ class PDAL_DLL HeadFilter : public Filter
<< ") exceeds number of available points.\n";
PointViewSet viewSet;
PointViewPtr outView = view->makeNew();
PointId start;
PointId end;
if (m_invert)
{
start = m_count;
end = view->size();
std::vector<PointId> ids(view->size()-m_count);
std::iota(ids.begin(), ids.end(), m_count);
outView->appendPoints(*view, ids);
}
else
{
start = 0;
end = (std::min)(m_count, view->size());
std::vector<PointId> ids(m_count);
std::iota(ids.begin(), ids.end(), 0);
outView->appendPoints(*view, ids);
}
for (PointId i = start; i < end; ++i)
outView->appendPoint(*view, i);
viewSet.insert(outView);
return viewSet;
}
Expand Down
17 changes: 8 additions & 9 deletions filters/TailFilter.hpp
Expand Up @@ -37,6 +37,8 @@
#include <pdal/Filter.hpp>
#include <pdal/PointViewIter.hpp>

#include <numeric>

namespace pdal
{

Expand Down Expand Up @@ -71,21 +73,18 @@ class PDAL_DLL TailFilter : public Filter
<< ") exceeds number of available points.\n";
PointViewSet viewSet;
PointViewPtr outView = view->makeNew();
PointId start;
PointId end;
if (m_invert)
{
start = 0;
end = view->size() - (std::min)(m_count, view->size());
std::vector<PointId> ids(view->size()-m_count);
std::iota(ids.begin(), ids.end(), 0);
outView->appendPoints(*view, ids);
}
else
{
start = view->size() - (std::min)(m_count, view->size());
end = view->size();
std::vector<PointId> ids(m_count);
std::iota(ids.begin(), ids.end(), view->size()-m_count);
outView->appendPoints(*view, ids);
}

for (PointId i = start; i < end; ++i)
outView->appendPoint(*view, i);
viewSet.insert(outView);
return viewSet;
}
Expand Down
7 changes: 7 additions & 0 deletions pdal/PointView.hpp
Expand Up @@ -94,6 +94,7 @@ class PDAL_DLL PointView : public PointContainer
{ return m_size == 0; }

inline void appendPoint(const PointView& buffer, PointId id);
inline void appendPoints(const PointView& buffer, std::vector<PointId> ids);
void append(const PointView& buf)
{
// We use size() instead of the index end because temp points
Expand Down Expand Up @@ -582,6 +583,12 @@ inline void PointView::appendPoint(const PointView& buffer, PointId id)
assert(m_temps.empty());
}

inline void PointView::appendPoints(const PointView& buffer, std::vector<PointId> ids)
{
for (auto const& i : ids)
appendPoint(buffer, i);
}


// Make a temporary copy of a point by adding an entry to the index.
inline PointId PointView::getTemp(PointId id)
Expand Down

0 comments on commit a9c24de

Please sign in to comment.