trimesh.voxel package¶
Submodules¶
- trimesh.voxel.base module
- voxel.py
VoxelGrid
VoxelGrid.__init__()
VoxelGrid.apply_transform()
VoxelGrid.as_boxes()
VoxelGrid.bounds
VoxelGrid.copy()
VoxelGrid.element_volume
VoxelGrid.encoding
VoxelGrid.export()
VoxelGrid.extents
VoxelGrid.fill()
VoxelGrid.filled_count
VoxelGrid.hollow()
VoxelGrid.indices_to_points()
VoxelGrid.is_empty
VoxelGrid.is_filled()
VoxelGrid.marching_cubes
VoxelGrid.matrix
VoxelGrid.pitch
VoxelGrid.points
VoxelGrid.points_to_indices()
VoxelGrid.revoxelized()
VoxelGrid.scale
VoxelGrid.shape
VoxelGrid.show()
VoxelGrid.sparse_indices
VoxelGrid.strip()
VoxelGrid.transform
VoxelGrid.translation
VoxelGrid.volume
- trimesh.voxel.creation module
- trimesh.voxel.encoding module
BinaryRunLengthEncoding
BinaryRunLengthEncoding.__init__()
BinaryRunLengthEncoding.binary_run_length_data()
BinaryRunLengthEncoding.copy()
BinaryRunLengthEncoding.dense
BinaryRunLengthEncoding.from_brle()
BinaryRunLengthEncoding.from_dense()
BinaryRunLengthEncoding.from_rle()
BinaryRunLengthEncoding.gather()
BinaryRunLengthEncoding.gather_nd()
BinaryRunLengthEncoding.is_empty
BinaryRunLengthEncoding.mask()
BinaryRunLengthEncoding.run_length_data()
BinaryRunLengthEncoding.size
BinaryRunLengthEncoding.sorted_gather()
BinaryRunLengthEncoding.sparse_components
BinaryRunLengthEncoding.sparse_indices
BinaryRunLengthEncoding.sparse_values
BinaryRunLengthEncoding.stripped
BinaryRunLengthEncoding.sum
DenseEncoding
DenseEncoding.__init__()
DenseEncoding.copy()
DenseEncoding.dense
DenseEncoding.dtype
DenseEncoding.flat
DenseEncoding.gather()
DenseEncoding.gather_nd()
DenseEncoding.get_value()
DenseEncoding.is_empty
DenseEncoding.mask()
DenseEncoding.reshape()
DenseEncoding.shape
DenseEncoding.size
DenseEncoding.sparse_components
DenseEncoding.sparse_indices
DenseEncoding.sparse_values
DenseEncoding.sum
Encoding
Encoding.__init__()
Encoding.binary_run_length_data()
Encoding.copy()
Encoding.data
Encoding.dense
Encoding.dtype
Encoding.flat
Encoding.flip()
Encoding.gather_nd()
Encoding.get_value()
Encoding.is_empty
Encoding.mask()
Encoding.mutable
Encoding.ndims
Encoding.reshape()
Encoding.run_length_data()
Encoding.shape
Encoding.size
Encoding.sparse_components
Encoding.sparse_indices
Encoding.sparse_values
Encoding.stripped
Encoding.sum
Encoding.transpose()
FlattenedEncoding
FlippedEncoding
LazyIndexMap
RunLengthEncoding
RunLengthEncoding.__init__()
RunLengthEncoding.binary_run_length_data()
RunLengthEncoding.copy()
RunLengthEncoding.dense
RunLengthEncoding.dtype
RunLengthEncoding.from_brle()
RunLengthEncoding.from_dense()
RunLengthEncoding.from_rle()
RunLengthEncoding.gather()
RunLengthEncoding.gather_nd()
RunLengthEncoding.get_value()
RunLengthEncoding.is_empty
RunLengthEncoding.mask()
RunLengthEncoding.ndims
RunLengthEncoding.run_length_data()
RunLengthEncoding.shape
RunLengthEncoding.size
RunLengthEncoding.sorted_gather()
RunLengthEncoding.sparse_components
RunLengthEncoding.sparse_indices
RunLengthEncoding.sparse_values
RunLengthEncoding.stripped
RunLengthEncoding.sum
ShapedEncoding
SparseBinaryEncoding()
SparseEncoding
SparseEncoding.__init__()
SparseEncoding.copy()
SparseEncoding.dense
SparseEncoding.dtype
SparseEncoding.from_dense()
SparseEncoding.gather_nd()
SparseEncoding.get_value()
SparseEncoding.mask()
SparseEncoding.ndims
SparseEncoding.shape
SparseEncoding.size
SparseEncoding.sparse_components
SparseEncoding.sparse_indices
SparseEncoding.sparse_values
SparseEncoding.stripped
SparseEncoding.sum
TransposedEncoding
- trimesh.voxel.morphology module
- trimesh.voxel.ops module
- trimesh.voxel.runlength module
brle_gather_1d()
brle_gatherer_1d()
brle_length()
brle_logical_not()
brle_mask()
brle_reverse()
brle_strip()
brle_to_brle()
brle_to_dense()
brle_to_rle()
brle_to_sparse()
dense_to_brle()
dense_to_rle()
merge_brle_lengths()
merge_rle_lengths()
rle_gather_1d()
rle_gatherer_1d()
rle_length()
rle_mask()
rle_reverse()
rle_strip()
rle_to_brle()
rle_to_dense()
rle_to_rle()
rle_to_sparse()
sorted_brle_gather_1d()
sorted_rle_gather_1d()
split_long_brle_lengths()
split_long_rle_lengths()
- trimesh.voxel.transforms module
Transform
Transform.__init__()
Transform.apply_scale()
Transform.apply_transform()
Transform.apply_translation()
Transform.copy()
Transform.inverse_matrix
Transform.inverse_transform_points()
Transform.is_identity
Transform.matrix
Transform.pitch
Transform.scale
Transform.transform_points()
Transform.translation
Transform.unit_volume
Module contents¶
- class trimesh.voxel.VoxelGrid(encoding, transform=None, metadata=None)¶
Bases:
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 (None, (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()¶
- property element_volume¶
- property encoding¶
Encoding object providing the occupancy grid.
See trimesh.voxel.encoding for implementations.
- export(file_obj=None, file_type=None, **kwargs)¶
Export the current VoxelGrid.
- Parameters:
file_obj (file-like or str) – File or file-name to export to.
file_type (None or str) – Only ‘binvox’ currently supported.
- Returns:
export – Value of export.
- Return type:
bytes
- property extents¶
- fill(method='holes', **kwargs)¶
Mutates self by filling in the encoding according to morphology.fill.
- Parameters:
method (hashable) – Implementation key, one of trimesh.voxel.morphology.fill.fillers keys
**kwargs (dict) – Additional kwargs passed through to the keyed implementation.
- Returns:
self – After replacing encoding with a filled version.
- Return type:
- property filled_count¶
int, number of occupied voxels in the grid.
- hollow()¶
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.
- Returns:
self – After replacing encoding with a surface version.
- Return type:
- 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 – Representing the current voxel object as returned by marching cubes algorithm.
- Return type:
- 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
- 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 – Points in space.
- Return type:
(self.filled, 3) float
- 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, int)) – The shape of the returned VoxelGrid.
- Returns:
vox – Of the given shape with possibly non-uniform scale and translation transformation matrix.
- Return type:
- 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 – Volume of filled cells.
- Return type:
float