diff --git a/cpp/open3d/geometry/VoxelGrid.cpp b/cpp/open3d/geometry/VoxelGrid.cpp index 4a6dac2d1a7..dafe6b52c01 100644 --- a/cpp/open3d/geometry/VoxelGrid.cpp +++ b/cpp/open3d/geometry/VoxelGrid.cpp @@ -197,6 +197,8 @@ void VoxelGrid::AddVoxel(const Voxel &voxel) { voxels_[voxel.grid_index_] = voxel; } +void VoxelGrid::RemoveVoxel(const Eigen::Vector3i &idx) { voxels_.erase(idx); } + std::vector VoxelGrid::CheckIfIncluded( const std::vector &queries) { std::vector output; diff --git a/cpp/open3d/geometry/VoxelGrid.h b/cpp/open3d/geometry/VoxelGrid.h index d12d664c5f9..b0d8cc458ed 100644 --- a/cpp/open3d/geometry/VoxelGrid.h +++ b/cpp/open3d/geometry/VoxelGrid.h @@ -123,6 +123,9 @@ class VoxelGrid : public Geometry3D { /// Add a voxel with specified grid index and color. void AddVoxel(const Voxel &voxel); + /// Remove a voxel with specified grid index. + void RemoveVoxel(const Eigen::Vector3i &idx); + /// Return a vector of 3D coordinates that define the indexed voxel cube. std::vector GetVoxelBoundingPoints( const Eigen::Vector3i &index) const; diff --git a/cpp/pybind/geometry/voxelgrid.cpp b/cpp/pybind/geometry/voxelgrid.cpp index 7abe1872e91..0528979b0f3 100644 --- a/cpp/pybind/geometry/voxelgrid.cpp +++ b/cpp/pybind/geometry/voxelgrid.cpp @@ -77,6 +77,10 @@ void pybind_voxelgrid(py::module &m) { "Returns ``True`` if the voxel grid contains voxels.") .def("get_voxel", &VoxelGrid::GetVoxel, "point"_a, "Returns voxel index given query point.") + .def("add_voxel", &VoxelGrid::AddVoxel, "voxel"_a, + "Add a new voxel into the VoxelGrid.") + .def("remove_voxel", &VoxelGrid::RemoveVoxel, "idx"_a, + "Remove a voxel given index.") .def("check_if_included", &VoxelGrid::CheckIfIncluded, "queries"_a, "Element-wise check if a query in the list is included in " "the VoxelGrid. Queries are double precision and " @@ -155,6 +159,11 @@ void pybind_voxelgrid(py::module &m) { docstring::ClassMethodDocInject(m, "VoxelGrid", "has_voxels"); docstring::ClassMethodDocInject(m, "VoxelGrid", "get_voxel", {{"point", "The query point."}}); + docstring::ClassMethodDocInject(m, "VoxelGrid", "add_voxel", + {{"Voxel", "A new voxel."}}); + docstring::ClassMethodDocInject( + m, "VoxelGrid", "remove_voxel", + {{"idx", "The grid index of the target voxel."}}); docstring::ClassMethodDocInject( m, "VoxelGrid", "check_if_included", {{"query", "a list of voxel indices to check."}});