Skip to content

Commit 1119fd4

Browse files
authored
Merge pull request #270 from libigl/alecjacobson/obb
oriented bounding box functions
2 parents 9fc5a36 + 5b36424 commit 1119fd4

File tree

6 files changed

+112
-1
lines changed

6 files changed

+112
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ option(LIBIGL_RESTRICTED_TRIANGLE "Build target igl_restricted::triangle" ON)
4545
FetchContent_Declare(
4646
libigl
4747
GIT_REPOSITORY https://github.com/libigl/libigl.git
48-
GIT_TAG v2.6.0
48+
GIT_TAG cf9ed7f492209590c42dc7247281dfdfb6618487
4949
)
5050
FetchContent_MakeAvailable(libigl)
5151

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "default_types.h"
2+
#include <igl/oriented_bounding_box.h>
3+
#include <nanobind/nanobind.h>
4+
#include <nanobind/ndarray.h>
5+
#include <nanobind/eigen/dense.h>
6+
7+
namespace nb = nanobind;
8+
using namespace nb::literals;
9+
10+
11+
void bind_OrientedBoundingBoxMinimizeType(nb::module_ &m)
12+
{
13+
nb::enum_<igl::OrientedBoundingBoxMinimizeType>(m, "OrientedBoundingBoxMinimizeType")
14+
.value("ORIENTED_BOUNDING_BOX_MINIMIZE_VOLUME", igl::ORIENTED_BOUNDING_BOX_MINIMIZE_VOLUME)
15+
.value("ORIENTED_BOUNDING_BOX_MINIMIZE_SURFACE_AREA", igl::ORIENTED_BOUNDING_BOX_MINIMIZE_SURFACE_AREA)
16+
.value("ORIENTED_BOUNDING_BOX_MINIMIZE_DIAGONAL_LENGTH", igl::ORIENTED_BOUNDING_BOX_MINIMIZE_DIAGONAL_LENGTH)
17+
.export_values()
18+
;
19+
}
20+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "default_types.h"
2+
#include <igl/copyleft/cgal/oriented_bounding_box.h>
3+
#include <nanobind/nanobind.h>
4+
#include <nanobind/ndarray.h>
5+
#include <nanobind/eigen/dense.h>
6+
#include <nanobind/stl/tuple.h>
7+
8+
namespace nb = nanobind;
9+
using namespace nb::literals;
10+
11+
namespace pyigl
12+
{
13+
auto oriented_bounding_box(
14+
const nb::DRef<const Eigen::MatrixXN> &P)
15+
{
16+
Eigen::MatrixXN R;
17+
igl::copyleft::cgal::oriented_bounding_box(P, R);
18+
return R;
19+
}
20+
}
21+
22+
// Bind the wrapper to the Python module
23+
void bind_oriented_bounding_box(nb::module_ &m)
24+
{
25+
m.def(
26+
"oriented_bounding_box",
27+
&pyigl::oriented_bounding_box,
28+
"P"_a,
29+
R"(Given a set of points compute the rotation transformation of them such
30+
that their axis-aligned bounding box is as small as possible.
31+
32+
igl::oriented_bounding_box is often faster and better
33+
34+
@param[in] P #P by 3 list of point locations
35+
@param[out] R rotation matrix
36+
)");
37+
38+
}
39+
40+

src/oriented_bounding_box.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "default_types.h"
2+
#include <igl/oriented_bounding_box.h>
3+
#include <nanobind/nanobind.h>
4+
#include <nanobind/ndarray.h>
5+
#include <nanobind/eigen/dense.h>
6+
#include <nanobind/stl/tuple.h>
7+
8+
namespace nb = nanobind;
9+
using namespace nb::literals;
10+
11+
namespace pyigl
12+
{
13+
auto oriented_bounding_box(
14+
const nb::DRef<const Eigen::MatrixXN> &P,
15+
const int n,
16+
const igl::OrientedBoundingBoxMinimizeType minimize_type)
17+
{
18+
Eigen::MatrixXN R;
19+
igl::oriented_bounding_box(P, n, minimize_type, R);
20+
return R;
21+
}
22+
}
23+
24+
// Bind the wrapper to the Python module
25+
void bind_oriented_bounding_box(nb::module_ &m)
26+
{
27+
m.def(
28+
"oriented_bounding_box",
29+
&pyigl::oriented_bounding_box,
30+
"P"_a,
31+
"n"_a=10000,
32+
"minimize_type"_a=igl::ORIENTED_BOUNDING_BOX_MINIMIZE_VOLUME,
33+
R"(Given a set of points compute the rotation transformation of them such
34+
that their axis-aligned bounding box is as small as possible.
35+
36+
Consider passing the points on the convex hull of original list of points.
37+
38+
@param[in] P #P by 3 list of point locations
39+
@param[in] n number of rotations to try
40+
@param[in] minimize_type which quantity to minimize
41+
@param[out] R rotation matrix
42+
)");
43+
44+
}
45+

src/remove_unreferenced.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void bind_remove_unreferenced(nb::module_ &m)
3333
R"(Remove unreferenced vertices from V, updating F accordingly
3434
@param[in] V #V by dim list of mesh vertex positions
3535
@param[in] F #F by ss list of simplices (Values of -1 are quitely skipped)
36+
@param[out] NV #NV by dim list of simplices
3637
@param[out] NF #NF by ss list of simplices
3738
@param[out] I #V by 1 list of indices such that: NF = IM(F) and NT = IM(T)
3839
and V(find(IM<=size(NV,1)),:) = NV

tests/test_all.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ def test_cgal():
491491
point_indices, CH,CN,W = igl.octree(X)
492492
I = igl.knn(X,X,20,point_indices,CH,CN,W)
493493
A,T = igl.copyleft.cgal.point_areas(X,I,N)
494+
495+
R = igl.copyleft.cgal.oriented_bounding_box(VC)
494496

495497
def test_embree():
496498
# octahedron
@@ -553,6 +555,9 @@ def test_misc():
553555
theta, cos_theta = igl.dihedral_angles_intrinsic(L,A)
554556
D = igl.all_pairs_distances(V,V,squared=False)
555557
D = igl.all_pairs_distances(V,V,squared=True)
558+
R = igl.oriented_bounding_box(V)
559+
R = igl.oriented_bounding_box(V,n=100,minimize_type=igl.ORIENTED_BOUNDING_BOX_MINIMIZE_SURFACE_AREA)
560+
556561

557562

558563

0 commit comments

Comments
 (0)