#ifndef CGAL_USE_LEDA int main(){ return 0; } #else #include //#include #include #include #include typedef CGAL::Cartesian K; //typedef CGAL::Simple_cartesian K; typedef CGAL::Point_set_2::Edge_iterator Edge_iterator; typedef CGAL::Point_set_2::Vertex_handle Vertex_handle; CGAL::Point_set_2 PSet; void output(CGAL::Window_stream& W, const CGAL::Point_set_2& PS) { W.clear(); Edge_iterator eit = PS.finite_edges_begin(); for(;eit != PS.finite_edges_end(); eit++) { CGAL::Segment_2 s= PS.segment(*eit); W << s; } } void redraw(CGAL::Window_stream* wptr) { output(*wptr,PSet); } int main() { CGAL::Window_stream W(600,500, "Finding nearest neighbor / k nearest neighbors"); W.init(-500,500,-400); W.set_redraw(redraw); W.display(100,100); #if defined(CGAL_USE_CGAL_WINDOW) W.set_point_style(CGAL::disc_point); #else W.set_point_style(leda_disc_point); #endif W.draw_text(-260,20, "Input some points; quit input with the right mouse button"); CGAL::Point_2 actual; /*std::cout << sizeof(actual) << "\n";*/ int i=0; while (W >> actual){ PSet.insert(actual); output(W,PSet); i++; } std::cout << i << " points were inserted !\n"; // nearest neighbor ... W.draw_text(-450,-350, "Input a point; we display the nearest neighbor ... "); for (i=0; i<5; i++){ W >> actual; Vertex_handle v = PSet.nearest_neighbor(actual); if (v != NULL) { CGAL::Segment_2 my_seg(actual,v->point()); W << CGAL::RED << v->point() << CGAL::BLACK; W << CGAL::BLUE << my_seg << CGAL::BLACK; } } // k nearest neighbors ... std::list L; std::list::const_iterator it; output(W,PSet); W.draw_text(-450,-350, "Input a point; we display the 5 nearest neighbors ... "); for (i=0; i<5; i++){ L.clear(); W >> actual; PSet.nearest_neighbors(actual,5, std::back_inserter(L)); std::cout << "actual point: " << actual << "\n"; W.clear(); W.draw_text(-450,-350, "Input a point; we display the 5 nearest neighbors ... "); output(W,PSet); W << CGAL::RED << actual << CGAL::BLACK; for (it=L.begin();it != L.end(); it++){ W << CGAL::GREEN << (*it)->point() << CGAL::BLACK; std::cout << (*it)->point() << "\n"; } std::cout << "\n"; } W.read_mouse(); return 1; } #endif