[Liblas-commits] hg-main-tree: add start of ScalingFilter test

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Jul 21 12:40:27 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/19c18266eae8
changeset: 899:19c18266eae8
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Jul 21 10:24:46 2011 -0500
description:
add start of ScalingFilter test
Subject: hg-main-tree: add setFieldData method for interacting with setting raw data

details:   http://hg.libpc.orghg-main-tree/rev/d687fc4366e3
changeset: 900:d687fc4366e3
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Jul 21 10:25:05 2011 -0500
description:
add setFieldData method for interacting with setting raw data
Subject: hg-main-tree: start on raw field copying -- doesn't work yet though

details:   http://hg.libpc.orghg-main-tree/rev/85ae5cf7617a
changeset: 901:85ae5cf7617a
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Jul 21 10:25:32 2011 -0500
description:
start on raw field copying -- doesn't work yet though
Subject: hg-main-tree: merge

details:   http://hg.libpc.orghg-main-tree/rev/2099aa9028f2
changeset: 902:2099aa9028f2
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Jul 21 10:25:58 2011 -0500
description:
merge

diffstat:

 include/pdal/Options.hpp                     |  132 +++++++--
 include/pdal/PipelineManager.hpp             |   54 ++-
 include/pdal/PointBuffer.hpp                 |   20 +-
 include/pdal/StageFactory.hpp                |   16 +-
 include/pdal/drivers/terrasolid/Iterator.hpp |    4 +-
 include/pdal/exceptions.hpp                  |   10 +
 src/Options.cpp                              |   52 ++-
 src/PipelineManager.cpp                      |  337 +++++++++++++++++++++++++-
 src/StageFactory.cpp                         |   60 ++--
 src/drivers/qfit/Reader.cpp                  |    2 +-
 src/filters/ScalingFilter.cpp                |   46 +++-
 test/unit/CMakeLists.txt                     |    1 +
 test/unit/OptionsTest.cpp                    |   96 ++++++-
 test/unit/PipelineManagerTest.cpp            |   33 ++-
 test/unit/ScalingFilterTest.cpp              |  121 +++++++++
 test/unit/StageFactoryTest.cpp               |   38 +-
 16 files changed, 836 insertions(+), 186 deletions(-)

diffs (truncated from 1546 to 300 lines):

diff -r bd90f06866ef -r 2099aa9028f2 include/pdal/Options.hpp
--- a/include/pdal/Options.hpp	Wed Jul 20 13:29:32 2011 -0700
+++ b/include/pdal/Options.hpp	Thu Jul 21 10:25:58 2011 -0500
@@ -36,8 +36,10 @@
 #define INCLUDED_OPTIONS_HPP
 
 #include <pdal/pdal.hpp>
+#include <pdal/exceptions.hpp>
 #include <pdal/Bounds.hpp>
 #include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/xml_parser.hpp>
 
 
 namespace pdal
@@ -46,17 +48,16 @@
     
 class PDAL_DLL OptionsOld
 {
-
 private:
     boost::property_tree::ptree m_tree;
 
 public:
-
-    OptionsOld();
+    OptionsOld()
+    {
+        m_tree.put("is3d", false);
+    }
+    
     OptionsOld(boost::property_tree::ptree const& tree) { m_tree = tree; }
-    //template<class T> void add(Option<T> const& option) { m_tree.put_child(option.getTree()); }
-    //template<class T> Option<T> const& get(std::string const& name) { return m_tree.get<T>(name); }
-    
     boost::property_tree::ptree& GetPTree() { return m_tree; }
     boost::property_tree::ptree const& GetPTree() const { return m_tree; }
 };
@@ -66,34 +67,63 @@
 //
 // Dumped as XML, it looks like this:
 //     <?xml...>
-//     <name>my name</name>
-//     <description>my descr</description>
-//     <value>17</value>
+//     <Name>myname</Name>
+//     <Description>my descr</Description>
+//     <Value>17</Value>
 // although of course that's not valid XML, since it has no single root element.
 
 template <typename T>
 class PDAL_DLL Option
 {
 public:
-    Option(std::string const& name, T value, std::string const& description) 
+    // construct it manually
+    Option(std::string const& name, T value, std::string const& description="")
         : m_name(name)
         , m_description(description)
         , m_value(value)
     {}
     
+    // construct it from an xml stream
+    Option(std::istream& istr)
+    {
+        boost::property_tree::ptree t;
+        boost::property_tree::xml_parser::read_xml(istr, t);
+        m_name = t.get<std::string>("Name");
+        m_value = t.get<T>("Value");
+        m_description = t.get<std::string>("Description", "");
+    }
+
+    // construct it from a ptree
+    Option(const boost::property_tree::ptree t)
+    {
+        m_name = t.get<std::string>("Name");
+        m_value = t.get<T>("Value");
+        m_description = t.get<std::string>("Description", "");
+    }
+
+    // getters
     std::string const& getName() const { return m_name; }
     std::string const& getDescription() const { return m_description; }
     T const& getValue() const { return m_value; }
     
-    boost::property_tree::ptree getPTree() const 
+    // return a ptree representation
+    boost::property_tree::ptree getPTree() const
     {
         boost::property_tree::ptree t;
-        t.put("name", getName());
-        t.put("description", getDescription());
-        t.put("value", getValue());
+        t.put("Name", getName());
+        t.put("Description", getDescription());
+        t.put("Value", getValue());
         return t;
     }
     
+    // return an xml representation
+    void write_xml(std::ostream& ostr) const
+    {
+        const boost::property_tree::ptree tree = getPTree();
+        boost::property_tree::xml_parser::write_xml(ostr, tree);
+        return;
+    }
+
 private:
     std::string m_name;
     std::string m_description;
@@ -108,12 +138,12 @@
 // Dumped as XML, an Options object with two Option objects looks like this:
 //     <?xml...>
 //     <option>
-//       <name>my name</name>
+//       <name>myname</name>
 //       <description>my descr</description>
 //       <value>17</value>
 //     </option>
 //     <option>
-//       <name>my name2</name>
+//       <name>myname2</name>
 //       <description>my descr2</description>
 //       <value>13</value>
 //     </option>
@@ -121,47 +151,79 @@
 class PDAL_DLL Options
 {
 public:
-    Options();
+    // defult ctor, empy options list
+    Options() {}
+
+    Options(boost::property_tree::ptree t);
+
+    // read options from an xml stream
+    Options(std::istream& istr);
 
     // add an option
     template<class T> void add(Option<T> const& option)
     {
        boost::property_tree::ptree fields = option.getPTree();
-       m_tree.add_child("option", fields);
+       m_tree.add_child("Option", fields);
     }
 
     // add an option (shortcut version, bypass need for an Option object)
-    template<class T> void add(const std::string& name, T value, const std::string& description)
+    template<class T> void add(const std::string& name, T value, const std::string& description="")
     {
         Option<T> opt(name, value, description);
         add(opt);
     }
 
-    // get value of an option
-    template<class T> T getValue(std::string const& name) const
+    // get an option, by name
+    // throws pdal::option_not_found if the option name is not valid
+    template<typename T> Option<T> getOption(std::string const& name) const
     {
-        try 
+        boost::property_tree::ptree::const_iterator iter = m_tree.begin();
+        while (iter != m_tree.end())
         {
-            boost::property_tree::ptree optionTree = getOptionPTree(name);
-            return optionTree.get_child("value").get_value<T>();
-        } catch (boost::property_tree::ptree_bad_path const&)
-        {
-            return T();
+            if (iter->first != "Option")
+                throw pdal_error("malformed Options ptree");
+
+            const boost::property_tree::ptree& optionTree = iter->second;
+            if (optionTree.get_child("Name").get_value<std::string>() == name)
+            {
+                Option<T> option(optionTree);
+                return option;
+            }
+            ++iter;
         }
-    
-
+        throw option_not_found(name);
     }
 
-    // get description of an option
-    std::string getDescription(std::string const& name) const;
-    
-    boost::property_tree::ptree const& getPTree() const;
+    // returns true iff the option name is valid
+    template<typename T> bool hasOption(std::string const& name) const
+    {
+        bool ok = false;
+
+        try
+        {
+            Option<T> option = getOption<T>(name);
+            ok = true;
+        }
+        catch (option_not_found&)
+        {
+            ok = false;
+        }
+        // any other exception will bubble up
+
+        return ok;
+    }
+
+    // get the ptree for the whole option block
+    const boost::property_tree::ptree& getPTree() const;
    
-    // return the empty options list
+    // the empty options list
+    // BUG: this should be a member variable, not a function, but doing so causes vs2010 to fail to link
     static const Options& none();
 
 private:
-    boost::property_tree::ptree getOptionPTree(std::string const& name) const;
+    // get the ptree for an option
+    // throws pdal::option_not_found if the option name is not valid
+    const boost::property_tree::ptree getOptionPTree(const std::string& name) const;
 
     boost::property_tree::ptree m_tree;
 };
diff -r bd90f06866ef -r 2099aa9028f2 include/pdal/PipelineManager.hpp
--- a/include/pdal/PipelineManager.hpp	Wed Jul 20 13:29:32 2011 -0700
+++ b/include/pdal/PipelineManager.hpp	Thu Jul 21 10:25:58 2011 -0500
@@ -35,50 +35,56 @@
 #ifndef INCLUDED_PIPELINEMANAGER_HPP
 #define INCLUDED_PIPELINEMANAGER_HPP
 
+#include <pdal/pdal.hpp>
+#include <pdal/StageFactory.hpp>
+
+#include <boost/shared_ptr.hpp>
+
 #include <vector>
-
-#include <pdal/Stage.hpp>
-#include <pdal/Filter.hpp>
-#include <pdal/Writer.hpp>
+#include <map>
+#include <string>
 
 
 namespace pdal
 {
 
-class OptionsNew;
+class Options;
+
 
 class PDAL_DLL PipelineManager
 {
 public:
     PipelineManager();
+    ~PipelineManager();
 
-    boost::uint32_t addReader(const std::string& type, const OptionsNew&);
-    boost::uint32_t addFilter(const std::string& type, boost::uint32_t prevStage, const OptionsNew&);
-    boost::uint32_t addFilter(const std::string& type, const std::vector<boost::uint32_t>& prevStages, const OptionsNew&);
-    boost::uint32_t addWriter(const std::string& type, boost::uint32_t prevStage, const OptionsNew&);
+    Reader* addReader(const std::string& type, const Options&);
+    Filter* addFilter(const std::string& type, const Stage& prevStage, const Options&);
+    MultiFilter* addMultiFilter(const std::string& type, const std::vector<const Stage*>& prevStages, const Options&);
+    Writer* addWriter(const std::string& type, const Stage& prevStage, const Options&);
     
-    Stage* getStage(boost::uint32_t);
-    Filter* getFilter(boost::uint32_t);
-    Writer* getWriter(boost::uint32_t);
-
-    typedef Stage* readerCreatorFunction(const OptionsNew&);
-    typedef Filter* filter1CreatorFunction(boost::uint32_t prevStage, const OptionsNew&);
-    typedef Filter* filterNCreatorFunction(const std::vector<boost::uint32_t>& prevStage, const OptionsNew&);
-    typedef Writer* writerCreatorFunction(boost::uint32_t prevStage, const OptionsNew&);
-    void registerReader(const std::string& type, readerCreatorFunction);
-    void registerFilter(const std::string& type, filter1CreatorFunction);
-    void registerFilter(const std::string& type, filterNCreatorFunction);
-    void registerWriter(const std::string& type, writerCreatorFunction);
+    void readXml(const std::string&);
 
 private:
-    void registerKnownReaders();
-    void registerKnownFilters();
-    void registerKnownWriters();
+    void parsePipeline(const boost::property_tree::ptree&, Writer*& writer, Stage*& stage);
+
+    Reader* parseReader(const boost::property_tree::ptree& tree);
+    Filter* parseFilter(const boost::property_tree::ptree& tree);
+    MultiFilter* parseMultiFilter(const boost::property_tree::ptree& tree);
+    Writer* parseWriter(const boost::property_tree::ptree& tree);
+
+    Option<std::string> parseOption(const boost::property_tree::ptree& tree);
+    std::string parseType(const boost::property_tree::ptree& tree);
+
+    StageFactory m_factory;
+
+    //typedef std::vector<StagePtr> StagePtrList;
+    //StagePtrList m_stages;
 
     PipelineManager& operator=(const PipelineManager&); // not implemented


More information about the Liblas-commits mailing list