Skip to content

Commit

Permalink
Add ContiguousPointTable.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Aug 9, 2018
1 parent 37646d1 commit 868a714
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pdal/PointTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ char *PointTable::getPoint(PointId idx)
}


ContiguousPointTable::~ContiguousPointTable()
{}


PointId ContiguousPointTable::addPoint()
{
m_buf.resize(pointsToBytes(m_numPts + 1));
return m_numPts++;
}


char *ContiguousPointTable::getPoint(PointId idx)
{
return m_buf.data() + pointsToBytes(idx);
}


MetadataNode BasePointTable::toMetadata() const
{
return layout()->toMetadata();
Expand Down
22 changes: 22 additions & 0 deletions pdal/PointTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,28 @@ class PDAL_DLL PointTable : public SimplePointTable
PointLayout m_layout;
};

class PDAL_DLL ContiguousPointTable : public SimplePointTable
{
private:
std::vector<char> m_buf;
point_count_t m_numPts;

public:
ContiguousPointTable() : SimplePointTable(m_layout), m_numPts(0)
{}
virtual ~ContiguousPointTable();
virtual bool supportsView() const
{ return true; }

protected:
virtual char *getPoint(PointId idx);

private:
virtual PointId addPoint();

PointLayout m_layout;
};

/// A StreamPointTable must provide storage for point data up to its capacity.
/// It must implement getPoint() which returns a pointer to a buffer of
/// sufficient size to contain a point's data. The minimum size required
Expand Down
54 changes: 54 additions & 0 deletions test/unit/PointTableTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,58 @@ TEST(PointTable, srs)
EXPECT_EQ(table.m_spatialRefs.size(), 2u);
}

void simpleTest(PointTableRef table)
{
PointLayoutPtr layout = table.layout();

layout->registerDim(Dimension::Id::X);
layout->registerDim(Dimension::Id::Y);
layout->registerDim(Dimension::Id::Z);
layout->registerDim(Dimension::Id::Intensity);
layout->registerDim(Dimension::Id::Blue);

PointView v(table);
for (PointId id = 0; id < 10000; id++)
{
if (id % 200 < 100)
{
v.setField(Dimension::Id::X, id, id);
v.setField(Dimension::Id::Y, id, id + 1);
v.setField(Dimension::Id::Z, id, id + 2);
v.setField(Dimension::Id::Intensity, id, (id * 100) % 6523);
}
else
v.setField(Dimension::Id::Blue, id, 0);
}

for (PointId id = 0; id < 10000; id++)
{
if (id % 200 < 100)
{
EXPECT_EQ(id, v.getFieldAs<PointId>(Dimension::Id::X, id));
EXPECT_EQ(id + 1, v.getFieldAs<PointId>(Dimension::Id::Y, id));
EXPECT_EQ(id + 2, v.getFieldAs<PointId>(Dimension::Id::Z, id));
EXPECT_EQ((id * 100) % 6523,
v.getFieldAs<PointId>(Dimension::Id::Intensity, id));
}
else
{
EXPECT_EQ(0U, v.getFieldAs<PointId>(Dimension::Id::X, id));
EXPECT_EQ(0U, v.getFieldAs<PointId>(Dimension::Id::Y, id));
EXPECT_EQ(0U, v.getFieldAs<PointId>(Dimension::Id::Z, id));
EXPECT_EQ(0U, v.getFieldAs<PointId>(Dimension::Id::Intensity, id));
}
}
}


TEST(PointTable, simple)
{
PointTable t;
simpleTest(t);

ContiguousPointTable t2;
simpleTest(t2);
}

} // namespace

0 comments on commit 868a714

Please sign in to comment.