sksurgerycore.transforms.transform_manager module

Class implementing a general purpose 4x4 transformation matrix manager.

class sksurgerycore.transforms.transform_manager.TransformManager[source]

Bases: object

Class for managing 4x4 transformation matrices. This class is NOT designed to be thread-safe.

The transforms are required to be 4x4 matrices. There is no checking that the upper left 3x3 is an orthonormal rotation matrix.

Usage:

tm = TransformManager()

# Imagine some example transformations:
t1 = np.eye(4)
t2 = np.eye(4)
t3 = np.eye(4)

# Add transformations to the TransformManager.
tm.add("model2world", t1)
tm.add("hand2eye",t2)
tm.add("hand2world",t3)

# Returns a transform from model to eye,
# by working through the above transforms.
t4 = tm.get("model2eye")

and so on.

add(name, transform)[source]

Adds a transform called name. If the name already exists, the corresponding transform is replaced without warning.

Parameters:
  • name – the name of the transform, e.g. model2world
  • transform – the transform, e.g. 4x4 matrix
count()[source]

Returns how many transforms are in the manager. Internally this class also stores the inverse, so this method will count those matrices as well.

exists(name)[source]

Returns True if the transform exists in the manager, and False otherwise. Internally this class stores the inverse. So, if you add model2world, you are also implicitly adding world2model, so this method will return True for both the originally added transform, and its own inverse.

static flip_name(name)[source]

Returns the inverse name.

Parameters:name – the name of a transformation, e.g. model2world
Returns:str – the opposite transformation name, e.g. world2model
get(name)[source]

Returns the named transform or throws ValueError.

Raises:ValueError
static is_valid_name(name)[source]

Validates the name, which must match “^([a-z]+)2([a-z]+)$”.

i.e. one or more lowercase letters, followed by the number 2, followed by one or more lowercase letters.

For example:

a2b
model2world

Identity transforms such as model2model raise ValueError.

Parameters:name – the name of the transform, eg. model2world
Raises:TypeError, ValueError
Returns:str, str – parts of string before and after the 2.
static is_valid_transform(transform)[source]

Validates the transform as a 4x4 numpy matrix.

Parameters:transform – 4x4 transformation matrix.
Raises:TypeError, ValueError
multiply_point(name, points)[source]

Multiplies points (4xN) by the named transform (4x4).

Returns:ndarray – 4xN matrix of transformed points
Raises:ValueError
remove(name)[source]

Removes a transform from the manager. If the transform name doesn’t exist, will throw ValueError.

Raises:ValueError