[Liblas-commits] hg: we don't believe any counts that liblas::detail::WriterI's h...

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Jan 26 10:48:07 EST 2011


details:   http://hg.liblas.orghg/rev/b71d99522ec2
changeset: 2820:b71d99522ec2
user:      Howard Butler <hobu.inc at gmail.com>
date:      Wed Jan 26 09:47:57 2011 -0600
description:
we don't believe any counts that liblas::detail::WriterI's header is given and we will carry forward the point count the writer has been maintaining on its header

diffstat:

 src/detail/writer/writer.cpp    |   9 +++++++++
 src/detail/writer/zipwriter.cpp |   9 +++++++++
 test/unit/writer_test.cpp       |  40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 0 deletions(-)

diffs (90 lines):

diff -r 8e82ca8320c0 -r b71d99522ec2 src/detail/writer/writer.cpp
--- a/src/detail/writer/writer.cpp	Tue Jan 25 14:17:58 2011 -0600
+++ b/src/detail/writer/writer.cpp	Wed Jan 26 09:47:57 2011 -0600
@@ -133,7 +133,16 @@
 }
 void WriterImpl::SetHeader(liblas::Header const& header)
 {
+    boost::uint32_t count = 0;
+    if (m_header.get())
+        count = m_header->GetPointRecordsCount();
+
     m_header = HeaderPtr(new liblas::Header(header));
+    
+    if (count)
+        m_header->SetPointRecordsCount(count);
+    else
+        m_header->SetPointRecordsCount(0);
 }
 
 
diff -r 8e82ca8320c0 -r b71d99522ec2 src/detail/writer/zipwriter.cpp
--- a/src/detail/writer/zipwriter.cpp	Tue Jan 25 14:17:58 2011 -0600
+++ b/src/detail/writer/zipwriter.cpp	Wed Jan 26 09:47:57 2011 -0600
@@ -219,7 +219,16 @@
 }
 void ZipWriterImpl::SetHeader(liblas::Header const& header)
 {
+    boost::uint32_t count = 0;
+    if (m_header.get())
+        count = m_header->GetPointRecordsCount();
+
     m_header = HeaderPtr(new liblas::Header(header));
+    
+    if (count)
+        m_header->SetPointRecordsCount(count);
+    else
+        m_header->SetPointRecordsCount(0);
 }
 
 
diff -r 8e82ca8320c0 -r b71d99522ec2 test/unit/writer_test.cpp
--- a/test/unit/writer_test.cpp	Tue Jan 25 14:17:58 2011 -0600
+++ b/test/unit/writer_test.cpp	Wed Jan 26 09:47:57 2011 -0600
@@ -313,6 +313,46 @@
 
     }
 
+    // Test using a bogus record count in the header
+    template<>
+    template<>
+    void to::test<6>()
+    {
+        size_t count = 10;
+        
+        // Create new LAS file using default header block
+        {
+            std::ofstream ofs;
+            ofs.open(tmpfile_.c_str(), std::ios::out | std::ios::binary);
+
+            // LAS 1.2, Point Format 0
+            liblas::Header header;
+            header.SetPointRecordsCount(12);
+            liblas::Writer writer(ofs, header);
+            
+            for ( size_t i = 0; i < count ; i++ )
+            {
+                liblas::Point point;
+                point.SetCoordinates( 10.0 + i, 20.0 + i, 30.0 + i );
+                writer.WritePoint( point );
+            }
+
+        }
+
+        // Read previously created LAS file and check its header block
+        {
+            std::ifstream ifs;
+            ifs.open(tmpfile_.c_str(), std::ios::in | std::ios::binary);
+            ensure(ifs.is_open());
+
+            liblas::Reader reader(ifs);
+
+            ensure_equals(reader.GetHeader().GetPointRecordsCount(), count);
+
+
+        }
+    }
+
 
 }
 


More information about the Liblas-commits mailing list