[Liblas-commits] libpc: get rid of readBegin/End;
each concrete stage must manage...
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Mar 11 19:24:06 EST 2011
details: http://hg.liblas.orglibpc/rev/f57baec8e09d
changeset: 220:f57baec8e09d
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Mar 11 16:23:59 2011 -0800
description:
get rid of readBegin/End; each concrete stage must manage currentPointIndex on its own now
diffstat:
include/libpc/CacheFilter.hpp | 6 ------
include/libpc/FauxReader.hpp | 2 +-
include/libpc/Filter.hpp | 10 +---------
include/libpc/LasReader.hpp | 2 +-
include/libpc/Producer.hpp | 13 +------------
include/libpc/Stage.hpp | 36 +++++++++++++++---------------------
src/CacheFilter.cpp | 33 ++++++++++++---------------------
src/CropFilter.cpp | 6 +++---
src/FauxReader.cpp | 2 ++
src/Filter.cpp | 20 --------------------
src/Producer.cpp | 27 ---------------------------
src/Stage.cpp | 27 +++++++++++++++++++--------
src/drivers/liblas/reader.hpp | 4 +---
13 files changed, 56 insertions(+), 132 deletions(-)
diffs (truncated from 436 to 300 lines):
diff -r 734f4bc84222 -r f57baec8e09d include/libpc/CacheFilter.hpp
--- a/include/libpc/CacheFilter.hpp Fri Mar 11 15:36:08 2011 -0800
+++ b/include/libpc/CacheFilter.hpp Fri Mar 11 16:23:59 2011 -0800
@@ -56,9 +56,6 @@
const std::string& getName() const;
// override
- boost::uint64_t getCurrentPointIndex() const;
-
- // override
void seekToPoint(boost::uint64_t index);
// clear cache (but leave cache params unchanged)
@@ -81,9 +78,6 @@
private:
boost::uint32_t readBuffer(PointData&);
- boost::uint64_t m_currentPointIndex;
- boost::uint64_t m_storedPointIndex;
- PointData* m_storedPointData;
boost::uint64_t m_numPointsRequested;
boost::uint64_t m_numPointsRead;
diff -r 734f4bc84222 -r f57baec8e09d include/libpc/FauxReader.hpp
--- a/include/libpc/FauxReader.hpp Fri Mar 11 15:36:08 2011 -0800
+++ b/include/libpc/FauxReader.hpp Fri Mar 11 16:23:59 2011 -0800
@@ -71,7 +71,7 @@
void seekToPoint(boost::uint64_t);
private:
- boost::uint32_t readBuffer(PointData& data);
+ boost::uint32_t readBuffer(PointData&);
Mode m_mode;
diff -r 734f4bc84222 -r f57baec8e09d include/libpc/Filter.hpp
--- a/include/libpc/Filter.hpp Fri Mar 11 15:36:08 2011 -0800
+++ b/include/libpc/Filter.hpp Fri Mar 11 16:23:59 2011 -0800
@@ -47,19 +47,11 @@
public:
Filter(Stage& prevStage);
- // 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);
-
+protected:
// 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);
- // default behaviour for filters is just to call the previous stage
- virtual boost::uint64_t getCurrentPointIndex() const;
-
protected:
Stage& m_prevStage;
diff -r 734f4bc84222 -r f57baec8e09d include/libpc/LasReader.hpp
--- a/include/libpc/LasReader.hpp Fri Mar 11 15:36:08 2011 -0800
+++ b/include/libpc/LasReader.hpp Fri Mar 11 16:23:59 2011 -0800
@@ -57,7 +57,7 @@
const LasHeader& getLasHeader() const;
protected:
- virtual boost::uint32_t readBuffer(PointData&);
+ boost::uint32_t readBuffer(PointData&);
LasHeader& getLasHeader();
void setLasHeader(const LasHeader&);
diff -r 734f4bc84222 -r f57baec8e09d include/libpc/Producer.hpp
--- a/include/libpc/Producer.hpp Fri Mar 11 15:36:08 2011 -0800
+++ b/include/libpc/Producer.hpp Fri Mar 11 16:23:59 2011 -0800
@@ -46,22 +46,11 @@
public:
Producer();
- virtual void readBegin(boost::uint32_t numPointsToRead);
-
- virtual void readEnd(boost::uint32_t numPointsRead);
-
- // default is to reset() and then read N points manually
+ // default is to read N points manually
// override this if you can
virtual void seekToPoint(boost::uint64_t pointNum);
- virtual boost::uint64_t getCurrentPointIndex() const;
-
-protected:
- void setCurrentPointIndex(boost::uint64_t);
-
private:
- boost::uint64_t m_currentPointIndex;
-
Producer& operator=(const Producer&); // not implemented
Producer(const Producer&); // not implemented
};
diff -r 734f4bc84222 -r f57baec8e09d include/libpc/Stage.hpp
--- a/include/libpc/Stage.hpp Fri Mar 11 15:36:08 2011 -0800
+++ b/include/libpc/Stage.hpp Fri Mar 11 16:23:59 2011 -0800
@@ -65,30 +65,11 @@
// we need to write into.
//
// This is NOT virtual. Derived classes should override the
- // readBegin/readBuffer/readEnd functions below, not this one.
+ // readBuffer function below, not this one.
//
// Returns the number of valid points read.
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.
@@ -97,7 +78,7 @@
// 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;
+ boost::uint64_t getCurrentPointIndex() const;
// returns the number of points this stage has available
// (actually a convenience function that gets it from the header)
@@ -111,10 +92,23 @@
Header& getHeader();
protected:
+ // Implement this to do the actual work to fill in a buffer of points.
+ virtual boost::uint32_t readBuffer(PointData&) = 0;
+
+ // Each concrete stage is repsonsible for managing its own current
+ // point index when a read or seek occurs. Call this function to set
+ // the value.
+ void setCurrentPointIndex(boost::uint64_t delta);
+
+ // this is easier than saying setCurrentPointIndex(getCurrentPointIndex()+n)
+ void incrementCurrentPointIndex(boost::uint64_t currentPointDelta);
+
void setHeader(Header*); // stage takes ownership
private:
Header* m_header;
+
+ boost::uint64_t m_currentPointIndex;
Stage& operator=(const Stage&); // not implemented
Stage(const Stage&); // not implemented
diff -r 734f4bc84222 -r f57baec8e09d src/CacheFilter.cpp
--- a/src/CacheFilter.cpp Fri Mar 11 15:36:08 2011 -0800
+++ b/src/CacheFilter.cpp Fri Mar 11 16:23:59 2011 -0800
@@ -43,9 +43,6 @@
// cache block size is measured in Points, not bytes
CacheFilter::CacheFilter(Stage& prevStage, boost::uint32_t maxCacheBlocks, boost::uint32_t cacheBlockSize)
: Filter(prevStage)
- , m_currentPointIndex(0)
- , m_storedPointIndex(0)
- , m_storedPointData(NULL)
, m_numPointsRequested(0)
, m_numPointsRead(0)
, m_cache(NULL)
@@ -59,8 +56,6 @@
CacheFilter::~CacheFilter()
{
- delete m_storedPointData;
-
delete m_cache;
}
@@ -99,15 +94,9 @@
}
-boost::uint64_t CacheFilter::getCurrentPointIndex() const
-{
- return m_currentPointIndex;
-}
-
-
void CacheFilter::seekToPoint(boost::uint64_t index)
{
- m_currentPointIndex = index;
+ setCurrentPointIndex(index);
m_prevStage.seekToPoint(index);
}
@@ -126,6 +115,8 @@
boost::uint32_t CacheFilter::readBuffer(PointData& data)
{
+ const boost::uint64_t currentPointIndex = getCurrentPointIndex();
+
// for now, we only read from the cache if they are asking for one point
// (this avoids the problem of an N-point request needing more than one
// cached block to satisfy it)
@@ -137,15 +128,15 @@
// and the block we got is properly aligned and not already cached,
// then let's cache it!
if (data.getNumPoints() == m_cacheBlockSize && numRead == m_cacheBlockSize &&
- (m_currentPointIndex % m_cacheBlockSize == 0) &&
- m_cache->lookup(m_currentPointIndex) == NULL)
+ (currentPointIndex % m_cacheBlockSize == 0) &&
+ m_cache->lookup(currentPointIndex) == NULL)
{
PointData* block = new PointData(data.getSchemaLayout(), m_cacheBlockSize);
block->copyPointsFast(0, 0, data, m_cacheBlockSize);
- m_cache->insert(m_currentPointIndex, block);
+ m_cache->insert(currentPointIndex, block);
}
- m_currentPointIndex += numRead;
+ incrementCurrentPointIndex(numRead);
m_numPointsRead += data.getNumPoints();
m_numPointsRequested += data.getNumPoints();
@@ -154,18 +145,18 @@
}
// they asked for just one point -- first, check Mister Cache
- boost::uint64_t blockNum = m_currentPointIndex / m_cacheBlockSize;
+ const boost::uint64_t blockNum = currentPointIndex / m_cacheBlockSize;
PointData* block = m_cache->lookup(blockNum);
if (block != NULL)
{
// A hit! A palpable hit!
- data.copyPointFast(0, m_currentPointIndex % m_cacheBlockSize, *block);
+ data.copyPointFast(0, currentPointIndex % m_cacheBlockSize, *block);
m_numPointsRead += 0;
m_numPointsRequested += 1;
- m_currentPointIndex += 1;
+ incrementCurrentPointIndex(1);
- m_prevStage.seekToPoint(m_currentPointIndex);
+ m_prevStage.seekToPoint(getCurrentPointIndex());
return 1;
}
@@ -173,7 +164,7 @@
const boost::uint32_t numRead = m_prevStage.read(data);
m_numPointsRead += numRead;
m_numPointsRequested += numRead;
- m_currentPointIndex += numRead;
+ incrementCurrentPointIndex(numRead);
return numRead;
}
diff -r 734f4bc84222 -r f57baec8e09d src/CropFilter.cpp
--- a/src/CropFilter.cpp Fri Mar 11 15:36:08 2011 -0800
+++ b/src/CropFilter.cpp Fri Mar 11 16:23:59 2011 -0800
@@ -58,9 +58,7 @@
boost::uint32_t CropFilter::readBuffer(PointData& data)
{
- m_prevStage.read(data);
-
- boost::uint32_t numPoints = data.getNumPoints();
+ boost::uint32_t numPoints = m_prevStage.read(data);
const SchemaLayout& schemaLayout = data.getSchemaLayout();
const Schema& schema = schemaLayout.getSchema();
@@ -92,6 +90,8 @@
}
}
+ incrementCurrentPointIndex(numPoints);
+
return numValidPoints;
}
diff -r 734f4bc84222 -r f57baec8e09d src/FauxReader.cpp
--- a/src/FauxReader.cpp Fri Mar 11 15:36:08 2011 -0800
+++ b/src/FauxReader.cpp Fri Mar 11 16:23:59 2011 -0800
@@ -153,6 +153,8 @@
++time;
}
+ incrementCurrentPointIndex(numPoints);
+
return numPoints;
}
More information about the Liblas-commits
mailing list