Skip to content

Reintroduce pointcloud render without Float_V message#755

Merged
arjo129 merged 8 commits intomainfrom
arjo/fix/reintroduce_pointcloud_render
Mar 18, 2026
Merged

Reintroduce pointcloud render without Float_V message#755
arjo129 merged 8 commits intomainfrom
arjo/fix/reintroduce_pointcloud_render

Conversation

@arjo129
Copy link
Copy Markdown
Contributor

@arjo129 arjo129 commented Mar 17, 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.

arjo129 added 3 commits March 4, 2026 09:34
Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai>
…issing

Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai>
arjo129 added 3 commits March 17, 2026 03:31
Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai>
Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai>
Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai>
@arjo129 arjo129 changed the title Arjo/fix/reintroduce pointcloud render Reintroduce pointcloud render without Float_V message Mar 17, 2026
Comment thread src/plugins/point_cloud/PointCloud.cc Outdated
Comment thread src/plugins/point_cloud/PointCloud.cc Outdated
Comment thread src/plugins/point_cloud/PointCloud.cc Outdated
Comment thread src/plugins/point_cloud/PointCloud.cc Outdated
Comment thread src/plugins/point_cloud/PointCloud.cc Outdated
Comment thread src/plugins/point_cloud/PointCloud.cc Outdated
arjo129 and others added 2 commits March 18, 2026 03:15
Co-authored-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Arjo Chakravarty <arjo129@gmail.com>
Co-authored-by: Ian Chen <iche@google.com>
Signed-off-by: Arjo Chakravarty <arjo129@gmail.com>
@arjo129 arjo129 requested a review from iche033 March 18, 2026 02:15
@github-project-automation github-project-automation bot moved this from Inbox to In review in Core development Mar 18, 2026
@arjo129 arjo129 merged commit d8b6a54 into main Mar 18, 2026
8 checks passed
@arjo129 arjo129 deleted the arjo/fix/reintroduce_pointcloud_render branch March 18, 2026 20:16
@github-project-automation github-project-automation bot moved this from In review to Done in Core development Mar 18, 2026
@arjo129
Copy link
Copy Markdown
Contributor Author

arjo129 commented Mar 18, 2026

@Mergifyio backport gz-sim10 gz-sim9 gz-sim8 ign-gazebo6

@mergify
Copy link
Copy Markdown

mergify bot commented Mar 18, 2026

backport gz-sim10 gz-sim9 gz-sim8 ign-gazebo6

❌ No backport have been created

Details
  • Backport to branch gz-sim10 failed

GitHub error: Branch not found

  • Backport to branch gz-sim9 failed

GitHub error: Branch not found

  • Backport to branch gz-sim8 failed

GitHub error: Branch not found

  • Backport to branch ign-gazebo6 failed

GitHub error: Branch not found

@azeey
Copy link
Copy Markdown
Contributor

azeey commented Mar 18, 2026

https://github.com/Mergifyio backport gz-sim10 gz-sim9 gz-sim8 ign-gazebo6

@mergify
Copy link
Copy Markdown

mergify bot commented Mar 18, 2026

backport gz-sim10 gz-sim9 gz-sim8 ign-gazebo6

❌ No backport have been created

Details
  • Backport to branch gz-sim10 failed

GitHub error: Branch not found

  • Backport to branch gz-sim9 failed

GitHub error: Branch not found

  • Backport to branch gz-sim8 failed

GitHub error: Branch not found

  • Backport to branch ign-gazebo6 failed

GitHub error: Branch not found

@azeey
Copy link
Copy Markdown
Contributor

azeey commented Mar 18, 2026

@Mergifyio backport gz-gui10 gz-gui8 gz-gui9 ign-gui6

@arjo129 oops, I did the same thing you did thinking it was a github outage. Btw, check out https://gazebosim.org/docs/latest/maintainers/#backporting for quickly generating the mergifyio command for a given PR.

@mergify
Copy link
Copy Markdown

mergify bot commented Mar 18, 2026

backport gz-gui10 gz-gui8 gz-gui9 ign-gui6

✅ Backports have been created

Details

Cherry-pick of d8b6a54 has failed:

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

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 <file>..." to mark resolution)
	both modified:   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

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

mergify bot pushed a commit that referenced this pull request Mar 18, 2026
 🦟 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)
mergify bot pushed a commit that referenced this pull request Mar 18, 2026
 🦟 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 bot pushed a commit that referenced this pull request Mar 18, 2026
 🦟 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)
mergify bot pushed a commit that referenced this pull request Mar 18, 2026
 🦟 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
arjo129 added a commit that referenced this pull request Mar 19, 2026
🦟 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.

---------





(cherry picked from commit d8b6a54)

Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai>
Signed-off-by: Arjo Chakravarty <arjo129@gmail.com>
Co-authored-by: Arjo Chakravarty <arjoc@intrinsic.ai>
Co-authored-by: Ian Chen <ichen@openrobotics.org>
Co-authored-by: Ian Chen <iche@google.com>
arjo129 added a commit that referenced this pull request Mar 19, 2026
🦟 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.

---------





(cherry picked from commit d8b6a54)

Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai>
Signed-off-by: Arjo Chakravarty <arjo129@gmail.com>
Co-authored-by: Arjo Chakravarty <arjoc@intrinsic.ai>
Co-authored-by: Ian Chen <ichen@openrobotics.org>
Co-authored-by: Ian Chen <iche@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants