[Liblas-commits] hg-main-tree: liblaswriter now does header rewriting

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Apr 15 15:43:52 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/cf246805e92b
changeset: 568:cf246805e92b
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Apr 15 12:43:44 2011 -0700
description:
liblaswriter now does header rewriting

diffstat:

 include/libpc/drivers/las/SummaryData.hpp |   87 ++++++++++++++
 include/libpc/drivers/las/Support.hpp     |    9 +
 include/libpc/drivers/liblas/Writer.hpp   |    3 +
 src/CMakeLists.txt                        |    2 +
 src/drivers/las/SummaryData.cpp           |  175 ++++++++++++++++++++++++++++++
 src/drivers/las/Support.cpp               |   36 ++++++
 src/drivers/liblas/Writer.cpp             |   15 ++
 test/data/simple.las                      |    0 
 test/data/simple.laz                      |    0 
 test/unit/LiblasWriterTest.cpp            |    6 +-
 10 files changed, 330 insertions(+), 3 deletions(-)

diffs (truncated from 448 to 300 lines):

diff -r e1b1e9a852d4 -r cf246805e92b include/libpc/drivers/las/SummaryData.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/libpc/drivers/las/SummaryData.hpp	Fri Apr 15 12:43:44 2011 -0700
@@ -0,0 +1,87 @@
+/******************************************************************************
+* Copyright (c) 2011, Michael P. Gerlek (mpg at flaxen.com)
+*
+* 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 Hobu, Inc. or Flaxen Geo Consulting 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 INCLUDED_DRIVERS_LAS_SUMMARYDATA_HPP
+#define INCLUDED_DRIVERS_LAS_SUMMARYDATA_HPP
+
+#include <libpc/libpc.hpp>
+
+namespace libpc {
+namespace drivers {
+namespace las {
+
+class LIBPC_DLL SummaryData
+{
+public:
+    SummaryData();
+    ~SummaryData();
+
+    void reset();
+
+    // note that returnNumber is in the range [1..5]
+    void addPoint(double x, double y, double z, int returnNumber);
+
+    boost::uint32_t getTotalNumPoints() const;
+
+    void getBounds(double& minX, double& minY, double& minZ, double& maxX, double& maxY, double& maxZ) const;
+
+    // note that returnNumber is in the range [1..5]
+    boost::uint32_t getReturnCount(int returnNumber) const;
+
+    void dump(std::ostream&) const;
+
+    static const int s_maxNumReturns = 5;
+
+private:
+    bool m_isFirst;
+    double m_minX;
+    double m_minY;
+    double m_minZ;
+    double m_maxX;
+    double m_maxY;
+    double m_maxZ;
+    boost::uint32_t m_returnCounts[s_maxNumReturns];
+    boost::uint32_t m_totalNumPoints;
+
+    SummaryData& operator=(const SummaryData&); // not implemented
+    SummaryData(const SummaryData&); // not implemented
+};
+
+
+LIBPC_DLL std::ostream& operator<<(std::ostream& ostr, const SummaryData&);
+
+
+} } } // namespaces
+
+#endif
diff -r e1b1e9a852d4 -r cf246805e92b include/libpc/drivers/las/Support.hpp
--- a/include/libpc/drivers/las/Support.hpp	Thu Apr 14 13:45:48 2011 -0500
+++ b/include/libpc/drivers/las/Support.hpp	Fri Apr 15 12:43:44 2011 -0700
@@ -39,7 +39,12 @@
 
 #include <libpc/Schema.hpp>
 
+#include <iostream>
+
 namespace libpc { namespace drivers { namespace las {
+    
+class SummaryData;
+
 
 enum PointFormat
 {
@@ -90,6 +95,10 @@
     static bool hasColor(PointFormat);
     static bool hasWave(PointFormat);
     static boost::uint16_t getPointDataSize(PointFormat pointFormat);
+
+    // assumes the stream position is pointing to the first byte of the header
+    // this function updates the header's min/max xyz fields, and the point return counts fields
+    static void rewriteHeader(std::ostream& stream, const SummaryData& data);
 };
 
 
diff -r e1b1e9a852d4 -r cf246805e92b include/libpc/drivers/liblas/Writer.hpp
--- a/include/libpc/drivers/liblas/Writer.hpp	Thu Apr 14 13:45:48 2011 -0500
+++ b/include/libpc/drivers/liblas/Writer.hpp	Fri Apr 15 12:43:44 2011 -0700
@@ -39,6 +39,7 @@
 
 #include <libpc/Writer.hpp>
 #include <libpc/drivers/las/Support.hpp>
+#include <libpc/drivers/las/SummaryData.hpp>
 
 #include <liblas/liblas.hpp>
 #include <liblas/guid.hpp>
@@ -89,6 +90,8 @@
     ::liblas::Writer* m_externalWriter;
     ::liblas::HeaderPtr m_externalHeader;
 
+    ::libpc::drivers::las::SummaryData m_summaryData;
+
     LiblasWriter& operator=(const LiblasWriter&); // not implemented
     LiblasWriter(const LiblasWriter&); // not implemented
 };
diff -r e1b1e9a852d4 -r cf246805e92b src/CMakeLists.txt
--- a/src/CMakeLists.txt	Thu Apr 14 13:45:48 2011 -0500
+++ b/src/CMakeLists.txt	Fri Apr 15 12:43:44 2011 -0700
@@ -117,6 +117,7 @@
   ${LIBPC_HEADERS_DIR}/drivers/las/Header.hpp
   ${LIBPC_HEADERS_DIR}/drivers/las/Iterator.hpp
   ${LIBPC_HEADERS_DIR}/drivers/las/Reader.hpp
+  ${LIBPC_HEADERS_DIR}/drivers/las/SummaryData.hpp
   ${LIBPC_HEADERS_DIR}/drivers/las/Support.hpp
   ${LIBPC_HEADERS_DIR}/drivers/las/Writer.hpp
 )
@@ -127,6 +128,7 @@
   ./drivers/las/LasHeaderReader.cpp
   ./drivers/las/LasHeaderWriter.cpp
   ./drivers/las/Reader.cpp
+  ./drivers/las/SummaryData.cpp
   ./drivers/las/Support.cpp
   ./drivers/las/Writer.cpp
 )
diff -r e1b1e9a852d4 -r cf246805e92b src/drivers/las/SummaryData.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/drivers/las/SummaryData.cpp	Fri Apr 15 12:43:44 2011 -0700
@@ -0,0 +1,175 @@
+/******************************************************************************
+* Copyright (c) 2011, Michael P. Gerlek (mpg at flaxen.com)
+*
+* 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 Hobu, Inc. or Flaxen Geo Consulting 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 <libpc/drivers/las/SummaryData.hpp>
+
+#include <iostream>
+
+#include <libpc/exceptions.hpp>
+
+namespace libpc { 
+namespace drivers { 
+namespace las {
+
+
+SummaryData::SummaryData()
+    : m_isFirst(true)
+    , m_minX(0.0)
+    , m_minY(0.0)
+    , m_minZ(0.0)
+    , m_maxX(0.0)
+    , m_maxY(0.0)
+    , m_maxZ(0.0)
+    , m_totalNumPoints(0)
+{
+    reset();
+    return;
+}
+
+
+SummaryData::~SummaryData()
+{
+}
+
+
+void SummaryData::reset()
+{
+    m_isFirst = true;
+
+    m_minX = 0.0;
+    m_minY = 0.0;
+    m_minZ = 0.0;
+    m_maxX = 0.0;
+    m_maxY = 0.0;
+    m_maxZ = 0.0;
+
+    for (int i=0; i<s_maxNumReturns; i++)
+        m_returnCounts[i] = 0;
+
+    m_totalNumPoints = 0;
+
+    return;
+}
+
+
+void SummaryData::addPoint(double x, double y, double z, int returnNumber)
+{
+    if (returnNumber <= 0 || returnNumber > s_maxNumReturns)
+        throw invalid_point_data("point returnNumber is out of range", 0);
+
+    if (m_isFirst)
+    {
+        m_isFirst = false;
+        m_minX = x;
+        m_minY = y;
+        m_minZ = z;
+        m_maxX = x;
+        m_maxY = y;
+        m_maxZ = z;
+    }
+    else
+    {
+        m_minX = std::min(m_minX, x);
+        m_minY = std::min(m_minY, y);
+        m_minZ = std::min(m_minZ, z);
+        m_maxX = std::max(m_maxX, x);
+        m_maxY = std::max(m_maxY, y);
+        m_maxZ = std::max(m_maxZ, z);
+    }
+
+    ++m_returnCounts[returnNumber-1];
+
+    ++m_totalNumPoints;
+
+    return;
+}
+
+
+boost::uint32_t SummaryData::getTotalNumPoints() const
+{
+    return m_totalNumPoints;
+}
+
+
+void SummaryData::getBounds(double& minX, double& minY, double& minZ, double& maxX, double& maxY, double& maxZ) const
+{
+    minX = m_minX;
+    minY = m_minY;
+    minZ = m_minZ;
+    maxX = m_maxX;
+    maxY = m_maxY;
+    maxZ = m_maxZ;
+}
+
+
+boost::uint32_t SummaryData::getReturnCount(int returnNumber) const
+{
+    if (returnNumber <= 0 || returnNumber > s_maxNumReturns)
+        throw invalid_point_data("point returnNumber is out of range", 0);


More information about the Liblas-commits mailing list