From 8e5b036fec982e4b001f8df3449a44295ff7a567 Mon Sep 17 00:00:00 2001 From: Martin Dobias Date: Wed, 6 Jan 2021 16:42:33 +0100 Subject: [PATCH] Untwine update: fixed warnings and 32-bit build --- external/untwine/bu/Processor.cpp | 3 ++ external/untwine/epf/Epf.cpp | 1 - external/untwine/epf/Grid.cpp | 1 - external/untwine/epf/Reprocessor.cpp | 3 ++ external/untwine/untwine/FileDimInfo.hpp | 4 ++- external/untwine/untwine/ProgressWriter.cpp | 20 ++++++++----- external/untwine/untwine/VoxelKey.hpp | 31 +++++++++++++++------ 7 files changed, 45 insertions(+), 18 deletions(-) diff --git a/external/untwine/bu/Processor.cpp b/external/untwine/bu/Processor.cpp index d2fd190c4d58..ee16394b9ef5 100644 --- a/external/untwine/bu/Processor.cpp +++ b/external/untwine/bu/Processor.cpp @@ -138,6 +138,9 @@ std::cerr << m_vi.key() << " Accepted/Rejected/num points = " << bool Processor::acceptable(int pointId, GridKey key) { + //ABELL - Currently unused - see commented-out code. + (void)pointId; + VoxelInfo::Grid& grid = m_vi.grid(); auto it = grid.find(key); diff --git a/external/untwine/epf/Epf.cpp b/external/untwine/epf/Epf.cpp index d54ecfd57435..36b2237d23cb 100644 --- a/external/untwine/epf/Epf.cpp +++ b/external/untwine/epf/Epf.cpp @@ -73,7 +73,6 @@ void Epf::run(const Options& options, ProgressWriter& progress) { using namespace pdal; - double millionPoints = 0; BOX3D totalBounds; if (pdal::FileUtils::fileExists(options.tempDir + "/" + MetadataFilename)) diff --git a/external/untwine/epf/Grid.cpp b/external/untwine/epf/Grid.cpp index 387ba5fc1784..8109354642e0 100644 --- a/external/untwine/epf/Grid.cpp +++ b/external/untwine/epf/Grid.cpp @@ -42,7 +42,6 @@ int Grid::calcLevel() { int level = 0; double mp = (double)m_millionPoints; - double limit = (MaxPointsPerNode / 1000000.0); double xside = m_bounds.maxx - m_bounds.minx; double yside = m_bounds.maxy - m_bounds.miny; diff --git a/external/untwine/epf/Reprocessor.cpp b/external/untwine/epf/Reprocessor.cpp index fdbc8bb4804e..99c679876320 100644 --- a/external/untwine/epf/Reprocessor.cpp +++ b/external/untwine/epf/Reprocessor.cpp @@ -10,6 +10,9 @@ * * ****************************************************************************/ + +// This include is necessary for released PDAL 2.0 and earlier, as it wasn't included in +// FileUtils.hpp. #include #include diff --git a/external/untwine/untwine/FileDimInfo.hpp b/external/untwine/untwine/FileDimInfo.hpp index 4cdbb26083da..600ffc1637ac 100644 --- a/external/untwine/untwine/FileDimInfo.hpp +++ b/external/untwine/untwine/FileDimInfo.hpp @@ -40,7 +40,9 @@ inline std::ostream& operator<<(std::ostream& out, const FileDimInfo& fdi) inline std::istream& operator>>(std::istream& in, FileDimInfo& fdi) { - in >> fdi.name >> (int&)fdi.type >> fdi.offset; + int type; + in >> fdi.name >> type >> fdi.offset; + fdi.type = (pdal::Dimension::Type)type; return in; } diff --git a/external/untwine/untwine/ProgressWriter.cpp b/external/untwine/untwine/ProgressWriter.cpp index 7130e3c99cc5..4bd053a4dd18 100644 --- a/external/untwine/untwine/ProgressWriter.cpp +++ b/external/untwine/untwine/ProgressWriter.cpp @@ -18,7 +18,7 @@ ProgressWriter::ProgressWriter(int fd) : m_progressFd(fd), m_percent(0.0), m_inc void ProgressWriter::setIncrement(double increment) { - if (!m_progressFd) + if (m_progressFd < 0) return; std::unique_lock lock(m_mutex); @@ -27,7 +27,7 @@ void ProgressWriter::setIncrement(double increment) void ProgressWriter::setPercent(double percent) { - if (!m_progressFd) + if (m_progressFd < 0) return; std::unique_lock lock(m_mutex); @@ -36,7 +36,7 @@ void ProgressWriter::setPercent(double percent) void ProgressWriter::writeIncrement(const std::string& message) { - if (!m_progressFd) + if (m_progressFd < 0) return; std::unique_lock lock(m_mutex); @@ -49,7 +49,7 @@ void ProgressWriter::writeIncrement(const std::string& message) void ProgressWriter::write(double percent, const std::string& message) { - if (!m_progressFd) + if (m_progressFd < 0) return; std::unique_lock lock(m_mutex); @@ -62,10 +62,16 @@ void ProgressWriter::write(double percent, const std::string& message) void ProgressWriter::writeMessage(uint32_t percent, const std::string& message) { #ifndef _WIN32 - ::write(m_progressFd, &percent, sizeof(percent)); + bool err = false; + err = (::write(m_progressFd, &percent, sizeof(percent)) == -1); uint32_t ssize = (uint32_t)message.size(); - ::write(m_progressFd, &ssize, sizeof(ssize)); - ::write(m_progressFd, message.data(), ssize); + err |= (::write(m_progressFd, &ssize, sizeof(ssize)) == -1); + err |= (::write(m_progressFd, message.data(), ssize) == -1); + if (err) + { + ::close(m_progressFd); + m_progressFd = -1; + } #else DWORD numWritten; HANDLE h = reinterpret_cast((intptr_t)m_progressFd); diff --git a/external/untwine/untwine/VoxelKey.hpp b/external/untwine/untwine/VoxelKey.hpp index 493083756591..bd66752ae6ae 100644 --- a/external/untwine/untwine/VoxelKey.hpp +++ b/external/untwine/untwine/VoxelKey.hpp @@ -102,15 +102,30 @@ namespace std { template<> struct hash { - long long operator()(const untwine::VoxelKey& k) const noexcept + size_t operator()(const untwine::VoxelKey& k) const noexcept { - static_assert(sizeof(long long) >= 8, "wrong assumption that long long is 64 bits"); - - // For this to work well we just assume that the values are no more than than 16 bits. - long long t = static_cast(k.x()) << 48; - t |= static_cast(k.y()) << 32; - t |= static_cast(k.z()) << 16; - t |= static_cast(k.level()); + size_t t; + + static_assert(sizeof(size_t) == sizeof(uint64_t) || + sizeof(size_t) == sizeof(uint32_t), + "Only systems with 32 and 64 bit size_t are currently supported."); + + // Counting on the compiler to optimize away the wrong branch. + if (sizeof(size_t) == sizeof(uint64_t)) + { + // For this to work well we just assume that the values are no more than 16 bits. + t = size_t(k.x()) << 48; + t |= size_t(k.y()) << 32; + t |= size_t(k.z()) << 16; + t |= size_t(k.level()); + } + else if (sizeof(size_t) == sizeof(uint32_t)) + { + t = size_t((k.x() << 24) | 0xFF000000); + t |= size_t((k.y() << 16) | 0xFF0000); + t |= size_t((k.z() << 8) | 0xFF00); + t |= size_t(k.level() | 0xFF); + } return t; } };