[Liblas-commits] hg: 2 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Jan 29 12:26:08 EST 2010


changeset c445567bfc6b in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=c445567bfc6b
summary: provide a GetVLRs() method to help eliminate some copying

changeset dabf631060e7 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=dabf631060e7
summary: refactor out a detail::reader::VLR class to handle VLR reading

diffstat:

 include/Makefile.am                     |    1 +
 include/liblas/detail/reader/reader.hpp |    1 -
 include/liblas/detail/reader/vlr.hpp    |   84 +++++++++++++++++++++++++
 include/liblas/lasheader.hpp            |    3 +
 src/Makefile.am                         |    1 +
 src/detail/reader/reader.cpp            |   55 +++-------------
 src/detail/reader/vlr.cpp               |  105 ++++++++++++++++++++++++++++++++
 src/lasheader.cpp                       |    5 +
 src/lasreader.cpp                       |    1 -
 9 files changed, 209 insertions(+), 47 deletions(-)

diffs (truncated from 350 to 300 lines):

diff -r 200c27551490 -r dabf631060e7 include/Makefile.am
--- a/include/Makefile.am	Fri Jan 29 10:21:08 2010 -0600
+++ b/include/Makefile.am	Fri Jan 29 11:21:09 2010 -0600
@@ -25,6 +25,7 @@
     liblas/detail/reader/reader10.hpp \
     liblas/detail/reader/reader11.hpp \
     liblas/detail/reader/reader12.hpp \
+    liblas/detail/reader/vlr.hpp \
     liblas/detail/sha1.hpp \
     liblas/detail/sharedptr.hpp \
     liblas/detail/timer.hpp \
diff -r 200c27551490 -r dabf631060e7 include/liblas/detail/reader/reader.hpp
--- a/include/liblas/detail/reader/reader.hpp	Fri Jan 29 10:21:08 2010 -0600
+++ b/include/liblas/detail/reader/reader.hpp	Fri Jan 29 11:21:09 2010 -0600
@@ -72,7 +72,6 @@
 
     std::istream& GetStream() const;
     bool ReadVLR(LASHeader& header);
-    bool ReadGeoreference(LASHeader& header);
     void Reset(LASHeader const& header);
     void SetSRS(const LASSpatialReference& srs);
     void SetInputSRS(const LASSpatialReference& srs);
diff -r 200c27551490 -r dabf631060e7 include/liblas/detail/reader/vlr.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/liblas/detail/reader/vlr.hpp	Fri Jan 29 11:21:09 2010 -0600
@@ -0,0 +1,84 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose:  VLR Reader implementation for C++ libLAS 
+ * Author:   Howard Butler, hobu.inc at gmail.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2010, Howard Butler
+ *
+ * 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_READER_VLR_HPP_INCLUDED
+#define LIBLAS_DETAIL_READER_VLR_HPP_INCLUDED
+
+#include <liblas/cstdint.hpp>
+#include <liblas/lasversion.hpp>
+#include <liblas/lasspatialreference.hpp>
+#include <liblas/detail/fwd.hpp>
+#include <liblas/lasheader.hpp>
+
+// std
+#include <iosfwd>
+
+namespace liblas { namespace detail { namespace reader {
+
+class VLR
+{
+public:
+
+    VLR(std::istream& ifs, const LASHeader& header);
+    virtual ~VLR();
+
+    std::istream& GetStream() const;
+    const LASHeader& GetHeader() const { return m_header; }
+    void read();
+    
+protected:
+
+    
+    std::istream& m_ifs;
+    LASHeader m_header;
+
+private:
+
+    // Blocked copying operations, declared but not defined.
+    VLR(VLR const& other);
+    VLR& operator=(VLR const& rhs);
+
+};
+
+
+}}} // namespace liblas::detail::reader
+
+#endif // LIBLAS_DETAIL_READER_VLR_HPP_INCLUDED
diff -r 200c27551490 -r dabf631060e7 include/liblas/lasheader.hpp
--- a/include/liblas/lasheader.hpp	Fri Jan 29 10:21:08 2010 -0600
+++ b/include/liblas/lasheader.hpp	Fri Jan 29 11:21:09 2010 -0600
@@ -300,6 +300,9 @@
     
     /// Returns a VLR 
     LASVariableRecord const& GetVLR(uint32_t index) const;
+    
+    /// Returns all of the VLRs
+    const std::vector<LASVariableRecord>& GetVLRs() const;
 
     /// Removes a VLR from the the header.
     void DeleteVLR(uint32_t index);
diff -r 200c27551490 -r dabf631060e7 src/Makefile.am
--- a/src/Makefile.am	Fri Jan 29 10:21:08 2010 -0600
+++ b/src/Makefile.am	Fri Jan 29 11:21:09 2010 -0600
@@ -41,6 +41,7 @@
 	detail/reader/reader10.cpp \
 	detail/reader/reader11.cpp \
 	detail/reader/reader12.cpp \
+	detail/reader/vlr.cpp \
 	detail/writer.cpp \
 	detail/writer10.cpp \
 	detail/writer11.cpp \
diff -r 200c27551490 -r dabf631060e7 src/detail/reader/reader.cpp
--- a/src/detail/reader/reader.cpp	Fri Jan 29 10:21:08 2010 -0600
+++ b/src/detail/reader/reader.cpp	Fri Jan 29 11:21:09 2010 -0600
@@ -39,11 +39,12 @@
  * OF SUCH DAMAGE.
  ****************************************************************************/
  
-#include <liblas/detail/reader.hpp>
-#include <liblas/detail/reader10.hpp>
-#include <liblas/detail/reader11.hpp>
-#include <liblas/detail/reader12.hpp>
+#include <liblas/detail/reader/reader.hpp>
+#include <liblas/detail/reader/reader10.hpp>
+#include <liblas/detail/reader/reader11.hpp>
+#include <liblas/detail/reader/reader12.hpp>
 #include <liblas/detail/utility.hpp>
+#include <liblas/detail/reader/vlr.hpp>
 #include <liblas/lasheader.hpp>
 #include <liblas/laspoint.hpp>
 #include <liblas/lasclassification.hpp>
@@ -129,48 +130,11 @@
 
 bool Reader::ReadVLR(LASHeader& header)
 {
-    VLRHeader vlrh = { 0 };
+    detail::reader::VLR reader(m_ifs, header);
+    reader.read();
+    header = reader.GetHeader();
 
-    m_ifs.seekg(header.GetHeaderSize(), std::ios::beg);
-    uint32_t count = header.GetRecordsCount();
-    header.SetRecordsCount(0);
-    for (uint32_t i = 0; i < count; ++i)
-    {
-        read_n(vlrh, m_ifs, sizeof(VLRHeader));
-
-        uint16_t length = vlrh.recordLengthAfterHeader;
-        if (length < 1)
-        {
-            throw std::domain_error("VLR record length must be at least 1 byte long");
-        } 
-        std::vector<uint8_t> data;
-        data.resize(length);
-
-        read_n(data.front(), m_ifs, length);
-         
-        LASVariableRecord vlr;
-        vlr.SetReserved(vlrh.reserved);
-        vlr.SetUserId(std::string(vlrh.userId));
-        vlr.SetDescription(std::string(vlrh.description));
-        vlr.SetRecordLength(vlrh.recordLengthAfterHeader);
-        vlr.SetRecordId(vlrh.recordId);
-        vlr.SetData(data);
-
-        header.AddVLR(vlr);
-    }
-    return true;
-}
-
-bool Reader::ReadGeoreference(LASHeader& header)
-{
-    std::vector<LASVariableRecord> vlrs;
-    for (uint16_t i = 0; i < header.GetRecordsCount(); ++i)
-    {
-        LASVariableRecord record = header.GetVLR(i);
-        vlrs.push_back(record);
-    }
-
-    LASSpatialReference srs(vlrs);    
+    LASSpatialReference srs(header.GetVLRs());    
     header.SetSRS(srs);
 
     // keep a copy on the reader in case we're going to reproject data 
@@ -180,6 +144,7 @@
     return true;
 }
 
+
 void Reader::Reset(LASHeader const& header)
 {
     m_ifs.clear();
diff -r 200c27551490 -r dabf631060e7 src/detail/reader/vlr.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/detail/reader/vlr.cpp	Fri Jan 29 11:21:09 2010 -0600
@@ -0,0 +1,105 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose:  VLR Reader implementation for C++ libLAS 
+ * Author:   Howard Butler, hobu.inc at gmail.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2010, Howard Butler
+ *
+ * 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/vlr.hpp>
+#include <liblas/detail/utility.hpp>
+#include <liblas/lasheader.hpp>
+#include <liblas/lasvariablerecord.hpp>
+
+
+namespace liblas { namespace detail { namespace reader {
+
+VLR::VLR(std::istream& ifs, const LASHeader& header) :
+    m_ifs(ifs), m_header(header)
+{
+}
+
+VLR::~VLR()
+{
+
+}
+
+std::istream& VLR::GetStream() const
+{
+    return m_ifs;
+}
+
+void VLR::read()
+{
+    VLRHeader vlrh = { 0 };
+
+    // seek to the start of the VLRs
+    m_ifs.seekg(m_header.GetHeaderSize(), std::ios::beg);
+
+    uint32_t count = m_header.GetRecordsCount();
+    
+    // We set the VLR records count to 0 because AddVLR 
+    // will ++ it each time we add a VLR instance to the 
+    // header.
+    m_header.SetRecordsCount(0);
+    for (uint32_t i = 0; i < count; ++i)
+    {
+        read_n(vlrh, m_ifs, sizeof(VLRHeader));
+


More information about the Liblas-commits mailing list