[Liblas-commits] hg-main-tree: refactored so we now have a ScalingFilter and a De...

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Jul 29 16:18:52 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/85319a61837a
changeset: 969:85319a61837a
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Jul 29 12:58:53 2011 -0700
description:
refactored so we now have a ScalingFilter and a DescalingFilter -- no more mixing up the two ctors
Subject: hg-main-tree: enable Options-based ctors

details:   http://hg.libpc.orghg-main-tree/rev/0a58c00bb880
changeset: 970:0a58c00bb880
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Jul 29 13:11:02 2011 -0700
description:
enable Options-based ctors
Subject: hg-main-tree: enable Options-based ctors

details:   http://hg.libpc.orghg-main-tree/rev/2c9f23486fd8
changeset: 971:2c9f23486fd8
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Jul 29 13:18:43 2011 -0700
description:
enable Options-based ctors

diffstat:

 apps/pc2pc.cpp                                 |   22 +--
 include/pdal/filters/ScalingFilter.hpp         |   38 +++++-
 include/pdal/filters/ScalingFilterIterator.hpp |    4 +-
 src/StageFactory.cpp                           |    2 +
 src/filters/ReprojectionFilter.cpp             |   10 +-
 src/filters/ScalingFilter.cpp                  |  141 ++++++++++++++++++++----
 src/filters/ScalingFilterIterator.cpp          |    2 +-
 test/unit/ReprojectionFilterTest.cpp           |   46 +++++++-
 test/unit/ScalingFilterTest.cpp                |    2 +-
 9 files changed, 213 insertions(+), 54 deletions(-)

diffs (truncated from 481 to 300 lines):

diff -r 0f158c29d276 -r 2c9f23486fd8 apps/pc2pc.cpp
--- a/apps/pc2pc.cpp	Fri Jul 29 12:20:31 2011 -0700
+++ b/apps/pc2pc.cpp	Fri Jul 29 13:18:43 2011 -0700
@@ -173,13 +173,12 @@
         
         pdal::filters::CacheFilter cache(reader, 1, capacity);
         pdal::filters::Chipper chipper(cache, capacity);
-        pdal::filters::ScalingFilter scalingFilter(chipper, false);
+        pdal::filters::ScalingFilter scalingFilter(chipper);
         pdal::filters::ReprojectionFilter reprojectionFilter(scalingFilter, in_ref, out_ref);
-        pdal::filters::ScalingFilter descalingFilter(   reprojectionFilter, 
-                                                        scalex, offsetx,
-                                                        scaley, offsety, 
-                                                        scalez, offsetz, 
-                                                        true);
+        pdal::filters::DescalingFilter descalingFilter(reprojectionFilter,
+                                                       scalex, offsetx,
+                                                       scaley, offsety,
+                                                       scalez, offsetz);
         
         // pdal::filters::ByteSwapFilter swapper(descalingFilter);
         pdal::drivers::oci::Writer writer(descalingFilter, options);
@@ -237,13 +236,12 @@
         if (!(in_ref == out_ref)) 
         {
             // pdal::filters::ByteSwapFilter swapper(reader);
-            pdal::filters::ScalingFilter scalingFilter(reader, false);
+            pdal::filters::ScalingFilter scalingFilter(reader);
             pdal::filters::ReprojectionFilter reprojectionFilter(scalingFilter, in_ref, out_ref);
-            pdal::filters::ScalingFilter descalingFilter(   reprojectionFilter, 
-                                                            scalex, offsetx,
-                                                            scaley, offsety, 
-                                                            scalez, offsetz, 
-                                                            true);
+            pdal::filters::DescalingFilter descalingFilter(reprojectionFilter, 
+                                                           scalex, offsetx,
+                                                           scaley, offsety,
+                                                           scalez, offsetz);
 
             writer = new pdal::drivers::las::LasWriter(descalingFilter, ofs);
             if (compress)
diff -r 0f158c29d276 -r 2c9f23486fd8 include/pdal/filters/ScalingFilter.hpp
--- a/include/pdal/filters/ScalingFilter.hpp	Fri Jul 29 12:20:31 2011 -0700
+++ b/include/pdal/filters/ScalingFilter.hpp	Fri Jul 29 13:18:43 2011 -0700
@@ -50,11 +50,10 @@
 
 class ScalingFilterSequentialIterator;
 
-class PDAL_DLL ScalingFilter : public Filter
+class PDAL_DLL ScalingFilterBase : public Filter
 {
-    DECLARE_STATICS
+protected: // the ctors are protected, since we want people to use the two derived classes below
 
-public:
     // for now...
     //   - we only support scaling of the X,Y,Z fields
     //   - we only support scaling doubles <--> int32s
@@ -62,10 +61,11 @@
     //   - "forward=true" means doubles --> ints
     //   - "forward=false" means ints --> doubles
     //   - 1st version uses the scale/offset values already present
-    ScalingFilter(const Stage& prevStage, const Options&);
-    ScalingFilter(const Stage& prevStage, bool forward);
-    ScalingFilter(const Stage& prevStage, double scaleX, double offsetX, double scaleY, double offsetY, double scaleZ, double offsetZ, bool forward);
+    ScalingFilterBase(const Stage& prevStage, bool isDescaling, const Options&);
+    ScalingFilterBase(const Stage& prevStage, bool isDescaling);
+    ScalingFilterBase(const Stage& prevStage, bool isDescaling, double scaleX, double offsetX, double scaleY, double offsetY, double scaleZ, double offsetZ);
 
+public:
     bool supportsIterator (StageIteratorType t) const
     {   
         if (t == StageIterator_Sequential ) return true;
@@ -85,10 +85,30 @@
     bool m_customScaleOffset;
     double m_scaleX, m_scaleY, m_scaleZ;
     double m_offsetX, m_offsetY, m_offsetZ;
-    bool m_forward;
+    bool m_isDescaling;
 
-    ScalingFilter& operator=(const ScalingFilter&); // not implemented
-    ScalingFilter(const ScalingFilter&); // not implemented
+    ScalingFilterBase& operator=(const ScalingFilterBase&); // not implemented
+    ScalingFilterBase(const ScalingFilterBase&); // not implemented
+};
+
+
+class PDAL_DLL ScalingFilter: public ScalingFilterBase
+{
+    DECLARE_STATICS
+public:
+    ScalingFilter(const Stage& prevStage);
+    ScalingFilter(const Stage& prevStage, const Options&);
+    ScalingFilter(const Stage& prevStage, double scaleX, double offsetX, double scaleY, double offsetY, double scaleZ, double offsetZ);
+};
+
+
+class PDAL_DLL DescalingFilter: public ScalingFilterBase
+{
+    DECLARE_STATICS
+public:
+    DescalingFilter(const Stage& prevStage);
+    DescalingFilter(const Stage& prevStage, const Options&);
+    DescalingFilter(const Stage& prevStage, double scaleX, double offsetX, double scaleY, double offsetY, double scaleZ, double offsetZ);
 };
 
 
diff -r 0f158c29d276 -r 2c9f23486fd8 include/pdal/filters/ScalingFilterIterator.hpp
--- a/include/pdal/filters/ScalingFilterIterator.hpp	Fri Jul 29 12:20:31 2011 -0700
+++ b/include/pdal/filters/ScalingFilterIterator.hpp	Fri Jul 29 13:18:43 2011 -0700
@@ -46,14 +46,14 @@
 class ScalingFilterSequentialIterator : public pdal::FilterSequentialIterator
 {
 public:
-    ScalingFilterSequentialIterator(const ScalingFilter& filter);
+    ScalingFilterSequentialIterator(const ScalingFilterBase& filter);
 
 private:
     boost::uint64_t skipImpl(boost::uint64_t);
     boost::uint32_t readImpl(PointBuffer&);
     bool atEndImpl() const;
 
-    const ScalingFilter& m_scalingFilter;
+    const ScalingFilterBase& m_scalingFilter;
 };
 
 
diff -r 0f158c29d276 -r 2c9f23486fd8 src/StageFactory.cpp
--- a/src/StageFactory.cpp	Fri Jul 29 12:20:31 2011 -0700
+++ b/src/StageFactory.cpp	Fri Jul 29 13:18:43 2011 -0700
@@ -101,6 +101,7 @@
 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)
 
@@ -246,6 +247,7 @@
     REGISTER_FILTER(DecimationFilter, pdal::filters::DecimationFilter);
     REGISTER_FILTER(ReprojectionFilter, pdal::filters::ReprojectionFilter);
     REGISTER_FILTER(ScalingFilter, pdal::filters::ScalingFilter);
+    REGISTER_FILTER(DescalingFilter, pdal::filters::DescalingFilter);
 }
 
 
diff -r 0f158c29d276 -r 2c9f23486fd8 src/filters/ReprojectionFilter.cpp
--- a/src/filters/ReprojectionFilter.cpp	Fri Jul 29 12:20:31 2011 -0700
+++ b/src/filters/ReprojectionFilter.cpp	Fri Jul 29 13:18:43 2011 -0700
@@ -86,8 +86,16 @@
 
 ReprojectionFilter::ReprojectionFilter(const 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"))
 {
-    throw not_yet_implemented("options ctor"); 
+    checkImpedance();
+
+    initialize();
+
+    updateBounds();
+
+    return;
 }
 
 
diff -r 0f158c29d276 -r 2c9f23486fd8 src/filters/ScalingFilter.cpp
--- a/src/filters/ScalingFilter.cpp	Fri Jul 29 12:20:31 2011 -0700
+++ b/src/filters/ScalingFilter.cpp	Fri Jul 29 13:18:43 2011 -0700
@@ -46,17 +46,55 @@
 namespace pdal { namespace filters {
 
 
-IMPLEMENT_STATICS(ScalingFilter, "filters.scaling", "Scaling Filter")
+// ------------------------------------------------------------------------
 
+ScalingFilterBase::ScalingFilterBase(const Stage& prevStage, bool isDescaling, const Options& options)
+    : Filter(prevStage, options)
+    , m_customScaleOffset(false)
+    , m_scaleX(0.0)
+    , m_scaleY(0.0)
+    , m_scaleZ(0.0)
+    , m_offsetX(0.0)
+    , m_offsetY(0.0)
+    , m_offsetZ(0.0)
+    , m_isDescaling(isDescaling)
+{
+    int sum = 0;
+    if (options.hasOption<double>("scale_x")) ++sum;
+    if (options.hasOption<double>("scale_y")) ++sum;
+    if (options.hasOption<double>("scale_z")) ++sum;
+    if (options.hasOption<double>("offset_x")) ++sum;
+    if (options.hasOption<double>("offset_y")) ++sum;
+    if (options.hasOption<double>("offset_z")) ++sum;
+    if (sum == 6)
+    {
+        m_customScaleOffset = true;
+    }
+    else if (sum == 0)
+    {
+        m_customScaleOffset = false;
+    }
+    else
+    {
+        throw pdal_error("not all 6 scaling factor options specified");
+    }
 
-ScalingFilter::ScalingFilter(const Stage& prevStage, const Options& options)
-    : pdal::Filter(prevStage, options)
-{
-    throw not_yet_implemented("options ctor"); 
+    m_scaleX = options.getValueOrDefault<double>("scale_x", 0.0);
+    m_scaleY = options.getValueOrDefault<double>("scale_y", 0.0);
+    m_scaleZ = options.getValueOrDefault<double>("scale_z", 0.0);
+    m_offsetX = options.getValueOrDefault<double>("offset_x", 0.0);
+    m_offsetY = options.getValueOrDefault<double>("offset_y", 0.0);
+    m_offsetZ = options.getValueOrDefault<double>("offset_z", 0.0);
+
+    checkImpedance();
+
+    initialize();
+
+    return;
 }
 
 
-ScalingFilter::ScalingFilter(const Stage& prevStage, bool forward)
+ScalingFilterBase::ScalingFilterBase(const Stage& prevStage, bool isDescaling)
     : Filter(prevStage, Options::none())
     , m_customScaleOffset(false)
     , m_scaleX(0.0)
@@ -65,7 +103,7 @@
     , m_offsetX(0.0)
     , m_offsetY(0.0)
     , m_offsetZ(0.0)
-    , m_forward(forward)
+    , m_isDescaling(isDescaling)
 {
     checkImpedance();
 
@@ -75,7 +113,7 @@
 }
 
 
-ScalingFilter::ScalingFilter(const Stage& prevStage, double scaleX, double offsetX, double scaleY, double offsetY, double scaleZ, double offsetZ, bool forward)
+ScalingFilterBase::ScalingFilterBase(const Stage& prevStage, bool isDescaling, double scaleX, double offsetX, double scaleY, double offsetY, double scaleZ, double offsetZ)
     : Filter(prevStage, Options::none())
     , m_customScaleOffset(true)
     , m_scaleX(scaleX)
@@ -84,7 +122,7 @@
     , m_offsetX(offsetX)
     , m_offsetY(offsetY)
     , m_offsetZ(offsetZ)
-    , m_forward(forward)
+    , m_isDescaling(isDescaling)
 {
     checkImpedance();
 
@@ -94,18 +132,11 @@
 }
 
 
-const Options& ScalingFilter::s_getDefaultOptions()
-{
-    static Options options;
-    return options;
-}
-
-
-void ScalingFilter::checkImpedance()
+void ScalingFilterBase::checkImpedance()
 {
     Schema& schema = this->getSchemaRef();
 
-    if (m_forward)
+    if (m_isDescaling)
     {
         // doubles --> ints
 
@@ -213,13 +244,13 @@
 }
 
 
-void ScalingFilter::initialize()
+void ScalingFilterBase::initialize()
 {
     return;
 }
 
 
-void ScalingFilter::processBuffer(const PointBuffer& srcData, PointBuffer& dstData) const
+void ScalingFilterBase::processBuffer(const PointBuffer& srcData, PointBuffer& dstData) const
 {
     const boost::uint32_t numPoints = srcData.getNumPoints();
 
@@ -230,8 +261,8 @@
     const Schema& dstSchema = dstSchemaLayout.getSchema();
 
     // rather than think about "src/dst", we will think in terms of "doubles" and "ints"


More information about the Liblas-commits mailing list