[Liblas-commits] hg-main-tree: work on pc2pc
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Aug 17 17:37:01 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/30d1b1369259
changeset: 1127:30d1b1369259
user: Michael P. Gerlek <mpg at flaxen.com>
date: Wed Aug 17 14:37:00 2011 -0700
description:
work on pc2pc
diffstat:
apps/AppSupport.cpp | 86 ++++++++++++++-
apps/AppSupport.hpp | 21 +++-
apps/Application.cpp | 4 +-
apps/Application.hpp | 14 +-
apps/pc2pc.cpp | 305 ++++++++++----------------------------------------
apps/pcinfo.cpp | 23 +---
6 files changed, 177 insertions(+), 276 deletions(-)
diffs (truncated from 631 to 300 lines):
diff -r fd247f84127a -r 30d1b1369259 apps/AppSupport.cpp
--- a/apps/AppSupport.cpp Wed Aug 17 14:36:27 2011 -0700
+++ b/apps/AppSupport.cpp Wed Aug 17 14:37:00 2011 -0700
@@ -37,13 +37,13 @@
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
+#include <pdal/FileUtils.hpp>
#include <pdal/Utils.hpp>
#include <pdal/PipelineManager.hpp>
#include <pdal/PipelineReader.hpp>
#include <pdal/StageFactory.hpp>
-
std::string AppSupport::inferReaderDriver(const std::string& filename)
{
std::string ext = boost::filesystem::extension(filename);
@@ -66,6 +66,25 @@
}
+std::string AppSupport::inferWriterDriver(const std::string& filename)
+{
+ std::string ext = boost::filesystem::extension(filename);
+ if (ext == "") return "";
+ ext = ext.substr(1, ext.length()-1);
+ if (ext == "") return "";
+
+ boost::to_lower(ext);
+
+ // maybe this should live in StageFactory?
+ std::map<std::string, std::string> drivers;
+ drivers["las"] = "drivers.las.writer";
+ drivers["laz"] = "drivers.las.writer";
+
+ std::string driver = drivers[ext];
+ return driver; // will be "" if not found
+}
+
+
pdal::Stage* AppSupport::createReader(const std::string& driver, const std::string& filename, const pdal::Options& extraOptions)
{
pdal::Stage* reader = NULL;
@@ -78,3 +97,68 @@
return reader;
}
+
+
+pdal::Writer* AppSupport::createWriter(const std::string& driver, const std::string& filename, pdal::Stage& stage, const pdal::Options& extraOptions)
+{
+ pdal::Writer* writer = NULL;
+
+ pdal::Options opts(extraOptions);
+ opts.add<std::string>("filename", filename);
+
+ pdal::StageFactory factory;
+ writer = factory.createWriter(driver, stage, opts);
+
+ return writer;
+}
+
+
+pdal::Stage* AppSupport::makeReader(const std::string& inputFile, const Application& app)
+{
+ if (!pdal::FileUtils::fileExists(inputFile))
+ {
+ throw app_runtime_error("file not found: " + inputFile);
+ }
+
+ std::string driver = AppSupport::inferReaderDriver(inputFile);
+ if (driver == "")
+ {
+ throw app_runtime_error("Cannot determine file type of " + inputFile);
+ }
+
+ if (app.hasOption("liblas") && driver == "drivers.las.reader")
+ {
+ driver = "drivers.liblas.reader";
+ }
+
+ pdal::Options options;
+ options.add<bool>("debug", app.isDebug());
+ options.add<boost::uint8_t>("verbose", app.getVerboseLevel());
+
+ pdal::Stage* stage = AppSupport::createReader(driver, inputFile, options);
+
+ return stage;
+}
+
+
+pdal::Writer* AppSupport::makeWriter(const std::string& outputFile, pdal::Stage& stage, const Application& app)
+{
+ std::string driver = AppSupport::inferWriterDriver(outputFile);
+ if (driver == "")
+ {
+ throw app_runtime_error("Cannot determine file type of " + outputFile);
+ }
+
+ if (app.hasOption("liblas") && driver == "drivers.las.writer")
+ {
+ driver = "drivers.liblas.writer";
+ }
+
+ pdal::Options options;
+ options.add<bool>("debug", app.isDebug());
+ options.add<boost::uint8_t>("verbose", app.getVerboseLevel());
+
+ pdal::Writer* writer = AppSupport::createWriter(driver, outputFile, stage, options);
+
+ return writer;
+}
diff -r fd247f84127a -r 30d1b1369259 apps/AppSupport.hpp
--- a/apps/AppSupport.hpp Wed Aug 17 14:36:27 2011 -0700
+++ b/apps/AppSupport.hpp Wed Aug 17 14:37:00 2011 -0700
@@ -39,19 +39,38 @@
#include <pdal/Options.hpp>
#include <pdal/Stage.hpp>
+#include <pdal/Writer.hpp>
+
+#include "Application.hpp"
+
// this is a static class with some helper functions the cmd line apps need
class AppSupport
{
public:
+ // makes a reader/stage, from just the filename and some options
+ static pdal::Stage* AppSupport::makeReader(const std::string& inputFile, const Application& app);
+
+ // makes a writer, from just the filename and some options (and the input stage)
+ static pdal::Writer* AppSupport::makeWriter(const std::string& outputFile, pdal::Stage& stage, const Application& app);
+
+private:
// infer the driver to use based on filename extension
// returns "" if no driver found
static std::string inferReaderDriver(const std::string& filename);
+ // infer the driver to use based on filename extension
+ // returns "" if no driver found
+ static std::string inferWriterDriver(const std::string& filename);
+
// creates a Reader using the given driver type
- // caller takes ownership of the returned pointer... unless it's of type XML :-(
+ // caller does NOT take ownership of the returned pointer
static pdal::Stage* createReader(const std::string& driver, const std::string& filename, const pdal::Options& options);
+ // creates a Writer using the given driver type
+ // caller does NOT take ownership of the returned pointer
+ static pdal::Writer* createWriter(const std::string& driver, const std::string& filename, pdal::Stage& stage, const pdal::Options& options);
+
AppSupport& operator=(const AppSupport&); // not implemented
AppSupport(const AppSupport&); // not implemented
};
diff -r fd247f84127a -r 30d1b1369259 apps/Application.cpp
--- a/apps/Application.cpp Wed Aug 17 14:36:27 2011 -0700
+++ b/apps/Application.cpp Wed Aug 17 14:37:00 2011 -0700
@@ -137,14 +137,14 @@
}
-void Application::printError(const std::string& err)
+void Application::printError(const std::string& err) const
{
std::cout << err << std::endl;
std::cout << std::endl;
}
-bool Application::hasOption(const std::string& name)
+bool Application::hasOption(const std::string& name) const
{
return m_variablesMap.count(name) > 0;
}
diff -r fd247f84127a -r 30d1b1369259 apps/Application.hpp
--- a/apps/Application.hpp Wed Aug 17 14:36:27 2011 -0700
+++ b/apps/Application.hpp Wed Aug 17 14:37:00 2011 -0700
@@ -80,7 +80,15 @@
// call this, to start the machine
int run();
+ bool isDebug() const;
+ boost::uint8_t getVerboseLevel() const;
+ bool hasOption(const std::string& name) const;
+ void printError(const std::string&) const;
+
protected:
+ // this is protected; your derived class ctor will be the public entry point
+ Application(int argc, char* argv[], const std::string& appName);
+
// implement this, with calls to addOptionSet()
virtual void addOptions() {}
@@ -92,14 +100,8 @@
// it will be wrapped in a global catch try/block for you
virtual int execute() = 0;
-protected:
- Application(int argc, char* argv[], const std::string& appName);
void addOptionSet(boost::program_options::options_description* options);
void addPositionalOption(const char* name, int max_count);
- bool isDebug() const;
- boost::uint8_t getVerboseLevel() const;
- bool hasOption(const std::string& name);
- void printError(const std::string&);
private:
int innerRun();
diff -r fd247f84127a -r 30d1b1369259 apps/pc2pc.cpp
--- a/apps/pc2pc.cpp Wed Aug 17 14:36:27 2011 -0700
+++ b/apps/pc2pc.cpp Wed Aug 17 14:37:00 2011 -0700
@@ -1,49 +1,59 @@
-/***************************************************************************
- *
- * Project: libLAS -- C/C++ read/write library for LAS LIDAR data
- * Purpose: LAS translation with optional configuration
- * Author: Howard Butler, hobu.inc at gmail.com
- ***************************************************************************
- * Copyright (c) 2010, Howard Butler, hobu.inc at gmail.com
- *
- * See LICENSE.txt in this source distribution for more information.
- **************************************************************************/
-
+/******************************************************************************
+* 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,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+* OF SUCH DAMAGE.
+****************************************************************************/
#include <iostream>
#include <pdal/exceptions.hpp>
#include <pdal/FileUtils.hpp>
-//#include <pdal/pdal_config.hpp>
-//#include <pdal/Bounds.hpp>
-//#include <pdal/Color.hpp>
-//#include <pdal/Dimension.hpp>
-//#include <pdal/Schema.hpp>
-#include <pdal/filters/Chipper.hpp>
-#include <pdal/filters/ReprojectionFilter.hpp>
-#include <pdal/filters/ScalingFilter.hpp>
-
-//#include <pdal/ColorFilter.hpp>
-//#include <pdal/MosaicFilter.hpp>
-//#include <pdal/FauxReader.hpp>
-//#include <pdal/FauxWriter.hpp>
#include <pdal/drivers/las/Reader.hpp>
-//#include <pdal/LasHeader.hpp>
#include <pdal/drivers/las/Writer.hpp>
-#include <pdal/filters/CacheFilter.hpp>
-#include <pdal/filters/ByteSwapFilter.hpp>
-
#ifdef PDAL_HAVE_LIBLAS
#include <pdal/drivers/liblas/Writer.hpp>
#include <pdal/drivers/liblas/Reader.hpp>
#endif
-
#ifdef PDAL_HAVE_ORACLE
#include <pdal/drivers/oci/Writer.hpp>
#include <pdal/drivers/oci/Reader.hpp>
#endif
+#include <pdal/filters/ByteSwapFilter.hpp>
+#include <pdal/filters/CacheFilter.hpp>
+#include <pdal/filters/Chipper.hpp>
+#include <pdal/filters/ReprojectionFilter.hpp>
+#include <pdal/filters/ScalingFilter.hpp>
+
#include <boost/property_tree/xml_parser.hpp>
More information about the Liblas-commits
mailing list