lagrange.volume¶
Classes¶
Compression method for VDB and NanoVDB grid IO |
|
Signing method used to determine inside/outside voxels |
Module Contents¶
- class lagrange.volume.Compression(*args, **kwds)¶
Bases:
enum.EnumCompression method for VDB and NanoVDB grid IO
- Blosc = 2¶
Blosc compression.
- Uncompressed = 0¶
No compression.
- Zip = 1¶
Zip compression.
- class lagrange.volume.Grid¶
- densify()¶
Densify the grid by filling in inactive voxels within the active voxel bounding box.
- Returns:
Densified grid.
- Return type:
- static from_mesh(mesh, voxel_size=-0.01, signing_method=Sign.FloodFill, dtype=numpy.float32)¶
Convert a triangle mesh to a sparse voxel grid, writing the result to a file.
- Parameters:
mesh (lagrange.core.SurfaceMesh) – Input mesh. Must be a triangle mesh, a quad-mesh, or a quad-dominant mesh.
voxel_size (float) – Voxel size. Negative means relative to bbox diagonal (vs -> -vs * bbox_diag).
signing_method (Sign) – Method used to compute the sign of the distance field.
dtype (type) – Scalar type of the output grid (float32 or float64).
- Returns:
Generated sparse voxel grid.
- Return type:
- index_to_world(indices)¶
Convert a set of voxel indices to world coordinates.
- Parameters:
indices (Annotated[numpy.typing.NDArray[numpy.int32], dict(shape=(None, 3), order='C', device='cpu', writable=False)] | Annotated[numpy.typing.NDArray[numpy.float32], dict(shape=(None, 3), order='C', device='cpu', writable=False)] | Annotated[numpy.typing.NDArray[numpy.float64], dict(shape=(None, 3), order='C', device='cpu', writable=False)]) – Input voxel indices as an (N, 3) array of integers or double.
- Returns:
World coordinates as an (N, 3) array of double.
- Return type:
Annotated[numpy.typing.NDArray[numpy.float32], dict(shape=(None, 3), order=’F’)] | Annotated[numpy.typing.NDArray[numpy.float64], dict(shape=(None, 3), order=’F’)]
- static load(input_path_or_buffer)¶
Load a grid from a file or memory buffer.
- Parameters:
input_path_or_buffer (str | os.PathLike | bytes) – Input file path (str or pathlib.Path) or memory buffer (bytes).
- Returns:
Loaded grid.
- Return type:
- offset_in_place(offset_radius, relative=False)¶
Apply an offset to the signed distance field in-place.
- Parameters:
offset_radius (float) – Offset radius. A negative value dilates the surface, a positive value erodes it.
relative (bool) – Whether the offset radius is relative to the grid voxel size.
- Return type:
None
- redistance()¶
Recompute the signed distance values of the grid using a fast sweeping method.
- Returns:
Redistanced grid.
- Return type:
- resample(voxel_size)¶
Resample the grid to a new voxel size.
- Parameters:
voxel_size (float) – New voxel size. Negative means relative to the input grid voxel size.
- Returns:
Resampled grid.
- Return type:
- sample_trilinear_index_space(points)¶
Sample the grid at the given world coordinates using trilinear interpolation.
- Parameters:
points (Annotated[numpy.typing.NDArray[numpy.int32], dict(shape=(None, 3), order='C', device='cpu', writable=False)] | Annotated[numpy.typing.NDArray[numpy.float32], dict(shape=(None, 3), order='C', device='cpu', writable=False)] | Annotated[numpy.typing.NDArray[numpy.float64], dict(shape=(None, 3), order='C', device='cpu', writable=False)]) – Input index coordinates as an (N, 3) array of integers or double.
- Returns:
Sampled values as an (N,) array of double.
- Return type:
Annotated[numpy.typing.NDArray[numpy.float32], dict(shape=(None, ), order=’C’)] | Annotated[numpy.typing.NDArray[numpy.float64], dict(shape=(None, ), order=’C’)]
- sample_trilinear_world_space(points)¶
Sample the grid at the given world coordinates using trilinear interpolation.
- Parameters:
points (Annotated[numpy.typing.NDArray[numpy.float32], dict(shape=(None, 3), order='C', device='cpu', writable=False)] | Annotated[numpy.typing.NDArray[numpy.float64], dict(shape=(None, 3), order='C', device='cpu', writable=False)]) – Input world coordinates as an (N, 3) array of double.
- Returns:
Sampled values as an (N,) array of double.
- Return type:
Annotated[numpy.typing.NDArray[numpy.float32], dict(shape=(None, ), order=’C’)] | Annotated[numpy.typing.NDArray[numpy.float64], dict(shape=(None, ), order=’C’)]
- save(output_path, compression=Compression.Blosc)¶
Save the grid to a file.
- Parameters:
output_path (str | os.PathLike) – Output file path (str or pathlib.Path).
compression (Compression) – Compression method to use. Default is Blosc.
- Return type:
None
- to_buffer(compression=Compression.Blosc)¶
Save the grid to a memory buffer.
- Parameters:
grid_type – Output grid type, either ‘vdb’ or ‘nvdb’.
compression (Compression) – Compression method to use. Default is Blosc.
- Returns:
Memory buffer (bytes).
- Return type:
bytes
- to_mesh(isovalue=0.0, adaptivity=0.0, relax_disoriented_triangles=True, normal_attribute_name=None)¶
Mesh the isosurface of a sparse voxel grid.
- Parameters:
grid – Input grid to mesh.
isovalue (float) – Value of the isosurface.
adaptivity (float) – Surface adaptivity threshold [0 to 1]. 0 keeps the original quad mesh, while 1 simplifies the most.
relax_disoriented_triangles (bool) – Toggle relaxing disoriented triangles during adaptive meshing.
normal_attribute_name (str | None) – If provided, computes vertex normals from the volume and store them in the appropriately named attribute.
- Returns:
Meshed isosurface.
- Return type:
- world_to_index(points)¶
Convert a set of world coordinates to voxel indices.
- Parameters:
points (Annotated[numpy.typing.NDArray[numpy.float32], dict(shape=(None, 3), order='C', device='cpu', writable=False)] | Annotated[numpy.typing.NDArray[numpy.float64], dict(shape=(None, 3), order='C', device='cpu', writable=False)]) – Input world coordinates as an (N, 3) array of double.
- Returns:
Voxel indices as an (N, 3) array of double.
- Return type:
Annotated[numpy.typing.NDArray[numpy.float32], dict(shape=(None, 3), order=’F’)] | Annotated[numpy.typing.NDArray[numpy.float64], dict(shape=(None, 3), order=’F’)]
- property background: float | float¶
Return the grid background value.
- Return type:
float | float
- property bbox_index: Annotated[numpy.typing.NDArray[numpy.int32], dict(shape=2, 3, order='F')]¶
Return the axis-aligned bounding box of all active voxels in index space. If the grid is empty a default bbox is returned.
- Return type:
Annotated[numpy.typing.NDArray[numpy.int32], dict(shape=(2, 3), order=’F’)]
- property bbox_world: Annotated[numpy.typing.NDArray[numpy.float64], dict(shape=2, 3, order='F')]¶
Return the axis-aligned bounding box of all active voxels in world space. If the grid is empty a default bbox is returned.
- Return type:
Annotated[numpy.typing.NDArray[numpy.float64], dict(shape=(2, 3), order=’F’)]
- property num_active_voxels: int¶
Return the number of active voxels in the grid.
- Return type:
int
- property voxel_size: Annotated[numpy.typing.NDArray[numpy.float64], dict(shape=3, order='C')]¶
Return the grid voxel size.
- Return type:
Annotated[numpy.typing.NDArray[numpy.float64], dict(shape=3, order=’C’)]
- class lagrange.volume.Sign(*args, **kwds)¶
Bases:
enum.EnumSigning method used to determine inside/outside voxels
- FloodFill = 0¶
Default voxel flood-fill method used by OpenVDB.
- Unsigned = 2¶
Do not compute sign, output unsigned distance field.
- WindingNumber = 1¶
Fast winding number method based on [Barill et al. 2018].