[Liblas-commits] hg: keep a reference to the point's header when it is read

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Jul 21 10:26:30 EDT 2010


changeset 4a7f891d09d1 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=4a7f891d09d1
summary: keep a reference to the point's header when it is read

diffstat:

 include/liblas/laspoint.hpp  |  21 +++++++++++++
 include/liblas/lasreader.hpp |   4 +-
 src/detail/reader/point.cpp  |   9 +++++-
 src/detail/reader/reader.cpp |  68 +++++++++++++++++++------------------------
 src/laspoint.cpp             |  11 +++++-
 src/lasreader.cpp            |  44 ++++++++++++++++++----------
 6 files changed, 99 insertions(+), 58 deletions(-)

diffs (truncated from 404 to 300 lines):

diff -r 57a472166c20 -r 4a7f891d09d1 include/liblas/laspoint.hpp
--- a/include/liblas/laspoint.hpp	Wed Jul 21 09:24:35 2010 -0500
+++ b/include/liblas/laspoint.hpp	Wed Jul 21 09:26:24 2010 -0500
@@ -46,6 +46,7 @@
 #include <liblas/detail/fwd.hpp>
 #include <liblas/detail/utility.hpp>
 #include <liblas/lasclassification.hpp>
+#include <liblas/lasheader.hpp>
 #include <liblas/lascolor.hpp>
 
 // std
@@ -53,10 +54,17 @@
 #include <cstdlib> // std::size_t
 #include <vector> // std::vector
 
+#include <boost/shared_ptr.hpp>
+
+
+
 namespace liblas {
 
+
 /// Point data record composed with X, Y, Z coordinates and attributes.
 class Point
+
+
 {
 public:
 
@@ -187,6 +195,11 @@
     std::vector<liblas::uint8_t> const& GetExtraData() const {return m_extra_data; }
     void SetExtraData(std::vector<uint8_t> const& v) { m_extra_data = v;}
 
+    std::vector<liblas::uint8_t> const& GetData() const {return m_format_data; }
+    void SetData(std::vector<uint8_t> const& v) { m_format_data = v;}
+    
+    void SetHeader(const liblas::Header& header);
+    const liblas::Header* GetHeader () { return m_hdr; }
 private:
 
     static std::size_t const coords_size = 3;
@@ -203,6 +216,9 @@
     int8_t m_angleRank;
 
     std::vector<uint8_t> m_extra_data;
+    std::vector<uint8_t> m_format_data;
+    
+    const liblas::Header* m_hdr;
     
     void throw_out_of_range() const
     {
@@ -360,6 +376,11 @@
     return m_coords[n];
 }
 
+inline void Point::SetHeader(const liblas::Header& header) 
+{
+    m_hdr = &header;
+}
+
 } // namespace liblas
 
 #endif // LIBLAS_LASPOINT_HPP_INCLUDED
diff -r 57a472166c20 -r 4a7f891d09d1 include/liblas/lasreader.hpp
--- a/include/liblas/lasreader.hpp	Wed Jul 21 09:24:35 2010 -0500
+++ b/include/liblas/lasreader.hpp	Wed Jul 21 09:26:24 2010 -0500
@@ -171,10 +171,12 @@
     void Init(); // throws on error
 
     const std::auto_ptr<ReaderI> m_pimpl;
-    Header m_header;
+
+    Header* m_header;
     Point* m_point;
     Point* m_empty_point;
     
+    
     // Set if the user provides a header to override the header as 
     // read from the istream
     bool bCustomHeader;
diff -r 57a472166c20 -r 4a7f891d09d1 src/detail/reader/point.cpp
--- a/src/detail/reader/point.cpp	Wed Jul 21 09:24:35 2010 -0500
+++ b/src/detail/reader/point.cpp	Wed Jul 21 09:26:24 2010 -0500
@@ -81,12 +81,17 @@
     liblas::uint16_t red(0);
     liblas::uint16_t blue(0);
     liblas::uint16_t green(0);
+
+    // raw byte data necessary to fill out the point format    
+    std::vector<uint8_t> format_data; 
+    
+    format_data.resize(m_format.GetBaseByteSize());
     
     detail::PointRecord record;
     // TODO: Replace with compile-time assert
+
     assert(liblas::ePointSize0 == sizeof(record));
 
-    // const PointFormat& format = m_header.GetPointFormat();
     
     try
     {
@@ -159,6 +164,8 @@
         throw std::runtime_error(msg.str());
         
     }
+    
+    m_point.SetHeader(m_header);
 }
 
 
diff -r 57a472166c20 -r 4a7f891d09d1 src/detail/reader/reader.cpp
--- a/src/detail/reader/reader.cpp	Wed Jul 21 09:24:35 2010 -0500
+++ b/src/detail/reader/reader.cpp	Wed Jul 21 09:26:24 2010 -0500
@@ -197,35 +197,36 @@
 
 void CachedReaderImpl::CacheData(liblas::uint32_t position, const liblas::Header& header) 
 {
-        std::vector<uint8_t>::size_type old_cache_start_position = m_cache_start_position;
-        m_cache_start_position = position;
+    std::vector<uint8_t>::size_type old_cache_start_position = m_cache_start_position;
+    m_cache_start_position = position;
 
     std::vector<uint8_t>::size_type header_size = static_cast<std::vector<uint8_t>::size_type>(header.GetPointRecordsCount());
     std::vector<uint8_t>::size_type left_to_cache = std::min(m_cache_size, header_size - m_cache_start_position);
 
     std::vector<uint8_t>::size_type to_mark = std::min(m_cache_size, header_size - old_cache_start_position);
-        for (uint32_t i = 0; i < to_mark; ++i) {
-            m_mask[old_cache_start_position + i] = 0;
+
+    for (uint32_t i = 0; i < to_mark; ++i) {
+        m_mask[old_cache_start_position + i] = 0;
+    }
+
+    // if these aren't equal, we've hopped around with ReadPointAt
+    // and we need to seek to the proper position.
+    if (m_current != position) {
+        CachedReaderImpl::Seek(position, header);
+        m_current = position;
+    }
+    m_cache_read_position =  position;
+
+    for (uint32_t i = 0; i < left_to_cache; ++i) 
+    {
+        try {
+            m_mask[m_current] = 1;
+            m_cache[i] = ReaderImpl::ReadNextPoint(header);
+        } catch (std::out_of_range&) {
+            // cached to the end
+            break;
         }
-
-        // if these aren't equal, we've hopped around with ReadPointAt
-        // and we need to seek to the proper position.
-        if (m_current != position) {
-            CachedReaderImpl::Seek(position, header);
-            m_current = position;
-        }
-        m_cache_read_position =  position;
-
-        for (uint32_t i = 0; i < left_to_cache; ++i) 
-        {
-            try {
-                m_mask[m_current] = 1;
-                m_cache[i] = ReaderImpl::ReadNextPoint(header);
-            } catch (std::out_of_range&) {
-                // cached to the end
-                break;
-            }
-        }
+    }
 
 }
 
@@ -304,7 +305,9 @@
     
     } else if (m_size < n) {
         std::ostringstream output;
-        output << "ReadPointAt:: Inputted value: " << n << " is greater than the number of points: " << m_size;
+        output << "ReadPointAt:: Inputted value: " 
+               << n << " is greater than the number of points: " 
+               << m_size;
         std::string out(output.str());
         throw std::runtime_error(out);
     }
@@ -336,6 +339,7 @@
     m_cache_start_position = 0;
     m_cache_read_position = 0;
 
+
     ReaderImpl::Reset(header);
 
 }
@@ -350,20 +354,8 @@
    m_cache_read_position = n;
    ReaderImpl::Seek(n,header);
 }
-// 
-// void CachedReaderImpl::SetOutputSRS(const SpatialReference& srs, const liblas::Header& header)
-// {
-//     // We need to wipe out the cache if we've set the output srs.
-//     std::vector<uint8_t>::size_type header_size = static_cast<std::vector<uint8_t>::size_type>(header.GetPointRecordsCount());
-//     std::vector<uint8_t>::size_type left_to_cache = std::min(m_cache_size, header_size - m_cache_start_position);
-// 
-//     std::vector<uint8_t>::size_type to_mark = std::max(m_cache_size, left_to_cache);
-//     for (uint32_t i = 0; i < to_mark; ++i) {
-//         m_mask[m_cache_start_position + i] = 0;
-//     }
-//     
-//     ReaderImpl::SetOutputSRS(srs, header);
-// }
+
+
 
 // ReaderImpl* ReaderFactory::Create(std::istream& ifs)
 // {
diff -r 57a472166c20 -r 4a7f891d09d1 src/laspoint.cpp
--- a/src/laspoint.cpp	Wed Jul 21 09:24:35 2010 -0500
+++ b/src/laspoint.cpp	Wed Jul 21 09:26:24 2010 -0500
@@ -55,10 +55,12 @@
     m_pointSourceId(0),
     m_flags(0),
     m_userData(0),
-    m_angleRank(0)
+    m_angleRank(0),
+    m_hdr(0)
 {
     std::memset(m_coords, 0, sizeof(m_coords));
     m_extra_data.resize(0);
+    m_format_data.resize(0);
 }
 
 Point::Point(Point const& other) :
@@ -69,10 +71,13 @@
     m_pointSourceId(other.m_pointSourceId),
     m_flags(other.m_flags),
     m_userData(other.m_userData),
-    m_angleRank(other.m_angleRank)
+    m_angleRank(other.m_angleRank),
+    m_hdr(other.m_hdr)
 {
     std::memcpy(m_coords, other.m_coords, sizeof(m_coords));
     std::vector<uint8_t>(other.m_extra_data).swap(m_extra_data);
+    std::vector<uint8_t>(other.m_format_data).swap(m_format_data);
+    
 }
 
 Point& Point::operator=(Point const& rhs)
@@ -91,6 +96,8 @@
         m_gpsTime = rhs.m_gpsTime;
         m_color = rhs.m_color;
         std::vector<uint8_t>(rhs.m_extra_data).swap(m_extra_data);
+        std::vector<uint8_t>(rhs.m_format_data).swap(m_format_data);
+        m_hdr = rhs.m_hdr;
     }
     return *this;
 }
diff -r 57a472166c20 -r 4a7f891d09d1 src/lasreader.cpp
--- a/src/lasreader.cpp	Wed Jul 21 09:24:35 2010 -0500
+++ b/src/lasreader.cpp	Wed Jul 21 09:26:24 2010 -0500
@@ -58,6 +58,7 @@
 
 Reader::Reader(std::istream& ifs) :
     m_pimpl(new detail::CachedReaderImpl(ifs,3)),
+    m_header(0),
     m_point(0),
     m_empty_point(new Point()),
     bCustomHeader(false),
@@ -70,6 +71,7 @@
 
 Reader::Reader(ReaderI* reader) :
     m_pimpl(reader),
+    m_header(0),
     m_point(0),
     m_empty_point(new Point()),
     bCustomHeader(false),
@@ -82,15 +84,17 @@
 
 Reader::Reader(std::istream& ifs, Header& header) :
     m_pimpl(new detail::CachedReaderImpl(ifs,3)),
+    m_header(new Header()),    
     m_point(0),
     m_empty_point(new Point()),
-    bCustomHeader(false),
+    bCustomHeader(true),
     m_filters(0),
     m_transforms(0),
     m_reprojection_transform(TransformPtr())
 {
-    m_header = header;
-    bCustomHeader = true;
+    // if we have a custom header, create a slot for it and then copy 
+    // the header we were given
+    *m_header = header;
     Init();
 }
 
@@ -100,11 +104,14 @@
     // std::auto_ptr with incomplete type (Reader).
     delete m_empty_point;


More information about the Liblas-commits mailing list