diff --git a/include/pdal/PointBuffer.hpp b/include/pdal/PointBuffer.hpp index a12fbe2be9..4beda80410 100644 --- a/include/pdal/PointBuffer.hpp +++ b/include/pdal/PointBuffer.hpp @@ -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. @@ -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. @@ -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; diff --git a/include/pdal/PointContext.hpp b/include/pdal/PointContext.hpp index 548dd99e05..99b43af92b 100644 --- a/include/pdal/PointContext.hpp +++ b/include/pdal/PointContext.hpp @@ -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 @@ -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: @@ -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(offset); + m_ptBuf->setPointSize(m_pointSize); } Dimension::Type::Enum resolveType(Dimension::Type::Enum t1, diff --git a/include/pdal/RawPtBuf.hpp b/include/pdal/RawPtBuf.hpp index fc32b18da7..f9b3ed5268 100644 --- a/include/pdal/RawPtBuf.hpp +++ b/include/pdal/RawPtBuf.hpp @@ -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) @@ -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; } };