本文整理汇总了C++中GraphType::compute_maxflow方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphType::compute_maxflow方法的具体用法?C++ GraphType::compute_maxflow怎么用?C++ GraphType::compute_maxflow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphType
的用法示例。
在下文中一共展示了GraphType::compute_maxflow方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run_GridCut_3D_6C
void run_GridCut_3D_6C(MFI* mfi,unsigned char* out_label,int* out_maxflow,double* time_init,double* time_maxflow,double* time_output)
{
const int w = mfi->width;
const int h = mfi->height;
const int d = mfi->depth;
const type_terminal_cap* cap_source = (type_terminal_cap*)mfi->cap_source;
const type_terminal_cap* cap_sink = (type_terminal_cap*)mfi->cap_sink;
const type_neighbor_cap* cap_neighbor[6] = { (type_neighbor_cap*)(mfi->cap_neighbor[0]),
(type_neighbor_cap*)(mfi->cap_neighbor[1]),
(type_neighbor_cap*)(mfi->cap_neighbor[2]),
(type_neighbor_cap*)(mfi->cap_neighbor[3]),
(type_neighbor_cap*)(mfi->cap_neighbor[4]),
(type_neighbor_cap*)(mfi->cap_neighbor[5]) };
typedef GridGraph_3D_6C<type_terminal_cap,type_neighbor_cap,int> GraphType;
CLOCK_START();
GraphType* graph = new GraphType(w,h,d);
for(int z=0;z<d;z++)
for(int y=0;y<h;y++)
for(int x=0;x<w;x++)
{
const int node = graph->node_id(x,y,z);
graph->set_terminal_cap(node,cap_source[x+y*w+z*(w*h)],cap_sink[x+y*w+z*(w*h)]);
if (x>0 ) graph->set_neighbor_cap(node,-1, 0, 0,cap_neighbor[MFI::ARC_LEE][x+y*w+z*(w*h)]);
if (x<w-1) graph->set_neighbor_cap(node,+1, 0, 0,cap_neighbor[MFI::ARC_GEE][x+y*w+z*(w*h)]);
if (y>0 ) graph->set_neighbor_cap(node, 0,-1, 0,cap_neighbor[MFI::ARC_ELE][x+y*w+z*(w*h)]);
if (y<h-1) graph->set_neighbor_cap(node, 0,+1, 0,cap_neighbor[MFI::ARC_EGE][x+y*w+z*(w*h)]);
if (z>0 ) graph->set_neighbor_cap(node, 0, 0,-1,cap_neighbor[MFI::ARC_EEL][x+y*w+z*(w*h)]);
if (z<d-1) graph->set_neighbor_cap(node, 0, 0,+1,cap_neighbor[MFI::ARC_EEG][x+y*w+z*(w*h)]);
}
CLOCK_STOP(time_init);
CLOCK_START();
graph->compute_maxflow();
CLOCK_STOP(time_maxflow)
CLOCK_START();
*out_maxflow = graph->get_flow();
for(int z=0;z<d;z++)
for(int y=0;y<h;y++)
for(int x=0;x<w;x++)
{
out_label[x+y*w+z*(w*h)] = graph->get_segment(graph->node_id(x,y,z));
}
delete graph;
CLOCK_STOP(time_output);
}
示例2: run_GridCut_3D_6C_MT
void run_GridCut_3D_6C_MT(MFI* mfi,unsigned char* out_label,int* out_maxflow,double* time_init,double* time_maxflow,double* time_output)
{
const int w = mfi->width;
const int h = mfi->height;
const int d = mfi->depth;
const type_terminal_cap* cap_source = (type_terminal_cap*)mfi->cap_source;
const type_terminal_cap* cap_sink = (type_terminal_cap*)mfi->cap_sink;
const type_neighbor_cap* cap_neighbor[6] = { (type_neighbor_cap*)(mfi->cap_neighbor[0]),
(type_neighbor_cap*)(mfi->cap_neighbor[1]),
(type_neighbor_cap*)(mfi->cap_neighbor[2]),
(type_neighbor_cap*)(mfi->cap_neighbor[3]),
(type_neighbor_cap*)(mfi->cap_neighbor[4]),
(type_neighbor_cap*)(mfi->cap_neighbor[5]) };
typedef GridGraph_3D_6C_MT<type_terminal_cap,type_neighbor_cap,int> GraphType;
CLOCK_START();
int block_size = (int)(exp(log((double)w * h * d / (num_threads * num_tasks)) / 3) + 0.5);
GraphType* graph = new GraphType(w,h,d,num_threads,block_size);
graph->set_caps(cap_source, cap_sink,
cap_neighbor[MFI::ARC_LEE], cap_neighbor[MFI::ARC_GEE],
cap_neighbor[MFI::ARC_ELE], cap_neighbor[MFI::ARC_EGE],
cap_neighbor[MFI::ARC_EEL], cap_neighbor[MFI::ARC_EEG]);
CLOCK_STOP(time_init);
CLOCK_START();
graph->compute_maxflow();
CLOCK_STOP(time_maxflow)
CLOCK_START();
*out_maxflow = graph->get_flow();
for(int z=0;z<d;z++)
for(int y=0;y<h;y++)
for(int x=0;x<w;x++)
{
out_label[x+y*w+z*(w*h)] = graph->get_segment(graph->node_id(x,y,z));
}
delete graph;
CLOCK_STOP(time_output);
}