warp.geometry.IsoSurfaceBase#
- class warp.geometry.IsoSurfaceBase(nx, ny, nz, *, lower=None, upper=None)[source]#
Abstract base class for isosurface extraction from dense 3D scalar fields.
Concrete backends such as
warp.geometry.IsoSurfaceMarchingCubesimplement this interface so that extraction algorithms can be swapped behind a single API: construct an instance with the grid dimensions, then callsurface()repeatedly to extract meshes from fields of that size, reading the results from thevertsandindicesattributes. For a stateless one-shot extraction, use theextract()class method instead.All backends share the same conventions: the input is a dense 3D
warp.float32field sampled at grid nodes, the output faces are wound counter-clockwise when viewed from outside for a signed distance field (negative inside), and theindicesarray is a flatwarp.int32array listing the vertices of each face in order. Backends produce triangles, where each group of three consecutive entries forms one face, unless they support another face type and were configured to use it.All backends support backward-mode automatic differentiation from
fieldto the outputvertspositions;indicesis always discrete and carries no gradient. See each backend’s class docstring for the specific interpolation its gradient flows through.- Parameters:
nx (int) – Number of grid nodes in the x-direction.
ny (int) – Number of grid nodes in the y-direction.
nz (int) – Number of grid nodes in the z-direction.
lower (warp.vec3 | tuple[float, float, float] | None) – The 3D coordinate that the grid’s corner at index (0,0,0) maps to. Defaults to
(0.0, 0.0, 0.0)ifNone.upper (warp.vec3 | tuple[float, float, float] | None) – The 3D coordinate that the grid’s corner at index (nx-1, ny-1, nz-1) maps to. Defaults to align with the grid’s maximal indices if
None.
- lower#
The lower bound for the mesh coordinate scaling.
- Type:
warp.vec3f | tuple | None
- upper#
The upper bound for the mesh coordinate scaling.
- Type:
warp.vec3f | tuple | None
Methods
extract(field[, threshold, lower, upper])Extract a mesh from a 3D scalar field in a single stateless call.
resize(nx, ny, nz)Update the grid dimensions for the context.
surface(field, threshold)Compute a 2D surface mesh of a given isosurface from a 3D scalar field.
Attributes
An array of vertex positions of type
warp.vec3ffor the output mesh.An array of face vertex indices of type
warp.int32for the output mesh.- verts: wp.array[wp.vec3f] | None#
An array of vertex positions of type
warp.vec3ffor the output mesh. This is populated by calling thesurface()method.
- indices: wp.array[wp.int32] | None#
An array of face vertex indices of type
warp.int32for the output mesh. This is populated by calling thesurface()method.
- resize(nx, ny, nz)[source]#
Update the grid dimensions for the context.
This allows the instance to be reused for scalar fields of a different resolution. The new dimensions take effect on the next call to
surface().
- abstractmethod surface(field, threshold)[source]#
Compute a 2D surface mesh of a given isosurface from a 3D scalar field.
The resulting mesh data is stored in the
vertsandindicesattributes, replacing any previous outputs.- Parameters:
field (warp.array3d[warp.float32]) – A 3D scalar field whose shape must match the grid dimensions (nx, ny, nz) of the instance.
threshold (float) – The field value defining the isosurface to extract.
- Raises:
ValueError – If the shape of
fielddoes not match the configured grid dimensions of the instance.- Return type:
None
- abstractmethod classmethod extract(
- field,
- threshold=0.0,
- *,
- lower=None,
- upper=None,
Extract a mesh from a 3D scalar field in a single stateless call.
- Parameters:
field (warp.array3d[warp.float32]) – A 3D array representing the scalar values on a regular grid.
threshold (float) – The field value defining the isosurface to extract.
lower (vec3f | tuple[float, float, float] | None) – The 3D coordinate that the grid’s corner at index (0,0,0) maps to. Defaults to
(0.0, 0.0, 0.0)ifNone.upper (vec3f | tuple[float, float, float] | None) – The 3D coordinate that the grid’s corner at index (nx-1, ny-1, nz-1) maps to. Defaults to align with the grid’s maximal indices if
None.
- Returns:
A tuple
(vertices, indices), whereindicesis a flatwarp.int32array in which each group of three consecutive entries forms one triangle by referencing vertices in theverticesarray. Backends that support another face type accept a keyword argument to select it, and then write that type of face toindicesinstead.- Raises:
ValueError – If
fieldis not a 3D array, or has fewer than two nodes on any axis.TypeError – If the
fielddata type is notwarp.float32.
- Return type: