[Liblas-commits] hg: fix lasblock --write-points to actually write the blocks ins...

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Jan 5 00:53:47 EST 2011


details:   http://hg.liblas.orghg/rev/b7c1461cbc82
changeset: 2686:b7c1461cbc82
user:      Howard Butler <hobu.inc at gmail.com>
date:      Tue Jan 04 23:53:18 2011 -0600
description:
fix lasblock --write-points to actually write the blocks instead of the first n-capacity points of the file every time through
Subject: hg: merge

details:   http://hg.liblas.orghg/rev/c5dbd6afa5cc
changeset: 2687:c5dbd6afa5cc
user:      Howard Butler <hobu.inc at gmail.com>
date:      Tue Jan 04 23:53:39 2011 -0600
description:
merge

diffstat:

 apps/lasblock.cpp               |  41 ++++++++++++++++-----------------
 src/detail/reader/zipreader.cpp |  37 ++++++++++++++++++++++++++----
 src/detail/writer/header.cpp    |  29 ++++++++++++++---------
 src/detail/writer/zipwriter.cpp |  50 ++++++++++++++++++++++++++++++++--------
 test/unit/zipreader_test.cpp    |   2 +-
 test/unit/zipwriter_test.cpp    |   2 +-
 6 files changed, 112 insertions(+), 49 deletions(-)

diffs (284 lines):

diff -r b2b4ee72c615 -r c5dbd6afa5cc apps/lasblock.cpp
--- a/apps/lasblock.cpp	Tue Jan 04 11:54:33 2011 -0800
+++ b/apps/lasblock.cpp	Tue Jan 04 23:53:39 2011 -0600
@@ -102,35 +102,34 @@
     
     for ( boost::uint32_t i = 0; i < c.GetBlockCount(); ++i )
     {
-        OStreamPtr ofs(new std::ofstream);
-        SummaryPtr summary(new::liblas::CoordinateSummary);
-
         std::ostringstream name;
         name << out << "-" << i <<".las";
+        SummaryPtr summary(new::liblas::CoordinateSummary);        
 
-        const liblas::chipper::Block& b = c.GetBlock(i);
-        header.SetExtent(b.GetBounds());
+        {
+            OStreamPtr ofs(new std::ofstream);
 
-        WriterPtr writer = start_writer(ofs, name.str(), header);
+            const liblas::chipper::Block& b = c.GetBlock(i);
+            header.SetExtent(b.GetBounds());
+        
+            WriterPtr writer = start_writer(ofs, name.str(), header);
 
+            std::vector<boost::uint32_t> ids = b.GetIDs();
         
+        
+            for ( boost::uint32_t pi = 0; pi < ids.size(); ++pi )
+            {
+            
+                bool read = reader.ReadPointAt(ids[pi]);
+                if (read) {
+                    liblas::Point const& p = reader.GetPoint();
+                    summary->AddPoint(p);
+                    writer->WritePoint(p);
+                }
+            }
 
-        std::vector<boost::uint32_t> ids = b.GetIDs();
-        
-        
-        for ( boost::uint32_t pi = 0; pi < ids.size(); ++pi )
-        {
-            bool read = reader.ReadPointAt(pi);
-            if (read) {
-                liblas::Point const& p = reader.GetPoint();
-                summary->AddPoint(p);
-                writer->WritePoint(p);
-            }
+            
         }
-
-
-        writer = WriterPtr();
-        ofs = OStreamPtr();
         
         liblas::Header hnew = FetchHeader(name.str());
         RepairHeader(*summary, hnew);
diff -r b2b4ee72c615 -r c5dbd6afa5cc src/detail/reader/zipreader.cpp
--- a/src/detail/reader/zipreader.cpp	Tue Jan 04 11:54:33 2011 -0800
+++ b/src/detail/reader/zipreader.cpp	Tue Jan 04 23:53:39 2011 -0600
@@ -106,14 +106,31 @@
     // we'll create a point reader at this point.
     if (!m_unzipper)
     {
-        m_unzipper = new LASunzipper();
+        try
+        {
+            m_unzipper = new LASunzipper();
+        }
+        catch(...)
+        {
+            throw liblas_error("Failed to open laszip decompression engine (1)"); 
+        }
 
         PointFormatName format = m_header->GetDataFormatId();
         m_zipPoint = new ZipPoint(format);
 
-        unsigned int stat = m_unzipper->open(m_ifs, m_zipPoint->m_num_items, m_zipPoint->m_items, LASzip::COMPRESSION_DEFAULT);
+        unsigned int stat = 1;
+        try
+        {
+            stat = m_unzipper->open(m_ifs, m_zipPoint->m_num_items, m_zipPoint->m_items, LASzip::COMPRESSION_DEFAULT);
+        }
+        catch(...)
+        {
+            throw liblas_error("Failed to open laszip decompression engine (2)"); 
+        }
         if (stat != 0)
-            throw liblas_error("Failed to open laszip decompression engine"); 
+        {
+            throw liblas_error("Failed to open laszip decompression engine (3)"); 
+        }
     }
 
     return;
@@ -183,9 +200,19 @@
     //////++m_current;
     //////*m_point = m_point_reader->GetPoint();
 
-    bool ok = m_unzipper->read(m_zipPoint->m_lz_point);
+    bool ok = false;
+    try
+    {
+        ok = m_unzipper->read(m_zipPoint->m_lz_point);
+    }
+    catch(...)
+    {
+        throw liblas_error("Error reading compressed point data (1)");
+    }
     if (!ok)
-        throw liblas_error("Error reading compressed point data");
+    {
+        throw liblas_error("Error reading compressed point data (2)");
+    }
 
     std::vector<boost::uint8_t> v(m_zipPoint->m_lz_point_size);
     for (unsigned int i=0; i<m_zipPoint->m_lz_point_size; i++)
diff -r b2b4ee72c615 -r c5dbd6afa5cc src/detail/writer/header.cpp
--- a/src/detail/writer/header.cpp	Tue Jan 04 11:54:33 2011 -0800
+++ b/src/detail/writer/header.cpp	Tue Jan 04 23:53:39 2011 -0600
@@ -101,20 +101,27 @@
     {
         // We're opened in append mode
         
-        ios::off_type points = end - static_cast<ios::off_type>(m_header.GetDataOffset());
-        ios::off_type count = points / static_cast<ios::off_type>(m_header.GetDataRecordLength());
+        if (m_header.Compressed())
+        {
+            m_pointCount = m_header.GetPointRecordsCount();
+        }
+        else
+        {
+            ios::off_type points = end - static_cast<ios::off_type>(m_header.GetDataOffset());
+            ios::off_type count = points / static_cast<ios::off_type>(m_header.GetDataRecordLength());
         
-        if (points < 0) {
-            std::ostringstream oss;
-            oss << "The header's data offset, " << m_header.GetDataOffset() 
-                <<", is much larger than the size of the file, " << end
-                <<", and something is amiss.  Did you use the right header"
-                <<" offset value?";
-            throw std::runtime_error(oss.str());
+            if (points < 0) {
+                std::ostringstream oss;
+                oss << "The header's data offset, " << m_header.GetDataOffset() 
+                    <<", is much larger than the size of the file, " << end
+                    <<", and something is amiss.  Did you use the right header"
+                    <<" offset value?";
+                throw std::runtime_error(oss.str());
+            }
+
+            m_pointCount = static_cast<uint32_t>(count);
         }
 
-        m_pointCount = static_cast<uint32_t>(count);
-
         // Position to the beginning of the file to start writing the header
         m_ofs.seekp(0, ios::beg);
 
diff -r b2b4ee72c615 -r c5dbd6afa5cc src/detail/writer/zipwriter.cpp
--- a/src/detail/writer/zipwriter.cpp	Tue Jan 04 11:54:33 2011 -0800
+++ b/src/detail/writer/zipwriter.cpp	Tue Jan 04 23:53:39 2011 -0600
@@ -81,6 +81,8 @@
 
 void ZipWriterImpl::UpdatePointCount(boost::uint32_t count)
 {
+    std::streamoff orig_pos = m_ofs.tellp();
+
     boost::uint32_t out = m_pointCount;
     
     if ( count != 0 ) { out = count; }
@@ -90,6 +92,8 @@
     std::streamsize const dataPos = 107; 
     m_ofs.seekp(dataPos, std::ios::beg);
     detail::write_n(m_ofs, out , sizeof(out));
+
+    m_ofs.seekp(orig_pos, std::ios::beg);
 }
 
 
@@ -102,14 +106,31 @@
 
     if (m_zipper==NULL)
     {
-        m_zipper = new LASzipper();
+        try
+        {
+            m_zipper = new LASzipper();
+        }
+        catch(...)
+        {
+            throw liblas_error("Error opening compression engine (1)");
+        }
 
         PointFormatName format = m_header->GetDataFormatId();
         m_zipPoint = new ZipPoint(format);
 
-        unsigned int stat = m_zipper->open(m_ofs, m_zipPoint->m_num_items, m_zipPoint->m_items, LASzip::COMPRESSION_DEFAULT);
+        unsigned int stat = 1;
+        try
+        {
+            stat = m_zipper->open(m_ofs, m_zipPoint->m_num_items, m_zipPoint->m_items, LASzip::COMPRESSION_DEFAULT);
+        }
+        catch(...)
+        {
+            throw liblas_error("Error opening compression engine (3)");
+        }
         if (stat != 0)
-            throw liblas_error("Error opening compression engine");
+        {
+            throw liblas_error("Error opening compression engine (2)");
+        }
     }
 
     const std::vector<boost::uint8_t>& v = point.GetData();
@@ -119,11 +140,21 @@
         //printf("%d %d\n", v[i], i);
     }
 
-    bool ok = m_zipper->write(m_zipPoint->m_lz_point);
+    bool ok = false;
+    try
+    {
+        ok = m_zipper->write(m_zipPoint->m_lz_point);
+    }
+    catch(...)
+    {
+        throw liblas_error("Error writing compressed point data (1)");
+    }
     if (!ok)
-        throw liblas_error("Error writing compressed point data");
+    {
+        throw liblas_error("Error writing compressed point data (2)");
+    }
 
-    /*++m_pointCount;*/
+    ++m_pointCount;
 
     return;
 }
@@ -132,14 +163,13 @@
 {
     // 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
+    try
     {
         UpdatePointCount(0);
-        
     } catch (std::runtime_error const&)
     {
-        
-    }*/
+        // ignore?
+    }
 
     delete m_zipper;
     delete m_zipPoint;
diff -r b2b4ee72c615 -r c5dbd6afa5cc test/unit/zipreader_test.cpp
--- a/test/unit/zipreader_test.cpp	Tue Jan 04 11:54:33 2011 -0800
+++ b/test/unit/zipreader_test.cpp	Tue Jan 04 23:53:39 2011 -0600
@@ -5,7 +5,7 @@
 // http://www.opensource.org/licenses/bsd-license.php)
 //
 
-#ifdef HAVE_LASZIPxxx
+#ifdef HAVE_LASZIP
 
 #include <liblas/liblas.hpp>
 #include <liblas/variablerecord.hpp>
diff -r b2b4ee72c615 -r c5dbd6afa5cc test/unit/zipwriter_test.cpp
--- a/test/unit/zipwriter_test.cpp	Tue Jan 04 11:54:33 2011 -0800
+++ b/test/unit/zipwriter_test.cpp	Tue Jan 04 23:53:39 2011 -0600
@@ -5,7 +5,7 @@
 // http://www.opensource.org/licenses/bsd-license.php)
 //
 
-#ifdef HAVE_LASZIPxxx
+#ifdef HAVE_LASZIP
 
 #include <liblas/liblas.hpp>
 #include <tut/tut.hpp>


More information about the Liblas-commits mailing list