[Liblas-commits] hg-main-tree: added support class for the apps

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Aug 15 17:02:56 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/74f565d6ec8f
changeset: 1099:74f565d6ec8f
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Mon Aug 15 12:34:52 2011 -0700
description:
added support class for the apps
Subject: hg-main-tree: lint

details:   http://hg.libpc.orghg-main-tree/rev/88a33994dd73
changeset: 1100:88a33994dd73
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Mon Aug 15 12:57:12 2011 -0700
description:
lint
Subject: hg-main-tree: turn compare_no_case into a safer function

details:   http://hg.libpc.orghg-main-tree/rev/32eec148a72e
changeset: 1101:32eec148a72e
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Mon Aug 15 13:07:02 2011 -0700
description:
turn compare_no_case into a safer function
Subject: hg-main-tree: added copy ctor

details:   http://hg.libpc.orghg-main-tree/rev/18de837c4805
changeset: 1102:18de837c4805
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Mon Aug 15 13:22:06 2011 -0700
description:
added copy ctor
Subject: hg-main-tree: handle unknown options

details:   http://hg.libpc.orghg-main-tree/rev/6401f2b79b79
changeset: 1103:6401f2b79b79
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Mon Aug 15 13:50:31 2011 -0700
description:
handle unknown options
Subject: hg-main-tree: start of for-real pcinfo app

details:   http://hg.libpc.orghg-main-tree/rev/0dec1d001f3a
changeset: 1104:0dec1d001f3a
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Mon Aug 15 14:02:39 2011 -0700
description:
start of for-real pcinfo app

diffstat:

 apps/AppSupport.cpp          |   92 ++++++++++++++++++++++++++++++++
 apps/AppSupport.hpp          |   67 +++++++++++++++++++++++
 apps/Application.cpp         |   14 +++-
 apps/CMakeLists.txt          |    7 +-
 apps/pc2pc.cpp               |    2 +
 apps/pcinfo.cpp              |  123 ++++++++++++++++++++++--------------------
 apps/pcpipeline.cpp          |    2 +
 include/pdal/Options.hpp     |    3 +
 include/pdal/Utils.hpp       |   13 +---
 src/Options.cpp              |   11 +++-
 src/Utils.cpp                |   32 +++++++++++
 src/XMLSchema.cpp            |  118 ++++++++++++++++++++--------------------
 src/drivers/faux/Reader.cpp  |    6 +-
 src/drivers/las/ZipPoint.cpp |    2 +-
 src/drivers/oci/Iterator.cpp |   21 +++---
 src/drivers/oci/Reader.cpp   |   26 ++++----
 src/drivers/oci/Writer.cpp   |    6 +-
 test/unit/OptionsTest.cpp    |   18 ++++++
 18 files changed, 399 insertions(+), 164 deletions(-)

diffs (truncated from 1037 to 300 lines):

diff -r 4c606c33b9c6 -r 0dec1d001f3a apps/AppSupport.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/AppSupport.cpp	Mon Aug 15 14:02:39 2011 -0700
@@ -0,0 +1,92 @@
+/******************************************************************************
+* 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 "AppSupport.hpp"
+
+#include <boost/filesystem.hpp>
+#include <pdal/Utils.hpp>
+#include <pdal/PipelineManager.hpp>
+#include <pdal/PipelineReader.hpp>
+#include <pdal/drivers/las/Reader.hpp>
+#ifdef PDAL_HAVE_LIBLAS
+#include <pdal/drivers/liblas/Reader.hpp>
+#endif
+
+AppSupport::FileType AppSupport::inferFileType(const std::string& filename)
+{
+    const std::string ext = boost::filesystem::extension(filename);
+
+    if (pdal::Utils::compare_no_case(ext, ".las")==0) return LAS;
+    if (pdal::Utils::compare_no_case(ext, ".laz")==0) return LAZ;
+    if (pdal::Utils::compare_no_case(ext, ".xml")==0) return XML;
+
+    return UNKNOWN;
+}
+
+
+pdal::Stage* AppSupport::createReader(FileType type, const std::string& filename, const pdal::Options& extraOptions)
+{
+    pdal::Stage* reader = NULL;
+
+    pdal::Options opts(extraOptions);
+    opts.add<std::string>("filename", filename);
+
+    switch (type)
+    {
+    case LAS:
+    case LAZ:
+        reader = new pdal::drivers::las::LasReader(opts);
+        reader->initialize();
+        break;
+#ifdef PDAL_HAVE_LIBLAS
+    case LIBLAS_LAS:
+    case LIBLAS_LAZ:
+        reader = new pdal::drivers::liblas::LiblasReader(opts);
+        reader->initialize();
+        break;
+#endif
+    case XML:
+        {
+            pdal::PipelineManager* pipeManager(new pdal::PipelineManager); // BUG: memleak
+            pdal::PipelineReader pipeReader(*pipeManager);
+            pipeReader.readReaderPipeline(filename);
+            reader = pipeManager->getStage();
+        }
+        break;
+    default:
+        return NULL;
+    }
+
+    return reader;
+}
diff -r 4c606c33b9c6 -r 0dec1d001f3a apps/AppSupport.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/AppSupport.hpp	Mon Aug 15 14:02:39 2011 -0700
@@ -0,0 +1,67 @@
+/******************************************************************************
+* 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.
+****************************************************************************/
+
+#ifndef INCLUDED_APPSUPPORT_HPP
+#define INCLUDED_APPSUPPORT_HPP
+
+#include <string>
+
+#include <pdal/Options.hpp>
+#include <pdal/Stage.hpp>
+
+// this is a static class with some helper functions the cmd line apps need
+class AppSupport
+{
+public:
+    enum FileType
+    {
+        LAS,
+        LAZ,
+        LIBLAS_LAS,
+        LIBLAS_LAZ,
+        XML,
+        UNKNOWN
+    };
+
+    static FileType inferFileType(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 :-(
+    static pdal::Stage* createReader(FileType type, const std::string& filename, const pdal::Options& options);
+
+    AppSupport& operator=(const AppSupport&); // not implemented
+    AppSupport(const AppSupport&); // not implemented
+};
+
+#endif
diff -r 4c606c33b9c6 -r 0dec1d001f3a apps/Application.cpp
--- a/apps/Application.cpp	Mon Aug 15 12:21:54 2011 -0700
+++ b/apps/Application.cpp	Mon Aug 15 14:02:39 2011 -0700
@@ -226,9 +226,17 @@
         options.add(*sub_options);
     }
 
-    po::store(po::command_line_parser(m_argc, m_argv).
-        options(options).positional(m_positionalOptions).run(), 
-        m_variablesMap);
+    try
+    {
+        po::store(po::command_line_parser(m_argc, m_argv).
+            options(options).positional(m_positionalOptions).run(), 
+            m_variablesMap);
+    }
+    catch (boost::program_options::unknown_option e)
+    {
+        usageError("unknown option: " + e.get_option_name());
+        exit(1);
+    }
 
     po::notify(m_variablesMap);
 
diff -r 4c606c33b9c6 -r 0dec1d001f3a apps/CMakeLists.txt
--- a/apps/CMakeLists.txt	Mon Aug 15 12:21:54 2011 -0700
+++ b/apps/CMakeLists.txt	Mon Aug 15 14:02:39 2011 -0700
@@ -25,6 +25,7 @@
 set(PCINFO pcinfo)
 set(PCPIPELINE pcpipeline)
 
+set(COMMON_APP_SOURCES Application.cpp Application.hpp AppSupport.cpp AppSupport.hpp)
 
 set(PDAL_UTILITIES
     ${PCPIPELINE} ${PCINFO} ${PC2PC} ${PCVIEW})
@@ -52,17 +53,17 @@
 
 # Build pcinfo
 if(PCINFO)
-    add_executable(${PCINFO} pcinfo.cpp Application.cpp Application.hpp)
+    add_executable(${PCINFO} pcinfo.cpp ${COMMON_APP_SOURCES})
     target_link_libraries(${PCINFO} ${APPS_CPP_DEPENDENCIES} )
 endif()
 
 if(PC2PC)
-    add_executable(${PC2PC} pc2pc.cpp Application.cpp Application.hpp)
+    add_executable(${PC2PC} pc2pc.cpp ${COMMON_APP_SOURCES})
     target_link_libraries(${PC2PC} ${APPS_CPP_DEPENDENCIES} )
 endif()
 
 if(PCPIPELINE)
-    add_executable(${PCPIPELINE} pcpipeline.cpp Application.cpp Application.hpp)
+    add_executable(${PCPIPELINE} pcpipeline.cpp ${COMMON_APP_SOURCES})
     target_link_libraries(${PCPIPELINE} ${APPS_CPP_DEPENDENCIES} )
 endif()
 
diff -r 4c606c33b9c6 -r 0dec1d001f3a apps/pc2pc.cpp
--- a/apps/pc2pc.cpp	Mon Aug 15 12:21:54 2011 -0700
+++ b/apps/pc2pc.cpp	Mon Aug 15 14:02:39 2011 -0700
@@ -46,6 +46,8 @@
 
 #include <boost/property_tree/xml_parser.hpp>
 
+#include "AppSupport.hpp"
+
 #include "Application.hpp"
 
 using namespace pdal;
diff -r 4c606c33b9c6 -r 0dec1d001f3a apps/pcinfo.cpp
--- a/apps/pcinfo.cpp	Mon Aug 15 12:21:54 2011 -0700
+++ b/apps/pcinfo.cpp	Mon Aug 15 14:02:39 2011 -0700
@@ -1,33 +1,44 @@
-/***************************************************************************
- *
- * Project: libLAS -- C/C++ read/write library for LAS LIDAR data
- * Purpose: LAS information 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 <pdal/drivers/las/Reader.hpp>
-
-#ifdef PDAL_HAVE_LIBLAS
-#include <pdal/drivers/liblas/Reader.hpp>
-#endif
-
+#include <pdal/Stage.hpp>
 #include <pdal/FileUtils.hpp>
-
-#ifdef PDAL_HAVE_MRSID
-#include <pdal/drivers/mrsid/Reader.hpp>
-#endif
-
 #include <iostream>
-
+#include "AppSupport.hpp"


More information about the Liblas-commits mailing list