Improve numerical stability of catmark subdivision

This change sums the vertex point last, since it's normally the largest
value.  There may be other numerical stability issues in this code that I
haven't discovered.
This commit is contained in:
Andrew Clinton 2013-09-12 16:36:45 -04:00
parent e34122223c
commit a778521c2f

View File

@ -1063,8 +1063,6 @@ HbrCatmarkSubdivision<T>::Subdivide(HbrMesh<T>* mesh, HbrVertex<T>* vertex) {
switch (masks[i]) { switch (masks[i]) {
case HbrVertex<T>::k_Smooth: case HbrVertex<T>::k_Smooth:
case HbrVertex<T>::k_Dart: { case HbrVertex<T>::k_Dart: {
// Compute n-2/n of the old vertex value
data.AddWithWeight(vertex->GetData(), weights[i] * invvalencesquared * valence * (valence - 2));
// Add 1 / n^2 * surrounding edge vertices and surrounding face // Add 1 / n^2 * surrounding edge vertices and surrounding face
// subdivided vertices // subdivided vertices
HbrSubdivision<T>::AddSurroundingVerticesWithWeight( HbrSubdivision<T>::AddSurroundingVerticesWithWeight(
@ -1078,16 +1076,18 @@ HbrCatmarkSubdivision<T>::Subdivide(HbrMesh<T>* mesh, HbrVertex<T>* vertex) {
edge = vertex->GetNextEdge(edge); edge = vertex->GetNextEdge(edge);
if (edge == start) break; if (edge == start) break;
} }
// Compute n-2/n of the old vertex value
data.AddWithWeight(vertex->GetData(), weights[i] * invvalencesquared * valence * (valence - 2));
break; break;
} }
case HbrVertex<T>::k_Crease: { case HbrVertex<T>::k_Crease: {
// Compute 3/4 of old vertex value
data.AddWithWeight(vertex->GetData(), weights[i] * 0.75f);
// Add 0.125f of the (hopefully only two!) neighbouring // Add 0.125f of the (hopefully only two!) neighbouring
// sharp edges // sharp edges
HbrSubdivision<T>::AddCreaseEdgesWithWeight( HbrSubdivision<T>::AddCreaseEdgesWithWeight(
mesh, vertex, i == 1, weights[i] * 0.125f, &data); mesh, vertex, i == 1, weights[i] * 0.125f, &data);
// Compute 3/4 of old vertex value
data.AddWithWeight(vertex->GetData(), weights[i] * 0.75f);
break; break;
} }
case HbrVertex<T>::k_Corner: case HbrVertex<T>::k_Corner: