[Liblas-commits] hg-main-tree: refactor for const-correctness and
to unfriend the...
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Mar 23 13:54:33 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/55dde853abae
changeset: 410:55dde853abae
user: Michael P. Gerlek <mpg at flaxen.com>
date: Wed Mar 23 10:54:26 2011 -0700
description:
refactor for const-correctness and to unfriend the Iter
diffstat:
include/libpc/drivers/faux/Reader.hpp | 6 +-
src/drivers/faux/Iterator.cpp | 69 +---------------------------------
src/drivers/faux/Reader.cpp | 71 +++++++++++++++++++++++++++++++++++
3 files changed, 76 insertions(+), 70 deletions(-)
diffs (182 lines):
diff -r 8404b7fd80ce -r 55dde853abae include/libpc/drivers/faux/Reader.hpp
--- a/include/libpc/drivers/faux/Reader.hpp Wed Mar 23 10:47:37 2011 -0700
+++ b/include/libpc/drivers/faux/Reader.hpp Wed Mar 23 10:54:26 2011 -0700
@@ -40,8 +40,6 @@
namespace libpc { namespace drivers { namespace faux {
-class Iterator;
-
// 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.
@@ -74,7 +72,11 @@
libpc::Iterator* createIterator() const;
+ // this is called by the stage's iterator
+ boost::uint32_t processBuffer(PointBuffer& data, boost::uint64_t index) const;
+
private:
+
Mode m_mode;
Reader& operator=(const Reader&); // not implemented
diff -r 8404b7fd80ce -r 55dde853abae src/drivers/faux/Iterator.cpp
--- a/src/drivers/faux/Iterator.cpp Wed Mar 23 10:47:37 2011 -0700
+++ b/src/drivers/faux/Iterator.cpp Wed Mar 23 10:54:26 2011 -0700
@@ -72,74 +72,7 @@
boost::uint32_t Iterator::readImpl(PointBuffer& data)
{
- Reader& reader = const_cast<Reader&>(m_reader); // BUG BUG BUG
-
- if (data.getSchemaLayout().getSchema().getDimensions().size() != 4)
- throw not_yet_implemented("need to add ability to read from arbitrary fields");
-
- // make up some data and put it into the buffer
-
- const SchemaLayout& schemaLayout = data.getSchemaLayout();
- const Schema& schema = schemaLayout.getSchema();
- Header& header = reader.getHeader();
-
- // how many are they asking for?
- boost::uint64_t numPointsWanted = data.getCapacity();
-
- // we can only give them as many as we have left
- boost::uint64_t numPointsAvailable = header.getNumPoints() - getIndex();
- if (numPointsAvailable < numPointsWanted)
- numPointsWanted = numPointsAvailable;
-
- const Bounds<double>& bounds = header.getBounds();
- const std::vector< Range<double> >& dims = bounds.dimensions();
- const double minX = dims[0].getMinimum();
- const double maxX = dims[0].getMaximum();
- const double minY = dims[1].getMinimum();
- const double maxY = dims[1].getMaximum();
- const double minZ = dims[2].getMinimum();
- const double maxZ = dims[2].getMaximum();
-
- const int offsetT = schema.getDimensionIndex(Dimension::Field_Time);
- 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 = getIndex();
-
- const Reader::Mode mode = reader.getMode();
-
- boost::uint32_t& cnt = data.getNumPointsRef();
- cnt = 0;
- for (boost::uint32_t pointIndex=0; pointIndex<numPointsWanted; pointIndex++)
- {
- double x;
- double y;
- double z;
- if (mode == Reader::Random)
- {
- x = (double)Utils::random(minX, maxX);
- y = (double)Utils::random(minY, maxY);
- z = (double)Utils::random(minZ, maxZ);
- }
- else
- {
- x = (double)minX;
- y = (double)minY;
- z = (double)minZ;
- }
-
- data.setField<double>(pointIndex, offsetX, x);
- data.setField<double>(pointIndex, offsetY, y);
- data.setField<double>(pointIndex, offsetZ, z);
- data.setField<boost::uint64_t>(pointIndex, offsetT, time);
-
- ++time;
- ++cnt;
- assert(cnt <= data.getCapacity());
- }
-
- return cnt;
+ return m_reader.processBuffer(data, getIndex());
}
} } } // namespaces
diff -r 8404b7fd80ce -r 55dde853abae src/drivers/faux/Reader.cpp
--- a/src/drivers/faux/Reader.cpp Wed Mar 23 10:47:37 2011 -0700
+++ b/src/drivers/faux/Reader.cpp Wed Mar 23 10:54:26 2011 -0700
@@ -110,4 +110,75 @@
}
+boost::uint32_t Reader::processBuffer(PointBuffer& data, boost::uint64_t index) const
+{
+ const SchemaLayout& schemaLayout = data.getSchemaLayout();
+ const Schema& schema = schemaLayout.getSchema();
+ const Header& header = getHeader();
+
+ if (schema.getDimensions().size() != 4)
+ throw not_yet_implemented("need to add ability to read from arbitrary fields");
+
+ // make up some data and put it into the buffer
+
+ // how many are they asking for?
+ boost::uint64_t numPointsWanted = data.getCapacity();
+
+ // we can only give them as many as we have left
+ boost::uint64_t numPointsAvailable = header.getNumPoints() - index;
+ if (numPointsAvailable < numPointsWanted)
+ numPointsWanted = numPointsAvailable;
+
+ const Bounds<double>& bounds = header.getBounds();
+ const std::vector< Range<double> >& dims = bounds.dimensions();
+ const double minX = dims[0].getMinimum();
+ const double maxX = dims[0].getMaximum();
+ const double minY = dims[1].getMinimum();
+ const double maxY = dims[1].getMaximum();
+ const double minZ = dims[2].getMinimum();
+ const double maxZ = dims[2].getMaximum();
+
+ const int offsetT = schema.getDimensionIndex(Dimension::Field_Time);
+ 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 = index;
+
+ const Reader::Mode mode = getMode();
+
+ boost::uint32_t& cnt = data.getNumPointsRef();
+ cnt = 0;
+ for (boost::uint32_t pointIndex=0; pointIndex<numPointsWanted; pointIndex++)
+ {
+ double x;
+ double y;
+ double z;
+ if (mode == Reader::Random)
+ {
+ x = (double)Utils::random(minX, maxX);
+ y = (double)Utils::random(minY, maxY);
+ z = (double)Utils::random(minZ, maxZ);
+ }
+ else
+ {
+ x = (double)minX;
+ y = (double)minY;
+ z = (double)minZ;
+ }
+
+ data.setField<double>(pointIndex, offsetX, x);
+ data.setField<double>(pointIndex, offsetY, y);
+ data.setField<double>(pointIndex, offsetZ, z);
+ data.setField<boost::uint64_t>(pointIndex, offsetT, time);
+
+ ++time;
+ ++cnt;
+ assert(cnt <= data.getCapacity());
+ }
+
+ return cnt;
+}
+
+
} } } // namespaces
More information about the Liblas-commits
mailing list