Meshes
qim3d.mesh.from_volume
from_volume(
volume,
mesh_precision=1.0,
backend='pyvista',
method='marching_cubes',
return_pygel3D=False,
**kwargs,
)
Converts a 3D binary or grayscale volume into a polygon mesh (isosurface extraction).
This function transforms voxel-based data into a vector-based surface representation (triangular mesh). This process, often called polygonization or tessellation, is a necessary step for 3D printing (exporting to STL), finite element analysis (FEA), or surface-based geometric measurements. It utilizes the volumetric_isocontour function from PyGEL3D to generate a high-quality manifold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
A 3D numpy array representing a volume. |
required |
mesh_precision
|
float
|
Scaling factor for adjusting the resolution of the mesh. Default is 1.0 (no scaling). |
1.0
|
backend
|
str
|
What python package is used to compute mesh from volume. It is either 'pyvista' or 'pygel'. Default is 'pyvista' |
'pyvista'
|
method
|
str
|
Only applies if ˚backend = pyvista˚. What method is used to compute mesh from volume. It can be either 'marching_cubes' or 'flying_edges'. Default is 'marching_cubes |
'marching_cubes'
|
return_pygel3D
|
bool
|
If set to True, returns pygel3d.hmesh.Manifold. If False, returns qim3d.mesh.SurfaceMesh. Default is False. |
False
|
**kwargs
|
any
|
Additional arguments to pass to the Pygel3D volumetric_isocontour function. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input is not 3D, is empty, or if |
Returns:
| Name | Type | Description |
|---|---|---|
mesh |
Manifold
|
The generated mesh object containing vertices, edges, and faces. |
Example
Convert a 3D numpy array to a Pygel3D mesh object:
import qim3d
# Generate a 3D blob
synthetic_blob = qim3d.generate.volume()
# Visualize the generated blob
qim3d.viz.volumetric(synthetic_blob)
# Convert the 3D numpy array to a Pygel3D mesh object
mesh = qim3d.mesh.from_volume(synthetic_blob, mesh_precision=0.5)
# Visualize the generated mesh
qim3d.viz.mesh(mesh)
Source code in qim3d/mesh/_common_mesh_methods.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |