From 7cf1c575bc859c44c3075e908a5eb40bdacf3f10 Mon Sep 17 00:00:00 2001 From: Saurabh Khanduja Date: Mon, 13 Nov 2023 00:00:20 +0100 Subject: [PATCH] Change invalid values of min_bound and max_bound as done in legacy, related pr #6444 --- cpp/open3d/t/geometry/BoundingVolume.cpp | 9 ++++++--- cpp/tests/t/geometry/AxisAlignedBoundingBox.cpp | 9 +++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cpp/open3d/t/geometry/BoundingVolume.cpp b/cpp/open3d/t/geometry/BoundingVolume.cpp index 0e529f27d1d..bf3e740779f 100644 --- a/cpp/open3d/t/geometry/BoundingVolume.cpp +++ b/cpp/open3d/t/geometry/BoundingVolume.cpp @@ -42,9 +42,12 @@ AxisAlignedBoundingBox::AxisAlignedBoundingBox(const core::Tensor &min_bound, // Check if the bounding box is valid. if (Volume() < 0) { - utility::LogError( - "Invalid axis-aligned bounding box. Please make sure all " - "the elements in max bound are larger than min bound."); + 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_.ToString(false), min_bound_.ToString(false)); + max_bound_ = open3d::core::Maximum(min_bound, max_bound); + min_bound_ = open3d::core::Minimum(min_bound, max_bound); } } diff --git a/cpp/tests/t/geometry/AxisAlignedBoundingBox.cpp b/cpp/tests/t/geometry/AxisAlignedBoundingBox.cpp index 333895493ba..144b837dc89 100644 --- a/cpp/tests/t/geometry/AxisAlignedBoundingBox.cpp +++ b/cpp/tests/t/geometry/AxisAlignedBoundingBox.cpp @@ -60,10 +60,6 @@ TEST_P(AxisAlignedBoundingBoxPermuteDevices, Constructor) { core::Tensor min_bound = core::Tensor::Init({-1, -1, -1}, device); core::Tensor max_bound = core::Tensor::Init({1, 1, 1}, device); - // Attempt to construct with invalid min/max bound. - EXPECT_THROW(t::geometry::AxisAlignedBoundingBox(max_bound, min_bound), - std::runtime_error); - t::geometry::AxisAlignedBoundingBox aabb(min_bound, max_bound); // Public members. @@ -76,6 +72,11 @@ TEST_P(AxisAlignedBoundingBoxPermuteDevices, Constructor) { core::Tensor::Init({1, 1, 1}, device))); EXPECT_EQ(aabb.GetDevice(), device); + + // Attempt to construct with invalid min/max bound should create a valid + // bounding box with a warning. + t::geometry::AxisAlignedBoundingBox aabb_invalid(max_bound, min_bound); + EXPECT_TRUE(aabb_invalid.GetBoxPoints().AllClose(aabb.GetBoxPoints())); } TEST_P(AxisAlignedBoundingBoxPermuteDevicePairs, CopyDevice) {