virtual Cell::PooledStack read( const arbiter::Endpoint& endpoint, PointPool& pool, const Id& id) const override { auto data(io::ensureGet(endpoint, m_metadata.basename(id))); const Tail tail(*data, m_tailFields); const char* pos(data->data()); const Schema& schema(pool.schema()); const std::size_t pointSize(schema.pointSize()); const std::size_t numPoints(data->size() / pointSize); const std::size_t numBytes(data->size() + tail.size()); BinaryPointTable table(schema); pdal::PointRef pointRef(table, 0); if (pointSize * numPoints != data->size()) { throw std::runtime_error("Invalid binary chunk size"); } if (tail.numPoints() && tail.numPoints() != numPoints) { throw std::runtime_error("Invalid binary chunk numPoints"); } if (tail.numBytes() && tail.numBytes() != numBytes) { throw std::runtime_error("Invalid binary chunk numBytes"); } Data::PooledStack dataStack(pool.dataPool().acquire(numPoints)); Cell::PooledStack cellStack(pool.cellPool().acquire(numPoints)); for (Cell& cell : cellStack) { table.setPoint(pos); Data::PooledNode dataNode(dataStack.popOne()); std::copy(pos, pos + pointSize, *dataNode); cell.set(pointRef, std::move(dataNode)); pos += pointSize; } assert(dataStack.empty()); return cellStack; }
Cell::PooledStack LazPerfStorage::read( const arbiter::Endpoint& endpoint, PointPool& pool, const Id& id) const { auto compressed(io::ensureGet(endpoint, m_metadata.basename(id))); const Tail tail(*compressed, m_tailFields); const Schema& schema(pool.schema()); const std::size_t pointSize(schema.pointSize()); const std::size_t numPoints(tail.numPoints()); const std::size_t numBytes(compressed->size() + tail.size()); BinaryPointTable table(schema); pdal::PointRef pointRef(table, 0); if (id >= m_metadata.structure().coldIndexBegin() && !numPoints) { throw std::runtime_error("Invalid lazperf chunk - no numPoints"); } if (tail.numBytes() && tail.numBytes() != numBytes) { std::cout << tail.numBytes() << " != " << numBytes << std::endl; throw std::runtime_error("Invalid lazperf chunk numBytes"); } Data::PooledStack dataStack(pool.dataPool().acquire(numPoints)); Cell::PooledStack cellStack(pool.cellPool().acquire(numPoints)); DecompressionStream stream(*compressed); pdal::LazPerfDecompressor<DecompressionStream> decompressor( stream, schema.pdalLayout().dimTypes()); for (Cell& cell : cellStack) { Data::PooledNode dataNode(dataStack.popOne()); table.setPoint(*dataNode); decompressor.decompress(*dataNode, pointSize); cell.set(pointRef, std::move(dataNode)); } assert(dataStack.empty()); return cellStack; }
std::vector<char> buildData(Chunk& chunk) const { Cell::PooledStack cellStack(chunk.acquire()); Data::PooledStack dataStack(chunk.pool().dataPool()); for (Cell& cell : cellStack) dataStack.push(cell.acquire()); cellStack.release(); const std::size_t pointSize(chunk.schema().pointSize()); std::vector<char> data; data.reserve( dataStack.size() * pointSize + buildTail(chunk, dataStack.size()).size()); for (const char* d : dataStack) { data.insert(data.end(), d, d + pointSize); } return data; }
PooledInfoStack Compression::decompress( const std::vector<char>& data, const std::size_t numPoints, PointPool& pointPool) { PooledDataStack dataStack(pointPool.dataPool().acquire(numPoints)); PooledInfoStack infoStack(pointPool.infoPool().acquire(numPoints)); BinaryPointTable table(pointPool.schema()); pdal::PointRef pointRef(table, 0); const std::size_t pointSize(pointPool.schema().pointSize()); DecompressionStream decompressionStream(data); pdal::LazPerfDecompressor<DecompressionStream> decompressor( decompressionStream, pointPool.schema().pdalLayout().dimTypes()); RawInfoNode* info(infoStack.head()); char* pos(nullptr); while (info) { info->construct(dataStack.popOne()); pos = info->val().data(); decompressor.decompress(pos, pointSize); table.setPoint(pos); info->val().point(pointRef); info = info->next(); } return infoStack; }