[Liblas-commits] libpc: clean up reader/writer classes

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Feb 23 20:16:59 EST 2011


details:   http://hg.liblas.orglibpc/rev/429bb8a2745c
changeset: 80:429bb8a2745c
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Wed Feb 23 17:16:53 2011 -0800
description:
clean up reader/writer classes

diffstat:

 apps/pc2pc.cpp                 |  12 +++---
 include/libpc/ColorFilter.hpp  |   2 +-
 include/libpc/CropFilter.hpp   |   2 +-
 include/libpc/Dimension.hpp    |   2 +-
 include/libpc/FauxReader.hpp   |  29 ++++++++++++++--
 include/libpc/FauxWriter.hpp   |  17 ++++++++-
 include/libpc/Filter.hpp       |   5 ++-
 include/libpc/LasReader.hpp    |   2 +-
 include/libpc/LasWriter.hpp    |  10 +----
 include/libpc/MosaicFilter.hpp |   2 +-
 include/libpc/PointData.hpp    |   4 ++
 include/libpc/Reader.hpp       |   2 +
 include/libpc/Stage.hpp        |   7 +++-
 include/libpc/Writer.hpp       |  27 +++++++++++----
 src/ColorFilter.cpp            |  29 ++++++++++------
 src/CropFilter.cpp             |  28 +++++++++------
 src/FauxReader.cpp             |  63 +++++++++++++++++++----------------
 src/FauxWriter.cpp             |  54 +++++++++++++++++++------------
 src/Filter.cpp                 |   7 ++++
 src/LasReader.cpp              |   8 ++-
 src/LasWriter.cpp              |  16 +++++---
 src/MosaicFilter.cpp           |  13 ++++--
 src/Reader.cpp                 |   6 +++
 src/Writer.cpp                 |  72 ++++++++++++++++++++++++++++--------------
 24 files changed, 272 insertions(+), 147 deletions(-)

diffs (truncated from 925 to 300 lines):

diff -r f1fb059c0456 -r 429bb8a2745c apps/pc2pc.cpp
--- a/apps/pc2pc.cpp	Wed Feb 23 15:06:04 2011 -0800
+++ b/apps/pc2pc.cpp	Wed Feb 23 17:16:53 2011 -0800
@@ -33,7 +33,7 @@
   // the faux reader only supports fields (X,Y,Z,T)
   const Bounds<double> bounds(0, 0, -100, 200, 200, 100);
   const int numPoints = 30;
-  FauxReader reader(bounds, numPoints);
+  FauxReader reader(bounds, numPoints, FauxReader::Random);
 
   CropFilter cropper(reader, Bounds<double>(0, 0, 0, 100, 100, 100));
 
@@ -41,7 +41,7 @@
 
   FauxWriter writer(colorizer);
   
-  writer.write();
+  writer.write(30);
 
   return;
 }
@@ -51,16 +51,16 @@
 {
   const int numPoints = 10;
   const Bounds<double> bounds1(0, 0, 0, 100, 100, 100);
-  FauxReader reader1(bounds1, numPoints);
+  FauxReader reader1(bounds1, numPoints, FauxReader::Random);
 
   const Bounds<double> bounds2(100, 100, 100, 200, 200, 100);
-  FauxReader reader2(bounds2, numPoints);
+  FauxReader reader2(bounds2, numPoints, FauxReader::Random);
 
   MosaicFilter mosaicker(reader1, reader2);
 
   FauxWriter writer(mosaicker);
   
-  writer.write();
+  writer.write(20);
   
   return;
 }
@@ -80,7 +80,7 @@
   std::ostream* ofs = Utils::createFile("temp.las");
 
   LasWriter lasWriter(reader, *ofs);
-  lasWriter.write();
+  lasWriter.write( header.getNumPoints() );
 
   Utils::closeFile(ofs);
 
diff -r f1fb059c0456 -r 429bb8a2745c include/libpc/ColorFilter.hpp
--- a/include/libpc/ColorFilter.hpp	Wed Feb 23 15:06:04 2011 -0800
+++ b/include/libpc/ColorFilter.hpp	Wed Feb 23 17:16:53 2011 -0800
@@ -50,7 +50,7 @@
 public:
     ColorFilter(Stage& prevStage);
 
-    void readPoints(PointData&);
+    boost::uint32_t readPoints(PointData&);
 
 private:
     void getColor(float value, boost::uint8_t& red, boost::uint8_t& green, boost::uint8_t& blue);
diff -r f1fb059c0456 -r 429bb8a2745c include/libpc/CropFilter.hpp
--- a/include/libpc/CropFilter.hpp	Wed Feb 23 15:06:04 2011 -0800
+++ b/include/libpc/CropFilter.hpp	Wed Feb 23 17:16:53 2011 -0800
@@ -49,7 +49,7 @@
 public:
     CropFilter(Stage& prevStage, Bounds<double> const& bounds);
 
-    void readPoints(PointData&);
+    boost::uint32_t readPoints(PointData&);
 
 private:
     Bounds<double> m_bounds;
diff -r f1fb059c0456 -r 429bb8a2745c include/libpc/Dimension.hpp
--- a/include/libpc/Dimension.hpp	Wed Feb 23 15:06:04 2011 -0800
+++ b/include/libpc/Dimension.hpp	Wed Feb 23 17:16:53 2011 -0800
@@ -85,7 +85,7 @@
         Field_PointSourceId,
         // ...
 
-        // add more here (but be sure and call setFieldName()!)
+        // add more here
         Field_User1 = 512,
         Field_User2,
         Field_User3,
diff -r f1fb059c0456 -r 429bb8a2745c include/libpc/FauxReader.hpp
--- a/include/libpc/FauxReader.hpp	Wed Feb 23 15:06:04 2011 -0800
+++ b/include/libpc/FauxReader.hpp	Wed Feb 23 17:16:53 2011 -0800
@@ -40,18 +40,37 @@
 namespace libpc
 {
 
+// The FauxReader doesn't read from disk, but instead just makes up data for its
+// points.  The reader is constructed with a given bounding box and a given 
+// number of points.
+//
+// This reader knows about 4 fields (Dimensions):
+//    X,Y,Z - floats
+//    Time  - uint64
+//
+// It supports two modes: "random" generates points that are randomly
+// distributed within the given bounding box, and "constant" generates its
+// points to always be at the minimum of the bounding box.
+//
 class LIBPC_DLL FauxReader : public Reader
 {
 public:
-    // generates N points randomly within the bounds
-    FauxReader(const Bounds<double>&, int numPoints);
+    enum Mode
+    {
+        Constant,
+        Random
+    };
 
-    void readPoints(PointData& data);
+public:
+    FauxReader(const Bounds<double>&, int numPoints, Mode mode);
 
-    // does nothing
-    void seekToPoint(boost::uint64_t&) { }
+    boost::uint32_t readPoints(PointData& data);
+
+    void seekToPoint(boost::uint64_t&);
 
 private:
+    Mode m_mode;
+
     FauxReader& operator=(const FauxReader&); // not implemented
     FauxReader(const FauxReader&); // not implemented
 };
diff -r f1fb059c0456 -r 429bb8a2745c include/libpc/FauxWriter.hpp
--- a/include/libpc/FauxWriter.hpp	Wed Feb 23 15:06:04 2011 -0800
+++ b/include/libpc/FauxWriter.hpp	Wed Feb 23 17:16:53 2011 -0800
@@ -42,16 +42,27 @@
 namespace libpc
 {
 
+//
+// The FauxWriter doesn't actually write to disk -- instead, it just
+// dumps to stdout some summary stats about the data it is given.
+//
+// This writer knows only about three dimensions: X,Y,Z (as floats).
+//
 class LIBPC_DLL FauxWriter : public Writer
 {
 public:
     FauxWriter(Stage& prevStage);
 
 private:
-    int m_numPointsWritten;
+    float m_minimumX;
+    float m_minimumY;
+    float m_minimumZ;
+    float m_maximumX;
+    float m_maximumY;
+    float m_maximumZ;
 
-    void writeBegin(std::size_t totalNumPoints);
-    void writeBuffer(const PointData&);
+    void writeBegin();
+    boost::uint32_t writeBuffer(const PointData&);
     void writeEnd();
 
     FauxWriter& operator=(const FauxWriter&); // not implemented
diff -r f1fb059c0456 -r 429bb8a2745c include/libpc/Filter.hpp
--- a/include/libpc/Filter.hpp	Wed Feb 23 15:06:04 2011 -0800
+++ b/include/libpc/Filter.hpp	Wed Feb 23 17:16:53 2011 -0800
@@ -47,7 +47,7 @@
 public:
     Filter(Stage& prevStage);
 
-    virtual void readPoints(PointData&) = 0;
+    virtual boost::uint32_t readPoints(PointData&) = 0;
 
     // advance (or retreat) to the Nth point in the file (absolute, 
     // default behaviour for filters is just to call seek on the previous stage
@@ -57,6 +57,9 @@
     // default behaviour for filters is just to call reset on the previous stage
     virtual void reset();
 
+    // default behaviour for filters is just to call reset on the previous stage
+    virtual bool atEnd() const;
+
 protected:
     int m_lastPointRead;
     Stage& m_prevStage;
diff -r f1fb059c0456 -r 429bb8a2745c include/libpc/LasReader.hpp
--- a/include/libpc/LasReader.hpp	Wed Feb 23 15:06:04 2011 -0800
+++ b/include/libpc/LasReader.hpp	Wed Feb 23 17:16:53 2011 -0800
@@ -48,7 +48,7 @@
 public:
     LasReader(std::istream&);
 
-    virtual void readPoints(PointData&);
+    virtual boost::uint32_t readPoints(PointData&);
 
     // default is to reset() and then read N points manually
     // override this if you can
diff -r f1fb059c0456 -r 429bb8a2745c include/libpc/LasWriter.hpp
--- a/include/libpc/LasWriter.hpp	Wed Feb 23 15:06:04 2011 -0800
+++ b/include/libpc/LasWriter.hpp	Wed Feb 23 17:16:53 2011 -0800
@@ -49,21 +49,15 @@
 
 protected:
     // this is called once before the loop with the writeBuffer calls
-    virtual void writeBegin(std::size_t totalNumPoints);
+    virtual void writeBegin();
 
     // called repeatedly, until out of data
-    virtual void writeBuffer(const PointData&);
+    virtual boost::uint32_t writeBuffer(const PointData&);
 
     // called once, after the writeBuffer calls
     virtual void writeEnd();
 
 private:
-    // not generally used in Writer objects
-    virtual void readPoints(PointData&)
-    {
-        throw;
-    }
-
     std::ostream& m_ostream;
 
     LasWriter& operator=(const LasWriter&); // not implemented
diff -r f1fb059c0456 -r 429bb8a2745c include/libpc/MosaicFilter.hpp
--- a/include/libpc/MosaicFilter.hpp	Wed Feb 23 15:06:04 2011 -0800
+++ b/include/libpc/MosaicFilter.hpp	Wed Feb 23 17:16:53 2011 -0800
@@ -48,7 +48,7 @@
 public:
     MosaicFilter(Stage& prevStage, Stage& prevStage2);
 
-    void readPoints(PointData&);
+    boost::uint32_t readPoints(PointData&);
 
     // BUG: what does seetToPoint() do for a mosaic filter?
 
diff -r f1fb059c0456 -r 429bb8a2745c include/libpc/PointData.hpp
--- a/include/libpc/PointData.hpp	Wed Feb 23 15:06:04 2011 -0800
+++ b/include/libpc/PointData.hpp	Wed Feb 23 17:16:53 2011 -0800
@@ -66,6 +66,10 @@
     // number of points in this buffer
     boost::uint32_t getNumPoints() const;
 
+    // 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
+    boost::uint32_t getNumValidPoints();
+
     // schema (number and kinds of fields) for a point in this buffer
     const SchemaLayout& getSchemaLayout() const;
 
diff -r f1fb059c0456 -r 429bb8a2745c include/libpc/Reader.hpp
--- a/include/libpc/Reader.hpp	Wed Feb 23 15:06:04 2011 -0800
+++ b/include/libpc/Reader.hpp	Wed Feb 23 17:16:53 2011 -0800
@@ -53,6 +53,8 @@
     // default just resets the point index
     virtual void reset();
 
+    bool atEnd() const;
+
 protected:
     boost::uint64_t m_currentPointIndex;
     boost::uint64_t m_numPointsRead;
diff -r f1fb059c0456 -r 429bb8a2745c include/libpc/Stage.hpp
--- a/include/libpc/Stage.hpp	Wed Feb 23 15:06:04 2011 -0800
+++ b/include/libpc/Stage.hpp	Wed Feb 23 17:16:53 2011 -0800
@@ -58,7 +58,9 @@
     // not match our own header's schema.  That's okay, though: all
     // that matters is that the buffer we are given has the fields
     // we need to write into.
-    virtual void readPoints(PointData&) = 0;
+    //
+    // Returns the number of valid points read.
+    virtual boost::uint32_t readPoints(PointData&) = 0;
 
     // advance (or retreat) to the Nth point in the file (absolute, 
     // not relative).  In some cases, this might be a very slow, painful
@@ -69,6 +71,9 @@
     // of the file, as if no reads had yet been done
     virtual void reset() = 0;
 
+    // returns true after we've read all the points available to this stage
+    virtual bool atEnd() const = 0;
+
     const Header& getHeader() const;
     Header& getHeader();
 
diff -r f1fb059c0456 -r 429bb8a2745c include/libpc/Writer.hpp
--- a/include/libpc/Writer.hpp	Wed Feb 23 15:06:04 2011 -0800
+++ b/include/libpc/Writer.hpp	Wed Feb 23 17:16:53 2011 -0800
@@ -47,24 +47,35 @@
 public:
     Writer(Stage& prevStage);
 
-    void write();
+    // size of the PointData buffer to use
+    void setChunkSize(boost::uint32_t);
+    boost::uint32_t getChunkSize() const;


More information about the Liblas-commits mailing list