Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 committed Jun 6, 2024
1 parent 778da6a commit 75a8081
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ msgs::Geometry gz::sim::convert(const sdf::Geometry &_in)
header->set_key("max_convex_hulls");
header->add_value(std::to_string(
meshSdf->ConvexDecomposition()->MaxConvexHulls()));
header = out.mutable_header()->add_data();
header->set_key("voxel_resolution");
header->add_value(std::to_string(
meshSdf->ConvexDecomposition()->VoxelResolution()));
}
}
else if (_in.Type() == sdf::GeometryType::HEIGHTMAP && _in.HeightmapShape())
Expand Down Expand Up @@ -355,6 +359,8 @@ sdf::Geometry gz::sim::convert(const msgs::Geometry &_in)
meshShape.SetSubmesh(_in.mesh().submesh());
meshShape.SetCenterSubmesh(_in.mesh().center_submesh());

sdf::ConvexDecomposition convexDecomp;
bool setConvexDecomp = false;
for (int i = 0; i < _in.header().data_size(); ++i)
{
auto data = _in.header().data(i);
Expand All @@ -364,11 +370,17 @@ sdf::Geometry gz::sim::convert(const msgs::Geometry &_in)
}
if (data.key() == "max_convex_hulls" && data.value_size() > 0)
{
sdf::ConvexDecomposition convexDecomp;
convexDecomp.SetMaxConvexHulls(std::stoul(data.value(0)));
meshShape.SetConvexDecomposition(convexDecomp);
setConvexDecomp = true;
}
if (data.key() == "voxel_resolution" && data.value_size() > 0)
{
convexDecomp.SetVoxelResolution(std::stoul(data.value(0)));
setConvexDecomp = true;
}
}
if (setConvexDecomp)
meshShape.SetConvexDecomposition(convexDecomp);
out.SetMeshShape(meshShape);
}
else if (_in.type() == msgs::Geometry::HEIGHTMAP && _in.has_heightmap())
Expand Down
14 changes: 14 additions & 0 deletions src/Conversions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ TEST(Conversions, GeometryMesh)
meshShape.SetSubmesh("grape");
meshShape.SetCenterSubmesh(true);
meshShape.SetOptimization("convex_decomposition");
sdf::ConvexDecomposition convexDecomp;
convexDecomp.SetMaxConvexHulls(4);
convexDecomp.SetVoxelResolution(10000);
meshShape.SetConvexDecomposition(convexDecomp);
geometry.SetMeshShape(meshShape);

auto geometryMsg = convert<msgs::Geometry>(geometry);
Expand All @@ -477,6 +481,12 @@ TEST(Conversions, GeometryMesh)
auto header = geometryMsg.header().data(0);
EXPECT_EQ("optimization", header.key());
EXPECT_EQ("convex_decomposition", header.value(0));
header = geometryMsg.header().data(1);
EXPECT_EQ("max_convex_hulls", header.key());
EXPECT_EQ("4", header.value(0));
header = geometryMsg.header().data(2);
EXPECT_EQ("voxel_resolution", header.key());
EXPECT_EQ("10000", header.value(0));

auto newGeometry = convert<sdf::Geometry>(geometryMsg);
EXPECT_EQ(sdf::GeometryType::MESH, newGeometry.Type());
Expand All @@ -486,6 +496,10 @@ TEST(Conversions, GeometryMesh)
EXPECT_EQ("grape", newGeometry.MeshShape()->Submesh());
EXPECT_TRUE(newGeometry.MeshShape()->CenterSubmesh());
EXPECT_EQ("convex_decomposition", newGeometry.MeshShape()->OptimizationStr());
auto newConvexDecomp = newGeometry.MeshShape()->ConvexDecomposition();
ASSERT_NE(nullptr, newConvexDecomp);
EXPECT_EQ(4, newConvexDecomp->MaxConvexHulls());
EXPECT_EQ(10000, newConvexDecomp->VoxelResolution());
}

/////////////////////////////////////////////////
Expand Down

0 comments on commit 75a8081

Please sign in to comment.