[Liblas-commits] hg: 2 new changesets
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Oct 7 17:47:12 EDT 2009
changeset 88471ec2904e in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=88471ec2904e
summary: be more explicit for operator precedence
changeset c0caf67671c3 in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=c0caf67671c3
summary: reinstate the check for extra 1.0-style pad bytes around the end of the header. some people are writing them but not accounting for them in the dataoffset (qtmodeler)
diffstat:
include/liblas/detail/reader.hpp | 2 +-
src/detail/reader.cpp | 29 ++++++++++++++++++++++++++++-
src/detail/reader10.cpp | 13 +++++++++++++
src/detail/reader11.cpp | 17 ++++++++++++++++-
src/detail/reader12.cpp | 13 +++++++++++++
src/laspoint.cpp | 6 +++---
6 files changed, 74 insertions(+), 6 deletions(-)
diffs (159 lines):
diff -r fdcd26af0c5a -r c0caf67671c3 include/liblas/detail/reader.hpp
--- a/include/liblas/detail/reader.hpp Wed Oct 07 14:41:07 2009 -0500
+++ b/include/liblas/detail/reader.hpp Wed Oct 07 16:44:33 2009 -0500
@@ -93,7 +93,7 @@
void FillPoint(PointRecord& record, LASPoint& point, const LASHeader& header);
void Project(LASPoint& point);
-
+ bool HasPointDataSignature();
private:
// Blocked copying operations, declared but not defined.
diff -r fdcd26af0c5a -r c0caf67671c3 src/detail/reader.cpp
--- a/src/detail/reader.cpp Wed Oct 07 14:41:07 2009 -0500
+++ b/src/detail/reader.cpp Wed Oct 07 16:44:33 2009 -0500
@@ -113,7 +113,6 @@
point.SetY(y);
point.SetZ(z);
-
} else {
point.SetX(record.x);
point.SetY(record.y);
@@ -276,6 +275,33 @@
#endif
}
+bool Reader::HasPointDataSignature()
+{
+ uint8_t const sgn1 = 0xCC;
+ uint8_t const sgn2 = 0xDD;
+ uint8_t pad1 = 0x0;
+ uint8_t pad2 = 0x0;
+
+ std::streamsize const current_pos = m_ifs.tellg();
+
+ 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);
+
+ // Put the stream back where we found it
+ m_ifs.seekg(current_pos, std::ios::beg);
+
+ // 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;
+
+ return found;
+}
Reader* ReaderFactory::Create(std::istream& ifs)
{
if (!ifs)
@@ -319,4 +345,5 @@
p = 0;
}
+
}} // namespace liblas::detail
diff -r fdcd26af0c5a -r c0caf67671c3 src/detail/reader10.cpp
--- a/src/detail/reader10.cpp Wed Oct 07 14:41:07 2009 -0500
+++ b/src/detail/reader10.cpp Wed Oct 07 16:44:33 2009 -0500
@@ -213,6 +213,19 @@
header.SetMax(x1, y1, z1);
header.SetMin(x2, y2, z2);
+ // We're going to check the two bytes off the end of the header to
+ // see if they're pad bytes anyway. Some softwares, notably older QTModeler,
+ // write 1.0-style pad bytes off the end of their files but state that the
+ // offset is actually 2 bytes back. We need to set the dataoffset
+ // appropriately in those cases anyway.
+ m_ifs.seekg(header.GetDataOffset());
+ bool has_pad = HasPointDataSignature();
+ if (has_pad) {
+ std::streamsize const current_pos = m_ifs.tellg();
+ m_ifs.seekg(current_pos + 2);
+ header.SetDataOffset(header.GetDataOffset() + 2);
+ }
+
Reset(header);
return true;
diff -r fdcd26af0c5a -r c0caf67671c3 src/detail/reader11.cpp
--- a/src/detail/reader11.cpp Wed Oct 07 14:41:07 2009 -0500
+++ b/src/detail/reader11.cpp Wed Oct 07 16:44:33 2009 -0500
@@ -214,7 +214,20 @@
header.SetMax(x1, y1, z1);
header.SetMin(x2, y2, z2);
-
+
+ // We're going to check the two bytes off the end of the header to
+ // see if they're pad bytes anyway. Some softwares, notably older QTModeler,
+ // write 1.0-style pad bytes off the end of their files but state that the
+ // offset is actually 2 bytes back. We need to set the dataoffset
+ // appropriately in those cases anyway.
+ m_ifs.seekg(header.GetDataOffset());
+ bool has_pad = HasPointDataSignature();
+ if (has_pad) {
+ std::streamsize const current_pos = m_ifs.tellg();
+ m_ifs.seekg(current_pos + 2);
+ header.SetDataOffset(header.GetDataOffset() + 2);
+ }
+
Reset(header);
return true;
@@ -250,6 +263,8 @@
Reader::FillPoint(record, point, header);
point.SetCoordinates(header, point.GetX(), point.GetY(), point.GetZ());
+
+ // printf("ReadNextPoint: %d %d %d\n%.3f %.3f %.3f\n", record.x, record.y, record.z, point.GetX(), point.GetY(), point.GetZ());
if (header.GetDataFormatId() == LASHeader::ePointFormat1)
{
diff -r fdcd26af0c5a -r c0caf67671c3 src/detail/reader12.cpp
--- a/src/detail/reader12.cpp Wed Oct 07 14:41:07 2009 -0500
+++ b/src/detail/reader12.cpp Wed Oct 07 16:44:33 2009 -0500
@@ -217,6 +217,19 @@
header.SetMax(x1, y1, z1);
header.SetMin(x2, y2, z2);
+ // We're going to check the two bytes off the end of the header to
+ // see if they're pad bytes anyway. Some softwares, notably older QTModeler,
+ // write 1.0-style pad bytes off the end of their files but state that the
+ // offset is actually 2 bytes back. We need to set the dataoffset
+ // appropriately in those cases anyway.
+ m_ifs.seekg(header.GetDataOffset());
+ bool has_pad = HasPointDataSignature();
+ if (has_pad) {
+ std::streamsize const current_pos = m_ifs.tellg();
+ m_ifs.seekg(current_pos + 2);
+ header.SetDataOffset(header.GetDataOffset() + 2);
+ }
+
Reset(header);
return true;
diff -r fdcd26af0c5a -r c0caf67671c3 src/laspoint.cpp
--- a/src/laspoint.cpp Wed Oct 07 14:41:07 2009 -0500
+++ b/src/laspoint.cpp Wed Oct 07 16:44:33 2009 -0500
@@ -94,9 +94,9 @@
void LASPoint::SetCoordinates(LASHeader const& header, double x, double y, double z)
{
- double const cx = x * header.GetScaleX() + header.GetOffsetX();
- double const cy = y * header.GetScaleY() + header.GetOffsetY();
- double const cz = z * header.GetScaleZ() + header.GetOffsetZ();
+ double const cx = (x * header.GetScaleX()) + header.GetOffsetX();
+ double const cy = (y * header.GetScaleY()) + header.GetOffsetY();
+ double const cz = (z * header.GetScaleZ()) + header.GetOffsetZ();
SetCoordinates(cx, cy, cz);
}
More information about the Liblas-commits
mailing list