trimesh.voxel.encoding

OO interfaces to encodings for ND arrays which caching.

Classes

BinaryRunLengthEncoding(data)

1D binary run length encoding.

DenseEncoding(data)

Simple Encoding implementation based on a numpy ndarray.

Encoding(data)

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

FlattenedEncoding(data)

Lazily flattened encoding.

FlippedEncoding(encoding, axes)

Encoding with entries flipped along one or more axes.

LazyIndexMap(data)

Abstract class for implementing lazy index mapping operations.

RunLengthEncoding(data[, dtype])

1D run length encoding.

ShapedEncoding(encoding, shape)

Lazily reshaped encoding.

SparseEncoding(indices, values[, shape])

Encoding implementation based on an ND sparse implementation.

TransposedEncoding(base_encoding, perm)

Lazily transposed encoding

Functions

SparseBinaryEncoding(indices[, shape])

Convenient factory constructor for SparseEncodings with values all ones.

class trimesh.voxel.encoding.BinaryRunLengthEncoding(data)

Bases: trimesh.voxel.encoding.RunLengthEncoding

1D binary run length encoding.

See trimesh.voxel.runlength documentation for implementation details.

Methods

binary_run_length_data([dtype])

copy()

from_brle(brle_data[, dtype])

from_dense(dense_data[, encoding_dtype])

from_rle(rle_data[, dtype])

gather(indices)

gather_nd(indices)

mask(mask)

run_length_data([dtype])

sorted_gather(ordered_indices)

Attributes

dense

is_empty

size

sparse_components

sparse_indices

sparse_values

stripped

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

sum

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: trimesh.voxel.encoding.Encoding

Simple Encoding implementation based on a numpy ndarray.

Methods

copy()

gather(indices)

gather_nd(indices)

get_value(index)

mask(mask)

reshape(shape)

Attributes

dense

dtype

flat

is_empty

shape

size

sparse_components

sparse_indices

sparse_values

sum

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.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).

Methods

binary_run_length_data([dtype])

copy()

crc()

flip([axis])

gather_nd(indices)

get_value(index)

mask(mask)

md5()

reshape(shape)

run_length_data([dtype])

transpose(perm)

Attributes

data

dense

dtype

flat

is_empty

mutable

ndims

shape

size

sparse_components

sparse_indices

sparse_values

stripped

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

sum

binary_run_length_data(dtype=<class 'numpy.int64'>)
abstract copy()
crc()
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)
md5()
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: trimesh.voxel.encoding.LazyIndexMap

Lazily flattened encoding.

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

Methods

copy()

mask(mask)

Attributes

dense

flat

shape

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

Bases: trimesh.voxel.encoding.LazyIndexMap

Encoding with entries flipped along one or more axes.

Dense equivalent is np.flip

Methods

copy()

flip([axis])

mask(mask)

Attributes

dense

shape

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

Bases: trimesh.voxel.encoding.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)

Attributes

dtype

is_empty

size

sparse_indices

sparse_values

sum

Methods

gather_nd(indices)

get_value(index)

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: trimesh.voxel.encoding.Encoding

1D run length encoding.

See trimesh.voxel.runlength documentation for implementation details.

Methods

binary_run_length_data([dtype])

copy()

crc()

from_brle(brle_data[, dtype])

from_dense(dense_data[, dtype, encoding_dtype])

from_rle(rle_data[, dtype])

gather(indices)

gather_nd(indices)

get_value(index)

mask(mask)

md5()

run_length_data([dtype])

sorted_gather(ordered_indices)

Attributes

dense

dtype

is_empty

ndims

shape

size

sparse_components

sparse_indices

sparse_values

stripped

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

sum

binary_run_length_data(dtype=<class 'numpy.int64'>)
copy()
crc()
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)
md5()
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: trimesh.voxel.encoding.LazyIndexMap

Lazily reshaped encoding.

Numpy equivalent is np.reshape

Methods

copy()

mask(mask)

Attributes

dense

flat

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

Returns

Return type

rank n bool SparseEncoding with True values at each index.

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

Bases: trimesh.voxel.encoding.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.

Methods

copy()

from_dense(dense_data)

gather_nd(indices)

get_value(index)

mask(mask)

Attributes

dense

dtype

ndims

shape

size

sparse_components

sparse_indices

sparse_values

stripped

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

sum

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: trimesh.voxel.encoding.LazyIndexMap

Lazily transposed encoding

Dense equivalent is np.transpose

Methods

copy()

gather(indices)

get_value(index)

mask(mask)

transpose(perm)

Attributes

data

dense

perm

shape

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