Skip to content

Commit

Permalink
rename VoxelColorMode to VoxelPoolingMode
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminum committed Dec 19, 2024
1 parent dd7e410 commit 41fe6b2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions cpp/open3d/geometry/VoxelGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ class VoxelGrid : public Geometry3D {
double height,
double depth);

/// \enum VoxelColorMode
/// \enum VoxelPoolingMode
///
/// \brief Possible ways of determining voxel color from PointCloud.
enum class VoxelColorMode { AVG, MIN, MAX, SUM };
enum class VoxelPoolingMode { AVG, MIN, MAX, SUM };

/// Creates a VoxelGrid from a given PointCloud. The color value of a given
/// voxel is determined by the VoxelColorMode, e.g. by default the average
/// voxel is determined by the VoxelPoolingMode, e.g. by default the average
/// color value of the points that fall into it (if the
/// PointCloud has colors).
/// The bounds of the created VoxelGrid are computed from the PointCloud.
Expand All @@ -206,10 +206,10 @@ class VoxelGrid : public Geometry3D {
static std::shared_ptr<VoxelGrid> CreateFromPointCloud(
const PointCloud &input,
double voxel_size,
VoxelColorMode color_mode = VoxelColorMode::AVG);
VoxelPoolingMode color_mode = VoxelPoolingMode::AVG);

/// Creates a VoxelGrid from a given PointCloud. The color value of a given
/// voxel is determined by the VoxelColorMode, e.g. by default the average
/// voxel is determined by the VoxelPoolingMode, e.g. by default the average
/// color value of the points that fall into it (if the
/// PointCloud has colors).
/// The bounds of the created VoxelGrid are defined by the given parameters.
Expand All @@ -224,7 +224,7 @@ class VoxelGrid : public Geometry3D {
double voxel_size,
const Eigen::Vector3d &min_bound,
const Eigen::Vector3d &max_bound,
VoxelColorMode color_mode = VoxelColorMode::AVG);
VoxelPoolingMode color_mode = VoxelPoolingMode::AVG);

/// Creates a VoxelGrid from a given TriangleMesh. No color information is
/// converted. The bounds of the created VoxelGrid are computed from the
Expand Down
14 changes: 7 additions & 7 deletions cpp/open3d/geometry/VoxelGridFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::shared_ptr<VoxelGrid> VoxelGrid::CreateFromPointCloudWithinBounds(
double voxel_size,
const Eigen::Vector3d &min_bound,
const Eigen::Vector3d &max_bound,
VoxelGrid::VoxelColorMode color_mode) {
VoxelGrid::VoxelPoolingMode pooling_mode) {
auto output = std::make_shared<VoxelGrid>();
if (voxel_size <= 0.0) {
utility::LogError("voxel_size <= 0.");
Expand Down Expand Up @@ -79,10 +79,10 @@ std::shared_ptr<VoxelGrid> VoxelGrid::CreateFromPointCloudWithinBounds(
const Eigen::Vector3i &grid_index = accpoint.second.GetVoxelIndex();
// clang-format off
const Eigen::Vector3d &color = has_colors ?
(color_mode == VoxelColorMode::AVG ? accpoint.second.GetAverageColor()
: color_mode == VoxelColorMode::MIN ? accpoint.second.GetMinColor()
: color_mode == VoxelColorMode::MAX ? accpoint.second.GetMaxColor()
: color_mode == VoxelColorMode::SUM ? accpoint.second.GetSumColor()
(pooling_mode == VoxelPoolingMode::AVG ? accpoint.second.GetAverageColor()
: pooling_mode == VoxelPoolingMode::MIN ? accpoint.second.GetMinColor()
: pooling_mode == VoxelPoolingMode::MAX ? accpoint.second.GetMaxColor()
: pooling_mode == VoxelPoolingMode::SUM ? accpoint.second.GetSumColor()
: Eigen::Vector3d::Zero())
: Eigen::Vector3d::Zero();
// clang-format on
Expand All @@ -97,12 +97,12 @@ std::shared_ptr<VoxelGrid> VoxelGrid::CreateFromPointCloudWithinBounds(
std::shared_ptr<VoxelGrid> VoxelGrid::CreateFromPointCloud(
const PointCloud &input,
double voxel_size,
VoxelGrid::VoxelColorMode color_mode) {
VoxelGrid::VoxelPoolingMode pooling_mode) {
Eigen::Vector3d voxel_size3(voxel_size, voxel_size, voxel_size);
Eigen::Vector3d min_bound = input.GetMinBound() - voxel_size3 * 0.5;
Eigen::Vector3d max_bound = input.GetMaxBound() + voxel_size3 * 0.5;
return CreateFromPointCloudWithinBounds(input, voxel_size, min_bound,
max_bound, color_mode);
max_bound, pooling_mode);
}

std::shared_ptr<VoxelGrid> VoxelGrid::CreateFromTriangleMeshWithinBounds(
Expand Down
24 changes: 12 additions & 12 deletions cpp/pybind/geometry/voxelgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ void pybind_voxelgrid_definitions(py::module &m) {
std::shared_ptr<VoxelGrid>, Geometry3D>>(
m.attr("VoxelGrid"));

py::enum_<VoxelGrid::VoxelColorMode> color_mode(
voxelgrid, "VoxelColorMode",
py::enum_<VoxelGrid::VoxelPoolingMode> pooling_mode(
voxelgrid, "VoxelPoolingMode",
"Mode of determining color for each voxel.");
color_mode.value("AVG", VoxelGrid::VoxelColorMode::AVG)
.value("MIN", VoxelGrid::VoxelColorMode::MIN)
.value("MAX", VoxelGrid::VoxelColorMode::MAX)
.value("SUM", VoxelGrid::VoxelColorMode::SUM);
pooling_mode.value("AVG", VoxelGrid::VoxelPoolingMode::AVG)
.value("MIN", VoxelGrid::VoxelPoolingMode::MIN)
.value("MAX", VoxelGrid::VoxelPoolingMode::MAX)
.value("SUM", VoxelGrid::VoxelPoolingMode::SUM);

py::detail::bind_default_constructor<VoxelGrid>(voxelgrid);
py::detail::bind_copy_functions<VoxelGrid>(voxelgrid);
Expand Down Expand Up @@ -139,22 +139,22 @@ void pybind_voxelgrid_definitions(py::module &m) {
&VoxelGrid::CreateFromPointCloud,
"Creates a VoxelGrid from a given PointCloud. The "
"color value of a given voxel is determined by the "
"VoxelColorMode, e.g. by default the average color "
"VoxelPoolingMode, e.g. by default the average color "
"value of the points that fall into it (if the "
"PointCloud has colors). The bounds of the created "
"VoxelGrid are computed from the PointCloud.",
"input"_a, "voxel_size"_a,
"color_mode"_a = VoxelGrid::VoxelColorMode::AVG)
"pooling_mode"_a = VoxelGrid::VoxelPoolingMode::AVG)
.def_static("create_from_point_cloud_within_bounds",
&VoxelGrid::CreateFromPointCloudWithinBounds,
"Creates a VoxelGrid from a given PointCloud. The "
"color value of a given voxel is determined by the "
"VoxelColorMode, e.g. by default the average color "
"VoxelPoolingMode, e.g. by default the average color "
"value of the points that fall into it (if the "
"PointCloud has colors). The bounds of the created "
"VoxelGrid are defined by the given parameters.",
"input"_a, "voxel_size"_a, "min_bound"_a, "max_bound"_a,
"color_mode"_a = VoxelGrid::VoxelColorMode::AVG)
"pooling_mode"_a = VoxelGrid::VoxelPoolingMode::AVG)
.def_static("create_from_triangle_mesh",
&VoxelGrid::CreateFromTriangleMesh,
"Creates a VoxelGrid from a given TriangleMesh. No "
Expand Down Expand Up @@ -229,7 +229,7 @@ void pybind_voxelgrid_definitions(py::module &m) {
m, "VoxelGrid", "create_from_point_cloud",
{{"input", "The input PointCloud"},
{"voxel_size", "Voxel size of of the VoxelGrid construction."},
{"color_mode", "VoxelColorMode for determining voxel color."}});
{"pooling_mode", "VoxelPoolingMode for determining voxel color."}});
docstring::ClassMethodDocInject(
m, "VoxelGrid", "create_from_point_cloud_within_bounds",
{{"input", "The input PointCloud"},
Expand All @@ -238,7 +238,7 @@ void pybind_voxelgrid_definitions(py::module &m) {
"Minimum boundary point for the VoxelGrid to create."},
{"max_bound",
"Maximum boundary point for the VoxelGrid to create."},
{"color_mode", "VoxelColorMode for determining voxel color."}});
{"pooling_mode", "VoxelPoolingMode that determines how to compute the voxel color."}});
docstring::ClassMethodDocInject(
m, "VoxelGrid", "create_from_triangle_mesh",
{{"input", "The input TriangleMesh"},
Expand Down
2 changes: 1 addition & 1 deletion docs/jupyter/geometry/voxelization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"metadata": {},
"source": [
"## From point cloud\n",
"The voxel grid can also be created from a point cloud using the method `create_from_point_cloud`. A voxel is occupied if at least one point of the point cloud is within the voxel. The argument `voxel_size` defines the resolution of the voxel grid. By default, the color of the voxel is the average of all the points within the voxel. The argument `color_mode` can be changed to determine the color by average, min, max or sum value of the points, e.g. with `o3d.geometry.VoxelGrid.VoxelColorMode.MIN`."
"The voxel grid can also be created from a point cloud using the method `create_from_point_cloud`. A voxel is occupied if at least one point of the point cloud is within the voxel. The argument `voxel_size` defines the resolution of the voxel grid. By default, the color of the voxel is the average of all the points within the voxel. The argument `pooling_mode` can be changed to determine the color by average, min, max or sum value of the points, e.g. with `o3d.geometry.VoxelGrid.VoxelPoolingMode.MIN`."
]
},
{
Expand Down

0 comments on commit 41fe6b2

Please sign in to comment.