[Liblas-commits] hg-1.6: cut down on unnecessary rescaling of data
by checking he...
liblas-commits at liblas.org
liblas-commits at liblas.org
Tue Feb 22 15:11:03 EST 2011
details: http://hg.liblas.orghg-1.6/rev/c4d52c8eeb77
changeset: 2852:c4d52c8eeb77
user: Howard Butler <hobu.inc at gmail.com>
date: Tue Feb 22 14:06:31 2011 -0600
description:
cut down on unnecessary rescaling of data by checking header offset/scale first
Subject: hg-1.6: add method to override ReprojectionTransform's header after it is instantiated
details: http://hg.liblas.orghg-1.6/rev/f4c8230665f0
changeset: 2853:f4c8230665f0
user: Howard Butler <hobu.inc at gmail.com>
date: Tue Feb 22 14:06:57 2011 -0600
description:
add method to override ReprojectionTransform's header after it is instantiated
Subject: hg-1.6: fix #216 mis-scaling of data with --min-offset and a reprojection operation
details: http://hg.liblas.orghg-1.6/rev/bbae04bc10a7
changeset: 2854:bbae04bc10a7
user: Howard Butler <hobu.inc at gmail.com>
date: Tue Feb 22 14:09:47 2011 -0600
description:
fix #216 mis-scaling of data with --min-offset and a reprojection operation
diffstat:
apps/las2las.cpp | 35 ++++++++++++++++++++++++++++----
include/liblas/transform.hpp | 1 +
src/point.cpp | 46 +++++++++++++++++++++++++++++++++++++------
3 files changed, 70 insertions(+), 12 deletions(-)
diffs (138 lines):
diff -r 4683dccafce5 -r bbae04bc10a7 apps/las2las.cpp
--- a/apps/las2las.cpp Mon Feb 21 14:47:34 2011 -0600
+++ b/apps/las2las.cpp Tue Feb 22 14:09:47 2011 -0600
@@ -88,6 +88,20 @@
std::cout << std::endl;
}
reader.Reset();
+
+ std::vector<liblas::TransformPtr> transforms = reader.GetTransforms();
+ std::vector<liblas::TransformPtr> new_transforms;
+ for (std::size_t i = 0; i < transforms.size(); i++)
+ {
+ liblas::TransformPtr transform = transforms[i];
+
+ if (dynamic_cast<liblas::ReprojectionTransform*>(transform.get()))
+ {
+ dynamic_cast<liblas::ReprojectionTransform*>(transform.get())->SetHeaderPtr(liblas::HeaderPtr(new liblas::Header(header)));
+ }
+ new_transforms.push_back(transform);
+ }
+ reader.SetTransforms(new_transforms);
}
std::ostream* ofs = NULL;
@@ -118,13 +132,24 @@
boost::int32_t split_bytes_count = 1024*1024*split_mb;
boost::uint32_t split_points_count = 0;
int fileno = 2;
-
+
+ liblas::HeaderPtr ptr = liblas::HeaderPtr(new liblas::Header(header));
+
while (reader.ReadNextPoint())
{
-
- liblas::Point const& p = reader.GetPoint();
- summary->AddPoint(p);
- writer->WritePoint(p);
+ if (min_offset)
+ {
+ liblas::Point p = reader.GetPoint();
+ summary->AddPoint(p);
+ p.SetHeaderPtr(ptr);
+ writer->WritePoint(p);
+ }
+ else
+ {
+ liblas::Point const& p = reader.GetPoint();
+ summary->AddPoint(p);
+ writer->WritePoint(p);
+ }
if (verbose)
term_progress(std::cout, (i + 1) / static_cast<double>(size));
i++;
diff -r 4683dccafce5 -r bbae04bc10a7 include/liblas/transform.hpp
--- a/include/liblas/transform.hpp Mon Feb 21 14:47:34 2011 -0600
+++ b/include/liblas/transform.hpp Tue Feb 22 14:09:47 2011 -0600
@@ -76,6 +76,7 @@
~ReprojectionTransform();
bool transform(Point& point);
+ void SetHeaderPtr(liblas::HeaderPtr header) {m_new_header = header;}
bool ModifiesHeader() { return true; }
private:
diff -r 4683dccafce5 -r bbae04bc10a7 src/point.cpp
--- a/src/point.cpp Mon Feb 21 14:47:34 2011 -0600
+++ b/src/point.cpp Tue Feb 22 14:09:47 2011 -0600
@@ -190,11 +190,33 @@
{
boost::uint16_t wanted_length;
+ bool bSetCoordinates = true;
+
const liblas::Schema* schema;
if (header.get()) {
wanted_length = header->GetDataRecordLength();
schema = &header->GetSchema();
+ if (m_header.get())
+ {
+ if (detail::compare_distance(header->GetScaleX(), m_header->GetScaleX()) ||
+ detail::compare_distance(header->GetScaleY(), m_header->GetScaleY()) ||
+ detail::compare_distance(header->GetScaleZ(), m_header->GetScaleZ()))
+ bSetCoordinates = false;
+ else
+ bSetCoordinates = true;
+
+ if (detail::compare_distance(header->GetOffsetX(), m_header->GetOffsetX()) ||
+ detail::compare_distance(header->GetOffsetY(), m_header->GetOffsetY()) ||
+ detail::compare_distance(header->GetOffsetZ(), m_header->GetOffsetZ()))
+ bSetCoordinates = false;
+ else
+ bSetCoordinates = true;
+
+ // if (!bSetCoordinates)
+ // std::cout << "Scales and offsets are equal, not resetting coordinates" << std::endl;
+ }
+
}
else
{
@@ -255,18 +277,28 @@
m_header = header;
return;
}
+
+ double x;
+ double y;
+ double z;
- double x = GetX();
- double y = GetY();
- double z = GetZ();
+ if (bSetCoordinates)
+ {
+ x = GetX();
+ y = GetY();
+ z = GetZ();
+ }
// The header's scale/offset can change the raw storage of xyz.
// SetHeaderPtr can result in a rescaling of the data.
m_header = header;
-
- SetX(x);
- SetY(y);
- SetZ(z);
+
+ if (bSetCoordinates)
+ {
+ SetX(x);
+ SetY(y);
+ SetZ(z);
+ }
}
HeaderPtr Point::GetHeaderPtr() const
More information about the Liblas-commits
mailing list