Skip to content

Commit

Permalink
Allow raw point access.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Feb 18, 2015
1 parent f52b08b commit fa0f827
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 42 deletions.
39 changes: 5 additions & 34 deletions include/pdal/PointBuffer.hpp
Expand Up @@ -65,27 +65,6 @@ class PDAL_DLL PointBuffer
public:
PointBuffer(PointContextRef context) : m_context(context), m_size(0)
{}
PointBuffer(std::istream& strm, PointContextRef ctx, PointId start,
PointId end) : m_context(ctx), m_size(0)
{
size_t pointSize = ctx.pointSize();

std::vector<char> bytes;
bytes.resize(pointSize);
char* start_pos = bytes.data();
for (PointId i = start; i < end; ++i)
{
char* pos = start_pos;
strm.read(pos, pointSize);
if (strm.eof() )
break; // done
for (const auto& dim : ctx.m_dims->m_used)
{
setFieldInternal(dim, i, pos);
pos += m_context.dimSize(dim);
}
}
}

PointBufferIter begin();
PointBufferIter end();
Expand Down Expand Up @@ -234,19 +213,11 @@ class PDAL_DLL PointBuffer
}
}

std::ostream& getBytes(std::ostream& strm, PointId start, PointId end) const
{
char buf[sizeof(double)];
for (PointId i = start; i < end; ++i)
{
for (const auto& dim : m_context.m_dims->m_used)
{
getFieldInternal(dim, i, buf);
strm.write(buf, m_context.dimSize(dim));
}
}
return strm;
}

/// Provides access to the memory storing the point data. Though this
/// function is public, other access methods are safer and preferred.
char *getPoint(PointId id)
{ return m_context.rawPtBuf()->getPoint(m_index[id]); }

// The standard idiom is swapping with a stack-created empty queue, but
// that invokes the ctor and probably allocates. We've probably only got
Expand Down
17 changes: 9 additions & 8 deletions include/pdal/RawPtBuf.hpp
Expand Up @@ -65,19 +65,20 @@ class RawPtBuf
return m_numPts++;
}

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

char *getDimension(Dimension::Detail *d, PointId idx)
{ return getPoint(idx) + d->offset(); }

void setField(Dimension::Detail *d, PointId idx, const void *value)
{ memcpy(getDimension(d, idx), value, d->size()); }

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

void setPointSize(size_t size)
{
Expand Down

0 comments on commit fa0f827

Please sign in to comment.