Skip to content

libigl-backed geometry processing and P1 finite elements (CVC_ENABLE_LIBIGL) - #591

Merged
transfix merged 4 commits into
masterfrom
feat/libigl-geometry
Oct 12, 2026
Merged

transfix merged 4 commits into
masterfrom
feat/libigl-geometry

Conversation

@transfix

@transfix transfix commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Brings libigl (MPL-2.0 core module only, header-only) and Eigen 5 into libcvc behind CVC_ENABLE_LIBIGL. They back an Eigen-free geometry / finite-element API and are used from cvcGL and Ariadne. Companion recipes: cy-pca/cvcpkg#145. The design rationale, current-state audit and phase plan are in docs/roadmap/LIBIGL-GEOMETRY-FE-ROADMAP.md.

What's in it (4 commits)

  1. geometry: inc/cvc/geometry/mesh_ops.h and fem.h, both Eigen-free.
    • Mesh ops:
      • Normals and repair: normals, orient_outward (an actual winding fix), repair.
      • Curvature: principal, mean and Gaussian.
      • Smoothing: implicit cotangent smoothing.
      • Spatial queries: mesh_locator (AABB closest point, scale-free double-precision ray casting, fast-winding-number signed distance).
      • Geodesics: heat-method geodesics.
      • Tet tools: volumes, orientation, boundary surface, isosurface and planar slice.
      • Colormaps.
    • P1 finite elements: stiffness and mass matrices, gradients, Poisson, Laplace, heat and Laplacian eigenmodes, on tets or surfaces.
    • Existing entry points:
      • cvc::sdf gets SDF_IGL (exact distance, robust sign on open meshes, any grid dimensions; cvc sdf -a igl).
      • geometry::project() uses exact closest points when libigl is enabled. The CGAL path, including its edge-clamp bug, stays as the fallback.
  2. cvcGL:
    • GeometryNode scalar-field colouring: setScalarField / setColorMap / setScalarRange, plus state keys color_by, colormap, scalar_min, scalar_max.
    • TETS render mode draws the outward boundary surface instead of the wireframe placeholder.
    • pycvc_gl bindings for the above.
  3. Ariadne:
    • mesh_lab node type: smooth, decimate, repair, orient, and curvature or geodesic colouring, run off the render thread.
    • fe_lab node type: LBIE tet mesh, then a Poisson or heat solve, with the field shown on the surface and on a movable slice.
    • mesh_tools.ari and fe_controls.ari components, and a mesh_lab.ari demo.
    • sdf: { algorithm: igl }.
    • AriRuntime now registers the cvcGL extensions.
  4. docs: the roadmap, the GEOMETRY_API reference, ARIADNE.md, and THIRD_PARTY_NOTICES (Eigen and libigl).

Build design

  • Option: CVC_ENABLE_LIBIGL defaults ON and switches itself OFF if Eigen3 or libigl is missing; the API then throws cvc::mesh_ops_unavailable. The finds run under CMAKE_FIND_PACKAGE_PREFER_CONFIG, because CGAL's FindEigen3.cmake cannot parse Eigen 5's version.
  • Code isolation: all Eigen and libigl code is in src/cvc/geometry/igl/, which includes no cvc headers, and builds as cvc_igl.
    • Shared cvc: cvc_igl is a private static archive, so the template instantiations stay out of cvc.dll's export table. The measured cost is +248 exports (47,084 in total).
    • Static cvc: cvc_igl is an OBJECT library compiled into libcvc.a.
    • Nothing reaches cvcTargets.cmake.
  • Threading: libigl loops run serially only on single-threaded wasm. wasm-mt keeps libigl's thread pool, matching the wasm-mt bundle.

Verification (Windows, MSVC 19.44, Release)

  • Shared build, ImageMagick ON: full suite 3,905 tests, all pass (40 intentional skips). The run used the same MAGICK_* coder-path environment as ci.yml. Separately, I found two pre-existing issues, both unrelated to this PR:
    • An intermittent segfault, about 2% of runs, in LBIE hexahedralize --improve optimization. Master-era code crashed 9 times in 400 runs, so it predates this branch. It makes CvcCliTest.Regression_MeshImproveMethodsNoCrash flaky.
    • magick_io.cpp's CVC_DEPS_PREFIX fallback doesn't locate the coders when running from a build tree.
  • Static build: the 55 libigl gtests and the cvc_igl packaging check pass.
  • CVC_ENABLE_LIBIGL=OFF (what CI builds until the bundles are published): cvc, cvcGL and the touched tests build and pass. The cvcGL tests also exercise their no-libigl branches.
  • Clang: em++ 5.0.7 compiles the igl TUs, mesh_ops.cpp and fem.cpp cleanly, with libigl on and off.
  • Review: the change went through an adversarial review; all 39 confirmed findings are fixed, with regression tests where testable.

Follow-up in this PR

CI currently builds with libigl auto-OFF, because the eigen and libigl bundles aren't on cvcpkg.org yet. Once cy-pca/cvcpkg#145 is merged and the bundles are published, a commit here will:

  • add eigen and libigl to cvcpkg/recipes/libcvc (runtime, scoped to linux, macos and windows);
  • add a CI guard that CVC_ENABLE_LIBIGL resolved ON.

Owner decision

Eigen/Core always includes the Apache-2.0 BFloat16.h, so it gets compiled into the LGPL-2.1-only cvc.dll. This is flagged in THIRD_PARTY_NOTICES and in roadmap §6.

…IBIGL)

New Eigen-free public API backed by libigl's MPL-2.0 core (header-only) and
Eigen 5:

- inc/cvc/geometry/mesh_ops.h: angle/area-weighted normals, orient_outward
  (real winding fix, what reorient() was meant to do), repair (weld by true
  distance, degenerate/unreferenced removal, attribute remapping), principal /
  mean / Gaussian curvature, implicit cotangent smoothing (+ uniform, Taubin),
  mesh_locator (AABB closest point, scale-free double-precision ray casting,
  fast-winding-number signed distance and winding number), heat-method
  geodesics with a cached solver, tet volumes / orientation / boundary surface
  / isosurface / planar slices, and colormaps (built-in tables without libigl).
- inc/cvc/geometry/fem.h: P1 FEM on tets or triangle surfaces: stiffness and
  mass matrices, gradients, Poisson, Laplace, backward-Euler heat with
  progress/cancel, Laplacian eigenmodes (dense up to 400 vertices, else a
  shift-invert subspace iteration on SimplicialLDLT); degenerate elements are
  dropped from assembly.
- cvc::sdf gains SDF_IGL (exact distance, FWN sign, any grid dims; cvc-cli
  `-a igl`, pycvc enum), and geometry::project() uses exact closest points
  when libigl is enabled (the CGAL path, with its edge-clamp bug, stays as
  the fallback).

Build: option CVC_ENABLE_LIBIGL (default ON, auto-OFF when Eigen3/libigl are
missing; the API then throws mesh_ops_unavailable). The finds run under
CMAKE_FIND_PACKAGE_PREFER_CONFIG because CGAL's FindEigen3 cannot parse Eigen
5. All Eigen/libigl code lives in src/cvc/geometry/igl/ (no cvc headers) and
builds as cvc_igl: a private static archive for a shared cvc, so template
instantiations stay out of cvc.dll's export table (+248 exports total), or an
OBJECT library compiled into a static cvc. Serial libigl loops on
single-threaded wasm only. New gtests: mesh_ops_test (39), fem_test (16) and
a cvc_igl packaging check.
GeometryNode can colour a mesh by a per-vertex scalar field:
setScalarField / setScalarRange / setColorMap / clearScalarField /
hasScalarField / scalarRange, plus state keys color_by (none, colors,
function, k1, k2, mean, gaussian), colormap, scalar_min and scalar_max, so
.ari documents and ImGui bindings can drive it with no glue. Colours are
computed on the CPU with cvc::colormap_rgb into the existing 3-channel uchar
array (WebGL-safe); range/colormap changes recolour in place without a
rebuild, and the field survives render-mode and use_single_color rebuilds.
Curvature kinds read geometry::curvatures() or compute them once via
cvc::compute_curvature when libigl is available; meshes with no surface
triangles get no field.

TETS render mode now draws the outward boundary surface
(cvc::tet_boundary_surface, all points kept so per-vertex fields still line
up) instead of the wireframe placeholder, falling back to edges without
libigl. pycvc_gl gains set_scalar_field / set_color_map / scalar_range.

Tests: cvcgl_scalar_field (incl. a rendered-pixel check that skips without
GL) and cvcgl_tet_surface (headless), both with libigl-on and -off branches.
…mponents

Two cvcGL scene node types, registered from register_cvcgl_extensions when
libcvc has CVC_ENABLE_LIBIGL (a document with `customs: required` fails fast
otherwise):

- mesh_lab: loads geometry like a `geometry` node, seeds node-scoped
  <node>.mesh_ops.* keys from its props, and runs smooth (cvc::smooth),
  decimate (cvc::simplify), repair, orient and curvature requests on a
  per-node async_lane, colouring by mean/gaussian/k1/k2 curvature or heat
  geodesic distance (cached solver) through GeometryNode::setScalarField.
- fe_lab: tet-meshes a volume source with LBIE (the SDF is negated first:
  LBIE meshes {v > iso}, verified empirically), orients the tets, solves
  Poisson or backward-Euler heat (hot floor, progress + Stop), and shows the
  field on the boundary surface and a movable slice child (<id>_slice).

Commands use a request-key convention (a button writes <node>.mesh_ops.request
or <node>.fe.request; the node's tick consumes it), documented in ARIADNE.md.
New components mesh_tools.ari and fe_controls.ari, INDEX.ari entries (plus the
missing forest/sea/sky ones), and a mesh_lab.ari demo for ariadne_hello.

Also: `source: { sdf: { algorithm: v1|v2|igl } }` (default v2; igl falls back
to v2 without libigl); scene_realize helpers (fit_to_ground,
read_node_geometry, load_node_volume, sdf_volume_from_mesh) promoted out of
the anonymous namespace; AriRuntime now calls register_cvcgl_extensions so
pycvc-hosted documents get custom node types; ARIADNE.md section 5.3 example
fixed to real loader syntax.

Tests: mesh_lab/fe_lab sections in cvcgl_ariadne_realize (decimate, curvature
and geodesic colouring, tet-meshing the bunny SDF, Poisson, heat, stop,
auto_solve queueing, slice visibility) and AriadneComponents.
ShippedComponentsLoadClean, which loads every shipped component from the
source tree and checks the INDEX catalog.
… notices

- docs/roadmap/LIBIGL-GEOMETRY-FE-ROADMAP.md: how libigl upgrades geometry
  processing and FE work in libcvc: decisions, what phase 1 delivers, an
  audit of current geometry defects with file:line, the phase 2-4 plan
  (recipe/CI wiring, pycvc bindings, AABB picking, tet data-path fixes, wasm
  rollout, CGAL reduction, volrover3 geometry_ops backend, deformation), what
  not to do, licensing, and the cvcpkg publish runbook.
- docs/GEOMETRY_API.md: a "Mesh Operations and Finite Elements (libigl)"
  reference for mesh_ops.h / fem.h, SDF_IGL and the exact project(); stale
  statements fixed (copy-on-write, 13 array types, smoothing signature and
  behaviour, enum names, sdf/iso/tetrahedralize signatures, the LBIE side of
  the isovalue, tet-orientation loss on decode).
- THIRD_PARTY_NOTICES.md: Eigen 5.0.1 (MPL-2.0 plus the Apache-2.0
  BFloat16.h, BSD, COLAMD and SuperLU notices actually compiled in) and
  libigl 2.6.4 core (MPL-2.0, MIT FastWindingNumberForSoups, public-domain
  raytri.c), with the Apache-2.0 question flagged for an owner decision.
- WATER-RENDERING-ROADMAP.md: a dated note at D-W6 that an FEM consumer now
  exists.
@transfix
transfix merged commit c16488c into master Oct 12, 2026
14 checks passed
transfix added a commit that referenced this pull request Oct 26, 2026
…BLE_LIBIGL in CI (#799)

#591 landed mesh_ops.h / fem.h behind CVC_ENABLE_LIBIGL, but the libcvc recipe
never declared eigen or libigl, so every install-deps-based lane (PR CI,
ci-recipe, publish, release/nightly) configured with the option auto-OFF:
CI never compiled the libigl code and the published libcvc bundles ship the
throwing stubs.

The bundles now exist on cvcpkg.org for every libcvc platform (eigen
5.0.1+cvc.1 and libigl 2.6.4+cvc.2, release/shared: linux x86_64 + arm64,
macos arm64 + x86_64, windows x86_64; cy-pca/cvcpkg#145, #148), and every
lane fetches release deps (Windows is release-only), so declare them as
runtime deps of libcvc (scoped to linux/macos/windows, like pocketfft) and
libcvc-cuda.

CVC_ENABLE_LIBIGL flips itself OFF when the packages are missing, which would
pass green while testing nothing, so the package-linux/macos/windows test
steps now fail unless MeshOps.* / Fem.* tests are registered (the same guard
the cvcgl_* tests already have).
@transfix
transfix deleted the feat/libigl-geometry branch October 29, 2026 20:52
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