Revert: remove triangle quality refinement

This commit is contained in:
wyj committed 2026-08-29 03:26:17 -04:00
1 parent 451b700b32
commit d1320fffc4
5 files changed
+9 -161

No files matched your search

+4 -50
View File
@@ -139,20 +139,6 @@ static double image_triangle_area(const LensVertex *a, const LensVertex *b,
(b->image_y - a->image_y) * (c->image_x - a->image_x));
}
/* Four times sqrt(3) times the area divided by the squared-edge sum. This
* is scale-independent, equals one for an equilateral triangle, and tends to
* zero for a sliver. */
static double image_triangle_quality(const LensVertex *a, const LensVertex *b,
const LensVertex *c) {
const double ab = image_edge_length(a, b);
const double bc = image_edge_length(b, c);
const double ca = image_edge_length(c, a);
const double squared_edges = ab * ab + bc * bc + ca * ca;
if (squared_edges == 0.0)
return 0.0;
return 4.0 * sqrt(3.0) * image_triangle_area(a, b, c) / squared_edges;
}
static unsigned int longest_side(const FrameLensMesh *mesh,
const LensTriangle *triangle) {
unsigned int best = 0;
@@ -444,24 +430,6 @@ static LensVertex midpoint_vertex(const LensVertex *a, const LensVertex *b) {
return result;
}
/* A conformity request can require splitting a neighbor along a non-longest
* edge. Unlike longest-edge bisection, that can create a sliver. Promote
* that leaf to red refinement before allocating vertices when either of the
* two prospective children violates the requested image-plane quality. */
static int single_edge_split_requires_red(const FrameLensMesh *mesh,
const LensTriangle *triangle,
unsigned int side,
const RefinementConfig *config) {
if (config->min_triangle_quality <= 0.0)
return 0;
const LensVertex *a = &mesh->vertices[triangle->vertex[side]];
const LensVertex *b = &mesh->vertices[triangle->vertex[(side + 1) % 3]];
const LensVertex *c = &mesh->vertices[triangle->vertex[(side + 2) % 3]];
const LensVertex midpoint = midpoint_vertex(a, b);
return image_triangle_quality(a, &midpoint, c) < config->min_triangle_quality ||
image_triangle_quality(&midpoint, b, c) < config->min_triangle_quality;
}
static int append_triangle(LensTriangle *triangles, size_t *count,
size_t capacity, size_t a, size_t b, size_t c,
unsigned int level, int evaluated) {
@@ -558,34 +526,20 @@ int frame_lens_mesh_finish_generation(FrameLensMesh *mesh,
requested[3 * edges[i].triangle + edges[i].side] = 0;
first = last;
}
/* Two requested sides require red refinement. A single requested edge
* whose bisection would form a sliver is also promoted to red refinement.
* Close every new shared-edge request before allocating any vertices. */
/* Two requested sides require red refinement. Add the third side, then
* close the new shared edge requests before allocating any vertices. */
for (;;) {
int changed = 0;
for (size_t t = 0; t < mesh->triangle_count; ++t) {
unsigned int count = 0;
unsigned int requested_side = 0;
for (unsigned int side = 0; side < 3; ++side)
if (requested[3 * t + side]) {
++count;
requested_side = side;
}
if (count == 1 && allowed[t] &&
single_edge_split_requires_red(mesh, &mesh->triangles[t],
requested_side, config)) {
count += requested[3 * t + side] != 0;
if (count >= 2 && allowed[t])
for (unsigned int side = 0; side < 3; ++side)
if (!requested[3 * t + side]) {
requested[3 * t + side] = 1;
changed = 1;
}
} else if (count >= 2 && allowed[t]) {
for (unsigned int side = 0; side < 3; ++side)
if (!requested[3 * t + side]) {
requested[3 * t + side] = 1;
changed = 1;
}
}
}
for (size_t first = 0; first < edge_count;) {
size_t last = first + 1;