Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pointcloud2 display not accepting valid points #189

Merged
merged 1 commit into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ bool PointCloud2Display::hasXYZChannels(
int32_t yi = findChannelIndex(cloud, "y");
int32_t zi = findChannelIndex(cloud, "z");

return xi == -1 || yi == -1 || zi == -1;
return xi != -1 && yi != -1 && zi != -1;
}

bool PointCloud2Display::cloudDataMatchesDimensions(
const sensor_msgs::msg::PointCloud2::ConstSharedPtr cloud) const
{
return cloud->width * cloud->height * cloud->point_step != cloud->data.size();
return cloud->width * cloud->height * cloud->point_step == cloud->data.size();
}

sensor_msgs::msg::PointCloud2::ConstSharedPtr PointCloud2Display::filterOutInvalidPoints(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class PointCloud2Display : public
sensor_msgs::msg::PointCloud2::ConstSharedPtr filterOutInvalidPoints(
sensor_msgs::msg::PointCloud2::ConstSharedPtr cloud) const;

/// Move to public for testing
bool hasXYZChannels(sensor_msgs::msg::PointCloud2::ConstSharedPtr cloud) const;

/// Move to public for testing
bool cloudDataMatchesDimensions(sensor_msgs::msg::PointCloud2::ConstSharedPtr cloud) const;

protected:
/** @brief Do initialization. Overridden from RosTopicDisplay. */
void onInitialize() override;
Expand All @@ -97,16 +103,12 @@ class PointCloud2Display : public

std::unique_ptr<PointCloudCommon> point_cloud_common_;

bool cloudDataMatchesDimensions(sensor_msgs::msg::PointCloud2::ConstSharedPtr cloud) const;

sensor_msgs::msg::PointCloud2::_data_type
filterData(sensor_msgs::msg::PointCloud2::ConstSharedPtr cloud) const;

bool validateFloatsAtPosition(
sensor_msgs::msg::PointCloud2::_data_type::const_iterator position, Offsets offsets) const;

bool hasXYZChannels(sensor_msgs::msg::PointCloud2::ConstSharedPtr cloud) const;

Offsets determineOffsets(sensor_msgs::msg::PointCloud2::ConstSharedPtr cloud) const;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ TEST(PointCloud2Display, filter_keeps_valid_points) {
ASSERT_EQ(buffer[5], 6);
}

TEST(PointCloud2Display, hasXYZChannels_returns_true_for_valid_pointcloud) {
// just plain Point is ambiguous on macOS
rviz_default_plugins::Point p1 = {1, 2, 3};
rviz_default_plugins::Point p2 = {1, NAN, 3};
auto cloud = createPointCloud2WithPoints(std::vector<rviz_default_plugins::Point>{p1, p2});

PointCloud2Display display;
bool has_xyz = display.hasXYZChannels(cloud);

ASSERT_TRUE(has_xyz);
}

TEST(PointCloud2Display, cloudDataMatchesDimensions_returns_true_for_valid_pointcloud) {
// just plain Point is ambiguous on macOS
rviz_default_plugins::Point p1 = {1, 2, 3};
rviz_default_plugins::Point p2 = {1, NAN, 3};
auto cloud = createPointCloud2WithPoints(std::vector<rviz_default_plugins::Point>{p1, p2});

PointCloud2Display display;
bool matches_dimensions = display.cloudDataMatchesDimensions(cloud);

ASSERT_TRUE(matches_dimensions);
}

TEST(PointCloud2Display, filter_removes_invalid_point) {
// just plain Point is ambiguous on macOS
rviz_default_plugins::Point p1 = {1, 2, 3};
Expand Down