warp.geometry.IsoSurfaceNets#
- class warp.geometry.IsoSurfaceNets(
- nx,
- ny,
- nz,
- *,
- lower=None,
- upper=None,
- topology='triangle',
A reusable isosurface extractor using Surface Nets.
The surface gets one vertex inside each grid cell it passes through, or one per pass if it passes through the same cell more than once. Each vertex lies at the average of the points where the surface crosses the cell’s edges.
A surface that lies entirely inside the grid produces a closed mesh with no holes, where every edge is shared by exactly two faces. A surface that extends past the grid produces an open mesh, which may end slightly before the edge of the grid instead of reaching it. Every vertex belongs to at least one face.
This class provides a stateful interface following
warp.geometry.IsoSurfaceBase: initialize it with a specific grid configuration and then call thesurface()method multiple times, which is convenient for processing fields of the same size. For a simpler, stateless operation, use theextract()class method.The
topologyparameter selects whether the output faces are triangles (the default) or quads. Faces are wound counter-clockwise viewed from outside for a signed distance field (negative inside).If
fieldhasrequires_grad=Trueand the call runs inside awarp.Tape(), gradients propagate fromvertsback tofield. Cell classification and mesh topology are not differentiated.- 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) – See the documentation in
extract().upper (warp.vec3 | tuple[float, float, float] | None) – See the documentation in
extract().topology (Literal['triangle', 'quad']) – The type of the faces that
surface()produces:"triangle"or"quad".
- lower#
The lower bound for the mesh coordinate scaling. See the documentation in
extract()for more details.- Type:
warp.vec3f | tuple | None
- upper#
The upper bound for the mesh coordinate scaling. See the documentation in
extract()for more details.- Type:
warp.vec3f | tuple | None
- verts#
An array of vertex positions of type
warp.vec3ffor the output mesh. This is populated by calling thesurface()method.- Type:
warp.array | None
- indices#
An array of face vertex indices of type
warp.int32for the output mesh, with three consecutive indices per face whentopologyis"triangle", and four when it is"quad". This is populated by calling thesurface()method.- Type:
warp.array | None
Methods
extract(field[, threshold, lower, upper, ...])Extract a mesh from a 3D scalar field.
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.- surface(field, threshold)[source]#
Compute a 2D surface mesh of a given isosurface from a 3D scalar field.
This method is a convenience wrapper that calls the
extract()class method and stores the resulting mesh data in thevertsandindicesattributes, with the faces of the type selected bytopology.- 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
- classmethod extract(
- field,
- threshold=0.0,
- *,
- lower=None,
- upper=None,
- topology='triangle',
Extract a mesh from a 3D scalar field.
This function generates an isosurface by processing the entire input
field. The resolution of the output mesh is determined by the shape of thefieldarray and may differ along each dimension.The coordinates of the mesh can be scaled to a specific bounding box using the
lowerandupperparameters. If a bound is not provided (i.e., left asNone), it will be assigned a default value that aligns the mesh with the integer indices of the input grid.- 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.topology (Literal['triangle', 'quad']) – The type of the faces to produce:
"triangle"or"quad".
- Returns:
A tuple
(vertices, indices)containing the output mesh data. Theindicesarray is a flat list where each group of three consecutive integers forms a single triangle, or four a single quad, by referencing vertices in theverticesarray.- Raises:
ValueError – If
fieldis not a 3D array, has fewer than two nodes on any axis, or iftopologyis not a valid face type.TypeError – If the
fielddata type is notwarp.float32.
- Return type: