[Liblas-commits] hg-main-tree: turn on native zip reading
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed May 11 20:05:46 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/93243578a99c
changeset: 718:93243578a99c
user: Michael P. Gerlek <mpg at flaxen.com>
date: Wed May 11 16:58:42 2011 -0700
description:
turn on native zip reading
Subject: hg-main-tree: strengthen seek/skip tests
details: http://hg.libpc.orghg-main-tree/rev/825756f7b2a6
changeset: 719:825756f7b2a6
user: Michael P. Gerlek <mpg at flaxen.com>
date: Wed May 11 17:05:37 2011 -0700
description:
strengthen seek/skip tests
diffstat:
include/libpc/drivers/las/Iterator.hpp | 38 ++++++-
include/libpc/drivers/las/Reader.hpp | 6 +-
src/drivers/las/Iterator.cpp | 143 +++++++++++++++++++++++++++++---
src/drivers/las/Reader.cpp | 41 +++++++++-
test/unit/LasReaderTest.cpp | 6 +-
test/unit/LiblasReaderTest.cpp | 4 +
6 files changed, 210 insertions(+), 28 deletions(-)
diffs (truncated from 478 to 300 lines):
diff -r 1c1b3de6f1a0 -r 825756f7b2a6 include/libpc/drivers/las/Iterator.hpp
--- a/include/libpc/drivers/las/Iterator.hpp Wed May 11 16:06:55 2011 -0700
+++ b/include/libpc/drivers/las/Iterator.hpp Wed May 11 17:05:37 2011 -0700
@@ -40,12 +40,40 @@
#include <libpc/Iterator.hpp>
#include <iosfwd>
+class LASzip;
+class LASunzipper;
namespace libpc { namespace drivers { namespace las {
class LasReader;
+class ZipPoint;
-class SequentialIterator : public libpc::SequentialIterator
+
+class IteratorBase
+{
+public:
+ IteratorBase(const LasReader& reader);
+ ~IteratorBase();
+
+private:
+ void initializeZip();
+
+protected:
+ const LasReader& m_reader;
+ std::istream* m_istream;
+
+public:
+ LASzip* m_zip;
+ LASunzipper* m_unzipper;
+ ZipPoint* m_zipPoint;
+
+private:
+ IteratorBase& operator=(const IteratorBase&); // not implemented
+ IteratorBase(const IteratorBase&); // not implemented
+};
+
+
+class SequentialIterator : public IteratorBase, public libpc::SequentialIterator
{
public:
SequentialIterator(const LasReader& reader);
@@ -55,13 +83,10 @@
boost::uint64_t skipImpl(boost::uint64_t);
boost::uint32_t readImpl(PointBuffer&);
bool atEndImpl() const;
-
- const LasReader& m_reader;
- std::istream* m_istream;
};
-class RandomIterator : public libpc::RandomIterator
+class RandomIterator : public IteratorBase, public libpc::RandomIterator
{
public:
RandomIterator(const LasReader& reader);
@@ -70,9 +95,6 @@
private:
boost::uint64_t seekImpl(boost::uint64_t);
boost::uint32_t readImpl(PointBuffer&);
-
- const LasReader& m_reader;
- std::istream* m_istream;
};
} } } // namespaces
diff -r 1c1b3de6f1a0 -r 825756f7b2a6 include/libpc/drivers/las/Reader.hpp
--- a/include/libpc/drivers/las/Reader.hpp Wed May 11 16:06:55 2011 -0700
+++ b/include/libpc/drivers/las/Reader.hpp Wed May 11 17:05:37 2011 -0700
@@ -41,6 +41,7 @@
#include <libpc/drivers/las/Header.hpp>
#include <libpc/drivers/las/ReaderBase.hpp>
+class LASunzipper;
namespace libpc
{
@@ -50,6 +51,7 @@
namespace libpc { namespace drivers { namespace las {
class LasHeader;
+class ZipPoint;
class LIBPC_DLL LasReader : public LasReaderBase
{
@@ -73,7 +75,7 @@
libpc::RandomIterator* createRandomIterator() const;
// this is called by the stage's iterator
- boost::uint32_t processBuffer(PointBuffer& PointBuffer, std::istream& stream, boost::uint64_t numPointsLeft) const;
+ boost::uint32_t processBuffer(PointBuffer& PointBuffer, std::istream& stream, boost::uint64_t numPointsLeft, LASunzipper* unzipper, ZipPoint* zipPoint) const;
int getMetadataRecordCount() const;
const MetadataRecord& getMetadataRecord(int index) const;
@@ -87,6 +89,8 @@
// we shouldn't have to expose this
const std::vector<VariableLengthRecord>& getVLRs() const;
+ bool isCompressed() const;
+
protected:
const LasHeader& getLasHeader() const { return m_lasHeader; }
LasHeader& getLasHeaderRef() { return m_lasHeader; }
diff -r 1c1b3de6f1a0 -r 825756f7b2a6 src/drivers/las/Iterator.cpp
--- a/src/drivers/las/Iterator.cpp Wed May 11 16:06:55 2011 -0700
+++ b/src/drivers/las/Iterator.cpp Wed May 11 17:05:37 2011 -0700
@@ -36,6 +36,9 @@
#include <iostream>
+#include "ZipPoint.hpp"
+#include <laszip/lasunzipper.hpp>
+
#include <libpc/drivers/las/Reader.hpp>
#include <libpc/exceptions.hpp>
#include <libpc/Utils.hpp>
@@ -44,28 +47,133 @@
namespace libpc { namespace drivers { namespace las {
-SequentialIterator::SequentialIterator(const LasReader& reader)
- : libpc::SequentialIterator(reader)
- , m_reader(reader)
+IteratorBase::IteratorBase(const LasReader& reader)
+ : m_reader(reader)
, m_istream(NULL)
+ , m_zip(NULL)
+ , m_unzipper(NULL)
+ , m_zipPoint(NULL)
{
m_istream = Utils::openFile(m_reader.getFileName());
m_istream->seekg(m_reader.getPointDataOffset());
+
+ if (m_reader.isCompressed())
+ {
+ initializeZip();
+ }
+
return;
}
-SequentialIterator::~SequentialIterator()
+IteratorBase::~IteratorBase()
{
+ delete m_unzipper;
+ delete m_zip;
+ delete m_zipPoint;
Utils::closeFile(m_istream);
+}
+
+
+void IteratorBase::initializeZip()
+{
+ try
+ {
+ m_zip = new LASzip();
+ }
+ catch(...)
+ {
+ throw libpc_error("Failed to open laszip compression core (1)");
+ }
+
+ PointFormat format = m_reader.getPointFormat();
+ delete m_zipPoint;
+ m_zipPoint = new ZipPoint(format, m_reader.getVLRs());
+
+ bool ok = false;
+ try
+ {
+ ok = m_zip->setup((unsigned char)format, (unsigned short)m_reader.getPointDataOffset());
+ }
+ catch(...)
+ {
+ throw libpc_error("Error opening compression core (3)");
+ }
+ if (!ok)
+ {
+ throw libpc_error("Error opening compression core (2)");
+ }
+
+ try
+ {
+
+ ok = m_zip->unpack(m_zipPoint->our_vlr_data, m_zipPoint->our_vlr_num);
+ }
+ catch(...)
+ {
+ throw libpc_error("Failed to open laszip compression core (2)");
+ }
+ if (!ok)
+ {
+ throw libpc_error("Failed to open laszip compression core (3)");
+ }
+
+ if (!m_unzipper)
+ {
+ try
+ {
+ m_unzipper = new LASunzipper();
+ }
+ catch(...)
+ {
+ throw libpc_error("Failed to open laszip decompression engine (1)");
+ }
+
+ unsigned int stat = 1;
+ try
+ {
+ m_istream->seekg(m_reader.getPointDataOffset(), std::ios::beg);
+ stat = m_unzipper->open(*m_istream, m_zip);
+ }
+ catch(...)
+ {
+ throw libpc_error("Failed to open laszip decompression engine (2)");
+ }
+ if (stat != 0)
+ {
+ throw libpc_error("Failed to open laszip decompression engine (3)");
+ }
+ }
+
return;
}
+SequentialIterator::SequentialIterator(const LasReader& reader)
+ : IteratorBase(reader)
+ , libpc::SequentialIterator(reader)
+{
+ return;
+}
+
+
+SequentialIterator::~SequentialIterator()
+{
+ return;
+}
+
+
boost::uint64_t SequentialIterator::skipImpl(boost::uint64_t count)
{
- boost::uint64_t delta = Support::getPointDataSize(m_reader.getPointFormat());
- m_istream->seekg(delta * count, std::ios::cur);
+ if (m_zip)
+ {
+ m_unzipper->seek(getIndex() + count);
+ }
+ else
+ {
+ boost::uint64_t delta = Support::getPointDataSize(m_reader.getPointFormat());
+ m_istream->seekg(delta * count, std::ios::cur);
+ }
return count;
}
@@ -78,40 +186,43 @@
boost::uint32_t SequentialIterator::readImpl(PointBuffer& data)
{
- return m_reader.processBuffer(data, *m_istream, getStage().getNumPoints()-this->getIndex());
+ return m_reader.processBuffer(data, *m_istream, getStage().getNumPoints()-this->getIndex(), m_unzipper, m_zipPoint);
}
RandomIterator::RandomIterator(const LasReader& reader)
- : libpc::RandomIterator(reader)
- , m_reader(reader)
- , m_istream(NULL)
+ : IteratorBase(reader)
+ , libpc::RandomIterator(reader)
{
- m_istream = Utils::openFile(m_reader.getFileName());
- m_istream->seekg(m_reader.getPointDataOffset());
return;
}
RandomIterator::~RandomIterator()
{
- Utils::closeFile(m_istream);
return;
}
boost::uint64_t RandomIterator::seekImpl(boost::uint64_t count)
{
- boost::uint64_t delta = Support::getPointDataSize(m_reader.getPointFormat());
- m_istream->seekg(m_reader.getPointDataOffset() + delta * count);
+ if (m_zip)
+ {
+ m_unzipper->seek(count);
+ }
+ else
+ {
More information about the Liblas-commits
mailing list