[Liblas-commits] hg: consolidate header reading with detail::reader::Header

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Jan 29 16:35:14 EST 2010


changeset ec0c8455b179 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=ec0c8455b179
summary: consolidate header reading with detail::reader::Header

diffstat:

 include/Makefile.am                     |    1 +
 include/liblas/detail/reader/header.hpp |   85 ++++++++++
 src/Makefile.am                         |    1 +
 src/detail/reader/header.cpp            |  271 ++++++++++++++++++++++++++++++++
 src/detail/reader/reader.cpp            |    1 +
 src/detail/reader/reader10.cpp          |  163 +------------------
 src/detail/reader/reader11.cpp          |  164 +------------------
 src/detail/reader/reader12.cpp          |  166 +------------------
 8 files changed, 376 insertions(+), 476 deletions(-)

diffs (truncated from 944 to 300 lines):

diff -r b696e7b2fee8 -r ec0c8455b179 include/Makefile.am
--- a/include/Makefile.am	Fri Jan 29 11:24:03 2010 -0600
+++ b/include/Makefile.am	Fri Jan 29 15:30:33 2010 -0600
@@ -26,6 +26,7 @@
     liblas/detail/reader/reader11.hpp \
     liblas/detail/reader/reader12.hpp \
     liblas/detail/reader/vlr.hpp \
+    liblas/detail/reader/header.hpp \
     liblas/detail/sha1.hpp \
     liblas/detail/sharedptr.hpp \
     liblas/detail/timer.hpp \
diff -r b696e7b2fee8 -r ec0c8455b179 include/liblas/detail/reader/header.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/liblas/detail/reader/header.hpp	Fri Jan 29 15:30:33 2010 -0600
@@ -0,0 +1,85 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose:  Header 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_HEADER_HPP_INCLUDED
+#define LIBLAS_DETAIL_READER_HEADER_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 Header
+{
+public:
+
+    Header(std::istream& ifs);
+    virtual ~Header();
+
+    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.
+    Header(Header const& other);
+    Header& operator=(Header const& rhs);
+    
+    bool HasLAS10PadSignature();
+
+};
+
+
+}}} // namespace liblas::detail::reader
+
+#endif // LIBLAS_DETAIL_READER_HEADER_HPP_INCLUDED
diff -r b696e7b2fee8 -r ec0c8455b179 src/Makefile.am
--- a/src/Makefile.am	Fri Jan 29 11:24:03 2010 -0600
+++ b/src/Makefile.am	Fri Jan 29 15:30:33 2010 -0600
@@ -42,6 +42,7 @@
 	detail/reader/reader11.cpp \
 	detail/reader/reader12.cpp \
 	detail/reader/vlr.cpp \
+	detail/reader/header.cpp \
 	detail/writer.cpp \
 	detail/writer10.cpp \
 	detail/writer11.cpp \
diff -r b696e7b2fee8 -r ec0c8455b179 src/detail/reader/header.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/detail/reader/header.cpp	Fri Jan 29 15:30:33 2010 -0600
@@ -0,0 +1,271 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose:  Header 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/header.hpp>
+#include <liblas/detail/utility.hpp>
+#include <liblas/lasheader.hpp>
+#include <liblas/lasvariablerecord.hpp>
+
+
+namespace liblas { namespace detail { namespace reader {
+
+Header::Header(std::istream& ifs) :
+    m_ifs(ifs)
+{
+}
+
+Header::~Header()
+{
+
+}
+
+
+void Header::read()
+{
+    using detail::read_n;
+
+    // Helper variables
+    uint8_t n1 = 0;
+    uint16_t n2 = 0;
+    uint32_t n4 = 0;
+    double x1 = 0;
+    double y1 = 0;
+    double z1 = 0;
+    double x2 = 0;
+    double y2 = 0;
+    double z2 = 0;
+    std::string buf;
+    std::string fsig;
+
+    m_ifs.seekg(0);
+
+    // 1. File Signature
+    read_n(fsig, m_ifs, 4);
+    m_header.SetFileSignature(fsig);
+
+    // 2. File Source ID
+    read_n(n2, m_ifs, sizeof(n2));
+    m_header.SetFileSourceId(n2);
+
+    // 3. Reserved
+    // This data must always contain Zeros.
+    read_n(n2, m_ifs, sizeof(n2));
+
+    // 4-7. Project ID
+    uint32_t d1 = 0;
+    uint16_t d2 = 0;
+    uint16_t d3 = 0;
+    uint8_t d4[8] = { 0 };
+    read_n(d1, m_ifs, sizeof(d1));
+    read_n(d2, m_ifs, sizeof(d2));
+    read_n(d3, m_ifs, sizeof(d3));
+    read_n(d4, m_ifs, sizeof(d4));
+    liblas::guid g(d1, d2, d3, d4);
+    m_header.SetProjectId(g);
+
+    // 8. Version major
+    read_n(n1, m_ifs, sizeof(n1));
+    m_header.SetVersionMajor(n1);
+
+    // 9. Version minor
+    read_n(n1, m_ifs, sizeof(n1));
+    m_header.SetVersionMinor(n1);
+
+    // 10. System ID
+    read_n(buf, m_ifs, 32);
+    m_header.SetSystemId(buf);
+
+    // 11. Generating Software ID
+    read_n(buf, m_ifs, 32);
+    m_header.SetSoftwareId(buf);
+
+    // 12. File Creation Day of Year
+    read_n(n2, m_ifs, sizeof(n2));
+    m_header.SetCreationDOY(n2);
+
+    // 13. File Creation Year
+    read_n(n2, m_ifs, sizeof(n2));
+    m_header.SetCreationYear(n2);
+
+    // 14. Header Size
+    // NOTE: Size of the stanard header block must always be 227 bytes
+    read_n(n2, m_ifs, sizeof(n2));
+
+    // 15. Offset to data
+    read_n(n4, m_ifs, sizeof(n4));
+    if (n4 < m_header.GetHeaderSize())
+    {
+        // TODO: Move this test to LASHeader::Validate()
+        throw std::domain_error("offset to point data smaller than header size");
+    }
+    m_header.SetDataOffset(n4);
+
+    // 16. Number of variable length records
+    read_n(n4, m_ifs, sizeof(n4));
+    m_header.SetRecordsCount(n4);
+
+    // 17. Point Data Format ID
+    read_n(n1, m_ifs, sizeof(n1));
+    if (n1 == liblas::ePointFormat0)
+    {
+        m_header.SetDataFormatId(liblas::ePointFormat0);
+    } 
+    else if (n1 == liblas::ePointFormat1)
+    {
+        m_header.SetDataFormatId(liblas::ePointFormat1);
+    }
+    else if (n1 == liblas::ePointFormat2)
+    {
+        m_header.SetDataFormatId(liblas::ePointFormat2);
+    }
+    else if (n1 == liblas::ePointFormat3)
+    {
+        m_header.SetDataFormatId(liblas::ePointFormat3);
+    }
+    else
+    {
+        throw std::domain_error("invalid point data format");
+    }
+    
+    // 18. Point Data Record Length
+    read_n(n2, m_ifs, sizeof(n2));
+    m_header.SetDataRecordLength(n2);
+
+    // 19. Number of point records
+    read_n(n4, m_ifs, sizeof(n4));
+    m_header.SetPointRecordsCount(n4);
+
+    // 20. Number of points by return
+    std::vector<uint32_t>::size_type const srbyr = 5;
+    uint32_t rbyr[srbyr] = { 0 };
+    read_n(rbyr, m_ifs, sizeof(rbyr));
+    for (std::size_t i = 0; i < srbyr; ++i)
+    {
+        m_header.SetPointRecordsByReturnCount(i, rbyr[i]);
+    }
+
+    // 21-23. Scale factors


More information about the Liblas-commits mailing list