warp.geometry.lipschitz_octree#

warp.geometry.lipschitz_octree(
field,
origin,
root_width,
max_depth,
threshold=0.0,
lipschitz_bound=1.0,
device=None,
)[source]#

Return max-depth octree cells that may intersect a level set of a Lipschitz-bounded implicit field.

Builds a sparse octree top-down, keeping only cells whose subtree can still reach the threshold level set of a 1-Lipschitz field: a cell of width h centered at c survives when |field(c) - threshold| <= lipschitz_bound * (sqrt(3)/2) * h. The surviving leaves at max_depth form a thin shell around the surface.

This mirrors igl::lipschitz_octree from libigl. It is the pruning stage used by sparse_marching_cubes(), exposed separately so callers can build their own extractors, visualize the adaptive grid, or reuse the cells.

This function does not support backward-mode automatic differentiation, by design: cell selection is a discrete, threshold-based search, not a smooth function of field’s values, so there is no gradient to carry from field to the output cells. Recording this function on a warp.Tape() is silent – no warning, no gradient; see sparse_marching_cubes_from_cells() for the differentiable extraction stage.

Parameters:
  • field (Callable[[array], array]) – The implicit function, in the batched form accepted by sparse_marching_cubes().

  • origin (vec3f | tuple[float, float, float]) – The minimum corner of the cubic root cell. Set origin and root_width so that the box [origin, origin + root_width] covers the entire level set to be found; cells outside it are never visited.

  • root_width (float) – The side length of the cubic root cell.

  • max_depth (int) – The octree depth. Leaf cells have width root_width / 2**max_depth.

  • threshold (float) – The isovalue defining the surface.

  • lipschitz_bound (float) – An upper bound on the Lipschitz constant of field.

  • device (Device | str | None) – The Warp device to run on. Defaults to the current device.

Returns:

A tuple (cells, cell_width) where cells is a warp.array[warp.vec3i] of the leaf cells’ integer minimum-corner subscripts, in the convention sparse_marching_cubes_from_cells() expects (cell (i, j, k) covers [origin + cell_width * (i, j, k), origin + cell_width * (i + 1, j + 1, k + 1)]), and cell_width is their common side length. cells is empty if the level set is not bracketed.

Return type:

tuple[array, float]