[Liblas-commits] hg: Defined Point::m_coords using boost::array. Tidy up.

liblas-commits at liblas.org liblas-commits at liblas.org
Sat Jul 31 21:02:34 EDT 2010


changeset c0853bafd094 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=c0853bafd094
summary: Defined Point::m_coords using boost::array. Tidy up.

diffstat:

 include/liblas/laspoint.hpp |  50 +++++++++++++--------------
 src/laspoint.cpp            |  79 ++++++++++++++++++++++----------------------
 2 files changed, 63 insertions(+), 66 deletions(-)

diffs (255 lines):

diff -r 45aefb0c99a3 -r c0853bafd094 include/liblas/laspoint.hpp
--- a/include/liblas/laspoint.hpp	Sat Jul 31 21:12:10 2010 +0100
+++ b/include/liblas/laspoint.hpp	Sun Aug 01 02:02:25 2010 +0100
@@ -47,6 +47,7 @@
 #include <liblas/detail/pointrecord.hpp>
 #include <liblas/detail/fwd.hpp>
 // boost
+#include <boost/array.hpp>
 #include <boost/cstdint.hpp>
 #include <boost/shared_ptr.hpp>
 // std
@@ -194,22 +195,18 @@
 
 private:
 
-    static std::size_t const coords_size = 3;
-
-    detail::PointRecord m_rec;
-    double m_coords[coords_size]; // FIXME: use boost::array
-    double m_gpsTime;
-    Color m_color;
-    Classification m_cls;
-    boost::uint16_t m_intensity;
-    boost::uint16_t m_pointSourceId;
-    boost::uint8_t m_flags;
-    boost::uint8_t m_userData;
-    boost::int8_t m_angleRank;
-
+    detail::PointRecord m_record;
     std::vector<boost::uint8_t> m_extra_data;
     std::vector<boost::uint8_t> m_format_data;
-    
+    boost::array<double, 3> m_coords;
+    Color m_color;
+    double m_gps_time;
+    boost::uint16_t m_intensity;
+    boost::uint16_t m_source_id;
+    boost::uint8_t m_flags;
+    boost::uint8_t m_user_data;
+    boost::int8_t m_angle_rank;
+    Classification m_class;
     HeaderPtr m_header;
 
     void throw_out_of_range() const;
@@ -310,32 +307,33 @@
 
 inline boost::int8_t Point::GetScanAngleRank() const
 {
-    return m_angleRank;
+    return m_angle_rank;
 }
 
 inline boost::uint8_t Point::GetUserData() const
 {
-    return m_userData;
+    return m_user_data;
 }
 
 inline boost::uint16_t Point::GetPointSourceID() const
 {
-    return m_pointSourceId;
+    return m_source_id;
 }
 
 inline void Point::SetPointSourceID(boost::uint16_t const& id)
 {
-    m_pointSourceId = id;
+    m_source_id = id;
 }
 
 inline double Point::GetTime() const
 {
-    return m_gpsTime;
+    return m_gps_time;
 }
 
 inline void Point::SetTime(double const& time)
 {
-    m_gpsTime = time;
+    assert(time >= 0); // TODO: throw? --mloskot
+    m_gps_time = time;
 }
 
 inline Color const& Point::GetColor() const
@@ -348,20 +346,20 @@
     m_color = value;
 }
 
-inline double& Point::operator[](std::size_t const& n)
+inline double& Point::operator[](std::size_t const& index)
 {
-    if (coords_size <= n)
+    if (index > m_coords.size() - 1)
         throw_out_of_range();
 
-    return m_coords[n];
+    return m_coords[index];
 }
 
-inline double const& Point::operator[](std::size_t const& n) const
+inline double const& Point::operator[](std::size_t const& index) const
 {
-    if (coords_size <= n)
+    if (index > m_coords.size() - 1)
         throw_out_of_range();
 
-    return m_coords[n];
+    return m_coords[index];
 }
 
 } // namespace liblas
diff -r 45aefb0c99a3 -r c0853bafd094 src/laspoint.cpp
--- a/src/laspoint.cpp	Sat Jul 31 21:12:10 2010 +0100
+++ b/src/laspoint.cpp	Sun Aug 01 02:02:25 2010 +0100
@@ -44,6 +44,7 @@
 #include <liblas/exception.hpp>
 #include <liblas/detail/pointrecord.hpp>
 // boost
+#include <boost/array.hpp>
 #include <boost/cstdint.hpp>
 // std
 #include <cstring>
@@ -54,51 +55,49 @@
 namespace liblas {
 
 Point::Point()
-    : m_gpsTime(0)
+    : m_extra_data(0)
+    , m_format_data(0)
+    , m_gps_time(0)
     , m_intensity(0)
-    , m_pointSourceId(0)
+    , m_source_id(0)
     , m_flags(0)
-    , m_userData(0)
-    , m_angleRank(0)
+    , m_user_data(0)
+    , m_angle_rank(0)
 {
-    std::memset(m_coords, 0, sizeof(m_coords));
-    m_extra_data.resize(0);
-    m_format_data.resize(0);
+    m_coords.assign(0);
 }
 
-Point::Point(Point const& other) :
-    m_gpsTime(other.m_gpsTime),
-    m_color(other.m_color),
-    m_cls(other.m_cls),
-    m_intensity(other.m_intensity),
-    m_pointSourceId(other.m_pointSourceId),
-    m_flags(other.m_flags),
-    m_userData(other.m_userData),
-    m_angleRank(other.m_angleRank),
-    m_header(other.m_header)
+Point::Point(Point const& other)
+    : m_extra_data(other.m_extra_data)
+    , m_format_data(other.m_format_data)
+    , m_coords(other.m_coords)
+    , m_color(other.m_color)
+    , m_gps_time(other.m_gps_time)
+    , m_intensity(other.m_intensity)
+    , m_source_id(other.m_source_id)
+    , m_flags(other.m_flags)
+    , m_user_data(other.m_user_data)
+    , m_angle_rank(other.m_angle_rank)
+    , m_class(other.m_class)
+    , m_header(other.m_header)
 {
-    std::memcpy(m_coords, other.m_coords, sizeof(m_coords));
-    std::vector<uint8_t>(other.m_extra_data).swap(m_extra_data);
-    std::vector<uint8_t>(other.m_format_data).swap(m_format_data);
 }
 
 Point& Point::operator=(Point const& rhs)
 {
     if (&rhs != this)
     {
-        m_coords[0] = rhs.m_coords[0];
-        m_coords[1] = rhs.m_coords[1];
-        m_coords[2] = rhs.m_coords[2];
+        m_extra_data = rhs.m_extra_data;
+        m_format_data = rhs.m_format_data;
+        m_coords = rhs.m_coords;
+        m_color = rhs.m_color;
+        m_gps_time = rhs.m_gps_time;
+        m_class = rhs.m_class;
         m_intensity = rhs.m_intensity;
+        m_source_id = rhs.m_source_id;
         m_flags = rhs.m_flags;
-        m_cls = rhs.m_cls;
-        m_angleRank = rhs.m_angleRank;
-        m_userData = rhs.m_userData;
-        m_pointSourceId = rhs.m_pointSourceId;
-        m_gpsTime = rhs.m_gpsTime;
-        m_color = rhs.m_color;
-        std::vector<uint8_t>(rhs.m_extra_data).swap(m_extra_data);
-        std::vector<uint8_t>(rhs.m_format_data).swap(m_format_data);
+        m_user_data = rhs.m_user_data;
+        m_angle_rank = rhs.m_angle_rank;
         m_header = rhs.m_header;
     }
     return *this;
@@ -161,32 +160,32 @@
 
 void Point::SetScanAngleRank(int8_t const& rank)
 {
-    m_angleRank = rank;
+    m_angle_rank = rank;
 }
 
 void Point::SetUserData(uint8_t const& data)
 {
-    m_userData = data;
+    m_user_data = data;
 }
 
 Classification const& Point::GetClassification() const
 {
-    return m_cls;
+    return m_class;
 }
 
 void Point::SetClassification(Classification const& cls)
 {
-    m_cls = cls;
+    m_class = cls;
 }
 
 void Point::SetClassification(Classification::bitset_type const& flags)
 {
-    m_cls = Classification(flags);
+    m_class = Classification(flags);
 }
 
 void Point::SetClassification(boost::uint8_t const& flags)
 {
-    m_cls = Classification(flags);
+    m_class = Classification(flags);
 }
 
 bool Point::equal(Point const& other) const
@@ -202,9 +201,9 @@
 
     // TODO: Should we compare other data members, besides the coordinates?
 
-    if (((dx <= epsilon) && (dx >= -epsilon))
-        && ((dy <= epsilon) && (dy >= -epsilon))
-        && ((dz <= epsilon) && (dz >= -epsilon)))
+    if ((dx <= epsilon && dx >= -epsilon)
+     && (dy <= epsilon && dy >= -epsilon)
+     && (dz <= epsilon && dz >= -epsilon))
     {
         return true;
     }


More information about the Liblas-commits mailing list