[Liblas-commits] hg-main-tree: added pcpipeline application

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Jul 29 14:03:19 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/e3e4bfdceaf1
changeset: 963:e3e4bfdceaf1
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Jul 29 11:03:13 2011 -0700
description:
added pcpipeline application

diffstat:

 apps/Application.cpp             |   16 +++-
 apps/Application.hpp             |    6 +-
 apps/CMakeLists.txt              |    7 +-
 apps/pcpipeline.cpp              |  128 +++++++++++++++++++++++++++++++++++++++
 include/pdal/PipelineManager.hpp |    4 +
 include/pdal/PipelineReader.hpp  |    5 +-
 mpg-config.bat                   |    2 +-
 src/PipelineManager.cpp          |    7 ++
 src/PipelineReader.cpp           |   23 +++++-
 9 files changed, 184 insertions(+), 14 deletions(-)

diffs (truncated from 356 to 300 lines):

diff -r a7b9128d7b29 -r e3e4bfdceaf1 apps/Application.cpp
--- a/apps/Application.cpp	Fri Jul 29 09:50:54 2011 -0700
+++ b/apps/Application.cpp	Fri Jul 29 11:03:13 2011 -0700
@@ -45,7 +45,8 @@
 
 
 Application::Application(int argc, char* argv[], const std::string& appName)
-    : m_isVerbose(false)
+    : m_isDebug(false)
+    , m_verboseLevel(0)
     , m_argc(argc)
     , m_argv(argv)
     , m_appName(appName)
@@ -136,9 +137,15 @@
 }
 
 
-bool Application::isVerbose() const
+bool Application::isDebug() const
 {
-    return m_isVerbose;
+    return m_isDebug;
+}
+
+
+boost::uint8_t Application::getVerboseLevel() const
+{
+    return m_verboseLevel;
 }
 
 
@@ -192,7 +199,8 @@
 
     basic_options->add_options()
         ("help,h", "produce help message")
-        ("verbose,v", po::value<bool>(&m_isVerbose)->zero_tokens(), "Verbose message output")
+        ("debug,d", po::value<bool>(&m_isDebug)->zero_tokens(), "Enable debug mode")
+        ("verbose,v", po::value<boost::uint8_t>(&m_verboseLevel)->default_value(0), "Set verbose message level (default is 0)")
         ("version", "Show version info")
         ("timer", "Show execution time")
         ;
diff -r a7b9128d7b29 -r e3e4bfdceaf1 apps/Application.hpp
--- a/apps/Application.hpp	Fri Jul 29 09:50:54 2011 -0700
+++ b/apps/Application.hpp	Fri Jul 29 11:03:13 2011 -0700
@@ -76,7 +76,8 @@
     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 isVerbose() const;
+    bool isDebug() const;
+    boost::uint8_t getVerboseLevel() const;
     bool hasOption(const std::string& name);
     void usageError(const std::string&);
     void runtimeError(const std::string&);
@@ -87,7 +88,8 @@
     void outputVersion();
     void addBasicOptionSet();
 
-    bool m_isVerbose;
+    bool m_isDebug;
+    boost::uint8_t m_verboseLevel;
     const int m_argc;
     char** m_argv;
     const std::string m_appName;
diff -r a7b9128d7b29 -r e3e4bfdceaf1 apps/CMakeLists.txt
--- a/apps/CMakeLists.txt	Fri Jul 29 09:50:54 2011 -0700
+++ b/apps/CMakeLists.txt	Fri Jul 29 11:03:13 2011 -0700
@@ -23,10 +23,11 @@
 
 set(PC2PC pc2pc)
 set(PCINFO pcinfo)
+set(PCPIPELINE pcpipeline)
 
 
 set(PDAL_UTILITIES
-    ${PCINFO} ${PC2PC} ${PCVIEW})
+    ${PCPIPELINE} ${PCINFO} ${PC2PC} ${PCVIEW})
 
 
 #------------------------------------------------------------------------------
@@ -60,6 +61,10 @@
     target_link_libraries(${PC2PC} ${APPS_CPP_DEPENDENCIES} )
 endif()
 
+if(PCPIPELINE)
+    add_executable(${PCPIPELINE} pcpipeline.cpp Application.cpp Application.hpp)
+    target_link_libraries(${PCPIPELINE} ${APPS_CPP_DEPENDENCIES} )
+endif()
 
 #------------------------------------------------------------------------------
 # Targets installation
diff -r a7b9128d7b29 -r e3e4bfdceaf1 apps/pcpipeline.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/pcpipeline.cpp	Fri Jul 29 11:03:13 2011 -0700
@@ -0,0 +1,128 @@
+/******************************************************************************
+* 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/PipelineReader.hpp>
+#include <pdal/PipelineManager.hpp>
+
+#include "Application.hpp"
+
+using namespace pdal;
+namespace po = boost::program_options;
+
+
+class Application_pcpipeline : public Application
+{
+public:
+    Application_pcpipeline(int argc, char* argv[]);
+    int execute();
+
+private:
+    void addOptions();
+    bool validateOptions();
+
+    std::string m_inputFile;
+};
+
+
+Application_pcpipeline::Application_pcpipeline(int argc, char* argv[])
+    : Application(argc, argv, "pcpipeline")
+    , m_inputFile("")
+{
+    return;
+}
+
+
+bool Application_pcpipeline::validateOptions()
+{
+    if (!hasOption("input"))
+    {
+        usageError("--input/-i required");
+        return false;
+    }
+
+    return true;
+}
+
+
+void Application_pcpipeline::addOptions()
+{
+    po::options_description* file_options = new po::options_description("file options");
+
+    file_options->add_options()
+        ("input,i", po::value<std::string>(&m_inputFile), "input file name (required)")
+        ;
+
+    addOptionSet(file_options);
+}
+
+
+int Application_pcpipeline::execute()
+{
+    if (!Utils::fileExists(m_inputFile))
+    {
+        runtimeError("file not found: " + m_inputFile);
+        return 1;
+    }
+
+    try
+    {
+        pdal::PipelineManager manager;
+
+        pdal::PipelineReader reader(manager, isDebug(), getVerboseLevel());
+        reader.readWriterPipeline(m_inputFile);
+
+        const boost::uint64_t np = manager.execute();
+
+        std::cout << "Wrote " << np << " points.\n";
+    }
+    catch (pdal::pdal_error ex)
+    {
+        std::cout << "Caught exception: " << ex.what() << "\n";
+        return 1;
+    }
+
+    return 0;
+}
+
+
+int main(int argc, char* argv[])
+{
+    Application_pcpipeline app(argc, argv);
+    return app.run();
+}
+
+
+
diff -r a7b9128d7b29 -r e3e4bfdceaf1 include/pdal/PipelineManager.hpp
--- a/include/pdal/PipelineManager.hpp	Fri Jul 29 09:50:54 2011 -0700
+++ b/include/pdal/PipelineManager.hpp	Fri Jul 29 11:03:13 2011 -0700
@@ -72,6 +72,10 @@
     // return the pipeline reader endpoint (or NULL, if not a reader pipeline)
     const Stage* getStage() const;
 
+    // for writer pipelines, this convenience function calls getWriter()->write() so that
+    // the user doesn't even need to know anything about the Writer class
+    boost::uint64_t execute();
+
 private:
     StageFactory m_factory;
 
diff -r a7b9128d7b29 -r e3e4bfdceaf1 include/pdal/PipelineReader.hpp
--- a/include/pdal/PipelineReader.hpp	Fri Jul 29 09:50:54 2011 -0700
+++ b/include/pdal/PipelineReader.hpp	Fri Jul 29 11:03:13 2011 -0700
@@ -54,7 +54,7 @@
     class StageParserContext;
 
 public:
-    PipelineReader(PipelineManager&);
+    PipelineReader(PipelineManager&, bool debug=false, boost::uint8_t verbose=0);
     ~PipelineReader();
 
    
@@ -82,6 +82,9 @@
 
 private:
     PipelineManager& m_manager;
+    bool m_isDebug;
+    boost::uint8_t m_verboseLevel;
+    Options m_baseOptions;
 
     PipelineReader& operator=(const PipelineReader&); // not implemented
     PipelineReader(const PipelineReader&); // not implemented
diff -r a7b9128d7b29 -r e3e4bfdceaf1 mpg-config.bat
--- a/mpg-config.bat	Fri Jul 29 09:50:54 2011 -0700
+++ b/mpg-config.bat	Fri Jul 29 11:03:13 2011 -0700
@@ -7,7 +7,7 @@
 set BUILD_TYPE=Debug
 
 set UTILS_DIR=c:\Utils
-set DEV_DIR=c:\dev
+set DEV_DIR=d:\dev
 set OSGEO4W_DIR=C:\OSGeo4W
 
 rem *** These packages are needed from OSGeo4W
diff -r a7b9128d7b29 -r e3e4bfdceaf1 src/PipelineManager.cpp
--- a/src/PipelineManager.cpp	Fri Jul 29 09:50:54 2011 -0700
+++ b/src/PipelineManager.cpp	Fri Jul 29 11:03:13 2011 -0700
@@ -143,4 +143,11 @@
     return m_lastStage;
 }
 
+
+boost::uint64_t PipelineManager::execute()
+{
+    return getWriter()->write(0);
+}
+
+
 } // namespace pdal
diff -r a7b9128d7b29 -r e3e4bfdceaf1 src/PipelineReader.cpp
--- a/src/PipelineReader.cpp	Fri Jul 29 09:50:54 2011 -0700
+++ b/src/PipelineReader.cpp	Fri Jul 29 11:03:13 2011 -0700
@@ -39,6 +39,7 @@
 #include <pdal/MultiFilter.hpp>
 #include <pdal/Reader.hpp>
 #include <pdal/Writer.hpp>
+#include <pdal/Options.hpp>
 
 #include <pdal/drivers/las/Reader.hpp>
 #include <pdal/drivers/las/Writer.hpp>
@@ -119,9 +120,21 @@
 // ------------------------------------------------------------------------
 


More information about the Liblas-commits mailing list