22#include < igl/vertex_components.h>
33#include < nanobind/nanobind.h>
44#include < nanobind/eigen/dense.h>
5+ #include < nanobind/eigen/sparse.h>
6+ #include < nanobind/stl/tuple.h>
57
68namespace nb = nanobind;
79using namespace nb ::literals;
@@ -16,6 +18,16 @@ namespace pyigl
1618 igl::vertex_components (F, C);
1719 return C;
1820 }
21+
22+ // Wrapper for vertex_components with adjacency matrix
23+ auto vertex_components_from_adjacency_matrix (
24+ const Eigen::SparseMatrixI &adjacency)
25+ {
26+ Eigen::VectorXI c;
27+ Eigen::VectorXI counts;
28+ igl::vertex_components (adjacency, c, counts);
29+ return std::make_tuple (c, counts);
30+ }
1931}
2032
2133// Bind the wrappers to the Python module
@@ -30,4 +42,13 @@ void bind_vertex_components(nb::module_ &m)
3042
3143@param[in] F Matrix of triangle indices
3244@return Vector C of component IDs per vertex)" );
33- }
45+
46+ m.def (
47+ " vertex_components_from_adjacency_matrix" ,
48+ &pyigl::vertex_components_from_adjacency_matrix,
49+ " adjacency" _a,
50+ R"( Compute the connected components of a graph using an adjacency matrix, returning component IDs and counts.
51+
52+ @param[in] adjacency n by n sparse adjacency matrix
53+ @return A tuple (c, counts) where c is an array of component ids (starting with 0) and counts is a #components array of counts for each component)" );
54+ }
0 commit comments