Skip to content

Reintroduce pointcloud render without Float_V message (backport #755)#759

Open
mergify[bot] wants to merge 1 commit intoign-gui6from
mergify/bp/ign-gui6/pr-755
Open

Reintroduce pointcloud render without Float_V message (backport #755)#759
mergify[bot] wants to merge 1 commit intoign-gui6from
mergify/bp/ign-gui6/pr-755

Conversation

@mergify
Copy link
Copy Markdown

@mergify mergify bot commented Mar 18, 2026

🦟 Bug fix

This bug

Summary

Re-introduce point cloud rendering without the Float_V message.

Screenshot From 2026-03-17 11-49-46

I tested it with the following program:

#include <iostream>
#include <cmath>
#include <thread>
#include <chrono>
#include <gz/msgs/pointcloud_packed.pb.h>
#include <gz/msgs/PointCloudPackedUtils.hh>
#include <gz/transport/Node.hh>

int main(int argc, char** argv)
{
  // Create a transport node.
  gz::transport::Node node;

  // Define the topic to publish on.
  std::string topic = "/sphere_points";

  // Create a publisher for PointCloudPacked messages.
  auto pub = node.Advertise<gz::msgs::PointCloudPacked>(topic);

  if (!pub)
  {
    std::cerr << "Error advertising topic [" << topic << "]" << std::endl;
    return -1;
  }

  // Sphere parameters
  double radius = 1.0;
  int num_theta = 20;
  int num_phi = 40;

  // Prepare the message
  gz::msgs::PointCloudPacked msg;
  // Initialize header
  msg.mutable_header()->mutable_stamp()->set_sec(0);
  msg.mutable_header()->mutable_stamp()->set_nsec(0);

  // Initialize PointCloudPacked
  gz::msgs::InitPointCloudPacked(msg, "frame_id", false,
      {{"xyz", gz::msgs::PointCloudPacked::Field::FLOAT32}});

  int num_points = (num_theta + 1) * num_phi;
  msg.set_width(num_points);
  msg.set_height(1);
  msg.set_is_dense(true);
  msg.mutable_data()->resize(num_points * msg.point_step());

  gz::msgs::PointCloudPackedIterator<float> iterX(msg, "x");
  gz::msgs::PointCloudPackedIterator<float> iterY(msg, "y");
  gz::msgs::PointCloudPackedIterator<float> iterZ(msg, "z");

  const double PI = std::acos(-1.0);

  for (int i = 0; i <= num_theta; ++i)
  {
    double theta = PI * i / num_theta;
    for (int j = 0; j < num_phi; ++j)
    {
      double phi = 2.0 * PI * j / num_phi;

      double x = radius * std::sin(theta) * std::cos(phi);
      double y = radius * std::sin(theta) * std::sin(phi);
      double z = radius * std::cos(theta);

      *iterX = static_cast<float>(x);
      *iterY = static_cast<float>(y);
      *iterZ = static_cast<float>(z);
      ++iterX;
      ++iterY;
      ++iterZ;
    }
  }

  std::cout << "Publishing a sphere with " << num_points
            << " points on topic [" << topic << "]" << std::endl;

  // Publish the message in a loop
  while (true)
  {
    if (!pub.Publish(msg))
    {
        std::cerr << "Failed to publish message" << std::endl;
    }
    std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  }

  return 0;
}

TODO: Color support: I think we should not implement the color rendering support here, rather perhaps we should have some PointCloud representation in gz-math. For now there is rudimentary support for colors in this PR.

Checklist

  • Signed all commits for DCO
  • Added a screen capture or video to the PR description that demonstrates the fix (as needed)
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • Updated Bazel files (if adding new files). Created an issue otherwise.
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers
  • Was GenAI used to generate this PR? If so, make sure to add "Generated-by" to your commits. (See this policy for more info.)

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by and Generated-by messages.

Backports: If this is a backport, please use Rebase and Merge instead.


This is an automatic backport of pull request #755 done by [Mergify](https://mergify.com).

 🦟 Bug fix

[This bug](#494 (comment))

## Summary
Re-introduce point cloud rendering without the Float_V message.

<img width="1198" height="996" alt="Screenshot From 2026-03-17 11-49-46" src="https://github.com/user-attachments/assets/fe538b5b-d93a-429b-9900-3b13345dece1" />

I tested it with the following program:
```C++
#include <iostream>
#include <cmath>
#include <thread>
#include <chrono>
#include <gz/msgs/pointcloud_packed.pb.h>
#include <gz/msgs/PointCloudPackedUtils.hh>
#include <gz/transport/Node.hh>

int main(int argc, char** argv)
{
  // Create a transport node.
  gz::transport::Node node;

  // Define the topic to publish on.
  std::string topic = "/sphere_points";

  // Create a publisher for PointCloudPacked messages.
  auto pub = node.Advertise<gz::msgs::PointCloudPacked>(topic);

  if (!pub)
  {
    std::cerr << "Error advertising topic [" << topic << "]" << std::endl;
    return -1;
  }

  // Sphere parameters
  double radius = 1.0;
  int num_theta = 20;
  int num_phi = 40;

  // Prepare the message
  gz::msgs::PointCloudPacked msg;
  // Initialize header
  msg.mutable_header()->mutable_stamp()->set_sec(0);
  msg.mutable_header()->mutable_stamp()->set_nsec(0);

  // Initialize PointCloudPacked
  gz::msgs::InitPointCloudPacked(msg, "frame_id", false,
      {{"xyz", gz::msgs::PointCloudPacked::Field::FLOAT32}});

  int num_points = (num_theta + 1) * num_phi;
  msg.set_width(num_points);
  msg.set_height(1);
  msg.set_is_dense(true);
  msg.mutable_data()->resize(num_points * msg.point_step());

  gz::msgs::PointCloudPackedIterator<float> iterX(msg, "x");
  gz::msgs::PointCloudPackedIterator<float> iterY(msg, "y");
  gz::msgs::PointCloudPackedIterator<float> iterZ(msg, "z");

  const double PI = std::acos(-1.0);

  for (int i = 0; i <= num_theta; ++i)
  {
    double theta = PI * i / num_theta;
    for (int j = 0; j < num_phi; ++j)
    {
      double phi = 2.0 * PI * j / num_phi;

      double x = radius * std::sin(theta) * std::cos(phi);
      double y = radius * std::sin(theta) * std::sin(phi);
      double z = radius * std::cos(theta);

      *iterX = static_cast<float>(x);
      *iterY = static_cast<float>(y);
      *iterZ = static_cast<float>(z);
      ++iterX;
      ++iterY;
      ++iterZ;
    }
  }

  std::cout << "Publishing a sphere with " << num_points
            << " points on topic [" << topic << "]" << std::endl;

  // Publish the message in a loop
  while (true)
  {
    if (!pub.Publish(msg))
    {
        std::cerr << "Failed to publish message" << std::endl;
    }
    std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  }

  return 0;
}

```

TODO: Color support: I think we should not implement the color rendering support here, rather perhaps we should have some PointCloud representation in `gz-math`. For now there is rudimentary support for colors in this PR.

---------

Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai>
Signed-off-by: Arjo Chakravarty <arjo129@gmail.com>
Co-authored-by: Ian Chen <ichen@openrobotics.org>
Co-authored-by: Ian Chen <iche@google.com>
(cherry picked from commit d8b6a54)

# Conflicts:
#	src/plugins/point_cloud/PointCloud.cc
@mergify mergify bot requested a review from jennuine as a code owner March 18, 2026 21:57
@mergify mergify bot added the conflicts label Mar 18, 2026
@mergify
Copy link
Copy Markdown
Author

mergify bot commented Mar 18, 2026

Cherry-pick of d8b6a54 has failed:

On branch mergify/bp/ign-gui6/pr-755
Your branch is up to date with 'origin/ign-gui6'.

You are currently cherry-picking commit d8b6a54.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   src/plugins/point_cloud/PointCloud.cc

no changes added to commit (use "git add" and/or "git commit -a")

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

2 participants