如何更改pcl::PointXYZRGBA的RGB值?

How can I change RGB values of pcl::PointXYZRGBA?

本文关键字:RGB PointXYZRGBA 何更改 pcl      更新时间:2023-10-16

我有一个类型为pcl::PointXYZRGBA的点。我如何分配/改变它的rgb值?

对于更改xyz坐标,我可以简单地执行point.x = some_value

或者直接使用

point.r = 255;
point.b = 0;
point.g = 0;
point.a = 255;

可以用pcl::PointXYZRGB代替pcl::PointXYZRGBA。我想它们都是一样的。然后将一个点涂成红色(255,0,0),你可以这样做:

pcl::PointXYZRGB point = pcl::PointXYZRGB(255, 0, 0);

然后分别分配xyz坐标:

point.x = x;
point.y = y;
point.z = z;

EDIT:或者如果你必须坚持使用pcl::PointXYZRGBA,你可以使用

pcl::PointXYZRGBA point;
uint8_t r = 255;
uint8_t g = 0;
uint8_t b = 0;
int32_t rgb = (r << 16) | (g << 8) | b; 
point.rgba = *(float *)(&rgb); // makes the point red