Skip to content

Commit e42624d

Browse files
committed
simplify: Minor refactoring of performEdgeCollapses
To avoid mistakes, extract kind into a variable (we're only concerned with source vertex kind for classification since that's what determines the wedges we need to remap), and also add a few comments. Notably, we probably don't need to worry about attribute quadrics for complex vertices long term; the intention for complex classification has been to treat vertices with attributes that are similar enough as one, so this probably can function similarly to ranking where we're okay with ignoring the topology somewhat. Also, while we're here, adjust complex collapses to collapse to i1, not r1. This code is not used right now but collapsing to r1 feels slightly wrong since in some cases we'd be collapsing to a vertex that was never connected to any wedge in the complex.
1 parent 5229595 commit e42624d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/simplifier.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,8 @@ static size_t performEdgeCollapses(unsigned int* collapse_remap, unsigned char*
11281128
unsigned int r0 = remap[i0];
11291129
unsigned int r1 = remap[i1];
11301130

1131+
unsigned char kind = vertex_kind[i0];
1132+
11311133
// we don't collapse vertices that had source or target vertex involved in a collapse
11321134
// it's important to not move the vertices twice since it complicates the tracking/remapping logic
11331135
// it's important to not move other vertices towards a moved vertex to preserve error since we don't re-rank collapses mid-pass
@@ -1160,26 +1162,29 @@ static size_t performEdgeCollapses(unsigned int* collapse_remap, unsigned char*
11601162
quadricAdd(attribute_quadrics[i1], attribute_quadrics[i0]);
11611163
quadricAdd(&attribute_gradients[i1 * attribute_count], &attribute_gradients[i0 * attribute_count], attribute_count);
11621164

1163-
if (vertex_kind[i0] == Kind_Seam)
1165+
// note: this is intentionally missing handling for Kind_Complex; we assume that complex vertices have similar attribute values so just using the primary vertex is fine
1166+
if (kind == Kind_Seam)
11641167
{
1168+
// seam collapses involve two edges so we need to update attribute quadrics for both target vertices; position quadrics are shared
11651169
unsigned int s0 = wedge[i0], s1 = wedge[i1];
11661170

11671171
quadricAdd(attribute_quadrics[s1], attribute_quadrics[s0]);
11681172
quadricAdd(&attribute_gradients[s1 * attribute_count], &attribute_gradients[s0 * attribute_count], attribute_count);
11691173
}
11701174
}
11711175

1172-
if (vertex_kind[i0] == Kind_Complex)
1176+
if (kind == Kind_Complex)
11731177
{
1178+
// remap all vertices in the complex to the target vertex
11741179
unsigned int v = i0;
11751180

11761181
do
11771182
{
1178-
collapse_remap[v] = r1;
1183+
collapse_remap[v] = i1;
11791184
v = wedge[v];
11801185
} while (v != i0);
11811186
}
1182-
else if (vertex_kind[i0] == Kind_Seam)
1187+
else if (kind == Kind_Seam)
11831188
{
11841189
// remap v0 to v1 and seam pair of v0 to seam pair of v1
11851190
unsigned int s0 = wedge[i0], s1 = wedge[i1];
@@ -1200,7 +1205,7 @@ static size_t performEdgeCollapses(unsigned int* collapse_remap, unsigned char*
12001205
collapse_locked[r1] = 1;
12011206

12021207
// border edges collapse 1 triangle, other edges collapse 2 or more
1203-
triangle_collapses += (vertex_kind[i0] == Kind_Border) ? 1 : 2;
1208+
triangle_collapses += (kind == Kind_Border) ? 1 : 2;
12041209
edge_collapses++;
12051210

12061211
result_error = result_error < c.error ? c.error : result_error;

0 commit comments

Comments
 (0)