[Liblas-commits] hg-main-tree: BOOST_CHECK_EQUAL tells us what the values were

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Aug 5 10:34:41 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/08dde85ca931
changeset: 1012:08dde85ca931
user:      Howard Butler <hobu.inc at gmail.com>
date:      Fri Aug 05 09:34:08 2011 -0500
description:
BOOST_CHECK_EQUAL tells us what the values were
Subject: hg-main-tree: bring the LASzip support up-to-snuff with LASzip 2.0.1+

details:   http://hg.libpc.orghg-main-tree/rev/435254c9c30f
changeset: 1013:435254c9c30f
user:      Howard Butler <hobu.inc at gmail.com>
date:      Fri Aug 05 09:34:30 2011 -0500
description:
bring the LASzip support up-to-snuff with LASzip 2.0.1+

diffstat:

 include/pdal/drivers/las/Iterator.hpp |    2 +-
 src/drivers/las/Header.cpp            |    1 +
 src/drivers/las/Iterator.cpp          |   45 ++-------
 src/drivers/las/LasHeaderWriter.cpp   |   16 +---
 src/drivers/las/Reader.cpp            |    6 +-
 src/drivers/las/Writer.cpp            |   42 +--------
 src/drivers/las/ZipPoint.cpp          |  143 +++++++++------------------------
 src/drivers/las/ZipPoint.hpp          |   25 +++--
 test/unit/Support.cpp                 |    6 +-
 9 files changed, 83 insertions(+), 203 deletions(-)

diffs (truncated from 509 to 300 lines):

diff -r 7a056e7bc4e5 -r 435254c9c30f include/pdal/drivers/las/Iterator.hpp
--- a/include/pdal/drivers/las/Iterator.hpp	Thu Aug 04 16:21:00 2011 -0500
+++ b/include/pdal/drivers/las/Iterator.hpp	Fri Aug 05 09:34:30 2011 -0500
@@ -65,9 +65,9 @@
 
 public:
 #ifdef PDAL_HAVE_LASZIP
-    boost::scoped_ptr<LASzip> m_zip;
     boost::scoped_ptr<ZipPoint> m_zipPoint;
     boost::scoped_ptr<LASunzipper> m_unzipper;
+    std::streampos m_zipReadStartPosition;
 
 #endif
 
diff -r 7a056e7bc4e5 -r 435254c9c30f src/drivers/las/Header.cpp
--- a/src/drivers/las/Header.cpp	Thu Aug 04 16:21:00 2011 -0500
+++ b/src/drivers/las/Header.cpp	Fri Aug 05 09:34:30 2011 -0500
@@ -649,6 +649,7 @@
     ostr << "  LasHeader" << std::endl;
     ostr << "    Header size: " << header.GetHeaderSize() << std::endl;
     ostr << "    Point records count: " << header.GetPointRecordsCount() << std::endl;
+    ostr << "    VLR count: " << header.getVLRs().count() << std::endl;
 
     return ostr;
 }
diff -r 7a056e7bc4e5 -r 435254c9c30f src/drivers/las/Iterator.cpp
--- a/src/drivers/las/Iterator.cpp	Thu Aug 04 16:21:00 2011 -0500
+++ b/src/drivers/las/Iterator.cpp	Fri Aug 05 09:34:30 2011 -0500
@@ -71,7 +71,6 @@
 {
 #ifdef PDAL_HAVE_LASZIP
     m_zipPoint.reset();
-    m_zip.reset();
     m_unzipper.reset();
 #endif
     FileUtils::closeFile(m_istream);
@@ -81,35 +80,11 @@
 void IteratorBase::initializeZip()
 {
 #ifdef PDAL_HAVE_LASZIP
-
-    // Initialize a scoped_ptr and swap it with our member variable 
-    // that will contain it.
-    boost::scoped_ptr<LASzip> s(new LASzip());
-    m_zip.swap(s);
-
-    PointFormat format = m_reader.getPointFormat();
-    
-    boost::scoped_ptr<ZipPoint> z(new ZipPoint(format, m_reader.getVLRs()));
-    m_zipPoint.swap(z);
-
-
-    bool ok = false;
-    ok = m_zip->setup((unsigned char)format, (unsigned short)m_reader.getPointDataOffset());
-
-    if (!ok)
+    if (!m_zipPoint)
     {
-        std::ostringstream oss;
-        oss << "Error setting up compression engine: " << std::string(m_zip->get_error());
-        throw pdal_error(oss.str());
-    }
-
-    ok = m_zip->unpack(m_zipPoint->our_vlr_data, m_zipPoint->our_vlr_num);
-
-    if (!ok)
-    {
-        std::ostringstream oss;
-        oss << "Error unpacking zip VLR data: " << std::string(m_zip->get_error());
-        throw pdal_error(oss.str());
+        PointFormat format = m_reader.getPointFormat();
+        boost::scoped_ptr<ZipPoint> z(new ZipPoint(format, m_reader.getVLRs()));
+        m_zipPoint.swap(z);
     }
 
     if (!m_unzipper)
@@ -119,12 +94,16 @@
 
         bool stat(false);
         m_istream->seekg(m_reader.getPointDataOffset(), std::ios::beg);
-        stat = m_unzipper->open(*m_istream, m_zip.get());
+        stat = m_unzipper->open(*m_istream, m_zipPoint->GetZipper());
 
+        // Martin moves the stream on us 
+        m_zipReadStartPosition = m_istream->tellg();
         if (!stat)
         {
             std::ostringstream oss;
-            oss << "Failed to open LASzip stream: " << std::string(m_zip->get_error());
+            const char* err = m_unzipper->get_error();
+            if (err==NULL) err="(unknown error)";
+            oss << "Failed to open LASzip stream: " << std::string(err);
             throw pdal_error(oss.str());
         }
     }
@@ -162,7 +141,7 @@
 boost::uint64_t SequentialIterator::skipImpl(boost::uint64_t count)
 {
 #ifdef PDAL_HAVE_LASZIP
-    if (m_zip)
+    if (m_unzipper)
     {
         const boost::uint32_t pos32 = safeconvert64to32(getIndex() + count);
         m_unzipper->seek(pos32);
@@ -215,7 +194,7 @@
 boost::uint64_t RandomIterator::seekImpl(boost::uint64_t count)
 {
 #ifdef PDAL_HAVE_LASZIP
-    if (m_zip)
+    if (m_unzipper)
     {
         const boost::uint32_t pos32 = safeconvert64to32(count);
         m_unzipper->seek(pos32);
diff -r 7a056e7bc4e5 -r 435254c9c30f src/drivers/las/LasHeaderWriter.cpp
--- a/src/drivers/las/LasHeaderWriter.cpp	Thu Aug 04 16:21:00 2011 -0500
+++ b/src/drivers/las/LasHeaderWriter.cpp	Fri Aug 05 09:34:30 2011 -0500
@@ -96,20 +96,6 @@
     }
 
     {
-        //// If we have a custom schema, add the VLR and write it into the 
-        //// file.  
-        //if (m_header.GetSchema().IsCustom()) {
-        //    
-        //    // Wipe any schema-related VLRs we might have, as this is now out of date.
-        //    m_header.DeleteVLRs("liblas", 7);
-        //
-        //    VariableRecord v = m_header.GetSchema().GetVLR();
-        //    std::cout <<  m_header.GetSchema()<< std::endl;
-        //    m_header.AddVLR(v);
-        //}
-    }
-    
-    {
         m_header.getVLRs().remove("laszip encoded", 22204);
 
         // add the laszip VLR, if needed
@@ -117,7 +103,7 @@
         {
 #ifdef PDAL_HAVE_LASZIP
             ZipPoint zpd(m_header.getPointFormat(), m_header.getVLRs().getAll());
-            VariableLengthRecord v = zpd.ConstructVLR(m_header.getPointFormat());
+            VariableLengthRecord v = zpd.ConstructVLR();
             m_header.getVLRs().add(v);
 #else
             throw configuration_error("LASzip compression support not enabled in this libLAS configuration.");
diff -r 7a056e7bc4e5 -r 435254c9c30f src/drivers/las/Reader.cpp
--- a/src/drivers/las/Reader.cpp	Thu Aug 04 16:21:00 2011 -0500
+++ b/src/drivers/las/Reader.cpp	Fri Aug 05 09:34:30 2011 -0500
@@ -202,11 +202,13 @@
             if (!ok)
             {
                 std::ostringstream oss;
-                oss << "Error reading compressed point data: " << std::string(unzipper->get_error());
+                const char* err = unzipper->get_error();
+                if (err==NULL) err="(unknown error)";
+                oss << "Error reading compressed point data: " << std::string(err);
                 throw pdal_error(oss.str());
             }
 
-            memcpy(p, zipPoint->m_lz_point_data, zipPoint->m_lz_point_size);
+            memcpy(p, zipPoint->m_lz_point_data.get(), zipPoint->m_lz_point_size);
             p +=  zipPoint->m_lz_point_size;
         }
 #else
diff -r 7a056e7bc4e5 -r 435254c9c30f src/drivers/las/Writer.cpp
--- a/src/drivers/las/Writer.cpp	Thu Aug 04 16:21:00 2011 -0500
+++ b/src/drivers/las/Writer.cpp	Fri Aug 05 09:34:30 2011 -0500
@@ -194,47 +194,17 @@
 
     LasHeaderWriter lasHeaderWriter(m_lasHeader, m_streamManager.ostream());
     lasHeaderWriter.write();
-
+    
     m_summaryData.reset();
 
     if (m_lasHeader.Compressed())
     {
 #ifdef PDAL_HAVE_LASZIP
-        if (!m_zip)
+        if (!m_zipPoint)
         {
-            // Initialize a scoped_ptr and swap it with our member variable 
-            // that will contain it.
-            boost::scoped_ptr<LASzip> s(new LASzip());
-            m_zip.swap(s);
-
-
             PointFormat format = m_lasHeader.getPointFormat();
             boost::scoped_ptr<ZipPoint> z(new ZipPoint(format, m_lasHeader.getVLRs().getAll()));
             m_zipPoint.swap(z);
-
-            bool ok = false;
-            try
-            {
-                ok = m_zip->setup((unsigned char)format, m_lasHeader.GetDataRecordLength());
-            }
-            catch(...)
-            {
-                throw pdal_error("Error opening compression core (3)");
-            }
-            if (!ok)
-            {
-                std::ostringstream oss;
-                oss << "Error opening compression core: " << std::string(m_zip->get_error());
-                throw pdal_error(oss.str());
-            }
-
-            ok = m_zip->pack(m_zipPoint->his_vlr_data, m_zipPoint->his_vlr_num);
-            if (!ok)
-            {
-                std::ostringstream oss;
-                oss << "Error packing VLR data for compression: " << std::string(m_zip->get_error());
-                throw pdal_error(oss.str());
-            }
         }
 
         if (!m_zipper)
@@ -242,14 +212,14 @@
             boost::scoped_ptr<LASzipper> z(new LASzipper());
             m_zipper.swap(z);
 
-
-
             bool stat(false);
-            stat = m_zipper->open(m_streamManager.ostream(), m_zip.get());
+            stat = m_zipper->open(m_streamManager.ostream(), m_zipPoint->GetZipper());
             if (!stat)
             {
                 std::ostringstream oss;
-                oss << "Error opening LASzipper: " << std::string(m_zip->get_error());
+                const char* err = m_zipper->get_error();
+                if (err==NULL) err="(unknown error)";
+                oss << "Error opening LASzipper: " << std::string(err);
                 throw pdal_error(oss.str());
             }
         }
diff -r 7a056e7bc4e5 -r 435254c9c30f src/drivers/las/ZipPoint.cpp
--- a/src/drivers/las/ZipPoint.cpp	Thu Aug 04 16:21:00 2011 -0500
+++ b/src/drivers/las/ZipPoint.cpp	Fri Aug 05 09:34:30 2011 -0500
@@ -64,154 +64,93 @@
 
 
 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(NULL)
     , m_lz_point_size(0)
 {
-    ConstructItems(format);
+
+    boost::scoped_ptr<LASzip> s(new LASzip());
+    m_zip.swap(s);
 
     const VariableLengthRecord* vlr = NULL;
-    for (unsigned int i=0; i<vlrs.size(); i++)
+    for (std::vector<VariableLengthRecord>::size_type i=0; i<vlrs.size(); i++)
     {
         const VariableLengthRecord& p = vlrs[i];
-        if (p.getRecordId() == 22204)
+        if (IsZipVLR(p))
         {
             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++)
+        bool ok(false);
+        ok = m_zip->unpack(&(vlr->getBytes()[0]), vlr->getLength());
+        if (!ok)
         {
-            our_vlr_data[i] = vlr->getBytes()[i];
+            std::ostringstream oss;
+            const char* err = m_zip->get_error();
+            if (err==NULL) err="(unknown error)";            
+            oss << "Error unpacking zip VLR data: " << std::string(err);
+            throw pdal_error(oss.str());
+        }
+
+    } else
+    {
+
+        if (!m_zip->setup(format, Support::getPointDataSize(format)))
+        {
+            std::ostringstream oss;
+            const char* err = m_zip->get_error();
+            if (err==NULL) err="(unknown error)";
+            oss << "Error setting up LASzip for format " << format <<": " << err; 
+            throw pdal_error(oss.str());


More information about the Liblas-commits mailing list