trimesh.voxel.base module¶
voxel.py¶
Convert meshes to a simple voxel data structure and back again.
Classes

Store 3D voxels. 

class
trimesh.voxel.base.
VoxelGrid
(encoding, transform=None, metadata=None)¶ Bases:
trimesh.parent.Geometry
Store 3D voxels.
Methods
apply_transform
(matrix)as_boxes
([colors])A rough Trimesh representation of the voxels with a box for each filled voxel.
copy
()crc
()fill
([method])Mutates self by filling in the encoding according to morphology.fill.
hollow
([structure])Mutates self by removing internal voxels leaving only surface elements.
indices_to_points
(indices)is_filled
(point)Query points to see if the voxel cells they lie in are filled or not.
md5
()points_to_indices
(points)Convert points to indices in the matrix array.
revoxelized
(shape)Create a new VoxelGrid without rotations, reflections or shearing.
show
(*args, **kwargs)Convert the current set of voxels into a trimesh for visualization and show that via its built in preview method.
strip
()Mutate self by stripping leading/trailing planes of zeros.
Attributes
Encoding object providing the occupancy grid.
int, number of occupied voxels in the grid.
A marching cubes Trimesh representation of the voxels.
Return a DENSE matrix of the current voxel encoding
Deprecated.
Uniform scaling factor representing the side length of each voxel.
The center of each filled cell as a list of points.
3element float representing peraxis scale.
3tuple of ints denoting shape of occupancy grid.
(n, 3) int array of sparse indices of occupied voxels.
4x4 homogeneous transformation matrix.
Location of voxel at [0, 0, 0].
What is the volume of the filled cells in the current voxel object.

apply_transform
(matrix)¶

as_boxes
(colors=None, **kwargs)¶ A rough Trimesh representation of the voxels with a box for each filled voxel.
 Parameters
colors ((3,) or (4,) float or uint8) – (X, Y, Z, 3) or (X, Y, Z, 4) float or uint8 Where matrix.shape == (X, Y, Z)
 Returns
mesh – Mesh with one box per filled cell.
 Return type

property
bounds
¶

copy
()¶

crc
()¶

property
element_volume
¶

property
encoding
¶ Encoding object providing the occupancy grid.
See trimesh.voxel.encoding for implementations.

property
extents
¶

fill
(method='holes', **kwargs)¶ Mutates self by filling in the encoding according to morphology.fill.
 Parameters
method (implementation key, one of) – trimesh.voxel.morphology.fill.fillers keys
**kwargs (additional kwargs passed to the keyed implementation) –
 Returns
 Return type
self after replacing encoding with a filled version.

property
filled_count
¶ int, number of occupied voxels in the grid.

hollow
(structure=None)¶ Mutates self by removing internal voxels leaving only surface elements.
Surviving elements are those in encoding that are adjacent to an empty voxel, where adjacency is controlled by structure.
 Parameters
structure (adjacency structure. If None, square connectivity is used.) –
 Returns
 Return type
self after replacing encoding with a surface version.

indices_to_points
(indices)¶

property
is_empty
¶

is_filled
(point)¶ Query points to see if the voxel cells they lie in are filled or not.
 Parameters
point ((n, 3) float) – Points in space
 Returns
is_filled – Is cell occupied or not for each point
 Return type
(n,) bool

property
marching_cubes
¶ A marching cubes Trimesh representation of the voxels.
No effort was made to clean or smooth the result in any way; it is merely the result of applying the scikitimage measure.marching_cubes function to self.encoding.dense.
 Returns
meshed – object, as returned by marching cubes algorithm.
 Return type
Trimesh object representing the current voxel

property
matrix
¶ Return a DENSE matrix of the current voxel encoding
 Returns
dense – Numpy array of dense matrix Shortcut to voxel.encoding.dense
 Return type
(a, b, c) bool

md5
()¶

property
origin
¶ Deprecated. Use self.translation.

property
pitch
¶ Uniform scaling factor representing the side length of each voxel.
Raises a RuntimeError if self.transformation has rotation or shear components of has nonuniform scaling.

property
points
¶ The center of each filled cell as a list of points.
 Returns
points
 Return type
(self.filled, 3) float, list of points

points_to_indices
(points)¶ Convert points to indices in the matrix array.
 Parameters
points ((n, 3) float, point in space) –
 Returns
indices
 Return type
(n, 3) int array of indices into self.encoding

revoxelized
(shape)¶ Create a new VoxelGrid without rotations, reflections or shearing.
 Parameters
shape (3tuple of ints denoting the shape of the returned VoxelGrid.) –
 Returns
VoxelGrid of the given shape with (possibly nonuniform) scale and
translation transformation matrix.

property
scale
¶ 3element float representing peraxis scale.
Raises a RuntimeError if self.transform has rotation or shear components.

property
shape
¶ 3tuple of ints denoting shape of occupancy grid.

show
(*args, **kwargs)¶ Convert the current set of voxels into a trimesh for visualization and show that via its built in preview method.

property
sparse_indices
¶ (n, 3) int array of sparse indices of occupied voxels.

strip
()¶ Mutate self by stripping leading/trailing planes of zeros.
 Returns
 Return type
self after mutation occurs inplace

property
transform
¶ 4x4 homogeneous transformation matrix.

property
translation
¶ Location of voxel at [0, 0, 0].

property
volume
¶ What is the volume of the filled cells in the current voxel object.
 Returns
volume
 Return type
float, volume of filled cells
