What's a good algorithm to traverse the edges of a Voronoi diagram using boost without recursion?
I know it'd have to check for infinite edges in a cell then check its neighbours and repeat from there, but I'd prefer a method that doesn't require recursion since I'm dealing with large sets of data.
Is this possible without recursion?
Edit, for more clarification:
This is a way to obtain all edge cells:
voronoi_diagram vd;
boost::polygon::construct_voronoi(in.begin(), in.end(), &vd);
std::vector<const voronoi_diagram::cell_type *> edge_cells;
for(const voronoi_diagram::edge_type & e : vd.edges())
if (e.is_infinite())
edge_cells.push_back(e.cell());
The problem with the approach above is that it will not traverse the edge cells in any specific order, say clockwise for example.
A recursive implementation would do something akin to this (hastily written and untested) code:
bool findNext(const voronoi_diagram::cell_type * c,
std::list<const voronoi_diagram::cell_type *> & list)
{
const voronoi_diagram::edge_type * e = c->incident_edge();
do
{
// Follow infinite edges, adding cells encountered along the way
if (e->is_infinite() && e->twin()->cell() != list.front() &&
e->twin()->cell() != list.back())
{
list.push_back(c);
return findNext(e->twin()->cell(), list);
}
else if (e->twin()->cell() == list.front())
{
list.push_back(c);
return true; // we reached the starting point, return
}
e = e->next();
} while (e != c->incident_edge());
return false;
}
// ...
std::list<const voronoi_diagram::cell_type *> edge_cells;
// ...
for(const voronoi_diagram::edge_type & e : vd.edges())
{
// find first infinite edge
if (e.is_infinite())
{
if (findNext(e.cell(), edge_cells))
break;
else
edge_cells.clear();
}
}
This would traverse the edges of the Voronoi diagram until it traces its way back to the first cell and then stops, filling the stack all the way.
A non-recursive implementation would model the second example, producing a list of the edge cells in a clockwise or counter-clockwise order, without using recursion.