[Liblas-commits] hg-main-tree: enable Options-based ctor
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Jul 29 14:44:37 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/dd22f40d38b3
changeset: 964:dd22f40d38b3
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Jul 29 11:31:43 2011 -0700
description:
enable Options-based ctor
Subject: hg-main-tree: enable Options-based ctors
details: http://hg.libpc.orghg-main-tree/rev/e013fe10c140
changeset: 965:e013fe10c140
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Jul 29 11:44:22 2011 -0700
description:
enable Options-based ctors
diffstat:
apps/pc2pc.cpp | 2 +-
include/pdal/StageBase.hpp | 15 ++++++++---
include/pdal/drivers/liblas/Reader.hpp | 1 +
include/pdal/drivers/liblas/Writer.hpp | 6 +++-
src/drivers/liblas/Reader.cpp | 31 ++++++++++++++++++-----
src/drivers/liblas/Writer.cpp | 34 ++++++++++++++++----------
src/filters/ColorFilter.cpp | 4 ++-
test/unit/LiblasReaderTest.cpp | 27 ++++++++++++++++++++
test/unit/LiblasWriterTest.cpp | 44 +++++++++++++++++++++++++++++++--
9 files changed, 133 insertions(+), 31 deletions(-)
diffs (truncated from 336 to 300 lines):
diff -r e3e4bfdceaf1 -r e013fe10c140 apps/pc2pc.cpp
--- a/apps/pc2pc.cpp Fri Jul 29 11:03:13 2011 -0700
+++ b/apps/pc2pc.cpp Fri Jul 29 11:44:22 2011 -0700
@@ -295,7 +295,7 @@
const boost::uint64_t numPoints = reader.getNumPoints();
- pdal::drivers::liblas::LiblasWriter writer(reader, *ofs);
+ pdal::drivers::liblas::LiblasWriter writer(reader, ofs);
//BUG: handle laz writer.setCompressed(false);
diff -r e3e4bfdceaf1 -r e013fe10c140 include/pdal/StageBase.hpp
--- a/include/pdal/StageBase.hpp Fri Jul 29 11:03:13 2011 -0700
+++ b/include/pdal/StageBase.hpp Fri Jul 29 11:44:22 2011 -0700
@@ -57,12 +57,19 @@
// recursively visit all child stages to populate the tree.
virtual boost::property_tree::ptree generatePTree() const = 0;
- // set by the "debug" option, which is a boolean
+ // This is set by the "debug" option, which is a boolean.
+ //
+ // This is intended to be used for adding debug code to stages, e.g. more than just the
+ // extra logging that "verbose" implies.
bool isDebug() const;
- // set by the "verbose" option, which is in range [0..255]
- // 0 means no verbosity at all; the meanings of other values are
- // defined by the individual stages
+ // This is set by the "verbose" option, which is in range [0..255].
+ // 0 - no verbosity at all
+ // >0 - meaning is left to the implementors of the individual stages
+ //
+ // "Verbose" is intended to only add logging/tracing/output functionality; to add or enable
+ // extra validation checks and such (code which is potentially side-effecting) you want to
+ // use the "debug" option.
bool isVerbose() const; // true iff verbosity>0
boost::uint8_t getVerboseLevel() const;
diff -r e3e4bfdceaf1 -r e013fe10c140 include/pdal/drivers/liblas/Reader.hpp
--- a/include/pdal/drivers/liblas/Reader.hpp Fri Jul 29 11:03:13 2011 -0700
+++ b/include/pdal/drivers/liblas/Reader.hpp Fri Jul 29 11:44:22 2011 -0700
@@ -86,6 +86,7 @@
pdal::StageRandomIterator* createRandomIterator() const;
private:
+ void initialize();
void processExternalHeader(::liblas::Reader& externalReader);
void registerFields(::liblas::Reader& externalReader);
MetadataRecord& getMetadataRecordRef(int index);
diff -r e3e4bfdceaf1 -r e013fe10c140 include/pdal/drivers/liblas/Writer.hpp
--- a/include/pdal/drivers/liblas/Writer.hpp Fri Jul 29 11:03:13 2011 -0700
+++ b/include/pdal/drivers/liblas/Writer.hpp Fri Jul 29 11:44:22 2011 -0700
@@ -38,6 +38,7 @@
#include <pdal/pdal.hpp>
#include <pdal/Writer.hpp>
+#include <pdal/StreamManager.hpp>
#include <pdal/drivers/las/Support.hpp>
#include <pdal/drivers/las/SummaryData.hpp>
@@ -56,7 +57,7 @@
public:
LiblasWriter(const Stage& prevStage, const Options&);
- LiblasWriter(Stage& prevStage, std::ostream&);
+ LiblasWriter(Stage& prevStage, std::ostream*);
~LiblasWriter();
void setFormatVersion(boost::uint8_t majorVersion, boost::uint8_t minorVersion);
@@ -85,9 +86,10 @@
virtual void writeEnd();
private:
+ void initialize();
void setupExternalHeader();
- std::ostream& m_ostream;
+ OStreamManager m_ostreamManager;
::liblas::Writer* m_externalWriter;
::liblas::HeaderPtr m_externalHeader;
diff -r e3e4bfdceaf1 -r e013fe10c140 src/drivers/liblas/Reader.cpp
--- a/src/drivers/liblas/Reader.cpp Fri Jul 29 11:03:13 2011 -0700
+++ b/src/drivers/liblas/Reader.cpp Fri Jul 29 11:44:22 2011 -0700
@@ -50,8 +50,19 @@
LiblasReader::LiblasReader(const Options& options)
: LasReaderBase(options)
+ , m_filename(options.getValueOrThrow<std::string>("filename"))
+ , m_versionMajor(0)
+ , m_versionMinor(0)
+ , m_scaleX(0.0)
+ , m_scaleY(0.0)
+ , m_scaleZ(0.0)
+ , m_offsetX(0.0)
+ , m_offsetY(0.0)
+ , m_offsetZ(0.0)
+ , m_isCompressed(false)
+ , m_pointFormat(::pdal::drivers::las::PointFormatUnknown)
{
- throw not_yet_implemented("options ctor");
+ initialize();
}
@@ -69,6 +80,18 @@
, m_isCompressed(false)
, m_pointFormat(::pdal::drivers::las::PointFormatUnknown)
{
+ initialize();
+}
+
+
+LiblasReader::~LiblasReader()
+{
+ return;
+}
+
+
+void LiblasReader::initialize()
+{
std::istream* str = Utils::openFile(m_filename);
{
@@ -86,12 +109,6 @@
}
-LiblasReader::~LiblasReader()
-{
- return;
-}
-
-
const Options& LiblasReader::s_getDefaultOptions()
{
static Options options;
diff -r e3e4bfdceaf1 -r e013fe10c140 src/drivers/liblas/Writer.cpp
--- a/src/drivers/liblas/Writer.cpp Fri Jul 29 11:03:13 2011 -0700
+++ b/src/drivers/liblas/Writer.cpp Fri Jul 29 11:44:22 2011 -0700
@@ -56,17 +56,31 @@
LiblasWriter::LiblasWriter(const Stage& prevStage, const Options& options)
: pdal::Writer(prevStage, options)
- , m_ostream(std::cout)
+ , m_ostreamManager(options.getValueOrThrow<std::string>("filename"))
{
- throw not_yet_implemented("options ctor");
+ initialize();
}
-LiblasWriter::LiblasWriter(Stage& prevStage, std::ostream& ostream)
+LiblasWriter::LiblasWriter(Stage& prevStage, std::ostream* ostream)
: Writer(prevStage, Options::none())
- , m_ostream(ostream)
+ , m_ostreamManager(ostream)
, m_externalWriter(NULL)
{
+ initialize();
+}
+
+
+LiblasWriter::~LiblasWriter()
+{
+ return;
+}
+
+
+void LiblasWriter::initialize()
+{
+ m_ostreamManager.open();
+
m_externalHeader = ::liblas::HeaderPtr(new ::liblas::Header);
m_externalHeader->SetCompressed(false);
@@ -76,12 +90,6 @@
}
-LiblasWriter::~LiblasWriter()
-{
- return;
-}
-
-
const Options& LiblasWriter::s_getDefaultOptions()
{
static Options options;
@@ -162,7 +170,7 @@
void LiblasWriter::writeBegin()
{
- m_externalWriter = new ::liblas::Writer(m_ostream, *m_externalHeader);
+ m_externalWriter = new ::liblas::Writer(m_ostreamManager.ostream(), *m_externalHeader);
m_summaryData.reset();
@@ -177,8 +185,8 @@
//std::cout << m_summaryData;
- m_ostream.seekp(0);
- ::pdal::drivers::las::Support::rewriteHeader(m_ostream, m_summaryData);
+ m_ostreamManager.ostream().seekp(0);
+ ::pdal::drivers::las::Support::rewriteHeader(m_ostreamManager.ostream(), m_summaryData);
return;
}
diff -r e3e4bfdceaf1 -r e013fe10c140 src/filters/ColorFilter.cpp
--- a/src/filters/ColorFilter.cpp Fri Jul 29 11:03:13 2011 -0700
+++ b/src/filters/ColorFilter.cpp Fri Jul 29 11:44:22 2011 -0700
@@ -50,7 +50,9 @@
ColorFilter::ColorFilter(const Stage& prevStage, const Options& options)
: pdal::Filter(prevStage, options)
{
- throw not_yet_implemented("options ctor");
+ checkImpedance();
+
+ return;
}
diff -r e3e4bfdceaf1 -r e013fe10c140 test/unit/LiblasReaderTest.cpp
--- a/test/unit/LiblasReaderTest.cpp Fri Jul 29 11:03:13 2011 -0700
+++ b/test/unit/LiblasReaderTest.cpp Fri Jul 29 11:44:22 2011 -0700
@@ -85,6 +85,33 @@
}
+BOOST_AUTO_TEST_CASE(test_options)
+{
+ Option<std::string> opt("filename", Support::datapath("1.2-with-color.las"));
+ Options opts(opt);
+ LiblasReader reader(opt);
+ BOOST_CHECK(reader.getDescription() == "Liblas Reader");
+
+ const Schema& schema = reader.getSchema();
+ SchemaLayout layout(schema);
+
+ PointBuffer data(layout, 3);
+
+ pdal::StageSequentialIterator* iter = reader.createSequentialIterator();
+
+ {
+ boost::uint32_t numRead = iter->read(data);
+ BOOST_CHECK(numRead == 3);
+
+ Support::check_p0_p1_p2(data, schema);
+ }
+
+ delete iter;
+
+ return;
+}
+
+
BOOST_AUTO_TEST_CASE(test_random)
{
LiblasReader reader(Support::datapath("1.2-with-color.las"));
diff -r e3e4bfdceaf1 -r e013fe10c140 test/unit/LiblasWriterTest.cpp
--- a/test/unit/LiblasWriterTest.cpp Fri Jul 29 11:03:13 2011 -0700
+++ b/test/unit/LiblasWriterTest.cpp Fri Jul 29 11:44:22 2011 -0700
@@ -62,7 +62,7 @@
const boost::uint64_t numPoints = reader.getNumPoints();
// need to scope the writer, so that's it dtor can use the stream
- LiblasWriter writer(reader, *ofs);
+ LiblasWriter writer(reader, ofs);
BOOST_CHECK(writer.getDescription() == "Liblas Writer");
writer.setCompressed(false);
@@ -87,6 +87,44 @@
return;
}
+BOOST_AUTO_TEST_CASE(test_options)
+{
+ // remove file from earlier run, if needed
+ Utils::deleteFile("temp.las");
+
+ LiblasReader reader(Support::datapath("1.2-with-color.las"));
+
+ Option<std::string> opt("filename", "temp.las");
+ Options opts(opt);
+
+ {
+ const boost::uint64_t numPoints = reader.getNumPoints();
+
+ // need to scope the writer, so that's it dtor can use the stream
+ LiblasWriter writer(reader, opts);
+ BOOST_CHECK(writer.getDescription() == "Liblas Writer");
+
+ writer.setCompressed(false);
+ writer.setDate(0, 0);
+ writer.setPointFormat(::pdal::drivers::las::PointFormat3);
+ writer.setSystemIdentifier("");
+ writer.setGeneratingSoftware("TerraScan");
+
More information about the Liblas-commits
mailing list