Exemple #1
0
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);
}
Exemple #2
0
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);
}