Skip to content

fix(LBIE): adaptive hex meshes without collapsed or inverted hexahedra; QUAD meshes all quads - #806

Merged
transfix merged 3 commits into
masterfrom
fix/lbie-adaptive-hex-collapse
Oct 25, 2026
Merged

transfix merged 3 commits into
masterfrom
fix/lbie-adaptive-hex-collapse

Conversation

@transfix

@transfix transfix commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

LBIE's adaptive hexahedral meshes came out about half collapsed on real inputs, fem_gallery's head.off and the vh4.rawiv CT: corners repeated, and many of the remaining hexes were inverted. QUAD meshes had degenerate faces and cracks. This PR fixes all of it in three commits.

1. Collapsed hexahedra: the octree stays on one level (55fcbcb)

LBIE builds hexahedra on a uniform grid of octree cells at oct_depth-2. hexahedralize's templates then refine that grid where the error is large. Octree::traverse_qef also refined the octree itself, for every mesh type, wherever a cell's QEF error passed err_tol. Across a level change:

  • min_vtx_hexa gave one coarse cell's vertex to up to four corners;
  • a coarse vertex overflowed its 18 refine_edge slots, and AddRefine_* returned vertex 0.

The fix keeps HEXA on one level.

2. Snapping, optimization, QUAD, refine slots (b87c749)

  • Snapping inverted hexahedra. get_vtx_new walks boundary vertices up to a cell along their normal. When that inverts a hexahedron, hexahedralize now extracts the same mesh again without snapping. That gives the same vertices and hexahedra, used as a reference. Vertices of bad hexahedra go back toward the reference, then advance toward the surface as far as they can without taking any hexahedron below a scaled Jacobian of 0.1, or below where it was.
  • One-face template: AddVert_hexa_adaptive_2_4 averaged point 41 where it meant 42, which made its hexahedra flat or skewed even in a cube.
  • Optimization judged corners with testHexa's unsigned Jacobian, so it pushed corners into inversions. Now:
    • moves are judged by the signed Jacobian, in double;
    • no move may take a corner below 0.01, or below where it was;
    • a move must make the worst corner around the vertex better;
    • the search tries getGrad's direction, the axes, then the corner's neighbours;
    • a stuck corner no longer ends the pass.
  • QUAD meshes. Method 5's templates now refine only an octree whose leaves are on one level. A mesh with triangles at level changes has every face split once into quads (quads into four, triangles into three), sharing edge midpoints.
  • Refine slots: an overflow map for more than 18 refinements at a vertex. AddBound_edge keeps every boundary edge, not just the first.

3. No inverted hexahedra left (f1f72fb)

The leftover inverted hexes were already inverted in the reference. Its boundary vertices sat at QEF points, which inverted 276 of vh4's hexes. The reference now puts every vertex at its cell's centre, where none is inverted. Further changes:

  • A corner with an edge under 1% of its longest counts as flat. The scaled Jacobian sees only edge directions, so a vertex could slide onto its neighbour unnoticed.
  • A vertex that can't advance keeps exactly its position, instead of being rebuilt from a rounded float.
  • Bad hexahedra pull their corners back together only as far as needed, instead of straight to the reference. Straight back spread to a third of vh4's vertices and took a sphere's boundary 40 times as far off the surface.
  • The advance revisits a vertex only when a neighbour has moved since its last try.

Results

Measured through LBIE::do_mesh (DUALLIB, NO_IMPROVE). The head input is head.off as a 64³ SDF, built with SDF_V1 because this build has no libigl. "Inverted" means a hexahedron with a corner whose scaled Jacobian is ≤ 0. "SJ" is the mean of each hexahedron's minimum corner scaled Jacobian.

master 55fcbcb b87c749 f1f72fb
vh4 hexes 952,750, 451,460 repeat a corner 183,708, none repeated same same
vh4 inverted / SJ most / 0.07 (reported) 19,974 / 0.70 23 / 0.77 0 / 0.77
head hexes 85,337, 44,908 repeat a corner 5,719, none repeated same same
head inverted / SJ / 0.005 (reported) 364 / 0.65 5 / 0.69 0 / 0.69
head QUAD 30,191 faces: 1,243 triangles, 1,709 open edges same 16,486 quads, 0 triangles, 0 open edges same
vh4 QUAD 299,205 faces: 9,330 triangles, 579 open edges same 123,725 quads, 0 triangles, 300 open edges same

On the remaining open and over-shared edges in vh4 QUAD:

The re-extraction runs only when snapping inverted something. Timing on the test machine was inconclusive: it was saturated by other jobs, and vh4 runs ranged from 3.9 to 7.7 s against about 7.5 s before.

Interplay with #808

#808 (tet meshing) also edits traverse_qef, so the two PRs conflict there and in lbie_mesher_test.cpp. I ran a trial merge of both, resolved as follows:

With that resolution, lbie_mesher_test passes 57/57 (this PR's 52 plus #808's 5), plus algorithm_test 10/10 and geometry_test 111.

Whichever PR lands second needs that rebase.

Tests

Each new test fails on the code before its fix:

  • HexahedraHaveEightDistinctCornersWhereTheErrorIsLarge
  • OneFaceTemplatePutsItsMiddlePointsHalfwayDown
  • SnappingToTheSurfaceInvertsNoHexahedron
  • HexahedraOnSharpEdgesAreNotInverted: before, 22 of 1,323 inverted.
  • QuadMeshesWithLevelChangesAreClosedAndAllQuads
  • RefinementPastEighteenEdgesAtAVertexMakesNewVertices
  • AVertexKeepsAllItsBoundaryEdges

OptimizationMovesTheWorstCornersOwnVertex now also checks that its corner, which is inverted, comes out uninverted.

Local runs (Windows, MSVC, shared): lbie_mesher_test 52/52, algorithm_test 10/10, geometry_test 111 passed (8 env-gated skips), cvc_cli_test mesh cases 31/31. The exact fem_gallery commands (#803) were not re-run, because they need a libigl-enabled build of this branch.

…s no longer collapse

LBIE builds hexahedra on a uniform grid of octree cells at oct_depth-2 and
refines that grid with hexahedralize's templates (hexa_adaptive_2) where the
error is large. Octree::traverse_qef also refined the octree itself, for every
mesh type, wherever a cell's QEF error passed err_tol. A variant still in the
file, commented out, stopped QUAD and HEXA at the grid's level (end_level =
start_level + 1); the live one computes start_level and end_level and never
uses them.

With leaves on two or three levels the grid has level changes, and hexahedra
across them collapse in two ways:
- min_vtx_hexa climbs to the leaf that holds a cell, so the dual hexahedron at
  a fine vertex on a coarse cell's face or edge takes the coarse cell's vertex
  for up to four corners;
- a coarse vertex is a corner of more refined edges and faces than its 18
  refine_edge slots hold, and AddRefine_edgevtx_hex / AddRefine_facevtx then
  return vertex 0.
The templates are not at fault: on one level every path (one vertex, one edge,
one face, all eight refined) gives eight distinct corners.

The QEF error is in the volume's units, which is why a terraced SDF (head.off)
or a CT in voxel units (vh4.rawiv) refined and a sphere in a unit box did not.
Through cvc::hexahedralize with NO_IMPROVE:
- vh4.rawiv, iso 45: 952,750 hexahedra, 451,460 with a repeated corner (leaves
  on L5, L6, L7) -> 183,708, none (L5 only); mean min-corner scaled Jacobian
  0.68 -> 0.92
- head.off as a 64^3 SDF (SDF_V1): 85,337 hexahedra, 44,908 repeated (L4, L5,
  L6) -> 5,719, none; mean min-corner scaled Jacobian -0.01 -> 0.65
The counts drop because the deeper levels produced mostly collapsed elements;
a finer mesh comes from a finer volume. Meshes whose octree never went past the
grid (the bunny, every sphere already in the tests) are unchanged.

Only HEXA changes. QUAD has the same level changes (1,243 of the head's 30,191
quads repeat a vertex), but on one level its surface drops to 988 quads, so it
is left alone here.

HexahedraHaveEightDistinctCornersWhereTheErrorIsLarge meshes the tests' sphere
at 17^3 in a box 32 across, where 3585 of 8051 hexahedra repeated a corner.
…meshes all quads; no vertex 0 from full refine slots

The follow-ups the first commit left open.

Inverted hexahedra. get_vtx_new snaps boundary vertices onto the surface by
walking each up to a cell along its normal, and the templates place their
vertices between snapped corners; that inverted 12 of the 189 hexahedra of a
17^3 sphere, 364 of the head SDF's 5,719 and 19,974 of the vh4 CT's 183,708.
Snapping only moves vertices, so hexahedralize now extracts again without it
(same vertices and hexahedra) whenever a hexahedron came out inverted or flat:
the vertices of those go back to their unsnapped places until none is left,
then each goes toward the surface again as far as it can without taking a
hexahedron around it below a scaled Jacobian of 0.1 (or below where it was).
Head: 5 inverted left, vh4: 23, all of them already inverted unsnapped; 8% and
11% of their vertices stop short of the surface. vh4 extraction takes 13.9 s
instead of 7.5.

The one-face template (AddVert_hexa_adaptive_2_4) averaged point 41 for 42 and
put one of its points half a sub-cell off: one of its hexahedra was flat and
four skewed even in a cube.

Optimization. testHexa's Jacobian is the square root of the Gram determinant,
so it never saw an inverted corner (and in float a nearly flat one is noise):
one -q pass inverted 21 of the sphere's 189 hexahedra, and
OptimizationMovesTheWorstCornersOwnVertex was pushing an already inverted
corner further in. Moves are now judged by the signed Jacobian in double, may
not take a corner below 0.01 (or below where it was), and must make the worst
corner around the vertex better. The search tries getGrad's direction and the
axes, then the corner's three neighbours when its own vertex is stuck, and a
stuck corner no longer ends the pass. A pass now never inverts a corner, and it
untangles 2 of the head's 5.

QUAD meshes. Where the octree's level changes a quad got two corners on one
vertex, a triangle (head 1,243, vh4 9,330), and method 5's templates did not
match up across the change, leaving open edges (head 1,709). The templates now
refine only an octree whose leaves are on one level, and a mesh with triangles
has every face split once, quads into four and triangles into three, sharing
edge midpoints: head 16,486 quads, none degenerate, no open edges. vh4 keeps
150 open edges per half (one vertex per cell on noisy CT), down from 579.

Refine slots. AddRefine_* returned vertex 0 once a vertex's 18 refine_edge slots
were full (32 of vh4's quads); further refinements now go to refine_more.
AddBound_edge filled every free slot with the first edge, so a vertex kept one.

Tests: OneFaceTemplatePutsItsMiddlePointsHalfwayDown,
SnappingToTheSurfaceInvertsNoHexahedron, QuadMeshesWithLevelChangesAreClosedAndAllQuads,
RefinementPastEighteenEdgesAtAVertexMakesNewVertices, AVertexKeepsAllItsBoundaryEdges,
each failing before; OptimizationMovesTheWorstCornersOwnVertex now also checks the
corner comes out uninverted.
@transfix transfix changed the title fix(LBIE): the hexahedral octree stays on one level, so adaptive hexes no longer collapse fix(LBIE): adaptive hex meshes without collapsed or inverted hexahedra; QUAD meshes all quads Oct 25, 2026
…ry kept closer to the surface

The previous commit left 5 inverted hexahedra in the head SDF's mesh and 23 in
the vh4 CT's. Each was already inverted in the reference mesh untangle_snapped
sends vertices back to: extracted without snapping, its boundary vertices sat at
QEF points, and those inverted 276 of vh4's hexahedra. The reference now puts
every vertex at its cell's centre (min_vtx_hexa), so none is inverted there, and
nothing is left inverted: head 5 -> 0, vh4 23 -> 0. A turned cube, whose QEF
points sit on its sharp edges, kept 22 of 1323
(HexahedraOnSharpEdgesAreNotInverted).

Three more fixes in the same loop, found with snapping started from cell
centres (as #808 does):
- hexa_min_scaled_jacobian counts a corner with an edge under 1% of its longest
  as flat. The scaled Jacobian sees only edge directions, so it rated a corner
  well while a vertex slid onto its neighbour, and mapping to world coordinates
  then made the two coincide.
- A vertex that cannot advance keeps exactly the position it had; rebuilding it
  from along[v], which was a float, landed a rounding error away.
- The corners of a bad hexahedron go back together only as far as it takes to
  mend it, instead of straight to the reference. Straight back spread to a third
  of vh4's vertices and took a 33^3 sphere's boundary 40 times as far off the
  surface (64.7 -> 1.6 cells summed), for no better quality.

The advance revisits a vertex only when a neighbour has moved since its last
try, and bisects 6 times instead of 12.
@transfix
transfix merged commit 6fe3af7 into master Oct 25, 2026
25 checks passed
transfix added a commit that referenced this pull request Oct 25, 2026
#806 and this branch both changed Octree::traverse_qef's refinement condition and
lbie_mesher_test.cpp.

- traverse_qef keeps this branch's condition (tets refine the surface to one level in
  two passes), with only hexahedra held at oct_depth-2 as #806 does: `hexa =
  (flag_type == 3)`. Quadrilaterals refine like a surface again, as #806 decided, and
  its split_quads makes their level changes all quads. The header comment says so
  instead of "quadrilaterals and hexahedra stay on oct_depth-2".
- lbie_mesher_test.cpp keeps both sets: #806's hexahedra_with_repeated_corners helper
  and its new hex/quad tests, then this branch's tet tests.
  AdaptiveHexahedraHaveEightDistinctCorners uses the helper and runs in a box whose
  voxels are 1 across too. The comment of HexahedraHaveEightDistinctCornersWhereTheErrorIsLarge
  now says the QEF error "was" in the volume's units.

Local (Windows, MSVC Release, shared): lbie_mesher_test 57/57, geometry_test 111/111,
algorithm_test 10/10, fem_test 16/16, mesh_ops_test 39/39, cvc_cli_test 180/180.
transfix added a commit that referenced this pull request Oct 27, 2026
…s/FEM_GALLERY.md (#803)

* fix(LBIE): cvc::hexahedralize returns untwisted hexahedra; a cube's scaled Jacobian is 1

geoframe stores a hexahedron as its six faces, and LBIE winds the second
face against the first (Octree::add_hexa); saveHexa and the optimizer in
octree.cpp read the top corners from it as v5 v4 v7 v6. The geoframe_adapter
read and wrote both faces in plain order, so every hexahedron from
cvc::hexahedralize was twisted (corner k + 4 not over corner k), and
geometry::quality_improve handed LBIE's optimizer twisted hexahedra. The older
convert() path (decode_hexs_from_quads) had it right. The adapter now reads and
writes LBIE's layout: on the bunny at 65^3 the mean scaled Jacobian goes from
~0 to 0.85, with 97-99% of the hexahedra right-handed at every corner.

hex_scaled_jacobian divided the centre Jacobian by the space diagonal cubed, so
a unit cube scored 1/sqrt(27) = 0.024, though its docs say 1 and
filter_hexs_by_quality's default threshold of 0.2 rejected every cube. It is now
the worst corner's determinant of unit edges (the Verdict definition): 1 for a
box, 1/sqrt(5) for a cube sheared by twice its height, -1 for its mirror image.

* examples: fem_gallery renders FEM, surface and LBIE mesh results; docs/FEM_GALLERY.md

fem_gallery is a synchronous offscreen CLI: load a surface mesh or a volume,
tet-mesh the solid (SDF_IGL + LBIE, or a CT isovalue), solve Poisson, heat or
Neumann eigenmodes with cvc::fem (or curvature, geodesics and Laplace-Beltrami
modes on the surface), colour the boundary and a planar cut, and write a PNG.
For a surface mesh the solution is sampled onto the input surface, which hides
the tet mesh's grid-aligned boundary. --problem mesh shows LBIE's tetrahedra or
hexahedra themselves, cut away and coloured by element size (octree level) or
quality (minimum dihedral angle, scaled Jacobian); --iso2 and --improve reach
cvc::tetrahedralize2 and LBIE's improvement passes.

docs/FEM_GALLERY.md shows 20 renders (bunny, the TexMol head, the VolRover vh4
CT), and examples/cvcgl/fem_gallery_docs.sh regenerates them. The page lists
what LBIE does not do well yet, so it isn't shown: staircase tet boundaries,
geometric flow on tets, tetrahedralize2's slivers, collapsed adaptive hexahedra
on the head and CT.

* docs(FEM_GALLERY): the LBIE limitations that kept interval meshes and --improve out are fixed by #808

The tetrahedral staircase boundary, geometric flow wrecking tetrahedra, tetrahedralize2's
broken layers and the collapsed hexahedra on the head and the CT are all fixed in #808. The
pictures and element counts here predate it and change once both land.

* docs(FEM_GALLERY): #806 fixes the collapsed hexahedra on its own too
transfix added a commit that referenced this pull request Oct 27, 2026
* fix(LBIE): cvc::hexahedralize returns untwisted hexahedra; a cube's scaled Jacobian is 1

geoframe stores a hexahedron as its six faces, and LBIE winds the second
face against the first (Octree::add_hexa); saveHexa and the optimizer in
octree.cpp read the top corners from it as v5 v4 v7 v6. The geoframe_adapter
read and wrote both faces in plain order, so every hexahedron from
cvc::hexahedralize was twisted (corner k + 4 not over corner k), and
geometry::quality_improve handed LBIE's optimizer twisted hexahedra. The older
convert() path (decode_hexs_from_quads) had it right. The adapter now reads and
writes LBIE's layout: on the bunny at 65^3 the mean scaled Jacobian goes from
~0 to 0.85, with 97-99% of the hexahedra right-handed at every corner.

hex_scaled_jacobian divided the centre Jacobian by the space diagonal cubed, so
a unit cube scored 1/sqrt(27) = 0.024, though its docs say 1 and
filter_hexs_by_quality's default threshold of 0.2 rejected every cube. It is now
the worst corner's determinant of unit edges (the Verdict definition): 1 for a
box, 1/sqrt(5) for a cube sheared by twice its height, -1 for its mirror image.

* examples: fem_gallery renders FEM, surface and LBIE mesh results; docs/FEM_GALLERY.md

fem_gallery is a synchronous offscreen CLI: load a surface mesh or a volume,
tet-mesh the solid (SDF_IGL + LBIE, or a CT isovalue), solve Poisson, heat or
Neumann eigenmodes with cvc::fem (or curvature, geodesics and Laplace-Beltrami
modes on the surface), colour the boundary and a planar cut, and write a PNG.
For a surface mesh the solution is sampled onto the input surface, which hides
the tet mesh's grid-aligned boundary. --problem mesh shows LBIE's tetrahedra or
hexahedra themselves, cut away and coloured by element size (octree level) or
quality (minimum dihedral angle, scaled Jacobian); --iso2 and --improve reach
cvc::tetrahedralize2 and LBIE's improvement passes.

docs/FEM_GALLERY.md shows 20 renders (bunny, the TexMol head, the VolRover vh4
CT), and examples/cvcgl/fem_gallery_docs.sh regenerates them. The page lists
what LBIE does not do well yet, so it isn't shown: staircase tet boundaries,
geometric flow on tets, tetrahedralize2's slivers, collapsed adaptive hexahedra
on the head and CT.

* docs(FEM_GALLERY): the LBIE limitations that kept interval meshes and --improve out are fixed by #808

The tetrahedral staircase boundary, geometric flow wrecking tetrahedra, tetrahedralize2's
broken layers and the collapsed hexahedra on the head and the CT are all fixed in #808. The
pictures and element counts here predate it and change once both land.

* docs(FEM_GALLERY): #806 fixes the collapsed hexahedra on its own too

* ariadne: host menus, and an empty stage for each document a host loads

AppRuntime::set_host_menus puts a host's menus in every document it mounts,
ahead of the document's own (a gallery's Demos menu), and gives a document
without a menubar one. Their menu_action events go to the host's on() handlers.

load() now clears the last document's scene before anything else: a new
SceneAdapter::clear(), which cvcGL's adapter implements as room_view takes a
room down -- the realized nodes and free lights, then the RealizedScene with its
rigs and physics -- and by putting back the background, shadows and chrome the
host had set up. A reload rebuilt every node already, but a switch to another
document kept the first one's nodes, lights and gradient. A document without
channels: also drops the last one's channel policy.

register_scene_panels registers stage_lighting_panel with or without a rig, so
a document loaded after one with a rig doesn't draw the gone rig's panel.

* arigl: a Demos menu over a gallery of documents, switched in place

With CVC_ARIGL_GALLERY naming a catalog of demos (JSON), arigl run puts a Demos
menu first in every document's menubar, through AppRuntime's host menus. A demo
there that is a .ari document replaces the running one in the same window,
loaded between frames; any other opens on its own: its page in the browser, its
program natively (cvc::process::spawn_detached beside arigl), and arigl closes.
In the browser the document's name goes into the page URL (?doc=), so a reload
or a shared link opens it again.

cvc::process (core) finds the running program and starts another: what arigl's
menu and the examples' C++ demos need, native only.

In a wasm build with the examples, arigl itself is the browser gallery's Ariadne
app: the documents, the component library and examples/data go into its file
system and it joins wasm-demos.

* examples: every demo opens every other from a Demos menu; arigl runs the .ari ones

A Demos menu comes first in each demo's main menu bar, over the gallery's list
(web/demos.json, made into a C table and arigl's catalogs by
common/demos.cmake). In the browser it lists what the gallery deployed (each
page's gallery.js) and goes to that demo's page; natively it starts the demo's
program beside this one -- an .ari demo is arigl on its document, with the
catalog so it has the menu too -- and the demo closes.

The browser gallery's .ari demos are now arigl, its one Ariadne app, opened on
each document (arigl/?doc=<name>) and switched in place from arigl's Demos menu.
demos.json marks them with "app"/"doc"; build-pages.py lists them when arigl was
built, redirects their old pages there, boots arigl from its "boot" entry
(command line, environment, files fetched before main), and writes gallery.json
and gallery.js. Every canvas page also gets a demo picker in its header. The
per-document ariadne_hello wasm targets are gone, and fem_gallery_ari joins the
list.

The gallery's wasm build turns the LBIE mesher on, and deploy-pages installs the
eigen and libigl wasm bundles, so the FEM gallery's fe_lab and mesh_lab nodes
exist in the browser.

* examples-web: the browser gallery builds with sdl3, eigen and libigl

The recipe and deploy-pages install them for wasm: SDL3 carries the documents' keys and pointer (cvcGL's SdlInput), and eigen + libigl are what the FEM gallery's fe_lab and mesh_lab nodes run on.

* gallery: the menus leave arigl's own page out; the picker follows an in-place switch

build-pages.py keeps a "card": false page (arigl's) out of gallery.json and gallery.js, since arigl is in the menus as its documents. When arigl loads a document in place it also selects it in the page's demo picker, not only in the URL.

* ariadne: fit: takes the dataset's up axis (x | y | z) and flip; scene nodes know their document's directory

fit: { up: x } turns the cyclic x -> z, and flip: true then turns the dataset upside down (a
half turn about x, for a scan stored head down), before the existing centre / ground / scale.
fit_to_ground, sdf_volume_from_mesh and the geometry nodes take the new form; turn_up and
turn_up_point expose the rotation alone, and sdf_volume_of_mesh the SDF of a mesh in hand.

The loader stamps every scene node with its document's directory (SceneNode::base_dir, empty
for a string), so a custom node can resolve a relative path the way an import: does. The
built-in nodes' source: { file } still resolves against the working directory.

* cvcGL: fe_lab and mesh_lab load new sources at run time, solve eigenmodes, mesh intervals and hexahedra, and show the elements

Both nodes:
- source.* keys (seeded from source: and fit:) and a `load` request that reads them again on
  the node's lane, only when one changed; `reload` always does. A relative path resolves
  against the document's directory, then the working directory; stanford.bunny stays built in.
- A request may chain commands separated by spaces ("load smooth", "stop load"), each run after
  the job before it.
- stats.work_ms: the wall time of the last run of commands.

mesh_lab: color.mode modes (a Laplace-Beltrami eigenfunction, modes.index, eigenpairs cached
per mesh) and geodesic.source -1 (the highest vertex). A load that finds its source unchanged
goes back to the loaded mesh and keeps the caches.

fe_lab:
- source.type sdf | volume, source.file, source.dim (the SDF's grid, or a volume's resample),
  source.algorithm, source.up / flip / height. An SDF is taken in the mesh's own units and fit:
  places the elements, as for a volume: LBIE refines by an error in value units, so an SDF
  scaled to the fit height refined a small model everywhere (the bunny at 48^3 gave 244,125
  hexahedra; now 12,822, as fem_gallery does).
- auto.mesh / auto.solve keys: a load re-meshes only when the source or a mesh.* key changed,
  else re-solves.
- problem modes (fem::laplacian_eigenmodes on the volume, modes.index, cached per mesh).
- mesh.interval + mesh.isovalue2 (tetrahedralize2, the upper isovalue first in the negated
  space of an inside-below volume) and mesh.elements tet | hex. A solve refuses hexahedra.
- view.mode elements: the elements on one side of the cut (view.cut_side), whole and flat-
  coloured by size or quality, outlined by <id>_edges, with <id>_ghost at view.ghost opacity;
  view.fixed_range / range_min / range_max in both views. stats.hexes and quality min / mean.
- view.boundary input: the field drawn on the surface the elements approximate (an SDF's
  mesh, or the volume's isosurface) instead of their staircase boundary.

fe_controls offers all of it, Optimization (5) among the improvements; mesh_tools the source
and the eigenfunction mode. cvcgl_ariadne_realize covers source switching, chaining, both
eigenmode kinds, intervals, hexahedra and the elements view.

* examples: fem_gallery.ari, the FEM and mesh gallery as a live Ariadne document

The twenty items of docs/FEM_GALLERY.md, computed in the scene one at a time by one fe_lab and
one mesh_lab node. init: writes the item table into state (each item's title, description, node
keys and starting request); on_tick applies the selected one (state-json / state-from-json onto
the nodes, the item's camera onto every viewer), and mirrors the node's status and timing. Step
with the Gallery menu, the Previous / Next buttons, or Left / Right and PageUp / PageDown where
the host passes keys; the Windows menu opens the component panels. Arguments: --item N, --data
DIR (default ../../data/fem, relative to the document) and --tour S.

examples/data/fem holds the head (TexMol's LBIE_lib/head.off, one vertex per line) and the CT
(VolRover's SimpleExample/vh4.rawiv), with a README on where they come from.

ARIADNE.md §5.4 documents the new keys and §6.5 the document; FEM_GALLERY.md points at it.

* cvcGL: an fe_lab SDF source's field loads on the first tick, not while the scene is realized

Realizing an fe_lab with source: { sdf } used to compute the SDF on the render thread before
the document showed: about 3 s for the bunny at 48^3 with the igl algorithm, a frozen start in a
single-threaded browser build. Now the realizer reads only the mesh (the bounds the camera frames
are its padded box, placed by fit:), and the first tick computes the field as a `load` on the
node's lane, reading the source.* keys -- so a document whose init: or first on_tick picks
another source (fem_gallery.ari --item 10) never computes the node's own. Requests wait for it,
status says loading; a build without CVC_ENABLE_SDF still refuses the node at realize.

* examples/web: the fem_gallery_ari card's thumbnail

Four of its items (the bunny's first vibration mode, heat in the CT body, LBIE's hexahedra by size, the head's mean curvature), from docs/img/fem-gallery.

* arigl's gallery build preloads its documents, components and data

Emscripten won't mix --preload-file with --embed-file, and the datasets are too big to embed
in the module. Also clang-format the lines this branch changed, leaving demos_menu's JavaScript
body alone.

* ariadne: sliders follow the drag, and arigl's menu bar stays the same across documents

- A slider writes its key on every change while it is dragged, so what it drives follows it.
  `commit: release` keeps the old single write at the end of the drag, for a key too costly to
  redo every frame. Both backends already reported each move; the core now writes it.
- AppRuntime::document_menus() marks where a host's menu bar puts the document's own menus.
  Given a label, one menu of that name holds them as submenus, so the bar keeps its shape from
  one document to the next (the menu is greyed out for a document without menus). Without one,
  they stand in the bar as written, and a host menu with the same name adds its items to theirs.
- arigl: with a gallery the bar is Demos | Document | Settings for every document; without one,
  Settings follows the document's own menus. Settings is the scene's display settings (shadows,
  grid, origin axis, bounding boxes, extent labels), from a new scene_settings custom widget.
- arigl's viewer is "main", so the shared camera_controls component (viewers.main.camera.*)
  reaches its camera.

* cvcGL: Ariadne windows fit their widgets, stack, and scroll both ways

- A window with no size: fits its widgets every frame, up to the viewport's edge, past which it
  scrolls. It used to stay at ImGui's 32 px minimum: the core persisted its geometry after its
  first, unmeasured frame and seeded that size back, which stopped ImGui's auto-fit.
- Windows with no pos: and nothing persisted stack down the left of the viewport, in columns,
  instead of all opening at ImGui's one default spot; one the user drags leaves the stack.
- A window with a size: keeps it and gets a horizontal scrollbar as well as the vertical one.
  windows.png is regenerated under Mesa llvmpipe for its fixed-size window's new scrollbar (the
  other goldens still match under it).
- cvcgl_imgui_window_fit covers all three on a bare ImGui context.

* cvcGL: a custom node's extra top-level nodes leave with its scene

forest_trees adds its needles as a second top-level node, which RealizedScene::created did not
list, so a host loading another document (arigl's Demos menu) left the trees' needles behind.
realize_scene now records every top-level node the scene's realizers added.

* arigl: keys through SDL3, and rebindable keys in a Keys window for every document

- cvc::gl::SdlInput::attach wraps the window VTK made, so SDL delivers its keys and pointer:
  natively the HWND (or X11 window), whose messages SDL passes on to VTK's procedure; in the
  browser a hidden canvas of SDL's own, with its key listeners on VTK's canvas and an event
  filter that keeps the keys (SDL would otherwise preventDefault them and swallow the keypress
  VTK turns into typed text). arigl attaches it once VTK's window exists, so a document's
  on_key and keys: work there. cvcgl_sdl_attach checks a Left arrow reaches both SDL and VTK.
- A document's `keys:` block names rebindable actions (label, default key(s), on:). Each
  binding's keys live at keys.<id>; Runtime::post_input runs the `on:` of a binding a key down
  matches, in the next drain. canonical_key matches SDL's and VTK's spellings of a key.
- AppRuntime puts a Keys window (closed until tree.ariadne_keys.open) in every document: a row
  per binding, the document's and the host's (set_host_keys), with a Change button that takes
  the next key down (Escape keeps the old one). A group with an id now scopes its children's
  identities, so each row's button is its own.
- arigl's Settings menu opens it, in a window and in the terminal, and the camera's fly keys
  are host bindings; the camera now matches its keys canonically and defaults to SDL's names.
- fem_gallery's arrow keys are a keys: block. FTXUI draws a bound text with no label as just its
  value, as ImGui does.

* ariadne: iTerm2 inline images in the terminal backend

`--graphics iterm` (FtxuiBackend::Options::ImageColor::Iterm) draws pixel images as iTerm2 inline
images: like Sixel, a bitmap per rectangle of uncovered cells over the half-block underlay,
re-sent after each repaint, but a JPEG in an OSC 1337 escape that names its cells, so the
terminal scales it and the cell size need not be known. WezTerm, iTerm2, mintty and xterm.js's
image addon show them. `Auto` picks it, after kitty and Sixel, when $TERM_PROGRAM names such a
terminal; TerminalScene renders the scene at the cells' pixels for it, and arigl/ari info report
it. The JPEG comes from stb_image_write, compiled into term_graphics as its own static copy.

On Windows a console program reaches its terminal through ConPTY. Windows Terminal's (1.22 and
later) passes Sixel on, and arigl draws real pixels there with --graphics sixel --cell-size WxH.
The ConPTY WezTerm 20240203 bundles, and Windows' own, drop kitty's APC and Sixel's DCS and forward
an iTerm2 image ahead of the cursor moves they redraw on their own, so a full-screen program's
images land misplaced and get painted over: kitty graphics need a terminal on Linux or macOS.
ARIADNE.md says so.

* tests: a click still reaches VTK with SDL attached, and Change rebinds through its program

cvcgl_sdl_attach also sends a click: SDL reports it and VTK's interactor (ImGui's input) still
gets it. The Keys window test clicks Change, so keys.capture is set by the button's own program,
and the next key down becomes the binding's key.

* ariadne, arigl: review fixes for keys, window layout and SDL input

Keys
- The Keys window's capture lives at tree.ariadne_keys.capture (beside its open state), so a
  document binding named `capture` is its own. A capture counts only while the window is open;
  closing it drops one still waiting.
- The comma key is stored as "Comma" (a comma separates stored keys), a document's "," default
  too, and a key with no name keeps the capture waiting.
- canonical_key matches SDL's and VTK's punctuation, shifted punctuation and keypad names (","
  and "comma", "+" and "plus", "'" and "quoteright", "Keypad 1" and "KP_1", "_", Numlock,
  Print).
- Documents a host loads in turn share its prefix: a new document's keys: defaults replace an
  earlier one's for the same id ("" for a binding with no key), where a reload of the same file
  keeps the user's keys. The defaults go in before init:, which can set its own.
- In the terminal, while the Keys window waits, every key goes to the capture
  (FtxuiBackend::route, now what run_loop does with each event, and the tvision desktop's host),
  Tab and Return included.

Window layout
- A new document starts its layout afresh: Runtime::forget_layout (AppRuntime::load on a
  switch) makes each window's and grid's first frame ignore the geometry, pane sizes and column
  widths the last document persisted, and Backend::reset_layout lets the ImGui and FTXUI
  backends forget their own.
- ImGuiBackend: an authored pos is in the work area, below a main menu bar, from the first frame
  (the bar drawn earlier this frame counts); flowing windows go below a window that stands where
  it is (told apart by ImGui id, not by name; nothing is in the way on a new document's first
  frame, and ImGui's own windows never are), and a column never starts past the right edge; a
  split-pane window with no size gets panes that fit their widgets, so the window does (it
  collapsed to ~30 px).
- The menus golden's window moves up under the open File menu, which its text says draws over
  it (it never did); menus.png regenerated under llvmpipe.
- forest_controls' structural sliders are commit: release: each would regrow the whole forest
  every frame of a drag.

SDL input
- SdlInput wraps VTK's window only on Windows (and listens on the page in the browser). On X11
  SDL's XInput2 selection takes VTK's clicks, and on Wayland it makes a window of its own, so
  there (and on macOS, without SDL, or with $CVC_SDLINPUT_VTK_KEYS=1) attach() observes VTK's
  key events instead: presses below ImGuiOverlay, releases above it, named as SDL names them,
  and a held key's presses (X11's release+press pairs too) marked as repeats.
- SDL video init no longer blocks display sleep or changes the process's DPI awareness (unless
  the app set those hints).
- arigl hands the document no key typed into an ImGui field and no click on an ImGui window.

Also: the iTerm2 probe is POSIX and needs a tty, VS Code's terminal is not assumed to show
images, a cached iTerm/Sixel bitmap is remade when its raster or cells change, and
ariadne_host_test.cpp is LF again.

* ariadne: the Keys window evaluates nothing per frame; the terminal menu bar keeps its colours

Found running the wasm gallery:

- With the Keys window open in fem_gallery, its rows' show/hide expressions (two per binding,
  twenty there) exhausted the per-frame reactive budget, and the document's own expressions were
  skipped. Each row is a bound text now, tree.ariadne_keys.shown.<id>: the binding's keys, or
  "press a key..." while its Change waits. The runtime keeps it each drain, writing only what
  changed.
- In the terminal, the menu bar over a picture behind the widgets took the picture's colours:
  its inverted titles came out the same colour as their background, so the bar was nearly
  invisible over a half-block scene. The bar clears the cells under it first.

* arigl_term: arigl --terminal in the browser, the 3D scene behind the widgets

arigl's terminal mode as a wasm page, beside ari's:

- src/arigl/CMakeLists.txt: an arigl_term target (built by name, where FTXUI is found), the
  documents, the terminal tour and the components preloaded as for arigl (no datasets),
  -sEXIT_RUNTIME and FTXUI's resize hook exported as for ari, and cvcGL's WebGL state shim off
  (it would patch xterm.js's renderer's context too).
- src/arigl/web/arigl_term.html, from ari.html: an xterm.js terminal with the image addon
  (iTerm2 inline images; Sixel off), VTK's hidden #canvas, the document and drawing from the URL
  (?doc=documents/terminal_scene, ?gfx=iterm|color|mono, switchable from the header), and one
  terminal write per animation frame, so a frame's text and the images after it go together.
- main(): opened without a command line it runs terminal_scene, and it is always in the
  terminal.
- The gallery: two cards, terminal_scene_term and terminal_tour_term, open arigl_term on their
  documents (with thumbnails). build-pages.py gives gallery.json a document to load in place only
  for arigl, so arigl's Demos menu opens these as pages; demos.cmake leaves them out of the native
  catalogs. build-wasm-demo.sh builds arigl_term beside ari, and deploy-pages checks it is live.

In the browser pane: terminal_scene renders through VTK/WebGL, is read back and drawn as
half-blocks and as iTerm2 images at real pixels; dragging orbits; F10, the menus, the Keys
window and clicks work; terminal_tour runs. FTXUI repaints every cell each frame and the addon
decodes images asynchronously, so the picture can flicker to its half-block underlay (ARIADNE.md).

* style: keep master's include-comment spacing in ariadne_runtime_test.cpp (clang-format, changed lines)
@transfix
transfix deleted the fix/lbie-adaptive-hex-collapse branch October 29, 2026 20:53
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