added graphcut 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 #include "image.h"
25
26 typedef signed int weight_t;
27 #define MAX_WEIGHT 0x07ffffff
28
29 typedef struct _halfedge halfedge_t;
30 typedef struct _node node_t;
31 typedef struct _graph graph_t;
32
33 struct _halfedge {
34     node_t*node;
35     struct _halfedge*fwd;
36     weight_t weight;
37     char used;
38     halfedge_t*next;
39 };
40
41 struct _node {
42     halfedge_t*edges;
43     int nr;
44 };
45
46 struct _graph {
47     node_t* nodes;
48     int num_nodes;
49 };
50
51 graph_t* graph_new(int num_nodes);
52 halfedge_t*edge_new(node_t*from, node_t*to, weight_t forward_weight, weight_t backward_weight);
53 weight_t graph_maxflow(graph_t*graph, node_t*pos1, node_t*pos2);
54 void graph_delete(graph_t*);
55
56 #endif