[Liblas-commits] hg: Reset() can't be allocating the ZipPoint/LASunzipper

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Jun 29 15:57:53 EDT 2011


details:   http://hg.liblas.orghg/rev/d2888a49b3b9
changeset: 3041:d2888a49b3b9
user:      Howard Butler <hobu.inc at gmail.com>
date:      Wed Jun 29 11:37:59 2011 -0500
description:
Reset() can't be allocating the ZipPoint/LASunzipper
Subject: hg: put LASzip compression information into the Header summary

details:   http://hg.liblas.orghg/rev/4f921fcb0c41
changeset: 3042:4f921fcb0c41
user:      Howard Butler <hobu.inc at gmail.com>
date:      Wed Jun 29 11:58:53 2011 -0500
description:
put LASzip compression information into the Header summary
Subject: hg: we must seek to the position that the LASunzipper stopped at when doing its init() to go back and start reading points again

details:   http://hg.liblas.orghg/rev/8de1f6ffbd01
changeset: 3043:8de1f6ffbd01
user:      Howard Butler <hobu.inc at gmail.com>
date:      Wed Jun 29 14:55:41 2011 -0500
description:
we must seek to the position that the LASunzipper stopped at when doing its init() to go back and start reading points again
Subject: hg: we should be initializing the LASzipper when we first write the header to make sure the chunk pointer and chunking table are written, even for 0 point files

details:   http://hg.liblas.orghg/rev/a90e0c8940e0
changeset: 3044:a90e0c8940e0
user:      Howard Butler <hobu.inc at gmail.com>
date:      Wed Jun 29 14:56:42 2011 -0500
description:
we should be initializing the LASzipper when we first write the header to make sure the chunk pointer and chunking table are written, even for 0 point files
Subject: hg: update with a copy of the file as written by LAStools

details:   http://hg.liblas.orghg/rev/43cb1509490b
changeset: 3045:43cb1509490b
user:      Howard Butler <hobu.inc at gmail.com>
date:      Wed Jun 29 14:56:59 2011 -0500
description:
update with a copy of the file as written by LAStools

diffstat:

 include/liblas/detail/reader/zipreader.hpp |    1 +
 src/detail/reader/zipreader.cpp            |   18 +++-----
 src/detail/writer/zipwriter.cpp            |   56 ++++++++++++++++------------
 src/header.cpp                             |   31 ++++++++++++++++
 test/data/1.2-with-color.laz               |    0 
 5 files changed, 70 insertions(+), 36 deletions(-)

diffs (235 lines):

diff -r b1bb60c9a930 -r 43cb1509490b include/liblas/detail/reader/zipreader.hpp
--- a/include/liblas/detail/reader/zipreader.hpp	Wed Jun 29 10:03:39 2011 -0500
+++ b/include/liblas/detail/reader/zipreader.hpp	Wed Jun 29 14:56:59 2011 -0500
@@ -117,6 +117,7 @@
     boost::scoped_ptr<LASunzipper> m_unzipper;
 
     bool bNeedHeaderCheck;
+    std::streampos m_zipReadStartPosition;
     
     // Blocked copying operations, declared but not defined.
     ZipReaderImpl(ZipReaderImpl const& other);
diff -r b1bb60c9a930 -r 43cb1509490b src/detail/reader/zipreader.cpp
--- a/src/detail/reader/zipreader.cpp	Wed Jun 29 10:03:39 2011 -0500
+++ b/src/detail/reader/zipreader.cpp	Wed Jun 29 14:56:59 2011 -0500
@@ -73,6 +73,7 @@
     , m_filters(0)
     , m_transforms(0)
     , bNeedHeaderCheck(false)
+    , m_zipReadStartPosition(0)
 {
     return;
 }
@@ -95,23 +96,18 @@
     m_ifs.clear();
     m_ifs.seekg(0);
 
-    m_zipPoint.reset();
-    m_unzipper.reset();
-    
     // Reset sizes and set internal cursor to the beginning of file.
     m_current = 0;
     m_size = m_header->GetPointRecordsCount();
-    
 
-    // If we reset the reader, we're ready to start reading points, so 
-    // we'll create a point reader at this point.
+
     if (!m_zipPoint)
     {
-
+    
         PointFormatName format = m_header->GetDataFormatId();
         boost::scoped_ptr<ZipPoint> z(new ZipPoint(format, m_header->GetVLRs()));
         m_zipPoint.swap(z);
-
+    
     }
 
     if (!m_unzipper)
@@ -123,6 +119,8 @@
         m_ifs.seekg(m_header->GetDataOffset(), std::ios::beg);
         ok = m_unzipper->open(m_ifs, m_zipPoint->GetZipper());
 
+        m_zipReadStartPosition = m_ifs.tellg();
+
         if (!ok)
         {
             std::ostringstream oss;
@@ -132,7 +130,6 @@
             throw liblas_error(oss.str());
         }
     }
-
     return;
 }
 
@@ -184,7 +181,6 @@
     if (!m_header->Compressed())
         throw liblas_error("Internal error: compressed reader encountered uncompressed header"); 
 
-    // m_point->SetHeaderPtr(m_header);
     m_point->SetHeader(HeaderOptionalConstRef(*m_header));
     Reset();
 }
@@ -227,7 +223,7 @@
     if (0 == m_current)
     {
         m_ifs.clear();
-        m_ifs.seekg(m_header->GetDataOffset(), std::ios::beg);
+        m_ifs.seekg(m_zipReadStartPosition, std::ios::beg);
     }
 
     if (m_current >= m_size ){
diff -r b1bb60c9a930 -r 43cb1509490b src/detail/writer/zipwriter.cpp
--- a/src/detail/writer/zipwriter.cpp	Wed Jun 29 10:03:39 2011 -0500
+++ b/src/detail/writer/zipwriter.cpp	Wed Jun 29 14:56:59 2011 -0500
@@ -78,6 +78,23 @@
     m_header_writer->write();
     
     m_header = HeaderPtr(new liblas::Header(m_header_writer->GetHeader()));
+
+    if (!m_zipper)
+    {
+        boost::scoped_ptr<LASzipper> z(new LASzipper());
+        m_zipper.swap(z);
+
+        bool stat(false);
+
+        stat = m_zipper->open(m_ofs, m_zipPoint->GetZipper());
+        if (!stat)
+        {
+            std::ostringstream oss;
+            oss << "Error opening LASzipper: " << std::string(m_zipPoint->GetZipper()->get_error());
+            throw liblas_error(oss.str());
+        }
+    }
+    
 }
 
 void ZipWriterImpl::UpdatePointCount(boost::uint32_t count)
@@ -100,30 +117,6 @@
 
 void ZipWriterImpl::WritePoint(liblas::Point const& point)
 {
-    if (!m_zipPoint)
-    {
-            
-        PointFormatName format = m_header->GetDataFormatId();
-
-        boost::scoped_ptr<ZipPoint> z(new ZipPoint(format, m_header->GetVLRs()));
-        m_zipPoint.swap(z);
-    }
-
-    if (!m_zipper)
-    {
-        boost::scoped_ptr<LASzipper> z(new LASzipper());
-        m_zipper.swap(z);
-
-        bool stat(false);
-
-        stat = m_zipper->open(m_ofs, m_zipPoint->GetZipper());
-        if (!stat)
-        {
-            std::ostringstream oss;
-            oss << "Error opening LASzipper: " << std::string(m_zipPoint->GetZipper()->get_error());
-            throw liblas_error(oss.str());
-        }
-    }
 
     bool ok = false;
     const std::vector<boost::uint8_t>* data = &point.GetData();
@@ -151,6 +144,7 @@
 {
     // Try to update the point count on our way out, but we don't really
     // care if we weren't able to write it.
+
     try
     {
         UpdatePointCount(0);
@@ -159,8 +153,9 @@
         // ignore?
     }
 
+
+    m_zipper.reset();
     m_zipPoint.reset();
-    m_zipper.reset();
 
 }
 
@@ -189,6 +184,17 @@
 void ZipWriterImpl::SetHeader(liblas::Header const& header)
 {
     m_header = HeaderPtr(new liblas::Header(header));
+
+    if (!m_zipPoint)
+    {
+            
+        PointFormatName format = m_header->GetDataFormatId();
+
+        boost::scoped_ptr<ZipPoint> z(new ZipPoint(format, m_header->GetVLRs()));
+        m_zipPoint.swap(z);
+    }
+
+
 }
 
 
diff -r b1bb60c9a930 -r 43cb1509490b src/header.cpp
--- a/src/header.cpp	Wed Jun 29 10:03:39 2011 -0500
+++ b/src/header.cpp	Wed Jun 29 14:56:59 2011 -0500
@@ -46,6 +46,12 @@
 #include <liblas/schema.hpp>
 #include <liblas/detail/private_utility.hpp>
 #include <liblas/utility.hpp>
+
+#ifdef HAVE_LASZIP
+#include <liblas/detail/zippoint.hpp>
+#include <laszip/laszip.hpp>
+#endif
+
 // boost
 #include <boost/cstdint.hpp>
 #include <boost/lambda/lambda.hpp>
@@ -721,6 +727,25 @@
     pt.put("datarecordlength", GetDataRecordLength());
     pt.put("compressed", Compressed());
 
+#ifdef HAVE_LASZIP
+    liblas::detail::ZipPoint zp(GetDataFormatId(), GetVLRs());
+    LASzip* laszip = zp.GetZipper();
+    std::ostringstream zip_version;
+    zip_version <<"LASzip Version " 
+                << (int)laszip->version_major << "." 
+                << (int)laszip->version_minor << "r"
+                << (int)laszip->version_revision << " c" 
+                << (int)laszip->compressor;
+    if (laszip->compressor == LASZIP_COMPRESSOR_CHUNKED) 
+        zip_version << " "<< (int)laszip->chunk_size << ":";
+    else
+        zip_version << ":";
+    for (int i = 0; i < (int)laszip->num_items; i++) 
+        zip_version <<" "<< laszip->items[i].get_name()<<" "<<  (int)laszip->items[i].version;
+
+    pt.put("compression_info", zip_version.str());
+#endif
+
     ptree return_count;
     liblas::Header::RecordsByReturnArray returns = GetPointRecordsByReturnCount();
     for (boost::uint32_t i=0; i< 5; i++){
@@ -793,6 +818,12 @@
     os << "  Point Data Format:           " << tree.get<boost::uint32_t>("dataformatid") << std::endl;
     os << "  Number of Point Records:     " << tree.get<boost::uint32_t>("count") << std::endl;
     os << "  Compressed:                  " << (tree.get<bool>("compressed")?"True":"False") << std::endl;
+    if (tree.get<bool>("compressed"))
+    {
+    os << "  Compression Info:            " << tree.get<std::string>("compression_info");
+    }
+    os << std::endl;
+    
     os << "  Number of Points by Return:  " ;
     BOOST_FOREACH(ptree::value_type &v,
           tree.get_child("returns"))
diff -r b1bb60c9a930 -r 43cb1509490b test/data/1.2-with-color.laz
Binary file test/data/1.2-with-color.laz has changed


More information about the Liblas-commits mailing list