[Liblas-commits] hg: Point::SetPoint and GetPoint now use binary unrolled-loop ut...

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Oct 21 09:04:56 EDT 2010


changeset dcf89ead4b25 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=dcf89ead4b25
summary: Point::SetPoint and GetPoint now use binary unrolled-loop utils. Tests pass. To be tested on big-endian.

diffstat:

 src/laspoint.cpp |  94 +++++++++++++++----------------------------------------
 1 files changed, 26 insertions(+), 68 deletions(-)

diffs (199 lines):

diff -r 5a272a57945c -r dcf89ead4b25 src/laspoint.cpp
--- a/src/laspoint.cpp	Thu Oct 21 01:28:06 2010 +0100
+++ b/src/laspoint.cpp	Thu Oct 21 14:04:36 2010 +0100
@@ -43,6 +43,7 @@
 #include <liblas/lasheader.hpp>
 #include <liblas/lasschema.hpp>
 #include <liblas/exception.hpp>
+#include <liblas/detail/binary.hpp>
 #include <liblas/detail/pointrecord.hpp>
 // boost
 #include <boost/array.hpp>
@@ -95,7 +96,6 @@
     return *this;
 }
 
-
 void Point::SetCoordinates(double const& x, double const& y, double const& z)
 {
     SetX(x);
@@ -103,7 +103,6 @@
     SetZ(z);
 }
 
-
 bool Point::equal(Point const& other) const
 {
     // TODO - mloskot: Default epsilon is too small.
@@ -184,7 +183,6 @@
     if (this->GetReturnNumber() > 0x07)
         return false;
 
-
     return true;
 }
 
@@ -230,24 +228,17 @@
         SetUserData(p.GetUserData());
         SetPointSourceID(p.GetPointSourceID());
         
-        try {
+        try
+        {
             SetTime(p.GetTime());
-        } catch (std::runtime_error const&) 
-        {
-            
+            SetColor(p.GetColor());
+        }
+        catch (std::runtime_error const&)
+        {   
         }
 
-        try {
-            SetColor(p.GetColor());
-        } catch (std::runtime_error const&) 
-        {
-            
-        }
-        
         // FIXME: copy other custom dimensions here?  resetting the 
         // headerptr can be catastrophic in a lot of cases.  
-
-        
     }
     
     m_header = header;
@@ -722,14 +713,11 @@
     return output;
 }
 
-
 void Point::SetPointSourceID(boost::uint16_t const& id)
 {
     // "Point Source ID" is always the 12th dimension    
     std::vector<boost::uint8_t>::size_type pos = GetDimensionBytePosition(11);
-    liblas::detail::intToBits<boost::uint16_t>(id, 
-                                               m_data, 
-                                               pos);
+    liblas::detail::intToBits<boost::uint16_t>(id, m_data, pos);
 }
 
 void Point::SetTime(double const& t)
@@ -753,54 +741,40 @@
     }
     std::vector<boost::uint8_t>::size_type pos = GetDimensionBytePosition(index_pos);
 
-    const boost::uint8_t* x_b =  reinterpret_cast<const boost::uint8_t*>(&t);
-#if defined(LIBLAS_BIG_ENDIAN)
-        for (boost::int32_t n = sizeof( double )-1; n >= 0; n--)
-#else
-        for (boost::uint32_t n = 0; n < sizeof( double ); n++)
-#endif 
-            m_data[pos+n] = x_b[n];
-
+    detail::binary::endian_value<double> value(t);
+    value.store<detail::binary::little_endian_tag>(&m_data[0] + pos);
 }
 
 double Point::GetTime() const
 {
-    // "Time" is the 13th dimension if it exists
-    std::size_t index_pos = 12;
-
     PointFormatName f;
-    if (m_header) {
+    if (m_header)
+    {
         f = m_header->GetDataFormatId();
-    } else {
+    }
+    else
+    {
         f = m_default_header.GetDataFormatId();
     }   
     
-    if ( f == ePointFormat0 || f == ePointFormat2 ) {
+    if (f == ePointFormat0 || f == ePointFormat2)
+    {
         // std::ostringstream msg;
         // msg << "Point::GetTime - Unable to get time for ePointFormat0 or ePointFormat2, "
         //     << "no Time dimension exists on this format";
         // throw std::runtime_error(msg.str());
         return 0.0;
     }
+
+    // "Time" is the 13th dimension if it exists
+    std::size_t const index_pos = 12;
     std::vector<boost::uint8_t>::size_type pos = GetDimensionBytePosition(index_pos);
 
-
-    boost::uint8_t* data = new boost::uint8_t[8];
-    
-#if defined(LIBLAS_BIG_ENDIAN)
-        for (boost::uint32_t n = 0; n < sizeof( double ); n++)
-#else
-        for (boost::int32_t n = sizeof( double )-1; n >= 0; n--)
-#endif  
-            data[n] = m_data[pos+n];
-
-    const double* output = reinterpret_cast<const double*>(data);
-    double out = *output;
-    delete[] data;
-    return out;
+    detail::binary::endian_value<double> value;
+    value.load<detail::binary::little_endian_tag>(&m_data[0] + pos);
+    return value;
 }
 
-
 Color Point::GetColor() const
 {
     boost::uint16_t red(0);
@@ -868,23 +842,14 @@
     
     std::vector<boost::uint8_t>::size_type green_pos = GetDimensionBytePosition(index_pos + 1);
     std::vector<boost::uint8_t>::size_type blue_pos = GetDimensionBytePosition(index_pos + 2);
- 
-
     std::vector<boost::uint8_t>::size_type red_pos = GetDimensionBytePosition(index_pos);
     assert(red_pos + sizeof(Color::value_type) <= m_data.size());
+    
     intToBits<boost::uint16_t>(value.GetRed(), m_data, red_pos);
-    intToBits<boost::uint16_t>(value.GetGreen(), 
-                                               m_data, 
-                                               green_pos);
-    intToBits<boost::uint16_t>(value.GetBlue(), 
-                                               m_data, 
-                                               blue_pos);
+    intToBits<boost::uint16_t>(value.GetGreen(), m_data, green_pos);
+    intToBits<boost::uint16_t>(value.GetBlue(), m_data, blue_pos);
 }
 
-
-
-
-
 std::vector<boost::uint8_t>::size_type Point::GetDimensionBytePosition(std::size_t dim_pos) const
 {
     std::size_t output = 0;
@@ -898,19 +863,12 @@
     return output;
 }
 
-
-
-
-
 boost::any Point::GetValue(Dimension const& d) const
 {
-
     boost::any output;
 
- 
     
     return output;
 }
 
-
 } // namespace liblas


More information about the Liblas-commits mailing list