diff --git a/include/sdf/Mesh.hh b/include/sdf/Mesh.hh
index 7cc48c955..c77cb7bff 100644
--- a/include/sdf/Mesh.hh
+++ b/include/sdf/Mesh.hh
@@ -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)
};
diff --git a/python/src/sdf/pyConvexDecomposition.cc b/python/src/sdf/pyConvexDecomposition.cc
index aacd7ee42..c3cefd5d8 100644
--- a/python/src/sdf/pyConvexDecomposition.cc
+++ b/python/src/sdf/pyConvexDecomposition.cc
@@ -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);
})
diff --git a/python/test/pyMesh_TEST.py b/python/test/pyMesh_TEST.py
index ac9840ea6..0990095d6 100644
--- a/python/test/pyMesh_TEST.py
+++ b/python/test/pyMesh_TEST.py
@@ -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
@@ -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())
@@ -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)
@@ -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))
@@ -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")
diff --git a/sdf/1.11/mesh_shape.sdf b/sdf/1.11/mesh_shape.sdf
index 1ed64ca44..38754e5f5 100644
--- a/sdf/1.11/mesh_shape.sdf
+++ b/sdf/1.11/mesh_shape.sdf
@@ -12,6 +12,9 @@
Maximum number of convex hulls to decompose into. This sets the maximum number of submeshes that the final decomposed mesh will contain.
+
+ The number of voxels to use for representing the source mesh before decomposition. Applicable only to voxel based convex decomposition methods.
+
diff --git a/sdf/1.12/mesh_shape.sdf b/sdf/1.12/mesh_shape.sdf
index 1ed64ca44..38754e5f5 100644
--- a/sdf/1.12/mesh_shape.sdf
+++ b/sdf/1.12/mesh_shape.sdf
@@ -12,6 +12,9 @@
Maximum number of convex hulls to decompose into. This sets the maximum number of submeshes that the final decomposed mesh will contain.
+
+ The number of voxels to use for representing the source mesh before decomposition. Applicable only to voxel based convex decomposition methods.
+
diff --git a/src/Mesh.cc b/src/Mesh.cc
index f026e2d63..d2ee4b7a8 100644
--- a/src/Mesh.cc
+++ b/src/Mesh.cc
@@ -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;
};
@@ -112,6 +116,10 @@ Errors ConvexDecomposition::Load(ElementPtr _sdf)
errors, "max_convex_hulls",
this->dataPtr->maxConvexHulls).first;
+ this->dataPtr->voxelResolution = _sdf->Get(
+ errors, "voxel_resolution",
+ this->dataPtr->voxelResolution).first;
+
return errors;
}
@@ -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())
@@ -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
diff --git a/src/Mesh_TEST.cc b/src/Mesh_TEST.cc
index 29ef70d85..391283976 100644
--- a/src/Mesh_TEST.cc
+++ b/src/Mesh_TEST.cc
@@ -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));
@@ -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());
}
/////////////////////////////////////////////////
@@ -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");
@@ -365,6 +369,7 @@ TEST(DOMMesh, ToElement)
sdf::ConvexDecomposition convexDecomp;
convexDecomp.SetMaxConvexHulls(10u);
+ convexDecomp.SetVoxelResolution(300000u);
mesh.SetConvexDecomposition(convexDecomp);
sdf::ElementPtr elem = mesh.ToElement();
@@ -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());
}
/////////////////////////////////////////////////
diff --git a/test/integration/geometry_dom.cc b/test/integration/geometry_dom.cc
index 5cc54f1e4..927850087 100644
--- a/test/integration/geometry_dom.cc
+++ b/test/integration/geometry_dom.cc
@@ -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());
diff --git a/test/sdf/shapes.sdf b/test/sdf/shapes.sdf
index 9c87c520b..cd5b31e41 100644
--- a/test/sdf/shapes.sdf
+++ b/test/sdf/shapes.sdf
@@ -141,6 +141,7 @@
4
+ 400000
https://fuel.gazebosim.org/1.0/an_org/models/a_model/mesh/mesh.dae