Skip to content

Commit

Permalink
Streamable skips. (#2224)
Browse files Browse the repository at this point in the history
  • Loading branch information
connormanning authored and abellgithub committed Oct 12, 2018
1 parent 28899ea commit 57706e8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
57 changes: 41 additions & 16 deletions pdal/PointTable.hpp
Expand Up @@ -196,58 +196,83 @@ class PDAL_DLL ContiguousPointTable : public SimplePointTable
class PDAL_DLL StreamPointTable : public SimplePointTable
{
protected:
StreamPointTable(PointLayout& layout) : SimplePointTable(layout)
StreamPointTable(PointLayout& layout, point_count_t capacity)
: SimplePointTable(layout)
, m_capacity(capacity)
, m_skips(m_capacity, false)
{}

public:
/// Called when a new point should be added. Probably a no-op for
/// streaming.
virtual PointId addPoint()
{ return 0; }
{ return 0; }

/// Called when execute() is started. Typically used to set buffer size
/// when all dimensions are known.
virtual void finalize()
{}
/// Called before the StreamPointTable is reset indicating the number of
/// points that were populated, which must be less than or equal to its
/// capacity.
virtual void setNumPoints(PointId n)
{}
{}

void clear(point_count_t count)
{
m_numPoints = count;
reset();
std::fill(m_skips.begin(), m_skips.end(), false);
}

/// Returns true if a point in the table was filtered out and should be
/// considered omitted.
bool skip(PointId n) const
{ return m_skips[n]; }
void setSkip(PointId n)
{ m_skips[n] = true; }

point_count_t capacity() const
{ return m_capacity; }

/// During a given call to reset(), this indicates the number of points
/// populated in the table. This value will always be less then or equal
/// to capacity(), and also includes skipped points.
point_count_t numPoints() const
{ return m_numPoints; }

protected:
/// Called when the contents of StreamPointTable have been consumed and
/// the point data will be potentially overwritten.
virtual void reset()
{}
virtual point_count_t capacity() const = 0;

private:
point_count_t m_capacity;
point_count_t m_numPoints;
std::vector<bool> m_skips;
};

class PDAL_DLL FixedPointTable : public StreamPointTable
{
public:
FixedPointTable(point_count_t capacity) : StreamPointTable(m_layout),
m_capacity(capacity)
FixedPointTable(point_count_t capacity)
: StreamPointTable(m_layout, capacity)
{}

virtual void finalize()
{
if (!m_layout.finalized())
{
BasePointTable::finalize();
m_buf.resize(pointsToBytes(m_capacity + 1));
m_buf.resize(pointsToBytes(capacity() + 1));
}
}

protected:
virtual void reset()
{ std::fill(m_buf.begin(), m_buf.end(), 0); }

point_count_t capacity() const
{ return m_capacity; }
protected:
virtual char *getPoint(PointId idx)
{ return m_buf.data() + pointsToBytes(idx); }

private:
std::vector<char> m_buf;
point_count_t m_capacity;
PointLayout m_layout;
};

Expand Down
11 changes: 3 additions & 8 deletions pdal/Streamable.cpp
Expand Up @@ -178,7 +178,6 @@ void Streamable::execute(StreamPointTable& table)
void Streamable::execute(StreamPointTable& table,
std::list<Streamable *>& stages, SrsMap& srsMap)
{
std::vector<bool> skips(table.capacity());
std::list<Streamable *> filters;
SpatialReference srs;

Expand Down Expand Up @@ -243,11 +242,11 @@ void Streamable::execute(StreamPointTable& table,
s->startLogging();
for (PointId idx = 0; idx < pointLimit; idx++)
{
if (skips[idx])
if (table.skip(idx))
continue;
point.setPointId(idx);
if (!s->processOne(point))
skips[idx] = true;
table.setSkip(idx);
}
const SpatialReference& tempSrs = s->getSpatialReference();
if (!tempSrs.empty())
Expand All @@ -258,11 +257,7 @@ void Streamable::execute(StreamPointTable& table,
s->stopLogging();
}

// Yes, vector<bool> is terrible. Can do something better later.
for (size_t i = 0; i < skips.size(); ++i)
skips[i] = false;
table.setNumPoints(pointLimit);
table.reset();
table.clear(pointLimit);
}
}

Expand Down

0 comments on commit 57706e8

Please sign in to comment.