[Liblas-commits] r1199 - in branches/1.2: include/liblas/detail
src/detail
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Apr 10 12:04:03 EDT 2009
Author: hobu
Date: Fri Apr 10 12:04:01 2009
New Revision: 1199
URL: http://liblas.org/changeset/1199
Log:
backport fixes for #124 r1190, r1193, r1194
Modified:
branches/1.2/include/liblas/detail/reader.hpp
branches/1.2/src/detail/reader.cpp
branches/1.2/src/detail/reader10.cpp
branches/1.2/src/detail/reader11.cpp
branches/1.2/src/detail/reader12.cpp
Modified: branches/1.2/include/liblas/detail/reader.hpp
==============================================================================
--- branches/1.2/include/liblas/detail/reader.hpp (original)
+++ branches/1.2/include/liblas/detail/reader.hpp Fri Apr 10 12:04:01 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: branches/1.2/src/detail/reader.cpp
==============================================================================
--- branches/1.2/src/detail/reader.cpp (original)
+++ branches/1.2/src/detail/reader.cpp Fri Apr 10 12:04:01 2009
@@ -275,6 +275,35 @@
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));
+
+ LIBLAS_SWAP_BYTES(pad1);
+ LIBLAS_SWAP_BYTES(pad2);
+
+ // FIXME: we have to worry about swapping issues
+ // but some people write the pad bytes backwards
+ // anyway. Let's check both ways.
+ bool found = false;
+ if (sgn1 == pad2 && sgn2 == pad1) found = true;
+ if (sgn1 == pad1 && sgn2 == pad2) found = true;
+ if (!found)
+ {
+ // 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: branches/1.2/src/detail/reader10.cpp
==============================================================================
--- branches/1.2/src/detail/reader10.cpp (original)
+++ branches/1.2/src/detail/reader10.cpp Fri Apr 10 12:04:01 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,7 +297,6 @@
return false;
std::streamsize pos = (static_cast<std::streamsize>(n) * m_recordlength) + m_offset;
-
m_ifs.clear();
m_ifs.seekg(pos, std::ios::beg);
detail::read_n(record, m_ifs, sizeof(record));
Modified: branches/1.2/src/detail/reader11.cpp
==============================================================================
--- branches/1.2/src/detail/reader11.cpp (original)
+++ branches/1.2/src/detail/reader11.cpp Fri Apr 10 12:04:01 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: branches/1.2/src/detail/reader12.cpp
==============================================================================
--- branches/1.2/src/detail/reader12.cpp (original)
+++ branches/1.2/src/detail/reader12.cpp Fri Apr 10 12:04:01 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