[Liblas-commits] hg-main-tree: cleanup; added XML driver support

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Aug 16 13:11:49 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/0b5dc4125ed9
changeset: 1109:0b5dc4125ed9
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Aug 16 10:11:20 2011 -0700
description:
cleanup; added XML driver support
Subject: hg-main-tree: now supports .xml files cleanly

details:   http://hg.libpc.orghg-main-tree/rev/97b01e5e8af2
changeset: 1110:97b01e5e8af2
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Aug 16 10:11:33 2011 -0700
description:
now supports .xml files cleanly

diffstat:

 apps/AppSupport.cpp  |   42 +++++++---------
 apps/AppSupport.hpp  |    1 +
 apps/pcinfo.cpp      |   15 ++----
 src/StageFactory.cpp |  123 +++++++++++++++++++++++++++-----------------------
 4 files changed, 90 insertions(+), 91 deletions(-)

diffs (truncated from 314 to 300 lines):

diff -r 0b21ca9d76d9 -r 97b01e5e8af2 apps/AppSupport.cpp
--- a/apps/AppSupport.cpp	Tue Aug 16 09:44:52 2011 -0700
+++ b/apps/AppSupport.cpp	Tue Aug 16 10:11:33 2011 -0700
@@ -35,30 +35,34 @@
 #include "AppSupport.hpp"
 
 #include <boost/filesystem.hpp>
+#include <boost/algorithm/string.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)
 {
-    const std::string ext = boost::filesystem::extension(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.reader";
-    drivers[".laz"] = "drivers.las.reader";
-    drivers[".bin"] = "drivers.terrasolid.reader";
-    drivers[".qi"] = "drivers.qfit.reader";
-    drivers[".xml"] = "drivers.pipeline.reader";
+    drivers["las"] = "drivers.las.reader";
+    drivers["laz"] = "drivers.las.reader";
+    drivers["bin"] = "drivers.terrasolid.reader";
+    drivers["qi"] = "drivers.qfit.reader";
+    drivers["xml"] = "drivers.pipeline.reader";
 
     std::string driver = drivers[ext];
-    if (driver == "")
-    {
-        return "";
-    }
-
-    return driver;
+    return driver; // will be "" if not found
 }
 
 
@@ -69,18 +73,8 @@
     pdal::Options opts(extraOptions);
     opts.add<std::string>("filename", filename);
 
-    if (driver == "drivers.pipeline.reader")
-    {
-        pdal::PipelineManager* pipeManager(new pdal::PipelineManager); // BUG: memleak
-        pdal::PipelineReader pipeReader(*pipeManager);
-        pipeReader.readReaderPipeline(filename);
-        reader = pipeManager->getStage();
-    }
-    else
-    {
-        pdal::StageFactory factory;
-        reader = factory.createReader(driver, opts);
-    }
+    pdal::StageFactory factory;
+    reader = factory.createReader(driver, opts);
 
     return reader;
 }
diff -r 0b21ca9d76d9 -r 97b01e5e8af2 apps/AppSupport.hpp
--- a/apps/AppSupport.hpp	Tue Aug 16 09:44:52 2011 -0700
+++ b/apps/AppSupport.hpp	Tue Aug 16 10:11:33 2011 -0700
@@ -45,6 +45,7 @@
 {
 public:
     // infer the driver to use based on filename extension
+    // returns "" if no driver found
     static std::string inferReaderDriver(const std::string& filename);
 
     // creates a Reader using the given driver type
diff -r 0b21ca9d76d9 -r 97b01e5e8af2 apps/pcinfo.cpp
--- a/apps/pcinfo.cpp	Tue Aug 16 09:44:52 2011 -0700
+++ b/apps/pcinfo.cpp	Tue Aug 16 10:11:33 2011 -0700
@@ -116,27 +116,22 @@
         return 1;
     }
 
-    if (hasOption("liblas"))
+    if (hasOption("liblas") && driver == "drivers.las.reader")
     {
-        if (driver == "drivers.las.reader")
-        {
-            driver = "drivers.liblas.reader";
-        }
+        driver = "drivers.liblas.reader";
     }
 
     pdal::Stage* reader = AppSupport::createReader(driver, m_inputFile, pdal::Options::none());
 
+    reader->initialize();
+
     const boost::uint64_t numPoints = reader->getNumPoints();
     const pdal::SpatialReference& srs = reader->getSpatialReference();
 
+    std::cout << "driver type: " << reader->getName() << "\n";
     std::cout << numPoints << " points\n";
     std::cout << "WKT: " << srs.getWKT() << "\n";
 
-    if (driver != "drivers.pipeline.reader")
-    {
-        delete reader;
-    }
-
     return 0;
 }
 
diff -r 0b21ca9d76d9 -r 97b01e5e8af2 src/StageFactory.cpp
--- a/src/StageFactory.cpp	Tue Aug 16 09:44:52 2011 -0700
+++ b/src/StageFactory.cpp	Tue Aug 16 10:11:33 2011 -0700
@@ -41,24 +41,21 @@
 
 #include <pdal/drivers/faux/Reader.hpp>
 #include <pdal/drivers/las/Reader.hpp>
-
 #ifdef PDAL_HAVE_LIBLAS
 #include <pdal/drivers/liblas/Reader.hpp>
 #endif
-
 #ifdef PDAL_HAVE_ORACLE
 #include <pdal/drivers/oci/Reader.hpp>
 #endif
+#include <pdal/drivers/pipeline/Reader.hpp>
 #include <pdal/drivers/qfit/Reader.hpp>
 #include <pdal/drivers/terrasolid/Reader.hpp>
 
 #include <pdal/drivers/faux/Writer.hpp>
 #include <pdal/drivers/las/Writer.hpp>
-
 #ifdef PDAL_HAVE_LIBLAS
 #include <pdal/drivers/liblas/Writer.hpp>
 #endif
-
 #ifdef PDAL_HAVE_ORACLE
 #include <pdal/drivers/oci/Writer.hpp>
 #endif
@@ -80,54 +77,77 @@
 
 namespace pdal
 {
+    //
+    // macros for creating the various stage types
+    //
+#define MAKE_READER_CREATOR(T, FullT) \
+    Reader* create_##T(const Options& options) \
+        { return new FullT(options); }
+#define MAKE_FILTER_CREATOR(T, FullT) \
+    Filter* create_##T(Stage& prevStage, const Options& options) \
+        { return new FullT(prevStage, options); }
+#define MAKE_MULTIFILTER_CREATOR(T, FullT) \
+    MultiFilter* create_##T(const std::vector<Stage*>& prevStages, const Options& options) \
+        { return new FullT(prevStages, options); }
+#define MAKE_WRITER_CREATOR(T, FullT) \
+    Writer* create_##T(Stage& prevStage, const Options& options) \
+        { return new FullT(prevStage, options); }
 
-#define MAKE_READER_CREATOR(T, FullT) \
-    Reader* create_##T(const Options& options) { return new FullT(options); }
+    //
+    // macros to register the stage creators
+    //
+#define REGISTER_WRITER(T, FullT) \
+    registerWriter(FullT::s_getName(), create_##T)
+#define REGISTER_READER(T, FullT) \
+    registerReader(FullT::s_getName(), create_##T)
+#define REGISTER_FILTER(T, FullT) \
+    registerFilter(FullT::s_getName(), create_##T)
+#define REGISTER_MULTIFILTER(T, FullT) \
+    registerMultiFilter(FullT::s_getName(), create_##T)
 
-#define MAKE_FILTER_CREATOR(T, FullT) \
-    Filter* create_##T(Stage& prevStage, const Options& options) { return new FullT(prevStage, options); }
+    //
+    // define the functions to create the readers
+    //
+    MAKE_READER_CREATOR(FauxReader, pdal::drivers::faux::Reader)
+    MAKE_READER_CREATOR(LasReader, pdal::drivers::las::LasReader)
+#ifdef PDAL_HAVE_LIBLAS
+    MAKE_READER_CREATOR(LiblasReader, pdal::drivers::liblas::LiblasReader)
+#endif
+#ifdef PDAL_HAVE_ORACLE
+    MAKE_READER_CREATOR(OciReader, pdal::drivers::oci::Reader)
+#endif
+    MAKE_READER_CREATOR(Reader, pdal::drivers::pipeline::Reader)
+    MAKE_READER_CREATOR(QfitReader, pdal::drivers::qfit::Reader)
+    MAKE_READER_CREATOR(TerrasolidReader, pdal::drivers::terrasolid::Reader)
 
-#define MAKE_MULTIFILTER_CREATOR(T, FullT) \
-    MultiFilter* create_##T(const std::vector<Stage*>& prevStages, const Options& options) { return new FullT(prevStages, options); }
+    //
+    // define the functions to create the filters
+    //
+    MAKE_FILTER_CREATOR(ByteSwapFilter, pdal::filters::ByteSwapFilter)
+    MAKE_FILTER_CREATOR(CacheFilter, pdal::filters::CacheFilter)
+    MAKE_FILTER_CREATOR(Chipper, pdal::filters::Chipper)
+    MAKE_FILTER_CREATOR(ColorFilter, pdal::filters::ColorFilter)
+    MAKE_FILTER_CREATOR(CropFilter, pdal::filters::CropFilter)
+    MAKE_FILTER_CREATOR(DecimationFilter, pdal::filters::DecimationFilter)
+    MAKE_FILTER_CREATOR(ReprojectionFilter, pdal::filters::ReprojectionFilter)
+    MAKE_FILTER_CREATOR(ScalingFilter, pdal::filters::ScalingFilter)
+    MAKE_FILTER_CREATOR(DescalingFilter, pdal::filters::DescalingFilter)
 
-#define MAKE_WRITER_CREATOR(T, FullT) \
-    Writer* create_##T(Stage& prevStage, const Options& options) { return new FullT(prevStage, options); }
+    //
+    // define the functions to create the multifilters
+    //
+    MAKE_MULTIFILTER_CREATOR(MosaicFilter, pdal::filters::MosaicFilter)
 
-MAKE_READER_CREATOR(FauxReader, pdal::drivers::faux::Reader)
-MAKE_READER_CREATOR(LasReader, pdal::drivers::las::LasReader)
-
+    //
+    // define the functions to create the writers
+    //
+    MAKE_WRITER_CREATOR(FauxWriter, pdal::drivers::faux::Writer)
+    MAKE_WRITER_CREATOR(LasWriter, pdal::drivers::las::LasWriter)
 #ifdef PDAL_HAVE_LIBLAS
-MAKE_READER_CREATOR(LiblasReader, pdal::drivers::liblas::LiblasReader)
+    MAKE_WRITER_CREATOR(LiblasWriter, pdal::drivers::liblas::LiblasWriter)
 #endif
-
 #ifdef PDAL_HAVE_ORACLE
-MAKE_READER_CREATOR(OciReader, pdal::drivers::oci::Reader)
-#endif
-
-MAKE_READER_CREATOR(QfitReader, pdal::drivers::qfit::Reader)
-MAKE_READER_CREATOR(TerrasolidReader, pdal::drivers::terrasolid::Reader)
-
-MAKE_FILTER_CREATOR(ByteSwapFilter, pdal::filters::ByteSwapFilter)
-MAKE_FILTER_CREATOR(CacheFilter, pdal::filters::CacheFilter)
-MAKE_FILTER_CREATOR(Chipper, pdal::filters::Chipper)
-MAKE_FILTER_CREATOR(ColorFilter, pdal::filters::ColorFilter)
-MAKE_FILTER_CREATOR(CropFilter, pdal::filters::CropFilter)
-MAKE_FILTER_CREATOR(DecimationFilter, pdal::filters::DecimationFilter)
-MAKE_FILTER_CREATOR(ReprojectionFilter, pdal::filters::ReprojectionFilter)
-MAKE_FILTER_CREATOR(ScalingFilter, pdal::filters::ScalingFilter)
-MAKE_FILTER_CREATOR(DescalingFilter, pdal::filters::DescalingFilter)
-
-MAKE_MULTIFILTER_CREATOR(MosaicFilter, pdal::filters::MosaicFilter)
-
-MAKE_WRITER_CREATOR(FauxWriter, pdal::drivers::faux::Writer)
-MAKE_WRITER_CREATOR(LasWriter, pdal::drivers::las::LasWriter)
-
-#ifdef PDAL_HAVE_LIBLAS
-MAKE_WRITER_CREATOR(LiblasWriter, pdal::drivers::liblas::LiblasWriter)
-#endif
-
-#ifdef PDAL_HAVE_ORACLE
-MAKE_WRITER_CREATOR(OciWriter, pdal::drivers::oci::Writer)
+    MAKE_WRITER_CREATOR(OciWriter, pdal::drivers::oci::Writer)
 #endif
 
 
@@ -261,9 +281,6 @@
 
 void StageFactory::registerKnownReaders()
 {
-#define REGISTER_READER(T, FullT) \
-    registerReader(FullT::s_getName(), create_##T)
-
     REGISTER_READER(FauxReader, pdal::drivers::faux::Reader);
     REGISTER_READER(LasReader, pdal::drivers::las::LasReader);
 #ifdef PDAL_HAVE_LIBLAS
@@ -272,6 +289,7 @@
 #ifdef PDAL_HAVE_ORACLE
     REGISTER_READER(OciReader, pdal::drivers::oci::Reader);
 #endif
+    REGISTER_READER(Reader, pdal::drivers::pipeline::Reader);
     REGISTER_READER(QfitReader, pdal::drivers::qfit::Reader);
     REGISTER_READER(TerrasolidReader, pdal::drivers::terrasolid::Reader);
 }
@@ -279,9 +297,6 @@
 
 void StageFactory::registerKnownFilters()
 {
-#define REGISTER_FILTER(T, FullT) \
-    registerFilter(FullT::s_getName(), create_##T)
-
     REGISTER_FILTER(ByteSwapFilter, pdal::filters::ByteSwapFilter);
     REGISTER_FILTER(CacheFilter, pdal::filters::CacheFilter);
     REGISTER_FILTER(Chipper, pdal::filters::Chipper);
@@ -295,19 +310,13 @@
 
 
 void StageFactory::registerKnownMultiFilters()
-{
-#define REGISTER_MULTIFILTER(T, FullT) \
-    registerMultiFilter(FullT::s_getName(), create_##T)


More information about the Liblas-commits mailing list