[Liblas-commits] hg: 2 new changesets
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Jul 30 10:17:05 EDT 2010
changeset fdf5dbd00a65 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=fdf5dbd00a65
summary: throw errors if we don't get valid pointers back from the liblas::detail::reader::Point
changeset 6a15d6ae9cee in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=6a15d6ae9cee
summary: fetch the point data into a single array instead of piece-wise reading it, use that array to set interpreted values on the liblas::Point, and set the raw data back onto the point
diffstat:
include/liblas/detail/reader/point.hpp | 1 +
src/detail/reader/point.cpp | 88 ++++++++++++++++++---------------
src/detail/reader/reader.cpp | 16 +++++-
3 files changed, 63 insertions(+), 42 deletions(-)
diffs (205 lines):
diff -r 52f24e850b32 -r 6a15d6ae9cee include/liblas/detail/reader/point.hpp
--- a/include/liblas/detail/reader/point.hpp Thu Jul 29 17:52:24 2010 +0100
+++ b/include/liblas/detail/reader/point.hpp Fri Jul 30 09:16:58 2010 -0500
@@ -81,6 +81,7 @@
std::istream& m_ifs;
HeaderPtr m_header;
PointPtr m_point;
+ std::vector<uint8_t> m_raw_data;
void setup();
void fill(PointRecord& record);
diff -r 52f24e850b32 -r 6a15d6ae9cee src/detail/reader/point.cpp
--- a/src/detail/reader/point.cpp Thu Jul 29 17:52:24 2010 +0100
+++ b/src/detail/reader/point.cpp Fri Jul 30 09:16:58 2010 -0500
@@ -51,7 +51,7 @@
void Point::setup()
{
-
+ m_raw_data.resize(m_header->GetSchema().GetByteSize());
}
Point::Point(std::istream& ifs, HeaderPtr header) :
@@ -73,102 +73,108 @@
void Point::read()
{
- // accounting to keep track of the fact that the DataRecordLength
- // might not map to ePointSize0 or ePointSize1 (see http://liblas.org/ticket/142)
- std::size_t bytesread(0);
double gpst(0);
liblas::uint16_t red(0);
liblas::uint16_t blue(0);
liblas::uint16_t green(0);
- // raw byte data necessary to fill out the point format
- std::vector<uint8_t> format_data;
-
- format_data.resize(m_header->GetSchema().GetBaseByteSize());
-
- detail::PointRecord record;
- // TODO: Replace with compile-time assert
-
- assert(liblas::ePointSize0 == sizeof(record));
+ // accounting to keep track of the fact that the DataRecordLength
+ // might not map to ePointSize0 or ePointSize1 (see http://liblas.org/ticket/142)
+ std::vector<uint8_t>::size_type i = 0;
// Set the header for the point early because
// SetCoordinates will use it later to scale the
// point
m_point->SetHeader(m_header);
-
+
try
{
- detail::read_n(record, m_ifs, sizeof(PointRecord));
- bytesread += sizeof(PointRecord);
+ detail::read_n(m_raw_data.front(), m_ifs, m_raw_data.size());
}
catch (std::out_of_range const& e) // we reached the end of the file
{
std::cerr << e.what() << std::endl;
- }
+ }
+
+ detail::PointRecord record;
+ memcpy(&record.x, &(m_raw_data[i]), sizeof(int32_t)); i+=sizeof(int32_t);
+ memcpy(&record.y, &(m_raw_data[i]), sizeof(int32_t)); i+=sizeof(int32_t);
+ memcpy(&record.z, &(m_raw_data[i]), sizeof(int32_t)); i+=sizeof(int32_t);
+ memcpy(&record.intensity, &(m_raw_data[i]), sizeof(uint16_t)); i+=sizeof(uint16_t);
+ memcpy(&record.flags, &(m_raw_data[i]), sizeof(uint8_t)); i+=sizeof(uint8_t);
+ memcpy(&record.classification, &(m_raw_data[i]), sizeof(uint8_t)); i+=sizeof(uint8_t);
+ memcpy(&record.scan_angle_rank, &(m_raw_data[i]), sizeof(int8_t)); i+=sizeof(int8_t);
+ memcpy(&record.user_data, &(m_raw_data[i]), sizeof(uint8_t)); i+=sizeof(uint8_t);
+ memcpy(&record.point_source_id, &(m_raw_data[i]), sizeof(uint16_t)); i+=sizeof(uint16_t);
+
+
fill(record);
- // Reader::FillPoint(record, m_point, m_header);
m_point->SetCoordinates(m_point->GetX(), m_point->GetY(), m_point->GetZ());
+
if (m_header->GetSchema().HasTime())
{
-
- detail::read_n(gpst, m_ifs, sizeof(double));
+ memcpy(&gpst, &(m_raw_data[i]), sizeof(double));
+
m_point->SetTime(gpst);
- bytesread += sizeof(double);
+ i += sizeof(double);
if (m_header->GetSchema().HasColor())
{
- detail::read_n(red, m_ifs, sizeof(uint16_t));
- detail::read_n(green, m_ifs, sizeof(uint16_t));
- detail::read_n(blue, m_ifs, sizeof(uint16_t));
-
+ memcpy(&red, &(m_raw_data[i]), sizeof(uint16_t));
+ memcpy(&green, &(m_raw_data[i]), sizeof(uint16_t));
+ memcpy(&blue, &(m_raw_data[i]), sizeof(uint16_t));
+
liblas::Color color(red, green, blue);
m_point->SetColor(color);
- bytesread += 3 * sizeof(uint16_t);
+ i += 3 * sizeof(uint16_t);
}
} else {
if (m_header->GetSchema().HasColor())
{
- detail::read_n(red, m_ifs, sizeof(uint16_t));
- detail::read_n(green, m_ifs, sizeof(uint16_t));
- detail::read_n(blue, m_ifs, sizeof(uint16_t));
-
+ memcpy(&red, &(m_raw_data[i]), sizeof(uint16_t));
+ memcpy(&green, &(m_raw_data[i]), sizeof(uint16_t));
+ memcpy(&blue, &(m_raw_data[i]), sizeof(uint16_t));
+
liblas::Color color(red, green, blue);
m_point->SetColor(color);
- bytesread += 3 * sizeof(uint16_t);
+ i += 3 * sizeof(uint16_t);
}
}
-
+
if (m_header->GetSchema().GetBaseByteSize() != m_header->GetSchema().GetByteSize())
{
- std::size_t bytesleft = m_header->GetDataRecordLength() - bytesread;
-
+ std::size_t bytesleft = m_header->GetDataRecordLength() - i;
+
+
std::vector<uint8_t> data;
data.resize(bytesleft);
-
- detail::read_n(data.front(), m_ifs, bytesleft);
+ memcpy(&(data.front()), &(m_raw_data[i]), bytesleft);
m_point->SetExtraData(data);
- bytesread = bytesread + bytesleft;
-
+ i = i + bytesleft;
+
}
- if (bytesread != m_header->GetSchema().GetByteSize()) {
+ if (i != m_header->GetSchema().GetByteSize()) {
std::ostringstream msg;
- msg << "The number of bytes that were read ("<< bytesread <<") does not "
+ msg << "The number of bytes that were read ("<< i <<") does not "
"match the number of bytes the point's format "
"says it should have (" <<
m_header->GetSchema().GetByteSize() << ")";
throw std::runtime_error(msg.str());
}
-
+
+ // Put the data on the point
+ m_point->SetData(m_raw_data);
+
}
diff -r 52f24e850b32 -r 6a15d6ae9cee src/detail/reader/reader.cpp
--- a/src/detail/reader/reader.cpp Thu Jul 29 17:52:24 2010 +0100
+++ b/src/detail/reader/reader.cpp Fri Jul 30 09:16:58 2010 -0500
@@ -112,7 +112,14 @@
if (m_current < m_size)
{
m_point_reader->read();
- PointPtr ptr(new liblas::Point(m_point_reader->GetPoint()));
+
+ PointPtr ptr = PointPtr(new liblas::Point(m_point_reader->GetPoint()));
+ if (ptr.get() == 0) {
+ std::ostringstream output;
+ output << "Unable to fetch point from reader " ;
+ std::string out(output.str());
+ throw std::runtime_error(out);
+ }
++m_current;
return ptr;
@@ -313,6 +320,13 @@
}
PointPtr ptr = ReadCachedPoint(n, header);
+ if (ptr.get() == 0 ) {
+ std::ostringstream output;
+ output << "unable to fetch point from cache at position : "
+ << n;
+ std::string out(output.str());
+ throw std::runtime_error(out);
+ }
m_cache_read_position = n;
return *ptr;
}
More information about the Liblas-commits
mailing list