Skip to content

Commit

Permalink
Test to exercise large point buffers.
Browse files Browse the repository at this point in the history
Test random access to filled point buffer.
  • Loading branch information
abellgithub committed Sep 15, 2014
1 parent d86004d commit 936ef4c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 11 deletions.
30 changes: 19 additions & 11 deletions include/pdal/RawPtBuf.hpp
Expand Up @@ -46,29 +46,37 @@ namespace pdal
class RawPtBuf
{
public:
RawPtBuf() : m_numPts(0), m_allocPts(0)
RawPtBuf() : m_numPts(0)
{}

~RawPtBuf()
{
for (auto vi = m_blocks.begin(); vi != m_blocks.end(); ++vi)
delete [] *vi;
}

PointId addPoint()
{
if (m_numPts >= m_allocPts)
if (m_numPts % m_blockPtCnt == 0)
{
m_allocPts += m_blockSize;
m_buf.resize(pointsToBytes(m_allocPts));
char *buf = new char[pointsToBytes(m_blockPtCnt)];
m_blocks.push_back(buf);
}
return m_numPts++;
}

void setField(Dimension::Detail *d, PointId idx, const void *value)
{
std::size_t offset = pointsToBytes(idx) + d->offset();
memcpy(m_buf.data() + offset, value, d->size());
char *buf = m_blocks[idx / m_blockPtCnt];
std::size_t offset = pointsToBytes(idx % m_blockPtCnt) + d->offset();
memcpy(buf + offset, value, d->size());
}

void getField(Dimension::Detail *d, PointId idx, void *value)
{
std::size_t offset = pointsToBytes(idx) + d->offset();
memcpy(value, m_buf.data() + offset, d->size());
char *buf = m_blocks[idx / m_blockPtCnt];
std::size_t offset = pointsToBytes(idx % m_blockPtCnt) + d->offset();
memcpy(value, buf + offset, d->size());
}

void setPointSize(size_t size)
Expand All @@ -80,12 +88,12 @@ class RawPtBuf
}

private:
std::vector<char> m_buf;
std::vector<char *> m_blocks;
point_count_t m_numPts;
point_count_t m_allocPts;
size_t m_pointSize;

static const point_count_t m_blockSize = 100000;
// The number of points in each memory block.
static const point_count_t m_blockPtCnt = 65536;

std::size_t pointsToBytes(point_count_t numPts)
{ return m_pointSize * numPts; }
Expand Down
58 changes: 58 additions & 0 deletions test/unit/PointBufferTest.cpp
Expand Up @@ -237,6 +237,64 @@ BOOST_AUTO_TEST_CASE(PointBufferTest_ptree)
}


BOOST_AUTO_TEST_CASE(bigfile)
{
PointContext ctx;

point_count_t NUM_PTS = 1000000;
// point_count_t NUM_PTS = 10;

ctx.registerDim(Dimension::Id::X);
ctx.registerDim(Dimension::Id::Y);
ctx.registerDim(Dimension::Id::Z);
PointBuffer buf(ctx);

for (PointId id = 0; id < NUM_PTS; ++id)
{
buf.setField(Dimension::Id::X, id, id);
buf.setField(Dimension::Id::Y, id, 2 * id);
buf.setField(Dimension::Id::Z, id, -(int)id);
}

for (PointId id = 0; id < NUM_PTS; ++id)
{
BOOST_CHECK_EQUAL(
buf.getFieldAs<PointId>(Dimension::Id::X, id), id);
BOOST_CHECK_EQUAL(
buf.getFieldAs<PointId>(Dimension::Id::Y, id), id * 2);
BOOST_CHECK_EQUAL(
buf.getFieldAs<int>(Dimension::Id::Z, id), -(int)id);
}

// Test some random access.
PointId ids[NUM_PTS];
for (PointId idx = 0; idx < NUM_PTS; ++idx)
ids[idx] = idx;
// Do a bunch of swaps.
for (PointId idx = 0; idx < NUM_PTS; ++idx)
std::swap(ids[idx], ids[random() % NUM_PTS]);

for (PointId idx = 0; idx < NUM_PTS; ++idx)
{
PointId id = ids[idx];
buf.setField(Dimension::Id::X, id, idx);
buf.setField(Dimension::Id::Y, id, 2 * idx);
buf.setField(Dimension::Id::Z, id, -(int)idx);
}

for (PointId idx = 0; idx < NUM_PTS; ++idx)
{
PointId id = ids[idx];
BOOST_CHECK_EQUAL(
buf.getFieldAs<PointId>(Dimension::Id::X, id), idx);
BOOST_CHECK_EQUAL(
buf.getFieldAs<PointId>(Dimension::Id::Y, id), idx * 2);
BOOST_CHECK_EQUAL(
buf.getFieldAs<int>(Dimension::Id::Z, id), -(int)idx);
}
}


//ABELL - Move to KdIndex
/**
BOOST_AUTO_TEST_CASE(test_indexed)
Expand Down

0 comments on commit 936ef4c

Please sign in to comment.