//ConnectedComponents PlannerPRM::connectedComponents(ComponentMap &componentMap, bool print)
void PlannerPRM::connectedComponents(ComponentMap &componentMap, ConnectedComponents &compList, bool print) const
{
	//qDebug() << __FUNCTION__;

	//create a vertex_index property map, since VertexList is listS and the graph does not have a "natural" index
 	typedef std::map<Vertex, size_t> IMap;
 	typedef boost::associative_property_map<IMap> IndexMap;
	IMap indexMap;
	IndexMap index( indexMap );

 	//indexing the vertices
 	int i=0;
 	BGL_FORALL_VERTICES(v, graph, Graph)
 		boost::put(index, v, i++);

	std::vector<int> components(boost::num_vertices(graph));
	boost::iterator_property_map< std::vector<int>::iterator, IndexMap> compIterMap( components.begin(), index );

  int numComps = boost::connected_components(graph, compIterMap, vertex_index_map(index));
	
	//Create a nice data structure to return info
	compList.resize(numComps);
	for(auto it : compList)
		it = std::make_pair(0, std::vector<Vertex>());

	BGL_FORALL_VERTICES(v, graph, Graph)
	{
		compList[get(compIterMap, v)].second.push_back( v );
		compList[get(compIterMap, v)].first++;
		componentMap.insert( std::pair<Vertex,int32_t>( v, get(compIterMap, v )));
	}
Esempio n. 2
0
File: emst.cpp Progetto: FMX/CGAL
int
main(int,char*[])
{
    Triangulation t;
    Filter is_finite(t);
    Finite_triangulation ft(t, is_finite, is_finite);

    Point p ;
    while(std::cin >> p) {
        t.insert(p);
    }

    vertex_iterator vit, ve;
    // Associate indices to the vertices
    int index = 0;
    // boost::tie assigns the first and second element of the std::pair
    // returned by boost::vertices to the variables vit and ve
    for(boost::tie(vit,ve)=boost::vertices(ft); vit!=ve; ++vit ) {
        vertex_descriptor  vd = *vit;
        vertex_id_map[vd]= index++;
    }


    // We use the default edge weight which is the squared length of the edge
    // This property map is defined in graph_traits_Triangulation_2.h

    // In the function call you can see a named parameter: vertex_index_map
    std::list<edge_descriptor> mst;
    boost::kruskal_minimum_spanning_tree(t,
                                         std::back_inserter(mst),
                                         vertex_index_map(vertex_index_pmap));


    std::cout << "The edges of the Euclidean mimimum spanning tree:" << std::endl;

    for(std::list<edge_descriptor>::iterator it = mst.begin(); it != mst.end(); ++it) {
        edge_descriptor ed = *it;
        vertex_descriptor svd = boost::source(ed,t);
        vertex_descriptor tvd = boost::target(ed,t);
        Triangulation::Vertex_handle sv = svd;
        Triangulation::Vertex_handle tv = tvd;
        std::cout << "[ " << sv->point() << "  |  " << tv->point() << " ] " << std::endl;
    }

    return 0;
}