pytransform3d.transform_manager.TransformManager

class pytransform3d.transform_manager.TransformManager(strict_check=True, check=True)[source]

Bases: object

Manage transformations between frames.

This is a simplified version of ROS tf that ignores the temporal aspect. A user can register transformations. The shortest path between all frames will be computed internally which enables us to provide transforms for any connected frames.

Suppose we know the transformations A2B, D2C, and B2C. The transform manager can compute any transformation between the frames A, B, C and D. For example, you can request the transformation that represents frame D in frame A. The transformation manager will automatically concatenate the transformations D2C, C2B, and B2A, where C2B and B2A are obtained by inverting B2C and A2B respectively.

Warning

It is possible to introduce inconsistencies in the transformation manager. Adding A2B and B2A with inconsistent values will result in an invalid state because inconsistencies will not be checked. It seems to be trivial in this simple case but can be computationally complex for large graphs. You can check the consistency explicitly with TransformManager.check_consistency().

Parameters
strict_checkbool, optional (default: True)

Raise a ValueError if the transformation matrix is not numerically close enough to a real transformation matrix. Otherwise we print a warning.

checkbool, optional (default: True)

Check if transformation matrices are valid and requested nodes exist, which might significantly slow down some operations.

__init__(strict_check=True, check=True)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__([strict_check, check])

Initialize self.

add_transform(from_frame, to_frame, A2B)

Register a transformation.

check_consistency()

Check consistency of the known transformations.

connected_components()

Get number of connected components.

get_transform(from_frame, to_frame)

Request a transformation.

has_frame(frame)

Check if frame has been registered.

plot_connections_in(frame[, ax, ax_s, whitelist])

Plot direct frame connections in a given reference frame.

plot_frames_in(frame[, ax, s, ax_s, …])

Plot all frames in a given reference frame.

remove_transform(from_frame, to_frame)

Remove a transformation.

write_png(filename[, prog])

Create PNG from dot graph of the transformations.

add_transform(from_frame, to_frame, A2B)[source]

Register a transformation.

Parameters
from_frameHashable

Name of the frame for which the transformation is added in the to_frame coordinate system

to_frameHashable

Name of the frame in which the transformation is defined

A2Barray-like, shape (4, 4)

Homogeneous matrix that represents the transformation from ‘from_frame’ to ‘to_frame’

Returns
selfTransformManager

This object for chaining

remove_transform(from_frame, to_frame)[source]

Remove a transformation.

Nothing happens if there is no such transformation.

Parameters
from_frameHashable

Name of the frame for which the transformation is added in the to_frame coordinate system

to_frameHashable

Name of the frame in which the transformation is defined

Returns
selfTransformManager

This object for chaining

has_frame(frame)[source]

Check if frame has been registered.

Parameters
frameHashable

Frame name

Returns
has_framebool

Frame is registered

get_transform(from_frame, to_frame)[source]

Request a transformation.

Parameters
from_frameHashable

Name of the frame for which the transformation is requested in the to_frame coordinate system

to_frameHashable

Name of the frame in which the transformation is defined

Returns
A2Barray-like, shape (4, 4)

Homogeneous matrix that represents the transformation from ‘from_frame’ to ‘to_frame’

Raises
KeyError

If one of the frames is unknown or there is no connection between them

plot_frames_in(frame, ax=None, s=1.0, ax_s=1, show_name=True, whitelist=None, **kwargs)[source]

Plot all frames in a given reference frame.

Note that frames that cannot be connected to the reference frame are omitted.

Parameters
frameHashable

Reference frame

axMatplotlib 3d axis, optional (default: None)

If the axis is None, a new 3d axis will be created

sfloat, optional (default: 1)

Scaling of the frame that will be drawn

ax_sfloat, optional (default: 1)

Scaling of the new matplotlib 3d axis

show_namebool, optional (default: True)

Print node names

whitelistlist, optional (default: None)

Frames that must be plotted

kwargsdict, optional (default: {})

Additional arguments for the plotting functions, e.g. alpha

Returns
axMatplotlib 3d axis

New or old axis

Raises
KeyError

If the frame is unknown

plot_connections_in(frame, ax=None, ax_s=1, whitelist=None, **kwargs)[source]

Plot direct frame connections in a given reference frame.

A line between each pair of frames for which a direct transformation is known will be plotted. Direct means that either A2B or B2A has been added to the transformation manager.

Note that frames that cannot be connected to the reference frame are omitted.

Parameters
frameHashable

Reference frame

axMatplotlib 3d axis, optional (default: None)

If the axis is None, a new 3d axis will be created

ax_sfloat, optional (default: 1)

Scaling of the new matplotlib 3d axis

whitelistlist, optional (default: None)

Both frames of a connection must be in the whitelist to plot the connection

kwargsdict, optional (default: {})

Additional arguments for the plotting functions, e.g. alpha

Returns
axMatplotlib 3d axis

New or old axis

Raises
KeyError

If the frame is unknown

check_consistency()[source]

Check consistency of the known transformations.

The complexity of this is between O(n^2) and O(n^3), where n is the number of nodes. In graphs where each pair of nodes is directly connected the complexity is O(n^2). In graphs that are actually paths, the complexity is O(n^3).

Returns
consistentbool

Is the graph consistent, i.e. is A2B always the same as the inverse of B2A?

connected_components()[source]

Get number of connected components.

If the number is larger than 1 there will be frames without connections.

Returns
n_connected_componentsint

Number of connected components.

write_png(filename, prog=None)[source]

Create PNG from dot graph of the transformations.

Warning

Note that this method requires the Python package pydot and an existing installation of graphviz on your system.

Parameters
filenamestr

Name of the output file. Should end with ‘.png’.

progstr, optional (default: dot)

Name of GraphViz executable that can be found in the $PATH or absolute path to GraphViz executable. Possible options are, for example, ‘dot’, ‘twopi’, ‘neato’, ‘circo’, ‘fdp’, ‘sfdp’.

Raises
ImportError

If pydot is not available