trimesh.voxel.encoding module

OO interfaces to encodings for ND arrays which caching.

class trimesh.voxel.encoding.BinaryRunLengthEncoding(data)

Bases: RunLengthEncoding

1D binary run length encoding.

See trimesh.voxel.runlength documentation for implementation details.

__init__(data)
Parameters:

data (binary run length encoded data.)

binary_run_length_data(dtype=<class 'numpy.int64'>)
copy()
property dense
static from_brle(brle_data, dtype=None)
static from_dense(dense_data, encoding_dtype=<class 'numpy.int64'>)
static from_rle(rle_data, dtype=None)
gather(indices)
gather_nd(indices)
property is_empty
mask(mask)
run_length_data(dtype=<class 'numpy.int64'>)
property size
sorted_gather(ordered_indices)
property sparse_components
property sparse_indices
property sparse_values
property stripped

Get encoding with all zeros stripped from the start and end of each axis.

Returns:

  • encoding (?)

  • padding ((n, 2) int) – Padding at the start and end that was stripped

property sum
class trimesh.voxel.encoding.DenseEncoding(data)

Bases: Encoding

Simple Encoding implementation based on a numpy ndarray.

__init__(data)
copy()
property dense
property dtype
property flat
gather(indices)
gather_nd(indices)
get_value(index)
property is_empty
mask(mask)
reshape(shape)
property shape
property size
property sparse_components
property sparse_indices
property sparse_values
property sum
class trimesh.voxel.encoding.Encoding(data)

Bases: ABC

Base class for objects that implement a specific subset of of ndarray ops.

This presents a unified interface for various different ways of encoding conceptually dense arrays and to interoperate between them.

Example implementations are ND sparse arrays, run length encoded arrays and dense encodings (wrappers around np.ndarrays).

__init__(data)
binary_run_length_data(dtype=<class 'numpy.int64'>)
abstract copy()
property data
abstract property dense
abstract property dtype
property flat
flip(axis=0)
abstract gather_nd(indices)
abstract get_value(index)
property is_empty
abstract mask(mask)
property mutable
property ndims
reshape(shape)
run_length_data(dtype=<class 'numpy.int64'>)
abstract property shape
abstract property size
property sparse_components
abstract property sparse_indices
abstract property sparse_values
property stripped

Get encoding with all zeros stripped from the start and end of each axis.

Returns:

  • encoding (?)

  • padding ((n, 2) int) – Padding at the start and end that was stripped

abstract property sum
transpose(perm)
class trimesh.voxel.encoding.FlattenedEncoding(data)

Bases: LazyIndexMap

Lazily flattened encoding.

Dense equivalent is np.reshape(data, (-1,)) (np.flatten creates a copy).

copy()
property dense
property flat
mask(mask)
property shape
class trimesh.voxel.encoding.FlippedEncoding(encoding, axes)

Bases: LazyIndexMap

Encoding with entries flipped along one or more axes.

Dense equivalent is np.flip

__init__(encoding, axes)
copy()
property dense
flip(axis=0)
mask(mask)
property shape
class trimesh.voxel.encoding.LazyIndexMap(data)

Bases: Encoding

Abstract class for implementing lazy index mapping operations.

Implementations include transpose, flatten/reshaping and flipping

Derived classes must implement:
  • _to_base_indices(indices)

  • _from_base_indices(base_indices)

  • shape

  • dense

  • mask(mask)

property dtype
gather_nd(indices)
get_value(index)
property is_empty
property size
property sparse_indices
property sparse_values
property sum
class trimesh.voxel.encoding.RunLengthEncoding(data, dtype=None)

Bases: Encoding

1D run length encoding.

See trimesh.voxel.runlength documentation for implementation details.

__init__(data, dtype=None)
Parameters:
  • data (run length encoded data.)

  • dtype (dtype of encoded data. Each second value of data is cast will be) – cast to this dtype if provided.

binary_run_length_data(dtype=<class 'numpy.int64'>)
copy()
property dense
property dtype
static from_brle(brle_data, dtype=None)
static from_dense(dense_data, dtype=<class 'numpy.int64'>, encoding_dtype=<class 'numpy.int64'>)
static from_rle(rle_data, dtype=None)
gather(indices)
gather_nd(indices)
get_value(index)
property is_empty
mask(mask)
property ndims
run_length_data(dtype=<class 'numpy.int64'>)
property shape
property size
sorted_gather(ordered_indices)
property sparse_components
property sparse_indices
property sparse_values
property stripped

Get encoding with all zeros stripped from the start and end of each axis.

Returns:

  • encoding (?)

  • padding ((n, 2) int) – Padding at the start and end that was stripped

property sum
class trimesh.voxel.encoding.ShapedEncoding(encoding, shape)

Bases: LazyIndexMap

Lazily reshaped encoding.

Numpy equivalent is np.reshape

__init__(encoding, shape)
copy()
property dense
property flat
mask(mask)
property shape
trimesh.voxel.encoding.SparseBinaryEncoding(indices, shape=None)

Convenient factory constructor for SparseEncodings with values all ones.

Parameters:
  • indices ((m, n) sparse indices into conceptual rank-n array)

  • shape (length n iterable or None. If None, maximum of indices along first) – axis + 1 is used

Return type:

rank n bool SparseEncoding with True values at each index.

class trimesh.voxel.encoding.SparseEncoding(indices, values, shape=None)

Bases: Encoding

Encoding implementation based on an ND sparse implementation.

Since the scipy.sparse implementations are for 2D arrays only, this implementation uses a single-column CSC matrix with index raveling/unraveling.

__init__(indices, values, shape=None)
Parameters:
  • indices ((m, n)-sized int array of indices)

  • values ((m, n)-sized dtype array of values at the specified indices)

  • shape ((n,) iterable of integers. If None, the maximum value of indices) –

    • 1 is used.

copy()
property dense
property dtype
static from_dense(dense_data)
gather_nd(indices)
get_value(index)
mask(mask)
property ndims
property shape
property size
property sparse_components
property sparse_indices
property sparse_values
property stripped

Get encoding with all zeros stripped from the start/end of each axis.

Returns:

SparseEncoding with same values but indices shifted down

by padding[:, 0]

padding: (n, 2) array of ints denoting padding at the start/end

that was stripped

Return type:

encoding

property sum
class trimesh.voxel.encoding.TransposedEncoding(base_encoding, perm)

Bases: LazyIndexMap

Lazily transposed encoding

Dense equivalent is np.transpose

__init__(base_encoding, perm)
copy()
property data
property dense
gather(indices)
get_value(index)
mask(mask)
property perm
property shape
transpose(perm)