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

Add emptiness check in copyPointCloud() #933

Merged
merged 1 commit into from
Oct 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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