How can I change RGB values of pcl::PointXYZRGBA?
Asked Answered
B

2

7

I have a point of the type pcl::PointXYZRGBA. How can I assign/change its rgb values?

For changing xyz coordinates, I can simply do point.x = some_value.

Bacteriostat answered 14/4, 2013 at 13:2 Comment(5)
The class Point does not seems to exist in the Pcl doc... I can only find pcl::PointXYZRGBA.Chaudoin
@Chaudoin : You are right. I am referring to an instance named 'point' of the class pcl::PointXYZRGBA .Bacteriostat
Can't you use getRGBEigen3i(), or point.r (and same for gand b) ?Chaudoin
@Chaudoin : with getRGBEigen3i(), I cannot replace them. About using point.r, I found a thread on pcl-users forum that said otherwise.Bacteriostat
i've replaced one of your tags, the correct one is point-cloud-libraryEisenstark
P
10

Or just use

point.r = 255;
point.b = 0;
point.g = 0;
point.a = 255;
Puggree answered 19/11, 2014 at 19:11 Comment(1)
This should be the corrected answer. Simple and clear.Billybillycock
D
4

You can use pcl::PointXYZRGB instead of pcl::PointXYZRGBA. I think they both do the same. And then to color a point red (255,0,0), you can do:

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

And the xyz-coordinates can then be assigned respectively:

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

EDIT: Or if you have to stick with pcl::PointXYZRGBA, you can do

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
Dysgenic answered 16/4, 2013 at 8:34 Comment(1)
Your second part is wrong - .rgba is a uint32_tHaughty

© 2022 - 2024 — McMap. All rights reserved.