[Liblas-commits] libpc: byte -> boost::uint8_t

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Feb 11 17:33:29 EST 2011


details:   http://hg.liblas.orglibpc/rev/48289cfd0230
changeset: 44:48289cfd0230
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Feb 11 14:18:05 2011 -0800
description:
byte -> boost::uint8_t
Subject: libpc: moved color ramp function

details:   http://hg.liblas.orglibpc/rev/1e55d495b161
changeset: 45:1e55d495b161
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Feb 11 14:18:19 2011 -0800
description:
moved color ramp function
Subject: libpc: lint

details:   http://hg.liblas.orglibpc/rev/01e4cf67e293
changeset: 46:01e4cf67e293
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Feb 11 14:33:25 2011 -0800
description:
lint

diffstat:

 doc/notes/misc.txt            |  14 +++++----
 include/libpc/Color.hpp       |   3 ++
 include/libpc/ColorFilter.hpp |   6 ++--
 include/libpc/PointData.hpp   |  12 ++++----
 src/Color.cpp                 |  61 ++++++++++++++++++++++++++++++++++++++++++
 src/ColorFilter.cpp           |  62 ++++++------------------------------------
 src/PointData.cpp             |  20 ++++++------
 7 files changed, 100 insertions(+), 78 deletions(-)

diffs (truncated from 358 to 300 lines):

diff -r 0083f658832d -r 01e4cf67e293 doc/notes/misc.txt
--- a/doc/notes/misc.txt	Fri Feb 11 14:00:41 2011 -0800
+++ b/doc/notes/misc.txt	Fri Feb 11 14:33:25 2011 -0800
@@ -129,13 +129,15 @@
 
 * *layout/organization of source tree?* 
     
-    public headers in ./include
-    private headers alongside source files in src/
+    - public headers in ./include
+    
+    - private headers alongside source files in src/
 
 * *use of namespaces?* (copy boost)
 
-    libpc::
-    libpc::detail::
+    - libpc\::
+    
+    - libpc::detail\::
     
 
 libPC Position on (Non)conformance
@@ -161,8 +163,8 @@
 as a practical matter, doing so would significantly aid the market.  Such an
 option would never be the default behavior, however.
 
-*We should also have a guiding principle about files that are conformant but
-which lie, such as the extents in the header being wrong.  
+* We should also have a guiding principle about files that are conformant but
+  which lie, such as the extents in the header being wrong.  
 
 Specifically, is
 our default path to propagate the wrong info or to helpfully correct it on
diff -r 0083f658832d -r 01e4cf67e293 include/libpc/Color.hpp
--- a/include/libpc/Color.hpp	Fri Feb 11 14:00:41 2011 -0800
+++ b/include/libpc/Color.hpp	Fri Feb 11 14:33:25 2011 -0800
@@ -131,6 +131,9 @@
         return m_color[index];
     }
 
+    static void interpolateColor(double value, double minValue, double maxValue, double& red, double& green, double& blue);
+    void interpolateColor(double value, double minValue, double maxValue);
+
 private:
     typedef boost::array<value_type, 3> base_type;
     base_type m_color;
diff -r 0083f658832d -r 01e4cf67e293 include/libpc/ColorFilter.hpp
--- a/include/libpc/ColorFilter.hpp	Fri Feb 11 14:00:41 2011 -0800
+++ b/include/libpc/ColorFilter.hpp	Fri Feb 11 14:33:25 2011 -0800
@@ -35,6 +35,8 @@
 #ifndef INCLUDED_COLORFILTER_HPP
 #define INCLUDED_COLORFILTER_HPP
 
+#include <boost/cstdint.hpp>
+
 #include "libpc/export.hpp"
 #include "libpc/Filter.hpp"
 
@@ -46,14 +48,12 @@
 class LIBPC_DLL ColorFilter : public Filter
 {
 public:
-    typedef unsigned char byte; // BUG
-
     ColorFilter(Stage& prevStage);
 
     void readNextPoints(PointData&);
 
 private:
-    void getColor(float value, byte& red, byte& green, byte& blue);
+    void getColor(float value, boost::uint8_t& red, boost::uint8_t& green, boost::uint8_t& blue);
 
     ColorFilter& operator=(const ColorFilter&); // not implemented
     ColorFilter(const ColorFilter&); // not implemented
diff -r 0083f658832d -r 01e4cf67e293 include/libpc/PointData.hpp
--- a/include/libpc/PointData.hpp	Fri Feb 11 14:00:41 2011 -0800
+++ b/include/libpc/PointData.hpp	Fri Feb 11 14:33:25 2011 -0800
@@ -35,6 +35,8 @@
 #ifndef INCLUDED_POINTDATA_HPP
 #define INCLUDED_POINTDATA_HPP
 
+#include <boost/cstdint.hpp>
+
 #include "libpc/export.hpp"
 #include "libpc/PointLayout.hpp"
 
@@ -53,8 +55,6 @@
 class LIBPC_DLL PointData
 {
 public:
-    typedef unsigned char byte; // BUG
-
     // note that when we make a PointData object all the fields are initialized to inactive,
     // regardless of what the passed-in layout says -- this is because the field object
     // represents the state within the owning object, which in this case is a completely
@@ -74,12 +74,12 @@
     void setValid(int pointIndex, bool value=true);
 
     // accessors to a particular field of a particular point in this buffer
-    byte getField_U8(int pointIndex, int fieldIndex) const;
+    boost::uint8_t getField_U8(int pointIndex, int fieldIndex) const;
     float getField_F32(int pointIndex, int fieldIndex) const;
     double getField_F64(int pointIndex, int fieldIndex) const;
 
     // accessors to a particular field of a particular point in this buffer
-    void setField_U8(int pointIndex, int fieldIndex, byte value);
+    void setField_U8(int pointIndex, int fieldIndex, boost::uint8_t value);
     void setField_F32(int pointIndex, int fieldIndex, float value);
     void setField_F64(int pointIndex, int fieldIndex, double value);
 
@@ -101,13 +101,13 @@
 
 private:
     // access to the raw memory
-    byte* getData(int pointIndex) const;
+    boost::uint8_t* getData(int pointIndex) const;
 
     template<class T> T getField(int fieldIndex, int itemOffset) const;
     template<class T> void setField(int fieldIndex, int itemOffset, T value);
 
     PointLayout m_layout;
-    byte* m_data;
+    boost::uint8_t* m_data;
     int m_pointSize;
     int m_numPoints;
     std::vector<bool> m_isValid; // one bool for each point
diff -r 0083f658832d -r 01e4cf67e293 src/Color.cpp
--- a/src/Color.cpp	Fri Feb 11 14:00:41 2011 -0800
+++ b/src/Color.cpp	Fri Feb 11 14:33:25 2011 -0800
@@ -98,4 +98,65 @@
     throw std::invalid_argument("Color component value too large.  Each must be less than 65536");
 }
 
+
+// static function to impute a color from within a range
+void Color::interpolateColor(double value, double minValue, double maxValue, double& red, double& green, double& blue)
+{
+    // initialize to white
+    red = 1.0;
+    green = 1.0;
+    blue = 1.0;
+
+    if (value < minValue)
+    {
+        value = minValue;
+    }
+
+    if (value > maxValue)
+    {
+        value = maxValue;
+    }
+
+    double dv = maxValue - minValue;
+
+    if (value < (minValue + (0.25 * dv)))
+    {
+        red = 0;
+        green = 4 * (value - minValue) / dv;
+    }
+    else if (value < (minValue + (0.5 * dv)))
+    {
+        red = 0;
+        blue = 1 + (4 * (minValue + (0.25 * dv) - value) / dv);
+    }
+    else if (value < (minValue + (0.75 * dv)))
+    {
+        red = 4 * (value - minValue - (0.5 * dv)) / dv;
+        blue = 0;
+    }
+    else
+    {
+        green = 1 + (4 * (minValue + (0.75 * dv) - value) / dv);
+        blue = 0;
+    }
+
+    return;
+}
+
+
+// taken from SlimDXControl
+void Color::interpolateColor(double value, double minValue, double maxValue)
+{
+    double fred, fgreen, fblue;
+    interpolateColor(value, minValue, maxValue, fred, fblue, fgreen);
+
+    const double vmax = (std::numeric_limits<boost::uint16_t>::max());
+    SetRed((value_type)(fred * vmax));
+    SetGreen((value_type)(fgreen * vmax));
+    SetBlue((value_type)(fblue * vmax));
+
+    return;
+}
+
+
 } // namespace liblas
diff -r 0083f658832d -r 01e4cf67e293 src/ColorFilter.cpp
--- a/src/ColorFilter.cpp	Fri Feb 11 14:00:41 2011 -0800
+++ b/src/ColorFilter.cpp	Fri Feb 11 14:33:25 2011 -0800
@@ -33,6 +33,7 @@
 ****************************************************************************/
 
 #include <cassert>
+#include "libpc/Color.hpp"
 #include "libpc/ColorFilter.hpp"
 
 namespace libpc
@@ -70,7 +71,7 @@
     for (int pointIndex=0; pointIndex<numPoints; pointIndex++)
     {
         float z = data.getZ(pointIndex);
-        byte red, green, blue;
+        boost::uint8_t red, green, blue;
         getColor(z, red, green, blue);
 
         // now we store the 3 u8's in the point data...
@@ -83,62 +84,17 @@
     return;
 }
 
-
-static void SlimDX_GetColor(float value, float minValue, float maxValue, float& red, float& green, float& blue)
+void ColorFilter::getColor(float value, boost::uint8_t& red, boost::uint8_t& green, boost::uint8_t& blue)
 {
-    // initialize to white
-    red = 1.0;
-    green = 1.0;
-    blue = 1.0;
-
-    if (value < minValue)
-    {
-        value = minValue;
-    }
-
-    if (value > maxValue)
-    {
-        value = maxValue;
-    }
-
-    float dv = maxValue - minValue;
-
-    if (value < (minValue + (0.25 * dv)))
-    {
-        red = 0;
-        green = 4 * (value - minValue) / dv;
-    }
-    else if (value < (minValue + (0.5 * dv)))
-    {
-        red = 0;
-        blue = 1 + (4 * (minValue + (0.25f * dv) - value) / dv);
-    }
-    else if (value < (minValue + (0.75 * dv)))
-    {
-        red = 4 * (value - minValue - (0.5f * dv)) / dv;
-        blue = 0;
-    }
-    else
-    {
-        green = 1 + (4 * (minValue + (0.75f * dv) - value) / dv);
-        blue = 0;
-    }
-
-    return;
-}
-
-
-// taken from SlimDXControl
-void ColorFilter::getColor(float value, byte& red, byte& green, byte& blue)
-{
-    float fred, fgreen, fblue;
+    double fred, fgreen, fblue;
 
     const Range<double>& zrange = getHeader().getBounds().dims()[2];
-    SlimDX_GetColor(value, (float)zrange.minimum(), (float)zrange.maximum(), fred, fblue, fgreen);
+    Color::interpolateColor(value, zrange.minimum(), zrange.maximum(), fred, fblue, fgreen);
 
-    red = (byte)(fred * 255.0);
-    green = (byte)(fgreen * 255.0);
-    blue = (byte)(fblue * 255.0);
+    const double vmax = (std::numeric_limits<boost::uint8_t>::max());
+    red = (boost::uint8_t)(fred * vmax);
+    green = (boost::uint8_t)(fgreen * vmax);
+    blue = (boost::uint8_t)(fblue * vmax);
 
     return;
 }
diff -r 0083f658832d -r 01e4cf67e293 src/PointData.cpp
--- a/src/PointData.cpp	Fri Feb 11 14:00:41 2011 -0800
+++ b/src/PointData.cpp	Fri Feb 11 14:33:25 2011 -0800
@@ -52,7 +52,7 @@
     m_pointSize(0)
 {
     m_pointSize = m_layout.getSizeInBytes();
-    m_data = new byte[m_pointSize * m_numPoints];
+    m_data = new boost::uint8_t[m_pointSize * m_numPoints];
 
     // the points will all be set to invalid here
     m_isValid.resize(m_numPoints);
@@ -75,7 +75,7 @@
 }


More information about the Liblas-commits mailing list