Skip to content

Commit

Permalink
More fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Oct 19, 2018
1 parent b00545c commit 04be6dc
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 25 deletions.
2 changes: 1 addition & 1 deletion filters/SMRFilter.cpp
Expand Up @@ -613,7 +613,7 @@ std::vector<int> SMRFilter::progressiveFilter(std::vector<double> 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<int>(std::ceil(max_window / m_args->m_cell));
std::vector<double> prevSurface = ZImin;
std::vector<double> prevErosion = ZImin;

Expand Down
12 changes: 7 additions & 5 deletions io/FauxReader.cpp
Expand Up @@ -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
{
Expand Down
19 changes: 13 additions & 6 deletions io/GDALWriter.cpp
Expand Up @@ -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<size_t>(((m_curBounds.maxx - m_curBounds.minx) /
m_edgeLength) + 1);
size_t height = static_cast<size_t>(((m_curBounds.maxy - m_curBounds.miny) / m_edgeLength) + 1);
try
{
m_grid.reset(new GDALGrid(width, height, m_edgeLength, m_radius,
Expand All @@ -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<size_t>(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<size_t>(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<size_t>(((bounds.maxx - bounds.minx) / m_edgeLength) + 1);
size_t height =
static_cast<size_t>(((bounds.maxy - bounds.miny) / m_edgeLength) + 1);
try
{
m_grid->expand(width, height, xshift, yshift);
Expand Down
7 changes: 5 additions & 2 deletions io/LasHeader.cpp
Expand Up @@ -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<uint32_t>::max)());
//ABELL - This needs fixing. Should set to 0 when we exceed
// std::numeric_limits<uint32_t>::max().
uint32_t legacyReturnCount =
static_cast<uint32_t>((std::min)(h.m_pointCountByReturn[i],
(uint64_t)(std::numeric_limits<uint32_t>::max)()));
out << legacyReturnCount;
}

Expand Down
2 changes: 1 addition & 1 deletion io/LasReader.cpp
Expand Up @@ -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<uint32_t>("count",
m.add<point_count_t>("count",
m_header.pointCount(), "This field contains the total "
"number of point records within the file.");

Expand Down
14 changes: 8 additions & 6 deletions io/LasWriter.cpp
Expand Up @@ -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);
Expand All @@ -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<uint16_t>(v["record_id"].asUInt64());

if (v.isMember("description"))
description = v["description"].asString();
Expand Down Expand Up @@ -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<float>(Id::ScanAngleRank) / .006);
std::round(point.getFieldAs<float>(Id::ScanAngleRank) / .006f);
p.extended_classification_flags = classFlags;
p.extended_classification = classification;
p.classification = (classification & 0x1F) | (classFlags << 5);
Expand Down Expand Up @@ -1092,9 +1092,11 @@ bool LasWriter::fillPointBuf(PointRef& point, LeInserter& ostream)
uint8_t userData = point.getFieldAs<uint8_t>(Id::UserData);
if (has14Format)
{
int16_t scanAngleRank =
point.getFieldAs<float>(Id::ScanAngleRank) / .006;
ostream << userData << scanAngleRank;
// Guaranteed to fit if scan angle rank isn't wonky.
int16_t scanAngleRank =
static_cast<int16_t>(std::round(
point.getFieldAs<float>(Id::ScanAngleRank) / .006f));
ostream << userData << scanAngleRank;
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion io/OptechReader.hpp
Expand Up @@ -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();

Expand Down
12 changes: 9 additions & 3 deletions pdal/EigenUtils.cpp
Expand Up @@ -95,9 +95,15 @@ Eigen::Matrix3f computeCovariance(PointView& view,
size_t k = 0;
for (auto const& j : ids)
{
A(0, k) = view.getFieldAs<double>(Dimension::Id::X, j) - centroid[0];
A(1, k) = view.getFieldAs<double>(Dimension::Id::Y, j) - centroid[1];
A(2, k) = view.getFieldAs<double>(Dimension::Id::Z, j) - centroid[2];
A(0, k) =
static_cast<float>(view.getFieldAs<double>(Dimension::Id::X, j) -
centroid[0]);
A(1, k) =
static_cast<float>(view.getFieldAs<double>(Dimension::Id::Y, j) -
centroid[1]);
A(2, k) =
static_cast<float>(view.getFieldAs<double>(Dimension::Id::Z, j) -
centroid[2]);
k++;
}

Expand Down

0 comments on commit 04be6dc

Please sign in to comment.