float ComputeEdgeCostAtVertexForBuffer( PMWorkingData workingData, uint vertIndex )
{
// compute the edge collapse cost for all edges that start
// from vertex v. Since we are only interested in reducing
// the object by selecting the min cost edge at each step, we
// only cache the cost of the least cost edge at this vertex
// (in member variable collapse) as well as the value of the
// cost (in member variable objdist).
PMVertex v = workingData.vertList[ (int)vertIndex ];
if ( v.neighbors.Count == 0 )
{
// v doesn't have neighbors so nothing to collapse
v.NotifyRemoved();
return v.collapseCost;
}
// Init metrics
v.collapseCost = float.MaxValue;
v.collapseTo = null;
// search all neighboring edges for "least cost" edge
foreach ( PMVertex neighbor in v.neighbors )
{
float cost = ComputeEdgeCollapseCost( v, neighbor );
if ( ( v.collapseTo == null ) || cost < v.collapseCost )
{
v.collapseTo = neighbor; // candidate for edge collapse
v.collapseCost = cost; // cost of the collapse
}
}
return v.collapseCost;
}