Skip to content

Commit

Permalink
Add <voxel_resolution> SDF element to <convex_decomposition> (gazebos…
Browse files Browse the repository at this point in the history
…im#1403)

Signed-off-by: Ian Chen <[email protected]>
Co-authored-by: Steve Peters <[email protected]>
  • Loading branch information
iche033 and scpeters authored May 28, 2024
1 parent 3f84210 commit e2e72ae
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/sdf/Mesh.hh
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,23 @@ namespace sdf
public: sdf::ElementPtr Element() const;

/// \brief Get the maximum number of convex hulls that can be generated.
/// \return Maximum number of convex hulls.
public: unsigned int MaxConvexHulls() const;

/// \brief Set the maximum number of convex hulls that can be generated.
/// \param[in] _maxConvexHulls Maximum number of convex hulls.
public: void SetMaxConvexHulls(unsigned int _maxConvexHulls);

/// Get the voxel resolution to use for representing the mesh. Applicable
/// only to voxel based convex decomposition methods.
/// \param[in] _voxelResolution Voxel resolution to use.
public: unsigned int VoxelResolution() const;

/// Set the voxel resolution to use for representing the mesh. Applicable
/// only to voxel based convex decomposition methods.
/// \param[in] _voxelResolution Voxel resolution to use.
public: void SetVoxelResolution(unsigned int _voxelResolution);

/// \brief Private data pointer.
GZ_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
7 changes: 7 additions & 0 deletions python/src/sdf/pyConvexDecomposition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ void defineConvexDecomposition(pybind11::object module)
"Get the maximum number of convex hulls that can be generated.")
.def("set_max_convex_hulls", &sdf::ConvexDecomposition::SetMaxConvexHulls,
"Set the maximum number of convex hulls that can be generated.")
.def("voxel_resolution", &sdf::ConvexDecomposition::VoxelResolution,
"Get the voxel resolution to use. Applicable only to voxel based "
"convex decomposition methods.")
.def("set_voxel_resolution", &sdf::ConvexDecomposition::SetVoxelResolution,
"Set the voxel resolution to use. Applicable only to voxel based "
"convex decomposition methods.")

.def("__copy__", [](const sdf::ConvexDecomposition &self) {
return sdf::ConvexDecomposition(self);
})
Expand Down
6 changes: 6 additions & 0 deletions python/test/pyMesh_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_assigment(self):

convexDecomp = ConvexDecomposition()
convexDecomp.set_max_convex_hulls(10)
convexDecomp.set_voxel_resolution(100000)
mesh.set_convex_decomposition(convexDecomp)

mesh2 = mesh
Expand All @@ -58,6 +59,7 @@ def test_assigment(self):

convexDecomp2 = mesh2.convex_decomposition()
self.assertEqual(10, convexDecomp2.max_convex_hulls())
self.assertEqual(100000, convexDecomp2.voxel_resolution())

mesh.set_file_path("/apple")
self.assertEqual("/apple", mesh2.file_path())
Expand Down Expand Up @@ -86,6 +88,7 @@ def test_deepcopy_construction(self):

convexDecomp = ConvexDecomposition()
convexDecomp.set_max_convex_hulls(10)
convexDecomp.set_voxel_resolution(100000)
mesh.set_convex_decomposition(convexDecomp)

mesh2 = copy.deepcopy(mesh)
Expand All @@ -99,6 +102,7 @@ def test_deepcopy_construction(self):

convexDecomp2 = mesh2.convex_decomposition()
self.assertEqual(10, convexDecomp2.max_convex_hulls())
self.assertEqual(100000, convexDecomp2.voxel_resolution())

mesh.set_file_path("/apple")
mesh.set_scale(Vector3d(0.3, 0.2, 0.4))
Expand Down Expand Up @@ -131,8 +135,10 @@ def test_set(self):

convexDecomp = ConvexDecomposition()
convexDecomp.set_max_convex_hulls(10)
convexDecomp.set_voxel_resolution(100000)
mesh.set_convex_decomposition(convexDecomp)
self.assertEqual(10, mesh.convex_decomposition().max_convex_hulls())
self.assertEqual(100000, mesh.convex_decomposition().voxel_resolution())

self.assertEqual("", mesh.uri())
mesh.set_uri("http://myuri.com")
Expand Down
3 changes: 3 additions & 0 deletions sdf/1.11/mesh_shape.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<element name="max_convex_hulls" type="unsigned int" default="16" required="0">
<description>Maximum number of convex hulls to decompose into. This sets the maximum number of submeshes that the final decomposed mesh will contain.</description>
</element>
<element name="voxel_resolution" type="unsigned int" default="200000" required="0">
<description>The number of voxels to use for representing the source mesh before decomposition. Applicable only to voxel based convex decomposition methods.</description>
</element>
</element>

<element name="uri" type="string" default="__default__" required="1">
Expand Down
3 changes: 3 additions & 0 deletions sdf/1.12/mesh_shape.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<element name="max_convex_hulls" type="unsigned int" default="16" required="0">
<description>Maximum number of convex hulls to decompose into. This sets the maximum number of submeshes that the final decomposed mesh will contain.</description>
</element>
<element name="voxel_resolution" type="unsigned int" default="200000" required="0">
<description>The number of voxels to use for representing the source mesh before decomposition. Applicable only to voxel based convex decomposition methods.</description>
</element>
</element>

<element name="uri" type="string" default="__default__" required="1">
Expand Down
22 changes: 22 additions & 0 deletions src/Mesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class sdf::ConvexDecomposition::Implementation
/// \brief Maximum number of convex hulls to generate.
public: unsigned int maxConvexHulls{16u};

/// \brief Voxel resolution. Applicable only to voxel based methods for
/// representing the mesh before decomposition
public: unsigned int voxelResolution{200000u};

/// \brief The SDF element pointer used during load.
public: sdf::ElementPtr sdf = nullptr;
};
Expand Down Expand Up @@ -112,6 +116,10 @@ Errors ConvexDecomposition::Load(ElementPtr _sdf)
errors, "max_convex_hulls",
this->dataPtr->maxConvexHulls).first;

this->dataPtr->voxelResolution = _sdf->Get<unsigned int>(
errors, "voxel_resolution",
this->dataPtr->voxelResolution).first;

return errors;
}

Expand All @@ -133,6 +141,18 @@ void ConvexDecomposition::SetMaxConvexHulls(unsigned int _maxConvexHulls)
this->dataPtr->maxConvexHulls = _maxConvexHulls;
}

/////////////////////////////////////////////////
unsigned int ConvexDecomposition::VoxelResolution() const
{
return this->dataPtr->voxelResolution;
}

/////////////////////////////////////////////////
void ConvexDecomposition::SetVoxelResolution(unsigned int _voxelResolution)
{
this->dataPtr->voxelResolution = _voxelResolution;
}

/////////////////////////////////////////////////
Mesh::Mesh()
: dataPtr(gz::utils::MakeImpl<Implementation>())
Expand Down Expand Up @@ -403,6 +423,8 @@ sdf::ElementPtr Mesh::ToElement(sdf::Errors &_errors) const
_errors);
convexDecomp->GetElement("max_convex_hulls")->Set(
this->dataPtr->convexDecomposition->MaxConvexHulls());
convexDecomp->GetElement("voxel_resolution")->Set(
this->dataPtr->convexDecomposition->VoxelResolution());
}

// Uri
Expand Down
6 changes: 6 additions & 0 deletions src/Mesh_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ TEST(DOMMesh, MoveConstructor)
sdf::ConvexDecomposition convexDecomp;
EXPECT_EQ(nullptr, convexDecomp.Element());
convexDecomp.SetMaxConvexHulls(10u);
convexDecomp.SetVoxelResolution(100000u);
mesh.SetConvexDecomposition(convexDecomp);

sdf::Mesh mesh2(std::move(mesh));
Expand All @@ -72,6 +73,7 @@ TEST(DOMMesh, MoveConstructor)
auto convexDecomp2 = mesh2.ConvexDecomposition();
ASSERT_NE(nullptr, convexDecomp2);
EXPECT_EQ(10u, convexDecomp2->MaxConvexHulls());
EXPECT_EQ(100000u, convexDecomp2->VoxelResolution());
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -186,9 +188,11 @@ TEST(DOMMesh, Set)

sdf::ConvexDecomposition convexDecomp;
convexDecomp.SetMaxConvexHulls(10u);
convexDecomp.SetVoxelResolution(200000u);
mesh.SetConvexDecomposition(convexDecomp);
ASSERT_NE(nullptr, mesh.ConvexDecomposition());
EXPECT_EQ(10u, mesh.ConvexDecomposition()->MaxConvexHulls());
EXPECT_EQ(200000u, mesh.ConvexDecomposition()->VoxelResolution());

EXPECT_EQ(std::string(), mesh.Uri());
mesh.SetUri("http://myuri.com");
Expand Down Expand Up @@ -365,6 +369,7 @@ TEST(DOMMesh, ToElement)

sdf::ConvexDecomposition convexDecomp;
convexDecomp.SetMaxConvexHulls(10u);
convexDecomp.SetVoxelResolution(300000u);
mesh.SetConvexDecomposition(convexDecomp);

sdf::ElementPtr elem = mesh.ToElement();
Expand All @@ -381,6 +386,7 @@ TEST(DOMMesh, ToElement)
EXPECT_EQ(mesh.CenterSubmesh(), mesh2.CenterSubmesh());
ASSERT_NE(nullptr, mesh2.ConvexDecomposition());
EXPECT_EQ(10u, mesh2.ConvexDecomposition()->MaxConvexHulls());
EXPECT_EQ(300000u, mesh2.ConvexDecomposition()->VoxelResolution());
}

/////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions test/integration/geometry_dom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ TEST(DOMGeometry, Shapes)
meshColGeom->Optimization());
ASSERT_NE(nullptr, meshColGeom->ConvexDecomposition());
EXPECT_EQ(4u, meshColGeom->ConvexDecomposition()->MaxConvexHulls());
EXPECT_EQ(400000u, meshColGeom->ConvexDecomposition()->VoxelResolution());

EXPECT_EQ("https://fuel.gazebosim.org/1.0/an_org/models/a_model/mesh/"
"mesh.dae", meshColGeom->Uri());
Expand Down
1 change: 1 addition & 0 deletions test/sdf/shapes.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<mesh optimization="convex_decomposition">
<convex_decomposition>
<max_convex_hulls>4</max_convex_hulls>
<voxel_resolution>400000</voxel_resolution>
</convex_decomposition>
<uri>https://fuel.gazebosim.org/1.0/an_org/models/a_model/mesh/mesh.dae</uri>
<submesh>
Expand Down

0 comments on commit e2e72ae

Please sign in to comment.