[Liblas-commits] hg-main-tree: added simple Stats filter

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Aug 16 14:41:32 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/f1769f13f8e2
changeset: 1111:f1769f13f8e2
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Aug 16 11:40:58 2011 -0700
description:
added simple Stats filter

diffstat:

 include/pdal/filters/StatsFilter.hpp         |   96 ++++++++++++++
 include/pdal/filters/StatsFilterIterator.hpp |   62 +++++++++
 src/CMakeLists.txt                           |    4 +
 src/StageFactory.cpp                         |    7 +-
 src/filters/StatsFilter.cpp                  |  180 +++++++++++++++++++++++++++
 src/filters/StatsFilterIterator.cpp          |   72 ++++++++++
 test/unit/CMakeLists.txt                     |    1 +
 test/unit/StatsFilterTest.cpp                |   88 +++++++++++++
 8 files changed, 508 insertions(+), 2 deletions(-)

diffs (truncated from 585 to 300 lines):

diff -r 97b01e5e8af2 -r f1769f13f8e2 include/pdal/filters/StatsFilter.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/pdal/filters/StatsFilter.hpp	Tue Aug 16 11:40:58 2011 -0700
@@ -0,0 +1,96 @@
+/******************************************************************************
+* 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_FILTERS_STATSFILTER_HPP
+#define INCLUDED_FILTERS_STATSFILTER_HPP
+
+#include <pdal/pdal.hpp>
+#include <pdal/Filter.hpp>
+#include <pdal/Range.hpp>
+#include <pdal/PointBuffer.hpp>
+
+
+namespace pdal { namespace filters {
+
+class StatsFilterSequentialIterator;
+
+// this is just a pass-thorugh filter, which collects some stats about the points
+// that are fed through it
+class PDAL_DLL StatsFilter : public Filter
+{
+public:
+    SET_STAGE_NAME("filters.stats", "Statistics Filter")
+
+    StatsFilter(Stage& prevStage, const Options&);
+    StatsFilter(Stage& prevStage);
+
+    virtual void initialize();
+    virtual const Options getDefaultOptions() const;
+
+    bool supportsIterator (StageIteratorType t) const
+    {   
+        if (t == StageIterator_Sequential ) return true;
+        if (t == StageIterator_Random ) return true;
+        if (t == StageIterator_Block ) return true;
+        return false;
+    }
+
+    pdal::StageSequentialIterator* createSequentialIterator() const;
+    pdal::StageRandomIterator* createRandomIterator() const { return 0; } // BUG: add this
+    pdal::StageBlockIterator* createBlockIterator() const { return 0; } // BUG: add this
+
+    void processBuffer(PointBuffer& data) const;
+
+    // clears the counters
+    void reset();
+    void getData(boost::uint64_t& count, 
+                 double& minx, double& miny, double& minz, 
+                 double& maxx, double& maxy, double& maxz,
+                 double& avgx, double& avgy, double& avgz) const;
+
+private:
+    // BUG: not threadsafe, these should maybe live in the iterator
+    mutable boost::uint64_t m_totalPoints;
+    mutable double m_minimumX, m_minimumY, m_minimumZ;
+    mutable double m_maximumX, m_maximumY, m_maximumZ;
+    mutable double m_sumX, m_sumY, m_sumZ;
+
+    StatsFilter& operator=(const StatsFilter&); // not implemented
+    StatsFilter(const StatsFilter&); // not implemented
+};
+
+
+} } // namespaces
+
+#endif
diff -r 97b01e5e8af2 -r f1769f13f8e2 include/pdal/filters/StatsFilterIterator.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/pdal/filters/StatsFilterIterator.hpp	Tue Aug 16 11:40:58 2011 -0700
@@ -0,0 +1,62 @@
+/******************************************************************************
+* 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_FILTERS_STATSFILTERITERATOR_HPP
+#define INCLUDED_FILTERS_STATSFILTERITERATOR_HPP
+
+#include <pdal/pdal.hpp>
+
+#include <pdal/filters/StatsFilter.hpp>
+#include <pdal/FilterIterator.hpp>
+
+namespace pdal { namespace filters {
+
+
+class StatsFilterSequentialIterator : public pdal::FilterSequentialIterator
+{
+public:
+    StatsFilterSequentialIterator(const StatsFilter& filter);
+
+private:
+    boost::uint64_t skipImpl(boost::uint64_t);
+    boost::uint32_t readBufferImpl(PointBuffer&);
+    bool atEndImpl() const;
+
+    const StatsFilter& m_statsFilter;
+};
+
+
+} } // namespaces
+
+#endif
diff -r 97b01e5e8af2 -r f1769f13f8e2 src/CMakeLists.txt
--- a/src/CMakeLists.txt	Tue Aug 16 10:11:33 2011 -0700
+++ b/src/CMakeLists.txt	Tue Aug 16 11:40:58 2011 -0700
@@ -330,6 +330,8 @@
   ${PDAL_FILTERS_HEADERS}/ReprojectionFilterIterator.hpp
   ${PDAL_FILTERS_HEADERS}/ScalingFilter.hpp
   ${PDAL_FILTERS_HEADERS}/ScalingFilterIterator.hpp
+  ${PDAL_FILTERS_HEADERS}/StatsFilter.hpp
+  ${PDAL_FILTERS_HEADERS}/StatsFilterIterator.hpp
 )
 
 set (PDAL_FILTERS_CPP 
@@ -351,6 +353,8 @@
   ${PDAL_FILTERS_SRC}/ReprojectionFilterIterator.cpp
   ${PDAL_FILTERS_SRC}/ScalingFilter.cpp
   ${PDAL_FILTERS_SRC}/ScalingFilterIterator.cpp
+  ${PDAL_FILTERS_SRC}/StatsFilter.cpp
+  ${PDAL_FILTERS_SRC}/StatsFilterIterator.cpp
 )
 
 list (APPEND PDAL_CPP ${PDAL_FILTERS_CPP} )
diff -r 97b01e5e8af2 -r f1769f13f8e2 src/StageFactory.cpp
--- a/src/StageFactory.cpp	Tue Aug 16 10:11:33 2011 -0700
+++ b/src/StageFactory.cpp	Tue Aug 16 11:40:58 2011 -0700
@@ -68,6 +68,7 @@
 #include <pdal/filters/DecimationFilter.hpp>
 #include <pdal/filters/ReprojectionFilter.hpp>
 #include <pdal/filters/ScalingFilter.hpp>
+#include <pdal/filters/StatsFilter.hpp>
 
 #include <pdal/filters/MosaicFilter.hpp>
 
@@ -129,9 +130,10 @@
     MAKE_FILTER_CREATOR(ColorFilter, pdal::filters::ColorFilter)
     MAKE_FILTER_CREATOR(CropFilter, pdal::filters::CropFilter)
     MAKE_FILTER_CREATOR(DecimationFilter, pdal::filters::DecimationFilter)
+    MAKE_FILTER_CREATOR(DescalingFilter, pdal::filters::DescalingFilter)
     MAKE_FILTER_CREATOR(ReprojectionFilter, pdal::filters::ReprojectionFilter)
     MAKE_FILTER_CREATOR(ScalingFilter, pdal::filters::ScalingFilter)
-    MAKE_FILTER_CREATOR(DescalingFilter, pdal::filters::DescalingFilter)
+    MAKE_FILTER_CREATOR(StatsFilter, pdal::filters::StatsFilter)
 
     //
     // define the functions to create the multifilters
@@ -303,9 +305,10 @@
     REGISTER_FILTER(ColorFilter, pdal::filters::ColorFilter);
     REGISTER_FILTER(CropFilter, pdal::filters::CropFilter);
     REGISTER_FILTER(DecimationFilter, pdal::filters::DecimationFilter);
+    REGISTER_FILTER(DescalingFilter, pdal::filters::DescalingFilter);
     REGISTER_FILTER(ReprojectionFilter, pdal::filters::ReprojectionFilter);
     REGISTER_FILTER(ScalingFilter, pdal::filters::ScalingFilter);
-    REGISTER_FILTER(DescalingFilter, pdal::filters::DescalingFilter);
+    REGISTER_FILTER(StatsFilter, pdal::filters::StatsFilter);
 }
 
 
diff -r 97b01e5e8af2 -r f1769f13f8e2 src/filters/StatsFilter.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/filters/StatsFilter.cpp	Tue Aug 16 11:40:58 2011 -0700
@@ -0,0 +1,180 @@
+/******************************************************************************
+* 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 <pdal/filters/StatsFilter.hpp>
+
+#include <pdal/Dimension.hpp>
+#include <pdal/Schema.hpp>
+#include <pdal/exceptions.hpp>
+#include <pdal/Color.hpp>
+#include <pdal/PointBuffer.hpp>
+#include <pdal/filters/StatsFilterIterator.hpp>
+
+namespace pdal { namespace filters {
+
+
+StatsFilter::StatsFilter(Stage& prevStage, const Options& options)
+    : pdal::Filter(prevStage, options)
+{
+    return;
+}
+
+
+StatsFilter::StatsFilter(Stage& prevStage)
+    : Filter(prevStage, Options::none())
+{
+    return;
+}
+
+
+void StatsFilter::initialize()
+{
+    Filter::initialize();
+
+    reset();
+
+    return;
+}
+
+
+const Options StatsFilter::getDefaultOptions() const
+{
+    Options options;
+    return options;


More information about the Liblas-commits mailing list