[Liblas-commits] hg: lasinfo and las2las coming on line for .laz support

liblas-commits at liblas.org liblas-commits at liblas.org
Sat Dec 18 15:37:27 EST 2010


changeset ecaf4ec83cd2 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=ecaf4ec83cd2
summary: lasinfo and las2las coming on line for .laz support

diffstat:

 apps/las2las.cpp                           |   15 ++-
 include/liblas/detail/reader/zipreader.hpp |   19 ++-
 include/liblas/detail/writer/zipwriter.hpp |   14 ++-
 src/detail/reader/zipreader.cpp            |  158 +++++++++++++++++++++++++---
 src/detail/writer/zipwriter.cpp            |  102 +++++++++++++++++-
 src/laswriter.cpp                          |    5 +
 6 files changed, 278 insertions(+), 35 deletions(-)

diffs (truncated from 519 to 300 lines):

diff -r 82459e1b0262 -r ecaf4ec83cd2 apps/las2las.cpp
--- a/apps/las2las.cpp	Fri Dec 17 21:22:40 2010 -0800
+++ b/apps/las2las.cpp	Sat Dec 18 12:31:40 2010 -0800
@@ -60,7 +60,8 @@
         return false;
     }
 
-    liblas::Reader reader(ifs);
+    liblas::ReaderFactory f;
+    liblas::Reader reader = f.CreateWithStream(ifs);
     SummaryPtr summary(new::liblas::Summary);
     
     reader.SetFilters(filters);
@@ -300,7 +301,8 @@
             }
             // set_ifstream_buffer(ifs, default_buffer_size);
 
-            liblas::Reader reader(ifs);
+            liblas::ReaderFactory f;
+            liblas::Reader reader = f.CreateWithStream(ifs);
             header = reader.GetHeader();
         } else {
             std::cerr << "Input LAS file not specified!\n";
@@ -322,6 +324,15 @@
         // Transforms alter our header as well.  Setting scales, offsets, etc.
         transforms = GetTransforms(vm, verbose, header);
         
+        if (output.compare(output.length()-4,4,".laz")==0)
+        {
+#ifdef HAVE_LASZIP
+            header.SetIsCompressed(true);
+#else
+            throw std::runtime_error("Compression support not enabled in liblas configuration");
+#endif
+        }
+
         bool op = process(  input, 
                             output,
                             header, 
diff -r 82459e1b0262 -r ecaf4ec83cd2 include/liblas/detail/reader/zipreader.hpp
--- a/include/liblas/detail/reader/zipreader.hpp	Fri Dec 17 21:22:40 2010 -0800
+++ b/include/liblas/detail/reader/zipreader.hpp	Sat Dec 18 12:31:40 2010 -0800
@@ -54,6 +54,10 @@
 #include <iosfwd>
 #include <boost/shared_ptr.hpp>
 
+// liblaszip
+class LASitem;
+class LASunzipper;
+
 namespace liblas { namespace detail { 
 
 typedef boost::shared_ptr< reader::Point > PointReaderPtr;
@@ -62,7 +66,6 @@
 class ZipReaderImpl : public ReaderI
 {
 public:
-
     ZipReaderImpl(std::istream& ifs);
     ~ZipReaderImpl();
 
@@ -79,9 +82,7 @@
     void SetFilters(std::vector<liblas::FilterPtr> const& filters);
     void SetTransforms(std::vector<liblas::TransformPtr> const& transforms);
 
-
 protected:
-
     bool FilterPoint(liblas::Point const& p);
     void TransformPoint(liblas::Point& p);
 
@@ -92,7 +93,7 @@
     boost::uint32_t m_size;
     boost::uint32_t m_current;
     
-    PointReaderPtr m_point_reader;
+    //PointReaderPtr m_point_reader;
     HeaderReaderPtr m_header_reader;
     
     HeaderPtr m_header;
@@ -101,7 +102,17 @@
 
     std::vector<liblas::FilterPtr> m_filters;
     std::vector<liblas::TransformPtr> m_transforms;
+
 private:
+    void ConstructItems();
+    void ReadIdiom();
+
+    LASunzipper* m_unzipper;
+    unsigned int m_num_items;
+    LASitem* m_items;
+    unsigned char** m_lz_point;
+    unsigned char* m_lz_point_data;
+    unsigned int m_lz_point_size;
 
     // Blocked copying operations, declared but not defined.
     ZipReaderImpl(ZipReaderImpl const& other);
diff -r 82459e1b0262 -r ecaf4ec83cd2 include/liblas/detail/writer/zipwriter.hpp
--- a/include/liblas/detail/writer/zipwriter.hpp	Fri Dec 17 21:22:40 2010 -0800
+++ b/include/liblas/detail/writer/zipwriter.hpp	Sat Dec 18 12:31:40 2010 -0800
@@ -52,6 +52,10 @@
 #include <boost/cstdint.hpp>
 #include <boost/shared_ptr.hpp>
 
+// liblaszip
+class LASzipper;
+class LASitem;
+
 namespace liblas { namespace detail { 
 
 typedef boost::shared_ptr< writer::Point > PointWriterPtr;
@@ -88,8 +92,16 @@
     HeaderPtr m_header;
 
 private:
+    boost::uint32_t m_pointCount;
 
-    boost::uint32_t m_pointCount;
+    void ConstructItems();
+
+    LASzipper* m_zipper;
+    unsigned int m_num_items;
+    LASitem* m_items;
+    unsigned char** m_lz_point;
+    unsigned char* m_lz_point_data;
+    unsigned int m_lz_point_size;
 
     // block copying operations
     ZipWriterImpl(ZipWriterImpl const& other);
diff -r 82459e1b0262 -r ecaf4ec83cd2 src/detail/reader/zipreader.cpp
--- a/src/detail/reader/zipreader.cpp	Fri Dec 17 21:22:40 2010 -0800
+++ b/src/detail/reader/zipreader.cpp	Sat Dec 18 12:31:40 2010 -0800
@@ -68,18 +68,39 @@
     : m_ifs(ifs)
     , m_size(0)
     , m_current(0)
-    , m_point_reader(PointReaderPtr())
+    //, m_point_reader(PointReaderPtr())
     , m_header_reader(new reader::Header(m_ifs))
     , m_header(HeaderPtr())
     , m_point(PointPtr(new liblas::Point()))
     , m_filters(0)
-    , m_transforms(0)
+    , m_transforms(0),
+    m_unzipper(NULL),
+    m_num_items(0),
+    m_items(NULL),
+    m_lz_point(NULL),
+    m_lz_point_data(NULL),
+    m_lz_point_size(0)
 {
-    new LASunzipper();
+    return;
 }
 
 ZipReaderImpl::~ZipReaderImpl()
 {
+    if (m_unzipper)
+    {
+        m_unzipper->close();
+        delete m_unzipper;
+        m_unzipper = NULL;
+    }
+
+    m_num_items = 0;
+    delete[] m_items;
+    m_items = NULL;
+
+    delete[] m_lz_point;
+    delete[] m_lz_point_data;
+
+    return;
 }
 
 void ZipReaderImpl::Reset()
@@ -93,10 +114,84 @@
     
     // If we reset the reader, we're ready to start reading points, so 
     // we'll create a point reader at this point.
-    if (!m_point_reader)
+    if (!m_unzipper)
     {
-        m_point_reader = PointReaderPtr(new reader::Point(m_ifs, m_header));
-    } 
+        m_unzipper = new LASunzipper();
+
+        ConstructItems();
+
+        bool ok = m_unzipper->open(&m_ifs, m_num_items, m_items, LASZIP_COMPRESSION_NONE);
+        if (!ok) throw 0; // BUG: need status codes?
+    }
+
+    return;
+}
+
+
+void ZipReaderImpl::ConstructItems()
+{
+    PointFormatName format = m_header->GetDataFormatId();
+
+    switch (format)
+    {
+    case ePointFormat0:
+        m_num_items = 1;
+        m_items = new LASitem[1];
+        m_items[0].set(LASitem::POINT10);
+        break;
+
+    case ePointFormat1:
+        m_num_items = 2;
+        m_items = new LASitem[2];
+        m_items[0].set(LASitem::POINT10);
+        m_items[1].set(LASitem::GPSTIME);
+        break;
+
+    case ePointFormat2:
+        m_num_items = 2;
+        m_items = new LASitem[2];
+        m_items[0].set(LASitem::POINT10);
+        m_items[1].set(LASitem::RGB);
+        break;
+
+    case ePointFormat3:
+        m_num_items = 3;
+        m_items = new LASitem[3];
+        m_items[0].set(LASitem::POINT10);
+        m_items[1].set(LASitem::GPSTIME);
+        m_items[2].set(LASitem::RGB);
+        break;
+
+    case ePointFormat4:
+        m_num_items = 3;
+        m_items = new LASitem[3];
+        m_items[0].set(LASitem::POINT10);
+        m_items[1].set(LASitem::GPSTIME);
+        m_items[2].set(LASitem::WAVEPACKET);
+        break;
+
+    default:
+        throw 0;
+    }
+
+    // construct the object that will hold a laszip point
+
+    // compute the point size
+    m_lz_point_size = 0;
+    for (unsigned int i = 0; i < m_num_items; i++) 
+        m_lz_point_size += m_items[i].size;
+
+    // create the point data
+    unsigned int point_offset = 0;
+    m_lz_point = new unsigned char*[m_num_items];
+    m_lz_point_data = new unsigned char[m_lz_point_size];
+    for (unsigned i = 0; i < m_num_items; i++)
+    {
+        m_lz_point[i] = &(m_lz_point_data[point_offset]);
+        point_offset += m_items[i].size;
+    }
+
+    return;
 }
 
 void ZipReaderImpl::TransformPoint(liblas::Point& p)
@@ -144,9 +239,9 @@
     m_header_reader->read();
     m_header = m_header_reader->GetHeader();
 
+    m_point->SetHeaderPtr(m_header);
+
     Reset();
-    
-
 }
 
 void ZipReaderImpl::SetHeader(liblas::Header const& header) 
@@ -154,6 +249,23 @@
     m_header = HeaderPtr(new liblas::Header(header));
 }
     
+void ZipReaderImpl::ReadIdiom()
+{
+    //////m_point_reader->read();
+    //////++m_current;
+    //////*m_point = m_point_reader->GetPoint();
+
+    bool ok = m_unzipper->read(m_lz_point);
+    if (!ok) throw 0;
+
+    std::vector<boost::uint8_t> v(m_lz_point_size);
+    for (unsigned int i=0; i<m_lz_point_size; i++)
+        v[i] = m_lz_point_data[i];
+    m_point->SetData(v);
+
+    ++m_current;
+}
+
 void ZipReaderImpl::ReadNextPoint()
 {
     if (0 == m_current)


More information about the Liblas-commits mailing list