Skip to content

Keep remesh and disk_cap finite on folded input - #133

Merged
m-reuter merged 1 commit into
Deep-MI:mainfrom
m-reuter:folded-disk-cap
Nov 12, 2026
Merged

m-reuter merged 1 commit into
Deep-MI:mainfrom
m-reuter:folded-disk-cap

Conversation

@m-reuter

@m-reuter m-reuter commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

disk_cap could fail with ValueError: 'x' must be finite or RuntimeError: Factor is exactly singular when the least-area triangulation of its boundary folds. This happens for long boundaries that wind through the folds of a brain surface, for example when closing patches or cropping protrusions in topology correction, and also for a simple figure eight.

Two causes, both in remeshing folded input:

  • remesh: tangential smoothing normalized the summed vertex normals with divide warnings switched off. At a vertex whose surrounding triangles face opposite ways the normals cancel, the vertex became NaN, and the next projection failed. Such vertices, and vertices whose neighbourhood has no area, now stay where they are, since they have no tangent plane to move in.
  • disk_cap: remeshing a folded disk can leave inner vertices with only triangles without area. Their rows in the cotangent matrix are zero, and the minimal surface step cannot be solved. A round whose step fails or gives non-finite vertices is now not applied, and the disk stays as it was, the same as for a round that would fold the disk more.

Tests:

  • remesh of a fan whose neighbours form a bowtie, so that the summed normal at its centre is zero: the result is finite and keeps its boundary.
  • disk_cap of a flat figure eight: the result is a finite, oriented disk spanning the boundary.

Both fail on the current release. The singular case only showed up on long boundaries from real surfaces and could not be reproduced with a small input, so the second change has no test of its own.

@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.23077% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.18%. Comparing base (23f321b) to head (f6ad4e1).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
lapy/topology.py 33.33% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #133      +/-   ##
==========================================
- Coverage   72.22%   72.18%   -0.05%     
==========================================
  Files          20       20              
  Lines        4087     4095       +8     
  Branches      522      523       +1     
==========================================
+ Hits         2952     2956       +4     
- Misses        919      922       +3     
- Partials      216      217       +1     
Flag Coverage Δ
unittests 72.18% <69.23%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The singular-solve and non-finite-result fallbacks lack regression tests verifying that disk_cap preserves the last accepted mesh when failure occurs initially or after a successful round.

1 open issue
What changed in this PR

This PR makes mesh remeshing and disk capping more robust on folded input, preventing undefined smoothing operations and preserving the last accepted disk when a harmonic step fails.

Changes:

  • Keep vertices stationary when their summed normals cancel or smoothing weights are zero.
  • Reject disk-cap rounds whose harmonic solve raises RuntimeError or returns non-finite coordinates.
  • Add bowtie and figure-eight regression tests for finite output and preserved boundary topology.
File Description
lapy/​utils/​tests/​test_topology.py Adds a figure-eight disk-cap regression test.
lapy/​utils/​tests/​test_remesh.py Tests remeshing with cancelling vertex normals.
lapy/​topology.py Handles failed or non-finite harmonic steps and documents the fallback.
lapy/​remesh.py Guards tangential smoothing against undefined normals and zero weights.

Review effort: Balanced

Comment thread lapy/topology.py Resolved
@m-reuter
m-reuter merged commit c6ac075 into Deep-MI:main Nov 12, 2026
15 checks passed
@m-reuter
m-reuter deleted the folded-disk-cap branch November 12, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants