Skip to content

Commit

Permalink
Some performance optimizations for naive readers.
Browse files Browse the repository at this point in the history
  • Loading branch information
connormanning committed Feb 7, 2015
1 parent fc7850d commit c702878
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
10 changes: 9 additions & 1 deletion include/pdal/PointBuffer.hpp
Expand Up @@ -107,6 +107,12 @@ class PDAL_DLL PointBuffer
m_size += buf.size();
clearTemps();
}
point_count_t append()
{
const PointId rawId(m_context.rawPtBuf()->addPoint());
m_index.push_back(rawId);
return m_size++;
}

/// Return a new point buffer with the same point context as this
/// point buffer.
Expand Down Expand Up @@ -205,6 +211,8 @@ class PDAL_DLL PointBuffer
{ return m_context.dimSize(id); }
DimTypeList dimTypes() const
{ return m_context.dimTypes(); }
PointContextRef context() const
{ return m_context; }


/// Fill a buffer with point data specified by the dimension list.
Expand Down Expand Up @@ -488,7 +496,7 @@ bool PointBuffer::convertAndSet(Dimension::Id::Enum dim, PointId idx, T_IN in)
// block seemed somewhat expensive.
// 2) Round to nearest instead of truncation without rounding before
// invoking the converter.
//
//
using namespace boost;
static bool ok;

Expand Down
17 changes: 10 additions & 7 deletions include/pdal/PointContext.hpp
Expand Up @@ -76,10 +76,15 @@ class PointContext
RawPtBufPtr m_ptBuf;
// Metadata storage;
MetadataPtr m_metadata;
// Combined size of all registered dimensions (in bytes).
std::size_t m_pointSize;

public:
PointContext() : m_dims(new DimInfo()), m_ptBuf(new RawPtBuf()),
m_metadata(new Metadata)
PointContext()
: m_dims(new DimInfo())
, m_ptBuf(new RawPtBuf())
, m_metadata(new Metadata)
, m_pointSize(0)
{}

RawPtBuf *rawPtBuf() const
Expand Down Expand Up @@ -216,10 +221,7 @@ class PointContext

size_t pointSize() const
{
size_t size(0);
for (const auto& d : m_dims->m_detail)
size += d.size();
return size;
return m_pointSize;
}

private:
Expand Down Expand Up @@ -248,7 +250,8 @@ class PointContext
m_dims->m_detail[*ui].m_offset = offset;
offset += (int)m_dims->m_detail[*ui].size();
}
m_ptBuf->setPointSize((size_t)offset);
m_pointSize = static_cast<std::size_t>(offset);
m_ptBuf->setPointSize(m_pointSize);
}

Dimension::Type::Enum resolveType(Dimension::Type::Enum t1,
Expand Down
16 changes: 15 additions & 1 deletion include/pdal/RawPtBuf.hpp
Expand Up @@ -79,6 +79,20 @@ class RawPtBuf
memcpy(value, buf + offset, d->size());
}

void setPoint(PointId idx, const void *value)
{
char *buf = m_blocks[idx / m_blockPtCnt];
std::size_t offset = pointsToBytes(idx % m_blockPtCnt);
memcpy(buf + offset, value, m_pointSize);
}

void getPoint(PointId idx, void* value)
{
char *buf = m_blocks[idx / m_blockPtCnt];
std::size_t offset = pointsToBytes(idx % m_blockPtCnt);
memcpy(value, buf + offset, m_pointSize);
}

void setPointSize(size_t size)
{
if (m_numPts != 0)
Expand All @@ -98,7 +112,7 @@ class RawPtBuf

// 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

0 comments on commit c702878

Please sign in to comment.