[Liblas-commits] libpc: fix argument order

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Mar 3 15:16:10 EST 2011


details:   http://hg.liblas.orglibpc/rev/a67292b37e25
changeset: 165:a67292b37e25
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Thu Mar 03 12:15:52 2011 -0800
description:
fix argument order
Subject: libpc: merge

details:   http://hg.liblas.orglibpc/rev/946a47f1de74
changeset: 166:946a47f1de74
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Thu Mar 03 12:16:04 2011 -0800
description:
merge

diffstat:

 include/libpc/Utils.hpp   |    6 +
 include/libpc/chipper.hpp |  139 +++++++++++++++++
 src/CMakeLists.txt        |    1 +
 src/PointData.cpp         |    2 +-
 src/chipper.cpp           |  371 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 518 insertions(+), 1 deletions(-)

diffs (truncated from 564 to 300 lines):

diff -r 598d3126a001 -r 946a47f1de74 include/libpc/Utils.hpp
--- a/include/libpc/Utils.hpp	Thu Mar 03 10:09:26 2011 -0800
+++ b/include/libpc/Utils.hpp	Thu Mar 03 12:16:04 2011 -0800
@@ -39,6 +39,7 @@
 #include <string>
 #include <stdexcept>
 #include <cassert>
+#include <cmath>
 
 #include <boost/concept_check.hpp>
 #include <boost/cstdint.hpp>
@@ -135,6 +136,11 @@
         dest.write(p, num);
         assert(check_stream_state(dest));
     }
+    
+    // From http://stackoverflow.com/questions/485525/round-for-float-in-c
+    static inline double sround(double r) {
+        return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
+    }
 
 private:
     template<typename T>
diff -r 598d3126a001 -r 946a47f1de74 include/libpc/chipper.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/libpc/chipper.hpp	Thu Mar 03 12:16:04 2011 -0800
@@ -0,0 +1,139 @@
+#ifndef LIBLAS_CHIPPER_H
+#define LIBLAS_CHIPPER_H
+
+#include <libpc/Stage.hpp>
+#include <libpc/Bounds.hpp>
+#include <libpc/export.hpp>
+#include <libpc/Dimension.hpp>
+
+#include <vector>
+
+namespace libpc
+{
+
+namespace chipper
+{
+
+enum Direction
+{
+    DIR_X,
+    DIR_Y,
+    DIR_NONE
+};
+
+class LIBPC_DLL PtRef
+{
+public:
+    double m_pos;
+    boost::uint32_t m_ptindex;
+    boost::uint32_t m_oindex;
+
+    bool operator < (const PtRef& pt) const
+        { return m_pos < pt.m_pos; }
+};
+
+struct LIBPC_DLL RefList
+{
+public:
+    std::vector<PtRef> m_vec;
+    Direction m_dir;
+
+    RefList(Direction dir = DIR_NONE) : m_dir(dir)
+        {}
+    std::vector<PtRef>::size_type size() const
+        { return m_vec.size(); }
+    void reserve(std::vector<PtRef>::size_type n)
+        { m_vec.reserve(n); }
+    void resize(std::vector<PtRef>::size_type n)
+        { m_vec.resize(n); }
+    void push_back(const PtRef& ref)
+        { m_vec.push_back(ref); }
+    std::vector<PtRef>::iterator begin()
+        { return m_vec.begin(); }
+    std::vector<PtRef>::iterator end()
+        { return m_vec.end(); }
+    PtRef& operator[](boost::uint32_t pos)
+        { return m_vec[pos]; }
+    std::string Dir()
+    {
+        if (m_dir == DIR_X)
+            return "X";
+        else if (m_dir == DIR_Y)
+            return "Y";
+        else
+            return "NONE";
+    }
+};
+
+class LIBPC_DLL Chipper;
+
+class LIBPC_DLL Block
+{
+    friend class Chipper;
+
+private:
+    RefList *m_list_p;
+    boost::uint32_t m_left;
+    boost::uint32_t m_right;
+    libpc::Bounds<double> m_bounds;
+    // double m_xmin;
+    // double m_ymin;
+    // double m_xmax;
+    // double m_ymax;
+
+public:
+    std::vector<boost::uint32_t> GetIDs() const; 
+    libpc::Bounds<double> const& GetBounds() const {return m_bounds;} 
+    void SetBounds(libpc::Bounds<double> const& bounds) {m_bounds = bounds;}
+    // double GetXmin() const
+    //     { return m_xmin; }
+    // double GetYmin() const
+    //     { return m_ymin; }
+    // double GetXmax() const
+    //     { return m_xmax; }
+    // double GetYmax() const
+    //     { return m_ymax; }
+};
+
+class LIBPC_DLL Chipper
+{
+public:
+    Chipper(Stage& prevStage, boost::uint32_t max_partition_size) :
+        m_stage(prevStage), m_threshold(max_partition_size),
+        m_xvec(DIR_X), m_yvec(DIR_Y), m_spare(DIR_NONE)
+    {}
+
+    void Chip();
+    std::vector<Block>::size_type GetBlockCount()
+        { return m_blocks.size(); }
+    const Block& GetBlock(std::vector<Block>::size_type i)
+        { return m_blocks[i]; }
+
+private:
+    void Load(RefList& xvec, RefList& yvec, RefList& spare);
+    void Partition(boost::uint32_t size);
+    void Split(RefList& xvec, RefList& yvec, RefList& spare);
+    void DecideSplit(RefList& v1, RefList& v2, RefList& spare,
+        boost::uint32_t left, boost::uint32_t right);
+    void Split(RefList& wide, RefList& narrow, RefList& spare,
+        boost::uint32_t left, boost::uint32_t right);
+    void FinalSplit(RefList& wide, RefList& narrow,
+        boost::uint32_t pleft, boost::uint32_t pcenter);
+    void Emit(RefList& wide, boost::uint32_t widemin, boost::uint32_t widemax,
+        RefList& narrow, boost::uint32_t narrowmin, boost::uint32_t narrowmax );
+
+    // Reader *m_reader;
+    Stage& m_stage;
+    boost::uint32_t m_threshold;
+    std::vector<Block> m_blocks;
+    std::vector<boost::uint32_t> m_partitions;
+    RefList m_xvec;
+    RefList m_yvec;
+    RefList m_spare;
+};
+
+} // namespace chipper
+
+} // namespace liblas
+
+#endif
diff -r 598d3126a001 -r 946a47f1de74 src/CMakeLists.txt
--- a/src/CMakeLists.txt	Thu Mar 03 10:09:26 2011 -0800
+++ b/src/CMakeLists.txt	Thu Mar 03 12:16:04 2011 -0800
@@ -62,6 +62,7 @@
 set(LIBPC_CPP
     ${LIBPC_SOURCES}
   Bounds.cpp
+  chipper.cpp
   Color.cpp
   ColorFilter.cpp
   CropFilter.cpp
diff -r 598d3126a001 -r 946a47f1de74 src/PointData.cpp
--- a/src/PointData.cpp	Thu Mar 03 10:09:26 2011 -0800
+++ b/src/PointData.cpp	Thu Mar 03 12:16:04 2011 -0800
@@ -54,7 +54,7 @@
     m_data = new boost::uint8_t[m_pointSize * m_numPoints];
     
     // the points will all be set to invalid here
-    m_isValid.assign(0, m_isValid.size());
+    m_isValid.assign(m_isValid.size(), 0);
 
     return;
 }
diff -r 598d3126a001 -r 946a47f1de74 src/chipper.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/chipper.cpp	Thu Mar 03 12:16:04 2011 -0800
@@ -0,0 +1,371 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
+ * Purpose:  Point Partitioning/blocking for OPC
+ * Author:   Andrew Bell andrew.bell.ia at gmail.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2010, Andrew Bell
+ *
+ * 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 Andrew Bell or libLAS 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/chipper.hpp>
+#include <libpc/Utils.hpp>
+// boost
+#include <boost/cstdint.hpp>
+// std
+#include <cmath>
+
+using namespace std;
+
+/**
+The objective is to split the region into non-overlapping blocks, each
+containing approximately the same number of points, as specified by the
+user.
+
+First, the points are read into arrays - one for the x direction, and one for
+the y direction.  The arrays are sorted and are initialized with indices into
+the other array of the location of the other coordinate of the same point.
+
+Partitions are created that place the maximum number of points in a
+block, subject to the user-defined threshold, using a cumulate and round
+procedure.
+
+The distance of the point-space is checked in each direction and the
+wider dimension is chosen for splitting at an appropriate partition point.
+The points in the narrower direction are copied to locations in the spare
+array at one side or the other of the chosen partition, and that portion
+of the spare array then becomes the active array for the narrow direction.
+This avoids resorting of the arrays, which are already sorted.
+
+This procedure is then recursively applied to the created blocks until
+they contains only one or two partitions.  In the case of one partition,
+we are done, and we simply store away the contents of the block.  If there are
+two partitions in a block, we avoid the recopying the narrow array to the
+spare since the wide array already contains the desired points partitioned
+into two blocks.  We simply need to locate the maximum and minimum values
+from the narrow array so that the approriate extrema of the block can
+be stored.
+**/
+
+namespace libpc { namespace chipper {
+
+vector<boost::uint32_t> Block::GetIDs() const
+{
+    vector<boost::uint32_t> ids;
+
+    for (boost::uint32_t i = m_left; i <= m_right; ++i)
+        ids.push_back((*m_list_p)[i].m_ptindex);
+    return ids;
+}
+
+void Chipper::Chip()
+{
+    Load(m_xvec, m_yvec, m_spare);
+    Partition(m_xvec.size());
+    DecideSplit(m_xvec, m_yvec, m_spare, 0, m_partitions.size() - 1);
+}
+
+void Chipper::Load(RefList& xvec, RefList& yvec, RefList& spare )
+{
+    PtRef ref;
+    boost::uint32_t idx;
+    vector<PtRef>::iterator it;
+   
+    libpc::Header const& header = m_stage.getHeader();
+    libpc::Schema const& schema = header.getSchema();
+    
+    boost::uint64_t count = header.getNumPoints();


More information about the Liblas-commits mailing list