marching_cubes
pleat.marching_cubes ¶
Marching-cubes mesh generation from signed-distance fields.
Thin wrapper around :mod:sdf for converting SDFs into triangle meshes that
can be exported to STL via :mod:meshio. Used to produce 3D-printable
thickened versions of crease patterns. Optional dependency: threed.
CartesianGrid ¶
Axis aligned cartesian grid in n-dimensional euclidean space
Source code in pleat/marching_cubes.py
cell_centers ¶
Get the centers of grid cells at specified indices
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
ndarray
|
Array of shape (n, dim), of indices along the different axes. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
center positions as array of shape (n, dim). |
Source code in pleat/marching_cubes.py
get_1d_axis_grids ¶
Get a list of 1D grids, corresponding to the axes of this grid
subdivide ¶
Subdivide the grid, resulting in a finer grid
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subdivisions
|
int | tuple | ndarray
|
Number of subdivisions per dimension. If integer, each dimension will be subdivided by the given number. Default is 2. |
2
|
Returns:
| Type | Description |
|---|---|
'CartesianGrid'
|
The subdivided :class: |
Source code in pleat/marching_cubes.py
coarsen ¶
The inverse to :meth:subdivide.
Source code in pleat/marching_cubes.py
coarsen_indices ¶
Get list of unique indices of cells in coarser grid, that the grid cells at given indices are part of.
Source code in pleat/marching_cubes.py
coarsen_block_indices ¶
coarsen_block_indices(
indices_per_dim: list[ndarray],
subdivisions: int | tuple | ndarray,
) -> list[np.ndarray]
Apply :meth:coarsen_indices independently per axis to a block of indices.
Source code in pleat/marching_cubes.py
subdivide_indices ¶
Get list of indices of cells in finer grid that encompass the grid cells at given indices.
Source code in pleat/marching_cubes.py
oct_tree_marching_cubes ¶
oct_tree_marching_cubes(
f: callable,
step: ndarray,
bounds: ndarray | None = None,
) -> tuple[np.ndarray, CartesianGrid]
Locate boundary cells of an SDF using an oct-tree refinement strategy.
Builds successively coarser grids until the bounding box fits in one cell, then refines top-down, keeping only cells whose distance is within the cell radius. Returns the surviving cell indices and the finest grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
callable
|
Signed-distance function mapping |
required |
step
|
ndarray
|
Grid spacing per axis (or scalar applied to all). |
required |
bounds
|
ndarray | None
|
Axis-aligned bounding box |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
|
CartesianGrid
|
indices in the finest grid and |