[Liblas-commits] hg: add ValidationFilter and ContinuousValueFilter template

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Aug 5 17:39:13 EDT 2010


changeset 51f7a84a025f in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=51f7a84a025f
summary: add ValidationFilter and ContinuousValueFilter template

diffstat:

 apps/las2las2.cpp            |  21 ++++++++++++++++-
 include/liblas/lasfilter.hpp |  54 +++++++++++++++++++++++++++++++++++++++++++-
 src/lasfilter.cpp            |  24 +++++++++++++++++++
 3 files changed, 97 insertions(+), 2 deletions(-)

diffs (171 lines):

diff -r 78e653b322d9 -r 51f7a84a025f apps/las2las2.cpp
--- a/apps/las2las2.cpp	Wed Aug 04 13:43:22 2010 -0500
+++ b/apps/las2las2.cpp	Thu Aug 05 16:39:06 2010 -0500
@@ -18,6 +18,7 @@
 #include <string>
 #include <vector>
 #include <string>
+#include <functional>
 
 #include <boost/program_options.hpp>
 #include <boost/tokenizer.hpp>
@@ -187,6 +188,7 @@
     
     bool last_return_only;
     bool first_return_only;
+    bool valid_only;
     std::vector<liblas::FilterI*> filters;    
 
     try {
@@ -209,7 +211,9 @@
             ("first_return_only", po::value<bool>(&first_return_only)->zero_tokens(), "Keep first returns (cannot be used with --last_return_only")
             ("keep-returns", po::value< string >(), "Return numbers to keep.\nUse a comma-separated list, for example, --keep-returns 1\nUse --last_return_only or --first_return_only if you want to ensure getting either one of these.")
             ("drop-returns", po::value< string >(), "Return numbers to drop.\nUse a comma-separated list, for example, --drop-returns 2,3,4,5\nUse --last_return_only or --first_return_only if you want to ensure getting either one of these.")
-
+            ("valid_only", po::value<bool>(&valid_only)->zero_tokens(), "Keep only valid points")
+            ("keep-intensity", po::value< string >(), "Range in which to keep intensity.\nUse a comma-separated list, for example, --keep-intensity 0-100 --keep-intensity <200\n")
+            
 
     ;
     
@@ -296,6 +300,16 @@
             filters.push_back(bounds_filter);
             
         }
+        if (vm.count("keep-intensity")) 
+        {
+            std::string intensities = vm["keep-intensity"].as< string >();
+            boost::function<uint16_t (const Point*) > f =&liblas::Point::GetIntensity;
+
+            liblas::ContinuousValueFilter<uint16_t>* intensity_filter = new liblas::ContinuousValueFilter<uint16_t>(f, atoi(intensities.c_str()));
+            intensity_filter->SetType(liblas::FilterI::eInclusion);
+            filters.push_back(intensity_filter);
+        }
+
         if (thin > 0) 
         {
             liblas::ThinFilter* thin_filter = new ThinFilter(thin);
@@ -320,6 +334,11 @@
             filters.push_back(return_filter);
         }
         
+        if (valid_only){
+            liblas::ValidationFilter* valid_filter = new ValidationFilter();
+            filters.push_back(valid_filter);            
+        }
+        
         
         if (vm.count("input")) 
         {
diff -r 78e653b322d9 -r 51f7a84a025f include/liblas/lasfilter.hpp
--- a/include/liblas/lasfilter.hpp	Wed Aug 04 13:43:22 2010 -0500
+++ b/include/liblas/lasfilter.hpp	Thu Aug 05 16:39:06 2010 -0500
@@ -48,8 +48,10 @@
 #include <liblas/detail/fwd.hpp>
 // boost
 #include <boost/cstdint.hpp>
+#include <boost/function.hpp>
 // std
 #include <vector>
+#include <functional>
 
 namespace liblas {
 
@@ -139,7 +141,6 @@
 };
 
 
-
 class ReturnFilter: public FilterI
 {
 public:
@@ -159,6 +160,57 @@
 };
 
 
+class ValidationFilter: public FilterI
+{
+public:
+
+    ValidationFilter();
+    bool filter(const Point& point);
+    
+private:
+
+    ValidationFilter(ValidationFilter const& other);
+    ValidationFilter& operator=(ValidationFilter const& rhs);
+};
+
+
+
+
+template <typename T>
+class ContinuousValueFilter: public FilterI
+{
+public:
+    typedef boost::function<T (const Point*)> filter_func;
+
+    ContinuousValueFilter(filter_func f, T value) :
+        liblas::FilterI(eInclusion), f(f), value(value)
+            {};
+            
+    bool filter(const liblas::Point& p)
+    {
+
+        bool output = false;
+
+        T v = f(&p);
+        if (v > value ){
+            if (GetType() == eInclusion) {
+                output = true;
+            } else {
+                output = false;
+            }    
+        }
+
+        return output;
+    }    
+private:
+
+    ContinuousValueFilter(ContinuousValueFilter const& other);
+    ContinuousValueFilter& operator=(ContinuousValueFilter const& rhs);
+    filter_func f;
+    T value;
+
+
+};
 
 } // namespace liblas
 
diff -r 78e653b322d9 -r 51f7a84a025f src/lasfilter.cpp
--- a/src/lasfilter.cpp	Wed Aug 04 13:43:22 2010 -0500
+++ b/src/lasfilter.cpp	Thu Aug 05 16:39:06 2010 -0500
@@ -209,4 +209,28 @@
     return output;
 }
 
+ValidationFilter::ValidationFilter() :
+ liblas::FilterI(eInclusion)
+{
+
+}
+
+
+
+bool ValidationFilter::filter(const liblas::Point& p)
+{
+
+    bool output = false;
+    if (p.IsValid()){
+        if (GetType() == eInclusion) {
+            output = true;
+        } else {
+            output = false;
+        }    
+    }
+
+    return output;
+}
+
+
 } // namespace liblas


More information about the Liblas-commits mailing list