Skip to content

Commit 2b3d069

Browse files
committed
add a literal for the VoxelizeMethodType string argument
1 parent 82e4b2f commit 2b3d069

File tree

2 files changed

+57
-23
lines changed

2 files changed

+57
-23
lines changed

trimesh/typed.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@
6969

7070
# what 3D boolean engines are available
7171
BooleanEngineType = Literal["manifold", "blender", None]
72+
# what are the substrings for each operation
7273
BooleanOperationType = Literal["difference", "union", "intersection"]
7374

75+
VoxelizationMethodType = Literal["subdivide", "ray", "binvox"]
76+
7477
__all__ = [
7578
"IO",
7679
"Any",

trimesh/voxel/creation.py

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
from ..constants import log_time
66
from . import base
77
from . import encoding as enc
8+
from .typed import ArrayLike, Integer, Number, Optional, VoxelizationMethodsType
89

910

1011
@log_time
11-
def voxelize_subdivide(mesh, pitch: float, max_iter: int = 10, edge_factor: float = 2.0):
12+
def voxelize_subdivide(
13+
mesh, pitch: Number, max_iter: Optional[Integer] = 10, edge_factor: Number = 2.0
14+
) -> base.VoxelGrid:
1215
"""
1316
Voxelize a surface by subdividing a mesh until every edge is
1417
shorter than: (pitch / edge_factor)
@@ -17,11 +20,11 @@ def voxelize_subdivide(mesh, pitch: float, max_iter: int = 10, edge_factor: floa
1720
-----------
1821
mesh : trimesh.Trimesh
1922
Source mesh
20-
pitch : float
23+
pitch
2124
Side length of a single voxel cube
22-
max_iter : int
25+
max_iter
2326
Cap maximum subdivisions or None for no limit.
24-
edge_factor : float
27+
edge_factor
2528
Proportion of pitch maximum edge length.
2629
2730
Returns
@@ -62,7 +65,14 @@ def voxelize_subdivide(mesh, pitch: float, max_iter: int = 10, edge_factor: floa
6265
)
6366

6467

65-
def local_voxelize(mesh, point, pitch, radius, fill=True, **kwargs):
68+
def local_voxelize(
69+
mesh,
70+
point: ArrayLike,
71+
pitch: Number,
72+
radius: Number,
73+
fill: bool = True,
74+
**kwargs,
75+
) -> Optional[base.VoxelGrid]:
6676
"""
6777
Voxelize a mesh in the region of a cube around a point. When fill=True,
6878
uses proximity.contains to fill the resulting voxels so may be meaningless
@@ -75,11 +85,12 @@ def local_voxelize(mesh, point, pitch, radius, fill=True, **kwargs):
7585
Source geometry
7686
point : (3, ) float
7787
Point in space to voxelize around
78-
pitch : float
88+
pitch
7989
Side length of a single voxel cube
80-
radius : int
90+
radius
8191
Number of voxel cubes to return in each direction.
82-
kwargs : parameters to pass to voxelize_subdivide
92+
kwargs
93+
Parameters to pass to voxelize_subdivide
8394
8495
Returns
8596
-----------
@@ -152,22 +163,25 @@ def local_voxelize(mesh, point, pitch, radius, fill=True, **kwargs):
152163

153164

154165
@log_time
155-
def voxelize_ray(mesh, pitch, per_cell=None):
166+
def voxelize_ray(
167+
mesh, pitch: Number, per_cell: Optional[ArrayLike] = None
168+
) -> base.VoxelGrid:
156169
"""
157170
Voxelize a mesh using ray queries.
158171
159172
Parameters
160173
-------------
161-
mesh : Trimesh object
162-
Mesh to be voxelized
163-
pitch : float
164-
Length of voxel cube
174+
mesh
175+
Mesh to be voxelized
176+
pitch
177+
Length of voxel cube
165178
per_cell : (2,) int
166-
How many ray queries to make per cell
179+
How many ray queries to make per cell
167180
168181
Returns
169182
-------------
170-
VoxelGrid instance representing the voxelized mesh.
183+
grid
184+
VoxelGrid instance representing the voxelized mesh.
171185
"""
172186
if per_cell is None:
173187
# how many rays per cell
@@ -211,7 +225,13 @@ def voxelize_ray(mesh, pitch, per_cell=None):
211225

212226

213227
@log_time
214-
def voxelize_binvox(mesh, pitch=None, dimension=None, bounds=None, **binvoxer_kwargs):
228+
def voxelize_binvox(
229+
mesh,
230+
pitch: Optional[Number] = None,
231+
dimension: Optional[Integer] = None,
232+
bounds: Optional[ArrayLike] = None,
233+
**binvoxer_kwargs,
234+
) -> base.VoxelGrid:
215235
"""
216236
Voxelize via binvox tool.
217237
@@ -233,7 +253,8 @@ def voxelize_binvox(mesh, pitch=None, dimension=None, bounds=None, **binvoxer_kw
233253
234254
Returns
235255
--------------
236-
`VoxelGrid` instance
256+
grid
257+
`VoxelGrid` instance
237258
238259
Raises
239260
--------------
@@ -263,7 +284,12 @@ def voxelize_binvox(mesh, pitch=None, dimension=None, bounds=None, **binvoxer_kw
263284
)
264285

265286

266-
def voxelize(mesh, pitch, method="subdivide", **kwargs):
287+
def voxelize(
288+
mesh,
289+
pitch: Number,
290+
method: VoxelizationMethodsType = "subdivide",
291+
**kwargs,
292+
) -> Optional[base.VoxelGrid]:
267293
"""
268294
Voxelize the given mesh using the specified implementation.
269295
@@ -275,13 +301,18 @@ def voxelize(mesh, pitch, method="subdivide", **kwargs):
275301
276302
Parameters
277303
--------------
278-
mesh: Trimesh object (left unchanged).
279-
pitch: float, side length of each voxel.
280-
method: implementation method. Must be in `fillers`.
281-
**kwargs: additional kwargs passed to the specified implementation.
304+
mesh
305+
Geometry to voxelize
306+
pitch
307+
Side length of each voxel.
308+
method
309+
Which voxelization method to use.
310+
kwargs
311+
Passed through to the specified implementation.
282312
283313
Returns
284314
--------------
285-
A VoxelGrid instance.
315+
grid
316+
A VoxelGrid instance.
286317
"""
287318
return voxelizers(method, mesh=mesh, pitch=pitch, **kwargs)

0 commit comments

Comments
 (0)