allow to reset a graphcut graph
authorMatthias Kramm <kramm@quiss.org>
Wed, 25 Nov 2009 20:23:35 +0000 (12:23 -0800)
committerMatthias Kramm <kramm@quiss.org>
Wed, 25 Nov 2009 20:34:23 +0000 (12:34 -0800)
lib/devices/swf.c
lib/graphcut.c
lib/graphcut.h

index a3f57e9..8d557da 100644 (file)
@@ -114,6 +114,7 @@ typedef struct _swfoutput_internal
     int config_bboxvars;
     int config_disable_polygon_conversion;
     int config_normalize_polygon_positions;
+    int config_alignfonts;
     char config_disablelinks;
     RGBA config_linkcolor;
     float config_minlinewidth;
@@ -1479,7 +1480,7 @@ void swfoutput_finalize(gfxdevice_t*dev)
     while(iterator) {
        TAG*mtag = i->swf->firstTag;
        if(iterator->swffont) {
-           if(use_font3) {
+           if(use_font3 && i->config_alignfonts) {
                // needs to be done before the reduce
                swf_FontCreateAlignZones(iterator->swffont);
            }
index fd6da5a..641fa61 100644 (file)
@@ -393,7 +393,7 @@ static weight_t decrease_weights(graph_t*map, path_t*path)
     }
     assert(min);
     if(min<=0) 
-        return;
+        return 0;
 
     for(t=0;t<path->length-1;t++) {
        path->dir[t]->weight-=min;
@@ -530,12 +530,28 @@ static void check_graph(graph_t*g)
     }
 }
 
+void graph_reset(graph_t*g)
+{
+    int t;
+    for(t=0;t<g->num_nodes;t++) {
+       g->nodes[t].nr = t;
+       assert(g->nodes[t].nr==t);
+       halfedge_t*e = g->nodes[t].edges;
+       while(e) {
+           e->used = 0;
+           e->weight = e->init_weight;
+           e = e->next;
+       }
+    }
+}
+
 weight_t graph_maxflow(graph_t*graph, node_t*pos1, node_t*pos2)
 {
     int max_flow = 0;
     graphcut_workspace_t* w = graphcut_workspace_new(graph, pos1, pos2);
 
-    check_graph(graph);
+    graph_reset(graph);
+    DBG check_graph(graph);
    
     posqueue_addpos(w->queue1, pos1); w->flags1[pos1->nr] |= ACTIVE|IN_TREE; 
     posqueue_addpos(w->queue2, pos2); w->flags2[pos2->nr] |= ACTIVE|IN_TREE; 
@@ -589,7 +605,7 @@ weight_t graph_maxflow(graph_t*graph, node_t*pos1, node_t*pos2)
     return max_flow;
 }
 
-halfedge_t*edge_new(node_t*from, node_t*to, weight_t forward_weight, weight_t backward_weight)
+halfedge_t*graph_add_edge(node_t*from, node_t*to, weight_t forward_weight, weight_t backward_weight)
 {
     halfedge_t*e1 = (halfedge_t*)rfx_calloc(sizeof(halfedge_t));
     halfedge_t*e2 = (halfedge_t*)rfx_calloc(sizeof(halfedge_t));
@@ -597,6 +613,8 @@ halfedge_t*edge_new(node_t*from, node_t*to, weight_t forward_weight, weight_t ba
     e2->fwd = e1;
     e1->node = from;
     e2->node = to;
+    e1->init_weight = forward_weight;
+    e2->init_weight = backward_weight;
     e1->weight = forward_weight;
     e2->weight = backward_weight;
 
@@ -620,10 +638,10 @@ int main()
            int y = t/width;
            int w = 1;
 #define R (lrand48()%32)
-           if(x>0) edge_new(&g->nodes[t], &g->nodes[t-1], R, R);
-           if(x<width-1) edge_new(&g->nodes[t], &g->nodes[t+1], R, R);
-           if(y>0) edge_new(&g->nodes[t], &g->nodes[t-width], R, R);
-           if(y<width-1) edge_new(&g->nodes[t], &g->nodes[t+width], R, R);
+           if(x>0) graph_add_edge(&g->nodes[t], &g->nodes[t-1], R, R);
+           if(x<width-1) graph_add_edge(&g->nodes[t], &g->nodes[t+1], R, R);
+           if(y>0) graph_add_edge(&g->nodes[t], &g->nodes[t-width], R, R);
+           if(y<width-1) graph_add_edge(&g->nodes[t], &g->nodes[t+width], R, R);
        }
        
        int x = graph_maxflow(g, &g->nodes[0], &g->nodes[width*width-1]);
index ca6d82a..b085770 100644 (file)
 #ifndef __graphcut_h__
 #define __graphcut_h__
 
-#include "image.h"
-
 typedef signed int weight_t;
-#define MAX_WEIGHT 0x07ffffff
 
 typedef struct _halfedge halfedge_t;
 typedef struct _node node_t;
@@ -34,6 +31,7 @@ struct _halfedge {
     node_t*node;
     struct _halfedge*fwd;
     weight_t weight;
+    weight_t init_weight;
     char used;
     halfedge_t*next;
 };
@@ -49,7 +47,7 @@ struct _graph {
 };
 
 graph_t* graph_new(int num_nodes);
-halfedge_t*edge_new(node_t*from, node_t*to, weight_t forward_weight, weight_t backward_weight);
+halfedge_t*graph_add_edge(node_t*from, node_t*to, weight_t forward_weight, weight_t backward_weight);
 weight_t graph_maxflow(graph_t*graph, node_t*pos1, node_t*pos2);
 void graph_delete(graph_t*);