Skip to content

Commit

Permalink
add add_voxel and remove_voxel in pybind for VoxelGrid::AddVoxel, Vox…
Browse files Browse the repository at this point in the history
…elGrid::RemoveVoxel (#6023)

Co-authored-by: Rishabh Singh <rishabh.17iitkgp@gmail.com>
  • Loading branch information
ohkwon718 and reyanshsolis authored Aug 29, 2023
1 parent 5ba4a42 commit 3db1647
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cpp/open3d/geometry/VoxelGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> VoxelGrid::CheckIfIncluded(
const std::vector<Eigen::Vector3d> &queries) {
std::vector<bool> output;
Expand Down
3 changes: 3 additions & 0 deletions cpp/open3d/geometry/VoxelGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Eigen::Vector3d> GetVoxelBoundingPoints(
const Eigen::Vector3i &index) const;
Expand Down
9 changes: 9 additions & 0 deletions cpp/pybind/geometry/voxelgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -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."}});
Expand Down

0 comments on commit 3db1647

Please sign in to comment.