computeEdgeCostAtVertex static method
void
computeEdgeCostAtVertex(
- Vertex v
)
Implementation
static void computeEdgeCostAtVertex(Vertex v ) {
// 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 collapseCost).
if ( v.neighbors.length == 0 ) {
// collapse if no neighbors.
v.collapseNeighbor = null;
v.collapseCost = -0.01;
return;
}
v.collapseCost = 100000;
v.collapseNeighbor = null;
// search all neighboring edges for "least cost" edge
for (int i = 0; i < v.neighbors.length; i ++ ) {
final collapseCost = computeEdgeCollapseCost( v, v.neighbors[ i ] );
if(v.collapseNeighbor == null){
v.collapseNeighbor = v.neighbors[i];
v.collapseCost = collapseCost;
v.minCost = collapseCost;
v.totalCost = 0;
v.costCount = 0;
}
v.costCount++;
v.totalCost += collapseCost;
if ( collapseCost < v.minCost ) {
v.collapseNeighbor = v.neighbors[ i ];
v.minCost = collapseCost;
}
}
// we average the cost of collapsing at this vertex
v.collapseCost = v.totalCost / v.costCount;
// v.collapseCost = v.minCost;
}