Skip to content

Commit

Permalink
Added Classification::GetFlags() method. Fixed bug in SetClasification (
Browse files Browse the repository at this point in the history
#1). Added more tests for setting Point with classification flags.
  • Loading branch information
mloskot committed Oct 26, 2011
1 parent f09aeb3 commit f34666e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
7 changes: 6 additions & 1 deletion include/liblas/classification.hpp
Expand Up @@ -141,11 +141,16 @@ class LAS_DLL Classification

/// Conversion operator.
/// Returns classification object as in form of std::bitset<8>.
/// bitset< object
operator bitset_type() const
{
return bitset_type(m_flags);
}

/// Named accessor converting Classification to std::bitset<8>.
bitset_type GetFlags() const
{
return bitset_type(m_flags);
}

/// Raturns name of class as defined in LAS 1.1+
/// Finds class name in lookup table based on class index
Expand Down
12 changes: 6 additions & 6 deletions src/point.cpp
Expand Up @@ -715,24 +715,24 @@ void Point::SetClassification(Classification const& cls)
{
// "Classification" is always the 9th dimension
// std::vector<boost::uint8_t>::size_type pos = GetDimensionBytePosition(8);
std::vector<boost::uint8_t>::size_type pos = 15;
m_data[pos] = cls.GetClass();
std::vector<boost::uint8_t>::size_type const pos = 15;
m_data[pos] = static_cast<boost::uint8_t>(cls.GetFlags().to_ulong());
}

void Point::SetClassification(Classification::bitset_type const& flags)
{
// "Classification" is always the 9th dimension
// std::vector<boost::uint8_t>::size_type pos = GetDimensionBytePosition(8);
std::vector<boost::uint8_t>::size_type pos = 15;
m_data[pos] = Classification(flags).GetClass();
std::vector<boost::uint8_t>::size_type const pos = 15;
m_data[pos] = static_cast<boost::uint8_t>(flags.to_ulong());
}

void Point::SetClassification(boost::uint8_t const& flags)
{
// "Classification" is always the 9th dimension
// std::vector<boost::uint8_t>::size_type pos = GetDimensionBytePosition(8);
std::vector<boost::uint8_t>::size_type pos = 15;
m_data[pos] = Classification(flags).GetClass();
std::vector<boost::uint8_t>::size_type const pos = 15;
m_data[pos] = flags;
}

void Point::SetScanAngleRank(int8_t const& rank)
Expand Down
28 changes: 25 additions & 3 deletions test/unit/point_test.cpp
Expand Up @@ -256,21 +256,43 @@ namespace tut
{
ensure_equals("invalid default classification",
m_default.GetClassification(), liblas::Classification::bitset_type());

liblas::Classification c;

boost::uint8_t const begclass = 0;
c.SetClass(begclass);

liblas::Classification c(begclass, false, true, false);
m_default.SetClassification(c);

ensure_equals("invalid class index",
m_default.GetClassification().GetClass(), begclass);
ensure_not("synthetic bit", m_default.GetClassification().IsSynthetic());
ensure("keypoint bit", m_default.GetClassification().IsKeyPoint());
ensure_not("withheld bit", m_default.GetClassification().IsWithheld());

{
// Not paranoid, just show how to manually inspect flags
std::ostringstream oss;
oss << m_default.GetClassification().GetFlags();
ensure_equals(oss.str(), "01000000");
}

boost::uint8_t const endclass = 31;
c.SetClass(endclass);
c.SetSynthetic(true);
c.SetKeyPoint(true);
c.SetWithheld(false);
m_default.SetClassification(c);
ensure_equals("invalid class index",
m_default.GetClassification().GetClass(), endclass);
ensure("synthetic bit", m_default.GetClassification().IsSynthetic());
ensure("keypoint bit", m_default.GetClassification().IsKeyPoint());
ensure_not("withheld bit", m_default.GetClassification().IsWithheld());

{
// Not paranoid, just show how to manually inspect flags
std::ostringstream oss;
oss << m_default.GetClassification().GetFlags();
ensure_equals(oss.str(), "01111111");
}
}

// Test Get/SetScanAngleRank
Expand Down

4 comments on commit f34666e

@hobu
Copy link
Member

@hobu hobu commented on f34666e Oct 27, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c.GetFlags(): 01000000

m_default.SetClassification(c);

m_default.GetClassifcation().GetFlags(): 00000000

@hobu
Copy link
Member

@hobu hobu commented on f34666e Oct 27, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't work can it?

    m_data[pos] = static_cast<boost::uint8_t>(cls.GetFlags().to_ulong());

to_ulong() == 32bits, but we only have 8 bits of space here.

@hobu
Copy link
Member

@hobu hobu commented on f34666e Oct 27, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't work can it?

    m_data[pos] = static_cast<boost::uint8_t>(cls.GetFlags().to_ulong());

to_ulong() == 32bits, but we only have 8 bits of space here.

@mloskot
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cast does the clamping, doesn't it?

static_cast<boost::uint8_t>

I have made a quick test https://gist.github.com/1320853

Please sign in to comment.