[Liblas-commits] libpc: started ability to use custom fields

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Feb 28 18:31:46 EST 2011


details:   http://hg.liblas.orglibpc/rev/ffbba34bc372
changeset: 116:ffbba34bc372
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Mon Feb 28 15:28:52 2011 -0800
description:
started ability to use custom fields
Subject: libpc: note custom fields NYI

details:   http://hg.liblas.orglibpc/rev/75065ec5d144
changeset: 117:75065ec5d144
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Mon Feb 28 15:30:53 2011 -0800
description:
note custom fields NYI
Subject: libpc: added addDims()

details:   http://hg.liblas.orglibpc/rev/a4f68c513443
changeset: 118:a4f68c513443
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Mon Feb 28 15:31:29 2011 -0800
description:
added addDims()

diffstat:

 include/libpc/FauxReader.hpp |   1 +
 include/libpc/Schema.hpp     |   1 +
 src/FauxReader.cpp           |  29 ++++++++++++++++++++++++++---
 src/Schema.cpp               |  14 ++++++++++++--
 test/unit/FauxReaderTest.cpp |  21 +++++++++++++++++++++
 5 files changed, 61 insertions(+), 5 deletions(-)

diffs (128 lines):

diff -r 531aa8c0544d -r a4f68c513443 include/libpc/FauxReader.hpp
--- a/include/libpc/FauxReader.hpp	Mon Feb 28 14:22:15 2011 -0800
+++ b/include/libpc/FauxReader.hpp	Mon Feb 28 15:31:29 2011 -0800
@@ -64,6 +64,7 @@
 
 public:
     FauxReader(const Bounds<double>&, int numPoints, Mode mode);
+    FauxReader(const Bounds<double>&, int numPoints, Mode mode, const std::vector<Dimension>& dimensions);
 
     boost::uint32_t readPoints(PointData& data);
 
diff -r 531aa8c0544d -r a4f68c513443 include/libpc/Schema.hpp
--- a/include/libpc/Schema.hpp	Mon Feb 28 14:22:15 2011 -0800
+++ b/include/libpc/Schema.hpp	Mon Feb 28 15:31:29 2011 -0800
@@ -74,6 +74,7 @@
     bool operator!=(const Schema& other) const;
 
     void addDimension(Dimension const& dim);
+    void addDimensions(const std::vector<Dimension>& dims);
 
     const Dimension& getDimension(std::size_t index) const
     {
diff -r 531aa8c0544d -r a4f68c513443 src/FauxReader.cpp
--- a/src/FauxReader.cpp	Mon Feb 28 14:22:15 2011 -0800
+++ b/src/FauxReader.cpp	Mon Feb 28 15:31:29 2011 -0800
@@ -37,6 +37,7 @@
 
 #include "libpc/FauxReader.hpp"
 #include "libpc/Utils.hpp"
+#include "libpc/exceptions.hpp"
 
 using std::vector;
 using std::string;
@@ -52,14 +53,36 @@
     Header* header = new Header;
     Schema& schema = header->getSchema();
 
-    header->setNumPoints(numPoints);
-    header->setBounds(bounds);
-
     schema.addDimension(Dimension(Dimension::Field_X, Dimension::Float));
     schema.addDimension(Dimension(Dimension::Field_Y, Dimension::Float));
     schema.addDimension(Dimension(Dimension::Field_Z, Dimension::Float));
     schema.addDimension(Dimension(Dimension::Field_GpsTime, Dimension::Uint64));
 
+    header->setNumPoints(numPoints);
+    header->setBounds(bounds);
+
+    setHeader(header);
+
+    return;
+}
+
+FauxReader::FauxReader(const Bounds<double>& bounds, int numPoints, Mode mode, const std::vector<Dimension>& dimensions)
+    : Reader()
+    , m_mode(mode)
+{
+    Header* header = new Header;
+
+    Schema& schema = header->getSchema();
+    if (dimensions.size() == 0)
+    {
+        throw; // BUG
+    }
+    schema.addDimensions(dimensions);
+    throw not_yet_implemented("need to add ability to read from arbitrary fields");
+
+    header->setNumPoints(numPoints);
+    header->setBounds(bounds);
+
     setHeader(header);
 
     return;
diff -r 531aa8c0544d -r a4f68c513443 src/Schema.cpp
--- a/src/Schema.cpp	Mon Feb 28 14:22:15 2011 -0800
+++ b/src/Schema.cpp	Mon Feb 28 15:31:29 2011 -0800
@@ -124,10 +124,20 @@
 }
 
 
+void Schema::addDimensions(const std::vector<Dimension>& dims)
+{
+    for (DimensionsCIter iter = dims.begin(); iter != dims.end(); ++iter)
+    {
+        const Dimension& dim = *iter;
+        addDimension(dim);
+    }
+
+    return;
+}
+
+
 void Schema::addDimension(Dimension const& dim)
 {
-    // BUG: assert not already added
-
     std::size_t index = m_dimensions.size();
 
     m_dimensions.push_back(dim);
diff -r 531aa8c0544d -r a4f68c513443 test/unit/FauxReaderTest.cpp
--- a/test/unit/FauxReaderTest.cpp	Mon Feb 28 14:22:15 2011 -0800
+++ b/test/unit/FauxReaderTest.cpp	Mon Feb 28 15:31:29 2011 -0800
@@ -112,4 +112,25 @@
     return;
 }
 
+
+BOOST_AUTO_TEST_CASE(test_custom_fields)
+{
+    Bounds<double> bounds(1.0, 2.0, 3.0, 101.0, 102.0, 103.0);
+
+    Dimension dimY(Dimension::Field_Y, Dimension::Uint8);
+    Dimension dimX(Dimension::Field_X, Dimension::Uint8);
+    std::vector<Dimension> dims;
+    dims.push_back(dimY);
+    dims.push_back(dimX);
+
+    FauxReader reader(bounds, 1000, FauxReader::Random, dims);
+
+    const Schema& schema = reader.getHeader().getSchema();
+    BOOST_CHECK(schema.getDimensions().size() == 2);
+    BOOST_CHECK(schema.getDimension(0).getField() == Dimension::Field_Y);
+    BOOST_CHECK(schema.getDimension(1).getField() == Dimension::Field_X);
+
+    return;
+}
+
 BOOST_AUTO_TEST_SUITE_END()


More information about the Liblas-commits mailing list