[Liblas-commits]
libpc: improved virtual functions in Stage classes; implemented ...
liblas-commits at liblas.org
liblas-commits at liblas.org
Thu Mar 3 19:46:42 EST 2011
details: http://hg.liblas.orglibpc/rev/95b6b16e10c2
changeset: 167:95b6b16e10c2
user: Michael P. Gerlek <mpg at flaxen.com>
date: Thu Mar 03 16:44:46 2011 -0800
description:
improved virtual functions in Stage classes; implemented MosaicFilter
diffstat:
include/libpc/ColorFilter.hpp | 4 +-
include/libpc/CropFilter.hpp | 4 +-
include/libpc/FauxReader.hpp | 4 +-
include/libpc/Filter.hpp | 15 ++--
include/libpc/LasReader.hpp | 7 +-
include/libpc/MosaicFilter.hpp | 8 +-
include/libpc/Reader.hpp | 13 ++-
include/libpc/Stage.hpp | 38 ++++++++++-
include/libpc/Writer.hpp | 2 +-
src/ColorFilter.cpp | 4 +-
src/CropFilter.cpp | 4 +-
src/FauxReader.cpp | 19 ++---
src/Filter.cpp | 16 +++-
src/LasReader.cpp | 14 +---
src/LasWriter.cpp | 4 +-
src/MosaicFilter.cpp | 125 ++++++++++++++++++++++++----------------
src/Reader.cpp | 42 +++++++++---
src/Stage.cpp | 26 ++++++++
src/Writer.cpp | 6 +-
src/chipper.cpp | 2 +-
src/drivers/liblas/reader.cpp | 8 +--
src/drivers/liblas/reader.hpp | 7 +-
test/unit/CMakeLists.txt | 1 +
test/unit/FauxReaderTest.cpp | 4 +-
test/unit/LiblasReaderTest.cpp | 10 +-
test/unit/MosaicFilterTest.cpp | 109 +++++++++++++++++++++++++++++++++++
26 files changed, 345 insertions(+), 151 deletions(-)
diffs (truncated from 927 to 300 lines):
diff -r 946a47f1de74 -r 95b6b16e10c2 include/libpc/ColorFilter.hpp
--- a/include/libpc/ColorFilter.hpp Thu Mar 03 12:16:04 2011 -0800
+++ b/include/libpc/ColorFilter.hpp Thu Mar 03 16:44:46 2011 -0800
@@ -52,9 +52,9 @@
const std::string& getName() const;
- boost::uint32_t readPoints(PointData&);
+private:
+ boost::uint32_t readBuffer(PointData&);
-private:
void getColor(float value, boost::uint8_t& red, boost::uint8_t& green, boost::uint8_t& blue);
ColorFilter& operator=(const ColorFilter&); // not implemented
diff -r 946a47f1de74 -r 95b6b16e10c2 include/libpc/CropFilter.hpp
--- a/include/libpc/CropFilter.hpp Thu Mar 03 12:16:04 2011 -0800
+++ b/include/libpc/CropFilter.hpp Thu Mar 03 16:44:46 2011 -0800
@@ -51,9 +51,9 @@
const std::string& getName() const;
- boost::uint32_t readPoints(PointData&);
+private:
+ boost::uint32_t readBuffer(PointData&);
-private:
Bounds<double> m_bounds;
CropFilter& operator=(const CropFilter&); // not implemented
diff -r 946a47f1de74 -r 95b6b16e10c2 include/libpc/FauxReader.hpp
--- a/include/libpc/FauxReader.hpp Thu Mar 03 12:16:04 2011 -0800
+++ b/include/libpc/FauxReader.hpp Thu Mar 03 16:44:46 2011 -0800
@@ -68,11 +68,11 @@
const std::string& getName() const;
- boost::uint32_t readPoints(PointData& data);
-
void seekToPoint(boost::uint64_t);
private:
+ boost::uint32_t readBuffer(PointData& data);
+
Mode m_mode;
FauxReader& operator=(const FauxReader&); // not implemented
diff -r 946a47f1de74 -r 95b6b16e10c2 include/libpc/Filter.hpp
--- a/include/libpc/Filter.hpp Thu Mar 03 12:16:04 2011 -0800
+++ b/include/libpc/Filter.hpp Thu Mar 03 16:44:46 2011 -0800
@@ -47,21 +47,20 @@
public:
Filter(Stage& prevStage);
- virtual boost::uint32_t readPoints(PointData&) = 0;
+ // default behaviour for filters is just to call readBegin() on the previous stage
+ virtual void readBegin(boost::uint32_t numPointsToRead);
+
+ // default behaviour for filters is just to call readEnd() on the previous stage
+ virtual void readEnd(boost::uint32_t numPointsRead);
// advance (or retreat) to the Nth point in the file (absolute,
// default behaviour for filters is just to call seek on the previous stage
virtual void seekToPoint(boost::uint64_t pointNum);
- // reset the filter
- // 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;
+ // default behaviour for filters is just to call the previous stage
+ virtual boost::uint64_t getCurrentPointIndex() const;
protected:
- int m_lastPointRead;
Stage& m_prevStage;
private:
diff -r 946a47f1de74 -r 95b6b16e10c2 include/libpc/LasReader.hpp
--- a/include/libpc/LasReader.hpp Thu Mar 03 12:16:04 2011 -0800
+++ b/include/libpc/LasReader.hpp Thu Mar 03 16:44:46 2011 -0800
@@ -50,18 +50,15 @@
const std::string& getName() const;
- virtual boost::uint32_t readPoints(PointData&);
-
// default is to reset() and then read N points manually
// override this if you can
virtual void seekToPoint(boost::uint64_t pointNum);
- // default just resets the point index
- virtual void reset();
-
const LasHeader& getLasHeader() const;
protected:
+ virtual boost::uint32_t readBuffer(PointData&);
+
LasHeader& getLasHeader();
void setLasHeader(const LasHeader&);
diff -r 946a47f1de74 -r 95b6b16e10c2 include/libpc/MosaicFilter.hpp
--- a/include/libpc/MosaicFilter.hpp Thu Mar 03 12:16:04 2011 -0800
+++ b/include/libpc/MosaicFilter.hpp Thu Mar 03 16:44:46 2011 -0800
@@ -46,16 +46,16 @@
class LIBPC_DLL MosaicFilter : public Filter
{
public:
- MosaicFilter(Stage& prevStage, Stage& prevStage2);
+ MosaicFilter(Stage& prevStage, std::vector<Stage*> prevStages);
const std::string& getName() const;
- boost::uint32_t readPoints(PointData&);
-
// BUG: what does seetToPoint() do for a mosaic filter?
private:
- Stage& m_prevStage2;
+ boost::uint32_t readBuffer(PointData&);
+
+ std::vector<Stage*> m_prevStages;
MosaicFilter& operator=(const MosaicFilter&); // not implemented
MosaicFilter(const MosaicFilter&); // not implemented
diff -r 946a47f1de74 -r 95b6b16e10c2 include/libpc/Reader.hpp
--- a/include/libpc/Reader.hpp Thu Mar 03 12:16:04 2011 -0800
+++ b/include/libpc/Reader.hpp Thu Mar 03 16:44:46 2011 -0800
@@ -46,20 +46,21 @@
public:
Reader();
+ virtual void readBegin(boost::uint32_t numPointsToRead);
+
+ virtual void readEnd(boost::uint32_t numPointsRead);
+
// default is to reset() and then read N points manually
// override this if you can
virtual void seekToPoint(boost::uint64_t pointNum);
- // default just resets the point index
- virtual void reset();
-
- bool atEnd() const;
+ virtual boost::uint64_t getCurrentPointIndex() const;
protected:
- boost::uint64_t m_currentPointIndex;
- boost::uint64_t m_numPointsRead;
+ void setCurrentPointIndex(boost::uint64_t);
private:
+ boost::uint64_t m_currentPointIndex;
Reader& operator=(const Reader&); // not implemented
Reader(const Reader&); // not implemented
diff -r 946a47f1de74 -r 95b6b16e10c2 include/libpc/Stage.hpp
--- a/include/libpc/Stage.hpp Thu Mar 03 12:16:04 2011 -0800
+++ b/include/libpc/Stage.hpp Thu Mar 03 16:44:46 2011 -0800
@@ -64,20 +64,48 @@
// 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
+ // readBegin/readBuffer/readEnd functions below, not this one.
+ //
// Returns the number of valid points read.
- virtual boost::uint32_t readPoints(PointData&) = 0;
+ boost::uint32_t read(PointData&);
+
+ // Implement this to do any setup work you need to do before the
+ // sequence of calls the readBuffer starts up.
+ //
+ // Do not call this yourself -- use the read() call above.
+ virtual void readBegin(boost::uint32_t numPointsToRead) = 0;
+
+ // Implement this to do the actual work to fill in a buffer of points.
+ //
+ // Do not call this yourself -- use the read() call above
+ //
+ // This is called after readBegin() is called. It may be called
+ // multiple times for one read() call.
+ virtual boost::uint32_t readBuffer(PointData&) = 0;
+
+ // This is called once, after the readBuffer() calls are done.
+ //
+ // Do not call this yourself -- use the read() call above.
+ virtual void readEnd(boost::uint32_t numPointsRead) = 0;
// 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;
- // resets the object's state such that it is positioned to the beginning
- // of the file, as if no reads had yet been done
- virtual void reset() = 0;
+ // 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).
+ virtual boost::uint64_t getCurrentPointIndex() const = 0;
+
+ // returns the number of points this stage has available
+ // (actually a convenience function that gets it from the header)
+ boost::uint64_t getNumPoints() const;
// returns true after we've read all the points available to this stage
- virtual bool atEnd() const = 0;
+ // (actually a convenience function that compares getCurrentPointIndex and getNumPoints)
+ bool atEnd() const;
const Header& getHeader() const;
Header& getHeader();
diff -r 946a47f1de74 -r 95b6b16e10c2 include/libpc/Writer.hpp
--- a/include/libpc/Writer.hpp Thu Mar 03 12:16:04 2011 -0800
+++ b/include/libpc/Writer.hpp Thu Mar 03 16:44:46 2011 -0800
@@ -67,7 +67,7 @@
virtual void writeEnd() = 0;
// not generally used in Writer objects
- virtual boost::uint32_t readPoints(PointData&);
+ virtual boost::uint32_t readBuffer(PointData&);
// these two are valid for use after writeBegin has been called
std::size_t m_actualNumPointsWritten;
diff -r 946a47f1de74 -r 95b6b16e10c2 src/ColorFilter.cpp
--- a/src/ColorFilter.cpp Thu Mar 03 12:16:04 2011 -0800
+++ b/src/ColorFilter.cpp Thu Mar 03 16:44:46 2011 -0800
@@ -60,9 +60,9 @@
}
-boost::uint32_t ColorFilter::readPoints(PointData& data)
+boost::uint32_t ColorFilter::readBuffer(PointData& data)
{
- m_prevStage.readPoints(data);
+ m_prevStage.read(data);
boost::uint32_t numPoints = data.getNumPoints();
diff -r 946a47f1de74 -r 95b6b16e10c2 src/CropFilter.cpp
--- a/src/CropFilter.cpp Thu Mar 03 12:16:04 2011 -0800
+++ b/src/CropFilter.cpp Thu Mar 03 16:44:46 2011 -0800
@@ -56,9 +56,9 @@
}
-boost::uint32_t CropFilter::readPoints(PointData& data)
+boost::uint32_t CropFilter::readBuffer(PointData& data)
{
- m_prevStage.readPoints(data);
+ m_prevStage.read(data);
boost::uint32_t numPoints = data.getNumPoints();
diff -r 946a47f1de74 -r 95b6b16e10c2 src/FauxReader.cpp
--- a/src/FauxReader.cpp Thu Mar 03 12:16:04 2011 -0800
+++ b/src/FauxReader.cpp Thu Mar 03 16:44:46 2011 -0800
@@ -95,7 +95,7 @@
}
-boost::uint32_t FauxReader::readPoints(PointData& data)
+boost::uint32_t FauxReader::readBuffer(PointData& data)
{
if (data.getSchemaLayout().getSchema().getDimensions().size() != 4)
throw not_yet_implemented("need to add ability to read from arbitrary fields");
@@ -103,7 +103,7 @@
// make up some data and put it into the buffer
const boost::uint32_t numPoints = data.getNumPoints();
- assert(m_currentPointIndex + numPoints <= getHeader().getNumPoints());
+ assert(getCurrentPointIndex() + numPoints <= getHeader().getNumPoints());
const SchemaLayout& schemaLayout = data.getSchemaLayout();
const Schema& schema = schemaLayout.getSchema();
@@ -118,12 +118,12 @@
const double minZ = dims[2].getMinimum();
const double maxZ = dims[2].getMaximum();
- const std::size_t offsetT = schema.getDimensionIndex(Dimension::Field_GpsTime);
- const std::size_t offsetX = schema.getDimensionIndex(Dimension::Field_X);
- const std::size_t offsetY = schema.getDimensionIndex(Dimension::Field_Y);
- const std::size_t offsetZ = schema.getDimensionIndex(Dimension::Field_Z);
+ const int offsetT = schema.getDimensionIndex(Dimension::Field_GpsTime);
+ const int offsetX = schema.getDimensionIndex(Dimension::Field_X);
+ const int offsetY = schema.getDimensionIndex(Dimension::Field_Y);
+ const int offsetZ = schema.getDimensionIndex(Dimension::Field_Z);
- boost::uint64_t time = m_currentPointIndex;
+ boost::uint64_t time = getCurrentPointIndex();
for (boost::uint32_t pointIndex=0; pointIndex<numPoints; pointIndex++)
{
@@ -153,16 +153,13 @@
++time;
}
More information about the Liblas-commits
mailing list