// Compute all the finite voronoi vertices and the circumradius of all the finite cells. void compute_voronoi_vertex_and_cell_radius(Triangulation& triang) { bool is_there_any_problem_in_VV_computation = false; for (FCI cit = triang.finite_cells_begin(); cit != triang.finite_cells_end(); cit ++) { //we tell CGAL to call our function if there is a problem //we also tell it not to die if things go haywire //CGAL::Failure_function old_ff = CGAL::set_error_handler(failure_func); //CGAL::Failure_behaviour old_fb = CGAL::set_error_behaviour(CGAL::CONTINUE); // be optimistic :-) //this is a global cgal_failed = false; cit->set_voronoi(triang.dual(cit)); bool is_correct_computation = !cgal_failed; is_there_any_problem_in_VV_computation |= !is_correct_computation; if (cgal_failed) { // set cc the centroid of the cell. Vector cc = CGAL::NULL_VECTOR; for (int i = 0; i < 4; i ++) { cc = cc + (cit->vertex(i)->point() - CGAL::ORIGIN); } cc = (1./4.)*cc; cit->set_voronoi(CGAL::ORIGIN + cc); } //put everything back the way we found it, //CGAL::set_error_handler(old_ff); //CGAL::set_error_behaviour(old_fb); // set the cell radius. cit->set_cell_radius(CGAL::to_double((cit->vertex(0)->point()-cit->voronoi()) *(cit->vertex(0)->point()-cit->voronoi()))); } return; }
int main() { Triangulation tr; int a, b, d; for (a=0;a!=4;a++) for (b=0;b!=4;b++) for (d=0;d!=4;d++) tr.insert(Point((a*b-d*a)*10 +a ,(a-b+d +5*b)*100, a*a-d*d-b)); Triangulation::Finite_cells_iterator cit=tr.finite_cells_begin(); for(; cit != tr.finite_cells_end(); ++cit) { Point circum = tr.dual(cit); CGAL_USE(circum); } return 0; }
bool recurse(Face_handle current_face, long d, vector<Face_handle>& visited, Triangulation t) { // Remember we visited this node visited.push_back(current_face); cout << "Recursion at: " << t.dual(current_face) << endl; // Base of recursion: check if we are free if(t.is_infinite(current_face)) { cout << "Infinite face!" << endl; return true; } for(int neighbor_num=0; neighbor_num<3; neighbor_num++) { Face_handle neighbor_face = current_face->neighbor(neighbor_num); //cout << (current_face == neighbor_face) << endl; cout << "\tChecking neighbor of vertex " << current_face->vertex(neighbor_num)->point() << endl; cout << "\tPoints: "; for(int j=0; j<3; j++) { cout << neighbor_face->vertex(j)->point() << ", "; } cout << endl; // If we already visited if(find(visited.begin(), visited.end(), current_face) != visited.end()) { continue; } Vertex_handle border_endpoint1 = current_face->vertex((neighbor_num + 1) % 3); Vertex_handle border_endpoint2 = current_face->vertex((neighbor_num + 2) % 3); K::FT border_length_sq = CGAL::squared_distance(border_endpoint1->point(), border_endpoint2->point()); if(CGAL::to_double(border_length_sq) >= 4 * d) { // If we can fit through that edge // cout << "can fit through edge " << neighbor_num << endl; // New search starting from neighbor if(recurse(neighbor_face, d, visited, t)) { return true; } } else { cout << "cannot fit through edge :S" << endl; } } return false; }
int main( ) { std::ifstream in("data/voronoi.cin"); std::istream_iterator<Point> begin(in); std::istream_iterator<Point> end; Triangulation T; T.insert(begin, end); int ns = 0; int nr = 0; Edge_iterator eit =T.edges_begin(); for ( ; eit !=T.edges_end(); ++eit) { CGAL::Object o = T.dual(eit); if (CGAL::object_cast<K::Segment_2>(&o)) {++ns;} else if (CGAL::object_cast<K::Ray_2>(&o)) {++nr;} } std::cout << "The Voronoi diagram has " << ns << " finite edges " << " and " << nr << " rays" << std::endl; return 0; }