[Liblas-commits] r1209 - trunk/src/detail
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Apr 15 10:27:05 EDT 2009
Author: mloskot
Date: Wed Apr 15 10:27:05 2009
New Revision: 1209
URL: http://liblas.org/changeset/1209
Log:
* Initialize objects of LASColor using new constructor (#130).
* Tighten variables to as local scope as possible, to gain better optimization. A little refactoring.
* TODO:
** mloskot, you really need to move your arse and removing redundant and repeated code!
** Also, exception ticket (#12) has been waiting for too long. Don't forget to send what() messages somewhere like std::log to give users a chance to generate log files.
Modified:
trunk/src/detail/reader10.cpp
trunk/src/detail/reader11.cpp
trunk/src/detail/reader12.cpp
Modified: trunk/src/detail/reader10.cpp
==============================================================================
--- trunk/src/detail/reader10.cpp (original)
+++ trunk/src/detail/reader10.cpp Wed Apr 15 10:27:05 2009
@@ -146,19 +146,24 @@
// 16. Point Data Format ID
read_n(n1, m_ifs, sizeof(n1));
- if (n1 == LASHeader::ePointFormat0) {
+ if (n1 == LASHeader::ePointFormat0)
+ {
header.SetDataFormatId(LASHeader::ePointFormat0);
}
- else if (n1 == LASHeader::ePointFormat1) {
+ else if (n1 == LASHeader::ePointFormat1)
+ {
header.SetDataFormatId(LASHeader::ePointFormat1);
}
- else if (n1 == LASHeader::ePointFormat2) {
+ else if (n1 == LASHeader::ePointFormat2)
+ {
header.SetDataFormatId(LASHeader::ePointFormat2);
}
- else if (n1 == LASHeader::ePointFormat3) {
+ else if (n1 == LASHeader::ePointFormat3)
+ {
header.SetDataFormatId(LASHeader::ePointFormat3);
}
- else {
+ else
+ {
throw std::domain_error("invalid point data format");
}
@@ -212,58 +217,48 @@
// a fucking mess -- hobu.
m_has_pad_bytes = false;
- try {
+ try
+ {
SkipPointDataSignature();
m_has_pad_bytes = true;
}
- catch (std::out_of_range const& e)
+ catch (std::out_of_range const&)
{
// Ignore the out_of_range here for the case of a
// file with just a header and no pad
}
- catch (std::runtime_error const& e)
+ catch (std::runtime_error const&)
{
// Ignore the runtime_error here for the case of a
// file with just a header and no pad
// This is what is thrown when we compile *without* debug
}
- catch (std::domain_error const& e)
+ catch (std::domain_error const&)
{
// 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;
}
bool ReaderImpl::ReadNextPoint(LASPoint& point, const LASHeader& header)
{
- // Read point data record format 0
-
- // TODO: Replace with compile-time assert
-
- detail::PointRecord record;
- double t=0;
-
- assert(LASHeader::ePointSize0 == sizeof(record));
-
if (0 == m_current)
{
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 {
+ try
+ {
SkipPointDataSignature();
}
- catch (std::domain_error const& e)
+ catch (std::domain_error const&)
{
// TODO: We'll want to put this error on the validation errors stack
// but for now, we'll just move back to the offset
@@ -273,6 +268,10 @@
if (m_current < m_size)
{
+ detail::PointRecord record;
+ // TODO: Replace with compile-time assert
+ assert(LASHeader::ePointSize0 == sizeof(record));
+
try
{
detail::read_n(record, m_ifs, sizeof(PointRecord));
@@ -286,10 +285,13 @@
Reader::FillPoint(record, point);
point.SetCoordinates(header, point.GetX(), point.GetY(), point.GetZ());
-
- if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
- detail::read_n(t, m_ifs, sizeof(double));
- point.SetTime(t);
+
+ if (header.GetDataFormatId() == LASHeader::ePointFormat1)
+ {
+ double gpst(0);
+
+ detail::read_n(gpst, m_ifs, sizeof(double));
+ point.SetTime(gpst);
}
return true;
}
@@ -299,28 +301,29 @@
bool ReaderImpl::ReadPointAt(std::size_t n, LASPoint& point, const LASHeader& header)
{
- // Read point data record format 0
-
- // TODO: Replace with compile-time assert
- double t=0;
- detail::PointRecord record;
- assert(LASHeader::ePointSize0 == sizeof(record));
-
if (m_size <= n)
+ {
return false;
- std::streamsize pos = (static_cast<std::streamsize>(n) * m_recordlength) + m_offset;
+ }
+ std::streamsize pos = (static_cast<std::streamsize>(n) * m_recordlength) + m_offset;
m_ifs.clear();
m_ifs.seekg(pos, std::ios::beg);
+
+ detail::PointRecord record;
+ // TODO: Replace with compile-time assert
+ assert(LASHeader::ePointSize0 == sizeof(record));
+
detail::read_n(record, m_ifs, sizeof(record));
Reader::FillPoint(record, point);
point.SetCoordinates(header, point.GetX(), point.GetY(), point.GetZ());
-
- if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
- detail::read_n(t, m_ifs, sizeof(double));
- point.SetTime(t);
+ if (header.GetDataFormatId() == LASHeader::ePointFormat1)
+ {
+ double gpst(0);
+ detail::read_n(gpst, m_ifs, sizeof(double));
+ point.SetTime(gpst);
}
return true;
Modified: trunk/src/detail/reader11.cpp
==============================================================================
--- trunk/src/detail/reader11.cpp (original)
+++ trunk/src/detail/reader11.cpp Wed Apr 15 10:27:05 2009
@@ -150,19 +150,24 @@
// 17. Point Data Format ID
read_n(n1, m_ifs, sizeof(n1));
- if (n1 == LASHeader::ePointFormat0) {
+ if (n1 == LASHeader::ePointFormat0)
+ {
header.SetDataFormatId(LASHeader::ePointFormat0);
}
- else if (n1 == LASHeader::ePointFormat1) {
+ else if (n1 == LASHeader::ePointFormat1)
+ {
header.SetDataFormatId(LASHeader::ePointFormat1);
}
- else if (n1 == LASHeader::ePointFormat2) {
+ else if (n1 == LASHeader::ePointFormat2)
+ {
header.SetDataFormatId(LASHeader::ePointFormat2);
}
- else if (n1 == LASHeader::ePointFormat3) {
+ else if (n1 == LASHeader::ePointFormat3)
+ {
header.SetDataFormatId(LASHeader::ePointFormat3);
}
- else {
+ else
+ {
throw std::domain_error("invalid point data format");
}
@@ -214,56 +219,50 @@
m_has_pad_bytes = false;
m_ifs.seekg(header.GetDataOffset(), std::ios::beg);
- try {
+ 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::out_of_range const& e)
+ catch (std::out_of_range const&)
{
// Ignore the out_of_range here for the case of a
// file with just a header and no pad
}
- catch (std::runtime_error const& e)
+ catch (std::runtime_error const&)
{
// Ignore the runtime_error here for the case of a
// file with just a header and no pad
// This is what is thrown when we compile *without* debug
}
- catch (std::domain_error const& e)
+ catch (std::domain_error const&)
{
+ // 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;
}
bool ReaderImpl::ReadNextPoint(LASPoint& point, const LASHeader& header)
{
- // Read point data record format 0
-
- // TODO: Replace with compile-time assert
-
- double t = 0;
- detail::PointRecord record;
- assert(LASHeader::ePointSize0 == sizeof(record));
-
if (0 == m_current)
{
m_ifs.clear();
m_ifs.seekg(m_offset, std::ios::beg);
- try {
+ try
+ {
// If this call succeeds, we'll want to put this on the
- // validation errors stack. 1.1 files shouldn't have
- // pad bytes.
+ // validation errors stack. 1.1 files shouldn't have pad bytes.
SkipPointDataSignature();
}
- catch (std::domain_error const& e)
+ catch (std::domain_error const&)
{
m_ifs.seekg(m_offset, std::ios::beg);
}
@@ -271,6 +270,10 @@
if (m_current < m_size)
{
+ detail::PointRecord record;
+ // TODO: Replace with compile-time assert
+ assert(LASHeader::ePointSize0 == sizeof(record));
+
try
{
detail::read_n(record, m_ifs, sizeof(PointRecord));
@@ -285,9 +288,11 @@
Reader::FillPoint(record, point);
point.SetCoordinates(header, point.GetX(), point.GetY(), point.GetZ());
- if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
- detail::read_n(t, m_ifs, sizeof(double));
- point.SetTime(t);
+ if (header.GetDataFormatId() == LASHeader::ePointFormat1)
+ {
+ double gpst = 0;
+ detail::read_n(gpst, m_ifs, sizeof(double));
+ point.SetTime(gpst);
}
return true;
}
@@ -298,35 +303,38 @@
bool ReaderImpl::ReadPointAt(std::size_t n, LASPoint& point, const LASHeader& header)
{
- // Read point data record format 0
-
- // TODO: Replace with compile-time assert
-
- double t = 0;
- detail::PointRecord record;
- assert(LASHeader::ePointSize0 == sizeof(record));
-
if (m_size <= n)
+ {
return false;
+ }
std::streamsize pos = (static_cast<std::streamsize>(n) * m_recordlength) + m_offset;
- if (m_has_pad_bytes) pos += 2;
-
+ if (m_has_pad_bytes)
+ {
+ pos += 2;
+ }
m_ifs.clear();
m_ifs.seekg(pos, std::ios::beg);
+
+ detail::PointRecord record;
+ // TODO: Replace with compile-time assert
+ assert(LASHeader::ePointSize0 == sizeof(record));
+
detail::read_n(record, m_ifs, sizeof(record));
Reader::FillPoint(record, point);
point.SetCoordinates(header, point.GetX(), point.GetY(), point.GetZ());
- if (header.GetDataFormatId() == LASHeader::ePointFormat1) {
- detail::read_n(t, m_ifs, sizeof(double));
- point.SetTime(t);
+ if (header.GetDataFormatId() == LASHeader::ePointFormat1)
+ {
+ double gpst = 0;
+ detail::read_n(gpst, m_ifs, sizeof(double));
+ point.SetTime(gpst);
}
+
return true;
}
-
}}} // namespace liblas::detail::v11
Modified: trunk/src/detail/reader12.cpp
==============================================================================
--- trunk/src/detail/reader12.cpp (original)
+++ trunk/src/detail/reader12.cpp Wed Apr 15 10:27:05 2009
@@ -220,62 +220,51 @@
m_has_pad_bytes = false;
m_ifs.seekg(header.GetDataOffset(), std::ios::beg);
- try {
+ try
+ {
// If this call succeeds, we'll want to put this on the
- // validation errors stack. 1.2 files shouldn't have
- // pad bytes.
+ // validation errors stack. 1.2 files shouldn't have pad bytes.
SkipPointDataSignature();
m_has_pad_bytes = true;
}
- catch (std::out_of_range const& e)
+ catch (std::out_of_range const&)
{
// Ignore the out_of_range here for the case of a
// file with just a header and no pad
// This is what is thrown when we compile *with* debug
}
- catch (std::runtime_error const& e)
+ catch (std::runtime_error const&)
{
// Ignore the runtime_error here for the case of a
// file with just a header and no pad
// This is what is thrown when we compile *without* debug
}
- catch (std::domain_error const& e)
+ catch (std::domain_error const&)
{
+ // 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;
}
bool ReaderImpl::ReadNextPoint(LASPoint& point, LASHeader const& header)
{
- // Read point data record format 0
-
- // TODO: Replace with compile-time assert
-
- double t = 0;
- uint16_t red = 0;
- uint16_t blue = 0;
- uint16_t green = 0;
- LASColor color;
-
- detail::PointRecord record;
- assert(LASHeader::ePointSize0 == sizeof(record));
-
if (0 == m_current)
{
m_ifs.clear();
m_ifs.seekg(m_offset, std::ios::beg);
- try {
+ 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)
+ catch (std::domain_error const&)
{
m_ifs.seekg(m_offset, std::ios::beg);
}
@@ -283,6 +272,10 @@
if (m_current < m_size)
{
+ detail::PointRecord record;
+ // TODO: Replace with compile-time assert
+ assert(LASHeader::ePointSize0 == sizeof(record));
+
try
{
detail::read_n(record, m_ifs, sizeof(PointRecord));
@@ -297,31 +290,35 @@
Reader::FillPoint(record, point);
point.SetCoordinates(header, point.GetX(), point.GetY(), point.GetZ());
+ double gpst = 0;
+ uint16_t red = 0;
+ uint16_t blue = 0;
+ uint16_t green = 0;
+
if (header.GetDataFormatId() == LASHeader::ePointFormat1)
{
- detail::read_n(t, m_ifs, sizeof(double));
- point.SetTime(t);
+ detail::read_n(gpst, m_ifs, sizeof(double));
+ point.SetTime(gpst);
}
else if (header.GetDataFormatId() == LASHeader::ePointFormat2)
{
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));
- color.SetRed(red);
- color.SetBlue(blue);
- color.SetGreen(green);
+
+ LASColor color(red, green, blue);
point.SetColor(color);
}
else if (header.GetDataFormatId() == LASHeader::ePointFormat3)
{
- detail::read_n(t, m_ifs, sizeof(double));
- point.SetTime(t);
+ detail::read_n(gpst, m_ifs, sizeof(double));
+ point.SetTime(gpst);
+
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));
- color.SetRed(red);
- color.SetBlue(blue);
- color.SetGreen(green);
+
+ LASColor color(red, green, blue);
point.SetColor(color);
}
More information about the Liblas-commits
mailing list