NaviNIBS.util.Transforms module¶
- NaviNIBS.util.Transforms.decomposeTransform(A2B)[source]¶
Extract translation and rotation components from transform. Assume the transform is rigid. :rtype:
tuple
[ndarray
,ndarray
] :return: (3x3 rotation matrix, 3-elem translation vector)
- NaviNIBS.util.Transforms.applyTransform(A2B, pts, doCheck=True, doStrictCheck=True)[source]¶
Apply 4x4 transform(s) to a set of points :type A2B:
Union
[ndarray
,Iterable
[ndarray
]] :param A2B: single 4x4 transform, or iterable of 4x4 transforms. If multiple, will apply in reversed order, so thatapplyTransform([space1ToSpace2Transf, space2TransfToSpace3Transf], pts) correctly transforms from space1 to space3 as might be expected with space2TransfToSpace3Transf @ space1ToSpace2Transf @ augmentedPts
- Parameters:
pts (
ndarray
) – Nx3 points. Or can be in shape (3,) and will return transformed points with same shape.- Param:
doCheck: whether to check that transform is valid
- Param:
doStrictCheck: whether raise error if transform is not valid
- Return type:
ndarray
- Returns:
transformed points
- NaviNIBS.util.Transforms.applyDirectionTransform(A2B, dirs, doCheck=True, doStrictCheck=True)[source]¶
- Return type:
ndarray
- NaviNIBS.util.Transforms.concatenateTransforms(A2B)[source]¶
Combine transforms in reverse order, using same ordering convention as applyTransform, such that applyTransform(concatenateTransforms([space1ToSpace2Transf, space2TransfToSpace3Transf]), pts) correctly transforms from space1 to space3 as might be expected with space2TransfToSpace3Transf @ space1ToSpace2Transf @ augmentedPts
- Return type:
ndarray
- NaviNIBS.util.Transforms.stringToTransform(inputStr)[source]¶
Raises ValueError if unable to convert to valid transform :type inputStr:
str
:param inputStr: str representation of a transform, e.g. fromtransformToString(np.asarray([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]))
- Return type:
ndarray
- Returns:
transform as 4x4 ndarray
- NaviNIBS.util.Transforms.calculateRotationMatrixFromTwoVectors(vecA, vecB)[source]¶
Calculate rotation such that X-axis points in direction of vecA, Y-axis points in direction of (oproj_vecA vecB) adapted from https://rock-learning.github.io/pytransform3d/_apidoc/pytransform3d.rotations.matrix_from_two_vectors.html
- Parameters:
vecA (
ndarray
)vecB (
ndarray
)
- Return type:
ndarray
- Returns:
3x3 rotation matrix
- NaviNIBS.util.Transforms.calculateRotationMatrixFromVectorToVector(vecA, vecB)[source]¶
Calculate rotation that would rotate vecA to vecB
- Return type:
ndarray
- NaviNIBS.util.Transforms.estimateAligningTransform(ptsA, ptsB, method='kabsch-svd', weights=None)[source]¶
Estimate a transform that aligns one set of points onto another.
Some methods assume row-wise matching of points between sets.
- For details of the kabsch-svd method, see:
- Parameters:
ptsA (
ndarray
) – Nx3 ndarray of pointsptsB (
ndarray
) – Mx3 ndarray of pointsmethod (
str
) – method to use for estimating transform. Default is ‘kabsch-svd’’weights (
Optional
[ndarray
]) –default None, otherwise format depends on method: if method == ‘kabsch-svd’:
Kabsch weighted algorithm will be used. Weights should be of length equal to number of points in ptsA and ptsB.
- elif method == ‘ICP’:
Weights should be of length 6, with values as defined by simpleicp’s rbp_observation_weights argument.
- Return type:
ndarray
- Returns:
A2B, 4x4 transform aligning ptsA to ptsB