Skip to content
Snippets Groups Projects

Sphericity

2 files
+ 2
1
Compare changes
  • Side-by-side
  • Inline

Files

+ 9
2
@@ -9,6 +9,7 @@ def create_mesh(
volume: np.ndarray,
level: float = None,
step_size=1,
allow_degenerate=False,
padding: Tuple[int, int, int] = (2, 2, 2),
**kwargs: Any,
) -> trimesh.Trimesh:
@@ -18,6 +19,9 @@ def create_mesh(
Args:
volume (np.ndarray): The 3D numpy array representing the volume.
level (float, optional): The threshold value for Marching Cubes. If None, Otsu's method is used.
step_size (int, optional): The step size for the Marching Cubes algorithm.
allow_degenerate (bool, optional): Whether to allow degenerate (i.e. zero-area) triangles in the end-result.
If False, degenerate triangles are removed, at the cost of making the algorithm slower. Default False.
padding (tuple of int, optional): Padding to add around the volume.
**kwargs: Additional keyword arguments to pass to `skimage.measure.marching_cubes`.
@@ -39,7 +43,7 @@ def create_mesh(
mesh = qim3d.processing.create_mesh(vol, step_size=3)
qim3d.viz.mesh(mesh.vertices, mesh.faces)
```
<iframe src="https://platform.qim.dk/k3d/mesh_visualization.html" width="100%" height="500" frameborder="0"></iframe>
"""
if volume.ndim != 3:
raise ValueError("The input volume must be a 3D numpy array.")
@@ -63,10 +67,13 @@ def create_mesh(
# Call skimage.measure.marching_cubes with user-provided kwargs
verts, faces, normals, values = measure.marching_cubes(
volume, level=level, step_size=step_size, **kwargs
volume, level=level, step_size=step_size, allow_degenerate=allow_degenerate, **kwargs
)
# Create the Trimesh object
mesh = trimesh.Trimesh(vertices=verts, faces=faces)
# Fix face orientation to ensure normals point outwards
trimesh.repair.fix_inversion(mesh, multibody=True)
return mesh
Loading