[Liblas-commits] hg-main-tree: playing around with pipeline builder

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Jul 12 23:39:04 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/92f26eab6619
changeset: 856:92f26eab6619
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Jul 12 20:38:47 2011 -0700
description:
playing around with pipeline builder
Subject: hg-main-tree: merge

details:   http://hg.libpc.orghg-main-tree/rev/23549d6e8f19
changeset: 857:23549d6e8f19
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Jul 12 20:38:59 2011 -0700
description:
merge

diffstat:

 apps/CMakeLists.txt               |    8 +-
 apps/qfit2las.cpp                 |  116 +++++++++++++++++++++++++
 include/pdal/PipelineManager.hpp  |   54 ++++++-----
 include/pdal/Schema.hpp           |    5 +
 include/pdal/StageFactory.hpp     |   99 +++++++++++++++++++++
 src/CMakeLists.txt                |    2 +
 src/PipelineManager.cpp           |  114 +++++++++++++++++++-----
 src/Schema.cpp                    |   38 ++++++++-
 src/StageFactory.cpp              |  173 ++++++++++++++++++++++++++++++++++++++
 src/drivers/las/Header.cpp        |   18 ++-
 src/drivers/qfit/Reader.cpp       |    4 +-
 test/unit/CMakeLists.txt          |    1 +
 test/unit/PipelineManagerTest.cpp |    5 +
 test/unit/QFITReaderTest.cpp      |    5 +-
 test/unit/StageFactoryTest.cpp    |   52 +++++++++++
 15 files changed, 634 insertions(+), 60 deletions(-)

diffs (truncated from 929 to 300 lines):

diff -r 638cd2e5253c -r 23549d6e8f19 apps/CMakeLists.txt
--- a/apps/CMakeLists.txt	Mon Jul 11 13:54:36 2011 -0700
+++ b/apps/CMakeLists.txt	Tue Jul 12 20:38:59 2011 -0700
@@ -23,10 +23,11 @@
 
 set(PC2PC pc2pc)
 set(PCINFO pcinfo)
+set(QFIT2LAS qfit2las)
 
 
 set(PDAL_UTILITIES
-    ${PCINFO} ${PC2PC} ${PCVIEW})
+    ${PCINFO} ${PC2PC} ${PCVIEW} ${QFIT2LAS})
 
 
 #------------------------------------------------------------------------------
@@ -60,6 +61,11 @@
     target_link_libraries(${PC2PC} ${APPS_CPP_DEPENDENCIES} )
 endif()
 
+if(QFIT2LAS)
+    add_executable(${QFIT2LAS} qfit2las.cpp Application.cpp Application.hpp)
+    target_link_libraries(${QFIT2LAS} ${APPS_CPP_DEPENDENCIES} )
+endif()
+
 
 #------------------------------------------------------------------------------
 # Targets installation
diff -r 638cd2e5253c -r 23549d6e8f19 apps/qfit2las.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/qfit2las.cpp	Tue Jul 12 20:38:59 2011 -0700
@@ -0,0 +1,116 @@
+/***************************************************************************
+ *
+ * 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.
+ **************************************************************************/
+
+
+#include <iostream>
+
+#include <pdal/exceptions.hpp>
+#include <pdal/drivers/las/Reader.hpp>
+
+#include <pdal/drivers/las/Writer.hpp>
+#include <pdal/drivers/qfit/Reader.hpp>
+
+#include "Application.hpp"
+
+using namespace pdal;
+namespace po = boost::program_options;
+
+
+class Application_pc2pc : public Application
+{
+public:
+    Application_pc2pc(int argc, char* argv[]);
+    int execute();
+
+private:
+    void addOptions();
+    bool validateOptions();
+
+    std::string m_inputFile;
+    std::string m_outputFile;
+    
+};
+
+
+Application_pc2pc::Application_pc2pc(int argc, char* argv[])
+    : Application(argc, argv, "pc2pc")
+{
+}
+
+
+bool Application_pc2pc::validateOptions()
+{
+    if (!hasOption("input"))
+    {
+        usageError("--input/-i required");
+        return false;
+    }
+
+    if (!hasOption("output"))
+    {
+        usageError("--output/-o required");
+        return false;
+    }
+
+    return true;
+}
+
+
+void Application_pc2pc::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")
+        ("output,o", po::value<std::string>(&m_outputFile), "output file name")
+        ;
+
+    addOptionSet(file_options);
+}
+
+int Application_pc2pc::execute()
+{
+    if (!Utils::fileExists(m_inputFile))
+    {
+        runtimeError("file not found: " + m_inputFile);
+        return 1;
+    }
+
+    std::ostream* ofs = Utils::createFile(m_outputFile);
+    pdal::Options options;
+
+    pdal::Option<std::string> filename("input", m_inputFile, "Input filename for reader to use" );
+    options.add(filename);
+    pdal::drivers::qfit::Reader reader(options);
+    
+    const boost::uint64_t numPoints = reader.getNumPoints();
+
+    pdal::drivers::las::LasWriter writer(reader, *ofs);
+
+
+    // writer.setPointFormat( reader.getPointFormat() );
+
+    writer.write(numPoints);
+
+
+    Utils::closeFile(ofs);
+
+    return 0;
+}
+
+int main(int argc, char* argv[])
+{
+    Application_pc2pc app(argc, argv);
+    return app.run();
+}
+
+
+
diff -r 638cd2e5253c -r 23549d6e8f19 include/pdal/PipelineManager.hpp
--- a/include/pdal/PipelineManager.hpp	Mon Jul 11 13:54:36 2011 -0700
+++ b/include/pdal/PipelineManager.hpp	Tue Jul 12 20:38:59 2011 -0700
@@ -35,50 +35,56 @@
 #ifndef INCLUDED_PIPELINEMANAGER_HPP
 #define INCLUDED_PIPELINEMANAGER_HPP
 
+#include <pdal/pdal.hpp>
+#include <pdal/StageFactory.hpp>
+
+#include <boost/shared_ptr.hpp>
+
 #include <vector>
-
-#include <pdal/Stage.hpp>
-#include <pdal/Filter.hpp>
-#include <pdal/Writer.hpp>
+#include <map>
+#include <string>
 
 
 namespace pdal
 {
 
-class OptionsNew;
+class Stage;
+class Reader;
+class Filter;
+class MultiFilter;
+class Writer;
+class Options;
+
 
 class PDAL_DLL PipelineManager
 {
 public:
     PipelineManager();
+    ~PipelineManager();
 
-    boost::uint32_t addReader(const std::string& type, const OptionsNew&);
-    boost::uint32_t addFilter(const std::string& type, boost::uint32_t prevStage, const OptionsNew&);
-    boost::uint32_t addFilter(const std::string& type, const std::vector<boost::uint32_t>& prevStages, const OptionsNew&);
-    boost::uint32_t addWriter(const std::string& type, boost::uint32_t prevStage, const OptionsNew&);
+    boost::uint32_t addReader(const std::string& type, const Options&);
+    boost::uint32_t addFilter(const std::string& type, boost::uint32_t prevStage, const Options&);
+    boost::uint32_t addMultiFilter(const std::string& type, const std::vector<boost::uint32_t>& prevStages, const Options&);
+    boost::uint32_t addWriter(const std::string& type, boost::uint32_t prevStage, const Options&);
     
-    Stage* getStage(boost::uint32_t);
-    Filter* getFilter(boost::uint32_t);
-    Writer* getWriter(boost::uint32_t);
-
-    typedef Stage* readerCreatorFunction(const OptionsNew&);
-    typedef Filter* filter1CreatorFunction(boost::uint32_t prevStage, const OptionsNew&);
-    typedef Filter* filterNCreatorFunction(const std::vector<boost::uint32_t>& prevStage, const OptionsNew&);
-    typedef Writer* writerCreatorFunction(boost::uint32_t prevStage, const OptionsNew&);
-    void registerReader(const std::string& type, readerCreatorFunction);
-    void registerFilter(const std::string& type, filter1CreatorFunction);
-    void registerFilter(const std::string& type, filterNCreatorFunction);
-    void registerWriter(const std::string& type, writerCreatorFunction);
+    boost::shared_ptr<Reader> getReader(boost::uint32_t);
+    boost::shared_ptr<Filter> getFilter(boost::uint32_t);
+    boost::shared_ptr<MultiFilter> getMultiFilter(boost::uint32_t);
+    boost::shared_ptr<Writer> getWriter(boost::uint32_t);
 
 private:
-    void registerKnownReaders();
-    void registerKnownFilters();
-    void registerKnownWriters();
+    StageFactory m_factory;
+
+    std::vector<boost::shared_ptr<Reader>> m_readerStages;
+    std::vector<boost::shared_ptr<Filter>> m_filterStages;
+    std::vector<boost::shared_ptr<MultiFilter>> m_multifilterStages;
+    std::vector<boost::shared_ptr<Writer>> m_writerStages;
 
     PipelineManager& operator=(const PipelineManager&); // not implemented
     PipelineManager(const PipelineManager&); // not implemented
 };
 
+
 } // namespace pdal
 
 #endif
diff -r 638cd2e5253c -r 23549d6e8f19 include/pdal/Schema.hpp
--- a/include/pdal/Schema.hpp	Mon Jul 11 13:54:36 2011 -0700
+++ b/include/pdal/Schema.hpp	Tue Jul 12 20:38:59 2011 -0700
@@ -88,6 +88,10 @@
       >
 > IndexMap;
 
+// typedef IndexMap::index<name>::type index_by_name;
+// typedef IndexMap::index<position>::type index_by_position;
+typedef IndexMap::index<index>::type index_by_index;
+
 }} // pdal::schema::index
 
 /// Schema definition
@@ -137,6 +141,7 @@
 
 private:
     std::vector<Dimension> m_dimensions;
+    pdal::schema::index::IndexMap m_index;
 
     // this is a mapping from field name to index position in the
     // m_dimensions array (or -1 if field not present)
diff -r 638cd2e5253c -r 23549d6e8f19 include/pdal/StageFactory.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/pdal/StageFactory.hpp	Tue Jul 12 20:38:59 2011 -0700
@@ -0,0 +1,99 @@
+/******************************************************************************
+* 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_STAGEFACTORY_HPP
+#define INCLUDED_STAGEFACTORY_HPP
+
+#include <pdal/pdal.hpp>
+
+#include <boost/shared_ptr.hpp>
+
+#include <vector>


More information about the Liblas-commits mailing list