trimesh.voxel¶
- trimesh.voxel.base
- voxel.py
VoxelGridVoxelGrid.__init__()VoxelGrid.apply_transform()VoxelGrid.as_boxes()VoxelGrid.boundsVoxelGrid.copy()VoxelGrid.element_volumeVoxelGrid.encodingVoxelGrid.export()VoxelGrid.extentsVoxelGrid.fill()VoxelGrid.filled_countVoxelGrid.hollow()VoxelGrid.identifier_hashVoxelGrid.indices_to_points()VoxelGrid.is_emptyVoxelGrid.is_filled()VoxelGrid.marching_cubesVoxelGrid.matrixVoxelGrid.pitchVoxelGrid.pointsVoxelGrid.points_to_indices()VoxelGrid.revoxelized()VoxelGrid.scaleVoxelGrid.shapeVoxelGrid.show()VoxelGrid.sparse_indicesVoxelGrid.strip()VoxelGrid.transformVoxelGrid.translationVoxelGrid.volume
- trimesh.voxel.creation
- trimesh.voxel.encoding
BinaryRunLengthEncodingBinaryRunLengthEncoding.__init__()BinaryRunLengthEncoding.binary_run_length_data()BinaryRunLengthEncoding.copy()BinaryRunLengthEncoding.denseBinaryRunLengthEncoding.from_brle()BinaryRunLengthEncoding.from_dense()BinaryRunLengthEncoding.from_rle()BinaryRunLengthEncoding.gather()BinaryRunLengthEncoding.gather_nd()BinaryRunLengthEncoding.is_emptyBinaryRunLengthEncoding.mask()BinaryRunLengthEncoding.run_length_data()BinaryRunLengthEncoding.sizeBinaryRunLengthEncoding.sorted_gather()BinaryRunLengthEncoding.sparse_componentsBinaryRunLengthEncoding.sparse_indicesBinaryRunLengthEncoding.sparse_valuesBinaryRunLengthEncoding.strippedBinaryRunLengthEncoding.sum
DenseEncodingDenseEncoding.__init__()DenseEncoding.copy()DenseEncoding.denseDenseEncoding.dtypeDenseEncoding.flatDenseEncoding.gather()DenseEncoding.gather_nd()DenseEncoding.get_value()DenseEncoding.is_emptyDenseEncoding.mask()DenseEncoding.reshape()DenseEncoding.shapeDenseEncoding.sizeDenseEncoding.sparse_componentsDenseEncoding.sparse_indicesDenseEncoding.sparse_valuesDenseEncoding.sum
EncodingEncoding.__init__()Encoding.binary_run_length_data()Encoding.copy()Encoding.dataEncoding.denseEncoding.dtypeEncoding.flatEncoding.flip()Encoding.gather_nd()Encoding.get_value()Encoding.is_emptyEncoding.mask()Encoding.mutableEncoding.ndimsEncoding.reshape()Encoding.run_length_data()Encoding.shapeEncoding.sizeEncoding.sparse_componentsEncoding.sparse_indicesEncoding.sparse_valuesEncoding.strippedEncoding.sumEncoding.transpose()
FlattenedEncodingFlippedEncodingLazyIndexMapRunLengthEncodingRunLengthEncoding.__init__()RunLengthEncoding.binary_run_length_data()RunLengthEncoding.copy()RunLengthEncoding.denseRunLengthEncoding.dtypeRunLengthEncoding.from_brle()RunLengthEncoding.from_dense()RunLengthEncoding.from_rle()RunLengthEncoding.gather()RunLengthEncoding.gather_nd()RunLengthEncoding.get_value()RunLengthEncoding.is_emptyRunLengthEncoding.mask()RunLengthEncoding.ndimsRunLengthEncoding.run_length_data()RunLengthEncoding.shapeRunLengthEncoding.sizeRunLengthEncoding.sorted_gather()RunLengthEncoding.sparse_componentsRunLengthEncoding.sparse_indicesRunLengthEncoding.sparse_valuesRunLengthEncoding.strippedRunLengthEncoding.sum
ShapedEncodingSparseBinaryEncoding()SparseEncodingSparseEncoding.__init__()SparseEncoding.copy()SparseEncoding.denseSparseEncoding.dtypeSparseEncoding.from_dense()SparseEncoding.gather_nd()SparseEncoding.get_value()SparseEncoding.mask()SparseEncoding.ndimsSparseEncoding.shapeSparseEncoding.sizeSparseEncoding.sparse_componentsSparseEncoding.sparse_indicesSparseEncoding.sparse_valuesSparseEncoding.strippedSparseEncoding.sum
TransposedEncoding
- trimesh.voxel.morphology
- trimesh.voxel.ops
- trimesh.voxel.runlength
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
TransformTransform.__init__()Transform.apply_scale()Transform.apply_transform()Transform.apply_translation()Transform.copy()Transform.inverse_matrixTransform.inverse_transform_points()Transform.is_identityTransform.matrixTransform.pitchTransform.scaleTransform.transform_points()Transform.translationTransform.unit_volume
- class trimesh.voxel.VoxelGrid(encoding, transform=None, metadata=None)¶
Bases:
GeometryStore 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:
- property identifier_hash: str¶
- 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