Skip to content

Commit

Permalink
point_cloud: Ensure flag printing handles all fields
Browse files Browse the repository at this point in the history
  • Loading branch information
EricCousineau-TRI committed Feb 6, 2019
1 parent e3f6051 commit 098eeaa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion perception/point_cloud_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ std::ostream& join(std::ostream& os,
namespace pc_flags {

std::ostream& operator<<(std::ostream& os, const Fields& fields) {
DRAKE_DEMAND(internal::kMaxBitInUse == kRGBs);
std::vector<std::string> values;
if (fields.contains(pc_flags::kXYZs))
if (fields.contains(kXYZs))
values.push_back("kXYZs");
if (fields.contains(kNormals))
values.push_back("kNormals");
if (fields.contains(kRGBs))
values.push_back("kRGBs");
if (fields.has_descriptor()) {
values.push_back(fields.descriptor_type().name());
}
Expand Down
1 change: 1 addition & 0 deletions perception/point_cloud_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum BaseField : int {

namespace internal {

// N.B. Ensure this is the largest bit.
constexpr BaseField kMaxBitInUse = kRGBs;

} // namespace internal
Expand Down
6 changes: 6 additions & 0 deletions perception/test/point_cloud_flags_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ GTEST_TEST(PointCloudFlagsTest, Basic) {
os << (pcf::kXYZs | pcf::kDescriptorCurvature);
EXPECT_EQ("(kXYZs | kDescriptorCurvature)", os.str());
}
// Ensure it works for multiple types.
{
std::ostringstream os;
os << (pcf::kXYZs | pcf::kRGBs | pcf::kDescriptorCurvature);
EXPECT_EQ("(kXYZs | kRGBs | kDescriptorCurvature)", os.str());
}

// Check basics.
pcf::Fields lhs = pcf::kXYZs;
Expand Down

0 comments on commit 098eeaa

Please sign in to comment.