X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fgraphcut.c;fp=lib%2Fgraphcut.c;h=93ff79cbac7281c6c6672a8e5a301b2346d4daec;hb=062138c37383ec48082037f0610b7c8da41f6d0d;hp=641fa61a27c9f12260625674e2db566fcc45d3aa;hpb=21630ba77e5b648554e06dff2a5117811d30b80b;p=swftools.git diff --git a/lib/graphcut.c b/lib/graphcut.c index 641fa61..93ff79c 100644 --- a/lib/graphcut.c +++ b/lib/graphcut.c @@ -625,6 +625,33 @@ halfedge_t*graph_add_edge(node_t*from, node_t*to, weight_t forward_weight, weigh return e1; } +static void do_dfs(node_t*n, int color) +{ + int t; + n->tmp = color; + halfedge_t*e = n->edges; + while(e) { + if(e->fwd->node->tmp<0) + do_dfs(e->fwd->node, color); + e = e->next; + } +} + +int graph_find_components(graph_t*g) +{ + int t; + int count = 0; + for(t=0;tnum_nodes;t++) { + g->nodes[t].tmp = -1; + } + for(t=0;tnum_nodes;t++) { + if(g->nodes[t].tmp<0) { + do_dfs(&g->nodes[t], count++); + } + } + return count; +} + #ifdef MAIN int main() {