Skip to content

Commit

Permalink
Merge pull request #902 from PDAL/las-header-incorrect-pointcount
Browse files Browse the repository at this point in the history
Read mislabeled LAS files where the header says there are more
  • Loading branch information
hobu committed May 8, 2015
2 parents b3ad381 + 7c1b669 commit 75c9bf4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
12 changes: 11 additions & 1 deletion io/las/LasReader.cpp
Expand Up @@ -111,7 +111,7 @@ void LasReader::processOptions(const Options& options)
static PluginInfo const s_info = PluginInfo(
"readers.las",
"ASPRS LAS 1.0 - 1.4 read support. LASzip support is also \n" \
"enabled through this driver if LASzip was found diring \n" \
"enabled through this driver if LASzip was found during \n" \
"compilation.",
"http://pdal.io/stages/readers.las.html" );

Expand Down Expand Up @@ -619,7 +619,17 @@ point_count_t LasReader::readFileBlock(std::vector<char>& buf,
point_count_t blockpoints = buf.size() / ptLen;

blockpoints = std::min(maxpoints, blockpoints);
if (m_istream->eof())
throw pdal::invalid_stream("stream is done");

m_istream->read(buf.data(), blockpoints * ptLen);
if (m_istream->gcount() != (std::streamsize)(blockpoints * ptLen))
{
// we read fewer bytes than we asked for
// because the file was either truncated
// or the header is bunk.
blockpoints = m_istream->gcount() / ptLen;
}
return blockpoints;
}

Expand Down
18 changes: 18 additions & 0 deletions test/unit/io/las/LasReaderTest.cpp
Expand Up @@ -392,3 +392,21 @@ TEST(LasReaderTest, callback)
EXPECT_EQ(count, (point_count_t)1065);
}


// The header of 1.2-with-color-clipped says that it has 1065 points,
// but it really only has 1064.
TEST(LasReaderTest, LasHeaderIncorrentPointcount)
{
PointTable table;

Options readOps;
readOps.add("filename", Support::datapath("las/1.2-with-color-clipped.las"));
LasReader reader;
reader.setOptions(readOps);

reader.prepare(table);
PointViewSet viewSet = reader.execute(table);
PointViewPtr view = *viewSet.begin();

EXPECT_EQ(1064, view->size());
}

0 comments on commit 75c9bf4

Please sign in to comment.