[Liblas-commits] hg: fix up some liblas::Point header assignment
stuff introduced...
liblas-commits at liblas.org
liblas-commits at liblas.org
Tue Dec 21 16:44:03 EST 2010
changeset 4cf422b7140a in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=4cf422b7140a
summary: fix up some liblas::Point header assignment stuff introduced by the last few days of performance tweaking
diffstat:
src/detail/reader/reader.cpp | 5 ++-
src/laspoint.cpp | 51 +++++++++++++++++++++++++++++--------------
src/utility.cpp | 1 +
3 files changed, 38 insertions(+), 19 deletions(-)
diffs (154 lines):
diff -r f7e0d60d2e06 -r 4cf422b7140a src/detail/reader/reader.cpp
--- a/src/detail/reader/reader.cpp Tue Dec 21 08:40:29 2010 -0600
+++ b/src/detail/reader/reader.cpp Tue Dec 21 15:43:55 2010 -0600
@@ -134,6 +134,7 @@
m_header_reader->read();
m_header = m_header_reader->GetHeader();
+ m_point->SetHeaderPtr(m_header);
Reset();
@@ -159,7 +160,7 @@
if (bNeedHeaderCheck)
{
- if (m_point->GetHeaderPtr() != m_header)
+ if (m_point->GetHeaderPtr().get() != m_header.get())
m_point->SetHeaderPtr(m_header);
}
@@ -222,7 +223,7 @@
if (bNeedHeaderCheck)
{
- if (m_point->GetHeaderPtr() != m_header)
+ if (m_point->GetHeaderPtr().get() != m_header.get())
m_point->SetHeaderPtr(m_header);
}
diff -r f7e0d60d2e06 -r 4cf422b7140a src/laspoint.cpp
--- a/src/laspoint.cpp Tue Dec 21 08:40:29 2010 -0600
+++ b/src/laspoint.cpp Tue Dec 21 15:43:55 2010 -0600
@@ -190,7 +190,7 @@
{
boost::uint16_t wanted_length;
- if (header)
+ if (header.get())
wanted_length = header->GetDataRecordLength();
else
wanted_length = m_default_header.GetDataRecordLength();
@@ -200,8 +200,10 @@
boost::uint32_t sum = std::accumulate(m_data.begin(), m_data.end(), 0);
if (!sum) {
- m_data.resize(wanted_length);
- m_data.assign(wanted_length, 0);
+ std::vector<boost::uint8_t> data;
+ data.resize(wanted_length);
+ data.assign(wanted_length, 0);
+ m_data = data;
m_header = header;
return;
}
@@ -213,9 +215,12 @@
// layout is likely changing as a result of the
// schema change.
Point p(*this);
-
- m_data.resize(wanted_length);
- m_data.assign(wanted_length, 0);
+
+ std::vector<boost::uint8_t> data;
+ data.resize(wanted_length);
+ data.assign(wanted_length, 0);
+ m_data = data;
+ m_header = header;
SetX(p.GetX());
SetY(p.GetY());
@@ -239,6 +244,10 @@
// FIXME: copy other custom dimensions here? resetting the
// headerptr can be catastrophic in a lot of cases.
+ } else
+ {
+ m_header = header;
+ return;
}
double x = GetX();
@@ -849,17 +858,18 @@
if (f == ePointFormat3)
index_pos = index_pos + 8; // increment to include position of Time.
+
+
std::vector<boost::uint8_t>::size_type red_pos = index_pos;
+ std::vector<boost::uint8_t>::size_type green_pos = index_pos + 2;
+ std::vector<boost::uint8_t>::size_type blue_pos = index_pos + 4;
- assert(red_pos + sizeof(Color::value_type) <= m_data.size());
+ assert(red_pos <= m_data.size());
+ assert(blue_pos <= m_data.size());
+ assert(green_pos <= m_data.size());
+
red = bitsToInt<boost::uint16_t>(red, m_data, red_pos);
-
- std::vector<boost::uint8_t>::size_type green_pos = index_pos + 2;
- assert(green_pos + sizeof(Color::value_type) <= m_data.size());
green = bitsToInt<boost::uint16_t>(green, m_data, green_pos);
-
- std::vector<boost::uint8_t>::size_type blue_pos = index_pos + 4;
- assert(blue_pos + sizeof(Color::value_type) <= m_data.size());
blue = bitsToInt<boost::uint16_t>(blue, m_data, blue_pos);
return Color(red, green, blue);
@@ -872,7 +882,7 @@
// std::size_t index_pos = 13;
PointFormatName f;
- if (m_header) {
+ if (m_header.get()) {
f = m_header->GetDataFormatId();
} else {
f = m_default_header.GetDataFormatId();
@@ -885,6 +895,13 @@
throw std::runtime_error(msg.str());
}
+ if ( m_data.size() == ePointFormat0 || f == ePointFormat1 ) {
+ std::ostringstream msg;
+ msg << "Point::SetColor - Unable to set color for ePointFormat0 or ePointFormat1, "
+ << "no Color dimension exists on this format";
+ throw std::runtime_error(msg.str());
+ }
+
using liblas::detail::intToBits;
std::size_t index_pos = 20;
@@ -896,9 +913,9 @@
std::vector<boost::uint8_t>::size_type green_pos = index_pos + 2;
std::vector<boost::uint8_t>::size_type blue_pos = index_pos + 4;
- assert(red_pos + sizeof(Color::value_type) <= m_data.size());
- assert(blue_pos + sizeof(Color::value_type) <= m_data.size());
- assert(green_pos + sizeof(Color::value_type) <= m_data.size());
+ assert(red_pos <= m_data.size());
+ assert(blue_pos <= m_data.size());
+ assert(green_pos <= m_data.size());
intToBits<boost::uint16_t>(value.GetRed(), m_data, red_pos);
intToBits<boost::uint16_t>(value.GetGreen(), m_data, green_pos);
diff -r f7e0d60d2e06 -r 4cf422b7140a src/utility.cpp
--- a/src/utility.cpp Tue Dec 21 08:40:29 2010 -0600
+++ b/src/utility.cpp Tue Dec 21 15:43:55 2010 -0600
@@ -128,6 +128,7 @@
liblas::Header header;
header.SetScale(hdr->GetScaleX(), hdr->GetScaleY(), hdr->GetScaleZ());
header.SetOffset(hdr->GetOffsetX(), hdr->GetOffsetY(), hdr->GetOffsetZ());
+ header.SetDataFormatId(hdr->GetDataFormatId());
liblas::HeaderPtr h(new liblas::Header(header));
min.SetHeaderPtr(h);
max.SetHeaderPtr(h);
More information about the Liblas-commits
mailing list