-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathedges_to_path.cpp
More file actions
56 lines (49 loc) · 1.64 KB
/
edges_to_path.cpp
File metadata and controls
56 lines (49 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "default_types.h"
#include <igl/edges_to_path.h>
#include <nanobind/nanobind.h>
#include <nanobind/eigen/dense.h>
#include <nanobind/stl/tuple.h>
namespace nb = nanobind;
using namespace nb::literals;
namespace pyigl
{
// Wrapper for igl::edges_to_path
auto edges_to_path(const nb::DRef<const Eigen::MatrixXI> &E)
{
// libigl's implementation internally maps to an int-backed buffer,
// so ensure the input scalar type is 32-bit int to avoid Map pointer mismatches.
using MatXI32 = Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Options>;
using VecXI32 = Eigen::Matrix<int, Eigen::Dynamic, 1>;
MatXI32 Ei = E.template cast<int>();
VecXI32 Ii, Ji, Ki;
igl::edges_to_path(Ei, Ii, Ji, Ki);
Eigen::VectorXI I = Ii.template cast<Integer>();
Eigen::VectorXI J = Ji.template cast<Integer>();
Eigen::VectorXI K = Ki.template cast<Integer>();
return std::make_tuple(I, J, K);
}
}
// Bind the wrapper to the Python module
void bind_edges_to_path(nb::module_ &m)
{
m.def(
"edges_to_path",
&pyigl::edges_to_path,
"E"_a,
R"(Given a set of undirected, unique edges such that all form a
single connected component with exactly 0 or 2 nodes with valence = 1,
determine a path visiting all nodes.
Parameters
----------
E : (#E, 2) int array
Undirected edges
Returns
-------
I : (#E+1,) int array
Nodes in order tracing the chain (loop). If the output is a loop then I[0] == I[-1]
J : (#I-1,) int array
Indices into E of edges tracing I
K : (#I-1,) int array in {0,1}
Column indices so that I[i] == E[J[i], K[i]] for i < len(I)-1)"
);
}