Skip to content

Commit e1e4114

Browse files
committed
simplify: Add a more verbose tracing mode for edge collapses
This is too noisy for any reasonably sized model but it helps debug small isolated test cases and unit tests. Ideally we would probably remove the 'edge eval' (as in a given pass we may evaluate way more edges than we end up collapsing) but for now since we are not storing position/attribute errors separately that's the only place where we can output both errors as well as evaluate bidirectional flips.
1 parent 20536cf commit e1e4114

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/simplifier.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,13 @@ static bool hasTriangleFlips(const EdgeAdjacency& adjacency, const Vector3* vert
914914

915915
// early-out when at least one triangle flips due to a collapse
916916
if (hasTriangleFlip(vertex_positions[a], vertex_positions[b], v0, v1))
917+
{
918+
#if TRACE >= 2
919+
printf("edge block %d -> %d: flip welded %d %d %d\n", i0, i1, a, i0, b);
920+
#endif
921+
917922
return true;
923+
}
918924
}
919925

920926
return false;
@@ -1017,6 +1023,10 @@ static void rankEdgeCollapses(Collapse* collapses, size_t collapse_count, const
10171023
float ei = quadricError(vertex_quadrics[remap[i0]], vertex_positions[i1]);
10181024
float ej = quadricError(vertex_quadrics[remap[j0]], vertex_positions[j1]);
10191025

1026+
#if TRACE >= 2
1027+
float di = ei, dj = ej;
1028+
#endif
1029+
10201030
if (attribute_count)
10211031
{
10221032
ei += quadricError(attribute_quadrics[remap[i0]], &attribute_gradients[remap[i0] * attribute_count], attribute_count, vertex_positions[i1], &vertex_attributes[i1 * attribute_count]);
@@ -1027,6 +1037,16 @@ static void rankEdgeCollapses(Collapse* collapses, size_t collapse_count, const
10271037
c.v0 = ei <= ej ? i0 : j0;
10281038
c.v1 = ei <= ej ? i1 : j1;
10291039
c.error = ei <= ej ? ei : ej;
1040+
1041+
#if TRACE >= 2
1042+
if (i0 == j0) // c.bidi has been overwritten
1043+
printf("edge eval %d -> %d: error %f (pos %f, attr %f)\n", c.v0, c.v1,
1044+
sqrtf(c.error), sqrtf(ei <= ej ? di : dj), sqrtf(ei <= ej ? ei - di : ej - dj));
1045+
else
1046+
printf("edge eval %d -> %d: error %f (pos %f, attr %f); reverse %f (pos %f, attr %f)\n", c.v0, c.v1,
1047+
sqrtf(ei <= ej ? ei : ej), sqrtf(ei <= ej ? di : dj), sqrtf(ei <= ej ? ei - di : ej - dj),
1048+
sqrtf(ei <= ej ? ej : ei), sqrtf(ei <= ej ? dj : di), sqrtf(ei <= ej ? ej - dj : ei - di));
1049+
#endif
10301050
}
10311051
}
10321052

@@ -1126,6 +1146,10 @@ static size_t performEdgeCollapses(unsigned int* collapse_remap, unsigned char*
11261146
continue;
11271147
}
11281148

1149+
#if TRACE >= 2
1150+
printf("edge commit %d -> %d: kind %d->%d, error %f\n", i0, i1, vertex_kind[i0], vertex_kind[i1], sqrtf(c.error));
1151+
#endif
1152+
11291153
assert(collapse_remap[r0] == r0);
11301154
assert(collapse_remap[r1] == r1);
11311155

@@ -1673,6 +1697,10 @@ size_t meshopt_simplifyEdge(unsigned int* destination, const unsigned int* indic
16731697
if (edge_collapse_count == 0)
16741698
break;
16751699

1700+
#if TRACE
1701+
printf("pass %d:%c", int(pass_count++), TRACE >= 2 ? '\n' : ' ');
1702+
#endif
1703+
16761704
rankEdgeCollapses(edge_collapses, edge_collapse_count, vertex_positions, vertex_attributes, vertex_quadrics, attribute_quadrics, attribute_gradients, attribute_count, remap);
16771705

16781706
sortEdgeCollapses(collapse_order, edge_collapses, edge_collapse_count);
@@ -1684,10 +1712,6 @@ size_t meshopt_simplifyEdge(unsigned int* destination, const unsigned int* indic
16841712

16851713
memset(collapse_locked, 0, vertex_count);
16861714

1687-
#if TRACE
1688-
printf("pass %d: ", int(pass_count++));
1689-
#endif
1690-
16911715
size_t collapses = performEdgeCollapses(collapse_remap, collapse_locked, vertex_quadrics, attribute_quadrics, attribute_gradients, attribute_count, edge_collapses, edge_collapse_count, collapse_order, remap, wedge, vertex_kind, vertex_positions, adjacency, triangle_collapse_goal, error_limit, result_error);
16921716

16931717
// no edges can be collapsed any more due to hitting the error limit or triangle collapse limit

0 commit comments

Comments
 (0)