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

Fix PolygonMesh::concatenate and its unit test #4745

Merged
merged 7 commits into from
May 13, 2021
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: 2 additions & 1 deletion common/include/pcl/PolygonMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ namespace pcl
static bool
concatenate (pcl::PolygonMesh &mesh1, const pcl::PolygonMesh &mesh2)
{
const auto point_offset = mesh1.cloud.width * mesh1.cloud.height;

bool success = pcl::PCLPointCloud2::concatenate(mesh1.cloud, mesh2.cloud);
if (success == false) {
return false;
}
// Make the resultant polygon mesh take the newest stamp
mesh1.header.stamp = std::max(mesh1.header.stamp, mesh2.header.stamp);

const auto point_offset = mesh1.cloud.width * mesh1.cloud.height;
std::transform(mesh2.polygons.begin (),
mesh2.polygons.end (),
std::back_inserter (mesh1.polygons),
Expand Down
30 changes: 15 additions & 15 deletions test/common/test_polygon_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ TEST(PolygonMesh, concatenate_cloud)

TEST(PolygonMesh, concatenate_vertices)
{
const std::size_t size = 15;

PolygonMesh test, dummy;
test.cloud.width = 10;
test.cloud.height = 5;
// The algorithm works regardless of the organization.
test.cloud.width = dummy.cloud.width = size;
test.cloud.height = dummy.cloud.height = 1;
kunaltyagi marked this conversation as resolved.
Show resolved Hide resolved

const std::size_t size = 15;
for (std::size_t i = 0; i < size; ++i)
{
dummy.polygons.emplace_back();
Expand All @@ -111,18 +113,16 @@ TEST(PolygonMesh, concatenate_vertices)
EXPECT_EQ(2 * dummy.polygons.size(), test.polygons.size());

const auto cloud_size = test.cloud.width * test.cloud.height;
for (std::size_t i = 0; i < dummy.polygons.size(); ++i)
{
EXPECT_EQ(dummy.polygons[i].vertices.size(), test.polygons[i].vertices.size());
EXPECT_EQ(dummy.polygons[i].vertices.size(),
test.polygons[i + dummy.polygons.size()].vertices.size());
for (std::size_t j = 0; j < size; ++j)
{
EXPECT_EQ(dummy.polygons[i].vertices[j],
test.polygons[i].vertices[j]);
EXPECT_EQ(dummy.polygons[i].vertices[j] + cloud_size,
test.polygons[i + dummy.polygons.size()].vertices[j]);
}
for (const auto& polygon : test.polygons)
for (const auto& vertex : polygon.vertices)
EXPECT_LT(vertex, cloud_size);

pcl::Indices vertices(size);
for (std::size_t i = 0; i < size; ++i) {
vertices = dummy.polygons[i].vertices;
EXPECT_EQ_VECTORS(vertices, test.polygons[i].vertices);
for (auto& vertex : vertices) { vertex += size; }
EXPECT_EQ_VECTORS(vertices, test.polygons[i + size].vertices);
}
}

Expand Down