[Liblas-commits] r1201 - branches/1.2/src

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Apr 10 13:16:00 EDT 2009


Author: hobu
Date: Fri Apr 10 13:16:00 2009
New Revision: 1201
URL: http://liblas.org/changeset/1201

Log:
Fix #127, scan flag order sensitivity.  All tests pass backport of r1200

Modified:
   branches/1.2/src/laspoint.cpp

Modified: branches/1.2/src/laspoint.cpp
==============================================================================
--- branches/1.2/src/laspoint.cpp	(original)
+++ branches/1.2/src/laspoint.cpp	Fri Apr 10 13:16:00 2009
@@ -104,43 +104,35 @@
 
 void LASPoint::SetReturnNumber(uint16_t const& num)
 {
-    // Store value in bits 1,2,3
-    uint8_t val = static_cast<uint8_t>(num);
-    uint16_t const begin = 1;
-    uint8_t mask = uint8_t(~0);
-    m_flags &= ~(mask << (begin - 1)); 
-    m_flags |= ((val & mask) << (begin - 1));
+    // Store value in bits 0,1,2
+    uint8_t mask = 0x7 << 0; // 0b00000111
+    m_flags &= ~mask;
+    m_flags |= mask & (static_cast<uint8_t>(num) << 0);
+
 }
 
 void LASPoint::SetNumberOfReturns(uint16_t const& num)
 {
-    // Store value in bits 4,5,6
-    uint8_t val = static_cast<uint8_t>(num);
-    uint16_t const begin = 4;
-    uint8_t mask = uint8_t(~0);
-    m_flags &= ~(mask << (begin - 1)); 
-    m_flags |= ((val & mask) << (begin - 1));
+    // Store value in bits 3,4,5
+    uint8_t mask = 0x7 << 3; // 0b00111000
+    m_flags &= ~mask;
+    m_flags |= mask & (static_cast<uint8_t>(num) << 3);
 }
 
 void LASPoint::SetScanDirection(uint16_t const& dir)
 {
-    // Store value in bit 7th
-    uint8_t val = static_cast<uint8_t>(dir);
-    uint16_t const begin = 7;
-    uint8_t mask = uint8_t(~0);
-    m_flags &= ~(mask << (begin - 1)); 
-    m_flags |= ((val & mask) << (begin - 1));
+    // Store value in bit 6
+    uint8_t mask = 0x1 << 6; // 0b01000000
+    m_flags &= ~mask;
+    m_flags |= mask & (static_cast<uint8_t>(dir) << 6);
 }
 
 void LASPoint::SetFlightLineEdge(uint16_t const& edge)
 {
-    // Store value in bit 8th
-    uint8_t val = static_cast<uint8_t>(edge);
-    uint16_t const begin = 8;
-    uint8_t mask = uint8_t(~0);
-    m_flags &= ~(mask << (begin - 1)); 
-    m_flags |= ((val & mask) << (begin - 1));
-}
+    // Store value in bit 7
+    uint8_t mask = 0x1 << 7; // 0b10000000
+    m_flags &= ~mask;
+    m_flags |= mask & (static_cast<uint8_t>(edge) << 7);}
 
 void LASPoint::SetScanAngleRank(int8_t const& rank)
 {


More information about the Liblas-commits mailing list