Skip to content

Commit

Permalink
make PaintUniformColor return by reference (#5566)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuecideng authored Oct 18, 2022
1 parent ea1a263 commit 4eef4b3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
7 changes: 3 additions & 4 deletions cpp/open3d/t/geometry/PointCloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ std::tuple<PointCloud, core::Tensor> PointCloud::RemoveDuplicatedPoints()
return std::make_tuple(SelectByMask(masks), masks);
}

PointCloud PointCloud::PaintUniformColor(const core::Tensor &color) const {
PointCloud &PointCloud::PaintUniformColor(const core::Tensor &color) {
core::AssertTensorShape(color, {3});
core::Tensor clipped_color = color.To(GetDevice());
if (color.GetDtype() == core::Float32 ||
Expand All @@ -458,10 +458,9 @@ PointCloud PointCloud::PaintUniformColor(const core::Tensor &color) const {
core::Tensor::Empty({GetPointPositions().GetLength(), 3},
clipped_color.GetDtype(), GetDevice());
pcd_colors.AsRvalue() = clipped_color;
PointCloud pcd(this->Clone());
pcd.SetPointColors(pcd_colors);
SetPointColors(pcd_colors);

return pcd;
return *this;
}

std::tuple<PointCloud, core::Tensor> PointCloud::ComputeBoundaryPoints(
Expand Down
12 changes: 6 additions & 6 deletions cpp/open3d/t/geometry/PointCloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ class PointCloud : public Geometry, public DrawableGeometry {
/// \return Rotated point cloud
PointCloud &Rotate(const core::Tensor &R, const core::Tensor &center);

/// \brief Assigns uniform color to the point cloud.
///
/// \param color RGB color for the point cloud. {3,} shaped Tensor.
/// Floating color values are clipped between 0.0 and 1.0.
PointCloud &PaintUniformColor(const core::Tensor &color);

/// \brief Select points from input pointcloud, based on boolean mask
/// indices into output point cloud.
///
Expand Down Expand Up @@ -395,12 +401,6 @@ class PointCloud : public Geometry, public DrawableGeometry {
std::tuple<PointCloud, core::Tensor> RemoveNonFinitePoints(
bool remove_nan = true, bool remove_infinite = true) const;

/// \brief Assigns uniform color to the point cloud.
///
/// \param color RGB color for the point cloud. {3,} shaped Tensor.
/// Floating color values are clipped between 0.0 and 1.0.
PointCloud PaintUniformColor(const core::Tensor &color) const;

/// \brief Returns the device attribute of this PointCloud.
core::Device GetDevice() const override { return device_; }

Expand Down
2 changes: 1 addition & 1 deletion cpp/tests/t/geometry/PointCloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ TEST_P(PointCloudPermuteDevices, HiddenPointRemoval) {
TEST_P(PointCloudPermuteDevices, PaintUniformColor) {
core::Device device = GetParam();

const t::geometry::PointCloud pcd_small(
t::geometry::PointCloud pcd_small(
core::Tensor::Init<double>({{1.0, 1.0, 1.0},
{1.1, 1.1, 1.1},
{1.2, 1.2, 1.2},
Expand Down

0 comments on commit 4eef4b3

Please sign in to comment.