Skip to content
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

Merged
merged 2 commits into from
Nov 11, 2017

Conversation

SergioRAgostinho
Copy link
Member

No description provided.

@SergioRAgostinho SergioRAgostinho added this to the pcl-1.9.0 milestone Nov 10, 2017
@SergioRAgostinho SergioRAgostinho changed the title Suppress stric alias warning Suppress strict alias warning Nov 10, 2017
@@ -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);
Copy link
Member

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));
Copy link
Member

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 + ....

@@ -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]);
Copy link
Member

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.

Copy link
Member Author

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.

@SergioRAgostinho
Copy link
Member Author

Btw there's a typo in my commit message. It's supposed to be strict not stric.

@taketwo taketwo merged commit 5e83e92 into PointCloudLibrary:master Nov 11, 2017
@taketwo
Copy link
Member

taketwo commented Nov 11, 2017

Thanks!

@SergioRAgostinho SergioRAgostinho deleted the strict-alias-warn branch November 11, 2017 16:48
UnaNancyOwen pushed a commit to UnaNancyOwen/pcl that referenced this pull request Nov 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants