Ticket #127 (closed defect: fixed)

Opened 11 months ago

Last modified 11 months ago

Scan flags is order sensitive

Reported by: hobu Owned by: hobu
Priority: blocker Milestone: 1.2.1
Component: General Version: 1.2
Keywords: Cc:
LAS Format Version: Not Applicable

Description

From someone who wishes to remain anonymous:

The old code only worked it you set up the point in the following order:

- SetReturnNumber?()

- SetNumberOfReturns?()

- SetScanDirection?()

- SetFlightLineEdge?()

I found this because were calling in this order:

- SetNumberOfReturns?()

- SetReturnNumber?()

- SetScanDirection?()

- SetFlightLineEdge?()

Also I change the bit numbering to be Zero base to match the spec.

diff -r e3fa73a0a747 las-1.2/src/laspoint.cpp
--- a/src/las-1.2/src/laspoint.cpp    Thu Apr 09 11:41:59 2009
-0700
+++ b/src/las-1.2/src/laspoint.cpp    Thu Apr 09 12:42:05 2009
-0700
@@ -104,42 +104,34 @@

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)

Change History

Changed 11 months ago by hobu

  • status changed from new to closed
  • resolution set to fixed
  • milestone set to 1.2.1

Applied in r1200 and backported in r1201

Changed 11 months ago by mloskot

  • status changed from closed to reopened
  • resolution fixed deleted

Changed 11 months ago by mloskot

  • owner changed from mloskot to hobu
  • status changed from reopened to new

Changed 11 months ago by mloskot

  • status changed from new to closed
  • resolution set to fixed

Thanks for reporting and fixing this issue.

Note: See TracTickets for help on using tickets.