diff --git a/CMakeLists.txt b/CMakeLists.txt index 265343ba..411357bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ option(LIBIGL_RESTRICTED_TRIANGLE "Build target igl_restricted::triangle" ON) FetchContent_Declare( libigl GIT_REPOSITORY https://github.com/libigl/libigl.git - GIT_TAG v2.6.0 + GIT_TAG cf9ed7f492209590c42dc7247281dfdfb6618487 ) FetchContent_MakeAvailable(libigl) diff --git a/src/OrientedBoundingBoxMinimizeType.cpp b/src/OrientedBoundingBoxMinimizeType.cpp new file mode 100644 index 00000000..86cadd1a --- /dev/null +++ b/src/OrientedBoundingBoxMinimizeType.cpp @@ -0,0 +1,20 @@ +#include "default_types.h" +#include +#include +#include +#include + +namespace nb = nanobind; +using namespace nb::literals; + + +void bind_OrientedBoundingBoxMinimizeType(nb::module_ &m) +{ + nb::enum_(m, "OrientedBoundingBoxMinimizeType") + .value("ORIENTED_BOUNDING_BOX_MINIMIZE_VOLUME", igl::ORIENTED_BOUNDING_BOX_MINIMIZE_VOLUME) + .value("ORIENTED_BOUNDING_BOX_MINIMIZE_SURFACE_AREA", igl::ORIENTED_BOUNDING_BOX_MINIMIZE_SURFACE_AREA) + .value("ORIENTED_BOUNDING_BOX_MINIMIZE_DIAGONAL_LENGTH", igl::ORIENTED_BOUNDING_BOX_MINIMIZE_DIAGONAL_LENGTH) + .export_values() + ; +} + diff --git a/src/copyleft/cgal/oriented_bounding_box.cpp b/src/copyleft/cgal/oriented_bounding_box.cpp new file mode 100644 index 00000000..b1965ea3 --- /dev/null +++ b/src/copyleft/cgal/oriented_bounding_box.cpp @@ -0,0 +1,40 @@ +#include "default_types.h" +#include +#include +#include +#include +#include + +namespace nb = nanobind; +using namespace nb::literals; + +namespace pyigl +{ + auto oriented_bounding_box( + const nb::DRef &P) + { + Eigen::MatrixXN R; + igl::copyleft::cgal::oriented_bounding_box(P, R); + return R; + } +} + +// Bind the wrapper to the Python module +void bind_oriented_bounding_box(nb::module_ &m) +{ + m.def( + "oriented_bounding_box", + &pyigl::oriented_bounding_box, + "P"_a, + R"(Given a set of points compute the rotation transformation of them such +that their axis-aligned bounding box is as small as possible. + +igl::oriented_bounding_box is often faster and better + + @param[in] P #P by 3 list of point locations + @param[out] R rotation matrix + )"); + +} + + diff --git a/src/oriented_bounding_box.cpp b/src/oriented_bounding_box.cpp new file mode 100644 index 00000000..feadb061 --- /dev/null +++ b/src/oriented_bounding_box.cpp @@ -0,0 +1,45 @@ +#include "default_types.h" +#include +#include +#include +#include +#include + +namespace nb = nanobind; +using namespace nb::literals; + +namespace pyigl +{ + auto oriented_bounding_box( + const nb::DRef &P, + const int n, + const igl::OrientedBoundingBoxMinimizeType minimize_type) + { + Eigen::MatrixXN R; + igl::oriented_bounding_box(P, n, minimize_type, R); + return R; + } +} + +// Bind the wrapper to the Python module +void bind_oriented_bounding_box(nb::module_ &m) +{ + m.def( + "oriented_bounding_box", + &pyigl::oriented_bounding_box, + "P"_a, + "n"_a=10000, + "minimize_type"_a=igl::ORIENTED_BOUNDING_BOX_MINIMIZE_VOLUME, +R"(Given a set of points compute the rotation transformation of them such +that their axis-aligned bounding box is as small as possible. + +Consider passing the points on the convex hull of original list of points. + + @param[in] P #P by 3 list of point locations + @param[in] n number of rotations to try + @param[in] minimize_type which quantity to minimize + @param[out] R rotation matrix + )"); + +} + diff --git a/src/remove_unreferenced.cpp b/src/remove_unreferenced.cpp index a23d6b16..17aafefa 100644 --- a/src/remove_unreferenced.cpp +++ b/src/remove_unreferenced.cpp @@ -33,6 +33,7 @@ void bind_remove_unreferenced(nb::module_ &m) R"(Remove unreferenced vertices from V, updating F accordingly @param[in] V #V by dim list of mesh vertex positions @param[in] F #F by ss list of simplices (Values of -1 are quitely skipped) +@param[out] NV #NV by dim list of simplices @param[out] NF #NF by ss list of simplices @param[out] I #V by 1 list of indices such that: NF = IM(F) and NT = IM(T) and V(find(IM<=size(NV,1)),:) = NV diff --git a/tests/test_all.py b/tests/test_all.py index 4dfd55eb..67aac710 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -491,6 +491,8 @@ def test_cgal(): point_indices, CH,CN,W = igl.octree(X) I = igl.knn(X,X,20,point_indices,CH,CN,W) A,T = igl.copyleft.cgal.point_areas(X,I,N) + + R = igl.copyleft.cgal.oriented_bounding_box(VC) def test_embree(): # octahedron @@ -553,6 +555,9 @@ def test_misc(): theta, cos_theta = igl.dihedral_angles_intrinsic(L,A) D = igl.all_pairs_distances(V,V,squared=False) D = igl.all_pairs_distances(V,V,squared=True) + R = igl.oriented_bounding_box(V) + R = igl.oriented_bounding_box(V,n=100,minimize_type=igl.ORIENTED_BOUNDING_BOX_MINIMIZE_SURFACE_AREA) +