[Liblas-commits] hg-main-tree: added toPTree()

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Aug 16 19:37:45 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/ab5feaec6887
changeset: 1117:ab5feaec6887
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Aug 16 16:33:22 2011 -0700
description:
added toPTree()
Subject: hg-main-tree: dump a point

details:   http://hg.libpc.orghg-main-tree/rev/5a3b4adbe9c4
changeset: 1118:5a3b4adbe9c4
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Aug 16 16:33:56 2011 -0700
description:
dump a point
Subject: hg-main-tree: merge

details:   http://hg.libpc.orghg-main-tree/rev/81a6d2019289
changeset: 1119:81a6d2019289
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Aug 16 16:34:03 2011 -0700
description:
merge
Subject: hg-main-tree: sync test with pg's fix

details:   http://hg.libpc.orghg-main-tree/rev/3bee676e3465
changeset: 1120:3bee676e3465
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Aug 16 16:37:29 2011 -0700
description:
sync test with pg's fix

diffstat:

 apps/pcinfo.cpp              |  11 ++++-
 apps/pcpipeline.cpp          |   5 +-
 include/pdal/PointBuffer.hpp |  21 +++++++++-
 src/PointBuffer.cpp          |  85 +++++++++++++++++++++++++++++++++++++++----
 test/unit/pcpipelineTest.cpp |   2 +-
 5 files changed, 108 insertions(+), 16 deletions(-)

diffs (222 lines):

diff -r ccdbae669d00 -r 3bee676e3465 apps/pcinfo.cpp
--- a/apps/pcinfo.cpp	Tue Aug 16 13:04:42 2011 -0700
+++ b/apps/pcinfo.cpp	Tue Aug 16 16:37:29 2011 -0700
@@ -43,6 +43,8 @@
 #include <pdal/FileUtils.hpp>
 #include <pdal/PointBuffer.hpp>
 #include <pdal/filters/StatsFilter.hpp>
+#include <boost/property_tree/xml_parser.hpp>
+#include <boost/property_tree/json_parser.hpp>
 
 #include "AppSupport.hpp"
 #include "Application.hpp"
@@ -132,7 +134,12 @@
         throw app_runtime_error("problem reading point number " + m_pointNumber);
     }
 
-    std::cout << "Read point " << m_pointNumber << "\n";
+    std::cout << "Read point " << m_pointNumber << ":\n";
+
+    boost::property_tree::ptree t = data.toPTree();
+    write_json(std::cout, t.get_child("0"));
+
+    std::cout << "\n";
 
     return;
 }
@@ -148,7 +155,7 @@
     boost::uint64_t totRead = 0;
     while (!iter->atEnd())
     {
-        pdal::PointBuffer data(layout, 1024);
+        pdal::PointBuffer data(layout, iter->getChunkSize());
 
         const boost::uint32_t numRead = iter->read(data);
         totRead += numRead;
diff -r ccdbae669d00 -r 3bee676e3465 apps/pcpipeline.cpp
--- a/apps/pcpipeline.cpp	Tue Aug 16 13:04:42 2011 -0700
+++ b/apps/pcpipeline.cpp	Tue Aug 16 16:37:29 2011 -0700
@@ -72,7 +72,7 @@
 {
     if (!hasOption("input"))
     {
-        throw app_usage_error("--input/-i required");
+        throw app_usage_error("input file name required");
     }
 
     return;
@@ -84,10 +84,11 @@
     po::options_description* file_options = new po::options_description("file options");
 
     file_options->add_options()
-        ("input,i", po::value<std::string>(&m_inputFile), "input file name (required)")
+        ("input,i", po::value<std::string>(&m_inputFile), "input file name")
         ;
 
     addOptionSet(file_options);
+    addPositionalOption("input", 1);
 }
 
 
diff -r ccdbae669d00 -r 3bee676e3465 include/pdal/PointBuffer.hpp
--- a/include/pdal/PointBuffer.hpp	Tue Aug 16 13:04:42 2011 -0700
+++ b/include/pdal/PointBuffer.hpp	Tue Aug 16 16:37:29 2011 -0700
@@ -178,15 +178,32 @@
     // access to the raw memory
     void getData(boost::uint8_t** data, std::size_t* array_size) const;
 
+    // returns a ptree containing the point records, useful for dumping
+    // and such
+    //
+    // The tree will look like this:
+    //
+    //    0:
+    //        X: 1.00
+    //        Y: 2.00
+    //        Z: 3.00
+    //    1:
+    //        X: 1.00
+    //        Y: 2.00
+    //        Z: 3.00
+    //
+    // If you want to print out details about the fields, e.g. the byte 
+    // offset or the datatype, use the Schema's ptree dumper.
+    // 
+    boost::property_tree::ptree toPTree() const;
+
 private:
-
     SchemaLayout m_schemaLayout;
     boost::scoped_array<boost::uint8_t> m_data;
     std::size_t m_pointSize;
     boost::uint32_t m_numPoints;
     boost::uint32_t m_capacity;    
     Bounds<double> m_bounds;
-
 };
 
 
diff -r ccdbae669d00 -r 3bee676e3465 src/PointBuffer.cpp
--- a/src/PointBuffer.cpp	Tue Aug 16 13:04:42 2011 -0700
+++ b/src/PointBuffer.cpp	Tue Aug 16 16:37:29 2011 -0700
@@ -34,6 +34,11 @@
 
 #include <pdal/PointBuffer.hpp>
 
+#include <boost/lexical_cast.hpp>
+
+#include <pdal/exceptions.hpp>
+
+
 namespace pdal
 {
 
@@ -127,6 +132,75 @@
 }
 
 
+boost::property_tree::ptree PointBuffer::toPTree() const
+{
+    boost::property_tree::ptree tree;
+
+    const SchemaLayout& schemaLayout = getSchemaLayout();
+    const std::vector<DimensionLayout>& dimensionLayouts = schemaLayout.getDimensionLayouts();
+    const boost::uint32_t numPoints = getNumPoints();
+
+    for (boost::uint32_t pointIndex=0; pointIndex<numPoints; pointIndex++)
+    {
+        const std::string pointstring = boost::lexical_cast<std::string>(pointIndex) + ".";
+        
+        for (SchemaLayout::DimensionLayoutsCIter citer=dimensionLayouts.begin(); citer != dimensionLayouts.end(); ++citer)
+        {
+            const DimensionLayout& dimensionLayout = *citer;
+            const Dimension& dimension = dimensionLayout.getDimension();
+            const std::size_t fieldIndex = dimensionLayout.getPosition();
+
+            const std::string key = pointstring + dimension.getFieldName();
+            
+            std::string value = "";
+            
+            switch (dimension.getDataType())
+            {
+#define GETFIELDAS(type) getField<##type##>(pointIndex, fieldIndex)
+#define STRINGIFY(x) boost::lexical_cast<std::string>(x)
+                // note we convert 8-bit fields to ints, so they aren't treated as chars
+            case Dimension::Int8:
+                value += STRINGIFY((int)GETFIELDAS(boost::int8_t));
+                break;
+            case Dimension::Uint8:
+                value += STRINGIFY((int)GETFIELDAS(boost::uint8_t));
+                break;
+            case Dimension::Int16:
+                value += STRINGIFY(GETFIELDAS(boost::int16_t));
+                break;
+            case Dimension::Uint16:
+                value += STRINGIFY(GETFIELDAS(boost::uint16_t));
+                break;
+            case Dimension::Int32:
+                value += STRINGIFY(GETFIELDAS(boost::int32_t));
+                break;
+            case Dimension::Uint32:
+                value += STRINGIFY(GETFIELDAS(boost::uint32_t));
+                break;
+            case Dimension::Int64:
+                value += STRINGIFY(GETFIELDAS(boost::int64_t));
+                break;
+            case Dimension::Uint64:
+                value += STRINGIFY(GETFIELDAS(boost::uint64_t));
+                break;
+            case Dimension::Float:
+                value += STRINGIFY(GETFIELDAS(float));
+                break;
+            case Dimension::Double:
+                value += STRINGIFY(GETFIELDAS(double));
+                break;
+            
+            default:
+                throw pdal_error("unknown dimension data type");
+            }
+
+            tree.add(key, value);
+        }
+    }
+    return tree;
+}
+
+
 std::ostream& operator<<(std::ostream& ostr, const PointBuffer& PointBuffer)
 {
     using std::endl;
@@ -135,18 +209,11 @@
     const std::vector<DimensionLayout>& dimensionLayouts = schemaLayout.getDimensionLayouts();
     const std::size_t numPoints = PointBuffer.getNumPoints();
 
-    int cnt = 0;
-    for (boost::uint32_t pointIndex=0; pointIndex<numPoints; pointIndex++)
-    {
-
-        ++cnt;
-    }
-    ostr << "Contains " << cnt << "  points (" << PointBuffer.getNumPoints() << " total)" << endl;
+    ostr << "Contains " << numPoints << "  points" << endl;
 
     for (boost::uint32_t pointIndex=0; pointIndex<numPoints; pointIndex++)
     {
-
-        
+       
         ostr << "Point: " << pointIndex << endl;
 
         for (SchemaLayout::DimensionLayoutsCIter citer=dimensionLayouts.begin(); citer != dimensionLayouts.end(); ++citer)
diff -r ccdbae669d00 -r 3bee676e3465 test/unit/pcpipelineTest.cpp
--- a/test/unit/pcpipelineTest.cpp	Tue Aug 16 13:04:42 2011 -0700
+++ b/test/unit/pcpipelineTest.cpp	Tue Aug 16 16:37:29 2011 -0700
@@ -61,7 +61,7 @@
     int stat = Support::run_command(cmd, output);
     BOOST_CHECK_EQUAL(stat, 1);
 
-    const std::string expected = "Usage error: --input";
+    const std::string expected = "Usage error: input file name required";
     BOOST_CHECK_EQUAL(output.substr(0, expected.length()), expected);
 
     return;


More information about the Liblas-commits mailing list