[Liblas-commits] hg-main-tree: use copyable PointBuffer for caching points in Chi...

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Mar 23 11:11:31 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/eaeee09463b3
changeset: 395:eaeee09463b3
user:      Howard Butler <hobu.inc at gmail.com>
date:      Wed Mar 23 10:11:26 2011 -0500
description:
use copyable PointBuffer for caching points in Chipper

diffstat:

 include/libpc/Chipper.hpp |  22 ++++++----------------
 src/Chipper.cpp           |  15 ++++++---------
 2 files changed, 12 insertions(+), 25 deletions(-)

diffs (95 lines):

diff -r 50bd6887c749 -r eaeee09463b3 include/libpc/Chipper.hpp
--- a/include/libpc/Chipper.hpp	Wed Mar 23 09:56:21 2011 -0500
+++ b/include/libpc/Chipper.hpp	Wed Mar 23 10:11:26 2011 -0500
@@ -29,13 +29,13 @@
 {
     
 public:
-    PtRef() :m_data(0) {};
+    PtRef(PointBuffer& buffer) :m_data(buffer) {};
 
     // PtRef(PointBuffer const& data) : m_data(0), m_pointSize(data.getSchemaLayout().getByteSize()) {};
     double m_pos;
     boost::uint32_t m_ptindex;
     boost::uint32_t m_oindex;
-    boost::uint8_t* m_data;
+    PointBuffer m_data;
     boost::uint32_t m_pointSize;
 
     bool operator < (const PtRef& pt) const
@@ -46,13 +46,7 @@
         m_ptindex(other.m_ptindex), 
         m_oindex(other.m_oindex),
         m_data(other.m_data) 
-        { 
-            if (other.m_data)
-            {
-                m_data = new boost::uint8_t[m_pointSize * 1]; 
-                memcpy(m_data, other.m_data, m_pointSize*1);
-            }
-        }
+    {}
 
     PtRef& operator=(const PtRef& rhs)
     {
@@ -61,11 +55,7 @@
             m_pos = rhs.m_pos;
             m_ptindex = rhs.m_ptindex;
             m_oindex = rhs.m_oindex;
-            if (rhs.m_data)
-            {
-                m_data = new boost::uint8_t [m_pointSize * 1];
-                memcpy(m_data, rhs.m_data, m_pointSize*1);            
-            }
+            m_data = rhs.m_data;
         }
         return *this;
     }
@@ -84,8 +74,8 @@
         { return m_vec.size(); }
     void reserve(std::vector<PtRef>::size_type n)
         { m_vec.reserve(n); }
-    void resize(std::vector<PtRef>::size_type n)
-        { m_vec.resize(n); }
+    // void resize(std::vector<PtRef>::size_type n)
+    //     { m_vec.resize(n); }
     void push_back(const PtRef& ref)
         { m_vec.push_back(ref); }
     std::vector<PtRef>::iterator begin()
diff -r 50bd6887c749 -r eaeee09463b3 src/Chipper.cpp
--- a/src/Chipper.cpp	Wed Mar 23 09:56:21 2011 -0500
+++ b/src/Chipper.cpp	Wed Mar 23 10:11:26 2011 -0500
@@ -123,13 +123,11 @@
     libpc::Schema const& schema = header.getSchema();
     libpc::SchemaLayout const& layout = SchemaLayout(schema);
     
-    PtRef ref;
-    ref.m_pointSize = layout.getByteSize();
     
     boost::uint64_t count = header.getNumPoints();
     xvec.reserve(count);
     yvec.reserve(count);
-    spare.resize(count);
+    spare.reserve(count);
     
     // boost::uint32_t chunks = count/m_threshold;
 
@@ -165,13 +163,12 @@
 
         for (boost::uint32_t j = 0; j < m_threshold; j++)
         {
-            // PointBuffer data(schema, 1);            
-            // data.copyPointFast(j, 0, buffer);
-            boost::uint8_t* raw_data = new boost::uint8_t[ref.m_pointSize*1];
-            boost::uint8_t* src_data = buffer.getData(j);
-            memcpy(raw_data, src_data, ref.m_pointSize*1);
+            PointBuffer data(buffer.getSchemaLayout(), 1);            
+            data.copyPointFast(0, j, buffer);
+            PtRef ref(data);
+            
+            if (j == num_to_read) break; // we're outta here
 
-            if (j == num_to_read) break; // we're outta here
             // (v * m_header->GetScaleX()) + m_header->GetOffsetX();
             const double x = (buffer.getField<boost::int32_t>(j, indexX) * xscale) + xoffset;
             const double y = (buffer.getField<boost::int32_t>(j, indexY) * yscale) + yoffset;


More information about the Liblas-commits mailing list