[Liblas-commits] hg-main-tree: disallow multiple init() calls

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Aug 2 14:42:50 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/eabd37518696
changeset: 983:eabd37518696
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Aug 02 11:42:17 2011 -0700
description:
disallow multiple init() calls
Subject: hg-main-tree: add ctor that infers input SRS

details:   http://hg.libpc.orghg-main-tree/rev/80e015bd150c
changeset: 984:80e015bd150c
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Aug 02 11:42:42 2011 -0700
description:
add ctor that infers input SRS

diffstat:

 include/pdal/StageBase.hpp                  |   2 +-
 include/pdal/filters/ReprojectionFilter.hpp |   3 ++
 src/StageBase.cpp                           |  11 ++++-----
 src/filters/ReprojectionFilter.cpp          |  28 +++++++++++++++++++++++++-
 test/unit/ReprojectionFilterTest.cpp        |  31 ++++------------------------
 5 files changed, 41 insertions(+), 34 deletions(-)

diffs (189 lines):

diff -r 75f6b5eb3fdb -r 80e015bd150c include/pdal/StageBase.hpp
--- a/include/pdal/StageBase.hpp	Tue Aug 02 11:25:52 2011 -0700
+++ b/include/pdal/StageBase.hpp	Tue Aug 02 11:42:42 2011 -0700
@@ -55,7 +55,7 @@
     // This function is for derived stages to perform "static" validation, e.g. bad Option arguments.
     // It will recursively call initialize() on all previous stages.
     // Users must call this after the last stage in the pipeline has been consturcted.  
-    // It is not illegal to call this twice for a stage, but that doesn't mean you should.
+    // It is illegal to call this twice for a stage.
     // Derived stages should feel free to provide their own implementations.  Remeber to call initialize() on
     //   the parent class before your own class-specific code.
     // This function will throw when errors are found.
diff -r 75f6b5eb3fdb -r 80e015bd150c include/pdal/filters/ReprojectionFilter.hpp
--- a/include/pdal/filters/ReprojectionFilter.hpp	Tue Aug 02 11:25:52 2011 -0700
+++ b/include/pdal/filters/ReprojectionFilter.hpp	Tue Aug 02 11:42:42 2011 -0700
@@ -57,6 +57,8 @@
 public:
     ReprojectionFilter(Stage& prevStage, const Options&);
     ReprojectionFilter(Stage& prevStage,
+                       const SpatialReference& outSRS);
+    ReprojectionFilter(Stage& prevStage,
                        const SpatialReference& inSRS,
                        const SpatialReference& outSRS);
     virtual void initialize();
@@ -80,6 +82,7 @@
 
     SpatialReference m_inSRS;
     SpatialReference m_outSRS;
+    bool m_inferInputSRS;
 
     typedef boost::shared_ptr<void> ReferencePtr;
     typedef boost::shared_ptr<void> TransformPtr;
diff -r 75f6b5eb3fdb -r 80e015bd150c src/StageBase.cpp
--- a/src/StageBase.cpp	Tue Aug 02 11:25:52 2011 -0700
+++ b/src/StageBase.cpp	Tue Aug 02 11:42:42 2011 -0700
@@ -61,12 +61,11 @@
 
 void StageBase::initialize()
 {
-    // it is legal now to call initialize() twice (but you really shouldn't)
-    //
-    //if (m_initialized)
-    //{
-    //    throw pdal_error("Class already initialized: " + this->getName());
-    //}
+    // it is illegal to call initialize() twice
+    if (m_initialized)
+    {
+        throw pdal_error("Class already initialized: " + this->getName());
+    }
 
     m_debug = m_options.getValueOrDefault<bool>("debug", false);
     m_verbose = m_options.getValueOrDefault<boost::uint8_t>("verbose", 0);
diff -r 75f6b5eb3fdb -r 80e015bd150c src/filters/ReprojectionFilter.cpp
--- a/src/filters/ReprojectionFilter.cpp	Tue Aug 02 11:25:52 2011 -0700
+++ b/src/filters/ReprojectionFilter.cpp	Tue Aug 02 11:42:42 2011 -0700
@@ -86,8 +86,28 @@
 
 ReprojectionFilter::ReprojectionFilter(Stage& prevStage, const Options& options)
     : pdal::Filter(prevStage, options)
-    , m_inSRS(options.getValueOrThrow<std::string>("in_srs"))
     , m_outSRS(options.getValueOrThrow<std::string>("out_srs"))
+    , m_inferInputSRS(false)
+{
+    if (options.hasOption<std::string>("in_srs"))
+    {
+        m_inSRS = SpatialReference(options.getValueOrThrow<std::string>("in_srs"));
+        m_inferInputSRS = false;
+    }
+    else
+    {
+        m_inferInputSRS = true;
+    }
+
+    return;
+}
+
+
+ReprojectionFilter::ReprojectionFilter(Stage& prevStage,
+                                       const SpatialReference& outSRS)
+    : Filter(prevStage, Options::none())
+    , m_outSRS(outSRS)
+    , m_inferInputSRS(true)
 {
     return;
 }
@@ -99,6 +119,7 @@
     : Filter(prevStage, Options::none())
     , m_inSRS(inSRS)
     , m_outSRS(outSRS)
+    , m_inferInputSRS(false)
 {
     return;
 }
@@ -110,6 +131,11 @@
 
     checkImpedance();
 
+    if (m_inferInputSRS)
+    {
+        m_inSRS = getPrevStage().getSpatialReference();
+    }
+
 #ifdef PDAL_HAVE_GDAL
     
     m_in_ref_ptr = ReferencePtr(OSRNewSpatialReference(0), OGRSpatialReferenceDeleter());
diff -r 75f6b5eb3fdb -r 80e015bd150c test/unit/ReprojectionFilterTest.cpp
--- a/test/unit/ReprojectionFilterTest.cpp	Tue Aug 02 11:25:52 2011 -0700
+++ b/test/unit/ReprojectionFilterTest.cpp	Tue Aug 02 11:42:42 2011 -0700
@@ -144,17 +144,11 @@
     //
     {
         const pdal::SpatialReference out_ref(epsg4326_wkt);
-        pdal::SpatialReference in_ref;
-        {
-            pdal::drivers::las::LasReader reader(Support::datapath("utm15.las"));
-            reader.initialize();
-            in_ref.setWKT(reader.getSpatialReference().getWKT());
-        }
 
         pdal::drivers::las::LasReader reader(Support::datapath("utm15.las"));
 
         pdal::filters::ScalingFilter scalingFilter(reader);
-        pdal::filters::ReprojectionFilter reprojectionFilter(scalingFilter, in_ref, out_ref);
+        pdal::filters::ReprojectionFilter reprojectionFilter(scalingFilter, out_ref);
         pdal::filters::DescalingFilter descalingFilter(reprojectionFilter);
         
         descalingFilter.initialize();
@@ -185,18 +179,11 @@
     //
     {
         const pdal::SpatialReference out_ref(epsg4326_wkt);
-        pdal::SpatialReference in_ref;
-        {
-            pdal::drivers::las::LasReader reader(Support::datapath("utm15.las"));
-            reader.initialize();
-            in_ref.setWKT(reader.getSpatialReference().getWKT());
-        }
 
         pdal::drivers::las::LasReader reader(Support::datapath("utm15.las"));
 
-        pdal::Option<std::string> opt1("in_srs", in_ref.getWKT());
         pdal::Option<std::string> opt2("out_srs", out_ref.getWKT());
-        pdal::Options opts(opt1, opt2);
+        pdal::Options opts(opt2);
 
         pdal::filters::ScalingFilter scalingFilter(reader);
         pdal::filters::ReprojectionFilter reprojectionFilter(scalingFilter, opts);
@@ -230,19 +217,13 @@
     //
     {
         const pdal::SpatialReference out_ref(epsg4326_wkt);
-        pdal::SpatialReference in_ref;
-        {
-            pdal::drivers::las::LasReader reader(Support::datapath("utm15.las"));
-            reader.initialize();
-            in_ref.setWKT(reader.getSpatialReference().getWKT());
-        }
 
         pdal::drivers::las::LasReader reader(Support::datapath("utm15.las"));
             
         // convert to doubles, use internal scale factor
         pdal::filters::ScalingFilter scalingFilter(reader);
 
-        pdal::filters::ReprojectionFilter reprojectionFilter(scalingFilter, in_ref, out_ref);
+        pdal::filters::ReprojectionFilter reprojectionFilter(scalingFilter, out_ref);
     
         // convert to ints, using custom scale factor
         pdal::filters::DescalingFilter descalingFilter(reprojectionFilter, 0.000001, 0.0, 0.000001, 0.0, 0.01, 0.0);
@@ -274,9 +255,7 @@
 BOOST_AUTO_TEST_CASE(test_impedence_mismatch)
 {
     pdal::drivers::las::LasReader reader(Support::datapath("utm15.las"));
-        
-    const pdal::SpatialReference& in_ref = reader.getSpatialReference();
-        
+              
     const char* epsg4326_wkt = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433],AUTHORITY[\"EPSG\",\"4326\"]]";
         
     pdal::SpatialReference out_ref;
@@ -285,7 +264,7 @@
     bool ok = false;
     try
     {
-        pdal::filters::ReprojectionFilter filter(reader, in_ref, out_ref);
+        pdal::filters::ReprojectionFilter filter(reader, out_ref);
         filter.initialize();
         ok = false;
     }


More information about the Liblas-commits mailing list