From 9c4013a3f522fa059ead4bf667444131d39bd403 Mon Sep 17 00:00:00 2001 From: Andrew Bell Date: Thu, 30 Sep 2021 10:20:03 -0400 Subject: [PATCH] Don't write chunks when there are no points. Close #80 --- bu/CopcSupport.cpp | 7 +++++++ bu/Processor.cpp | 12 +++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bu/CopcSupport.cpp b/bu/CopcSupport.cpp index e166728..f3093c2 100644 --- a/bu/CopcSupport.cpp +++ b/bu/CopcSupport.cpp @@ -98,6 +98,13 @@ int CopcSupport::extraByteSize(const DimInfoList& dims) const /// \return The offset of the chunk in the file. uint64_t CopcSupport::newChunk(const VoxelKey& key, int32_t size, int32_t count) { + // Chunks of size zero are a special case. + if (count == 0) + { + m_hierarchy[key] = { 0, 0, 0 }; + return 0; + } + uint64_t chunkStart = m_pointPos; m_pointPos += size; assert(count <= (std::numeric_limits::max)() && count >= 0); diff --git a/bu/Processor.cpp b/bu/Processor.cpp index ec6589f..89dd8d5 100644 --- a/bu/Processor.cpp +++ b/bu/Processor.cpp @@ -22,6 +22,7 @@ #include #include +#include #include "Processor.hpp" #include "PyramidManager.hpp" @@ -127,11 +128,6 @@ void Processor::sample(Index& accepted, Index& rejected) void Processor::write(Index& accepted, Index& rejected) { -/** -std::cerr << m_vi.key() << " Accepted/Rejected/num points = " << - accepted.size() << "/" << rejected.size() << "/" << m_vi.numPoints() << "!\n"; -**/ - // If this is the final key, append any remaining file infos as accepted points and // write the accepted points as compressed. if (m_vi.key() == VoxelKey(0, 0, 0, 0)) @@ -469,6 +465,12 @@ void Processor::createChunk(const VoxelKey& key, pdal::PointViewPtr view) { using namespace pdal; + if (view->size() == 0) + { + m_manager.newChunk(key, 0, 0); + return; + } + PointLayoutPtr layout = view->layout(); int ebCount {0}; for (DimType dim : m_extraDims)