Skip to content

Commit

Permalink
Handle count option on readers when streaming.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Jul 16, 2018
1 parent 6469b51 commit 7390b02
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pdal/Reader.hpp
Expand Up @@ -54,6 +54,8 @@ class PDAL_DLL Reader : public virtual Stage

void setReadCb(PointReadFunc cb)
{ m_cb = cb; }
point_count_t count() const
{ return m_count; }

protected:
std::string m_filename;
Expand Down
10 changes: 9 additions & 1 deletion pdal/Streamable.cpp
Expand Up @@ -35,6 +35,7 @@
#include <iterator>

#include <pdal/Streamable.hpp>
#include <pdal/Reader.hpp>

namespace pdal
{
Expand Down Expand Up @@ -169,6 +170,11 @@ void Streamable::execute(StreamPointTable& table,
// Separate out the first stage.
Streamable *reader = stages.front();

// We may be limited in the number of points requested.
point_count_t count = std::numeric_limits<point_count_t>::max();
if (Reader *r = dynamic_cast<Reader *>(reader))
count = r->count();

// Build a list of all stages except the first. We may have a writer in
// this list in addition to filters, but we treat them in the same way.
auto begin = stages.begin();
Expand All @@ -185,7 +191,7 @@ void Streamable::execute(StreamPointTable& table,
table.clearSpatialReferences();
PointId idx = 0;
PointRef point(table, idx);
point_count_t pointLimit = table.capacity();
point_count_t pointLimit = std::min(count, table.capacity());

reader->startLogging();
// When we get false back from a reader, we're done, so set
Expand All @@ -201,6 +207,8 @@ void Streamable::execute(StreamPointTable& table,
if (finished)
pointLimit = idx;
}
count -= pointLimit;

reader->stopLogging();
srs = reader->getSpatialReference();
if (!srs.empty())
Expand Down
34 changes: 34 additions & 0 deletions test/unit/StreamingTest.cpp
Expand Up @@ -399,3 +399,37 @@ TEST(Streaming, issue_2069)
t.execute(table);
}

// Make sure that we take the "count" option into account when streaming.
TEST(Streaming, issue_2086)
{
StageFactory f;
Stage *r = f.createStage("readers.las");
Options opts;
opts.add("filename", Support::datapath("las/autzen_trim.las"));
opts.add("count", 35U);
r->setOptions(opts);

StreamCallbackFilter streamFilter;

int cnt = 0;
auto cb = [&cnt](PointRef&)
{
cnt++;
return true;
};
streamFilter.setCallback(cb);
streamFilter.setInput(*r);

// Use a table size smaller than count.
FixedPointTable t(20);
streamFilter.prepare(t);
streamFilter.execute(t);
EXPECT_EQ(cnt, 35);

cnt = 0;
// Use a table size larger than count.
FixedPointTable t2(100);
streamFilter.prepare(t2);
streamFilter.execute(t2);
EXPECT_EQ(cnt, 35);
}

0 comments on commit 7390b02

Please sign in to comment.