[Liblas-commits] hg-main-tree: add VLR support to liblas reader
liblas-commits at liblas.org
liblas-commits at liblas.org
Thu Apr 21 16:04:03 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/43b6218838a2
changeset: 611:43b6218838a2
user: Michael P. Gerlek <mpg at flaxen.com>
date: Thu Apr 21 13:03:56 2011 -0700
description:
add VLR support to liblas reader
diffstat:
include/libpc/drivers/las/Reader.hpp | 3 +-
include/libpc/drivers/las/ReaderBase.hpp | 64 ++++++++++++++++++++++
include/libpc/drivers/las/VariableLengthRecord.hpp | 17 +++--
include/libpc/drivers/liblas/Reader.hpp | 12 +++-
src/CMakeLists.txt | 1 +
src/drivers/las/LasHeaderReader.cpp | 2 +-
src/drivers/las/Reader.cpp | 2 +-
src/drivers/las/VariableLengthRecord.cpp | 18 +++--
src/drivers/liblas/Reader.cpp | 50 ++++++++++++++++-
test/unit/LiblasReaderTest.cpp | 10 +++
10 files changed, 158 insertions(+), 21 deletions(-)
diffs (truncated from 373 to 300 lines):
diff -r 7115cf9d8b9b -r 43b6218838a2 include/libpc/drivers/las/Reader.hpp
--- a/include/libpc/drivers/las/Reader.hpp Thu Apr 21 12:06:35 2011 -0700
+++ b/include/libpc/drivers/las/Reader.hpp Thu Apr 21 13:03:56 2011 -0700
@@ -39,6 +39,7 @@
#include <libpc/Stage.hpp>
#include <libpc/drivers/las/Header.hpp>
+#include <libpc/drivers/las/ReaderBase.hpp>
namespace libpc
@@ -50,7 +51,7 @@
class LasHeader;
-class LIBPC_DLL LasReader : public Stage
+class LIBPC_DLL LasReader : public LasReaderBase
{
public:
LasReader(const std::string& filename);
diff -r 7115cf9d8b9b -r 43b6218838a2 include/libpc/drivers/las/ReaderBase.hpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/include/libpc/drivers/las/ReaderBase.hpp Thu Apr 21 13:03:56 2011 -0700
@@ -0,0 +1,64 @@
+/******************************************************************************
+* Copyright (c) 2011, Michael P. Gerlek (mpg at flaxen.com)
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following
+* conditions are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in
+* the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
+* names of its contributors may be used to endorse or promote
+* products derived from this software without specific prior
+* written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+* OF SUCH DAMAGE.
+****************************************************************************/
+
+#ifndef INCLUDED_DRIVERS_LAS_READERBASE_HPP
+#define INCLUDED_DRIVERS_LAS_READERBASE_HPP
+
+#include <libpc/libpc.hpp>
+
+#include <libpc/Stage.hpp>
+
+
+namespace libpc { namespace drivers { namespace las {
+
+
+// this class gives the interfaces for the LAS-specific header data access functions -- we use
+// this to make sure that the native las and liblas readers both have the same API
+class LIBPC_DLL LasReaderBase: public Stage
+{
+public:
+ LasReaderBase() : Stage() {}
+
+ virtual int getMetadataRecordCount() const = 0;
+ virtual const MetadataRecord& getMetadataRecord(int index) const = 0;
+
+ virtual PointFormat getPointFormat() const = 0;
+ virtual boost::uint8_t getVersionMajor() const = 0;
+ virtual boost::uint8_t getVersionMinor() const = 0;
+};
+
+
+} } } // namespaces
+
+#endif
diff -r 7115cf9d8b9b -r 43b6218838a2 include/libpc/drivers/las/VariableLengthRecord.hpp
--- a/include/libpc/drivers/las/VariableLengthRecord.hpp Thu Apr 21 12:06:35 2011 -0700
+++ b/include/libpc/drivers/las/VariableLengthRecord.hpp Thu Apr 21 13:03:56 2011 -0700
@@ -48,14 +48,18 @@
{
public:
// makes a local copy of the bytes buffer, which is a shared ptr among by all copes of the metadata record
- VariableLengthRecord(boost::uint8_t userId[16],
+ VariableLengthRecord(boost::uint16_t reserved,
+ boost::uint8_t* userId, // always 16 bytes
boost::uint16_t recordId,
- boost::uint16_t recordLenAfterHeader,
- boost::uint8_t description[32],
+ boost::uint8_t* description, // always 32 bytes
const boost::uint8_t* bytes, std::size_t len);
VariableLengthRecord(const VariableLengthRecord&);
+ ~VariableLengthRecord();
- ~VariableLengthRecord();
+ boost::uint16_t getReserved() const { return m_reserved; }
+ boost::uint8_t* getUserId() const { return (boost::uint8_t*)m_userId; }
+ boost::uint16_t getRecordId() const { return m_recordId; }
+ boost::uint8_t* getDescription() const { return (boost::uint8_t*)m_description; }
bool operator==(const VariableLengthRecord&) const;
VariableLengthRecord& operator=(const VariableLengthRecord&);
@@ -64,10 +68,9 @@
private:
boost::uint16_t m_reserved;
- boost::uint8_t m_userId[16];
+ boost::uint8_t* m_userId; // always 16 bytes
boost::uint16_t m_recordId;
- boost::uint16_t m_recordLenAfterHeader;
- boost::uint8_t m_description[32];
+ boost::uint8_t* m_description; // always 32 bytes
};
diff -r 7115cf9d8b9b -r 43b6218838a2 include/libpc/drivers/liblas/Reader.hpp
--- a/include/libpc/drivers/liblas/Reader.hpp Thu Apr 21 12:06:35 2011 -0700
+++ b/include/libpc/drivers/liblas/Reader.hpp Thu Apr 21 13:03:56 2011 -0700
@@ -37,9 +37,11 @@
#include <libpc/libpc.hpp>
+#include <vector>
+
#include <libpc/Stage.hpp>
-
#include <libpc/drivers/las/Support.hpp>
+#include <libpc/drivers/las/ReaderBase.hpp>
// fwd decls
namespace liblas
@@ -51,7 +53,7 @@
class LiblasHeader;
-class LIBPC_DLL LiblasReader : public Stage
+class LIBPC_DLL LiblasReader : public libpc::drivers::las::LasReaderBase
{
public:
LiblasReader(const std::string& filename);
@@ -66,6 +68,9 @@
boost::uint8_t getVersionMajor() const;
boost::uint8_t getVersionMinor() const;
+ int LiblasReader::getMetadataRecordCount() const;
+ const MetadataRecord& LiblasReader::getMetadataRecord(int index) const;
+
bool supportsIterator (StageIteratorType t) const
{
if (t == StageIterator_Sequential ) return true;
@@ -80,6 +85,7 @@
private:
void processExternalHeader(::liblas::Reader& externalReader);
void registerFields(::liblas::Reader& externalReader);
+ MetadataRecord& LiblasReader::getMetadataRecordRef(int index);
std::string m_filename;
@@ -96,6 +102,8 @@
::libpc::drivers::las::PointFormat m_pointFormat;
+ std::vector<MetadataRecord> m_metadataRecords;
+
LiblasReader& operator=(const LiblasReader&); // not implemented
LiblasReader(const LiblasReader&); // not implemented
};
diff -r 7115cf9d8b9b -r 43b6218838a2 src/CMakeLists.txt
--- a/src/CMakeLists.txt Thu Apr 21 12:06:35 2011 -0700
+++ b/src/CMakeLists.txt Thu Apr 21 13:03:56 2011 -0700
@@ -118,6 +118,7 @@
${LIBPC_HEADERS_DIR}/drivers/las/Header.hpp
${LIBPC_HEADERS_DIR}/drivers/las/Iterator.hpp
${LIBPC_HEADERS_DIR}/drivers/las/Reader.hpp
+ ${LIBPC_HEADERS_DIR}/drivers/las/ReaderBase.hpp
${LIBPC_HEADERS_DIR}/drivers/las/SummaryData.hpp
${LIBPC_HEADERS_DIR}/drivers/las/Support.hpp
${LIBPC_HEADERS_DIR}/drivers/las/Writer.hpp
diff -r 7115cf9d8b9b -r 43b6218838a2 src/drivers/las/LasHeaderReader.cpp
--- a/src/drivers/las/LasHeaderReader.cpp Thu Apr 21 12:06:35 2011 -0700
+++ b/src/drivers/las/LasHeaderReader.cpp Thu Apr 21 13:03:56 2011 -0700
@@ -352,7 +352,7 @@
boost::uint8_t* data = new boost::uint8_t[recordLenAfterHeader];
Utils::read_n(data, m_istream, recordLenAfterHeader);
- VariableLengthRecord vlr(userId, recordId, recordLenAfterHeader, description, data, recordLenAfterHeader);
+ VariableLengthRecord vlr(reserved, userId, recordId, description, data, recordLenAfterHeader);
m_header.getVLRsRef().push_back(vlr);
diff -r 7115cf9d8b9b -r 43b6218838a2 src/drivers/las/Reader.cpp
--- a/src/drivers/las/Reader.cpp Thu Apr 21 12:06:35 2011 -0700
+++ b/src/drivers/las/Reader.cpp Thu Apr 21 13:03:56 2011 -0700
@@ -45,7 +45,7 @@
LasReader::LasReader(const std::string& filename)
- : Stage()
+ : LasReaderBase()
, m_filename(filename)
{
std::istream* str = Utils::openFile(m_filename);
diff -r 7115cf9d8b9b -r 43b6218838a2 src/drivers/las/VariableLengthRecord.cpp
--- a/src/drivers/las/VariableLengthRecord.cpp Thu Apr 21 12:06:35 2011 -0700
+++ b/src/drivers/las/VariableLengthRecord.cpp Thu Apr 21 13:03:56 2011 -0700
@@ -39,17 +39,18 @@
namespace libpc { namespace drivers { namespace las {
-VariableLengthRecord::VariableLengthRecord(boost::uint8_t userId[16],
+VariableLengthRecord::VariableLengthRecord(boost::uint16_t reserved,
+ boost::uint8_t* userId,
boost::uint16_t recordId,
- boost::uint16_t recordLenAfterHeader,
- boost::uint8_t description[32],
+ boost::uint8_t* description,
const boost::uint8_t* bytes, std::size_t len)
: MetadataRecord(bytes, len)
- , m_reserved(0)
+ , m_reserved(reserved)
, m_recordId(recordId)
- , m_recordLenAfterHeader(recordLenAfterHeader)
{
+ m_userId = new boost::uint8_t[16];
memcpy(m_userId, userId, 16);
+ m_description = new boost::uint8_t[32];
memcpy(m_description, description, 32);
return;
}
@@ -59,9 +60,10 @@
: MetadataRecord(vlr)
, m_reserved(vlr.m_reserved)
, m_recordId(vlr.m_recordId)
- , m_recordLenAfterHeader(vlr.m_recordLenAfterHeader)
{
+ m_userId = new boost::uint8_t[16];
memcpy(m_userId, vlr.m_userId, 16);
+ m_description = new boost::uint8_t[32];
memcpy(m_description, vlr.m_description, 32);
return;
}
@@ -69,6 +71,8 @@
VariableLengthRecord::~VariableLengthRecord()
{
+ delete[] m_userId;
+ delete[] m_description;
return;
}
@@ -79,7 +83,6 @@
m_reserved = vlr.m_reserved;
m_recordId = vlr.m_recordId;
- m_recordLenAfterHeader = vlr.m_recordLenAfterHeader;
memcpy(m_userId, vlr.m_userId, 16);
memcpy(m_description, vlr.m_description, 32);
@@ -92,7 +95,6 @@
{
if (m_reserved != vlr.m_reserved) return false;
if (m_recordId != vlr.m_recordId) return false;
- if (m_recordLenAfterHeader != vlr.m_recordLenAfterHeader) return false;
for (int i=0; i<16; i++)
if (m_userId[i] != vlr.m_userId[i]) return false;
diff -r 7115cf9d8b9b -r 43b6218838a2 src/drivers/liblas/Reader.cpp
--- a/src/drivers/liblas/Reader.cpp Thu Apr 21 12:06:35 2011 -0700
+++ b/src/drivers/liblas/Reader.cpp Thu Apr 21 13:03:56 2011 -0700
@@ -35,14 +35,17 @@
#include <libpc/drivers/liblas/Reader.hpp>
#include <liblas/factory.hpp>
+#include <liblas/variablerecord.hpp>
#include <libpc/exceptions.hpp>
#include <libpc/drivers/liblas/Iterator.hpp>
+#include <libpc/drivers/las/VariableLengthRecord.hpp>
+
namespace libpc { namespace drivers { namespace liblas {
LiblasReader::LiblasReader(const std::string& filename)
- : Stage()
+ : LasReaderBase()
, m_filename(filename)
, m_versionMajor(0)
, m_versionMinor(0)
More information about the Liblas-commits
mailing list