[Liblas-commits] r1190 - in trunk: include/liblas/detail src/detail
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Apr 8 22:59:49 EDT 2009
Author: hobu
Date: Wed Apr 8 22:59:46 2009
New Revision: 1190
URL: http://liblas.org/changeset/1190
Log:
attempt to fix #124, working with files that have pad bytes when they shouldn't
Modified:
trunk/include/liblas/detail/reader.hpp
trunk/src/detail/reader.cpp
trunk/src/detail/reader10.cpp
trunk/src/detail/reader11.cpp
trunk/src/detail/reader12.cpp
Modified: trunk/include/liblas/detail/reader.hpp
==============================================================================
--- trunk/include/liblas/detail/reader.hpp (original)
+++ trunk/include/liblas/detail/reader.hpp Wed Apr 8 22:59:46 2009
@@ -74,6 +74,7 @@
bool ReadGeoreference(LASHeader& header);
void Reset(LASHeader const& header);
void SetSRS(const LASSpatialReference& srs);
+ void SkipPointDataSignature();
protected:
@@ -87,6 +88,7 @@
OGRCoordinateTransformationH m_transform;
OGRSpatialReferenceH m_in_ref;
OGRSpatialReferenceH m_out_ref;
+ bool m_has_pad_bytes;
void FillPoint(PointRecord& record, LASPoint& point);
void Project(LASPoint& point);
Modified: trunk/src/detail/reader.cpp
==============================================================================
--- trunk/src/detail/reader.cpp (original)
+++ trunk/src/detail/reader.cpp Wed Apr 8 22:59:46 2009
@@ -275,6 +275,27 @@
throw std::runtime_error("LAS file of unknown version");
}
+void Reader::SkipPointDataSignature()
+{
+ uint8_t const sgn1 = 0xCC;
+ uint8_t const sgn2 = 0xDD;
+ uint8_t pad1 = 0x0;
+ uint8_t pad2 = 0x0;
+ detail::read_n(pad1, m_ifs, sizeof(uint8_t));
+ detail::read_n(pad2, m_ifs, sizeof(uint8_t));
+
+ // FIXME: we have to worry about swapping issues
+ // for now, just check oppositely
+ if (! (sgn1 == pad2 && sgn2 == pad1))
+ {
+ // If the two bytes we read weren't signature bytes
+ // we'll throw an exception. Depending on the version
+ // we may want ot throw an error to the user or
+ // silently continue on.
+ throw std::domain_error("point data signature (1.0's 0xCC and 0xDD padding) not found");
+ }
+}
+
void ReaderFactory::Destroy(Reader* p)
{
delete p;
Modified: trunk/src/detail/reader10.cpp
==============================================================================
--- trunk/src/detail/reader10.cpp (original)
+++ trunk/src/detail/reader10.cpp Wed Apr 8 22:59:46 2009
@@ -207,8 +207,24 @@
header.SetMax(x1, y1, z1);
header.SetMin(x2, y2, z2);
+ // The 1.0 version *requires* the pad bytes, but in
+ // many instances, there are files without them. What
+ // a fucking mess -- hobu.
+ try {
+ SkipPointDataSignature();
+ m_has_pad_bytes = true;
+ }
+ catch (std::domain_error const& e)
+ {
+ // TODO: We'll want to put this error on the validation errors stack
+ // but for now, we'll just move back to the offset
+ }
+
+
Reset(header);
+
+
return true;
}
@@ -227,6 +243,19 @@
{
m_ifs.clear();
m_ifs.seekg(m_offset, std::ios::beg);
+
+ // The 1.0 version *requires* the pad bytes, but in
+ // many instances, there are files without them. What
+ // a fucking mess -- hobu.
+ try {
+ SkipPointDataSignature();
+ }
+ catch (std::domain_error const& e)
+ {
+ // TODO: We'll want to put this error on the validation errors stack
+ // but for now, we'll just move back to the offset
+ m_ifs.seekg(m_offset, std::ios::beg);
+ }
}
if (m_current < m_size)
@@ -268,6 +297,7 @@
return false;
std::streamsize pos = (static_cast<std::streamsize>(n) * m_recordlength) + m_offset;
+ if (m_has_pad_bytes) pos += 2;
m_ifs.clear();
m_ifs.seekg(pos, std::ios::beg);
Modified: trunk/src/detail/reader11.cpp
==============================================================================
--- trunk/src/detail/reader11.cpp (original)
+++ trunk/src/detail/reader11.cpp Wed Apr 8 22:59:46 2009
@@ -211,8 +211,21 @@
header.SetMax(x1, y1, z1);
header.SetMin(x2, y2, z2);
+ m_ifs.seekg(header.GetDataOffset(), std::ios::beg);
+ try {
+ // If this call succeeds, we'll want to put this on the
+ // validation errors stack. 1.1 files shouldn't have
+ // pad bytes.
+ SkipPointDataSignature();
+ m_has_pad_bytes = true;
+ }
+ catch (std::domain_error const& e)
+ {
+ }
+
Reset(header);
-
+
+
return true;
}
@@ -230,6 +243,17 @@
{
m_ifs.clear();
m_ifs.seekg(m_offset, std::ios::beg);
+
+ try {
+ // If this call succeeds, we'll want to put this on the
+ // validation errors stack. 1.1 files shouldn't have
+ // pad bytes.
+ SkipPointDataSignature();
+ }
+ catch (std::domain_error const& e)
+ {
+ m_ifs.seekg(m_offset, std::ios::beg);
+ }
}
if (m_current < m_size)
@@ -272,8 +296,10 @@
if (m_size <= n)
return false;
- std::streamsize const pos = (static_cast<std::streamsize>(n) * m_recordlength) + m_offset;
+ std::streamsize pos = (static_cast<std::streamsize>(n) * m_recordlength) + m_offset;
+ if (m_has_pad_bytes) pos += 2;
+
m_ifs.clear();
m_ifs.seekg(pos, std::ios::beg);
detail::read_n(record, m_ifs, sizeof(record));
Modified: trunk/src/detail/reader12.cpp
==============================================================================
--- trunk/src/detail/reader12.cpp (original)
+++ trunk/src/detail/reader12.cpp Wed Apr 8 22:59:46 2009
@@ -217,6 +217,19 @@
header.SetMax(x1, y1, z1);
header.SetMin(x2, y2, z2);
+ m_ifs.seekg(header.GetDataOffset(), std::ios::beg);
+ try {
+ // If this call succeeds, we'll want to put this on the
+ // validation errors stack. 1.2 files shouldn't have
+ // pad bytes.
+ SkipPointDataSignature();
+ m_has_pad_bytes = true;
+ }
+ catch (std::domain_error const& e)
+ {
+ }
+
+
Reset(header);
return true;
@@ -241,6 +254,17 @@
{
m_ifs.clear();
m_ifs.seekg(m_offset, std::ios::beg);
+
+ try {
+ // If this call succeeds, we'll want to put this on the
+ // validation errors stack. 1.2 files shouldn't have
+ // pad bytes.
+ SkipPointDataSignature();
+ }
+ catch (std::domain_error const& e)
+ {
+ m_ifs.seekg(m_offset, std::ios::beg);
+ }
}
if (m_current < m_size)
@@ -313,7 +337,9 @@
return false;
}
- std::streamsize const pos = (static_cast<std::streamsize>(n) * m_recordlength) + m_offset;
+ std::streamsize pos = (static_cast<std::streamsize>(n) * m_recordlength) + m_offset;
+
+ if (m_has_pad_bytes) pos += 2;
m_ifs.clear();
m_ifs.seekg(pos, std::ios::beg);
More information about the Liblas-commits
mailing list