[Liblas-commits] hg-main-tree: banish vile const_cast

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Mar 23 12:18:43 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/7487a3b19bc0
changeset: 397:7487a3b19bc0
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Mar 22 16:05:20 2011 -0700
description:
banish vile const_cast
Subject: hg-main-tree: iter work

details:   http://hg.libpc.orghg-main-tree/rev/e5d4d5519e3f
changeset: 398:e5d4d5519e3f
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Wed Mar 23 08:01:47 2011 -0700
description:
iter work
Subject: hg-main-tree: iter work - tests passing now

details:   http://hg.libpc.orghg-main-tree/rev/9b398706f6f1
changeset: 399:9b398706f6f1
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Wed Mar 23 08:36:31 2011 -0700
description:
iter work - tests passing now
Subject: hg-main-tree: merge

details:   http://hg.libpc.orghg-main-tree/rev/8cb5d9abf57a
changeset: 400:8cb5d9abf57a
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Wed Mar 23 08:36:43 2011 -0700
description:
merge
Subject: hg-main-tree: rename some iter functions

details:   http://hg.libpc.orghg-main-tree/rev/f96012950314
changeset: 401:f96012950314
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Wed Mar 23 08:48:01 2011 -0700
description:
rename some iter functions
Subject: hg-main-tree: iter work - hiding the point count management

details:   http://hg.libpc.orghg-main-tree/rev/b505d7fc67af
changeset: 402:b505d7fc67af
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Wed Mar 23 09:10:20 2011 -0700
description:
iter work - hiding the point count management
Subject: hg-main-tree: merge

details:   http://hg.libpc.orghg-main-tree/rev/7dd22518e8a2
changeset: 403:7dd22518e8a2
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Wed Mar 23 09:10:46 2011 -0700
description:
merge

diffstat:

 include/libpc/Chipper.hpp                          |  22 +---
 include/libpc/FilterIterator.hpp                   |   6 +
 include/libpc/Iterator.hpp                         |  45 +++++-----
 include/libpc/PointBuffer.hpp                      |   7 +-
 include/libpc/drivers/faux/Iterator.hpp            |   6 +-
 include/libpc/drivers/las/Iterator.hpp             |   6 +-
 include/libpc/drivers/liblas/Iterator.hpp          |   6 +-
 include/libpc/filters/CacheFilterIterator.hpp      |   6 +-
 include/libpc/filters/ColorFilter.hpp              |   2 +
 include/libpc/filters/ColorFilterIterator.hpp      |  10 +-
 include/libpc/filters/CropFilter.hpp               |   4 +
 include/libpc/filters/CropFilterIterator.hpp       |  10 +-
 include/libpc/filters/DecimationFilter.hpp         |   2 +
 include/libpc/filters/DecimationFilterIterator.hpp |   6 +-
 include/libpc/filters/MosaicFilterIterator.hpp     |  11 +-
 include/libpc/types.hpp                            |   5 +-
 src/Chipper.cpp                                    |  15 +--
 src/FilterIterator.cpp                             |   6 +
 src/Iterator.cpp                                   |  60 +++++++++++--
 src/PointBuffer.cpp                                |   6 +-
 src/Stage.cpp                                      |   1 -
 src/Utils.cpp                                      |   2 +-
 src/drivers/faux/Iterator.cpp                      |  30 +++++--
 src/drivers/faux/Reader.cpp                        |   2 +
 src/drivers/las/Iterator.cpp                       |  18 ++-
 src/drivers/liblas/Iterator.cpp                    |  21 +++-
 src/drivers/oci/Reader.cpp                         |   2 +-
 src/filters/CacheFilterIterator.cpp                |  22 ++--
 src/filters/ColorFilter.cpp                        |  30 +++++++
 src/filters/ColorFilterIterator.cpp                |  46 +++-------
 src/filters/CropFilter.cpp                         |  42 ++++++++++
 src/filters/CropFilterIterator.cpp                 |  90 ++++++++++++---------
 src/filters/DecimationFilter.cpp                   |  23 +++++
 src/filters/DecimationFilterIterator.cpp           |  67 +++++++++++----
 src/filters/MosaicFilterIterator.cpp               |  16 ++-
 test/unit/CacheFilterTest.cpp                      |  23 +++--
 test/unit/LiblasReaderTest.cpp                     |  20 ++--
 37 files changed, 455 insertions(+), 241 deletions(-)

diffs (truncated from 1336 to 300 lines):

diff -r b19b24391fd1 -r 7dd22518e8a2 include/libpc/Chipper.hpp
--- a/include/libpc/Chipper.hpp	Tue Mar 22 15:55:30 2011 -0700
+++ b/include/libpc/Chipper.hpp	Wed Mar 23 09:10:46 2011 -0700
@@ -29,13 +29,13 @@
 {
     
 public:
-    PtRef() :m_data(0) {};
+    PtRef(PointBuffer& buffer) :m_data(buffer) {};
 
     // PtRef(PointBuffer const& data) : m_data(0), m_pointSize(data.getSchemaLayout().getByteSize()) {};
     double m_pos;
     boost::uint32_t m_ptindex;
     boost::uint32_t m_oindex;
-    boost::uint8_t* m_data;
+    PointBuffer m_data;
     boost::uint32_t m_pointSize;
 
     bool operator < (const PtRef& pt) const
@@ -46,13 +46,7 @@
         m_ptindex(other.m_ptindex), 
         m_oindex(other.m_oindex),
         m_data(other.m_data) 
-        { 
-            if (other.m_data)
-            {
-                m_data = new boost::uint8_t[m_pointSize * 1]; 
-                memcpy(m_data, other.m_data, m_pointSize*1);
-            }
-        }
+    {}
 
     PtRef& operator=(const PtRef& rhs)
     {
@@ -61,11 +55,7 @@
             m_pos = rhs.m_pos;
             m_ptindex = rhs.m_ptindex;
             m_oindex = rhs.m_oindex;
-            if (rhs.m_data)
-            {
-                m_data = new boost::uint8_t [m_pointSize * 1];
-                memcpy(m_data, rhs.m_data, m_pointSize*1);            
-            }
+            m_data = rhs.m_data;
         }
         return *this;
     }
@@ -84,8 +74,8 @@
         { 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 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()
diff -r b19b24391fd1 -r 7dd22518e8a2 include/libpc/FilterIterator.hpp
--- a/include/libpc/FilterIterator.hpp	Tue Mar 22 15:55:30 2011 -0700
+++ b/include/libpc/FilterIterator.hpp	Wed Mar 23 09:10:46 2011 -0700
@@ -48,7 +48,13 @@
     virtual ~FilterIterator();
 
 protected:
+    // from Iterator
+    virtual boost::uint32_t readImpl(PointBuffer&) = 0;
+    virtual boost::uint64_t skipImpl(boost::uint64_t pointNum) = 0;
+    virtual bool atEndImpl() const = 0;
+
     Iterator& getPrevIterator();
+    const Iterator& getPrevIterator() const;
 
 private:
     const Filter& m_stageAsFilter;
diff -r b19b24391fd1 -r 7dd22518e8a2 include/libpc/Iterator.hpp
--- a/include/libpc/Iterator.hpp	Tue Mar 22 15:55:30 2011 -0700
+++ b/include/libpc/Iterator.hpp	Wed Mar 23 09:10:46 2011 -0700
@@ -57,41 +57,44 @@
     // that matters is that the buffer we are given has the fields
     // we need to write into.
     //
-    // This is NOT virtual.  Derived classes should override the 
-    // readBuffer function below, not this one.
-    //
     // Returns the number of valid points read.
     boost::uint32_t read(PointBuffer&);
 
-    // advance (or retreat) to the Nth point in the file (absolute, 
-    // not relative).  In some cases, this might be a very slow, painful
-    // function to call.
-    virtual void seekToPoint(boost::uint64_t pointNum) = 0;
+    // advance N points ahead in the file
+    //
+    // In some cases, this might be a very slow, painful function to call because
+    // it might entail physically reading the N points (and dropping the data on the
+    // floor)
+    //
+    // Returns the number actually skipped (which might be less than count, if the
+    // end of the stage was reached first).
+    boost::uint64_t skip(boost::uint64_t count);
 
     // returns true after we've read all the points available to this stage
-    // (actually a convenience function that compares getCurrentPointIndex and getNumPoints)
-    bool atEnd();
+    bool atEnd() const;
 
-protected:
     // Returns the current point number.  The first point is 0.
     // If this number if > getNumPoints(), then no more points
     // may be read (and atEnd() should be true).
-    boost::uint64_t getCurrentPointIndex() const;
+    //
+    // All stages have the notion of a current point number, even for stages
+    // that are not really "oredered", in that the index just starts at zero 
+    // and increments by N every time another N points are read
+    boost::uint64_t getIndex() const;
 
-    // Implement this to do the actual work to fill in a buffer of points.
-    virtual boost::uint32_t readBuffer(PointBuffer&) = 0;
+    // used to control intermediate buffering needed by some stages
+    void setChunkSize(boost::uint32_t size);
+    boost::uint32_t getChunkSize() const;
 
-    // Each concrete stage is repsonsible for managing its own current
-    // point index when a read or seek occurs.  Call this function t o set
-    // the value.
-    void setCurrentPointIndex(boost::uint64_t delta);
-
-    // this is easier than saying setCurrentPointIndex(getCurrentPointIndex()+n)
-    void incrementCurrentPointIndex(boost::uint64_t currentPointDelta);
+protected:
+    virtual boost::uint32_t readImpl(PointBuffer&) = 0;
+    virtual boost::uint64_t skipImpl(boost::uint64_t pointNum) = 0;
+    virtual bool atEndImpl() const = 0;
 
 private:
     const Stage& m_stage;
-    boost::uint64_t m_currentPointIndex;
+    boost::uint64_t m_index;
+    boost::uint32_t m_chunkSize;
 
     Iterator& operator=(const Iterator&); // not implemented
     Iterator(const Iterator&); // not implemented
diff -r b19b24391fd1 -r 7dd22518e8a2 include/libpc/PointBuffer.hpp
--- a/include/libpc/PointBuffer.hpp	Tue Mar 22 15:55:30 2011 -0700
+++ b/include/libpc/PointBuffer.hpp	Wed Mar 23 09:10:46 2011 -0700
@@ -74,15 +74,16 @@
     const Bounds<double>& getSpatialBounds() const;
     void setSpatialBounds(const Bounds<double>& bounds);
 
-    // number of points in this buffer
+    // This is the number of points in this buffer that actually have valid data.  This number
+    // will be less than or equal to the getCapacity() value.
     boost::uint32_t getNumPoints() const;
     
     inline void setNumPoints(boost::uint32_t v) { assert(v <= m_capacity);m_numPoints = v; } 
 
     inline boost::uint32_t& getNumPointsRef() {assert(m_numPoints <= m_capacity);return m_numPoints; }
     
-    // number of points in this buffer that have legit data; initially will be zero,
-    // and after a read() call it will be in the range 0 to getNumPoints()-1
+    // This is the number of points that this buffer is allocated to be able to store.
+    // This is a fixed constant, set at ctor time by the person constructing the buffer.
     inline boost::uint32_t getCapacity() const { return m_capacity; }
 
     // schema (number and kinds of fields) for a point in this buffer
diff -r b19b24391fd1 -r 7dd22518e8a2 include/libpc/drivers/faux/Iterator.hpp
--- a/include/libpc/drivers/faux/Iterator.hpp	Tue Mar 22 15:55:30 2011 -0700
+++ b/include/libpc/drivers/faux/Iterator.hpp	Wed Mar 23 09:10:46 2011 -0700
@@ -48,10 +48,10 @@
 public:
     Iterator(const Reader& reader);
 
-    void seekToPoint(boost::uint64_t);
-
 private:
-    boost::uint32_t readBuffer(PointBuffer&);
+    boost::uint64_t skipImpl(boost::uint64_t);
+    boost::uint32_t readImpl(PointBuffer&);
+    bool atEndImpl() const;
 
     const Reader& m_stageAsDerived;
 };
diff -r b19b24391fd1 -r 7dd22518e8a2 include/libpc/drivers/las/Iterator.hpp
--- a/include/libpc/drivers/las/Iterator.hpp	Tue Mar 22 15:55:30 2011 -0700
+++ b/include/libpc/drivers/las/Iterator.hpp	Wed Mar 23 09:10:46 2011 -0700
@@ -50,10 +50,10 @@
 public:
     Iterator(const LasReader& reader);
 
-    void seekToPoint(boost::uint64_t);
-
 private:
-    boost::uint32_t readBuffer(PointBuffer&);
+    boost::uint64_t skipImpl(boost::uint64_t);
+    boost::uint32_t readImpl(PointBuffer&);
+    bool atEndImpl() const;
 
     const LasReader& m_stageAsDerived;
 };
diff -r b19b24391fd1 -r 7dd22518e8a2 include/libpc/drivers/liblas/Iterator.hpp
--- a/include/libpc/drivers/liblas/Iterator.hpp	Tue Mar 22 15:55:30 2011 -0700
+++ b/include/libpc/drivers/liblas/Iterator.hpp	Wed Mar 23 09:10:46 2011 -0700
@@ -58,10 +58,10 @@
 public:
     Iterator(const LiblasReader& reader);
 
-    void seekToPoint(boost::uint64_t);
-
 private:
-    boost::uint32_t readBuffer(PointBuffer&);
+    boost::uint64_t skipImpl(boost::uint64_t);
+    boost::uint32_t readImpl(PointBuffer&);
+    bool atEndImpl() const;
 
     const LiblasReader& m_stageAsDerived;
 };
diff -r b19b24391fd1 -r 7dd22518e8a2 include/libpc/filters/CacheFilterIterator.hpp
--- a/include/libpc/filters/CacheFilterIterator.hpp	Tue Mar 22 15:55:30 2011 -0700
+++ b/include/libpc/filters/CacheFilterIterator.hpp	Wed Mar 23 09:10:46 2011 -0700
@@ -51,10 +51,10 @@
 public:
     CacheFilterIterator(const CacheFilter& filter);
 
-    void seekToPoint(boost::uint64_t);
-
 private:
-    boost::uint32_t readBuffer(PointBuffer&);
+    boost::uint64_t skipImpl(boost::uint64_t);
+    boost::uint32_t readImpl(PointBuffer&);
+    bool atEndImpl() const;
 
     const CacheFilter& m_stageAsDerived;
 };
diff -r b19b24391fd1 -r 7dd22518e8a2 include/libpc/filters/ColorFilter.hpp
--- a/include/libpc/filters/ColorFilter.hpp	Tue Mar 22 15:55:30 2011 -0700
+++ b/include/libpc/filters/ColorFilter.hpp	Wed Mar 23 09:10:46 2011 -0700
@@ -58,6 +58,8 @@
 
     Iterator* createIterator() const;
 
+    void processBuffer(PointBuffer& data) const;
+
 private:
     void checkImpedance();
 
diff -r b19b24391fd1 -r 7dd22518e8a2 include/libpc/filters/ColorFilterIterator.hpp
--- a/include/libpc/filters/ColorFilterIterator.hpp	Tue Mar 22 15:55:30 2011 -0700
+++ b/include/libpc/filters/ColorFilterIterator.hpp	Wed Mar 23 09:10:46 2011 -0700
@@ -50,12 +50,12 @@
 public:
     ColorFilterIterator(const ColorFilter& filter);
 
-    void seekToPoint(boost::uint64_t);
+private:
+    boost::uint64_t skipImpl(boost::uint64_t);
+    boost::uint32_t readImpl(PointBuffer&);
+    bool atEndImpl() const;
 
-private:
-    boost::uint32_t readBuffer(PointBuffer&);
-
-    const ColorFilter& m_stageAsDerived;
+    const ColorFilter& m_colorFilter;
 };
 
 
diff -r b19b24391fd1 -r 7dd22518e8a2 include/libpc/filters/CropFilter.hpp
--- a/include/libpc/filters/CropFilter.hpp	Tue Mar 22 15:55:30 2011 -0700
+++ b/include/libpc/filters/CropFilter.hpp	Wed Mar 23 09:10:46 2011 -0700
@@ -55,6 +55,10 @@
 
     Iterator* createIterator() const;
 
+    // returns number of points accepted into the data buffer (which may be less than data.getNumPoints(),
+    // if we're calling this routine multiple times with the same buffer
+    boost::uint32_t processBuffer(PointBuffer& dstData, const PointBuffer& srcData) const;
+
     const Bounds<double>& getBounds() const;
 
 private:
diff -r b19b24391fd1 -r 7dd22518e8a2 include/libpc/filters/CropFilterIterator.hpp
--- a/include/libpc/filters/CropFilterIterator.hpp	Tue Mar 22 15:55:30 2011 -0700
+++ b/include/libpc/filters/CropFilterIterator.hpp	Wed Mar 23 09:10:46 2011 -0700
@@ -49,12 +49,12 @@
 public:
     CropFilterIterator(const CropFilter& filter);
 
-    void seekToPoint(boost::uint64_t);
+private:
+    boost::uint64_t skipImpl(boost::uint64_t);
+    boost::uint32_t readImpl(PointBuffer&);
+    bool atEndImpl() const;
 
-private:
-    boost::uint32_t readBuffer(PointBuffer&);
-
-    const CropFilter& m_stageAsDerived;
+    const CropFilter& m_cropFilter;


More information about the Liblas-commits mailing list