Example #1
0
File: emst.cpp Project: 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;
}
Example #2
0
void testcase(int n) {
	vector<K::Point_2> delaunay_vertices;
	for(int i = 0; i < n; ++i) {
		K::Point_2 p; cin >> p;
		delaunay_vertices.push_back(p);
	}

	Triangulation t;
	t.insert(delaunay_vertices.begin(), delaunay_vertices.end());

	int points; cin >> points;
	for(int i = 0; i < points; ++i) {
		K::Point_2 p; cin >> p;
		Triangulation::Vertex_handle v = t.nearest_vertex(p);
		K::Point_2 vp = v->point();
		K::FT distance = CGAL::squared_distance(p, vp);
		cout << floor_to_double(distance) << "\n";
	}
}