From 04be6dc4bbb8c6401aff644cb9f8b1ee2d61cadc Mon Sep 17 00:00:00 2001 From: Andrew Bell Date: Fri, 19 Oct 2018 14:01:48 -0400 Subject: [PATCH] More fix. --- filters/SMRFilter.cpp | 2 +- io/FauxReader.cpp | 12 +++++++----- io/GDALWriter.cpp | 19 +++++++++++++------ io/LasHeader.cpp | 7 +++++-- io/LasReader.cpp | 2 +- io/LasWriter.cpp | 14 ++++++++------ io/OptechReader.hpp | 3 ++- pdal/EigenUtils.cpp | 12 +++++++++--- 8 files changed, 46 insertions(+), 25 deletions(-) diff --git a/filters/SMRFilter.cpp b/filters/SMRFilter.cpp index eb146c1471..83c0d6428d 100644 --- a/filters/SMRFilter.cpp +++ b/filters/SMRFilter.cpp @@ -613,7 +613,7 @@ std::vector SMRFilter::progressiveFilter(std::vector const& ZImin, // but is internally converted to a pixel equivalent by dividing it by the // cell size and rounding the result toward positive infinity (i.e., taking // the ceiling value)." - int max_radius = std::ceil(max_window / m_args->m_cell); + int max_radius = static_cast(std::ceil(max_window / m_args->m_cell)); std::vector prevSurface = ZImin; std::vector prevErosion = ZImin; diff --git a/io/FauxReader.cpp b/io/FauxReader.cpp index 993cf05987..bcb0695210 100644 --- a/io/FauxReader.cpp +++ b/io/FauxReader.cpp @@ -83,30 +83,32 @@ void FauxReader::initialize() m_bounds.minz = ceil(m_bounds.minz); m_bounds.maxz = ceil(m_bounds.maxz); // Here delX/Y/Z represent the number of points in each direction. - m_count = 1; + double count = 1.0; if (m_bounds.maxx <= m_bounds.minx) m_delX = 0; else { m_delX = m_bounds.maxx - m_bounds.minx; - m_count *= m_delX; + count *= m_delX; } if (m_bounds.maxy <= m_bounds.miny) m_delY = 0; else { m_delY = m_bounds.maxy - m_bounds.miny; - m_count *= m_delY; + count *= m_delY; } if (m_bounds.maxz <= m_bounds.minz) m_delZ = 0; else { m_delZ = m_bounds.maxz - m_bounds.minz; - m_count *= m_delZ; + count *= m_delZ; } if (!m_delX && !m_delY && !m_delZ) - m_count = 0; + count = 0; + if (!Utils::numericCast(count, m_count)) + throwError("Requested range generates more points than supported."); } else { diff --git a/io/GDALWriter.cpp b/io/GDALWriter.cpp index 8536c375b5..ffeee3e005 100644 --- a/io/GDALWriter.cpp +++ b/io/GDALWriter.cpp @@ -142,8 +142,9 @@ void GDALWriter::readyFile(const std::string& filename, void GDALWriter::createGrid(BOX2D bounds) { m_curBounds = bounds; - size_t width = ((m_curBounds.maxx - m_curBounds.minx) / m_edgeLength) + 1; - size_t height = ((m_curBounds.maxy - m_curBounds.miny) / m_edgeLength) + 1; + size_t width = static_cast(((m_curBounds.maxx - m_curBounds.minx) / + m_edgeLength) + 1); + size_t height = static_cast(((m_curBounds.maxy - m_curBounds.miny) / m_edgeLength) + 1); try { m_grid.reset(new GDALGrid(width, height, m_edgeLength, m_radius, @@ -162,13 +163,19 @@ void GDALWriter::expandGrid(BOX2D bounds) return; bounds.grow(m_curBounds); - size_t xshift = ceil((m_curBounds.minx - bounds.minx) / m_edgeLength); + size_t xshift = + static_cast(std::ceil((m_curBounds.minx - bounds.minx) / + m_edgeLength)); bounds.minx = m_curBounds.minx - (xshift * m_edgeLength); - size_t yshift = ceil((m_curBounds.miny - bounds.miny) / m_edgeLength); + size_t yshift = + static_cast(std::ceil((m_curBounds.miny - bounds.miny) / + m_edgeLength)); bounds.miny = m_curBounds.miny - (yshift * m_edgeLength); - size_t width = ((bounds.maxx - bounds.minx) / m_edgeLength) + 1; - size_t height = ((bounds.maxy - bounds.miny) / m_edgeLength) + 1; + size_t width = + static_cast(((bounds.maxx - bounds.minx) / m_edgeLength) + 1); + size_t height = + static_cast(((bounds.maxy - bounds.miny) / m_edgeLength) + 1); try { m_grid->expand(width, height, xshift, yshift); diff --git a/io/LasHeader.cpp b/io/LasHeader.cpp index ec615c4a82..1c6a8d5943 100644 --- a/io/LasHeader.cpp +++ b/io/LasHeader.cpp @@ -435,8 +435,11 @@ OLeStream& operator<<(OLeStream& out, const LasHeader& h) for (size_t i = 0; i < LasHeader::LEGACY_RETURN_COUNT; ++i) { - uint32_t legacyReturnCount = (std::min)(h.m_pointCountByReturn[i], - (uint64_t)(std::numeric_limits::max)()); + //ABELL - This needs fixing. Should set to 0 when we exceed + // std::numeric_limits::max(). + uint32_t legacyReturnCount = + static_cast((std::min)(h.m_pointCountByReturn[i], + (uint64_t)(std::numeric_limits::max)())); out << legacyReturnCount; } diff --git a/io/LasReader.cpp b/io/LasReader.cpp index fb97d30091..aa96f012a2 100644 --- a/io/LasReader.cpp +++ b/io/LasReader.cpp @@ -416,7 +416,7 @@ void LasReader::extractHeaderMetadata(MetadataNode& forward, MetadataNode& m) "The max and min data fields are the actual unscaled extents of the " "LAS point file data, specified in the coordinate system of the LAS " "data."); - m.add("count", + m.add("count", m_header.pointCount(), "This field contains the total " "number of point records within the file."); diff --git a/io/LasWriter.cpp b/io/LasWriter.cpp index 6c758ef472..8fc4d2d6d9 100644 --- a/io/LasWriter.cpp +++ b/io/LasWriter.cpp @@ -228,7 +228,6 @@ void LasWriter::prepared(PointTableRef table) // Capture user-specified VLRs void LasWriter::addUserVlrs() { - for (const auto& v : m_userVLRs) { uint16_t recordId(1); @@ -244,8 +243,9 @@ void LasWriter::addUserVlrs() throw pdal_error("VLR must contain a base64-encoded 'data' member"); b64data = v["data"].asString(); + // Record ID should always be no more than 2 bytes. if (v.isMember("record_id")) - recordId = v["record_id"].asUInt64(); + recordId = static_cast(v["record_id"].asUInt64()); if (v.isMember("description")) description = v["description"].asString(); @@ -942,7 +942,7 @@ bool LasWriter::writeLasZipBuf(PointRef& point) p.extended_number_of_returns = numberOfReturns; p.extended_scanner_channel = scanChannel; p.extended_scan_angle = - roundf(point.getFieldAs(Id::ScanAngleRank) / .006); + std::round(point.getFieldAs(Id::ScanAngleRank) / .006f); p.extended_classification_flags = classFlags; p.extended_classification = classification; p.classification = (classification & 0x1F) | (classFlags << 5); @@ -1092,9 +1092,11 @@ bool LasWriter::fillPointBuf(PointRef& point, LeInserter& ostream) uint8_t userData = point.getFieldAs(Id::UserData); if (has14Format) { - int16_t scanAngleRank = - point.getFieldAs(Id::ScanAngleRank) / .006; - ostream << userData << scanAngleRank; + // Guaranteed to fit if scan angle rank isn't wonky. + int16_t scanAngleRank = + static_cast(std::round( + point.getFieldAs(Id::ScanAngleRank) / .006f)); + ostream << userData << scanAngleRank; } else { diff --git a/io/OptechReader.hpp b/io/OptechReader.hpp index 5a873e809b..2f4b3dc7b2 100644 --- a/io/OptechReader.hpp +++ b/io/OptechReader.hpp @@ -55,7 +55,8 @@ class PDAL_DLL OptechReader : public Reader static const size_t MaximumNumberOfReturns = 4; static const size_t NumBytesInRecord = 69; - static const size_t MaxNumRecordsInBuffer = 1e6 / NumBytesInRecord; + static const size_t BufferSize = 1000000; + static const size_t MaxNumRecordsInBuffer = BufferSize / NumBytesInRecord; OptechReader(); diff --git a/pdal/EigenUtils.cpp b/pdal/EigenUtils.cpp index 52a5b018ca..d2e3201007 100644 --- a/pdal/EigenUtils.cpp +++ b/pdal/EigenUtils.cpp @@ -95,9 +95,15 @@ Eigen::Matrix3f computeCovariance(PointView& view, size_t k = 0; for (auto const& j : ids) { - A(0, k) = view.getFieldAs(Dimension::Id::X, j) - centroid[0]; - A(1, k) = view.getFieldAs(Dimension::Id::Y, j) - centroid[1]; - A(2, k) = view.getFieldAs(Dimension::Id::Z, j) - centroid[2]; + A(0, k) = + static_cast(view.getFieldAs(Dimension::Id::X, j) - + centroid[0]); + A(1, k) = + static_cast(view.getFieldAs(Dimension::Id::Y, j) - + centroid[1]); + A(2, k) = + static_cast(view.getFieldAs(Dimension::Id::Z, j) - + centroid[2]); k++; }