Skip to content

P1 part 2: the VolumeRover Skeletonization port on cvc::tet_complex - #1167

Merged
transfix merged 13 commits into
masterfrom
p1/skeleton
Nov 14, 2026
Merged

transfix merged 13 commits into
masterfrom
p1/skeleton

Conversation

@transfix

@transfix transfix commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Part 2 of P1: the VolumeRover Skeletonization port (docs/roadmap/VOLROVER-LIBRARY-PORTS-ROADMAP.md §2), built on cvc::tet_complex as you decided in #1157.

#1157 merged on 2026-11-13 (squash fb634c5), and master is merged into this branch (b5990c2). So the diff is now this PR's own work only, starting with 0e97c3c.

What lands

inc/cvc/geometry/skeleton.h and skeleton_params.h

  • cvc::skeletonize(points | geometry, params), skeleton_stepper and skeletonize_job (a result_job<skeleton>).
  • skeleton_params, with its param_table: 14 fields, legacy defaults, units and ranges.

The result holds:

  • strands: the U2 polylines as segments, plus the stars of the small planar clusters;
  • sheets: the big clusters' Voronoi facets, fanned into triangles;
  • helix: the legacy protein-helix strips, only with helix_window;
  • strand_of_line, sheet_of_tri, counts, and warnings.

src/cvc/geometry/skeleton/: the legacy library, ported (~5k lines). It is transfix/volrover src/Skeletonization at the pinned sha, UT LGPL-2.1, copyright headers kept.

  • The cvc::cocone core, shared: init, util, tcocone (Tight Cocone), rcocone (Robust Cocone). TightCocone, PocketTunnel and Curation reuse these later.
  • The skeleton stages: medax, U1 (in medax.cpp), U2 with the graph (u2.cpp), and skel (clusters, stars, polylines).
  • datastruct.h, the CGAL-shaped adapter over tet_complex, so the vendored files keep their shape:
    • handles are pointers to VC_cell / VC_vertex, which carry the legacy cell and vertex bases' fields;
    • CGAL's iterator orders (a facet is reported from its lower cell, an edge from its lowest cell);
    • CGAL's Facet_circulator / Cell_circulator moves;
    • an EPICK-like kernel: constructions term for term as CGAL computes them, exact predicates from Shewchuk's code.
  • Resumable (§1.9) through C++20 coroutines (stepping.h). Every long legacy function yields once per loop iteration and per step of every walk: the umbrella walks, the boundary growth, the in/out propagation, U1's growth, U2's integral curves and the polyline walks. So every phase is sliced and the legacy control flow is untouched. libcvc's state_exec already uses coroutines on every platform.
    • The phases are the triangulation's own, then building, voronoi, tight cocone, medial axis, sheets, strands, clean-up and output.
    • A sliced merge sort replaces the one sort that was added.
  • The skeleton_context of §1.3 is the stepper's impl: the bounding box, diagnostics, the triangulation and the partial results are all per call.

What it fixes on the way in (§2, plus what the A/B turned up)

From §2:

  • The global bounding_box is now the call's own. The T6 order test guards it.
  • srand(0) / rand() colours are gone. Colours depend on the sheet's rank; strands are green, stars blue.
  • Debug files in the current directory (degen_tetra, *.degen, *.degen_VF) are gone. Each case is counted and becomes a warning.
  • Flat Phi and the sharp angle are parameters. The VolumeRover2 dialog left Flat Phi uninitialised and hard-coded the sharp angle.
  • The helix window is an off-by-default parameter, with its own output.
  • Both sheets and strands are returned. Sheets are fanned from their first vertex: Voronoi facets are convex, and zero-area triangles are dropped.

Found in the port:

  • Five CGAL_assertion()s had side effects. has_vertex() in medax.cpp and tcocone.cpp, and find_acceptor() in u1.cpp and u2.cpp, fill the indices the code then uses. Release builds compile the assertions out, which leaves the indices at -1 or uninitialised: the code then reads vertex(-1), and set_VF_on_medax(-1, -1) writes out of bounds. The port makes the calls.
  • is_cospherical_pair() read the infinite vertex's uninitialised point across hull facets. It now returns false there.
  • Closed loops were dropped. The legacy walks polylines only from joints and leaves, so a torus's core circle gave an empty skeleton. The port also walks loops, so the roadmap's "a torus gives one closed strand" holds.
  • U2 depended on CGAL's memory layout. Which pieces of merging chains survive depends on the order the index-2 saddles are traced in. The legacy used its cells' memory order (CGAL's allocation history); the port sorts them by circumradius, as the legacy's switched-off sort intended, with a geometric tie-break. The skeleton is then a function of the point set (T4 checks shuffled input).
  • Degenerate triangles in do_intersect (from Voronoi facets whose vertices coincide on cospherical input) are tested as the point or segment they span. The legacy passed them to CGAL's do_intersect, which excludes them by precondition.

T1: the legacy library's own output

tools/volrover-goldens now also builds the legacy Skeletonization with CGAL (cvcpkg's, in the volrover goldens CI job). It compiles patched copies of the sources, with the five assertions made plain calls, as the port does. skeleton_driver.cpp writes what skeletonize() returns. Four committed float-exact point clouds:

Case Legacy Port
capsule (941 pts) 180 polyline segments 180, all matched exact
torus (768 pts) empty (the loop is dropped) the same open part (none) + 1 closed loop (T3 checks it) exact on the comparable part
box_grid, exactly cospherical (154 pts) 216 segments, 38 stars, 169 polygons (74 points, area 10.0659) all matched, same area exact, because the triangulation is CGAL's even here
dumbbell (1,236 pts) 362 segments (Linux goldens) 363: all 362 matched + 1 the U2 order effect above. Windows' legacy build gives 361, a slightly different set, and the port contains all of those too

Coordinates are compared to 1e-9 of the extent. The same T1 passes as wasm-mt under node, so MSVC and clang agree.

On the T16 skeleton row: the roadmap asked for "the skeletons built on each" triangulation. The goldens are exactly that: the legacy code on CGAL's DT3, against the port on tet_complex.

Other tests (skeleton_test, in CVC_PORT_TESTS and SAN_CXX_TESTS)

  • T2: do_intersect (crossing, beside, coplanar, through an edge, degenerate point and segment), the circumcentres, orientation, collinearity, ray/segment.
  • T3: a torus gives one closed strand near radius 4; a capsule one strand on its axis; a thin slab a sheet near its middle plane.
  • T4: shuffled input gives the same skeleton (box_grid, dumbbell, capsule). An exact quarter turn plus a translation maps it back, in general position. On cospherical input, the perturbation's lexicographic tie-breaking changes under rotation, as CGAL's does.
  • T5: too few points, coplanar, collinear, NaN, invalid parameters (every problem listed); a sphere sample, duplicates and four points all run.
  • T6: B after A and A after B equal each alone; two threads with different parameters equal each alone.
  • T7: the harness (bit-identical at budgets 1, 64, random and 0; cancel in each phase; frames). The slowest 4,096-unit step was 10 ms natively and 12 ms under node on the capsule.
  • T8: the table's fields and params_validate.

Checked locally

  • Windows, MSVC 19.44: skeleton_test 10/10, tet_complex_test 10/10, and cgal_ab_test passes.
  • wasm-mt under node 22: skeleton_test 10/10.
  • make_goldens.py --libs genseg,skeleton with CGAL 6.0.1 rewrites the GenSeg goldens byte-identically and writes the skeleton ones. CI's Linux check then made different bytes: the last digits, the order of tied box polygons, and on the dumbbell the merged chains (the legacy cells' memory order is the allocator's). So the committed skeleton goldens are the ones CI made on ubuntu-24.04 (21beba7; two runs made the same bytes), and skeleton_test passes against both sets.

Not here (part 3)

cvc skeleton, pycvc, the skeleton.compute intrinsic (with -start / -async / job.cancel), and T10–T12.

macOS

Without Shewchuk's predicates until #1165 merges. The macOS bundles were published on 2026-11-12, and #1165 adds macOS to the recipe's scopes. Until then the skeleton is unavailable there: skeletonize throws, and the tests skip.

Update 2026-11-12 (late): #1165 has merged, and master is merged into this branch (0a4ed9e). So this CI run is the first with CVC_WITH_SHEWCHUK on macOS, and the tests run on Apple clang instead of skipping.

…, part 1)

The skeletonization port's tetrahedral complex (VOLROVER-LIBRARY-PORTS-ROADMAP.md §2), with
TDS_3's conventions (an infinite vertex closing the hull, neighbours opposite vertices, mirror
indices, CGAL's next_around_edge order), built by tet_complex_builder, a resumable stepper
(§1.9): checking, ordering (BRIO rounds of Morton keys, a sliced LSD radix sort), inserting
(Bowyer-Watson: a visibility walk from the last new cell, the conflict region re-starred from
the new point), compacting, circumcentres.

The predicates are Shewchuk's (cvcpkg shewchuk-predicates), with CGAL's symbolic perturbation
for cospherical and coplanar ties, so the triangulation is unique and is CGAL's
Delaunay_triangulation_3 cell for cell: cgal_ab_test's new tet_complex rows find it identical on
all 11 of its inputs, the 10^3 and 20^3 lattices, an exactly cospherical integer sphere, the
rounded sphere and a cocircular cylinder included, at 0.97-2x CGAL's speed in general position
and 4-6x Qhull's batch build. The INFO rows show what dropping Qhull's flat tetrahedra would
leave instead: 3,444 facets with no neighbour on the 10^3 lattice.

tet_complex_test (a port test, so also wasm-mt under node, and in the sanitizer lanes): exact
Delaunay and validity on clouds and degenerate input, equality with Qhull's batch build in
general position, independence of input order and seed, traversals against brute force,
duplicates, bad input, and the T7 harness. Without Shewchuk's predicates (macOS today) the
builder throws and the test skips. The ports lane installs qhull and shewchuk-predicates; the
cgal-ab job watches the new files.
The radix sort's arrays are allocated uninitialised, the point, duplicate and vertex-cell
arrays are filled while keying, the remap and the circumcentres are appended in counted loops,
and compaction moves the finite cells and then the infinite ones in two appending passes. The
slowest 4096-unit step is now 0.4-0.8 ms at 20k-100k points (cgal_ab's stepped rows report it).
§1.2's replacement table, §1.9's third-party calls, §2's triangulation and resumable phases,
the T16 row, the P1 row and §9 now say cvc::tet_complex, the exact incremental Delaunay on
Shewchuk's predicates measured in this PR, instead of Qhull. Qhull stays only as the
general-position cross-check in tet_complex_test and cgal_ab_test.
…n port, part 2)

cvc::skeletonize, skeleton_stepper and skeletonize_job (inc/cvc/geometry/skeleton.h) with
skeleton_params' table (skeleton_params.h): the legacy library (transfix/volrover
src/Skeletonization, UT LGPL-2.1) ported into src/cvc/geometry/skeleton/ as the shared
cvc::cocone core (init, util, Tight Cocone, Robust Cocone) and the skeleton stages (medial axis,
U1 and its planar clusters, U2 and its graph, polylines, stars), on tet_complex behind a
CGAL-shaped adapter (datastruct.h), so the vendored code keeps its shape.

Resumable (§1.9): every long legacy function is a C++20 coroutine that yields once per loop
iteration and per step of every walk (stepping.h); the stepper resumes the top one a unit at a
time, through the triangulation's own phases and "building", "voronoi", "tight cocone",
"medial axis", "sheets", "strands", "clean-up" and "output".

The fixes (§2): no global bounding box, no srand/rand (colours by index), no debug files (their
cases are warnings), Flat Phi and the sharp angle are parameters, the helix window is an
off-by-default parameter, and both sheets (fanned) and strands are returned. Also fixed: five
CGAL_assertion()s with side effects that release builds compiled out (has_vertex, find_acceptor),
the infinite vertex's point read in is_cospherical_pair, closed loops dropped from the strands, and
U2's dependence on the cells' memory order (the saddles are traced in a geometric order).

T1: tools/volrover-goldens builds the legacy library with CGAL (patched copies; the same five
assertions made plain calls) and writes goldens for four committed point clouds; the CI job
installs CGAL, GMP, MPFR and Boost. skeleton_test matches them exactly on the capsule, the torus
and the cospherical box, and contains all 361 legacy segments on the dumbbell (2 more, the order
effect). Also T2-T8: kernel predicates, known shapes, point-order and rigid-motion invariance,
bad input, threads and call order, the T7 harness, the parameter table. Passes natively and as
wasm-mt under node; joins the ports lane and the sanitizer lanes.
The asan-ubsan job failed in TetComplex.DuplicatesMapToTheirFirstPoint with
a stack-buffer-overflow in shewchuk::detail::fast_expansion_sum_zeroelim,
called from orient3dadapt. Shewchuk's expansion sums read one element past an
input expansion on their last pass (`fnow = f[++findex]`); the value is never
used, so the predicates' results are right, but the read is out of bounds.

exact_predicates.cpp is now the only file that includes
<shewchuk/predicates.hpp>, and tet_complex.cpp calls cvc::exact::orient3d,
insphere and orient2d. The ASan builds compile that one file without ASan, as
the cvcpkg deps are, so no instrumented copy of the header's inline functions
is linked. The header itself should guard the read in cvcpkg's recipe.
…n skips

The skeleton kernel (skeleton/datastruct.cpp) calls cvc::exact::orient3d and
orient2d too, so exact_predicates.cpp stays the only file that includes
<shewchuk/predicates.hpp> and no ASan-instrumented copy of its expansion
sums is linked.
The skeleton goldens were made on Windows, and CI's check on ubuntu-24.04 compares bytes, so
it failed on box_grid, capsule and dumbbell. The legacy output differs by platform: the last
digits and the order of tied sheet polygons on the box and capsule, and on the dumbbell the
merged chains themselves (361 segments on Windows, 362 on Linux), since the legacy code walks
its cells in the allocator's memory order.

Commit the goldens CI made (two CI runs made the same bytes). skeleton_test still passes against
them: capsule, box and torus exact to 1e-9, and the port has all 362 legacy dumbbell segments
plus 1 (it also contains Windows' 361). The README and the test's comment say so.
# Conflicts:
#	.github/workflows/ci.yml
#	src/cvc/tests/port_tests.cmake
# Conflicts:
#	.github/workflows/ci.yml
#	src/cvc/tests/port_tests.cmake
@transfix
transfix merged commit b5aae62 into master Nov 14, 2026
29 of 34 checks passed
@transfix
transfix deleted the p1/skeleton branch November 14, 2026 04:43
transfix added a commit that referenced this pull request Nov 14, 2026
transfix added a commit that referenced this pull request Nov 14, 2026
transfix added a commit that referenced this pull request Nov 14, 2026
…#1177, #1167) into perf/threaded-s1b

The one conflict is the sanitizers' SAN_CXX_TESTS list in ci.yml: this branch added
stream_test, net_ws_client_test and ariadne_host_test, and #1167 added skeleton_test. The
list keeps all four.
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