added graph_find_components() to graph library
[swftools.git] / lib / graphcut.h
1 /*
2     graphcut- a graphcut implementation based on the Boykov Kolmogorov algorithm 
3     
4     Part of the swftools package.
5
6     Copyright (c) 2007,2008,2009 Matthias Kramm <kramm@quiss.org>
7
8     This program is free software: you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License
19     along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21 #ifndef __graphcut_h__
22 #define __graphcut_h__
23
24 typedef signed int weight_t;
25
26 typedef struct _halfedge halfedge_t;
27 typedef struct _node node_t;
28 typedef struct _graph graph_t;
29
30 struct _halfedge {
31     node_t*node;
32     struct _halfedge*fwd;
33     weight_t weight;
34     weight_t init_weight;
35     char used;
36     halfedge_t*next;
37 };
38
39 struct _node {
40     halfedge_t*edges;
41     int tmp;
42     int nr;
43 };
44
45 struct _graph {
46     node_t* nodes;
47     int num_nodes;
48 };
49
50 graph_t* graph_new(int num_nodes);
51 halfedge_t*graph_add_edge(node_t*from, node_t*to, weight_t forward_weight, weight_t backward_weight);
52 weight_t graph_maxflow(graph_t*graph, node_t*pos1, node_t*pos2);
53 int graph_find_components(graph_t*g);
54 void graph_delete(graph_t*);
55
56 #endif