[Liblas-commits] hg-main-tree: cleanups for oper<<, dump(), toPTree()

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Aug 17 01:04:18 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/8b6a2d6f06dd
changeset: 1121:8b6a2d6f06dd
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Aug 16 22:02:37 2011 -0700
description:
cleanups for oper<<, dump(), toPTree()
Subject: hg-main-tree: tests for toPTree()

details:   http://hg.libpc.orghg-main-tree/rev/63a402b1c172
changeset: 1122:63a402b1c172
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Aug 16 22:03:07 2011 -0700
description:
tests for toPTree()
Subject: hg-main-tree: okay to have no opts

details:   http://hg.libpc.orghg-main-tree/rev/649a5bf0b633
changeset: 1123:649a5bf0b633
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Aug 16 22:03:38 2011 -0700
description:
okay to have no opts
Subject: hg-main-tree: added --schema

details:   http://hg.libpc.orghg-main-tree/rev/b783d1c72c38
changeset: 1124:b783d1c72c38
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Aug 16 22:03:58 2011 -0700
description:
added --schema

diffstat:

 apps/Application.hpp              |    2 +-
 apps/pcinfo.cpp                   |   58 +++-
 include/pdal/Bounds.hpp           |   17 +
 include/pdal/Dimension.hpp        |   13 +-
 include/pdal/DimensionLayout.hpp  |   13 +-
 include/pdal/Options.hpp          |    4 +-
 include/pdal/Range.hpp            |   16 +
 include/pdal/Schema.hpp           |   18 +-
 include/pdal/SchemaLayout.hpp     |   13 +-
 include/pdal/SpatialReference.hpp |    3 +-
 include/pdal/StageBase.hpp        |    3 +
 include/pdal/Vector.hpp           |   20 +-
 src/Dimension.cpp                 |  437 +++++++++++++++++++------------------
 src/DimensionLayout.cpp           |   39 +-
 src/Options.cpp                   |   22 +-
 src/Schema.cpp                    |   95 ++-----
 src/SchemaLayout.cpp              |   45 +--
 src/SpatialReference.cpp          |   61 +++--
 src/StageBase.cpp                 |   25 ++-
 test/unit/BoundsTest.cpp          |   59 +++-
 test/unit/DimensionLayoutTest.cpp |   23 +-
 test/unit/DimensionTest.cpp       |   22 +-
 test/unit/PointBufferTest.cpp     |   24 ++
 test/unit/RangeTest.cpp           |   20 +
 test/unit/SchemaLayoutTest.cpp    |   26 ++
 test/unit/SchemaTest.cpp          |   26 ++
 test/unit/VectorTest.cpp          |   22 +
 27 files changed, 718 insertions(+), 408 deletions(-)

diffs (truncated from 1652 to 300 lines):

diff -r 3bee676e3465 -r b783d1c72c38 apps/Application.hpp
--- a/apps/Application.hpp	Tue Aug 16 16:37:29 2011 -0700
+++ b/apps/Application.hpp	Tue Aug 16 22:03:58 2011 -0700
@@ -82,7 +82,7 @@
 
 protected:
     // implement this, with calls to addOptionSet()
-    virtual void addOptions() = 0;
+    virtual void addOptions() {}
 
     // implement this, to do sanity checking of cmd line
     // will throw if the user gave us bad options
diff -r 3bee676e3465 -r b783d1c72c38 apps/pcinfo.cpp
--- a/apps/pcinfo.cpp	Tue Aug 16 16:37:29 2011 -0700
+++ b/apps/pcinfo.cpp	Tue Aug 16 22:03:58 2011 -0700
@@ -54,13 +54,16 @@
 {
 public:
     PcInfo(int argc, char* argv[]);
-    int execute();
+    int execute(); // overrride
 
 private:
-    void addOptions();
-    void validateOptions();
-    void readOnePoint();
-    void readAllPoints();
+    void addOptions(); // overrride
+    void validateOptions(); // overrride
+
+    void dumpOnePoint() const;
+    void dumpPointsSummary() const;
+    void dumpSchema() const;
+    void dumpStage() const;
 
     pdal::Stage* m_reader;
     std::string m_inputFile;
@@ -108,6 +111,7 @@
     processing_options->add_options()
         ("point,p", po::value<boost::uint64_t>(&m_pointNumber), "point to dump")
         ("points,a", "dump stats on all points (read entire dataset)")
+        ("schema,s", "dump the schema")
         ;
 
     addOptionSet(processing_options);
@@ -118,7 +122,7 @@
 }
 
 
-void PcInfo::readOnePoint()
+void PcInfo::dumpOnePoint() const
 {
     const pdal::Schema& schema = m_reader->getSchema();
     pdal::SchemaLayout layout(schema);
@@ -145,7 +149,7 @@
 }
 
 
-void PcInfo::readAllPoints()
+void PcInfo::dumpPointsSummary() const
 {
     const pdal::Schema& schema = m_reader->getSchema();
     pdal::SchemaLayout layout(schema);
@@ -167,6 +171,29 @@
 }
 
 
+void PcInfo::dumpSchema() const
+{
+    const pdal::Schema& schema = m_reader->getSchema();
+
+    boost::property_tree::ptree tree = schema.toPTree();
+    
+    boost::property_tree::write_json(std::cout, tree);
+    
+    return;
+}
+
+
+void PcInfo::dumpStage() const
+{
+    const boost::uint64_t numPoints = m_reader->getNumPoints();
+    const pdal::SpatialReference& srs = m_reader->getSpatialReference();
+
+    std::cout << "driver type: " << m_reader->getName() << "\n";
+    std::cout << numPoints << " points\n";
+    std::cout << "WKT: " << srs.getWKT() << "\n";
+}
+
+
 int PcInfo::execute()
 {
     if (!pdal::FileUtils::fileExists(m_inputFile))
@@ -191,27 +218,24 @@
     options.add<boost::uint8_t>("verbose", getVerboseLevel());
 
     m_reader = AppSupport::createReader(driver, m_inputFile, options);
-
-    
+        
     m_reader->initialize();
     
+    dumpStage();
+
     if (hasOption("point"))
     {
-        readOnePoint();
+        dumpOnePoint();
     }
 
     if (hasOption("points"))
     {
-        readAllPoints();
+        dumpPointsSummary();
     }
 
+    if (hasOption("schema"))
     {
-        const boost::uint64_t numPoints = m_reader->getNumPoints();
-        const pdal::SpatialReference& srs = m_reader->getSpatialReference();
-
-        std::cout << "driver type: " << m_reader->getName() << "\n";
-        std::cout << numPoints << " points\n";
-        std::cout << "WKT: " << srs.getWKT() << "\n";
+        dumpSchema();
     }
 
     return 0;
diff -r 3bee676e3465 -r b783d1c72c38 include/pdal/Bounds.hpp
--- a/include/pdal/Bounds.hpp	Tue Aug 16 16:37:29 2011 -0700
+++ b/include/pdal/Bounds.hpp	Tue Aug 16 22:03:58 2011 -0700
@@ -47,6 +47,7 @@
 #include <cassert>
 #include <vector>
 #include <sstream>
+#include <boost/property_tree/ptree.hpp>
 
 #include <pdal/Vector.hpp>
 #include <pdal/Range.hpp>
@@ -424,6 +425,22 @@
         static Bounds v(minv,minv,minv,maxv,maxv,maxv);
         return v;
     }
+
+    boost::property_tree::ptree toPTree() const
+    {
+        boost::property_tree::ptree tree;
+        for (std::size_t i = 0; i < size(); ++i)
+        {
+            const Range<T>& r = dimensions()[i];
+            tree.add_child(boost::lexical_cast<std::string>(i), r.toPTree());
+        }
+        return tree;
+    }
+
+    void dump() const
+    {
+        std::cout << *this;
+    }
 };
 
 
diff -r 3bee676e3465 -r b783d1c72c38 include/pdal/Dimension.hpp
--- a/include/pdal/Dimension.hpp	Tue Aug 16 16:37:29 2011 -0700
+++ b/include/pdal/Dimension.hpp	Tue Aug 16 22:03:58 2011 -0700
@@ -281,7 +281,18 @@
         m_endian = v;
     }
 
-    boost::property_tree::ptree GetPTree() const;
+    // returns a ptree representing the Dimension
+    //
+    // looks like this:
+    //     name: X
+    //     datatype: double
+    //     description: ...
+    //     bytesize:
+    //     ...
+    //
+    boost::property_tree::ptree toPTree() const;
+
+    void dump() const;
 
 private:
     DataType m_dataType;
diff -r 3bee676e3465 -r b783d1c72c38 include/pdal/DimensionLayout.hpp
--- a/include/pdal/DimensionLayout.hpp	Tue Aug 16 16:37:29 2011 -0700
+++ b/include/pdal/DimensionLayout.hpp	Tue Aug 16 22:03:58 2011 -0700
@@ -102,6 +102,18 @@
         return m_position > dim.m_position;
     }
 
+    // returns a ptree representing the DimensionLayout
+    //
+    // looks like this:
+    //     dimension:
+    //         [Dimension ptree]
+    //     byteoffset: 41
+    //     position: 17
+    //
+    boost::property_tree::ptree toPTree() const;
+
+    void dump() const;
+
 private:
     Dimension m_dimension;
     std::size_t m_byteOffset;
@@ -111,7 +123,6 @@
 
 PDAL_DLL std::ostream& operator<<(std::ostream& os, pdal::DimensionLayout const& d);
 
-
 } // namespace pdal
 
 #endif // PDAL_DIMENSIONLAYOUT_HPP_INCLUDED
diff -r 3bee676e3465 -r b783d1c72c38 include/pdal/Options.hpp
--- a/include/pdal/Options.hpp	Tue Aug 16 16:37:29 2011 -0700
+++ b/include/pdal/Options.hpp	Tue Aug 16 22:03:58 2011 -0700
@@ -260,6 +260,8 @@
     // BUG: this should be a member variable, not a function, but doing so causes vs2010 to fail to link
     static const Options& none();
 
+    void dump() const;
+
 private:
     // get the ptree for an option
     // throws pdal::option_not_found if the option name is not valid
@@ -269,7 +271,7 @@
 };
 
 
-PDAL_DLL std::ostream& operator<<(std::ostream& ostr, const OptionsOld&);
+PDAL_DLL std::ostream& operator<<(std::ostream& ostr, const Options&);
 
 
 } // namespace pdal
diff -r 3bee676e3465 -r b783d1c72c38 include/pdal/Range.hpp
--- a/include/pdal/Range.hpp	Tue Aug 16 16:37:29 2011 -0700
+++ b/include/pdal/Range.hpp	Tue Aug 16 22:03:58 2011 -0700
@@ -37,6 +37,9 @@
 
 #include <pdal/pdal.hpp>
 
+#include <boost/lexical_cast.hpp>
+#include <boost/property_tree/ptree.hpp>
+
 #include <pdal/Utils.hpp>
 
 namespace pdal
@@ -186,6 +189,19 @@
     {
         return m_maximum - m_minimum;
     }
+
+    boost::property_tree::ptree toPTree() const
+    {
+        boost::property_tree::ptree tree;
+        tree.add("minimum", getMinimum());
+        tree.add("maximum", getMaximum());
+        return tree;
+    }
+
+    void dump() const
+    {
+        std::cout << *this;
+    }
 };
 
 
diff -r 3bee676e3465 -r b783d1c72c38 include/pdal/Schema.hpp
--- a/include/pdal/Schema.hpp	Tue Aug 16 16:37:29 2011 -0700
+++ b/include/pdal/Schema.hpp	Tue Aug 16 22:03:58 2011 -0700
@@ -105,10 +105,19 @@
     bool hasDimension(Dimension::Field field, Dimension::DataType datatype) const;
     bool hasDimension(const Dimension& dim) const;
 
-    boost::property_tree::ptree getPTree() const;
+    // returns a ptree reprsenting the Schema
+    //
+    // looks like this:
+    //    dimension:
+    //        [Dimension ptree]
+    //    dimension:
+    //        [Dimension ptree]
+    //    ...
+    //
+    boost::property_tree::ptree toPTree() const;
+   
+    void dump() const;
 
-    void dump() const;
-    
     static Schema from_xml(std::string const& xml, std::string const& xsd);
     static Schema from_xml(std::string const& xml);
     static std::string to_xml(Schema const& schema);
@@ -123,8 +132,7 @@
 };
 
 
-PDAL_DLL std::ostream& operator<<(std::ostream& os, Schema const&);


More information about the Liblas-commits mailing list