[Liblas-commits] hg-main-tree: add some parser helpers
liblas-commits at liblas.org
liblas-commits at liblas.org
Tue Apr 26 13:21:43 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/71a846b47171
changeset: 658:71a846b47171
user: Michael P. Gerlek <mpg at flaxen.com>
date: Tue Apr 26 10:19:21 2011 -0700
description:
add some parser helpers
Subject: hg-main-tree: start of Bounds oper>> parser
details: http://hg.libpc.orghg-main-tree/rev/9adef0eb972d
changeset: 659:9adef0eb972d
user: Michael P. Gerlek <mpg at flaxen.com>
date: Tue Apr 26 10:19:53 2011 -0700
description:
start of Bounds oper>> parser
Subject: hg-main-tree: tests for Bounds, Range parsers -- currently doesn't build
details: http://hg.libpc.orghg-main-tree/rev/6d17c3f91248
changeset: 660:6d17c3f91248
user: Michael P. Gerlek <mpg at flaxen.com>
date: Tue Apr 26 10:21:21 2011 -0700
description:
tests for Bounds, Range parsers -- currently doesn't build
Subject: hg-main-tree: merge
details: http://hg.libpc.orghg-main-tree/rev/fa451382042d
changeset: 661:fa451382042d
user: Michael P. Gerlek <mpg at flaxen.com>
date: Tue Apr 26 10:21:33 2011 -0700
description:
merge
diffstat:
apps/pc2pc.cpp | 88 +++++++++++++------------
include/libpc/Bounds.hpp | 5 +
include/libpc/Range.hpp | 7 +-
include/libpc/Utils.hpp | 7 ++
src/Bounds.cpp | 48 +++++++++++++-
src/CMakeLists.txt | 1 +
src/Range.cpp | 70 ++++++++++++++++++++
src/Utils.cpp | 20 +++++
src/drivers/las/SummaryData.cpp | 2 +-
src/drivers/oci/Writer.cpp | 136 ++++++++++++++++++++++++++++++++++++++-
src/drivers/oci/common.cpp | 2 +-
test/unit/BoundsTest.cpp | 35 ++++++++++
test/unit/RangeTest.cpp | 31 +++++++-
13 files changed, 396 insertions(+), 56 deletions(-)
diffs (truncated from 710 to 300 lines):
diff -r 5e725be08a10 -r fa451382042d apps/pc2pc.cpp
--- a/apps/pc2pc.cpp Tue Apr 26 10:20:32 2011 -0500
+++ b/apps/pc2pc.cpp Tue Apr 26 10:21:33 2011 -0700
@@ -36,6 +36,8 @@
#include <libpc/drivers/oci/Reader.hpp>
#endif
+#include <boost/property_tree/xml_parser.hpp>
+
#include "Application.hpp"
using namespace libpc;
@@ -54,8 +56,7 @@
std::string m_inputFile;
std::string m_outputFile;
- std::string m_OracleReadSQL;
- std::string m_OracleWriteSQL;
+ std::string m_xml;
};
@@ -92,8 +93,9 @@
("input,i", po::value<std::string>(&m_inputFile), "input file name")
("output,o", po::value<std::string>(&m_outputFile), "output file name")
("native", "use native LAS classes (not liblas)")
- ("oracle-writer", "write data into oracle (must edit source to make this work right now)")
- ("oracle-reader", po::value<std::string>(&m_OracleReadSQL), "SQL to select a block table")
+ ("oracle-writer", "Read data from LAS file and write to Oracle")
+ ("oracle-reader", "Read data from Oracle and write LAS file")
+ ("xml", po::value<std::string>(&m_xml)->default_value("log.xml"), "XML file to load process (OCI only right now)")
;
addOptionSet(file_options);
@@ -130,26 +132,29 @@
libpc::drivers::liblas::LiblasReader reader(m_inputFile);
const boost::uint64_t numPoints = reader.getNumPoints();
+
+ boost::property_tree::ptree load_tree;
- libpc::Options options = libpc::drivers::oci::GetDefaultOptions();
+ boost::property_tree::read_xml(m_xml, load_tree);
+
+ boost::property_tree::ptree oracle_options = load_tree.get_child("drivers.oci.writer");
+
+ libpc::Options options(oracle_options);
+
boost::property_tree::ptree& tree = options.GetPTree();
- boost::uint32_t capacity = 10000;
- tree.put("capacity", capacity);
- tree.put("overwrite", false);
- tree.put("connection", "lidar/lidar at oracle.hobu.biz/orcl");
- // tree.put("connection", "lidar/lidar at oracle.hobu.biz/crrel");
- tree.put("debug", true);
- tree.put("verbose", true);
- tree.put("scale.x", 0.0000001);
- tree.put("scale.y", 0.0000001);
- tree.put("scale.z", 0.001);
+ boost::uint32_t capacity = tree.get<boost::uint32_t>("capacity");
+
libpc::filters::CacheFilter cache(reader, 1, 1024);
libpc::filters::Chipper chipper(cache, capacity);
libpc::drivers::oci::Writer writer(chipper, options);
writer.write(numPoints);
+ boost::property_tree::ptree output_tree;
+ output_tree.put_child(writer.getName(), options.GetPTree());
+ boost::property_tree::write_xml(m_xml, output_tree);
+
#else
throw configuration_error("libPC not compiled with Oracle support");
#endif
@@ -157,39 +162,38 @@
else if (hasOption("oracle-reader"))
{
#ifdef LIBPC_HAVE_ORACLE
- libpc::Options options = libpc::drivers::oci::GetDefaultOptions();
- boost::property_tree::ptree& tree = options.GetPTree();
- tree.put("capacity", 12);
- tree.put("connection", "lidar/lidar at oracle.hobu.biz/orcl");
- // tree.put("connection", "lidar/lidar at oracle.hobu.biz/crrel");
- tree.put("debug", true);
- tree.put("verbose", true);
- tree.put("scale.x", 0.0000001);
- tree.put("scale.y", 0.0000001);
- tree.put("scale.z", 0.001);
- // tree.put("select_sql", "select * from output");
- // tree.put("select_sql", "select cloud from hobu where id = 5");
- // tree.put("select_sql", "select cloud from hobu where id = 1");
+
+ boost::property_tree::ptree load_tree;
+
+ boost::property_tree::read_xml(m_xml, load_tree);
+
+ boost::property_tree::ptree oracle_options = load_tree.get_child("drivers.oci.reader");
+
+ libpc::Options options(oracle_options);
+
+ libpc::drivers::oci::Reader reader(options);
+
+ const boost::uint64_t numPoints = reader.getNumPoints();
+
+
+
+ libpc::drivers::las::LasWriter writer(reader, *ofs);
+ // writer.setPointFormat( 3);
+ writer.write(numPoints);
+
+ boost::property_tree::ptree output_tree;
+
+ output_tree.put_child(reader.getName(), options.GetPTree());
+ // output_tree.put_child(writer.getName(), )
+ boost::property_tree::write_xml(m_xml, output_tree);
- if (m_OracleReadSQL.size() == 0) {
- throw libpc_error("Select statement to read OCI data is empty!");
- }
- tree.put("select_sql", m_OracleReadSQL);
-
- libpc::drivers::oci::Reader reader(options);
-
- const boost::uint64_t numPoints = reader.getNumPoints();
-
-
-
- libpc::drivers::las::LasWriter writer(reader, *ofs);
- // writer.setPointFormat( 3);
- writer.write(numPoints);
#else
throw configuration_error("libPC not compiled with Oracle support");
#endif
}
+
+
else
{
libpc::drivers::liblas::LiblasReader reader(m_inputFile);
diff -r 5e725be08a10 -r fa451382042d include/libpc/Bounds.hpp
--- a/include/libpc/Bounds.hpp Tue Apr 26 10:20:32 2011 -0500
+++ b/include/libpc/Bounds.hpp Tue Apr 26 10:21:33 2011 -0700
@@ -426,6 +426,7 @@
}
};
+
template<class T>
std::ostream& operator<<(std::ostream& ostr, const Bounds<T>& bounds)
{
@@ -440,6 +441,10 @@
return ostr;
}
+
+extern LIBPC_DLL std::istream& operator>>(std::istream& istr, Bounds<double>& bounds);
+
+
} // namespace libpc
// Needed for C++ DLL exports
diff -r 5e725be08a10 -r fa451382042d include/libpc/Range.hpp
--- a/include/libpc/Range.hpp Tue Apr 26 10:20:32 2011 -0500
+++ b/include/libpc/Range.hpp Tue Apr 26 10:21:33 2011 -0700
@@ -188,13 +188,18 @@
}
};
+
template<class T>
std::ostream& operator<<(std::ostream& ostr, const Range<T>& range)
{
- ostr << "[" << range.getMinimum() << " .. " << range.getMaximum() << "]";
+ ostr << "[" << range.getMinimum() << " , " << range.getMaximum() << "]";
return ostr;
}
+
+extern LIBPC_DLL std::istream& operator>>(std::istream& istr, Range<double>& range);
+
+
} // namespace libpc
#endif
diff -r 5e725be08a10 -r fa451382042d include/libpc/Utils.hpp
--- a/include/libpc/Utils.hpp Tue Apr 26 10:20:32 2011 -0500
+++ b/include/libpc/Utils.hpp Tue Apr 26 10:21:33 2011 -0700
@@ -152,6 +152,13 @@
static char* getenv(const char* env);
static int putenv(const char* env);
+ // aid to operator>> parsers
+ static void eatwhitespace(std::istream& s);
+
+ // aid to operator>> parsers
+ // if char found, eats it and returns true; otherwise, don't eat it and then return false
+ static bool eatcharacter(std::istream& s, char x);
+
private:
template<typename T>
static inline char* as_buffer(T& data)
diff -r 5e725be08a10 -r fa451382042d src/Bounds.cpp
--- a/src/Bounds.cpp Tue Apr 26 10:20:32 2011 -0500
+++ b/src/Bounds.cpp Tue Apr 26 10:21:33 2011 -0700
@@ -34,5 +34,51 @@
#include <libpc/Bounds.hpp>
+#include <libpc/Range.hpp>
+#include <libpc/Utils.hpp>
+#include <libpc/exceptions.hpp>
-// (no code here, everything is in the header)
+
+namespace libpc
+{
+
+
+std::istream& operator>>(std::istream& istr, Bounds<double>& bounds)
+{
+ Bounds<double>::RangeVector v;
+
+ char c;
+
+ Utils::eatwhitespace(istr);
+
+ if (!Utils::eatcharacter(istr,'('))
+ throw libpc_error("Bounds parser failed");
+
+ bool done = false;
+ while (!done)
+ {
+ Utils::eatwhitespace(istr);
+
+ Range<double> r;
+ istr >> r;
+
+ Utils::eatwhitespace(istr);
+
+ if ((c = (char)istr.peek()) == ',')
+ done = false;
+ else if ((c = (char)istr.peek()) == ')')
+ done = true;
+ else
+ throw libpc_error("Bounds parser failed");
+ }
+
+ if (!Utils::eatcharacter(istr,')'))
+ throw libpc_error("Bounds parser failed");
+
+ Bounds<double> xxx(v);
+ bounds = xxx;
+
+ return istr;
+}
+
+} // namespace
diff -r 5e725be08a10 -r fa451382042d src/CMakeLists.txt
--- a/src/CMakeLists.txt Tue Apr 26 10:20:32 2011 -0500
+++ b/src/CMakeLists.txt Tue Apr 26 10:21:33 2011 -0700
@@ -69,6 +69,7 @@
PointBuffer.cpp
PointBufferCache.cpp
Options.cpp
+ Range.cpp
Schema.cpp
SchemaLayout.cpp
Signaller.cpp
diff -r 5e725be08a10 -r fa451382042d src/Range.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Range.cpp Tue Apr 26 10:21:33 2011 -0700
@@ -0,0 +1,70 @@
+/******************************************************************************
+* Copyright (c) 2011, Michael P. Gerlek (mpg at flaxen.com)
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following
+* conditions are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in
+* the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
+* names of its contributors may be used to endorse or promote
+* products derived from this software without specific prior
+* written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
More information about the Liblas-commits
mailing list