TTK
Loading...
Searching...
No Matches
PersistentGenerators.cpp
Go to the documentation of this file.
2#include <UnionFind.h>
3
7
8void ttk::PersistentGenerators::getConnectedComponents(
9 const std::vector<std::array<SimplexId, 2>> &edgeNeighs,
10 std::vector<SimplexId> &connComp) const {
11
12 // use Union-Find to get connected components
13 std::vector<ttk::UnionFind> uf(connComp.size());
14
15 // initialize UFs
16 for(size_t j = 0; j < edgeNeighs.size(); ++j) {
17 uf[j].setRank(j);
18 }
19
20 // Union between adjacent edges
21 for(size_t j = 0; j < edgeNeighs.size(); ++j) {
22 ttk::UnionFind::makeUnion(&uf[j], &uf[edgeNeighs[j][0]]);
23 ttk::UnionFind::makeUnion(&uf[j], &uf[edgeNeighs[j][1]]);
24 }
25
26 // UF rank -> componend id mapping
27 std::vector<SimplexId> connCompIds(edgeNeighs.size(), -1);
28 size_t nConnComps{};
29
30 // find connected component ids
31 for(size_t j = 0; j < edgeNeighs.size(); ++j) {
32 const auto root{uf[j].find()};
33 if(root != nullptr) {
34 const auto rank{root->getRank()};
35 if(connCompIds[rank] == -1) {
36 connCompIds[rank] = nConnComps++;
37 }
38 connComp[j] = connCompIds[rank];
39 }
40 }
41}
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
static UnionFind * makeUnion(UnionFind *uf0, UnionFind *uf1)
Definition UnionFind.h:40