Skip to content

Commit

Permalink
Suppress strict alias warning (#2072)
Browse files Browse the repository at this point in the history
Suppress strict alias warning
  • Loading branch information
SergioRAgostinho authored and taketwo committed Nov 11, 2017
1 parent f556104 commit 5e83e92
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 72 deletions.
5 changes: 3 additions & 2 deletions examples/segmentation/example_supervoxels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ 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]);
new_point.rgb = *reinterpret_cast<float*> (&rgb);
new_point.r = color_pixel[0];
new_point.g = color_pixel[1];
new_point.b = color_pixel[2];
cloud->points.push_back (new_point);

}
Expand Down
69 changes: 20 additions & 49 deletions io/include/pcl/compression/organized_pointcloud_conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,20 +324,17 @@ namespace pcl
if (convertToMono)
{
// Encode point color
const uint32_t rgb = *reinterpret_cast<const int*> (&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));
uint8_t grayvalue = static_cast<uint8_t>(0.2989 * point.r
+ 0.5870 * point.g
+ 0.1140 * point.b);

rgbData_arg.push_back (grayvalue);
} else
{
// Encode point color
const uint32_t rgb = *reinterpret_cast<const int*> (&point.rgb);

rgbData_arg.push_back ( (rgb >> 16) & 0x0000ff);
rgbData_arg.push_back ( (rgb >> 8) & 0x0000ff);
rgbData_arg.push_back ( (rgb >> 0) & 0x0000ff);
rgbData_arg.push_back (point.r);
rgbData_arg.push_back (point.g);
rgbData_arg.push_back (point.b);
}


Expand Down Expand Up @@ -446,35 +443,22 @@ namespace pcl
{
if (monoImage_arg)
{
const uint8_t& pixel_r = rgbData_arg[i];
const uint8_t& pixel_g = rgbData_arg[i];
const uint8_t& pixel_b = rgbData_arg[i];

// Define point color
uint32_t rgb = (static_cast<uint32_t>(pixel_r) << 16
| static_cast<uint32_t>(pixel_g) << 8
| static_cast<uint32_t>(pixel_b));
newPoint.rgb = *reinterpret_cast<float*>(&rgb);
newPoint.r = rgbData_arg[i];
newPoint.g = rgbData_arg[i];
newPoint.b = rgbData_arg[i];
} else
{
const uint8_t& pixel_r = rgbData_arg[i*3+0];
const uint8_t& pixel_g = rgbData_arg[i*3+1];
const uint8_t& pixel_b = rgbData_arg[i*3+2];

// Define point color
uint32_t rgb = (static_cast<uint32_t>(pixel_r) << 16
| static_cast<uint32_t>(pixel_g) << 8
| static_cast<uint32_t>(pixel_b));
newPoint.rgb = *reinterpret_cast<float*>(&rgb);
newPoint.r = rgbData_arg[i*3+0];
newPoint.g = rgbData_arg[i*3+1];
newPoint.b = rgbData_arg[i*3+2];
}

} else
{
// Set white point color
uint32_t rgb = (static_cast<uint32_t>(255) << 16
| static_cast<uint32_t>(255) << 8
| static_cast<uint32_t>(255));
newPoint.rgb = *reinterpret_cast<float*>(&rgb);
newPoint.rgba = 0xffffffffu;
}
} else
{
Expand Down Expand Up @@ -564,35 +548,22 @@ namespace pcl
{
if (monoImage_arg)
{
const uint8_t& pixel_r = rgbData_arg[i];
const uint8_t& pixel_g = rgbData_arg[i];
const uint8_t& pixel_b = rgbData_arg[i];

// Define point color
uint32_t rgb = (static_cast<uint32_t>(pixel_r) << 16
| static_cast<uint32_t>(pixel_g) << 8
| static_cast<uint32_t>(pixel_b));
newPoint.rgb = *reinterpret_cast<float*>(&rgb);
newPoint.r = rgbData_arg[i];
newPoint.g = rgbData_arg[i];
newPoint.b = rgbData_arg[i];
} else
{
const uint8_t& pixel_r = rgbData_arg[i*3+0];
const uint8_t& pixel_g = rgbData_arg[i*3+1];
const uint8_t& pixel_b = rgbData_arg[i*3+2];

// Define point color
uint32_t rgb = (static_cast<uint32_t>(pixel_r) << 16
| static_cast<uint32_t>(pixel_g) << 8
| static_cast<uint32_t>(pixel_b));
newPoint.rgb = *reinterpret_cast<float*>(&rgb);
newPoint.r = rgbData_arg[i*3+0];
newPoint.g = rgbData_arg[i*3+1];
newPoint.b = rgbData_arg[i*3+2];
}

} else
{
// Set white point color
uint32_t rgb = (static_cast<uint32_t>(255) << 16
| static_cast<uint32_t>(255) << 8
| static_cast<uint32_t>(255));
newPoint.rgb = *reinterpret_cast<float*>(&rgb);
newPoint.rgba = 0xffffffffu;
}
} else
{
Expand Down
30 changes: 14 additions & 16 deletions test/common/test_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ TEST (PCL, PointXYZRGB)
PointXYZRGB p;

uint8_t r = 127, g = 64, b = 254;
uint32_t rgb = (static_cast<uint32_t> (r) << 16 |
static_cast<uint32_t> (g) << 8 |
static_cast<uint32_t> (b));
p.rgb = *reinterpret_cast<float*>(&rgb);
p.r = r;
p.g = g;
p.b = b;

rgb = *reinterpret_cast<int*>(&p.rgb);
uint8_t rr = (rgb >> 16) & 0x0000ff;
uint8_t gg = (rgb >> 8) & 0x0000ff;
uint8_t bb = (rgb) & 0x0000ff;
uint8_t rr = (p.rgba >> 16) & 0x0000ff;
uint8_t gg = (p.rgba >> 8) & 0x0000ff;
uint8_t bb = (p.rgba) & 0x0000ff;

EXPECT_EQ (r, rr);
EXPECT_EQ (g, gg);
Expand All @@ -75,7 +73,7 @@ TEST (PCL, PointXYZRGB)
EXPECT_EQ (bb, 254);

p.r = 0; p.g = 127; p.b = 0;
rgb = *reinterpret_cast<int*>(&p.rgb);
uint32_t rgb = p.rgba;
rr = (rgb >> 16) & 0x0000ff;
gg = (rgb >> 8) & 0x0000ff;
bb = (rgb) & 0x0000ff;
Expand All @@ -94,12 +92,11 @@ TEST (PCL, PointXYZRGBNormal)
uint32_t rgb = (static_cast<uint32_t> (r) << 16 |
static_cast<uint32_t> (g) << 8 |
static_cast<uint32_t> (b));
p.rgb = *reinterpret_cast<float*>(&rgb);
p.rgba = rgb;

rgb = *reinterpret_cast<int*>(&p.rgb);
uint8_t rr = (rgb >> 16) & 0x0000ff;
uint8_t gg = (rgb >> 8) & 0x0000ff;
uint8_t bb = (rgb) & 0x0000ff;
uint8_t rr = (p.rgba >> 16) & 0x0000ff;
uint8_t gg = (p.rgba >> 8) & 0x0000ff;
uint8_t bb = (p.rgba) & 0x0000ff;

EXPECT_EQ (r, rr);
EXPECT_EQ (g, gg);
Expand All @@ -109,7 +106,7 @@ TEST (PCL, PointXYZRGBNormal)
EXPECT_EQ (bb, 254);

p.r = 0; p.g = 127; p.b = 0;
rgb = *reinterpret_cast<int*>(&p.rgb);
rgb = p.rgba;
rr = (rgb >> 16) & 0x0000ff;
gg = (rgb >> 8) & 0x0000ff;
bb = (rgb) & 0x0000ff;
Expand Down Expand Up @@ -413,7 +410,8 @@ TEST (PCL, CopyIfFieldExists)
EXPECT_EQ (z_val, 3.0);
pcl::for_each_type<FieldList> (CopyIfFieldExists<PointXYZRGBNormal, float> (p, "rgb", is_rgb, rgb_val));
EXPECT_EQ (is_rgb, true);
int rgb = *reinterpret_cast<int*>(&rgb_val);
uint32_t rgb;
std::memcpy (&rgb, &rgb_val, sizeof(rgb_val));
EXPECT_EQ (rgb, 0xff7f40fe); // alpha is 255
pcl::for_each_type<FieldList> (CopyIfFieldExists<PointXYZRGBNormal, float> (p, "normal_x", is_normal_x, normal_x_val));
EXPECT_EQ (is_normal_x, true);
Expand Down
8 changes: 3 additions & 5 deletions test/filters/test_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,11 +895,9 @@ TEST (VoxelGrid_RGB, Filters)
for (int i = 0; i < 10; ++i)
{
PointXYZRGB pt;
int rgb = (col_r[i] << 16) | (col_g[i] << 8) | col_b[i];
pt.x = 0.0f;
pt.y = 0.0f;
pt.z = 0.0f;
pt.rgb = *reinterpret_cast<float*> (&rgb);
pt.r = col_r[i];
pt.g = col_g[i];
pt.b = col_b[i];
cloud_rgb_.points.push_back (pt);
}

Expand Down

0 comments on commit 5e83e92

Please sign in to comment.