-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suppress strict alias warning #2072
Suppress strict alias warning #2072
Conversation
@@ -231,7 +231,7 @@ main (int argc, char ** argv) | |||
} | |||
|
|||
uint32_t rgb = static_cast<uint32_t>(color_pixel[0]) << 16 | static_cast<uint32_t>(color_pixel[1]) << 8 | static_cast<uint32_t>(color_pixel[2]); | |||
new_point.rgb = *reinterpret_cast<float*> (&rgb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this piece of code has a problem. The rgb
variable has its upper bits set to zeros, so new_point.rgb
upper bits are zero as well. new_point
is actually a PointXYZRGBA
point, so the upper bits will be considered e.g. during visualization. And, surprise-surprise, the point will not show up, because zero Alpha means fully transparent.
I think we should rather assign color components of new_point
individually.
@@ -324,7 +324,8 @@ namespace pcl | |||
if (convertToMono) | |||
{ | |||
// Encode point color | |||
const uint32_t rgb = *reinterpret_cast<const int*> (&point.rgb); | |||
uint32_t rgb; | |||
std::memcpy (&rgb, &point.rgb, sizeof (point.rgb)); | |||
uint8_t grayvalue = static_cast<uint8_t>(0.2989 * static_cast<float>((rgb >> 16) & 0x0000ff) + | |||
0.5870 * static_cast<float>((rgb >> 8) & 0x0000ff) + | |||
0.1140 * static_cast<float>((rgb >> 0) & 0x0000ff)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also is totally outdated. A point that has color information will always have rgb
, rgba
, r
, g
, b
, and a
fields, all of them. So we can directly write 0.2989 * point.r + ....
38e464b
to
b6a28a1
Compare
@@ -230,8 +230,10 @@ main (int argc, char ** argv) | |||
new_point.z = depth; | |||
} | |||
|
|||
uint32_t rgb = static_cast<uint32_t>(color_pixel[0]) << 16 | static_cast<uint32_t>(color_pixel[1]) << 8 | static_cast<uint32_t>(color_pixel[2]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being picky, but this is not needed. Default constructor will properly initialize Alpha to 255.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be as picky as you need. Everyone benefits in the end.
I pushed on a separate commit, because it's just easier to see the changes and because we can squash on github.
Btw there's a typo in my commit message. It's supposed to be |
Thanks! |
Suppress strict alias warning
No description provided.