Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

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

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

Fedr wants to merge 8 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 (if it is unique), 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), all threads, same faces in the result except one tie noted below. Ryzen 9 with MSVC is min of 3 runs; i7-14700KF with MSVC and Apple M1 Pro with clang 22 are min of 2 alternating runs:

Case Ryzen master Ryzen PR i7 master i7 PR M1 master M1 PR
segmentByGraphCut, small far seeds, curvature metric 3183 764 1846 478 1956 629
segmentByGraphCut, seeds are 20% of the mesh at each end, length metric 13056 1501 12157 917 9939 1092
same, curvature metric 8373 1397 8014 1288 6262 1020
segmentByGraphCut, seeds 30% of the box apart 4904 989 4651 879 3889 788
same, 10% apart 277 271 214 244 220 219
same, 2% apart 52 51 48 49 35 35
fillContourLeftByGraphCut, closed contours 67 68 70 69 46 45
same, contours with many short gaps 167 165 161 142 124 124

The 10% case on i7 is 14% slower only when it runs after the far-seed cases in one process; started alone it takes 180 ms in master and 179 ms here (min of 4), and at one thread it is equal in both orders.

fillContourLeftByGraphCut with contours not separating the mesh: the first part of each of 5 loops (3287 edges in total), Ryzen:

Part of each loop Metric master this PR
90% length 5042 1571
90% absolute curvature 4699 1560
50% length 24225 1898
50% absolute curvature 25640 2165
10% length 9011 1622
10% absolute curvature 8865 1793

fillContourLeftByGraphCut with one closed loop not separating the mesh, torus of 1M faces stretched 2 times along x, Ryzen:

Loop Metric master this PR
around the tube, 501 edges length 103428 954
around the tube, 501 edges absolute curvature 69532 973
along the tube, 1000 edges length 119806 9066
along the tube, 1000 edges absolute curvature 159444 8844

The first row is the only measured case with another result: this torus is mirror-symmetric and has two shortest loops around the tube, and master and this PR return different cuts of the same cost. With the symmetry removed (the y > 0 side stretched 1.1 times) the faces are the same again, in 71248 and 943 ms. Loops around the thin handles of the dragon (8-495 edges) take 20-77 ms in both.

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

Thickness Ryzen master Ryzen PR i7 master i7 PR M1 master M1 PR
1.1% 454 455 267 268 290 286
1.8% 1658 1674 943 949 1084 1074
1.9% 3723 3175 2405 2076 2525 2118
2% 3436 3415 2110 2254 2502 2412
2.5% 7781 4242 5919 2984 4804 2854
3% 19557 6028 16086 4726 12767 3747

Up to 1.8% the switch is not reached and the code path is the same as in master. At 2% the switch comes just before the paths would finish: 7% slower on i7, and 4-6% slower at one thread on Ryzen and i7.

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 8 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>
…itch to push-relabel

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