Voronoi Diagram using CGAL: extract only edge points (convex hull)

447 Views Asked by At

I want to extract edge points (points lie on an edge of the boundary of the convex hull) using Voronoi diagram. I know that an unbounded cell contains a boundary site point, but how can I access to that information using iterators?

Solution

VD vd;
//initialise your voronoi diagram
VD::Face_iterator it = vd.faces_begin(), beyond = vd.faces_end();
for (int f = 0; it != beyond; ++f, ++it) 
{
  std::cout << "Face " << f << ": \n";
  if (it->is_unbounded()) 
  {
    // it's a boundary point
  }
}
1

There are 1 best solutions below

0
On

Read CGAL 2D Delaunay Triangulation: How to get edges as vertex id pairs, and having in mind the relation between Voronoi and Delaunay check this example:

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K>  Triangulation;
typedef Triangulation::Edge_iterator  Edge_iterator;
typedef Triangulation::Point          Point;
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;
}

If this doesn't answer your question, then get inspired by it and play around.