[Liblas-commits] hg: make liblas::Bounds a templated class, so we can use the sam...

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Aug 9 23:18:29 EDT 2010


changeset c3e01b4cb920 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=c3e01b4cb920
summary: make liblas::Bounds a templated class, so we can use the same code for liblas::Bounds<int>

diffstat:

 apps/kdx_util.cpp                     |    4 +-
 apps/kdx_util.hpp                     |    8 +-
 apps/las2las2.cpp                     |   55 +++++-
 apps/las2oci.cpp                      |   10 +-
 apps/lasblock.cpp                     |    2 +-
 include/liblas/detail/fwd.hpp         |    2 +-
 include/liblas/lasbounds.hpp          |  274 +++++++++++++++++++++++++++++++--
 include/liblas/lasfilter.hpp          |    2 +-
 include/liblas/lasheader.hpp          |    6 +-
 src/CMakeLists.txt                    |    1 -
 src/lasbounds.cpp                     |  260 --------------------------------
 src/lasfilter.cpp                     |    2 +-
 src/lasheader.cpp                     |    8 +-
 test/unit/common.hpp                  |    4 +-
 test/unit/lasreader_iterator_test.cpp |    2 +-
 15 files changed, 322 insertions(+), 318 deletions(-)

diffs (truncated from 922 to 300 lines):

diff -r 8426f4b8d999 -r c3e01b4cb920 apps/kdx_util.cpp
--- a/apps/kdx_util.cpp	Mon Aug 09 15:50:39 2010 -0500
+++ b/apps/kdx_util.cpp	Mon Aug 09 22:18:21 2010 -0500
@@ -41,7 +41,7 @@
             input >> i;
             ids.push_back(i);
         }
-        liblas::Bounds b(low[0], low[1], high[0],high[1]);
+        liblas::Bounds<double> b(low[0], low[1], high[0],high[1]);
         // SpatialIndex::Region* pr = new SpatialIndex::Region(low, high, 2);
         // printf("Ids size: %d %.3f\n", ids.size(), pr->getLow(0));
         IndexResult result(static_cast<uint32_t>(id));
@@ -50,7 +50,7 @@
         m_results.push_back(result);
     }
 
-    bounds = boost::shared_ptr<liblas::Bounds>(new liblas::Bounds(mins[0], mins[1], maxs[0], maxs[1]));
+    bounds = boost::shared_ptr<liblas::Bounds<double > >(new liblas::Bounds<double>(mins[0], mins[1], maxs[0], maxs[1]));
 }
 
 bool GetPointData(  liblas::Point const& p, 
diff -r 8426f4b8d999 -r c3e01b4cb920 apps/kdx_util.hpp
--- a/apps/kdx_util.hpp	Mon Aug 09 15:50:39 2010 -0500
+++ b/apps/kdx_util.hpp	Mon Aug 09 22:18:21 2010 -0500
@@ -23,8 +23,8 @@
 
     IDVector const& GetIDs() const { return ids; }
     void SetIDs(IDVector& v) {ids = v;}
-    const liblas::Bounds GetBounds() const { return bounds; }
-    void SetBounds(const liblas::Bounds b) {bounds = b;}
+    const liblas::Bounds<double> GetBounds() const { return bounds; }
+    void SetBounds(const liblas::Bounds<double> b) {bounds = b;}
     uint32_t GetID() const {return m_id;}
     void SetID(uint32_t v) {m_id = v;}
     
@@ -39,7 +39,7 @@
     // IndexResult& operator=(IndexResult const& rhs);
     
     IDVector ids;
-    liblas::Bounds bounds;
+    liblas::Bounds<double> bounds;
     uint32_t m_id;
 
 };
@@ -49,7 +49,7 @@
 {
 public:
     KDXIndexSummary(std::istream& input);    
-    boost::shared_ptr<liblas::Bounds> bounds;
+    boost::shared_ptr<liblas::Bounds<double > > bounds;
     ResultsVector& GetResults() { return m_results; }
 private:
     ResultsVector m_results;
diff -r 8426f4b8d999 -r c3e01b4cb920 apps/las2las2.cpp
--- a/apps/las2las2.cpp	Mon Aug 09 15:50:39 2010 -0500
+++ b/apps/las2las2.cpp	Mon Aug 09 22:18:21 2010 -0500
@@ -141,19 +141,19 @@
     boost::char_separator<char> sep(SEPARATORS);
     std::vector<double> vbounds;
     tokenizer tokens(bounds_string, sep);
-    liblas::Bounds bounds;
+    liblas::Bounds<double> bounds;
     for (tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t) {
         vbounds.push_back(atof((*t).c_str()));
     }
     if (vbounds.size() == 4) 
     {
-        bounds = liblas::Bounds(vbounds[0], 
+        bounds = liblas::Bounds<double>(vbounds[0], 
                                 vbounds[1], 
                                 vbounds[2], 
                                 vbounds[3]);
     } else if (vbounds.size() == 6)
     {
-        bounds = liblas::Bounds(vbounds[0], 
+        bounds = liblas::Bounds<double>(vbounds[0], 
                                 vbounds[1], 
                                 vbounds[2], 
                                 vbounds[3], 
@@ -178,8 +178,15 @@
     return intensity_filter;
 }
 
-            
-            
+
+liblas::FilterI*  MakeTimeFilter(std::string times, liblas::FilterI::FilterType ftype) 
+{
+    liblas::ContinuousValueFilter<double>::filter_func f = &liblas::Point::GetTime;
+    liblas::ContinuousValueFilter<double>* time_filter = new liblas::ContinuousValueFilter<double>(f, times);
+    time_filter->SetType(ftype);
+    return time_filter;
+}
+
 
 bool process(   std::string const& input,
                 std::string const& output,
@@ -276,7 +283,7 @@
 
     // std::vector<boost::uint16_t> returns;
     
-    liblas::Bounds bounds;
+    // liblas::Bounds<double bounds;
     
     bool last_return_only;
     bool first_return_only;
@@ -306,6 +313,8 @@
             ("valid_only", po::value<bool>(&valid_only)->zero_tokens(), "Keep only valid points")
             ("keep-intensity", po::value< string >(), "Range in which to keep intensity.\nThe following expression types are supported.  --keep-intensity 0-100\n --keep-intensity <200\n --keep-intensity >400\n--keep-intensity >=200")
             ("drop-intensity", po::value< string >(), "Range in which to drop intensity.\nThe following expression types are supported.  --drop-intensity <200\n --drop-intensity >400\n--drop-intensity >=200")
+            ("keep-time", po::value< string >(), "Range in which to keep time.\nThe following expression types are supported.  --keep-time 413665.2336-414092.8462\n --keep-time <414094.8462\n --keep-time >413665.2336\n--keep-time >=413665.2336")
+            ("drop-time", po::value< string >(), "Range in which to drop time.\nThe following expression types are supported.  --drop-time <413666.2336\n --drop-time >413665.2336\n--drop-time >=413665.2336")
             
 
     ;
@@ -391,12 +400,40 @@
                 return(1);
             } else {
                 liblas::FilterI* intensity_filter = MakeIntensityFilter(intensities, liblas::FilterI::eExclusion);
-                filters.push_back(intensity_filter);
+                filters.push_back(intensity_filter);   
+            }
+        }
+        if (vm.count("keep-time")) 
+        {
+            std::string times = vm["keep-time"].as< string >();
+            if (IsDualRangeFilter(times)) {
+                // We need to make two filters
+                // Given a range 0-200, split the expression into two filters 
+                string::size_type dash = times.find_first_of("-");
+                std::string low = times.substr(0,dash);
+                std::string high = times.substr(dash+1, times.size());
+
+                liblas::FilterI* lt_filter = MakeTimeFilter(">="+low, liblas::FilterI::eInclusion);
+                filters.push_back(lt_filter);
+                liblas::FilterI* gt_filter = MakeTimeFilter("<="+high, liblas::FilterI::eInclusion);
+                filters.push_back(gt_filter);                
+            } else {
+                liblas::FilterI* time_filter = MakeTimeFilter(times, liblas::FilterI::eInclusion);
+                filters.push_back(time_filter);
                 
             }
-
         }
-
+        if (vm.count("drop-time")) 
+        {
+            std::string times = vm["drop-time"].as< string >();
+            if (IsDualRangeFilter(times)) {
+                std::cerr << "Range filters are not supported for drop-time" << std::endl;
+                return(1);
+            } else {
+                liblas::FilterI* time_filter = MakeTimeFilter(times, liblas::FilterI::eExclusion);
+                filters.push_back(time_filter);   
+            }
+        }
         if (thin > 0) 
         {
             liblas::ThinFilter* thin_filter = new ThinFilter(thin);
diff -r 8426f4b8d999 -r c3e01b4cb920 apps/las2oci.cpp
--- a/apps/las2oci.cpp	Mon Aug 09 15:50:39 2010 -0500
+++ b/apps/las2oci.cpp	Mon Aug 09 22:18:21 2010 -0500
@@ -36,7 +36,7 @@
 
 void SetOrdinates(   OWStatement* statement,
                      OCIArray* sdo_ordinates, 
-                     liblas::Bounds const& extent)
+                     liblas::Bounds<double> const& extent)
 {
     
     statement->AddElement(sdo_ordinates, extent.min(0));
@@ -671,7 +671,7 @@
                         bool bUseSolidGeometry,
                         bool bUse3d,
                         bool bSetExtents,
-                        liblas::Bounds const& bounds)
+                        liblas::Bounds<double> const& bounds)
 {
     ostringstream oss;
     OWStatement* statement = 0;
@@ -693,7 +693,7 @@
     }
 
     double tolerance = 0.05;
-    liblas::Bounds e = *query->bounds.get();
+    liblas::Bounds<double> e = *query->bounds.get();
 
     if (IsGeographic(connection, srid)) {
         e.min(0,-180.0); e.max(0,180.0);
@@ -819,7 +819,7 @@
     
 
     // extent* e = GetExtent(  *(query->bounds.get()), bUse3d );
-    liblas::Bounds e =  *(query->bounds.get());
+    liblas::Bounds<double> e =  *(query->bounds.get());
 
     s_geom << "           mdsys.sdo_geometry("<<s_gtype.str() <<", "<<s_srid.str()<<", null,\n"
 "              mdsys.sdo_elem_info_array"<< s_eleminfo.str() <<",\n"
@@ -942,7 +942,7 @@
     int srid = 0;
     long precision = 8;
     
-    liblas::Bounds global_extent;
+    liblas::Bounds<double> global_extent;
     
     bool bSetExtents = false;
     
diff -r 8426f4b8d999 -r c3e01b4cb920 apps/lasblock.cpp
--- a/apps/lasblock.cpp	Mon Aug 09 15:50:39 2010 -0500
+++ b/apps/lasblock.cpp	Mon Aug 09 22:18:21 2010 -0500
@@ -138,7 +138,7 @@
             out << ids[pi] << " ";
         }
 
-        liblas::Bounds bds(b.GetXmin(), b.GetYmin(), b.GetXmax(), b.GetYmax());
+        liblas::Bounds<double> bds(b.GetXmin(), b.GetYmin(), b.GetXmax(), b.GetYmax());
 
         out << std::endl;
     }
diff -r 8426f4b8d999 -r c3e01b4cb920 include/liblas/detail/fwd.hpp
--- a/include/liblas/detail/fwd.hpp	Mon Aug 09 15:50:39 2010 -0500
+++ b/include/liblas/detail/fwd.hpp	Mon Aug 09 22:18:21 2010 -0500
@@ -47,7 +47,7 @@
 // Forward declarations
 namespace liblas {
 
-class Bounds;
+template<typename T>class Bounds;
 class Classification;
 class Color;
 class FilterI;
diff -r 8426f4b8d999 -r c3e01b4cb920 include/liblas/lasbounds.hpp
--- a/include/liblas/lasbounds.hpp	Mon Aug 09 15:50:39 2010 -0500
+++ b/include/liblas/lasbounds.hpp	Mon Aug 09 22:18:21 2010 -0500
@@ -43,53 +43,281 @@
 #define LIBLAS_LASBOUNDS_HPP_INCLUDED
 
 #include <liblas/detail/fwd.hpp>
+#include <liblas/laspoint.hpp>
+#include <liblas/detail/utility.hpp>
 
+// boost
+#include <boost/cstdint.hpp>
+
+#include <boost/concept_check.hpp>
+// std
+#include <cmath>
+#include <limits>
+#include <string>
+#include <sstream>
 #include <vector>
 
+
 namespace liblas {
 
+template <typename T>
 class Bounds
 {
 public:
 
-    typedef std::vector<double> Vector;
-    typedef std::vector<double>::size_type size_type;
+    typedef typename std::vector<T> Vector;
+    typedef typename std::vector<T>::size_type size_type;
         
-    Bounds();
-    Bounds(double minx, double miny, double maxx, double maxy, double minz, double maxz);
-    Bounds(double minx, double miny, double maxx, double maxy);
-    Bounds(const Point& min, const Point& max);
-    Bounds( std::vector<double> const& low, std::vector<double> const& high);
-    Bounds(Bounds const& other);
-    Bounds& operator=(Bounds const& rhs);
+    // Bounds<T>();
+    // Bounds(T minx, T miny, T maxx, T maxy, T minz, T maxz);
+    // Bounds(T minx, T miny, T maxx, T maxy);
+    // Bounds(const Point& min, const Point& max);
+    // // Bounds( Vector const& low, Vector const& high);
+    // Bounds(Bounds<T> const& other);
+    // Bounds& operator=(Bounds const& rhs);
     
-    double min(std::size_t const& index) const;
-    void min(std::size_t const& index, double v);
-    double max(std::size_t const& index) const;
-    void max(std::size_t const& index, double v);
+    // T min(std::size_t const& index) const;
+    // void min(std::size_t const& index, T v);
+    // T max(std::size_t const& index) const;
+    // void max(std::size_t const& index, T v);
     
-    bool equal(Bounds const& other) const;
-    bool intersects(Bounds const& other) const;
-    size_type dimension() const;
-    void dimension(size_type d);
+    // bool equal(Bounds<T> const& other) const;
+    // bool intersects(Bounds<T> const& other) const;
+    // size_type dimension() const;
+    // void dimension(size_type d);
         
 private:
     Vector mins;


More information about the Liblas-commits mailing list