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

Correct bound check for axis aligned bounding box and use same formatting for printing cuda or cpu tensor #6444

Merged
merged 4 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Changed TriangleMesh to store materials in a list so they can be accessed by the material index (PR #5938)
* Support multi-threading in the RayCastingScene function to commit scene (PR #6051).
* Fix some bad triangle generation in TriangleMesh::SimplifyQuadricDecimation
* Fix printing of tensor in gpu and add validation check for bounds of axis-aligned bounding box (PR #6444)

## 0.13

Expand Down
2 changes: 1 addition & 1 deletion cpp/open3d/core/Tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ std::string Tensor::ToString(bool with_suffix,
std::ostringstream rc;
if (IsCUDA() || !IsContiguous()) {
Tensor host_contiguous_tensor = Contiguous().To(Device("CPU:0"));
rc << host_contiguous_tensor.ToString(false, "");
rc << host_contiguous_tensor.ToString(with_suffix, indent);
Copy link
Contributor Author

@saurabheights saurabheights Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I added a regression here. with_suffix should be set to false, else it will print suffix twice. once in inner call where tensor is moved to CPU and once in outer call.

Example -

o3d.core.Tensor.eye(n=4, dtype=o3d.core.Dtype.Float64, device=o3d.core.Device('cuda:0'))
[[1 0 0 0],
 [0 1 0 0],
 [0 0 1 0],
 [0 0 0 1]]
Tensor[shape={4, 4}, stride={4, 1}, Float64, CPU:0, 0x561c38e195d0]
Tensor[shape={4, 4}, stride={4, 1}, Float64, CUDA:0, 0x302000000]

I will address this in my next PR.

} else {
if (shape_.NumElements() == 0) {
rc << indent;
Expand Down
16 changes: 16 additions & 0 deletions cpp/open3d/geometry/BoundingVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,22 @@ OrientedBoundingBox AxisAlignedBoundingBox::GetMinimalOrientedBoundingBox(
return OrientedBoundingBox::CreateFromAxisAlignedBoundingBox(*this);
}

AxisAlignedBoundingBox::AxisAlignedBoundingBox(const Eigen::Vector3d& min_bound,
const Eigen::Vector3d& max_bound)
: Geometry3D(Geometry::GeometryType::AxisAlignedBoundingBox),
min_bound_(min_bound),
max_bound_(max_bound),
color_(1, 1, 1) {
if ((max_bound_.array() < min_bound_.array()).any()) {
open3d::utility::LogWarning(
"max_bound {} of bounding box is smaller than min_bound {} in "
"one or more axes. Fix input values to remove this warning.",
max_bound_, min_bound_);
max_bound_ = max_bound.cwiseMax(min_bound);
min_bound_ = max_bound.cwiseMin(min_bound);
}
}

AxisAlignedBoundingBox& AxisAlignedBoundingBox::Transform(
const Eigen::Matrix4d& transformation) {
utility::LogError(
Expand Down
6 changes: 1 addition & 5 deletions cpp/open3d/geometry/BoundingVolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ class AxisAlignedBoundingBox : public Geometry3D {
/// \param min_bound Lower bounds of the bounding box for all axes.
/// \param max_bound Upper bounds of the bounding box for all axes.
AxisAlignedBoundingBox(const Eigen::Vector3d& min_bound,
const Eigen::Vector3d& max_bound)
: Geometry3D(Geometry::GeometryType::AxisAlignedBoundingBox),
min_bound_(min_bound),
max_bound_(max_bound),
color_(1, 1, 1) {}
const Eigen::Vector3d& max_bound);
~AxisAlignedBoundingBox() override {}

public:
Expand Down
Loading