Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/vertex_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <igl/vertex_components.h>
#include <nanobind/nanobind.h>
#include <nanobind/eigen/dense.h>
#include <nanobind/eigen/sparse.h>
#include <nanobind/stl/tuple.h>

namespace nb = nanobind;
using namespace nb::literals;
Expand All @@ -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
Expand All @@ -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)");
}
Loading