资源简介
graphcuts算法界面实现
代码片段和文件信息
/* graph.cpp */
#include
#include
#include
#include “graph.h“
template
Graph::Graph(int node_num_max int edge_num_max void(*err_function)(char *))
: node_num(0)
nodeptr_block(NULL)
error_function(err_function)
{
if (node_num_max < 16) node_num_max = 16;
if (edge_num_max < 16) edge_num_max = 16;
nodes = (node*)malloc(node_num_max*sizeof(node));
arcs = (arc*)malloc(2 * edge_num_max*sizeof(arc));
if (!nodes || !arcs) { if (error_function) (*error_function)(“Not enough memory!“); exit(1); }
node_last = nodes;
node_max = nodes + node_num_max;
arc_last = arcs;
arc_max = arcs + 2 * edge_num_max;
maxflow_iteration = 0;
flow = 0;
}
template
Graph::~Graph()
{
if (nodeptr_block)
{
delete nodeptr_block;
nodeptr_block = NULL;
}
free(nodes);
free(arcs);
}
template
void Graph::reset()
{
node_last = nodes;
arc_last = arcs;
node_num = 0;
if (nodeptr_block)
{
delete nodeptr_block;
nodeptr_block = NULL;
}
maxflow_iteration = 0;
flow = 0;
}
template
void Graph::reallocate_nodes(int num)
{
int node_num_max = (int)(node_max - nodes);
node* nodes_old = nodes;
node_num_max += node_num_max / 2;
if (node_num_max < node_num + num) node_num_max = node_num + num;
nodes = (node*)realloc(nodes_old node_num_max*sizeof(node));
if (!nodes) { if (error_function) (*error_function)(“Not enough memory!“); exit(1); }
node_last = nodes + node_num;
node_max = nodes + node_num_max;
if (nodes != nodes_old)
{
arc* a;
for (a = arcs; a < arc_last; a++)
{
a->head = (node*)((char*)a->head + (((char*)nodes) - ((char*)nodes_old)));
}
}
}
template
void Graph::reallocate_arcs()
{
int arc_num_max = (int)(arc_max - arcs);
int arc_num = (int)(arc_last - arcs);
arc* arcs_old = arcs;
arc_num_max += arc_num_max / 2; if (arc_num_max & 1) arc_num_max++;
arcs = (arc*)realloc(arcs_old arc_num_max*sizeof(arc));
if (!arcs) { if (error_function) (*error_function)(“Not enough memory!“); exit(1); }
arc_last = arcs + arc_num;
arc_max = arcs + arc_num_max;
if (arcs != arcs_old)
{
node* i;
arc* a;
for (i = nodes; i < node_last; i++)
{
if (i->first) i->first = (arc*)((char*)i->first + (((char*)arcs) - ((char*)arcs_old)));
}
for (a = arcs; a < arc_last; a++)
{
if (a->next) a->next = (arc*)((char*)a->next + (((char*)arcs) - ((char*)arcs_old)));
a->sister = (arc*)((char*)a->sister + (((char*)arcs) - ((char*)arcs_old)));
}
}
}
#include “instances.inc“
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7022 2017-03-27 18:53 graphcut\graphcut\block.h
文件 76743 2017-08-23 20:20 graphcut\graphcut\Debug\graph.obj
文件 1427 2017-08-23 20:19 graphcut\graphcut\Debug\graphcut.Build.CppClean.log
文件 4097 2017-08-23 20:20 graphcut\graphcut\Debug\graphcut.log
文件 758152 2017-08-23 20:20 graphcut\graphcut\Debug\graphcut.obj
文件 8754 2017-08-23 20:20 graphcut\graphcut\Debug\graphcut.tlog\cl.command.1.tlog
文件 117426 2017-08-23 20:20 graphcut\graphcut\Debug\graphcut.tlog\CL.read.1.tlog
文件 3128 2017-08-23 20:20 graphcut\graphcut\Debug\graphcut.tlog\CL.write.1.tlog
文件 1710 2017-08-23 20:20 graphcut\graphcut\Debug\graphcut.tlog\custombuild.command.1.tlog
文件 426 2017-08-23 20:20 graphcut\graphcut\Debug\graphcut.tlog\custombuild.read.1.tlog
文件 650 2017-08-23 20:20 graphcut\graphcut\Debug\graphcut.tlog\custombuild.write.1.tlog
文件 154 2017-08-23 20:20 graphcut\graphcut\Debug\graphcut.tlog\graphcut.lastbuildstate
文件 3950 2017-08-23 20:20 graphcut\graphcut\Debug\graphcut.tlog\li
文件 8692 2017-08-23 20:20 graphcut\graphcut\Debug\graphcut.tlog\li
文件 1088 2017-08-23 20:20 graphcut\graphcut\Debug\graphcut.tlog\li
文件 238777 2017-08-23 20:20 graphcut\graphcut\Debug\LazySnapping.obj
文件 560047 2017-08-23 20:20 graphcut\graphcut\Debug\main.obj
文件 144620 2017-08-23 20:20 graphcut\graphcut\Debug\maxflow.obj
文件 563972 2017-08-23 20:20 graphcut\graphcut\Debug\moc_graphcut.obj
文件 4728 2017-08-23 20:20 graphcut\graphcut\Debug\qrc_graphcut.obj
文件 123774 2017-08-23 20:20 graphcut\graphcut\Debug\SimpleKMeans.obj
文件 2650112 2017-08-23 20:20 graphcut\graphcut\Debug\vc120.pdb
文件 4217 2017-08-23 20:20 graphcut\graphcut\GeneratedFiles\Debug\moc_graphcut.cpp
文件 1402 2017-08-23 20:20 graphcut\graphcut\GeneratedFiles\qrc_graphcut.cpp
文件 9189 2017-08-23 20:20 graphcut\graphcut\GeneratedFiles\ui_graphcut.h
文件 2897 2017-03-27 18:51 graphcut\graphcut\graph.cpp
文件 17127 2017-03-27 18:50 graphcut\graphcut\graph.h
文件 3940 2017-08-23 20:16 graphcut\graphcut\graphcut.cpp
文件 981 2017-08-23 20:19 graphcut\graphcut\graphcut.h
文件 68 2017-08-23 20:11 graphcut\graphcut\graphcut.qrc
............此处省略31个文件信息
- 上一篇:ITK入门中文教程2
- 下一篇:phreeqci 水化学软件
评论
共有 条评论