computeEdgeCollapseCost static method
dynamic
computeEdgeCollapseCost(
- dynamic u,
- dynamic v
Implementation
static computeEdgeCollapseCost( u, v ) {
// if we collapse edge uv by moving u to v then how
// much different will the model change, i.e. the "error".
final edgelength = v.position.distanceTo( u.position );
double curvature = 0;
final sideFaces = [];
// find the "sides" triangles that are on the edge uv
for (int i = 0, il = u.faces.length; i < il; i ++ ) {
final Tri face = u.faces[ i ];
if (face.hasVertex(v)) {
sideFaces.add(face);
}
}
// use the triangle facing most away from the sides
// to determine our curvature term
for (int i = 0, il = u.faces.length; i < il; i ++ ) {
double minCurvature = 1;
final Tri face = u.faces[i];
for (int j = 0; j < sideFaces.length; j ++ ) {
final sideFace = sideFaces[j];
// use dot product of face normals.
double dotProd = face.normal.dot(sideFace.normal).toDouble();
minCurvature = Math.min( minCurvature, ( 1.001 - dotProd ) / 2 );
}
curvature = Math.max( curvature, minCurvature );
}
// crude approach in attempt to preserve borders
// though it seems not to be totally correct
const borders = 0;
if ( sideFaces.length < 2 ) {
// we add some arbitrary cost for borders,
// borders += 10;
curvature = 1;
}
final amt = edgelength * curvature + borders;
return amt;
}