31 const int UNLABELED{-2};
51 template <
typename TT = ttk::AbstractTriangulation>
53 std::vector<Component> &components,
55 const TT *triangulation,
56 const TID seed)
const {
58 const TID componentId = components.size();
60 std::stack<TID> stack;
62 labels[seed] = componentId;
67 float center[3] = {0, 0, 0};
69 while(!stack.empty()) {
70 const auto cIndex = stack.top();
73 id = std::max(cIndex,
id);
76 triangulation->getVertexPoint(cIndex, x, y, z);
83 size_t const nNeighbors
84 = triangulation->getVertexNeighborNumber(cIndex);
85 for(
size_t i = 0; i < nNeighbors; i++) {
87 triangulation->getVertexNeighbor(cIndex, i, nIndex);
88 if(labels[nIndex] == this->UNLABELED) {
89 labels[nIndex] = componentId;
99 components.resize(componentId + 1);
100 auto &c = components[componentId];
101 std::copy(center, center + 3, c.center);
108 template <
typename DT>
111 const DT *featureMask =
nullptr,
112 const DT backgroundThreshold = 0)
const {
114 std::string
const msg
116 + std::string(featureMask
117 ? (
" with BT: " + std::to_string(backgroundThreshold))
121 for(TID i = 0; i < nVertices; i++)
122 componentIds[i] = featureMask[i] > backgroundThreshold
126 std::fill(componentIds, componentIds + nVertices, this->UNLABELED);
133 template <
typename TT = ttk::AbstractTriangulation>
136 const TT *triangulation)
const {
138 TID
const nVertices = triangulation->getNumberOfVertices();
141 const std::string msg =
"Computing Connected Components";
144 for(TID i = 0; i < nVertices; i++)
145 if(componentIds[i] == this->UNLABELED)
146 this->computeFloodFill<TT>(
147 componentIds, components, triangulation, i);
154 template <
typename F,
typename DT>
155 int mapData(std::vector<Component> &components,
156 const int *componentIds,
160 for(TID i = 0; i < nVertices; i++)
161 out[i] = f(components, componentIds[i]);
AbstractTriangulation is an interface class that defines an interface for efficient traversal methods...
virtual int preconditionVertexNeighbors()
TTK connectedComponents processing package.
int computeFloodFill(int *labels, std::vector< Component > &components, const TT *triangulation, const TID seed) const
int preconditionTriangulation(ttk::AbstractTriangulation *triangulation) const
int computeConnectedComponents(std::vector< Component > &components, int *componentIds, const TT *triangulation) const
int initializeComponentIds(int *componentIds, const TID nVertices, const DT *featureMask=nullptr, const DT backgroundThreshold=0) const
int mapData(std::vector< Component > &components, const int *componentIds, const int nVertices, const F f, DT *out) const
~ConnectedComponents() override=default
Minimalist debugging class.
void setDebugMsgPrefix(const std::string &prefix)
int SimplexId
Identifier type for simplices of any dimension.
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)