Skip to content

Commit 80c7653

Browse files
committed
Add hessian and hessian energy functions to bindings
1 parent 0fbf1c9 commit 80c7653

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed

src/curved_hessian_energy.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/curved_hessian_energy.h>
3+
#include <nanobind/nanobind.h>
4+
#include <nanobind/ndarray.h>
5+
#include <nanobind/eigen/dense.h>
6+
#include <nanobind/eigen/sparse.h>
7+
#include <nanobind/stl/tuple.h>
8+
9+
namespace nb = nanobind;
10+
using namespace nb::literals;
11+
12+
namespace pyigl
13+
{
14+
auto curved_hessian_energy(
15+
const nb::DRef<const Eigen::MatrixXN> &V,
16+
const nb::DRef<const Eigen::MatrixXI> &F)
17+
{
18+
Eigen::SparseMatrixN QH;
19+
igl::curved_hessian_energy(V,F,QH);
20+
return QH;
21+
}
22+
23+
}
24+
25+
// Bind the wrapper to the Python module
26+
void bind_curved_hessian_energy(nb::module_ &m)
27+
{
28+
m.def(
29+
"curved_hessian_energy",
30+
&pyigl::curved_hessian_energy,
31+
"V"_a,
32+
"F"_a,
33+
R"(Constructs the matrix for the curved Hessian energy for a given
34+
mesh (V,F).
35+
36+
@tparam DerivedV derived type of eigen matrix for V (e.g. derived from
37+
MatrixXd)
38+
@tparam DerivedF derived type of eigen matrix for F (e.g. derived from
39+
MatrixXi)
40+
@tparam Scalar scalar type for eigen sparse matrix (e.g. double)
41+
@param[in] V #V by dim list of mesh vertex positions
42+
@param[in] F #F by simplex_size list of mesh elements (triangles or tetrahedra)
43+
@param[out] QH #V by #V curved Hessian energy matrix, each row i corresponding to V(i,:))");
44+
45+
}

src/hessian.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/hessian.h>
3+
#include <nanobind/nanobind.h>
4+
#include <nanobind/ndarray.h>
5+
#include <nanobind/eigen/dense.h>
6+
#include <nanobind/eigen/sparse.h>
7+
#include <nanobind/stl/tuple.h>
8+
9+
namespace nb = nanobind;
10+
using namespace nb::literals;
11+
12+
namespace pyigl
13+
{
14+
auto hessian(
15+
const nb::DRef<const Eigen::MatrixXN> &V,
16+
const nb::DRef<const Eigen::MatrixXI> &F)
17+
{
18+
Eigen::SparseMatrixN H;
19+
igl::hessian(V,F,H);
20+
return H;
21+
}
22+
23+
}
24+
25+
// Bind the wrapper to the Python module
26+
void bind_hessian(nb::module_ &m)
27+
{
28+
m.def(
29+
"hessian",
30+
&pyigl::hessian,
31+
"V"_a,
32+
"F"_a,
33+
R"(Constructs the Hessian matrix for a given
34+
mesh (V,F).
35+
36+
@tparam DerivedV derived type of eigen matrix for V (e.g. derived from
37+
MatrixXd)
38+
@tparam DerivedF derived type of eigen matrix for F (e.g. derived from
39+
MatrixXi)
40+
@tparam Scalar scalar type for eigen sparse matrix (e.g. double)
41+
@param[in] V #V by dim list of mesh vertex positions
42+
@param[in] F #F by simplex_size list of mesh elements (triangles or tetrahedra)
43+
@param[out] H #V by #V Hessian matrix, each row i corresponding to V(i,:))");
44+
45+
}

src/hessian_energy.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/hessian_energy.h>
3+
#include <nanobind/nanobind.h>
4+
#include <nanobind/ndarray.h>
5+
#include <nanobind/eigen/dense.h>
6+
#include <nanobind/eigen/sparse.h>
7+
#include <nanobind/stl/tuple.h>
8+
9+
namespace nb = nanobind;
10+
using namespace nb::literals;
11+
12+
namespace pyigl
13+
{
14+
auto hessian_energy(
15+
const nb::DRef<const Eigen::MatrixXN> &V,
16+
const nb::DRef<const Eigen::MatrixXI> &F)
17+
{
18+
Eigen::SparseMatrixN QH;
19+
igl::hessian_energy(V,F,QH);
20+
return QH;
21+
}
22+
23+
}
24+
25+
// Bind the wrapper to the Python module
26+
void bind_hessian_energy(nb::module_ &m)
27+
{
28+
m.def(
29+
"hessian_energy",
30+
&pyigl::hessian_energy,
31+
"V"_a,
32+
"F"_a,
33+
R"(Constructs the matrix for the Hessian energy for a given
34+
mesh (V,F).
35+
36+
@tparam DerivedV derived type of eigen matrix for V (e.g. derived from
37+
MatrixXd)
38+
@tparam DerivedF derived type of eigen matrix for F (e.g. derived from
39+
MatrixXi)
40+
@tparam Scalar scalar type for eigen sparse matrix (e.g. double)
41+
@param[in] V #V by dim list of mesh vertex positions
42+
@param[in] F #F by simplex_size list of mesh elements (triangles or tetrahedra)
43+
@param[out] QH #V by #V Hessian energy matrix, each row i corresponding to V(i,:))");
44+
45+
}

tests/test_all.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def test_operators():
109109
K = igl.cotmatrix_entries(l=l)
110110
B1,B2,B3 = igl.local_basis(V,F)
111111
G = igl.grad(V,F)
112+
H = igl.hessian(V, F)
113+
QH = igl.hessian_energy(V, F)
114+
cQH = igl.curved_hessian_energy(V, F)
112115

113116
M = igl.massmatrix(V,F)
114117
M = igl.massmatrix(V,F,type=igl.MASSMATRIX_TYPE_BARYCENTRIC)

0 commit comments

Comments
 (0)