Commit d8b6a54
Reintroduce pointcloud render without Float_V message (#755)
🦟 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>1 parent 63203f5 commit d8b6a54
1 file changed
+109
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
96 | 98 | | |
97 | 99 | | |
98 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
99 | 106 | | |
100 | 107 | | |
101 | 108 | | |
| |||
182 | 189 | | |
183 | 190 | | |
184 | 191 | | |
| 192 | + | |
185 | 193 | | |
186 | 194 | | |
187 | 195 | | |
| |||
208 | 216 | | |
209 | 217 | | |
210 | 218 | | |
| 219 | + | |
211 | 220 | | |
212 | 221 | | |
213 | 222 | | |
| |||
411 | 420 | | |
412 | 421 | | |
413 | 422 | | |
414 | | - | |
415 | | - | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
416 | 452 | | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
438 | 524 | | |
439 | 525 | | |
440 | 526 | | |
| |||
0 commit comments