[Liblas-commits] hg: finish putting liblas::Reader on a big diet

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Dec 9 17:14:50 EST 2010


changeset 281a5b82de9c in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=281a5b82de9c
summary: finish putting liblas::Reader on a big diet

diffstat:

 include/liblas/detail/fwd.hpp                 |    1 +
 include/liblas/detail/reader/cachedreader.hpp |   19 ++-
 include/liblas/detail/reader/reader.hpp       |   19 ++-
 include/liblas/lasreader.hpp                  |   13 --
 include/liblas/liblas.hpp                     |   13 +-
 src/detail/reader/cachedreader.cpp            |   92 +++++++++++++-----
 src/detail/reader/reader.cpp                  |   69 +++++++------
 src/lasreader.cpp                             |  128 ++++++++-----------------
 8 files changed, 181 insertions(+), 173 deletions(-)

diffs (truncated from 761 to 300 lines):

diff -r 34d5d9cb5d36 -r 281a5b82de9c include/liblas/detail/fwd.hpp
--- a/include/liblas/detail/fwd.hpp	Tue Dec 07 08:29:07 2010 -0600
+++ b/include/liblas/detail/fwd.hpp	Thu Dec 09 16:14:39 2010 -0600
@@ -63,6 +63,7 @@
 class VariableRecord;
 
 typedef boost::shared_ptr<Header> HeaderPtr;
+typedef boost::shared_ptr<const Header> ConstHeaderPtr;
 typedef boost::shared_ptr<Point> PointPtr;
 
 namespace detail {
diff -r 34d5d9cb5d36 -r 281a5b82de9c include/liblas/detail/reader/cachedreader.hpp
--- a/include/liblas/detail/reader/cachedreader.hpp	Tue Dec 07 08:29:07 2010 -0600
+++ b/include/liblas/detail/reader/cachedreader.hpp	Thu Dec 09 16:14:39 2010 -0600
@@ -61,12 +61,14 @@
 
     CachedReaderImpl(std::istream& ifs, std::size_t cache_size);
 
-    HeaderPtr ReadHeader();
-    liblas::Point const& ReadNextPoint(HeaderPtr header);
-    liblas::Point const& ReadPointAt(std::size_t n, HeaderPtr header);
+    void ReadHeader();
+    void ReadNextPoint();
+    liblas::Point const& ReadPointAt(std::size_t n);
 
-    void Seek(std::size_t n, HeaderPtr header);
-    void Reset(HeaderPtr header);
+    void Seek(std::size_t n);
+    void Reset();
+    void SetFilters(std::vector<liblas::FilterPtr> const& filters);
+    void SetTransforms(std::vector<liblas::TransformPtr> const& transforms);
 
 protected:
 
@@ -75,10 +77,11 @@
     // Blocked copying operations, declared but not defined.
     CachedReaderImpl(CachedReaderImpl const& other);
     CachedReaderImpl& operator=(CachedReaderImpl const& rhs);
-    liblas::Point const& ReadCachedPoint(boost::uint32_t position, HeaderPtr header);
+    void ReadCachedPoint(boost::uint32_t position);
     
-    void CacheData(boost::uint32_t position, HeaderPtr header);
-
+    void CacheData(boost::uint32_t position);
+    void ReadNextUncachedPoint();
+    
     typedef std::vector<boost::uint8_t> cache_mask_type;
 
     cache_mask_type m_mask;
diff -r 34d5d9cb5d36 -r 281a5b82de9c include/liblas/detail/reader/reader.hpp
--- a/include/liblas/detail/reader/reader.hpp	Tue Dec 07 08:29:07 2010 -0600
+++ b/include/liblas/detail/reader/reader.hpp	Thu Dec 09 16:14:39 2010 -0600
@@ -64,19 +64,22 @@
     ReaderImpl(std::istream& ifs);
     ~ReaderImpl();
 
-    HeaderPtr ReadHeader();
-    liblas::Point const& ReadNextPoint(HeaderPtr header);
-    liblas::Point const& ReadPointAt(std::size_t n, HeaderPtr header);
-    void Seek(std::size_t n, HeaderPtr header);
+    void ReadHeader();
+    liblas::Header const& GetHeader() const {return *m_header;}
+    void SetHeader(liblas::Header const& header);
+    liblas::Point const& GetPoint() const { return *m_point; }
+    void ReadNextPoint();
+    liblas::Point const& ReadPointAt(std::size_t n);
+    void Seek(std::size_t n);
     
-    void Reset(HeaderPtr header);
+    void Reset();
 
     void SetFilters(std::vector<liblas::FilterPtr> const& filters);
     void SetTransforms(std::vector<liblas::TransformPtr> const& transforms);
 
 
 protected:
-    void CreateTransform();
+
     bool FilterPoint(liblas::Point const& p);
     void TransformPoint(liblas::Point& p);
 
@@ -89,6 +92,10 @@
     
     PointReaderPtr m_point_reader;
     HeaderReaderPtr m_header_reader;
+    
+    HeaderPtr m_header;
+    
+    PointPtr m_point;
 
     std::vector<liblas::FilterPtr> m_filters;
     std::vector<liblas::TransformPtr> m_transforms;
diff -r 34d5d9cb5d36 -r 281a5b82de9c include/liblas/lasreader.hpp
--- a/include/liblas/lasreader.hpp	Tue Dec 07 08:29:07 2010 -0600
+++ b/include/liblas/lasreader.hpp	Thu Dec 09 16:14:39 2010 -0600
@@ -145,21 +145,8 @@
     Reader& operator=(Reader const& rhs);
 
     void Init(); // throws on error
-    // bool KeepPoint(liblas::Point const& p);
-
     const std::auto_ptr<ReaderI> m_pimpl;
 
-    HeaderPtr m_header;
-    Point* m_point;
-    PointPtr m_empty_point;
-    
-    
-    // Set if the user provides a header to override the header as 
-    // read from the istream
-    bool bCustomHeader;
-    
-    // std::vector<liblas::FilterPtr> m_filters;
-    // std::vector<liblas::TransformPtr> m_transforms;
 
 };
 
diff -r 34d5d9cb5d36 -r 281a5b82de9c include/liblas/liblas.hpp
--- a/include/liblas/liblas.hpp	Tue Dec 07 08:29:07 2010 -0600
+++ b/include/liblas/liblas.hpp	Thu Dec 09 16:14:39 2010 -0600
@@ -122,12 +122,15 @@
 {
 public:
 
-    virtual HeaderPtr ReadHeader() = 0;
-    virtual Point const& ReadNextPoint(HeaderPtr header) = 0;
-    virtual Point const& ReadPointAt(std::size_t n, HeaderPtr header) = 0;
-    virtual void Seek(std::size_t n, HeaderPtr header) = 0;
+    virtual liblas::Header const& GetHeader() const = 0;
+    virtual void ReadHeader() = 0;
+    virtual void SetHeader(liblas::Header const& header) = 0;
+    virtual liblas::Point const& GetPoint() const = 0;
+    virtual void ReadNextPoint() = 0;
+    virtual Point const& ReadPointAt(std::size_t n) = 0;
+    virtual void Seek(std::size_t n) = 0;
     
-    virtual void Reset(HeaderPtr header) = 0;
+    virtual void Reset() = 0;
     
     virtual void SetFilters(std::vector<liblas::FilterPtr> const& filters) = 0;
     virtual void SetTransforms(std::vector<liblas::TransformPtr> const& transforms) = 0;
diff -r 34d5d9cb5d36 -r 281a5b82de9c src/detail/reader/cachedreader.cpp
--- a/src/detail/reader/cachedreader.cpp	Tue Dec 07 08:29:07 2010 -0600
+++ b/src/detail/reader/cachedreader.cpp	Thu Dec 09 16:14:39 2010 -0600
@@ -70,9 +70,10 @@
 {
 }
 
-HeaderPtr CachedReaderImpl::ReadHeader()
+void CachedReaderImpl::ReadHeader()
 {
-    HeaderPtr hptr = ReaderImpl::ReadHeader();
+    ReaderImpl::ReadHeader();
+    HeaderPtr hptr(new liblas::Header(ReaderImpl::GetHeader()));
     
     // If we were given no cache size, try to cache the whole thing
     if (m_cache_size == 0) {
@@ -90,15 +91,15 @@
     // boost::uint8_t const uncached_mask = 0;
     // cache_mask_type(hptr->GetPointRecordsCount(), uncached_mask).swap(m_mask);
     
-    return hptr;
+    m_header = hptr;
 }
 
-void CachedReaderImpl::CacheData(boost::uint32_t position, HeaderPtr header) 
+void CachedReaderImpl::CacheData(boost::uint32_t position) 
 {
     cache_mask_type::size_type old_cache_start_position = m_cache_start_position;
     m_cache_start_position = position;
 
-    cache_mask_type::size_type header_size = static_cast<cache_mask_type::size_type>(header->GetPointRecordsCount());
+    cache_mask_type::size_type header_size = static_cast<cache_mask_type::size_type>(m_header->GetPointRecordsCount());
     cache_mask_type::size_type left_to_cache = std::min(m_cache_size, header_size - m_cache_start_position);
 
     cache_mask_type::size_type to_mark = std::min(m_cache_size, header_size - old_cache_start_position);
@@ -111,7 +112,7 @@
     // 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);
+        CachedReaderImpl::Seek(position);
         m_current = position;
     }
     m_cache_read_position =  position;
@@ -120,7 +121,8 @@
     {
         try {
             m_mask[m_current] = 1;
-            m_cache[i] = ReaderImpl::ReadNextPoint(header);
+            ReadNextUncachedPoint();
+            m_cache[i] = ReaderImpl::GetPoint();
         } catch (std::out_of_range&) {
             // cached to the end
             break;
@@ -128,7 +130,31 @@
     }
 }
 
-liblas::Point const& CachedReaderImpl::ReadCachedPoint(boost::uint32_t position, HeaderPtr header) {
+void CachedReaderImpl::ReadNextUncachedPoint()
+{
+    if (0 == m_current)
+    {
+        m_ifs.clear();
+        m_ifs.seekg(m_header->GetDataOffset(), std::ios::beg);
+    }
+
+    if (m_current >= m_size ){
+        throw std::out_of_range("ReadNextPoint: file has no more points to read, end of file reached");
+    } 
+
+    m_point_reader->read();
+    ++m_current;
+    *m_point = m_point_reader->GetPoint();
+
+
+    if (!m_transforms.empty())
+    {
+        ReaderImpl::TransformPoint(*m_point);
+    }
+
+}
+
+void CachedReaderImpl::ReadCachedPoint(boost::uint32_t position) {
     
     int32_t cache_position = position - m_cache_start_position ;
 
@@ -150,16 +176,17 @@
         // Mark all positions as uncached and build up the mask
         // to the size of the number of points in the file
         boost::uint8_t const uncached_mask = 0;
-        cache_mask_type(header->GetPointRecordsCount(), uncached_mask).swap(m_mask);
+        cache_mask_type(m_header->GetPointRecordsCount(), uncached_mask).swap(m_mask);
  
         m_cache_initialized = true;
     }
     if (m_mask[position] == 1) {
         m_cache_read_position = position;
-        return m_cache[cache_position];
+        *m_point =  m_cache[cache_position];
+        return;
     } else {
 
-        CacheData(position, header);
+        CacheData(position);
         
         // At this point, we can't have a negative cache position.
         // If we do, it's a big error or we'll segfault.
@@ -182,7 +209,8 @@
                     << " greater than cache size: " << m_cache.size() ;
                 throw std::runtime_error(msg.str());
             }
-            return m_cache[cache_position];
+            *m_point = m_cache[cache_position];
+            return;
         } else {
             std::ostringstream msg;
             msg << "ReadCachedPoint:: unable to obtain cached point"
@@ -195,7 +223,7 @@
     }
 }
 
-liblas::Point const& CachedReaderImpl::ReadNextPoint(HeaderPtr header)
+void CachedReaderImpl::ReadNextPoint()
 {
     if (m_cache_read_position == m_size )
     {
@@ -203,12 +231,12 @@
     }
     
     // PointPtr ptr = ReadCachedPoint(m_cache_read_position, header);
-    liblas::Point const& point = ReadCachedPoint(m_cache_read_position, header);
+    ReadCachedPoint(m_cache_read_position);
     ++m_cache_read_position;
-    return point;
+    
 }
 
-liblas::Point const& CachedReaderImpl::ReadPointAt(std::size_t n, HeaderPtr header)
+liblas::Point const& CachedReaderImpl::ReadPointAt(std::size_t n)
 {
 
     if (n >= m_size ){
@@ -223,22 +251,22 @@
         throw std::runtime_error(out);
     }
     
-    liblas::Point const& p = ReadCachedPoint(n, header);
+    ReadCachedPoint(n);
     m_cache_read_position = n;
-    return p;
+    return *m_point;
 }
 
-void CachedReaderImpl::Reset(HeaderPtr header)
+void CachedReaderImpl::Reset()
 {
     if (m_mask.empty())
     {    


More information about the Liblas-commits mailing list