diff --git a/src/vertex_components.cpp b/src/vertex_components.cpp index 40be01c5..a17a306f 100644 --- a/src/vertex_components.cpp +++ b/src/vertex_components.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include namespace nb = nanobind; using namespace nb::literals; @@ -16,6 +18,16 @@ namespace pyigl igl::vertex_components(F, C); return C; } + + // Wrapper for vertex_components with adjacency matrix + auto vertex_components_from_adjacency_matrix( + const Eigen::SparseMatrixI &adjacency) + { + Eigen::VectorXI c; + Eigen::VectorXI counts; + igl::vertex_components(adjacency, c, counts); + return std::make_tuple(c, counts); + } } // Bind the wrappers to the Python module @@ -30,4 +42,13 @@ void bind_vertex_components(nb::module_ &m) @param[in] F Matrix of triangle indices @return Vector C of component IDs per vertex)"); -} + + m.def( + "vertex_components_from_adjacency_matrix", + &pyigl::vertex_components_from_adjacency_matrix, + "adjacency"_a, + R"(Compute the connected components of a graph using an adjacency matrix, returning component IDs and counts. + + @param[in] adjacency n by n sparse adjacency matrix + @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)"); +} \ No newline at end of file