[Liblas-commits] hg: 2 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Aug 16 15:21:52 EDT 2010


changeset 2270ceb210ab in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=2270ceb210ab
summary: add prototype for making a cached reader vs. an uncached one

changeset 951cd16484b9 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=951cd16484b9
summary: segregate CachedReaderImpl from ReaderImpl

diffstat:

 include/liblas/detail/reader/cachedreader.hpp |   97 +++++++++
 include/liblas/detail/reader/reader.hpp       |   35 ---
 include/liblas/lasreader.hpp                  |    1 +
 src/CMakeLists.txt                            |    6 +-
 src/detail/reader/cachedreader.cpp            |  257 ++++++++++++++++++++++++++
 src/detail/reader/reader.cpp                  |  192 -------------------
 src/lasreader.cpp                             |   15 +-
 7 files changed, 373 insertions(+), 230 deletions(-)

diffs (truncated from 682 to 300 lines):

diff -r 11422dede1a9 -r 951cd16484b9 include/liblas/detail/reader/cachedreader.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/liblas/detail/reader/cachedreader.hpp	Mon Aug 16 14:21:42 2010 -0500
@@ -0,0 +1,97 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose:  LAS 1.0 reader implementation for C++ libLAS 
+ * Author:   Mateusz Loskot, mateusz at loskot.net
+ *
+ ******************************************************************************
+ * Copyright (c) 2008, Mateusz Loskot
+ *
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without 
+ * modification, are permitted provided that the following 
+ * conditions are met:
+ * 
+ *     * Redistributions of source code must retain the above copyright 
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright 
+ *       notice, this list of conditions and the following disclaimer in 
+ *       the documentation and/or other materials provided 
+ *       with the distribution.
+ *     * Neither the name of the Martin Isenburg or Iowa Department 
+ *       of Natural Resources nor the names of its contributors may be 
+ *       used to endorse or promote products derived from this software 
+ *       without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
+ * OF SUCH DAMAGE.
+ ****************************************************************************/
+
+#ifndef LIBLAS_DETAIL_CACHEDREADERIMPL_HPP_INCLUDED
+#define LIBLAS_DETAIL_CACHEDREADERIMPL_HPP_INCLUDED
+
+#include <liblas/detail/fwd.hpp>
+#include <liblas/detail/reader/point.hpp>
+#include <liblas/detail/reader/header.hpp>
+#include <liblas/liblas.hpp>
+// boost
+#include <boost/cstdint.hpp>
+// std
+#include <iosfwd>
+#include <boost/shared_ptr.hpp>
+
+namespace liblas { namespace detail { 
+
+
+class CachedReaderImpl : public ReaderImpl
+{
+public:
+
+    CachedReaderImpl(std::istream& ifs, std::size_t cache_size);
+    // ~CachedReaderImpl();
+
+    HeaderPtr ReadHeader();
+    PointPtr ReadNextPoint(HeaderPtr header);
+    liblas::Point const& ReadPointAt(std::size_t n, HeaderPtr header);
+    // void SetOutputSRS(const SpatialReference& srs, const liblas::Header& header);
+
+    void Seek(std::size_t n, HeaderPtr header);
+    void Reset(HeaderPtr header);
+
+protected:
+
+private:
+
+    // Blocked copying operations, declared but not defined.
+    CachedReaderImpl(CachedReaderImpl const& other);
+    CachedReaderImpl& operator=(CachedReaderImpl const& rhs);
+    PointPtr ReadCachedPoint(boost::uint32_t position, HeaderPtr header);
+    
+    void CacheData(boost::uint32_t position, HeaderPtr header);
+
+    typedef std::vector<boost::uint8_t> cache_mask_type;
+    cache_mask_type m_mask;
+    cache_mask_type::size_type m_cache_size;    
+    cache_mask_type::size_type m_cache_start_position;
+    cache_mask_type::size_type m_cache_read_position;
+
+    typedef std::vector<PointPtr> cache_type;
+    cache_type m_cache;
+};
+
+
+}} // namespace liblas::detail
+
+#endif // LIBLAS_DETAIL_CACHEDREADERIMPL_HPP_INCLUDED
diff -r 11422dede1a9 -r 951cd16484b9 include/liblas/detail/reader/reader.hpp
--- a/include/liblas/detail/reader/reader.hpp	Mon Aug 16 14:04:31 2010 -0500
+++ b/include/liblas/detail/reader/reader.hpp	Mon Aug 16 14:21:42 2010 -0500
@@ -93,41 +93,6 @@
     ReaderImpl& operator=(ReaderImpl const& rhs);
 };
 
-class CachedReaderImpl : public ReaderImpl
-{
-public:
-
-    CachedReaderImpl(std::istream& ifs, std::size_t cache_size);
-    // ~CachedReaderImpl();
-
-    HeaderPtr ReadHeader();
-    PointPtr ReadNextPoint(HeaderPtr header);
-    liblas::Point const& ReadPointAt(std::size_t n, HeaderPtr header);
-    // void SetOutputSRS(const SpatialReference& srs, const liblas::Header& header);
-
-    void Seek(std::size_t n, HeaderPtr header);
-    void Reset(HeaderPtr header);
-
-protected:
-
-private:
-
-    // Blocked copying operations, declared but not defined.
-    CachedReaderImpl(CachedReaderImpl const& other);
-    CachedReaderImpl& operator=(CachedReaderImpl const& rhs);
-    PointPtr ReadCachedPoint(boost::uint32_t position, HeaderPtr header);
-    
-    void CacheData(boost::uint32_t position, HeaderPtr header);
-
-    typedef std::vector<boost::uint8_t> cache_mask_type;
-    cache_mask_type m_mask;
-    cache_mask_type::size_type m_cache_size;    
-    cache_mask_type::size_type m_cache_start_position;
-    cache_mask_type::size_type m_cache_read_position;
-
-    typedef std::vector<PointPtr> cache_type;
-    cache_type m_cache;
-};
 
 // class ReaderFactory
 // {
diff -r 11422dede1a9 -r 951cd16484b9 include/liblas/lasreader.hpp
--- a/include/liblas/lasreader.hpp	Mon Aug 16 14:04:31 2010 -0500
+++ b/include/liblas/lasreader.hpp	Mon Aug 16 14:21:42 2010 -0500
@@ -68,6 +68,7 @@
     /// @param ifs - stream used as source of LAS records.
     /// @excepion std::runtime_error - on failure state of the input stream.
     Reader(std::istream& ifs);
+    Reader(std::istream& ifs, uint32_t cache_size);
 
     Reader(ReaderI* reader);
     
diff -r 11422dede1a9 -r 951cd16484b9 src/CMakeLists.txt
--- a/src/CMakeLists.txt	Mon Aug 16 14:04:31 2010 -0500
+++ b/src/CMakeLists.txt	Mon Aug 16 14:21:42 2010 -0500
@@ -54,7 +54,8 @@
   ${LIBLAS_HEADERS_DIR}/detail/index/indexcell.hpp)
   
 set(LIBLAS_DETAIL_READER_HPP
-  ${LIBLAS_HEADERS_DIR}/detail/reader/reader.hpp
+  ${LIBLAS_HEADERS_DIR}/detail/reader/cachedreader.hpp
+  ${LIBLAS_HEADERS_DIR}/detail/reader/reader.hpp  
   ${LIBLAS_HEADERS_DIR}/detail/reader/header.hpp
   ${LIBLAS_HEADERS_DIR}/detail/reader/point.hpp)
 
@@ -89,7 +90,8 @@
 set(LIBLAS_DETAIL_READER_CPP
   detail/reader/header.cpp
   detail/reader/point.cpp
-  detail/reader/reader.cpp)
+  detail/reader/reader.cpp
+  detail/reader/cachedreader.cpp)
 
 set(LIBLAS_DETAIL_WRITER_CPP
   detail/writer/base.cpp
diff -r 11422dede1a9 -r 951cd16484b9 src/detail/reader/cachedreader.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/detail/reader/cachedreader.cpp	Mon Aug 16 14:21:42 2010 -0500
@@ -0,0 +1,257 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose:  LAS 1.0 reader implementation for C++ libLAS 
+ * Author:   Mateusz Loskot, mateusz at loskot.net
+ *
+ ******************************************************************************
+ * Copyright (c) 2008, Mateusz Loskot
+ *
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without 
+ * modification, are permitted provided that the following 
+ * conditions are met:
+ * 
+ *     * Redistributions of source code must retain the above copyright 
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright 
+ *       notice, this list of conditions and the following disclaimer in 
+ *       the documentation and/or other materials provided 
+ *       with the distribution.
+ *     * Neither the name of the Martin Isenburg or Iowa Department 
+ *       of Natural Resources nor the names of its contributors may be 
+ *       used to endorse or promote products derived from this software 
+ *       without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
+ * OF SUCH DAMAGE.
+ ****************************************************************************/
+
+#include <liblas/detail/reader/reader.hpp>
+#include <liblas/detail/reader/cachedreader.hpp>
+#include <liblas/detail/utility.hpp>
+#include <liblas/liblas.hpp>
+#include <liblas/lasheader.hpp>
+#include <liblas/laspoint.hpp>
+// boost
+#include <boost/cstdint.hpp>
+// std
+#include <fstream>
+#include <istream>
+#include <iostream>
+#include <stdexcept>
+#include <cstddef> // std::size_t
+#include <cstdlib> // std::free
+#include <cassert>
+
+using namespace boost;
+
+namespace liblas { namespace detail { 
+
+
+CachedReaderImpl::CachedReaderImpl(std::istream& ifs , std::size_t size)
+    : ReaderImpl(ifs)
+    , m_cache_size(size)
+    , m_cache_start_position(0)
+    , m_cache_read_position(0)
+{
+}
+
+HeaderPtr CachedReaderImpl::ReadHeader()
+{
+    HeaderPtr hptr = ReaderImpl::ReadHeader();
+    
+    // If we were given no cache size, try to cache the whole thing
+    if (m_cache_size == 0) {
+        m_cache_size = hptr->GetPointRecordsCount();
+    }
+
+    if (m_cache_size > hptr->GetPointRecordsCount()) {
+        m_cache_size = hptr->GetPointRecordsCount();
+    }
+    m_cache.resize(m_cache_size);
+    
+    // Mark all positions as uncached and build up the mask
+    // to the size of the number of points in the file
+    for (boost::uint32_t i = 0; i < hptr->GetPointRecordsCount(); ++i) {
+        m_mask.push_back(0);
+    }
+    
+    return hptr;
+}
+
+void CachedReaderImpl::CacheData(boost::uint32_t position, HeaderPtr header) 
+{
+    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 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);
+
+    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;


More information about the Liblas-commits mailing list