[Liblas-commits] hg-main-tree: added a Ramp mode to FauxReader
liblas-commits at liblas.org
liblas-commits at liblas.org
Thu Mar 24 14:19:17 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/acddf79a6421
changeset: 431:acddf79a6421
user: Michael P. Gerlek <mpg at flaxen.com>
date: Thu Mar 24 11:19:10 2011 -0700
description:
added a Ramp mode to FauxReader
diffstat:
include/libpc/drivers/faux/Reader.hpp | 12 +++++---
src/drivers/faux/Reader.cpp | 33 ++++++++++++++++-------
test/unit/FauxReaderTest.cpp | 49 ++++++++++++++++++++++++++++++++--
3 files changed, 76 insertions(+), 18 deletions(-)
diffs (160 lines):
diff -r ea942f2e7393 -r acddf79a6421 include/libpc/drivers/faux/Reader.hpp
--- a/include/libpc/drivers/faux/Reader.hpp Thu Mar 24 10:54:51 2011 -0700
+++ b/include/libpc/drivers/faux/Reader.hpp Thu Mar 24 11:19:10 2011 -0700
@@ -48,10 +48,11 @@
// 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. The Time field
-// is always set to the point number.
+// It supports a few modes:
+// - "random" generates points that are randomly distributed within the given bounding box
+// - "constant" generates its points to always be at the minimum of the bounding box
+// - "ramp" generates its points as a linear ramp from the minimum of the bbox to the maximum
+// In all these modes, however, the Time field is always set to the point number.
//
class LIBPC_DLL Reader : public libpc::Stage
{
@@ -59,7 +60,8 @@
enum Mode
{
Constant,
- Random
+ Random,
+ Ramp
};
public:
diff -r ea942f2e7393 -r acddf79a6421 src/drivers/faux/Reader.cpp
--- a/src/drivers/faux/Reader.cpp Thu Mar 24 10:54:51 2011 -0700
+++ b/src/drivers/faux/Reader.cpp Thu Mar 24 11:19:10 2011 -0700
@@ -142,6 +142,10 @@
const double maxY = dims[1].getMaximum();
const double minZ = dims[2].getMinimum();
const double maxZ = dims[2].getMaximum();
+
+ const double delX = (maxX - minX) / header.getNumPoints();
+ const double delY = (maxY - minY) / header.getNumPoints();
+ const double delZ = (maxZ - minZ) / header.getNumPoints();
const int offsetT = schema.getDimensionIndex(Dimension::Field_Time);
const int offsetX = schema.getDimensionIndex(Dimension::Field_X);
@@ -159,17 +163,26 @@
double x;
double y;
double z;
- if (mode == Reader::Random)
+ switch (mode)
{
- 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;
+ case Reader::Random:
+ x = Utils::random(minX, maxX);
+ y = Utils::random(minY, maxY);
+ z = Utils::random(minZ, maxZ);
+ break;
+ case Reader::Constant:
+ x = minX;
+ y = minY;
+ z = minZ;
+ break;
+ case Reader::Ramp:
+ x = minX + delX * pointIndex;
+ y = minY + delY * pointIndex;
+ z = minZ + delZ * pointIndex;
+ break;
+ default:
+ throw libpc_error("invalid mode in FauxReader");
+ break;
}
data.setField<double>(pointIndex, offsetX, x);
diff -r ea942f2e7393 -r acddf79a6421 test/unit/FauxReaderTest.cpp
--- a/test/unit/FauxReaderTest.cpp Thu Mar 24 10:54:51 2011 -0700
+++ b/test/unit/FauxReaderTest.cpp Thu Mar 24 11:19:10 2011 -0700
@@ -41,7 +41,7 @@
BOOST_AUTO_TEST_SUITE(FauxReaderTest)
-BOOST_AUTO_TEST_CASE(test_constant_sequential)
+BOOST_AUTO_TEST_CASE(test_constant_mode_sequential_iter)
{
Bounds<double> bounds(1.0, 2.0, 3.0, 101.0, 102.0, 103.0);
libpc::drivers::faux::Reader reader(bounds, 1000, libpc::drivers::faux::Reader::Constant);
@@ -82,7 +82,7 @@
}
-BOOST_AUTO_TEST_CASE(test_constant_random)
+BOOST_AUTO_TEST_CASE(test_constant_mode_random_iter)
{
Bounds<double> bounds(1.0, 2.0, 3.0, 101.0, 102.0, 103.0);
libpc::drivers::faux::Reader reader(bounds, 1000, libpc::drivers::faux::Reader::Constant);
@@ -183,7 +183,7 @@
}
-BOOST_AUTO_TEST_CASE(test_random)
+BOOST_AUTO_TEST_CASE(test_random_mode)
{
Bounds<double> bounds(1.0, 2.0, 3.0, 101.0, 102.0, 103.0);
libpc::drivers::faux::Reader reader(bounds, 1000, libpc::drivers::faux::Reader::Random);
@@ -222,6 +222,49 @@
}
+BOOST_AUTO_TEST_CASE(test_ramp_mode)
+{
+ Bounds<double> bounds(1.0, 2.0, 3.0, 101.0, 152.0, 203.0);
+ libpc::drivers::faux::Reader reader(bounds, 750, libpc::drivers::faux::Reader::Ramp);
+
+ const Schema& schema = reader.getHeader().getSchema();
+ SchemaLayout layout(schema);
+
+ PointBuffer data(layout, 750);
+
+ SequentialIterator* iter = reader.createSequentialIterator();
+ boost::uint32_t numRead = iter->read(data);
+
+ BOOST_CHECK(numRead == 750);
+
+ int offsetX = schema.getDimensionIndex(Dimension::Field_X);
+ int offsetY = schema.getDimensionIndex(Dimension::Field_Y);
+ int offsetZ = schema.getDimensionIndex(Dimension::Field_Z);
+ int offsetT = schema.getDimensionIndex(Dimension::Field_Time);
+
+ double delX = (101.0 - 1.0) / 750.0;
+ double delY = (152.0 - 2.0) / 750.0;
+ double delZ = (203.0 - 3.0) / 750.0;
+
+ for (boost::uint32_t i=0; i<numRead; i++)
+ {
+ double x = data.getField<double>(i, offsetX);
+ double y = data.getField<double>(i, offsetY);
+ double z = data.getField<double>(i, offsetZ);
+ boost::uint64_t t = data.getField<boost::uint64_t>(i, offsetT);
+
+ BOOST_CHECK(Utils::compare_approx<double>(x, 1.0 + delX*i, 0.0001));
+ BOOST_CHECK(Utils::compare_approx<double>(y, 2.0 + delY*i, 0.0001));
+ BOOST_CHECK(Utils::compare_approx<double>(z, 3.0 + delZ*i, 0.0001));
+ BOOST_CHECK(t == i);
+ }
+
+ delete iter;
+
+ return;
+}
+
+
BOOST_AUTO_TEST_CASE(test_custom_fields)
{
Bounds<double> bounds(1.0, 2.0, 3.0, 101.0, 102.0, 103.0);
More information about the Liblas-commits
mailing list