// This is a dynamic programming approach that fills a two-dimensional table of weights.
// The boundary is indexed by numbers ranging from 0 to n.
// The entry weights[x,y] (accessed via weights[index_of(x,y)]) gives the minimal weight to triangulate the boudary from vertex x to vertex y.
// Since only entries that span at least three vertices can span any triangles, only these need to be stored.
// The other entries are implicitly zero.
// This means, x ranges from 0 to n-1 and y ranges from 1 to n.
// In this implementation, the weight is equal to the triangle area.
// To extract the correct triangulation after the table of weights has been computed, a chosen triangle is also associated with each entry in the table.
// candidate triangle of the boundary, each corner is an index into the boundary
structindexed_triangle
{
inta,b,c;
};
std::vector<pm::vertex_index>boundary;
{// fill boundary
autocurrent=boundary_start;
do
{
boundary.push_back(current.vertex_to());
current=current.next();
}while(current!=boundary_start);
}
autoconstn=int(boundary.size())-1;
// only entries in the lower left half of the table can have non-zero entries.