Repository navigation
fix(LBIE): fitted tet boundaries in any units, a geometric flow that can't wreck tets, and real interval meshes - #808
Merged
Merged
Conversation
…verlapping tets `fem_gallery --mesh stanford.bunny --problem mesh --dim 64` gave 7,440 tets of one size whose boundary was an axis-aligned staircase, while the hexahedral mesh of the same SDF was adaptive and fitted. Units. Octree::interpRect3Dpts_x/y/z placed each edge crossing at span * grid index, span being the volume's voxel size, but the QEF solution built from the crossings is checked against its cell in grid units (Octree::get_solution), and do_duallib_extract maps every vertex from grid units to the box. Wherever a voxel is not 1 across, every QEF solution therefore "left its cell" and was replaced by the cell's centre, and the QEF error that drives traverse_qef's refinement shrank by span^2, so nothing refined. A tet mesh's boundary vertices are those QEF points: the bunny's SDF (voxels 0.003 across) came out as uniform cubes. A volume with 1-unit voxels (vh4.rawiv) always got a fitted, adaptive boundary. Hexahedra hid it: Octree::get_vtx_new walks each boundary vertex onto the surface afterwards. The crossings are now in grid units, and the normals that weight the QEF are the grid's gradient direction. Overlaps. With real QEF points the adaptive tet mesh overlaps itself where boundary cells of two sizes meet: tetrahedralize() covers each piece of the coarse cell's face twice, once from each cell's QEF point, and the tets overlap unless the segment between the points passes through that piece (it always does for cell centres, which is why the interior can be adaptive). A sphere's mesh covered 5% of its inside twice and had 13% too much volume. traverse_qef now refines a tet mesh in two passes: the first finds the finest level the error tolerance wants anywhere on the surface, the second refines the whole surface to it. It also drops the r < 60 condition for tets, which kept refinement inside a sphere of 60 voxels around the centre of the volume the code was written for. Boundary solutions. A QEF solution is a weighted mean of crossings, so it lies in the closed cell, but on the cell's boundary where every crossing is on one face. Such a solution went to the cell's centre, half a cell off the surface; now only NaN does, and the rest is clamped inside the cell: by a fifth of a cell for tets (a corner on a face makes slivers: a sphere's minimum dihedral angle goes 0.5 -> 11 degrees, boundary within 0.3 voxels), by a hundredth otherwise. Isovalue ties. A sample exactly at the isovalue is on neither side, and the extraction disagreed with itself about it: is_skipcell() said a coarse cell touching the surface only there was not crossed, so it was never refined, while is_intersect() let its edges cross, so it got a vertex at its centre, 3.4 voxels off a sphere through grid points. Integer CT data at an integer isovalue is full of such samples. collapse() now moves the isovalue off the samples, towards the inside. Quadrilaterals and hexahedra keep an octree that stops at oct_depth-2 and start each vertex at its cell's centre before get_vtx_new walks it onto the surface. That is what every volume whose voxels are not 1 across gave them before, so the bunny's hex mesh is unchanged; a refined octree made the hex templates collapse elements, and starting from the QEF point gave worse hexes (a sphere's worst corner condition 35 instead of 15). On vh4.rawiv, whose voxels are 1 across: iso 45 went from 952,750 hexes, about half with repeated corners, to 183,708 with none; iso 80 has 12,798, none repeated. Tets (minimum dihedral angle in degrees): - bunny SDF, --dim 64: 7,440 staircase (26.6) -> 160,090 fitted (0.04) - bunny SDF, --dim 128: 59,460 staircase -> 739,289 fitted (Poisson 8.5 s) - vh4.rawiv iso 45: 347,680 adaptive (0.001) -> 1,286,317 (0.004) - sphere r=0.6 at 33^3, box 1 or 0.01: 684 tets, boundary 2.97 voxels off -> 23,292 tets, boundary within 0.27 voxels, volume 1% over the sphere's The fitted boundary has slivers; geometric flow (next commit) is the remedy. Tests: TetraBoundaryFitsTheSurfaceInAnyUnits (same samples in three boxes give one mesh, on the surface, with the sphere's volume) and TetraMeshesAnIsovalueTheSamplesHit (a sphere through grid points, and unsigned-char data at an integer isovalue) fail before this; AdaptiveHexahedraHaveEightDistinctCorners now also runs in a box whose voxels are 1 across.
`fem_gallery --mesh stanford.bunny --problem mesh --dim 64 --improve geoflow` took the minimum dihedral angle from 26.6 to 0.75 degrees and threw a boundary vertex far outside the bunny. Octree::geometric_flow_tet had three faults; units were not one of them (#787 already runs the pass on the octree's grid): - It read each tet's corners in an order that made volume_tet() negative for every tet AddTetra stores, so every tet failed the "volume < 1e-5" skip and no interior vertex ever moved. Only boundary vertices did. - A boundary vertex moves in the tangent plane, x += dt * (p - (p.n) n), with n taken as a unit normal. n is the gradient of the volume's values, so where it is steeper than 1 the move overshoots along n and the overshoot grows every round: a CT's gradient is tens of units per voxel, and a sphere's in a box 0.01 across sent every vertex to infinity. n is now normalized. - Nothing checked the tets around a vertex, so a move could fold them. A move is now taken only if every tet around the vertex keeps a positive volume and none has a smaller dihedral angle than the worst of them had, so a pass never makes the mesh's worst tet worse. Each tet's worst dihedral cosine is cached and updated as its corners move. The vertex-to-tet table is no longer capped at 50 tets (a coarse cell's centre beside fine cells can be in about a hundred), and a boundary vertex with no boundary face is skipped without the stray "s<n>" printf. Minimum (mean) dihedral angle in degrees, NO_IMPROVE -> GEO_FLOW 1 iteration: - sphere r=0.6 at 17^3: 19.7 (49.8) -> 32.3 (50.6), in a box 8 across with values x1 and in a box 0.01 across with values x100 alike (before: NaN everywhere for the latter) - sphere r=0.6 at 33^3: 10.8 (46.6) -> 21.4 (48.3), 0 inverted, boundary within 0.27 voxels; 1 s for 23,292 tets - bunny SDF, --dim 64: 0.04 (46.3) -> 0.20 (47.7), 160,090 tets, nothing thrown out Test: TetraGeometricFlowNeverMakesTheWorstTetWorse. Before this the same checks on a 33^3 sphere found 357 inverted tets in the unit box and non-finite vertices in the box 0.01 across.
… either order `fem_gallery --mesh stanford.bunny --problem mesh --iso2 -0.012` gave a shell full of sliver fans and holes, and vh4.rawiv's `--iso 45 --iso2 80` layer was sparse noise with a minimum dihedral angle of 0.0005 degrees. Routing. cvc::tetrahedralize2 asks for LBIE's TETRA2 mesh with dual contouring, but do_mesh_geometry turned VOLUME_TET back into TETRA, so the layer went through the one-surface Octree::tetrahedralize on the interval's octree, which knows only the first isovalue. A dual-contoured VOLUME_TET is now TETRA2. Octree::tetrahedralize_interval, which TETRA2 then reaches, is no better: it chooses which isosurface an edge crosses by its cell rather than by the edge, gives an edge that crosses both isosurfaces a pyramid whose apex lies outside the layer, and makes a new grid vertex for every pyramid, so neighbouring tets do not share corners. Mesher::do_duallib_extract instead meshes a TETRA2 layer lo <= v <= hi as the solid min(v - lo, hi - v) >= 0, whose boundary is both isosurfaces, with the one-surface tetrahedralizer the previous commits fixed. The isovalues may come in either order (LBIE wanted the upper one first, and gave nothing otherwise), and a layer thinner than a voxel can break up. The one-isovalue tetrahedralize2(vol, iso) asked for the layer up to LBIE's default inner isovalue, 9.5001, from the data LBIE was first written for, which an SDF never reaches: it returned an empty mesh. It now meshes the solid above iso, the region tetrahedralize() meshes, and GeometryTest.Tetrahedralize2MeshExtraction checks that the two agree. Layer of a sphere, radius 0.6 +- 0.15 at 33^3 (exact volume 1.385): - before: 8,124 tets, volume 0.19, boundary 3.7 voxels off, corners off the layer; 0 tets with the lower isovalue first - after: 48,984 tets either way, volume 1.383, boundary within 0.33 voxels, every corner in the layer, minimum dihedral angle 7.7 degrees, 0 inverted - bunny, --iso2 -0.012 at --dim 64: 45,443 tets with fans and holes -> 232,166 in an even shell, minimum dihedral angle 6.6 -> 0.30 (0.34 after GEO_FLOW) - vh4.rawiv, --iso 45 --iso2 80: a solid layer of 1,948,887 tets with the lungs and the bone as cavities Test: Tetrahedralize2MeshesTheLayerBetweenTwoIsosurfaces (both orders, two boxes) fails before this. docs/GEOMETRY_API.md and the libigl roadmap's P2.2 row are updated.
Octree::compute_qef and compute_qef_interval compute each cell's QEF residual, which
get_err() hands to traverse_qef as the refinement error, as a sum over the three axes:
qef=0;
for (i=0;i<3;i++)
qef = sigma_ni_2_pi_2[i] - (sigma_ni_2_pi[i]*sigma_ni_2_pi[i]) / sigma_ni_2[i];
All six live copies assign instead of adding, so only the z term counted. Where no
crossing's normal has a z component the term is 0/0, so the error is NaN and the cell
never refines: the side of a cylinder along z stayed coarse while the same cylinder
along x or y refined. They now add, through qef_axis_residual(), which gives 0 for an
axis no normal has a component on (it constrains nothing) instead of NaN.
A capped cylinder r=0.4 at 33^3, triangles / tets:
- along x or y: 1,436 / 13,940 before and after
- along z: 156 / 540 before, 1,436 / 13,940 after
Tet meshes of the gallery's inputs do not change: their surfaces already reach the
finest level (bunny SDF at 64^3: 160,090 tets; vh4.rawiv iso 45: 1,286,317). DUALLIB
surfaces refine where the x and y terms say so: `cvc iso` on the bunny's 64^3 v2 SDF
goes from 19,088 to 28,183 triangles, with the vertices as close to the bunny as before
(median 0.23 voxels, 95th percentile 0.55). Hexahedra and quadrilaterals do not use
this error.
Test: RefinementIsTheSameAlongEveryAxis, which fails before this.
…_FLOW caches tet volumes package-linux / libcvc-debug failed on this PR: GeometryTest.QualityImproveTetrahedralMesh timed out (300 s), and GeometryTest.TetrahedralizeWithImprovementMethods took 178 s (21 s on other branches). Both run several GEO_FLOW passes over a bunny tet mesh, and that mesh grew with the fitted boundary: 7,440 -> ~290k tets from a 64^3 SDF, and ~63k from 32^3. They only check that each method keeps the topology and leaves finite points. - QualityImproveTetrahedralMesh meshes a 32^3 SDF instead of 64^3: 5.4 s in Release here, down from 31 s. - TetrahedralizeWithImprovementMethods meshes 16^3 instead of 32^3, which LBIE grids as 17^3 instead of 33^3 (any dim from 17 to 32 becomes 33): 11,825 tets, 1.7 s down from 11.7 s. - geometric_flow_tet keeps each tet's volume next to its cached dihedral cosine, from the same determinant the move check already computes, instead of recomputing every incident tet's volume with volume_tet() (Heron's formula, four square roots) in every round: a pass over 63k tets takes 1.3 s instead of 1.8 s. cvcgl_media_audio, which failed in the same job, passes on other branches built on the same master; its deep-graph program has to finish inside one 0.1 s drain, and here it ran while the timed-out test held a core for three 300 s attempts.
transfix
added a commit
that referenced
this pull request
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.
This was referenced Oct 25, 2026
Merged
transfix
added a commit
that referenced
this pull request
Oct 25, 2026
…a; QUAD meshes all quads (#806) * fix(LBIE): the hexahedral octree stays on one level, so adaptive hexes 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. * fix(LBIE): no inverted hexahedra from snapping or optimization; QUAD 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. * fix(LBIE): no inverted hexahedra left after snapping, with the boundary 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.
#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.
This was referenced Oct 26, 2026
transfix
added a commit
that referenced
this pull request
Oct 27, 2026
…sphere (#830) Master fails LbieMesherTest.AdapterKeepsLbiesHexahedronCorners on every platform: mean scaled Jacobian 0.49893 < 0.5. #802 added the test and #808 merged 13 minutes later from a branch that never had it, so neither PR's CI ran the two together. The mesh is fine; the threshold was set on the wrong mesh. The test's sphere (17^3 samples over [-1,1]^3, voxels 0.125 across) meshes as 27 hexahedra, a 3x3x3 block with 64 vertices, before and after #808. Measured: - #802's LBIE: the block was a cube inside the sphere. Its 56 outer vertices were 0.31-0.50 from the centre (radius 0.5), every hexahedron ~1.0, mean 0.9996. - #808's LBIE: the 56 outer vertices are on the sphere (0.491-0.513). The edge and corner hexahedra become wedges: mean 0.499, worst 0.218, none inverted. - The pre-#802 twisted adapter on today's mesh: every hexahedron inside out, mean -0.78. So the check that matters is that no hexahedron is inverted. The test now requires every hexahedron to be right-handed (it allowed a tenth to be inverted) and a mean above 0.4 instead of 0.5. The twisted layout still fails both by far.
transfix
added a commit
that referenced
this pull request
Oct 27, 2026
…terrupts (#825) * fix(volume): run HDF5 work on the caller's app and stop swallowing interrupts volume_io_test segfaulted intermittently when the whole binary ran as one process, in a test after CvcRawRoundTrip. It took two lifetime bugs: - hdf5_io kept the app that registered it and worked through that app instead of the one each call passes. Every cvc::app registers another hdf5_io into the process-wide handler map, and the first one registered serves every later call. So once the process's first app was destroyed, every HDF5 call ran through freed memory, and writeVolumeFile started its build_hierarchy thread on that dead app, where the writing app's ~app never saw it. hdf5_io now keeps no app; the maxdim default its constructor set moves to register_hdf5_io. - thread_info, thread_feedback and hdf5_utils::library_lock call app methods that are interruption points inside catch-alls. An interrupt that arrived there was thrown and swallowed, and boost clears the request when it throws, so the thread kept running. ~app gave up joining the hierarchy thread after 5 s and freed the app under it. They now hold interruption off (disable_interruption) while they keep their books, so the request stays pending for the thread's next interruption point. New tests, each failing without its fix: - Hdf5VolumeTest.HierarchyThreadRunsOnTheCallersApp - Hdf5VolumeTest.LibraryLockKeepsAnInterruptPending - AppTest.ThreadBookkeepingKeepsAnInterruptPending hdf5_volume_test's comment on its shared app described the first bug as the reason for sharing; it now says the sharing is no longer needed. * test(LBIE): AdapterKeepsLbiesHexahedronCorners expects #808's fitted sphere Master fails LbieMesherTest.AdapterKeepsLbiesHexahedronCorners on every platform: mean scaled Jacobian 0.49893 < 0.5. #802 added the test and #808 merged 13 minutes later from a branch that never had it, so neither PR's CI ran the two together. The mesh is fine; the threshold was set on the wrong mesh. The test's sphere (17^3 samples over [-1,1]^3, voxels 0.125 across) meshes as 27 hexahedra, a 3x3x3 block with 64 vertices, before and after #808. Measured: - #802's LBIE: the block was a cube inside the sphere. Its 56 outer vertices were 0.31-0.50 from the centre (radius 0.5), every hexahedron ~1.0, mean 0.9996. - #808's LBIE: the 56 outer vertices are on the sphere (0.491-0.513). The edge and corner hexahedra become wedges: mean 0.499, worst 0.218, none inverted. - The pre-#802 twisted adapter on today's mesh: every hexahedron inside out, mean -0.78. So the check that matters is that no hexahedron is inverted. The test now requires every hexahedron to be right-handed (it allowed a tenth to be inverted) and a mean above 0.4 instead of 0.5. The twisted layout still fails both by far.
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
added a commit
that referenced
this pull request
Oct 27, 2026
) #808 fixed tetrahedralize2's interval path: it reaches LBIE's TETRA2 mode and meshes the layer as the solid min(v - lo, hi - v) >= 0, with the isovalues in either order. fe_lab's tetrahedralize_interval built that same solid itself as a Float volume and meshed it with the single-isovalue tetrahedralize, waiting for this fix. It now calls tetrahedralize2 with the original volume and only chooses the two bounds: - A bound samples sit on is passed on half way to the nearest value beyond it, so the interval stays inclusive ([1, 3] on labels is [0.5, 3.5]). tetrahedralize2 on its own counts a sample on an isovalue as outside and keeps label 2 alone; a new check pins that down. - A bound no sample lies beyond is moved far enough past the data that the other bound's side of the min wins at every sample, so it adds no sheet; with neither passed, the whole box. - The rule that raised samples on a bound to keep the surface a quarter of a grid edge away is gone: since #808's QEF clamping the ball shell has no slivers and every boundary normal points out of the shell without it, and the shell no longer bulges at those samples. cvcgl_fe_interval, the acceptance test: on the SDF ball's shell 6 <= r <= 10 (grid points on both bounds), Poisson's peak is 2.048 vs 2.014 exact (it was ~22% low before #808) and the shell's volume is 1.8% over (2.1% before). The bound tightens from 30% to 10%, and the sliver count (0) becomes a check. fem_gallery's --iso2 passes the two isovalues as given (tetrahedralize2 takes either order). Docs: mesh_nodes.h, TRANSFER_FUNCTIONS.md section 6, and GEOMETRY_API.md (samples on an isovalue count as outside of a tetrahedralize2 layer).
transfix
added a commit
that referenced
this pull request
Oct 28, 2026
…oundary (#853) find_tets_containing_point and find_hexs_containing_point, above 10,000 elements, built the mesh's box by adding one bounding_box per vertex. A box around one point has no volume, so it isNull(), and a sum of null boxes stays null: the box test then rejected every point. Only a point the per-call AABB tree saw lying on the boundary surface skipped that test, so a query anywhere else returned nothing. #808 grew the bunny tet mesh in FindTetsContainingPointPerformanceLargeMesh from 7,440 tets to 289,946, which moved it onto this path. The test asserts only that something was found. Windows found 4 tets and Linux passed too, but macOS found 0. Testing every tet finds 25 of the 100 points, in 94 tets. The box is now compared coordinate by coordinate, for any mesh over 1000 elements, and the per-call surface extraction and CGAL AABB tree, which only fed that test, are gone. Both performance tests now check the result against testing every element.
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.
The FEM gallery (#803) shows three LBIE tetrahedral-meshing defects. This PR fixes all three, one commit each, and adds regression tests for each to
lbie_mesher_test.cpp. A fourth commit fixes the QEF error that drives refinement, which counted only its z term. The fix for the first also covers the gallery's fourth limitation, the collapsed hexahedra on the head and the CT, which #806 fixes independently (see Overlap with #806 below). Merges cleanly with #802 and #803; master, including #806, is merged in.1. Staircase tet boundary: a units bug
fem_gallery --mesh stanford.bunny --up y --problem mesh --dim 64 --slice ygave 7,440 tets of one size with an axis-aligned staircase boundary.--elements hexon the same input gave a fitted, adaptive boundary.Why.
Octree::interpRect3Dpts_x/y/zplaced each edge crossing atspan * grid index, wherespanis the volume's voxel size. But the QEF solution built from those crossings is checked against its cell in grid units (get_solution), anddo_duallib_extractmaps every vertex from grid units to the box. So wherever a voxel is not 1 across, every QEF solution "left its cell" and was replaced by the cell's centre. The QEF error that drivestraverse_qef's refinement also shrank by span², so nothing refined past the base level. The bunny SDF's voxels are 0.003 across. A volume with 1-unit voxels (vh4.rawiv) always got a fitted boundary. Hexahedra hid the bug becauseget_vtx_newwalks each boundary vertex onto the surface afterwards. It was not the error tolerance or the in/out sign convention.Fixing the units exposed three more problems, which this commit also fixes:
tetrahedralize()covers each piece of the coarse cell's face twice, once from each cell's QEF point. The two sets of tets overlap unless the segment between the points passes through that piece. Cell centres always pass through it, which is why the interior can be adaptive. A sphere's adaptive mesh covered 5% of its inside twice and had 13% too much volume; vh4's adaptive meshes always had this.traverse_qefnow refines tets in two passes. The first finds the finest level the error tolerance wants anywhere on the surface; the second refines the whole surface to that level. The interior stays coarse. I measured the alternatives: one-level steps on the surface still overlap, and any uniform surface level is clean. The tet path also dropsr < 60, which only refined inside a 60-voxel sphere around the centre of the volume the code was first written for.is_skipcell()says a coarse cell that touches the surface only at such a sample is not crossed, so it is never refined.is_intersect()still lets its edges cross, so the cell gets a vertex at its centre: 3.4 voxels off a sphere that passes through grid points. Integer CT data at an integer isovalue is full of these samples.collapse()now moves the isovalue off the samples, towards the inside.Hexahedra keep an octree that stops at
oct_depth-2(as #806 also does), and quadrilaterals and hexahedra start each vertex at its cell's centre beforeget_vtx_newwalks it onto the surface. Every volume whose voxels are not 1 across already got exactly this, so the bunny's hex mesh is unchanged (12,769 hexes / 15,474 vertices at--dim 64, as before). On a deeper octree the hex templates collapse elements, which was the gallery's "half of the head's and the CT's hexahedra have repeated corners". Onvh4.rawiv: iso 45 goes from 952,750 hexes, about half with repeated corners, to 183,708 with none. Iso 80 gives 12,798, none repeated.2. GEO_FLOW on tets: three bugs, not units
--improve geoflowtook the bunny's minimum dihedral angle from 26.6° to 0.75° and threw a boundary vertex far outside. #787 already runs this pass on the octree's grid;Octree::geometric_flow_tethad other faults:volume_tet()negative for every tetAddTetrastores, so every tet failed thevolume < 1e-5skip.dt * (p - (p·n) n), andnis the gradient of the volume's values. Where that gradient is steeper than 1, the vertex overshoots alongn, and the overshoot grows every round. A CT is tens of units per voxel. A sphere in a box 0.01 across sent every vertex to infinity.A move is now taken only if every tet around the vertex keeps a positive volume and none gets a smaller dihedral angle than the worst of them had. So a pass never makes the mesh's worst tet worse. The neighbour table is no longer capped at 50 tets.
3.
tetrahedralize2: never reached the interval mesher, and that mesher is brokencvc::tetrahedralize2asks for LBIE's TETRA2 mesh, butdo_mesh_geometrymappedVOLUME_TETback to TETRA. The layer therefore went through the one-surfaceOctree::tetrahedralizeon the interval's octree, which knows only the first isovalue. TETRA2 now gets through.Octree::tetrahedralize_interval, which TETRA2 then reaches, is broken too:Mesher::do_duallib_extractinstead meshes the layer lo ≤ v ≤ hi as the solidmin(v - lo, hi - v) >= 0. That solid's boundary is both isosurfaces, and it goes through the one-surface tetrahedralizer fixed above. The isovalues may come in either order; LBIE used to return nothing unless the upper one came first. A layer thinner than a voxel can break up.The one-isovalue
tetrahedralize2(vol, iso)used to ask for the layer up to LBIE's default inner isovalue, 9.5001, which an SDF never reaches, so it returned an empty mesh. It now meshes the solid aboveiso, the same regiontetrahedralize()meshes.4. The refinement error counted only z
compute_qefandcompute_qef_intervalsum each cell's QEF residual over the three axes, but all six live copies assigned (qef = ...) instead of adding inside the axis loop, so only the z term counted. Where no crossing's normal has a z component the term is 0/0, so the error was NaN and the cell never refined. A capped cylinder along z at 33³ gave 156 triangles / 540 tets, while the same cylinder along x or y gave 1,436 / 13,940. All three axes now give 1,436 / 13,940. An axis with no normal component now adds 0 instead of NaN.The gallery's tet meshes don't change, because their surfaces already reach the finest level. DUALLIB surfaces do:
cvc isoon the bunny's 64³ v2 SDF goes from 19,088 to 28,183 triangles, at the same distance from the bunny. Hexes don't use this error; quads refine with it like surfaces since #806.Overlap with #806 (merged)
#806 landed first and fixed the collapsed hexahedra with
flag_type != 3 &&on the sametraverse_qefcondition. Master is merged into this branch (88df8f3): the condition is this PR's, withhexa = (flag_type == 3), so only hexahedra stay onoct_depth-2. Quadrilaterals refine like a surface, as #806 decided, and itssplit_quadskeeps them all quads.lbie_mesher_test.cpphas both sets of tests (57);AdaptiveHexahedraHaveEightDistinctCornersuses #806's helper and also runs in a box with 1-unit voxels.Numbers
Tets (minimum / mean dihedral angle, degrees):
--dim 64--improve geoflow--dim 128--iso2 -0.012Spheres from
make_sphere_volume, r = 0.6:What callers will notice
--dim/ volume resolution gives fewer tets.GEO_FLOWis the remedy and now improves the worst tet rather than wrecking it.cvc isoon the bunny's 64³ v2 SDF went from 1,924 triangles to 28,183 adaptive ones. Distance to the bunny's vertices dropped from median 0.73 / 95th-percentile 2.1 voxels to 0.23 / 0.55. Its outliers are a column of wrong-sign samples in the v2 SDF itself.tetrahedralize2(vol, iso)is no longer empty, and the two-isovalue form takes either order.Tests
New (each fails on master):
TetraBoundaryFitsTheSurfaceInAnyUnits,TetraMeshesAnIsovalueTheSamplesHit,RefinementIsTheSameAlongEveryAxis,TetraGeometricFlowNeverMakesTheWorstTetWorse,Tetrahedralize2MeshesTheLayerBetweenTwoIsosurfaces. They measure boundary-vertex distance to the isosurface,compute_tet_quality_stats(TET_MIN_ANGLE), inverted tets, and total volume against the exact one.AdaptiveHexahedraHaveEightDistinctCornersnow also runs in a box with 1-unit voxels.Tetrahedralize2MeshExtraction(geometry_test) andTetrahedralize2Basic(algorithm_test) now expect tets.QualityImproveTetrahedralMeshandTetrahedralizeWithImprovementMethodsmesh smaller SDFs (32³ and 16³), because their bigger fitted meshes timed out a Debug CI build (300 s) or came close (178 s); they only check that each method keeps topology and finite points.test_tetrahedralize2_single_returns_geometry(pycvc) now expects vertices; I didn't run that one, because pycvc isn't built here.Locally on 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. Linux and macOS are CI's.
Not done
docs/FEM_GALLERY.mdlives in examples: fem_gallery renders FEM, surface and LBIE mesh results; docs/FEM_GALLERY.md #803. Its pictures and element counts predate this PR and need regenerating once both land (examples/cvcgl/fem_gallery_docs.sh).Octree::tetrahedralize_intervalis left in place, unused by TETRA2; DOUBLE still goes through the interval octree.