[Liblas-commits] hg-main-tree: rename Dimension::getNumericValue to applyScaling, ...

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Apr 12 15:48:30 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/c9eac97b063a
changeset: 541:c9eac97b063a
user:      Howard Butler <hobu.inc at gmail.com>
date:      Tue Apr 12 14:23:47 2011 -0500
description:
rename Dimension::getNumericValue to applyScaling, add a removeScaling method, and add an Undefined DataType
Subject: hg-main-tree: use applyScaling method that was renamed

details:   http://hg.libpc.orghg-main-tree/rev/169686855d1b
changeset: 542:169686855d1b
user:      Howard Butler <hobu.inc at gmail.com>
date:      Tue Apr 12 14:24:44 2011 -0500
description:
use applyScaling method that was renamed
Subject: hg-main-tree: add dimension_not_found exception

details:   http://hg.libpc.orghg-main-tree/rev/e67c3ddc6fb3
changeset: 543:e67c3ddc6fb3
user:      Howard Butler <hobu.inc at gmail.com>
date:      Tue Apr 12 14:26:01 2011 -0500
description:
add dimension_not_found exception
Subject: hg-main-tree: throw dimension_not_found error when it doesn't match up

details:   http://hg.libpc.orghg-main-tree/rev/4aad21b6c815
changeset: 544:4aad21b6c815
user:      Howard Butler <hobu.inc at gmail.com>
date:      Tue Apr 12 14:30:09 2011 -0500
description:
throw dimension_not_found error when it doesn't match up
Subject: hg-main-tree: rename getNumericValue

details:   http://hg.libpc.orghg-main-tree/rev/72d80c69e12e
changeset: 545:72d80c69e12e
user:      Howard Butler <hobu.inc at gmail.com>
date:      Tue Apr 12 14:30:30 2011 -0500
description:
rename getNumericValue

diffstat:

 csharp/libpc_swig_cpp/libpc.i  |   4 ++--
 include/libpc/Dimension.hpp    |  19 +++++++++++++++----
 include/libpc/exceptions.hpp   |  10 ++++++++++
 src/Dimension.cpp              |  12 ++++++++++++
 src/Schema.cpp                 |   2 +-
 test/unit/LiblasReaderTest.cpp |   6 +++---
 6 files changed, 43 insertions(+), 10 deletions(-)

diffs (172 lines):

diff -r 2ec6ae0b42f6 -r 72d80c69e12e csharp/libpc_swig_cpp/libpc.i
--- a/csharp/libpc_swig_cpp/libpc.i	Tue Apr 12 11:41:18 2011 -0500
+++ b/csharp/libpc_swig_cpp/libpc.i	Tue Apr 12 14:30:30 2011 -0500
@@ -280,7 +280,7 @@
     inline void setNumericOffset(double v);
 
     template<class T>
-    double getNumericValue(T x) const;
+    double applyScaling(T x) const;
 
     inline bool isFinitePrecision() const;
     inline void isFinitePrecision(bool v);
@@ -288,7 +288,7 @@
 
 %extend Dimension
 {
-    %template(getNumericValue_Int32) getNumericValue<boost::int32_t>;
+    %template(getNumericValue_Int32) applyScaling<boost::int32_t>;
 };
 
 
diff -r 2ec6ae0b42f6 -r 72d80c69e12e include/libpc/Dimension.hpp
--- a/include/libpc/Dimension.hpp	Tue Apr 12 11:41:18 2011 -0500
+++ b/include/libpc/Dimension.hpp	Tue Apr 12 14:30:30 2011 -0500
@@ -43,7 +43,7 @@
 #define LIBPC_DIMENSION_HPP_INCLUDED
 
 #include <libpc/libpc.hpp>
-
+#include <libpc/Utils.hpp>
 #include <boost/property_tree/ptree.hpp>
 
 
@@ -103,6 +103,8 @@
         Field_LAST = 1023
     };
 
+    // Do not explicitly specify these enum values because they 
+    // are (probably wrongly) used to iterate through for Schema::getX, Schema::getY, Schema::getZ
     enum DataType
     {
         Int8,
@@ -114,7 +116,8 @@
         Int64,
         Uint64,
         Float,       // 32 bits
-        Double       // 64 bits
+        Double,       // 64 bits
+        Undefined
     };
 
 public:
@@ -228,11 +231,19 @@
     }
 
     template<class T>
-    double getNumericValue(T x) const
+    double applyScaling(T v) const
     {
-        return (double)x * m_numericScale + m_numericOffset;
+        return (double)v * m_numericScale + m_numericOffset;
     }
 
+    template<class T>
+    T removeScaling(double v) const
+    {
+        T output = static_cast<T>(Utils::sround((v - m_numericOffset)/ m_numericScale));
+        return output;
+    }
+
+    
     /// If true, this dimension uses the numeric scale/offset values
     inline bool isFinitePrecision() const
     {
diff -r 2ec6ae0b42f6 -r 72d80c69e12e include/libpc/exceptions.hpp
--- a/include/libpc/exceptions.hpp	Tue Apr 12 11:41:18 2011 -0500
+++ b/include/libpc/exceptions.hpp	Tue Apr 12 14:30:30 2011 -0500
@@ -130,6 +130,16 @@
     {}
 };
 
+class dimension_not_found : public libpc_error
+{
+public:
+
+    dimension_not_found(std::string const& msg)
+        : libpc_error(msg)
+    {}
+};
+
+
 // use this for code still under development
 class not_yet_implemented : public libpc_error
 {
diff -r 2ec6ae0b42f6 -r 72d80c69e12e src/Dimension.cpp
--- a/src/Dimension.cpp	Tue Apr 12 11:41:18 2011 -0500
+++ b/src/Dimension.cpp	Tue Apr 12 14:30:30 2011 -0500
@@ -199,6 +199,8 @@
         return "Float";
     case Double:
         return "Double";
+    case Undefined:
+        return "Undefined";
     }
     throw;
 }
@@ -228,6 +230,8 @@
         return 4;
     case Double:
         return 8;
+    case Undefined:
+        throw;
     }
     throw;
 }
@@ -249,6 +253,8 @@
     case Float:
     case Double:
         return true;
+    case Undefined:
+        throw;
     }
     throw;
 }
@@ -271,6 +277,9 @@
     case Float:
     case Double:
         return true;
+    case Undefined:
+        throw;
+        
     }
     throw;
 }
@@ -293,6 +302,9 @@
     case Float:
     case Double:
         return false;
+    case Undefined:
+        throw;
+
     }
     throw;
 }
diff -r 2ec6ae0b42f6 -r 72d80c69e12e src/Schema.cpp
--- a/src/Schema.cpp	Tue Apr 12 11:41:18 2011 -0500
+++ b/src/Schema.cpp	Tue Apr 12 14:30:30 2011 -0500
@@ -175,7 +175,7 @@
     // assert(dim.getDataType() == datatype);
     if (dim.getDataType() != datatype)
     {
-        throw libpc_error("Requested dimension field present, but with different datatype");
+        throw dimension_not_found("Requested dimension field present, but with different datatype");
     }
     
     return index;
diff -r 2ec6ae0b42f6 -r 72d80c69e12e test/unit/LiblasReaderTest.cpp
--- a/test/unit/LiblasReaderTest.cpp	Tue Apr 12 11:41:18 2011 -0500
+++ b/test/unit/LiblasReaderTest.cpp	Tue Apr 12 14:30:30 2011 -0500
@@ -64,9 +64,9 @@
     boost::int32_t x0raw = data.getField<boost::int32_t>(index, offsetX);
     boost::int32_t y0raw = data.getField<boost::int32_t>(index, offsetY);
     boost::int32_t z0raw = data.getField<boost::int32_t>(index, offsetZ);
-    double x0 = schema.getDimension(offsetX).getNumericValue<boost::int32_t>(x0raw);
-    double y0 = schema.getDimension(offsetY).getNumericValue<boost::int32_t>(y0raw);
-    double z0 = schema.getDimension(offsetZ).getNumericValue<boost::int32_t>(z0raw);
+    double x0 = schema.getDimension(offsetX).applyScaling<boost::int32_t>(x0raw);
+    double y0 = schema.getDimension(offsetY).applyScaling<boost::int32_t>(y0raw);
+    double z0 = schema.getDimension(offsetZ).applyScaling<boost::int32_t>(z0raw);
     
     Compare(x0, xref);
     Compare(y0, yref);


More information about the Liblas-commits mailing list