Skip to content

Commit

Permalink
Merge pull request #933 from taketwo/fix-932
Browse files Browse the repository at this point in the history
Add emptiness check in copyPointCloud()
  • Loading branch information
jspricke committed Oct 1, 2014
2 parents bdce4cb + c949fd8 commit 21c5f0e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions common/include/pcl/common/impl/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ pcl::copyPointCloud (const pcl::PointCloud<PointInT> &cloud_in,
cloud_out.sensor_origin_ = cloud_in.sensor_origin_;
cloud_out.points.resize (cloud_in.points.size ());

if (cloud_in.points.size () == 0)
return;

if (isSamePointType<PointInT, PointOutT> ())
// Copy the whole memory block
memcpy (&cloud_out.points[0], &cloud_in.points[0], cloud_in.points.size () * sizeof (PointInT));
Expand Down
23 changes: 23 additions & 0 deletions test/common/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ using namespace std;
typedef PointCloud <PointXYZRGBA> CloudXYZRGBA;
typedef PointCloud <PointXYZRGB> CloudXYZRGB;
typedef PointCloud <PointXYZRGBNormal> CloudXYZRGBNormal;
typedef PointCloud <PointXYZ> CloudXYZ;

PointXYZRGBA pt_xyz_rgba, pt_xyz_rgba2;
PointXYZRGB pt_xyz_rgb;
PointXYZ pt_xyz;

///////////////////////////////////////////////////////////////////////////////////////////
TEST (PCL, concatenateFields)
Expand Down Expand Up @@ -337,6 +339,23 @@ TEST (PCL, CopyPointCloudWithIndicesAndRGBToRGBA)
}
}

TEST (PCL, CopyPointCloudWithSameTypes)
{
CloudXYZ cloud_in (5, 1, pt_xyz);
CloudXYZ cloud_in_empty;
CloudXYZ cloud_out;

pcl::copyPointCloud (cloud_in, cloud_out);

ASSERT_EQ (cloud_in.size (), cloud_out.size ());
for (size_t i = 0; i < cloud_out.size (); ++i)
EXPECT_XYZ_EQ (cloud_in[i], cloud_out[i]);

pcl::copyPointCloud (cloud_in_empty, cloud_out);

ASSERT_EQ (0, cloud_out.size ());
}

/* ---[ */
int
main (int argc, char** argv)
Expand Down Expand Up @@ -365,6 +384,10 @@ main (int argc, char** argv)
pt_xyz_rgb.b = 0;
pt_xyz_rgb.a = 255;

pt_xyz.x = 4;
pt_xyz.y = 1;
pt_xyz.z = 5;

testing::InitGoogleTest (&argc, argv);
return (RUN_ALL_TESTS ());
}
Expand Down

0 comments on commit 21c5f0e

Please sign in to comment.