[Liblas-commits] hg-main-tree: added stage dumping out to pipeline
xml
liblas-commits at liblas.org
liblas-commits at liblas.org
Tue Jul 26 21:15:12 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/bfd294cde5f9
changeset: 949:bfd294cde5f9
user: Michael P. Gerlek <mpg at flaxen.com>
date: Tue Jul 26 18:15:04 2011 -0700
description:
added stage dumping out to pipeline xml
diffstat:
include/pdal/Filter.hpp | 2 +
include/pdal/MultiFilter.hpp | 2 +
include/pdal/Options.hpp | 33 +++++++++++++-----------
include/pdal/PipelineManager.hpp | 13 +++++++++-
include/pdal/Reader.hpp | 2 +
include/pdal/Stage.hpp | 2 +-
include/pdal/StageBase.hpp | 4 +++
include/pdal/Writer.hpp | 4 ++-
src/Filter.cpp | 21 +++++++++++++++
src/MultiFilter.cpp | 22 ++++++++++++++++
src/PipelineManager.cpp | 44 +++++++++++++++++++++++++++++++-
src/Reader.cpp | 16 ++++++++++++
src/Stage.cpp | 1 +
src/Writer.cpp | 23 ++++++++++++++++-
test/data/pipeline1.xml | 25 ------------------
test/data/pipeline_read.xml | 17 ++++++++++++
test/data/pipeline_write.xml | 25 ++++++++++++++++++
test/data/pipeline_write_out.xml | 2 +
test/unit/OptionsTest.cpp | 4 +-
test/unit/PipelineManagerTest.cpp | 52 ++++++++++++++++++++++++++++++++++++---
20 files changed, 262 insertions(+), 52 deletions(-)
diffs (truncated from 571 to 300 lines):
diff -r 858fefc45f55 -r bfd294cde5f9 include/pdal/Filter.hpp
--- a/include/pdal/Filter.hpp Tue Jul 26 15:46:44 2011 -0700
+++ b/include/pdal/Filter.hpp Tue Jul 26 18:15:04 2011 -0700
@@ -49,6 +49,8 @@
const Stage& getPrevStage() const;
+ virtual boost::property_tree::ptree generatePTree() const;
+
protected:
const Stage& m_prevStage;
diff -r 858fefc45f55 -r bfd294cde5f9 include/pdal/MultiFilter.hpp
--- a/include/pdal/MultiFilter.hpp Tue Jul 26 15:46:44 2011 -0700
+++ b/include/pdal/MultiFilter.hpp Tue Jul 26 18:15:04 2011 -0700
@@ -51,6 +51,8 @@
const std::vector<const Stage*>& getPrevStages() const;
+ virtual boost::property_tree::ptree generatePTree() const;
+
protected:
std::vector<const Stage*> m_prevStages;
diff -r 858fefc45f55 -r bfd294cde5f9 include/pdal/Options.hpp
--- a/include/pdal/Options.hpp Tue Jul 26 15:46:44 2011 -0700
+++ b/include/pdal/Options.hpp Tue Jul 26 18:15:04 2011 -0700
@@ -68,8 +68,8 @@
// Dumped as XML, it looks like this:
// <?xml...>
// <Name>myname</Name>
+// <Value>17</Value>
// <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>
@@ -79,8 +79,8 @@
// construct it manually
Option(std::string const& name, T value, std::string const& description="")
: m_name(name)
+ , m_value(value)
, m_description(description)
- , m_value(value)
{}
// construct it from an xml stream
@@ -103,16 +103,19 @@
// getters
std::string const& getName() const { return m_name; }
+ T const& getValue() const { return m_value; }
std::string const& getDescription() const { return m_description; }
- T const& getValue() const { return m_value; }
// 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());
+ if (getDescription() != "")
+ {
+ t.put("Description", getDescription());
+ }
return t;
}
@@ -126,8 +129,8 @@
private:
std::string m_name;
- std::string m_description;
T m_value;
+ std::string m_description; // optional field
};
@@ -137,16 +140,16 @@
//
// Dumped as XML, an Options object with two Option objects looks like this:
// <?xml...>
-// <option>
-// <name>myname</name>
-// <description>my descr</description>
-// <value>17</value>
-// </option>
-// <option>
-// <name>myname2</name>
-// <description>my descr2</description>
-// <value>13</value>
-// </option>
+// <Option>
+// <Name>myname</name>
+// <Value>17</value>
+// <Description>my descr</description>
+// </Option>
+// <Option>
+// <Name>myname2</name>
+// <Value>13</value>
+// <Description>my descr2</description>
+// </Option>
// although of course that's not valid XML, since it has no single root element.
class PDAL_DLL Options
{
diff -r 858fefc45f55 -r bfd294cde5f9 include/pdal/PipelineManager.hpp
--- a/include/pdal/PipelineManager.hpp Tue Jul 26 15:46:44 2011 -0700
+++ b/include/pdal/PipelineManager.hpp Tue Jul 26 18:15:04 2011 -0700
@@ -57,12 +57,23 @@
PipelineManager();
~PipelineManager();
+ // Use these to manually add stages into the pipeline manager.
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&);
- Writer* readWriterPipeline(const std::string&);
+ // Use this to fill in a pipeline manager with an XML file that
+ // contains a <Writer> as the last pipeline stage.
+ Writer& readWriterPipeline(const std::string&);
+
+ // Use this to fill in a pipeline manager with an XML file that
+ // don't contain a <Writer>. (Even though this is called "parse
+ // READER pipeline", it actually returns a Stage; it can be used
+ // where the last pipeline stage is a Reader or Filter.)
+ const Stage& readReaderPipeline(const std::string&);
+
+ void writeWriterPipeline(const std::string& filename) const;
private:
void parsePipeline(const boost::property_tree::ptree&, Writer*& writer, Stage*& stage);
diff -r 858fefc45f55 -r bfd294cde5f9 include/pdal/Reader.hpp
--- a/include/pdal/Reader.hpp Tue Jul 26 15:46:44 2011 -0700
+++ b/include/pdal/Reader.hpp Tue Jul 26 18:15:04 2011 -0700
@@ -51,6 +51,8 @@
public:
Reader(const Options& options);
virtual ~Reader();
+
+ virtual boost::property_tree::ptree generatePTree() const;
};
} // namespace pdal
diff -r 858fefc45f55 -r bfd294cde5f9 include/pdal/Stage.hpp
--- a/include/pdal/Stage.hpp Tue Jul 26 15:46:44 2011 -0700
+++ b/include/pdal/Stage.hpp Tue Jul 26 18:15:04 2011 -0700
@@ -75,7 +75,7 @@
virtual StageBlockIterator* createBlockIterator() const { return NULL; }
void dump() const;
-
+
protected:
// setters for the core properties
Schema& getSchemaRef();
diff -r 858fefc45f55 -r bfd294cde5f9 include/pdal/StageBase.hpp
--- a/include/pdal/StageBase.hpp Tue Jul 26 15:46:44 2011 -0700
+++ b/include/pdal/StageBase.hpp Tue Jul 26 18:15:04 2011 -0700
@@ -53,6 +53,10 @@
const Options& getOptions() const;
+ // This is used to generate pipeline xml files. It will
+ // recursively visit all child stages to populate the tree.
+ virtual boost::property_tree::ptree generatePTree() const = 0;
+
// For Name, Description, and DefaultOptions:
// each concrete class should provide a static function s_getX() which returns a static object
// each concrete class should provide a virtual getX() which returns s_getX()
diff -r 858fefc45f55 -r bfd294cde5f9 include/pdal/Writer.hpp
--- a/include/pdal/Writer.hpp Tue Jul 26 15:46:44 2011 -0700
+++ b/include/pdal/Writer.hpp Tue Jul 26 18:15:04 2011 -0700
@@ -63,6 +63,8 @@
// If given number of points is 0, do as many points as the reader supplies to us.
boost::uint64_t write(boost::uint64_t targetNumPointsToWrite=0);
+ virtual boost::property_tree::ptree generatePTree() const;
+
protected:
// this is called once before the loop with the writeBuffer calls
virtual void writeBegin() = 0;
@@ -73,7 +75,7 @@
// called once, after the writeBuffer calls
virtual void writeEnd() = 0;
- const Stage& getPrevStage();
+ const Stage& getPrevStage() const;
// these two are valid for use after writeBegin has been called
boost::uint64_t m_actualNumPointsWritten;
diff -r 858fefc45f55 -r bfd294cde5f9 src/Filter.cpp
--- a/src/Filter.cpp Tue Jul 26 15:46:44 2011 -0700
+++ b/src/Filter.cpp Tue Jul 26 18:15:04 2011 -0700
@@ -56,4 +56,25 @@
}
+boost::property_tree::ptree Filter::generatePTree() const
+{
+ boost::property_tree::ptree tree;
+
+ tree.add("Type", getName());
+
+ boost::property_tree::ptree optiontree = getOptions().getPTree();
+ tree.add_child(optiontree.begin()->first, optiontree.begin()->second);
+
+ const Stage& stage = getPrevStage();
+ boost::property_tree::ptree subtree = stage.generatePTree();
+
+ tree.add_child(subtree.begin()->first, subtree.begin()->second);
+
+ boost::property_tree::ptree root;
+ root.add_child("Filter", tree);
+
+ return root;
+}
+
+
} // namespace pdal
diff -r 858fefc45f55 -r bfd294cde5f9 src/MultiFilter.cpp
--- a/src/MultiFilter.cpp Tue Jul 26 15:46:44 2011 -0700
+++ b/src/MultiFilter.cpp Tue Jul 26 18:15:04 2011 -0700
@@ -96,5 +96,27 @@
}
+boost::property_tree::ptree MultiFilter::generatePTree() const
+{
+ boost::property_tree::ptree tree;
+
+ tree.add("Type", getName());
+
+ boost::property_tree::ptree optiontree = getOptions().getPTree();
+ tree.add_child(optiontree.begin()->first, optiontree.begin()->second);
+
+ BOOST_FOREACH(const Stage* stage, getPrevStages())
+ {
+ boost::property_tree::ptree subtree = stage->generatePTree();
+
+ tree.add_child(subtree.begin()->first, subtree.begin()->second);
+ }
+
+ boost::property_tree::ptree root;
+ root.add_child("MultiFilter", tree);
+
+ return root;
+}
+
} // namespace pdal
diff -r 858fefc45f55 -r bfd294cde5f9 src/PipelineManager.cpp
--- a/src/PipelineManager.cpp Tue Jul 26 15:46:44 2011 -0700
+++ b/src/PipelineManager.cpp Tue Jul 26 18:15:04 2011 -0700
@@ -367,7 +367,7 @@
}
-Writer* PipelineManager::readWriterPipeline(const std::string& filename)
+Writer& PipelineManager::readWriterPipeline(const std::string& filename)
{
boost::property_tree::ptree tree;
boost::property_tree::xml_parser::read_xml(filename, tree);
@@ -378,8 +378,48 @@
Stage* stage = NULL;
parsePipeline(pipeline, writer, stage);
- return writer;
+ return *writer;
}
+const Stage& PipelineManager::readReaderPipeline(const std::string& filename)
+{
+ boost::property_tree::ptree tree;
+ boost::property_tree::xml_parser::read_xml(filename, tree);
+
+ boost::property_tree::ptree pipeline = tree.get_child("Pipeline"); // err check
+
+ Writer* writer = NULL;
+ Stage* stage = NULL;
+ parsePipeline(pipeline, writer, stage);
+
+ return *stage;
+}
+
+
+static boost::property_tree::ptree generateTreeFromWriter(const Writer& writer)
+{
+ boost::property_tree::ptree subtree = writer.generatePTree();
+
+ boost::property_tree::ptree tree;
+
+ tree.add_child("Pipeline", subtree);
+
+ return tree;
+}
+
More information about the Liblas-commits
mailing list