Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix VoxelGrid.voxels bug #1535 #1688

Merged
merged 1 commit into from
Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Open3D/Geometry/VoxelGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,5 +356,14 @@ VoxelGrid &VoxelGrid::CarveSilhouette(
return *this;
}

std::vector<Voxel> VoxelGrid::GetVoxels() const {
std::vector<Voxel> result;
result.reserve(voxels_.size());
for (const auto &keyval : voxels_) {
result.push_back(keyval.second);
}
return result;
}

} // namespace geometry
} // namespace open3d
5 changes: 5 additions & 0 deletions src/Open3D/Geometry/VoxelGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ class VoxelGrid : public Geometry3D {
const Eigen::Vector3d &min_bound,
const Eigen::Vector3d &max_bound);

/// Returns List of ``Voxel``: Voxels contained in voxel grid.
/// Changes to the voxels returned from this method are not reflected in
/// the voxel grid.
std::vector<Voxel> GetVoxels() const;

public:
/// Size of the voxel.
double voxel_size_ = 0.0;
Expand Down
6 changes: 4 additions & 2 deletions src/Python/open3d_pybind/geometry/voxelgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ void pybind_voxelgrid(py::module &m) {
})
.def(py::self + py::self)
.def(py::self += py::self)
.def_readwrite("voxels", &geometry::VoxelGrid::voxels_,
"List of ``Voxel``: Voxels contained in voxel grid")
.def("get_voxels", &geometry::VoxelGrid::GetVoxels,
"Returns List of ``Voxel``: Voxels contained in voxel grid. "
"Changes to the voxels returned from this method"
"are not reflected in the voxel grid.")
.def("has_colors", &geometry::VoxelGrid::HasColors,
"Returns ``True`` if the voxel grid contains voxel colors.")
.def("has_voxels", &geometry::VoxelGrid::HasVoxels,
Expand Down