Skip to content

GraphCut: push-relabel when augmenting paths get long - #7685

Open
Fedr wants to merge 7 commits into
masterfrom
graphcut-oneshot-faster
Open

Fedr wants to merge 7 commits into
masterfrom
graphcut-oneshot-faster

Conversation

@Fedr

@Fedr Fedr commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

segmentByGraphCut and fillContourLeftByGraphCut return the same minimal cut, faster when it is hard to find.

  • Augmenting paths between two trees run first, as before. After 32 work units (path steps and orphans) per face, push-relabel (highest label, global relabeling, gap heuristic) continues from the same flow. An earlier switch gains more on hard inputs, but is up to 1.5x slower where the paths were about to finish.
  • Push-relabel pushes from sinks to sources and releases sink capacity in 16 stages, so the result is the same source side as before. Global relabeling runs every n relabels from the source faces having other neighbors.
  • Contour edges get zero capacity instead of being checked in every scan.

Time in ms, 1M faces (dragon), min of 3 runs, same faces in the result everywhere:

Case master this PR
segmentByGraphCut, small far seeds, curvature metric 3074 736
segmentByGraphCut, seeds are 20% of the mesh at each end, length metric 12530 1463
same, curvature metric 8010 1357
segmentByGraphCut, seeds 30% of the box apart 4703 964
same, 10% apart 267 265
same, 2% apart 51 51
fillContourLeftByGraphCut, closed contours 67 65
same, contours with gaps 163 160

Graph cut inside findOuterLayer on a shell of 2M faces made by makeThickMesh, by thickness in percent of the box diagonal:

Thickness master this PR
1% 262 275
1.1% 454 455
1.2% 545 550
1.3% 601 609
1.4% 684 692
1.5% 867 875
1.6% 847 852
1.7% 1282 1271
1.8% 1658 1674
1.9% 3723 3175
2% 3436 3415
2.1% 3812 3566
2.2% 4007 3394
2.3% 4556 3571
2.5% 7781 4242
3% 19557 6028

Up to 1.8% the switch is not reached and the code path is the same as in master. Limited to one thread, 2% is 4% slower (3593 and 3730 ms), the other thicknesses are equal or faster.

Test plan

  • New test MRMesh.SegmentByGraphCutLongPaths reaches push-relabel; existing graph cut and contour cut tests pass.
  • Results compared face by face with master on 3 meshes and 11 seed and contour scenarios, also with asserts enabled.

Generated with Claude Code

Fedr and others added 7 commits December 4, 2026 18:25
Augmenting paths between two trees run first. If they take more than
16 orphans and path steps per face, or more than 500 per augmentation,
highest-label push-relabel with global relabeling and gap heuristic
continues from the same flow, releasing sink capacity in 16 stages.
4.5-15x faster for seeds far apart, the same minimal cut.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The work-per-augmentation rule fired after 0.2 units per face in findOuterLayer
on a thick shell of 2M faces, where the trees were about to finish: 2.4x slower than before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The constructor took 28 ms on 1M faces, now about 20 ms.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Shells in findOuterLayer with thickness 1.5-1.7% of the box diagonal were slower than with trees only, now they are faster.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Push-relabel works on a copy of the residual graph while path augmentation continues in a task, the first to finish gives the result. Shells in findOuterLayer with thickness 1.1-1.3% of the box diagonal were up to 1.46x slower than with trees only, now within 8%.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An earlier switch was up to 1.5x slower than trees only on shells in findOuterLayer with thickness 1.1-1.3% of the box diagonal, and racing the two methods helped only with a free thread. With the later switch no sampled thickness is slower.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

1 participant