1#ifndef PBAT_GRAPH_CONNECTEDCOMPONENTS_H
2#define PBAT_GRAPH_CONNECTEDCOMPONENTS_H
6#include "pbat/graph/BreadthFirstSearch.h"
7#include "pbat/graph/DepthFirstSearch.h"
26template <common::CIndex TIndex,
class TDerivedP,
class TDerivedAdj>
28 Eigen::DenseBase<TDerivedP>
const& ptr,
29 Eigen::DenseBase<TDerivedAdj>
const& adj,
30 Eigen::Ref<Eigen::Vector<TIndex, Eigen::Dynamic>> components,
33 PBAT_PROFILE_NAMED_SCOPE(
"pbat.graph.ConnectedComponents");
34 Eigen::Index nVertices = ptr.size() - 1;
37 for (TIndex u = 0; u < nVertices; ++u)
39 if (components[u] < TIndex(0))
42 dfs(ptr, adj, u, [&](TIndex v) { components[v] = c; });
61template <common::CIndex TIndex,
class TDerivedP,
class TDerivedAdj>
63 Eigen::DenseBase<TDerivedP>
const& ptr,
64 Eigen::DenseBase<TDerivedAdj>
const& adj,
65 Eigen::Ref<Eigen::Vector<TIndex, Eigen::Dynamic>> components,
68 PBAT_PROFILE_NAMED_SCOPE(
"pbat.graph.ConnectedComponents");
69 Eigen::Index nVertices = ptr.size() - 1;
72 for (TIndex u = 0; u < nVertices; ++u)
74 if (components[u] < TIndex(0))
77 bfs(ptr, adj, u, [&](TIndex v) { components[v] = c; });
Concepts for common types.
Definition Adjacency.h:24
TIndex ConnectedComponents(Eigen::DenseBase< TDerivedP > const &ptr, Eigen::DenseBase< TDerivedAdj > const &adj, Eigen::Ref< Eigen::Vector< TIndex, Eigen::Dynamic > > components, DepthFirstSearch< TIndex > &dfs)
Compute connected components of a graph using depth-first search.
Definition ConnectedComponents.h:27
Profiling utilities for the Physics-Based Animation Toolkit (PBAT)
Definition BreadthFirstSearch.h:14
Eigen::Index NumVertices() const
Get the number of vertices in the graph.
Definition BreadthFirstSearch.h:50
Definition DepthFirstSearch.h:15
Eigen::Index NumVertices() const
Get the number of vertices in the graph.
Definition DepthFirstSearch.h:51