[Liblas-commits] hg-main-tree: make build (but not yet run correctly) with laszip...

liblas-commits at liblas.org liblas-commits at liblas.org
Wed May 11 15:20:33 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/94d95d2a8197
changeset: 711:94d95d2a8197
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Wed May 11 12:19:54 2011 -0700
description:
make build (but not yet run correctly) with laszip/liblas changes

diffstat:

 include/libpc/drivers/las/Writer.hpp |    2 +
 src/drivers/las/LasHeaderWriter.cpp  |    4 +-
 src/drivers/las/Writer.cpp           |  108 +++++++++++++++++------
 src/drivers/las/ZipPoint.cpp         |  160 +++++++++++++++++-----------------
 src/drivers/las/ZipPoint.hpp         |   11 +-
 5 files changed, 173 insertions(+), 112 deletions(-)

diffs (truncated from 420 to 300 lines):

diff -r 9f91166cbf42 -r 94d95d2a8197 include/libpc/drivers/las/Writer.hpp
--- a/include/libpc/drivers/las/Writer.hpp	Wed May 11 12:05:38 2011 -0500
+++ b/include/libpc/drivers/las/Writer.hpp	Wed May 11 12:19:54 2011 -0700
@@ -42,6 +42,7 @@
 #include <libpc/drivers/las/SummaryData.hpp>
 
 // liblaszip
+class LASzip;
 class LASzipper;
 
 namespace libpc { namespace drivers { namespace las {
@@ -90,6 +91,7 @@
     boost::uint32_t m_numPointsWritten;
     bool m_isCompressed;
     SummaryData m_summaryData;
+    LASzip* m_zip;
     LASzipper* m_zipper;
     ZipPoint* m_zipPoint;
     SpatialReference m_spatialReference;
diff -r 9f91166cbf42 -r 94d95d2a8197 src/drivers/las/LasHeaderWriter.cpp
--- a/src/drivers/las/LasHeaderWriter.cpp	Wed May 11 12:05:38 2011 -0500
+++ b/src/drivers/las/LasHeaderWriter.cpp	Wed May 11 12:19:54 2011 -0700
@@ -116,8 +116,8 @@
         if (m_header.Compressed())
         {
 #ifdef LIBPC_HAVE_LASZIP
-            ZipPoint zpd(m_header.getPointFormat());
-            VariableLengthRecord v = zpd.ConstructVLR();
+            ZipPoint zpd(m_header.getPointFormat(), m_header.getVLRs().getAll());
+            VariableLengthRecord v = zpd.ConstructVLR(m_header.getPointFormat());
             m_header.getVLRs().add(v);
 #else
             throw configuration_error("LASzip compression support not enabled in this libLAS configuration.");
diff -r 9f91166cbf42 -r 94d95d2a8197 src/drivers/las/Writer.cpp
--- a/src/drivers/las/Writer.cpp	Wed May 11 12:05:38 2011 -0500
+++ b/src/drivers/las/Writer.cpp	Wed May 11 12:19:54 2011 -0700
@@ -57,6 +57,7 @@
     , m_ostream(ostream)
     , m_numPointsWritten(0)
     , m_isCompressed(false)
+    , m_zip(NULL)
     , m_zipper(NULL)
     , m_zipPoint(NULL)
 {
@@ -70,6 +71,7 @@
 {
     delete m_zipper;
     delete m_zipPoint;
+    delete m_zip;
 }
 
 
@@ -174,40 +176,86 @@
         m_zipper = NULL;
         m_zipPoint = NULL;
 
-        try
+        if (m_zip==NULL)
         {
-            m_zipper = new LASzipper();
-        }
-        catch(...)
-        {
-            delete m_zipper;
-            m_zipper = NULL;
-            throw libpc_error("Error opening compression engine (1)");
+            try
+            {
+                m_zip = new LASzip();
+            }
+            catch(...)
+            {
+                throw libpc_error("Error opening compression core (1)");
+            }
+
+            PointFormat format = m_lasHeader.getPointFormat();
+            delete m_zipPoint;
+            m_zipPoint = new ZipPoint(format, m_lasHeader.getVLRs().getAll());
+
+            bool ok = false;
+            try
+            {
+                ok = m_zip->setup((unsigned char)format, m_lasHeader.GetDataRecordLength());
+            }
+            catch(...)
+            {
+                throw libpc_error("Error opening compression core (3)");
+            }
+            if (!ok)
+            {
+                throw libpc_error("Error opening compression core (2)");
+            }
+
+            try
+            {
+                ok = m_zip->pack(m_zipPoint->his_vlr_data, m_zipPoint->his_vlr_num);
+            }
+            catch(...)
+            {
+                throw libpc_error("Error opening compression core (3)");
+            }
+            if (!ok)
+            {
+                throw libpc_error("Error opening compression core (2)");
+            }
         }
 
-        PointFormat format = m_lasHeader.getPointFormat();
-        m_zipPoint = new ZipPoint(format);
+        if (m_zipper == NULL)
+        {
+            try
+            {
+                m_zipper = new LASzipper();
+            }
+            catch(...)
+            {
+                delete m_zipper;
+                m_zipper = NULL;
+                throw libpc_error("Error opening compression engine (1)");
+            }
 
-        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)");
+            PointFormat format = m_lasHeader.getPointFormat();
+            m_zipPoint = new ZipPoint(format, m_lasHeader.getVLRs().getAll());
+
+            unsigned int stat = 1;
+            try
+            {
+                stat = m_zipper->open(m_ostream, m_zip);
+            }
+            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)");
+            }
         }
     }
 
diff -r 9f91166cbf42 -r 94d95d2a8197 src/drivers/las/ZipPoint.cpp
--- a/src/drivers/las/ZipPoint.cpp	Wed May 11 12:05:38 2011 -0500
+++ b/src/drivers/las/ZipPoint.cpp	Wed May 11 12:19:54 2011 -0700
@@ -38,6 +38,9 @@
 
 #include "ZipPoint.hpp"
 
+#include <laszip/laszip.hpp>
+#include <laszip/laszipper.hpp>
+
 #include <libpc/exceptions.hpp>
 #include <libpc/drivers/las/VariableLengthRecord.hpp>
 #include <string.h>
@@ -60,14 +63,39 @@
 static const char* 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)
+ZipPoint::ZipPoint(PointFormat format, const std::vector<VariableLengthRecord>& vlrs)
+    : his_vlr_num(0)
+    , his_vlr_data(0)
+    , our_vlr_num(0)
+    , our_vlr_data(0)
+    , m_num_items(0)
+    , m_items(NULL)
+    , m_lz_point(NULL)
+    , m_lz_point_data(NULL)
+    , m_lz_point_size(0)
 {
     ConstructItems(format);
+
+    const VariableLengthRecord* vlr = NULL;
+    for (unsigned int i=0; i<vlrs.size(); i++)
+    {
+        const VariableLengthRecord& p = vlrs[i];
+        if (p.getRecordId() == 22204)
+        {
+            vlr = &p;
+            break;
+        }
+    }
+    if (vlr)
+    {
+        our_vlr_num = vlr->getLength();
+        our_vlr_data = new unsigned char[our_vlr_num];
+        for (int i=0; i<our_vlr_num; i++)
+        {
+            our_vlr_data[i] = vlr->getBytes()[i];
+        }
+    }
+
     return;
 }
 
@@ -80,6 +108,8 @@
     delete[] m_lz_point;
     delete[] m_lz_point_data;
 
+    delete[] our_vlr_data;
+
     return;
 }
 
@@ -90,37 +120,37 @@
     case PointFormat0:
         m_num_items = 1;
         m_items = new LASitem[1];
-        m_items[0].set(LASitem::POINT10);
+        m_items[0].type = LASitem::POINT10;
+        m_items[0].size = 20;
         break;
 
     case PointFormat1:
         m_num_items = 2;
         m_items = new LASitem[2];
-        m_items[0].set(LASitem::POINT10);
-        m_items[1].set(LASitem::GPSTIME11);
+        m_items[0].type = LASitem::POINT10;
+        m_items[0].size = 8;
+        m_items[1].type = LASitem::GPSTIME11;
+        m_items[1].size = 8;
         break;
 
     case PointFormat2:
         m_num_items = 2;
         m_items = new LASitem[2];
-        m_items[0].set(LASitem::POINT10);
-        m_items[1].set(LASitem::RGB12);
+        m_items[0].type = LASitem::POINT10;
+        m_items[0].size = 20;
+        m_items[1].type = LASitem::RGB12;
+        m_items[1].size = 6;
         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);
+        m_items[0].type = LASitem::POINT10;
+        m_items[0].size = 20;
+        m_items[1].type = LASitem::GPSTIME11;
+        m_items[1].size = 8;
+        m_items[2].type = LASitem::RGB12;
+        m_items[2].size = 6;
         break;
 
     default:
@@ -148,68 +178,42 @@
 }
 
 
-VariableLengthRecord ZipPoint::ConstructVLR() const
+VariableLengthRecord ZipPoint::ConstructVLR(PointFormat format) const
 {
-    boost::uint16_t record_length_after_header = (boost::uint16_t)(34+6*m_num_items);
-


More information about the Liblas-commits mailing list