trimesh.voxel
- class trimesh.voxel.VoxelGrid(encoding, transform=None, metadata=None)
Bases:
trimesh.parent.Geometry
Store 3D voxels.
- __init__(encoding, transform=None, metadata=None)
- 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) –
- 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.) –
- 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 scikit-image 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.
- Returns
pitch – Pitch of the voxels.
- Return type
float
- Raises
RuntimeError – If self.transformation has rotation or shear components of has non-uniform 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 (3-tuple of ints denoting the shape of the returned VoxelGrid.) –
- Returns
VoxelGrid of the given shape with (possibly non-uniform) scale and
translation transformation matrix.
- property scale
3-element float representing per-axis scale.
Raises a RuntimeError if self.transform has rotation or shear components.
- property shape
3-tuple 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.
- Return type
self after mutation occurs in-place
- 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