Repository navigation
cvc::segment_seeded: GenSeg vendored, sliced, matching the legacy library voxel for voxel (P5 part 1) - #1248
Merged
3 commits merged intoNov 15, 2026
Merged
3 commits merged into
3 commits merged into
Conversation
…rary voxel for voxel (P5 part 1) VolumeRover's GenSeg seeded segmentation (docs/roadmap/VOLROVER-LIBRARY-PORTS-ROADMAP.md §5 step 1) in src/cvc/volume/segmentation/: segment.cpp's globals become genseg_context's members, its functions keep their bodies (the hand-unrolled neighbour updates included), and Segment(), GetGradient(), GetSeeds() and SearchIndex() are coroutines that yield a unit at a time. In-memory input and output: no files, no current directory. - inc/cvc/volume/segmentation.h: segment_seeded(volume, point_classes, params), segment_stepper (checking, normalising, seeding, classifying, marching, writing), segment_seeded_job (cvc::result_job), seeded_segmentation (labels, per-class volumes, border, counts, warnings). - inc/cvc/volume/segmentation_params.h: the param_table (thresholds in data units or the legacy 0..255 scale, gamma, automatic seeding, variable and timestep, class volumes). - Three fixes of the legacy code's undefined behaviour: an empty heap pop (the legacy executable crashes on such an input), a heap overflow, and a threshold sweep that ran on below 0. - tools/volrover-goldens: three more GenSeg cases that run the threshold sweep (the first three never did), with their goldens from the legacy build. - segmentation_test: T1 on all six goldens, T2-T8; in CVC_PORT_TESTS (the wasm-mt node lane) and SAN_CXX_TESTS.
This was referenced Nov 14, 2026
transfix
enabled auto-merge (squash)
November 15, 2026 04:49
…on says genseg.cpp and segmentation.cpp get -ffp-contract=off (/fp:precise on MSVC) like the other deterministic sources: the marches compare float arrival times, and a contracted step can flip which front wins a tie on targets with FMA (aarch64 macOS).
transfix
disabled auto-merge
November 15, 2026 04:54
transfix
enabled auto-merge
November 15, 2026 04:54
transfix
added a commit
that referenced
this pull request
Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
P5 part 1 of docs/roadmap/VOLROVER-LIBRARY-PORTS-ROADMAP.md (§5 step 1): VolumeRover's GenSeg seeded segmentation, vendored into
src/cvc/volume/segmentation/and matching the legacy library voxel for voxel.What lands
cvc::segment_seeded(inc/cvc/volume/segmentation.h): a volume andcvc::point_classes(P0d) in, aseeded_segmentationout: the labels as a UChar volume, a volume per class (the legacy_subunit_<n>.rawiv, now in the input's type and data units), the border voxels (the legacy_indices.txt), class names and counts, the seed counts and warnings. No files, no current directory.cvc::segment_stepperwith every phase sliced (§1.9):checking,normalising,seeding,classifying,marching,writing. A unit is a voxel visited, a seed placed, a voxel popped from a heap or a step of a walk.segment_seeded()is the stepper at budget 0;segment_seeded_job()wraps it incvc::result_job(P0b).seeded_segmentation_paramswith itscvc::param_table(inc/cvc/volume/segmentation_params.h):t_low,t_high(data units, or the legacy 0..255 scale withnormalized_thresholds),gamma(the paper's speed, -0.12 as in GenSeg),automatic(none/local_maxima, the default per Joe's decision),variable/timestep(which classes seed the run, as VolumeGridRover sent them),class_volumes.genseg.cpp,genseg.h): segment.cpp's ~25 globals aregenseg_contextmembers (§1.3); its functions keep their bodies, the hand-unrolled neighbour updates included.Segment(),GetGradient(),GetSeeds()andSearchIndex()are coroutines that yield a unit at a time. Every other change is listed at the top of genseg.cpp: no files or printf, exp() in double on every platform, size_t indices, and three fixes of undefined behaviour (below).-ffp-contract=off//fp:preciselike the other deterministic sources.Parity (T1)
segmentation_test'sMatchesTheLegacyLibrarycompares labels and border lists withtools/volrover-goldenson six cases: identical on all six, natively and under node.The three committed cases never ran GenSeg's threshold sweep (the code that gives each automatic seed a class): every automatic seed sat under a user seed. So this PR adds three cases to
make_inputs.py(the existing inputs regenerate byte for byte) and their goldens, made with the legacy build (MSVC 2022, as the first three were):auto_seeds_sweep(28³)blob_touching_shell(24³)noisy_many_seeds(24³)volrover goldensCI checks them on Linux with GCC.The legacy library crashes on some inputs. With noise 0.5 instead of 0.45,
noisy_many_seedsmakes the legacy executable crash with an access violation. A seed the sweep classifies has nowhere to go, and the legacy march then pops an empty heap and reads before its arrays. The port ends that march (RunsWhereTheLegacyLibraryCrashed). It also grows a heap that would overflow, where the legacy code wrote past the end, and it stops the sweep once the threshold is below 0, where every later search would find nothing again.A legacy behaviour worth knowing for P6 and P9: a step costs 0.01 exp(0.12 |∇I|), with |∇I| rescaled so that the steepest voxel is 255. Where |∇I| is above about 172 the cost passes
MAX_TIME, and the front stops. So on smooth data GenSeg labels each feature's core and stops at its steepest flank. The parity tests pin this; the paper mode (P6) is where it could change.Tests (§1.7 rows)
t_low;t_low;t_low.seed (3, 16, 2) of class 'c1' is outside the 16x16x16 volume), more than 254 classes, a constant volume, NaN and infinite voxels, and bad parameters throwsegmentation_error;t_low, a class with no points and a voxel in two classes are warnings;cvc::apps at once, each result belonging to its input's app.auto_seeds_sweep. The slowest step at budget 4096 is 0.75 ms natively, and stepping costs 3% over budget 0. A step of 64 units stays bounded at 48³ as at 16³.segmentation_testis inCVC_PORT_TESTS, so theports (wasm-mt, node)lane builds and runs it, and inSAN_CXX_TESTSfor the tsan and asan-ubsan lanes. No CI job is added or renamed.The port is as fast as the legacy executable: 2.2 s against 2.3 s on
noisy_many_seeds.Rules
git-clang-formaton the changed lines; ci.yml keeps its line endings (one line changed).Next (P5 parts 2 and 3)
cvc segment, pycvc, andsegment.seededwith its-asyncand-startforms.