[Liblas-commits] hg: some cleanup of GetStream and ReaderFactory

liblas-commits at liblas.org liblas-commits at liblas.org
Tue May 4 12:38:37 EDT 2010


changeset 5a3c264b030e in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=5a3c264b030e
summary: some cleanup of GetStream and ReaderFactory

diffstat:

 include/liblas/detail/reader/reader.hpp |   19 +-
 include/liblas/lasreader.hpp            |    2 +-
 include/liblas/liblas.hpp               |    6 +-
 src/detail/reader/reader.cpp            |  181 ++++++++++---------------------
 src/lasreader.cpp                       |   25 ++-
 5 files changed, 89 insertions(+), 144 deletions(-)

diffs (truncated from 353 to 300 lines):

diff -r d209d6f51200 -r 5a3c264b030e include/liblas/detail/reader/reader.hpp
--- a/include/liblas/detail/reader/reader.hpp	Mon May 03 12:05:11 2010 -0500
+++ b/include/liblas/detail/reader/reader.hpp	Tue May 04 11:38:30 2010 -0500
@@ -71,6 +71,7 @@
     liblas::Point const& ReadPointAt(std::size_t n, const liblas::Header& header);
 
     std::istream& GetStream() const;
+    
     void Reset(liblas::Header const& header);
     void SetSRS(const SpatialReference& srs, const liblas::Header& header);
     void SetInputSRS(const SpatialReference& srs);
@@ -123,7 +124,7 @@
     // Blocked copying operations, declared but not defined.
     CachedReaderImpl(CachedReaderImpl const& other);
     CachedReaderImpl& operator=(CachedReaderImpl const& rhs);
-    liblas::Point const& GetPoint(liblas::uint32_t position, const liblas::Header& header);
+    liblas::Point const& ReadCachedPoint(liblas::uint32_t position, const liblas::Header& header);
         
     liblas::uint64_t m_cache_size;
     std::vector<bool> m_mask;
@@ -134,14 +135,14 @@
 
 };
 
-class ReaderFactory
-{
-public:
-
-    // TODO: prototypes
-    static ReaderImpl* Create(std::istream& ifs);
-    static void Destroy(ReaderImpl* p);
-};
+// class ReaderFactory
+// {
+// public:
+// 
+//     // TODO: prototypes
+//     static ReaderImpl* Create(std::istream& ifs);
+//     static void Destroy(ReaderImpl* p);
+// };
 
 
 }} // namespace liblas::detail
diff -r d209d6f51200 -r 5a3c264b030e include/liblas/lasreader.hpp
--- a/include/liblas/lasreader.hpp	Mon May 03 12:05:11 2010 -0500
+++ b/include/liblas/lasreader.hpp	Tue May 04 11:38:30 2010 -0500
@@ -151,7 +151,7 @@
     // read from the istream
     bool bCustomHeader;
 
-    std::istream& m_ifs;
+    // std::istream& m_ifs;
     
 };
 
diff -r d209d6f51200 -r 5a3c264b030e include/liblas/liblas.hpp
--- a/include/liblas/liblas.hpp	Mon May 03 12:05:11 2010 -0500
+++ b/include/liblas/liblas.hpp	Tue May 04 11:38:30 2010 -0500
@@ -159,7 +159,9 @@
     virtual void Reset(const Header& header) = 0;
     virtual void SetInputSRS(const SpatialReference& srs) = 0;
     virtual void SetOutputSRS(const SpatialReference& srs, const Header& header) = 0;
-
+    
+    virtual std::istream& GetStream() const = 0;
+    
     virtual ~ReaderI() {};    
 };
 
@@ -174,6 +176,8 @@
     virtual void SetInputSRS(const SpatialReference& srs) = 0;
     virtual void SetOutputSRS(const SpatialReference& srs, const Header& header) = 0;
 
+    virtual std::ostream& GetStream() const = 0;
+
     virtual ~WriterI() {};    
 
 };
diff -r d209d6f51200 -r 5a3c264b030e src/detail/reader/reader.cpp
--- a/src/detail/reader/reader.cpp	Mon May 03 12:05:11 2010 -0500
+++ b/src/detail/reader/reader.cpp	Tue May 04 11:38:30 2010 -0500
@@ -270,7 +270,7 @@
     return header;
 }
 
-liblas::Point const& CachedReaderImpl::GetPoint(liblas::uint32_t position, const liblas::Header& header) {
+liblas::Point const& CachedReaderImpl::ReadCachedPoint(liblas::uint32_t position, const liblas::Header& header) {
     
     int32_t cache_position = position - m_cache_start_position ;
 
@@ -367,97 +367,29 @@
 
 liblas::Point const& CachedReaderImpl::ReadNextPoint(const liblas::Header& header)
 {
-    // uint32_t pos = m_current;
-    // std::cout   << "m_mask[m_cache_read_position]: " << m_mask[m_cache_read_position] 
-    //             << " m_current: " << m_current
-    //             << " m_size: " << m_size 
-    //             << " m_cache_read_position: " << m_cache_read_position 
-    //             << " m_cache_start_position: " << m_cache_start_position 
-    // //             <<std::endl;
     if (m_cache_read_position == m_size ){
         throw std::out_of_range("file has no more points to read, end of file reached");
     }
     
-     
-    // ++m_cache_read_position;
-    liblas::Point const& point = GetPoint(m_cache_read_position, header);
-    // if (point.GetX() == 0 || point.GetY() == 0.0 || point.GetReturnNumber() == 0) {
-    //     printf("X is zero for position %d\n", m_cache_read_position);
-    // }
+    liblas::Point const& point = ReadCachedPoint(m_cache_read_position, header);
     return point;
-    
-    // if (m_mask[m_cache_read_position] == true) {
-    //     // printf("have cached point at %d giving %d as the cached point\n", m_cache_read_position, m_cache_read_position - m_cache_start_position);
-    //     ++m_cache_read_position;
-    //     
-    //     uint32_t position = m_cache_read_position - m_cache_start_position - 1;
-    //     
-    //     // // If we're reading the very first point, we have already incremented 
-    //     // // the m_cache_read_position
-    //     // if (m_cache_read_position == 0 && m_cache_start_position == 0) {
-    //     //     position = position + 1;
-    //     // }
-    //     return m_cache[position];
-    // } else {
-    //     
-    // 
-    //     
-    //     uint32_t left_to_cache = std::min(m_cache_size, header.GetPointRecordsCount() - m_cache_start_position);
-    //     // printf("number of points left to cache: %d\n", left_to_cache);
-    //     // printf("old cache position %d\n", m_cache_start_position);
-    //     
-    //     // std::cout << "MASK: ";
-    //     // std::vector<bool>::iterator it;
-    //     // for (it = m_mask.begin(); it != m_mask.end(); ++it) {
-    //     //     std::cout << *it << ",";
-    //     // }
-    //     // std::cout << std::endl;
-    //     
-    //     // Mark old points as uncached
-    //     uint32_t to_mark = std::max(m_cache_size, static_cast<liblas::uint64_t>(left_to_cache));
-    //     for (uint32_t i = 0; i < to_mark; ++i) {
-    //         // printf ("Marking %d position false\n", m_cache_start_position + i);
-    //         m_mask[m_cache_start_position + i] = false;
-    //     }
-    //     // printf("number of points to mark: %d\n", to_mark);
-    //     
-    //     m_cache_start_position =  m_cache_read_position;
-    // 
-    //     for (uint32_t i = 0; i < left_to_cache; ++i) {
-    //         
-    //         try {
-    //             m_mask[m_current] = true;
-    //             m_cache[i] = ReaderImpl::ReadNextPoint(header);
-    //         } catch (std::out_of_range&) {
-    //             // cached to the end
-    //             break;
-    //         }
-    //         // printf("cached %d points at position %d with m_current: %d\n", i, m_cache_start_position, m_current);
-    // 
-    //     }
-    //     // 
-    //     // std::cout << "MASK: ";
-    //     // for (it = m_mask.begin(); it != m_mask.end(); ++it) {
-    //     //     std::cout << *it << ",";
-    //     // }
-    //     // std::cout << std::endl;
-    //     // printf("new m_cache_start_position: %d m_cache_read_position: %d\n", m_cache_start_position, m_cache_read_position);
-    //     ++m_cache_read_position;
-    //     
-    //     uint32_t position = m_cache_read_position - m_cache_start_position - 1;
-    //     // if (m_cache_read_position == 0 && m_cache_start_position == 0) {
-    //     //     position = position + 1;
-    //     // }
-    //     // printf("returning cache position %d\n", position);
-    //     return m_cache[position];
-    // }
-    // return ReaderImpl::ReadNextPoint(header);
 }
 
 liblas::Point const& CachedReaderImpl::ReadPointAt(std::size_t n, const liblas::Header& header)
 {
+
+    if (n >= m_size ){
+        throw std::out_of_range("file has no more points to read, end of file reached");
     
+    } else if (m_size < n) {
+        std::ostringstream output;
+        output << "ReadPointAt:: Inputted value: " << n << " is greater than the number of points: " << m_size;
+        std::string out(output.str());
+        throw std::runtime_error(out);
+    }
     return ReaderImpl::ReadPointAt(n, header);
+    // return ReadCachedPoint(n, header);
+
 }
 
 // CachedReaderImpl::~CachedReaderImpl()
@@ -465,50 +397,51 @@
 //     ~ReaderImpl();
 // }
 
-ReaderImpl* ReaderFactory::Create(std::istream& ifs)
-{
-    if (!ifs)
-    {
-        throw std::runtime_error("input stream state is invalid");
-    }
+// ReaderImpl* ReaderFactory::Create(std::istream& ifs)
+// {
+//     if (!ifs)
+//     {
+//         throw std::runtime_error("input stream state is invalid");
+//     }
+// 
+//     // Determine version of given LAS file and
+//     // instantiate appropriate reader.
+//     // uint8_t verMajor = 0;
+//     // uint8_t verMinor = 0;
+//     // ifs.seekg(24, std::ios::beg);
+//     // detail::read_n(verMajor, ifs, 1);
+//     // detail::read_n(verMinor, ifs, 1);
+//     
+//     return new ReaderImpl(ifs);
+//     // return new CachedReaderImpl(ifs, 3);
+//     
+//     // if (1 == verMajor && 0 == verMinor)
+//     // {
+//     // 
+//     //     return new ReaderImpl(ifs);
+//     // }
+//     // else if (1 == verMajor && 1 == verMinor)
+//     // {
+//     //     return new v11::ReaderImpl(ifs);
+//     // }
+//     // else if (1 == verMajor && 2 == verMinor)
+//     // {
+//     //     return new v12::ReaderImpl(ifs);
+//     // }
+//     // else if (2 == verMajor && 0 == verMinor )
+//     // {
+//     //     // TODO: LAS 2.0 read/write support
+//     //     throw std::runtime_error("LAS 2.0+ file detected but unsupported");
+//     // }
+// 
+//     // throw std::runtime_error("LAS file of unknown version");
+// }
 
-    // Determine version of given LAS file and
-    // instantiate appropriate reader.
-    // uint8_t verMajor = 0;
-    // uint8_t verMinor = 0;
-    // ifs.seekg(24, std::ios::beg);
-    // detail::read_n(verMajor, ifs, 1);
-    // detail::read_n(verMinor, ifs, 1);
 
-    return new CachedReaderImpl(ifs, 3);
-    
-    // if (1 == verMajor && 0 == verMinor)
-    // {
-    // 
-    //     return new ReaderImpl(ifs);
-    // }
-    // else if (1 == verMajor && 1 == verMinor)
-    // {
-    //     return new v11::ReaderImpl(ifs);
-    // }
-    // else if (1 == verMajor && 2 == verMinor)
-    // {
-    //     return new v12::ReaderImpl(ifs);
-    // }
-    // else if (2 == verMajor && 0 == verMinor )
-    // {
-    //     // TODO: LAS 2.0 read/write support
-    //     throw std::runtime_error("LAS 2.0+ file detected but unsupported");
-    // }
-
-    // throw std::runtime_error("LAS file of unknown version");
-}
-
-
-void ReaderFactory::Destroy(ReaderImpl* p) 
-{
-    delete p;
-    p = 0;
-}
+// void ReaderFactory::Destroy(ReaderImpl* p) 
+// {
+//     delete p;
+//     p = 0;
+// }
 }} // namespace liblas::detail
 
diff -r d209d6f51200 -r 5a3c264b030e src/lasreader.cpp
--- a/src/lasreader.cpp	Mon May 03 12:05:11 2010 -0500
+++ b/src/lasreader.cpp	Tue May 04 11:38:30 2010 -0500
@@ -57,22 +57,28 @@
 {


More information about the Liblas-commits mailing list