metaprogram_builder::vertex_descriptor metaprogram_builder::add_vertex(
    const std::string& context)
{
  element_vertex_map_t::iterator pos;
  bool inserted;

  std::tie(pos, inserted) = element_vertex_map.insert(
      std::make_pair(context, vertex_descriptor()));

  if (inserted) {
    pos->second = mp.add_vertex(context);
  }
  return pos->second;
}
  metaprogram_builder::vertex_descriptor
  metaprogram_builder::add_vertex(const data::type& type,
                                  const data::file_location& source_location)
  {
    element_vertex_map_t::iterator pos;
    bool inserted;

    std::tie(pos, inserted) = element_vertex_map.insert(std::make_pair(
        std::make_tuple(type, source_location), vertex_descriptor()));

    if (inserted)
    {
      pos->second = mp.add_vertex(type, source_location);
    }
    return pos->second;
  }
Example #3
0
template <typename PointT> bool
pcl::MinCutSegmentation<PointT>::buildGraph ()
{
  int number_of_points = static_cast<int> (input_->points.size ());
  int number_of_indices = static_cast<int> (indices_->size ());

  if (input_->points.size () == 0 || number_of_points == 0 || foreground_points_.empty () == true )
    return (false);

  if (search_ == 0)
    search_ = boost::shared_ptr<pcl::search::Search<PointT> > (new pcl::search::KdTree<PointT>);

  graph_.reset ();
  graph_ = boost::shared_ptr< mGraph > (new mGraph ());

  capacity_.reset ();
  capacity_ = boost::shared_ptr<CapacityMap> (new CapacityMap ());
  *capacity_ = boost::get (boost::edge_capacity, *graph_);

  reverse_edges_.reset ();
  reverse_edges_ = boost::shared_ptr<ReverseEdgeMap> (new ReverseEdgeMap ());
  *reverse_edges_ = boost::get (boost::edge_reverse, *graph_);

  VertexDescriptor vertex_descriptor(0);
  vertices_.clear ();
  vertices_.resize (number_of_points + 2, vertex_descriptor);

  std::set<int> out_edges_marker;
  edge_marker_.clear ();
  edge_marker_.resize (number_of_points + 2, out_edges_marker);

  for (int i_point = 0; i_point < number_of_points + 2; i_point++)
    vertices_[i_point] = boost::add_vertex (*graph_);

  source_ = vertices_[number_of_points];
  sink_ = vertices_[number_of_points + 1];

  for (int i_point = 0; i_point < number_of_indices; i_point++)
  {
    int point_index = (*indices_)[i_point];
    double source_weight = 0.0;
    double sink_weight = 0.0;
    calculateUnaryPotential (point_index, source_weight, sink_weight);
    addEdge (static_cast<int> (source_), point_index, source_weight);
    addEdge (point_index, static_cast<int> (sink_), sink_weight);
  }

  std::vector<int> neighbours;
  std::vector<float> distances;
  search_->setInputCloud (input_, indices_);
  for (int i_point = 0; i_point < number_of_indices; i_point++)
  {
    int point_index = (*indices_)[i_point];
    search_->nearestKSearch (i_point, number_of_neighbours_, neighbours, distances);
    for (size_t i_nghbr = 1; i_nghbr < neighbours.size (); i_nghbr++)
    {
      double weight = calculateBinaryPotential (point_index, neighbours[i_nghbr]);
      addEdge (point_index, neighbours[i_nghbr], weight);
      addEdge (neighbours[i_nghbr], point_index, weight);
    }
    neighbours.clear ();
    distances.clear ();
  }

  return (true);
}
Example #4
0
  boost::d_ary_heap_indirect<vertex_descriptor, 22, indicesInHeap_type, distances_type, std::greater<weight_type> > pq(distances, indicesInHeap);

  mas_edge_connectivity_visitor<undirected_unweighted_graph,boost::d_ary_heap_indirect<vertex_descriptor, 22, indicesInHeap_type, distances_type, std::greater<weight_type> > >  test_vis(pq);

  boost::maximum_adjacency_search(g, 
         boost::weight_map(boost::make_constant_property<edge_descriptor>(weight_type(1))).visitor(test_vis).max_priority_queue(pq));

  BOOST_CHECK_EQUAL(test_vis.curr(), vertex_descriptor(7));
  BOOST_CHECK_EQUAL(test_vis.prev(), vertex_descriptor(3));
  BOOST_CHECK_EQUAL(test_vis.reach_weight(), weight_type(2));

  weight_type ws[] = {2, 3, 4, 3, 2, 2, 2, 2, 2, 3, 1, 3};
  std::map<edge_descriptor, weight_type> wm;

  weight_type i = 0;
  BGL_FORALL_EDGES(e, g, undirected_unweighted_graph) {
    wm[e] = ws[i];
    ++i;
  }
  boost::associative_property_map<std::map<edge_descriptor, weight_type> > ws_map(wm);

  boost::maximum_adjacency_search(g, boost::weight_map(ws_map).visitor(test_vis).max_priority_queue(pq));
  BOOST_CHECK_EQUAL(test_vis.curr(), vertex_descriptor(7));
  BOOST_CHECK_EQUAL(test_vis.prev(), vertex_descriptor(6));
  BOOST_CHECK_EQUAL(test_vis.reach_weight(), weight_type(5));

}

#include <boost/graph/iteration_macros_undef.hpp>