[Liblas-commits] hg-main-tree: added Options ctor support for LasReader, LasReade...

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Jul 14 15:38:47 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/2194feefd1a9
changeset: 861:2194feefd1a9
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Thu Jul 14 12:24:37 2011 -0700
description:
added Options ctor support for LasReader, LasReader, Crop; had to make the Writer take a filename instead of a stream

diffstat:

 apps/pc2pc.cpp                       |  18 +++++-----
 apps/pcinfo.cpp                      |   8 +++-
 apps/pcview/main.cpp                 |   3 +-
 apps/qfit2las.cpp                    |   8 +---
 include/pdal/Options.hpp             |  57 ++++++++++++++++++++++++++++++++---
 include/pdal/drivers/las/Reader.hpp  |   3 +-
 include/pdal/drivers/las/Writer.hpp  |   4 +-
 include/pdal/exceptions.hpp          |   7 ++++
 include/pdal/filters/CropFilter.hpp  |   5 ---
 src/Options.cpp                      |  37 ++++++++++++++++++-----
 src/drivers/las/Reader.cpp           |  10 +-----
 src/drivers/las/Writer.cpp           |  32 +++++++++++--------
 src/filters/CropFilter.cpp           |  17 +--------
 test/unit/CropFilterTest.cpp         |   3 +-
 test/unit/LasReaderTest.cpp          |  27 +++++++++++-----
 test/unit/LasWriterTest.cpp          |  36 ++++++++-------------
 test/unit/OptionsTest.cpp            |  25 +++++++++++++++
 test/unit/PipelineManagerTest.cpp    |  13 ++++++-
 test/unit/ReprojectionFilterTest.cpp |  12 +++++--
 test/unit/SpatialReferenceTest.cpp   |  27 ++++++++--------
 test/unit/StageFactoryTest.cpp       |  11 +++++-
 21 files changed, 231 insertions(+), 132 deletions(-)

diffs (truncated from 937 to 300 lines):

diff -r 76841e1d4454 -r 2194feefd1a9 apps/pc2pc.cpp
--- a/apps/pc2pc.cpp	Wed Jul 13 20:21:56 2011 -0700
+++ b/apps/pc2pc.cpp	Thu Jul 14 12:24:37 2011 -0700
@@ -118,15 +118,16 @@
         return 1;
     }
 
-    std::ostream* ofs = Utils::createFile(m_outputFile);
+    Options optsW("filename", m_outputFile, "file to write to");
 
     if (hasOption("native"))
     {
-        pdal::drivers::las::LasReader reader(m_inputFile);
+        Options optsR("filename", m_inputFile, "file to read from");
+        pdal::drivers::las::LasReader reader(optsR);
     
         const boost::uint64_t numPoints = reader.getNumPoints();
 
-        pdal::drivers::las::LasWriter writer(reader, *ofs);
+        pdal::drivers::las::LasWriter writer(reader, optsW);
 
         //BUG: handle laz writer.setCompressed(false);
 
@@ -138,7 +139,8 @@
     else if (hasOption("oracle-writer"))
     {
 #ifdef PDAL_HAVE_ORACLE
-        pdal::drivers::las::LasReader reader(m_inputFile);
+        Options optsR("filename", m_inputFile, "file to read from");
+        pdal::drivers::las::LasReader reader(optsR);
     
         const boost::uint64_t numPoints = reader.getNumPoints();
 
@@ -250,7 +252,7 @@
                                                             scalez, offsetz, 
                                                             true);
 
-            pdal::drivers::las::LasWriter writer(descalingFilter, *ofs);
+            pdal::drivers::las::LasWriter writer(descalingFilter, optsW);
 
 
             if (compress)
@@ -266,7 +268,7 @@
             pdal::filters::ByteSwapFilter swapper(reader);
             
 
-            pdal::drivers::las::LasWriter writer(swapper, *ofs);
+            pdal::drivers::las::LasWriter writer(swapper, optsW);
             if (compress)
                 writer.setCompressed(true);
         
@@ -296,7 +298,7 @@
     
         const boost::uint64_t numPoints = reader.getNumPoints();
 
-        pdal::drivers::liblas::LiblasWriter writer(reader, *ofs);
+        pdal::drivers::liblas::LiblasWriter writer(reader, optsW);
 
         //BUG: handle laz writer.setCompressed(false);
 
@@ -305,8 +307,6 @@
         writer.write(numPoints);
     }
 
-    Utils::closeFile(ofs);
-
     return 0;
 }
 
diff -r 76841e1d4454 -r 2194feefd1a9 apps/pcinfo.cpp
--- a/apps/pcinfo.cpp	Wed Jul 13 20:21:56 2011 -0700
+++ b/apps/pcinfo.cpp	Thu Jul 14 12:24:37 2011 -0700
@@ -13,6 +13,8 @@
 #include <pdal/drivers/las/Reader.hpp>
 #include <pdal/drivers/liblas/Reader.hpp>
 #include <pdal/Utils.hpp>
+#include <pdal/Options.hpp>
+
 #ifdef PDAL_HAVE_MRSID
 #include <pdal/drivers/mrsid/Reader.hpp>
 #endif
@@ -88,13 +90,15 @@
         if (!m_inputFile.substr(ext).compare("las") ||
             !m_inputFile.substr(ext).compare("laz"))
         {
+            Options opts;
+            opts.add("filename", m_inputFile, "file to read from");
             if (hasOption("native"))
             {
-                reader = new pdal::drivers::las::LasReader(m_inputFile);
+                reader = new pdal::drivers::las::LasReader(opts);
             }
             else
             {
-                reader = new pdal::drivers::liblas::LiblasReader(m_inputFile);
+                reader = new pdal::drivers::liblas::LiblasReader(opts);
             }
         }
 #ifdef PDAL_HAVE_MRSID
diff -r 76841e1d4454 -r 2194feefd1a9 apps/pcview/main.cpp
--- a/apps/pcview/main.cpp	Wed Jul 13 20:21:56 2011 -0700
+++ b/apps/pcview/main.cpp	Thu Jul 14 12:24:37 2011 -0700
@@ -232,7 +232,8 @@
 {
     boost::timer timer;
 
-    pdal::Stage* reader = new pdal::drivers::las::LasReader(file);
+    pdal::Options optsR("filename", file, "file to read from");
+    pdal::Stage* reader = new pdal::drivers::las::LasReader(optsR);
     
     pdal::Stage* decimator = new pdal::filters::DecimationFilter(*reader, factor);
 
diff -r 76841e1d4454 -r 2194feefd1a9 apps/qfit2las.cpp
--- a/apps/qfit2las.cpp	Wed Jul 13 20:21:56 2011 -0700
+++ b/apps/qfit2las.cpp	Thu Jul 14 12:24:37 2011 -0700
@@ -84,7 +84,6 @@
         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" );
@@ -93,16 +92,13 @@
     
     const boost::uint64_t numPoints = reader.getNumPoints();
 
-    pdal::drivers::las::LasWriter writer(reader, *ofs);
-
+    Options optsW("filename", m_outputFile, "file to write to");
+    pdal::drivers::las::LasWriter writer(reader, optsW);
 
     // writer.setPointFormat( reader.getPointFormat() );
 
     writer.write(numPoints);
 
-
-    Utils::closeFile(ofs);
-
     return 0;
 }
 
diff -r 76841e1d4454 -r 2194feefd1a9 include/pdal/Options.hpp
--- a/include/pdal/Options.hpp	Wed Jul 13 20:21:56 2011 -0700
+++ b/include/pdal/Options.hpp	Thu Jul 14 12:24:37 2011 -0700
@@ -121,7 +121,43 @@
 class PDAL_DLL Options
 {
 public:
-    Options();
+    // defult ctor, empy options list
+    Options()
+    {
+    }
+
+    // convenience ctor, which adds 1 option
+    template<class T>
+    Options(const std::string& name, T value, const std::string& description)
+    {
+        Option<T> opt(name, value, description);
+        add(opt);
+    }
+
+    // convenience ctor, which adds 2 options
+    template<class T1, class T2>
+    Options(const std::string& name1, T1 value1, const std::string& description1,
+            const std::string& name2, T2 value2, const std::string& description2)
+    {
+        Option<T1> opt1(name1, value1, description1);
+        add(opt1);
+        Option<T2> opt2(name2, value2, description2);
+        add(opt2);
+    }
+
+    // convenience ctor, which adds 3 options
+    template<class T1, class T2, class T3>
+    Options(const std::string& name1, T1 value1, const std::string& description1,
+            const std::string& name2, T2 value2, const std::string& description2,
+            const std::string& name3, T3 value3, const std::string& description3)
+    {
+        Option<T1> opt1(name1, value1, description1);
+        add(opt1);
+        Option<T2> opt2(name2, value2, description2);
+        add(opt2);
+        Option<T3> opt3(name3, value3, description3);
+        add(opt3);
+    }
 
     // add an option
     template<class T> void add(Option<T> const& option)
@@ -138,23 +174,32 @@
     }
 
     // get value of an option
+    // throws pdal::option_not_found if the option name is not valid
     template<class T> T getValue(std::string const& name) const
     {
+        T value;
         try 
         {
             boost::property_tree::ptree optionTree = getOptionPTree(name);
-            return optionTree.get_child("value").get_value<T>();
-        } catch (boost::property_tree::ptree_bad_path const&)
+            value = optionTree.get_child("value").get_value<T>();
+        } 
+        catch (boost::property_tree::ptree_bad_path const&)
         {
-            return T();
+            throw option_not_found(name);
         }
-    
 
+        return value;
     }
 
     // get description of an option
+    // throws pdal::option_not_found if the option name is not valid
     std::string getDescription(std::string const& name) const;
-    
+
+    // returns true iff the option name is valid
+    bool hasOption(std::string const& name) const;
+
+    // get the ptree for an option
+    // throws pdal::option_not_found if the option name is not valid
     boost::property_tree::ptree const& getPTree() const;
    
     // return the empty options list
diff -r 76841e1d4454 -r 2194feefd1a9 include/pdal/drivers/las/Reader.hpp
--- a/include/pdal/drivers/las/Reader.hpp	Wed Jul 13 20:21:56 2011 -0700
+++ b/include/pdal/drivers/las/Reader.hpp	Thu Jul 14 12:24:37 2011 -0700
@@ -57,7 +57,6 @@
 {
 public:
     LasReader(const Options& options);
-    LasReader(const std::string& filename);
 
     const std::string& getDescription() const;
     const std::string& getName() const;
@@ -99,7 +98,7 @@
     MetadataRecord& getMetadataRecordRef(int index);
 
 private:
-    const std::string m_filename;
+    std::string m_filename;
     LasHeader m_lasHeader;
     std::vector<MetadataRecord> m_metadataRecords;
 
diff -r 76841e1d4454 -r 2194feefd1a9 include/pdal/drivers/las/Writer.hpp
--- a/include/pdal/drivers/las/Writer.hpp	Wed Jul 13 20:21:56 2011 -0700
+++ b/include/pdal/drivers/las/Writer.hpp	Thu Jul 14 12:24:37 2011 -0700
@@ -54,7 +54,6 @@
 {
 public:
     LasWriter(const Stage& prevStage, const Options& options);
-    LasWriter(const Stage& prevStage, std::ostream&);
     ~LasWriter();
 
     const std::string& getDescription() const;
@@ -88,7 +87,8 @@
     virtual void writeEnd();
 
 private:
-    std::ostream& m_ostream;
+    std::string m_filename;
+    std::ostream* m_ostream;
     LasHeader m_lasHeader;
     boost::uint32_t m_numPointsWritten;
     bool m_isCompressed;
diff -r 76841e1d4454 -r 2194feefd1a9 include/pdal/exceptions.hpp
--- a/include/pdal/exceptions.hpp	Wed Jul 13 20:21:56 2011 -0700
+++ b/include/pdal/exceptions.hpp	Thu Jul 14 12:24:37 2011 -0700
@@ -139,6 +139,13 @@
     {}
 };
 
+class option_not_found : public pdal_error
+{
+public:
+    option_not_found(std::string const& msg)
+        : pdal_error(msg)
+    {}
+};
 
 // use this for code still under development
 class not_yet_implemented : public pdal_error
diff -r 76841e1d4454 -r 2194feefd1a9 include/pdal/filters/CropFilter.hpp
--- a/include/pdal/filters/CropFilter.hpp	Wed Jul 13 20:21:56 2011 -0700
+++ b/include/pdal/filters/CropFilter.hpp	Thu Jul 14 12:24:37 2011 -0700
@@ -56,7 +56,6 @@
 {
 public:
     CropFilter(const Stage& prevStage, const Options& options);
-    CropFilter(const Stage& prevStage, Bounds<double> const& bounds);
 
     const std::string& getDescription() const;
     const std::string& getName() const;
@@ -75,11 +74,7 @@
     // if we're calling this routine multiple times with the same buffer
     boost::uint32_t processBuffer(PointBuffer& dstData, const PointBuffer& srcData) const;


More information about the Liblas-commits mailing list