From 53915ba7dce735cc3686a1f50791658aec865f6f Mon Sep 17 00:00:00 2001 From: Sharon Berezalsky Date: Tue, 3 Sep 2024 16:43:14 +0300 Subject: [PATCH 1/6] Expose the static functions to the python API --- cpp/pybind/geometry/boundingvolume.cpp | 21 +++++++++++++++++++++ cpp/pybind/t/geometry/boundingvolume.cpp | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/cpp/pybind/geometry/boundingvolume.cpp b/cpp/pybind/geometry/boundingvolume.cpp index e178adfe19b..edf6fab7c22 100644 --- a/cpp/pybind/geometry/boundingvolume.cpp +++ b/cpp/pybind/geometry/boundingvolume.cpp @@ -83,6 +83,27 @@ The returned bounding box is an approximation to the minimal bounding box. open3d.geometry.OrientedBoundingBox: The oriented bounding box. The bounding box is oriented such that the axes are ordered with respect to the principal components. +)doc") + .def_static("create_from_points_minimal", + &OrientedBoundingBox::CreateFromPointsMinimal, "points"_a, + "robust"_a = false, + R"doc( +Creates the oriented bounding box with the smallest volume. + +The algorithm makes use of the fact that at least one edge of +the convex hull must be collinear with an edge of the minimum +bounding box: for each triangle in the convex hull, calculate +the minimal axis aligned box in the frame of that triangle. +at the end, return the box with the smallest volume + +Args: + points (open3d.utility.Vector3dVector): Input points. + robust (bool): If set to true uses a more robust method which works in + degenerate cases but introduces noise to the points coordinates. + +Returns: + open3d.geometry.OrientedBoundingBox: The oriented bounding box. The + bounding box is oriented such that its volume is minimized. )doc") .def("volume", &OrientedBoundingBox::Volume, "Returns the volume of the bounding box.") diff --git a/cpp/pybind/t/geometry/boundingvolume.cpp b/cpp/pybind/t/geometry/boundingvolume.cpp index 981b8f3dd46..314b4f267c2 100644 --- a/cpp/pybind/t/geometry/boundingvolume.cpp +++ b/cpp/pybind/t/geometry/boundingvolume.cpp @@ -353,6 +353,15 @@ The scaling center will be the box center if it is not specified.)", Note that this is only an approximation to the minimum oriented bounding box that could be computed for example with O'Rourke's algorithm (cf. http://cs.smith.edu/~jorourke/Papers/MinVolBox.pdf, https://www.geometrictools.com/Documentation/MinimumVolumeBox.pdf) +This is a wrapper for a CPU implementation.)", + "points"_a, "robust"_a = false); + obb.def_static("create_from_points_minimal", &OrientedBoundingBox::CreateFromPointsMinimal, + R"(Creates the oriented bounding box with the smallest volume. +The algorithm makes use of the fact that at least one edge of +the convex hull must be collinear with an edge of the minimum +bounding box: for each triangle in the convex hull, calculate +the minimal axis aligned box in the frame of that triangle. +at the end, return the box with the smallest volume. This is a wrapper for a CPU implementation.)", "points"_a, "robust"_a = false); @@ -411,6 +420,15 @@ This is a wrapper for a CPU implementation.)", "If set to true uses a more robust method which works in " "degenerate cases but introduces noise to the points " "coordinates."}}); + docstring::ClassMethodDocInject( + m, "OrientedBoundingBox", "create_from_points_minimal", + {{"points", + "A list of points with data type of float32 or float64 (N x 3 " + "tensor, where N must be larger than 3)."}, + {"robust", + "If set to true uses a more robust method which works in " + "degenerate cases but introduces noise to the points " + "coordinates."}}); } } // namespace geometry From 5d600ea7a4fd55957cb0d9e9f06b13bb64923d77 Mon Sep 17 00:00:00 2001 From: Sharon Berezalsky Date: Tue, 3 Sep 2024 16:57:40 +0300 Subject: [PATCH 2/6] Change the function name --- cpp/pybind/geometry/boundingvolume.cpp | 2 +- cpp/pybind/t/geometry/boundingvolume.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/pybind/geometry/boundingvolume.cpp b/cpp/pybind/geometry/boundingvolume.cpp index edf6fab7c22..eda2f275679 100644 --- a/cpp/pybind/geometry/boundingvolume.cpp +++ b/cpp/pybind/geometry/boundingvolume.cpp @@ -84,7 +84,7 @@ The returned bounding box is an approximation to the minimal bounding box. bounding box is oriented such that the axes are ordered with respect to the principal components. )doc") - .def_static("create_from_points_minimal", + .def_static("create_minimal_from_points", &OrientedBoundingBox::CreateFromPointsMinimal, "points"_a, "robust"_a = false, R"doc( diff --git a/cpp/pybind/t/geometry/boundingvolume.cpp b/cpp/pybind/t/geometry/boundingvolume.cpp index 314b4f267c2..2dd484a7802 100644 --- a/cpp/pybind/t/geometry/boundingvolume.cpp +++ b/cpp/pybind/t/geometry/boundingvolume.cpp @@ -355,7 +355,7 @@ that could be computed for example with O'Rourke's algorithm (cf. http://cs.smith.edu/~jorourke/Papers/MinVolBox.pdf, https://www.geometrictools.com/Documentation/MinimumVolumeBox.pdf) This is a wrapper for a CPU implementation.)", "points"_a, "robust"_a = false); - obb.def_static("create_from_points_minimal", &OrientedBoundingBox::CreateFromPointsMinimal, + obb.def_static("create_minimal_from_points", &OrientedBoundingBox::CreateFromPointsMinimal, R"(Creates the oriented bounding box with the smallest volume. The algorithm makes use of the fact that at least one edge of the convex hull must be collinear with an edge of the minimum @@ -421,7 +421,7 @@ This is a wrapper for a CPU implementation.)", "degenerate cases but introduces noise to the points " "coordinates."}}); docstring::ClassMethodDocInject( - m, "OrientedBoundingBox", "create_from_points_minimal", + m, "OrientedBoundingBox", "create_minimal_from_points", {{"points", "A list of points with data type of float32 or float64 (N x 3 " "tensor, where N must be larger than 3)."}, From dc05a8c20b4b397e3e629c9e51a5170edbaf7568 Mon Sep 17 00:00:00 2001 From: Sharon Berezalsky Date: Tue, 3 Sep 2024 16:59:09 +0300 Subject: [PATCH 3/6] Fixed the format --- cpp/pybind/t/geometry/boundingvolume.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cpp/pybind/t/geometry/boundingvolume.cpp b/cpp/pybind/t/geometry/boundingvolume.cpp index 2dd484a7802..ab215383d80 100644 --- a/cpp/pybind/t/geometry/boundingvolume.cpp +++ b/cpp/pybind/t/geometry/boundingvolume.cpp @@ -421,14 +421,14 @@ This is a wrapper for a CPU implementation.)", "degenerate cases but introduces noise to the points " "coordinates."}}); docstring::ClassMethodDocInject( - m, "OrientedBoundingBox", "create_minimal_from_points", - {{"points", - "A list of points with data type of float32 or float64 (N x 3 " - "tensor, where N must be larger than 3)."}, - {"robust", - "If set to true uses a more robust method which works in " - "degenerate cases but introduces noise to the points " - "coordinates."}}); + m, "OrientedBoundingBox", "create_minimal_from_points", + {{"points", + "A list of points with data type of float32 or float64 (N x 3 " + "tensor, where N must be larger than 3)."}, + {"robust", + "If set to true uses a more robust method which works in " + "degenerate cases but introduces noise to the points " + "coordinates."}}); } } // namespace geometry From 78b8eba5a2968e771836484bd9c09b3e93034eb1 Mon Sep 17 00:00:00 2001 From: Sharon Berezalsky Date: Tue, 3 Sep 2024 17:17:24 +0300 Subject: [PATCH 4/6] Apply formatter --- cpp/pybind/geometry/boundingvolume.cpp | 4 ++-- cpp/pybind/t/geometry/boundingvolume.cpp | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cpp/pybind/geometry/boundingvolume.cpp b/cpp/pybind/geometry/boundingvolume.cpp index eda2f275679..52c52c4ec9c 100644 --- a/cpp/pybind/geometry/boundingvolume.cpp +++ b/cpp/pybind/geometry/boundingvolume.cpp @@ -85,8 +85,8 @@ The returned bounding box is an approximation to the minimal bounding box. the principal components. )doc") .def_static("create_minimal_from_points", - &OrientedBoundingBox::CreateFromPointsMinimal, "points"_a, - "robust"_a = false, + &OrientedBoundingBox::CreateFromPointsMinimal, + "points"_a, "robust"_a = false, R"doc( Creates the oriented bounding box with the smallest volume. diff --git a/cpp/pybind/t/geometry/boundingvolume.cpp b/cpp/pybind/t/geometry/boundingvolume.cpp index ab215383d80..58800d925f8 100644 --- a/cpp/pybind/t/geometry/boundingvolume.cpp +++ b/cpp/pybind/t/geometry/boundingvolume.cpp @@ -355,15 +355,17 @@ that could be computed for example with O'Rourke's algorithm (cf. http://cs.smith.edu/~jorourke/Papers/MinVolBox.pdf, https://www.geometrictools.com/Documentation/MinimumVolumeBox.pdf) This is a wrapper for a CPU implementation.)", "points"_a, "robust"_a = false); - obb.def_static("create_minimal_from_points", &OrientedBoundingBox::CreateFromPointsMinimal, - R"(Creates the oriented bounding box with the smallest volume. + obb.def_static( + "create_minimal_from_points", + &OrientedBoundingBox::CreateFromPointsMinimal, + R"(Creates the oriented bounding box with the smallest volume. The algorithm makes use of the fact that at least one edge of the convex hull must be collinear with an edge of the minimum bounding box: for each triangle in the convex hull, calculate the minimal axis aligned box in the frame of that triangle. at the end, return the box with the smallest volume. This is a wrapper for a CPU implementation.)", - "points"_a, "robust"_a = false); + "points"_a, "robust"_a = false); docstring::ClassMethodDocInject( m, "OrientedBoundingBox", "set_center", From e90cbc667c3a5558411774e1a65542908d067f60 Mon Sep 17 00:00:00 2001 From: Sharon Berezalsky Date: Tue, 3 Sep 2024 17:41:35 +0300 Subject: [PATCH 5/6] Revert the tensor version --- cpp/pybind/t/geometry/boundingvolume.cpp | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/cpp/pybind/t/geometry/boundingvolume.cpp b/cpp/pybind/t/geometry/boundingvolume.cpp index 58800d925f8..981b8f3dd46 100644 --- a/cpp/pybind/t/geometry/boundingvolume.cpp +++ b/cpp/pybind/t/geometry/boundingvolume.cpp @@ -355,17 +355,6 @@ that could be computed for example with O'Rourke's algorithm (cf. http://cs.smith.edu/~jorourke/Papers/MinVolBox.pdf, https://www.geometrictools.com/Documentation/MinimumVolumeBox.pdf) This is a wrapper for a CPU implementation.)", "points"_a, "robust"_a = false); - obb.def_static( - "create_minimal_from_points", - &OrientedBoundingBox::CreateFromPointsMinimal, - R"(Creates the oriented bounding box with the smallest volume. -The algorithm makes use of the fact that at least one edge of -the convex hull must be collinear with an edge of the minimum -bounding box: for each triangle in the convex hull, calculate -the minimal axis aligned box in the frame of that triangle. -at the end, return the box with the smallest volume. -This is a wrapper for a CPU implementation.)", - "points"_a, "robust"_a = false); docstring::ClassMethodDocInject( m, "OrientedBoundingBox", "set_center", @@ -422,15 +411,6 @@ This is a wrapper for a CPU implementation.)", "If set to true uses a more robust method which works in " "degenerate cases but introduces noise to the points " "coordinates."}}); - docstring::ClassMethodDocInject( - m, "OrientedBoundingBox", "create_minimal_from_points", - {{"points", - "A list of points with data type of float32 or float64 (N x 3 " - "tensor, where N must be larger than 3)."}, - {"robust", - "If set to true uses a more robust method which works in " - "degenerate cases but introduces noise to the points " - "coordinates."}}); } } // namespace geometry From 615b36d79291ef5d780f7fa6e8127bc46abb2056 Mon Sep 17 00:00:00 2001 From: Sharon Berezalsky Date: Wed, 4 Sep 2024 09:43:26 +0300 Subject: [PATCH 6/6] Rename the function name to match the C++ function name --- cpp/pybind/geometry/boundingvolume.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/pybind/geometry/boundingvolume.cpp b/cpp/pybind/geometry/boundingvolume.cpp index 52c52c4ec9c..4ffcbf8a52d 100644 --- a/cpp/pybind/geometry/boundingvolume.cpp +++ b/cpp/pybind/geometry/boundingvolume.cpp @@ -84,7 +84,7 @@ The returned bounding box is an approximation to the minimal bounding box. bounding box is oriented such that the axes are ordered with respect to the principal components. )doc") - .def_static("create_minimal_from_points", + .def_static("create_from_points_minimal", &OrientedBoundingBox::CreateFromPointsMinimal, "points"_a, "robust"_a = false, R"doc(