Modules | TS

Tetmesh

Constrained Delaunay tetrahedralization of closed surfaces.
This module is in active development: its surface and its results may change between releases.

The Tetmesh module fills the solid a closed surface encloses with tetrahedra. The surface is recovered exactly: every input face is a union of tetrahedron faces, and the tetrahedralization is constrained Delaunay.

import * as tf from "@polydera/trueform";

Tet Mesh

const result = tf.tetMesh(mesh);
// result.tetrahedra: NDArrayInt32 [T, 4]; result.points: NDArrayFloat64 [P, 3]
if (result.status === tf.TetMeshStatus.meshed) {
  // ...
}
tf.deleteTetMesh(result);

// off the main thread
const later = await tf.async.tetMesh(mesh, { tolerance: 1e-6 });
OptionTypeDescription
splitConstraintsboolean, default trueCut the crossings the recovery finds; without it the surface is meshed as given and a crossing in it refuses
tolerancenumber, default 0Plane pooling, in the mesh's coordinates: near-coplanar faces pool onto one plane at the entrance, and it is the band of every drain
siteBudgetRationumberAn integer: the sites a run may hold per site its entrance states. Default: the library's
returnReportboolean, default falseAlso return the report, measured only when asked
returnIndexMaptrueAlso return the index map

The points come back in float64 whatever the mesh's dtype: they are exact lattice positions mapped back, finer than a float32 holds. The mesh's transformation places it, so the points are world positions; its face membership and manifold edge link caches are reused. The result's arrays own WASM storage: release them with tf.deleteTetMesh, which leaves the input mesh untouched.

The Index Map

const r = tf.tetMesh(mesh, { returnIndexMap: true });
// r.facetOffsets [K + 1] / r.facetTriangles [N, 3]: per facet, the boundary triangles covering it
// r.faceFacetOffsets [F + 1] / r.faceFacets: per input face, the facets it lies in, ascending

Coplanar input triangles that meet wound alike are one facet; a face lies in one facet unless a crossing cut it. The map is only computed when asked for.

The Report

result.status is the call's answer, a tf.TetMeshStatus value:

StatusMeaning
meshedEvery constraint recovered and the surface winds consistently; the mesh is the cells it winds positively
refusedSome constraint was refused, the entrance left a carrier without its triangles, or its lattice cannot resolve the crossings its passes kept naming; the report counts each kind. A mesh is returned only when the surface still winds consistently
openThe recovered surface has a hole, a rim of free edges that hangs off no non-manifold attachment; no mesh. tf.fillHoles closes a hole
unwoundThe surface does not wind consistently, or it holds a sheet such as a flap whose free rim bounds nothing; no mesh
rankDeficientThe points span less than three dimensions
capacityThe cells or sites outgrew the index type

The rest of the report is opt-in. Under { returnReport: true }, result.report mirrors the C++ tf::tet_mesh_report in camelCase: status is a tf.TetMeshStatus value, refusals are counted by kind, and census carries the constraint recovery's counts. See the C++ Tetmesh module for every field.