[Liblas-commits] hg-main-tree: start to add native LAZ support

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Apr 15 23:21:18 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/78997149b0cf
changeset: 590:78997149b0cf
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Apr 15 20:21:11 2011 -0700
description:
start to add native LAZ support

diffstat:

 include/libpc/Writer.hpp             |    1 +
 include/libpc/drivers/las/Writer.hpp |    7 +
 src/CMakeLists.txt                   |    2 +
 src/drivers/las/Writer.cpp           |   75 ++++++++-
 src/drivers/las/ZipPoint.cpp         |  288 +++++++++++++++++++++++++++++++++++
 src/drivers/las/ZipPoint.hpp         |   76 +++++++++
 test/unit/LasWriterTest.cpp          |   72 ++++----
 7 files changed, 484 insertions(+), 37 deletions(-)

diffs (truncated from 626 to 300 lines):

diff -r f2f593d38000 -r 78997149b0cf include/libpc/Writer.hpp
--- a/include/libpc/Writer.hpp	Fri Apr 15 17:45:28 2011 -0700
+++ b/include/libpc/Writer.hpp	Fri Apr 15 20:21:11 2011 -0700
@@ -49,6 +49,7 @@
 {
 public:
     Writer(Stage& prevStage);
+    virtual ~Writer() {}
 
     // Implement this in your concrete classes to return a constant string
     // as the name of the stage.  Use upper camel case, with spaces between
diff -r f2f593d38000 -r 78997149b0cf include/libpc/drivers/las/Writer.hpp
--- a/include/libpc/drivers/las/Writer.hpp	Fri Apr 15 17:45:28 2011 -0700
+++ b/include/libpc/drivers/las/Writer.hpp	Fri Apr 15 20:21:11 2011 -0700
@@ -41,13 +41,18 @@
 #include <libpc/drivers/las/Header.hpp>
 #include <libpc/drivers/las/SummaryData.hpp>
 
+// liblaszip
+class LASzipper;
+
 namespace libpc { namespace drivers { namespace las {
 
+class ZipPoint;
 
 class LIBPC_DLL LasWriter : public Writer
 {
 public:
     LasWriter(Stage& prevStage, std::ostream&);
+    ~LasWriter();
 
     const std::string& getName() const;
 
@@ -82,6 +87,8 @@
     boost::uint32_t m_numPointsWritten;
     bool m_isCompressed;
     SummaryData m_summaryData;
+    LASzipper* m_zipper;
+    ZipPoint* m_zipPoint;
 
     LasWriter& operator=(const LasWriter&); // not implemented
     LasWriter(const LasWriter&); // not implemented
diff -r f2f593d38000 -r 78997149b0cf src/CMakeLists.txt
--- a/src/CMakeLists.txt	Fri Apr 15 17:45:28 2011 -0700
+++ b/src/CMakeLists.txt	Fri Apr 15 20:21:11 2011 -0700
@@ -114,6 +114,7 @@
 set (LIBPC_DRIVERS_LAS_HPP
   ./drivers/las/LasHeaderReader.hpp
   ./drivers/las/LasHeaderWriter.hpp
+  ./drivers/las/ZipPoint.hpp
   ${LIBPC_HEADERS_DIR}/drivers/las/Header.hpp
   ${LIBPC_HEADERS_DIR}/drivers/las/Iterator.hpp
   ${LIBPC_HEADERS_DIR}/drivers/las/Reader.hpp
@@ -131,6 +132,7 @@
   ./drivers/las/SummaryData.cpp
   ./drivers/las/Support.cpp
   ./drivers/las/Writer.cpp
+  ./drivers/las/ZipPoint.cpp
 )
   
 FOREACH(file ${LIBPC_DRIVERS_LAS_HPP})
diff -r f2f593d38000 -r 78997149b0cf src/drivers/las/Writer.cpp
--- a/src/drivers/las/Writer.cpp	Fri Apr 15 17:45:28 2011 -0700
+++ b/src/drivers/las/Writer.cpp	Fri Apr 15 20:21:11 2011 -0700
@@ -35,6 +35,13 @@
 #include <libpc/drivers/las/Writer.hpp>
 
 #include "LasHeaderWriter.hpp"
+
+// local
+#include "ZipPoint.hpp"
+
+// laszip
+#include <laszip/laszipper.hpp>
+
 #include <libpc/exceptions.hpp>
 #include <libpc/Stage.hpp>
 #include <libpc/SchemaLayout.hpp>
@@ -51,11 +58,20 @@
     , m_ostream(ostream)
     , m_numPointsWritten(0)
     , m_isCompressed(false)
+    , m_zipper(NULL)
+    , m_zipPoint(NULL)
 {
     return;
 }
 
 
+LasWriter::~LasWriter()
+{
+    delete m_zipper;
+    delete m_zipPoint;
+}
+
+
 const std::string& LasWriter::getName() const
 {
     static std::string name("Las Writer");
@@ -136,6 +152,50 @@
 
     m_summaryData.reset();
 
+    if (m_lasHeader.Compressed())
+    {
+        delete m_zipper;
+        delete m_zipPoint;
+        m_zipper = NULL;
+        m_zipPoint = NULL;
+
+        try
+        {
+            m_zipper = new LASzipper();
+        }
+        catch(...)
+        {
+            delete m_zipper;
+            m_zipper = NULL;
+            throw libpc_error("Error opening compression engine (1)");
+        }
+
+        PointFormat format = m_lasHeader.getPointFormat();
+        m_zipPoint = new ZipPoint(format);
+
+        unsigned int stat = 1;
+        try
+        {
+            stat = m_zipper->open(m_ostream, m_zipPoint->m_num_items, m_zipPoint->m_items, LASzip::DEFAULT_COMPRESSION);
+        }
+        catch(...)
+        {
+            delete m_zipper;
+            delete m_zipPoint;
+            m_zipper = NULL;
+            m_zipPoint = NULL;
+            throw libpc_error("Error opening compression engine (3)");
+        }
+        if (stat != 0)
+        {
+            delete m_zipper;
+            delete m_zipPoint;
+            m_zipper = NULL;
+            m_zipPoint = NULL;
+            throw libpc_error("Error opening compression engine (2)");
+        }
+    }
+
     return;
 }
 
@@ -218,7 +278,20 @@
             Utils::write_field<boost::uint16_t>(p, blue);
         }
 
-        Utils::write_n(m_ostream, buf, Support::getPointDataSize(pointFormat));
+        if (m_zipPoint)
+        {
+            for (unsigned int i=0; i<m_zipPoint->m_lz_point_size; i++)
+            {
+                m_zipPoint->m_lz_point_data[i] = buf[i];
+                //printf("%d %d\n", v[i], i);
+            }
+            bool ok = m_zipper->write(m_zipPoint->m_lz_point);
+            assert(ok);
+        }
+        else
+        {
+            Utils::write_n(m_ostream, buf, Support::getPointDataSize(pointFormat));
+        }
 
         ++numValidPoints;
 
diff -r f2f593d38000 -r 78997149b0cf src/drivers/las/ZipPoint.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/drivers/las/ZipPoint.cpp	Fri Apr 15 20:21:11 2011 -0700
@@ -0,0 +1,288 @@
+/******************************************************************************
+* 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.
+****************************************************************************/
+
+#include <libpc/libpc.hpp>
+
+#ifdef LIBPC_HAVE_LASZIP
+
+#include "ZipPoint.hpp"
+
+#include <libpc/exceptions.hpp>
+
+// laszip
+#include <laszip/laszip.hpp>
+
+// std
+//#include <vector>
+//#include <fstream>
+//#include <stdexcept>
+//#include <cstdlib> // std::size_t
+//#include <cassert>
+
+namespace libpc { namespace drivers { namespace las {
+
+static std::string laszip_userid("laszip encoded");
+static boost::uint16_t laszip_recordid = 22204;
+static std::string laszip_description = "encoded for sequential access";
+
+
+ZipPoint::ZipPoint(PointFormat format) :
+    m_num_items(0),
+    m_items(NULL),
+    m_lz_point(NULL),
+    m_lz_point_data(NULL),
+    m_lz_point_size(0)
+{
+    ConstructItems(format);
+    return;
+}
+
+ZipPoint::~ZipPoint()
+{
+    m_num_items = 0;
+    delete[] m_items;
+    m_items = NULL;
+
+    delete[] m_lz_point;
+    delete[] m_lz_point_data;
+
+    return;
+}
+
+void ZipPoint::ConstructItems(PointFormat format)
+{
+    switch (format)
+    {
+    case PointFormat0:
+        m_num_items = 1;
+        m_items = new LASitem[1];
+        m_items[0].set(LASitem::POINT10);
+        break;
+
+    case PointFormat1:
+        m_num_items = 2;
+        m_items = new LASitem[2];
+        m_items[0].set(LASitem::POINT10);
+        m_items[1].set(LASitem::GPSTIME11);
+        break;
+
+    case PointFormat2:
+        m_num_items = 2;
+        m_items = new LASitem[2];
+        m_items[0].set(LASitem::POINT10);
+        m_items[1].set(LASitem::RGB12);
+        break;
+
+    case PointFormat3:
+        m_num_items = 3;
+        m_items = new LASitem[3];
+        m_items[0].set(LASitem::POINT10);
+        m_items[1].set(LASitem::GPSTIME11);
+        m_items[2].set(LASitem::RGB12);
+        break;
+
+    case PointFormat4:
+        m_num_items = 3;
+        m_items = new LASitem[3];
+        m_items[0].set(LASitem::POINT10);
+        m_items[1].set(LASitem::GPSTIME11);
+        m_items[2].set(LASitem::WAVEPACKET13);
+        break;
+
+    default:
+        throw libpc_error("Bad point format in header"); 


More information about the Liblas-commits mailing list