RandomRotateTargetAngle#

class RandomRotateTargetAngle(angle=(0.5, 1, 1.5), center=None, axis='z', always_apply=False, p=0.75)[source]#

Bases: object

Rotate the cloud by a random angle drawn from a discrete set.

Like RandomRotate, but the angle is chosen uniformly from the discrete angle set (in units of pi radians) rather than a continuous range – useful for snapping to canonical orientations (e.g. quarter/half turns). With probability p (forced to 1 when always_apply), rotates coord about axis around center in place, and applies the same rotation to v3 vertex metadata, aux_position_keys, normal, and (linear part, re-normalized) aux_direction_keys. When center is None the bounding-box center is used. Requires coord. Registered as RandomRotateTargetAngle – use this string as the type in a transform=[...] config list.

Parameters:
  • angle (Sequence[float]) – discrete set of angles, in units of pi radians, to choose from. Defaults to (1/2, 1, 3/2) (90, 180, 270 degrees).

  • center (Sequence[float], optional) – rotation center. None uses the per-sample bounding-box center. Defaults to None.

  • axis (str) – rotation axis, one of "x", "y", "z". Defaults to "z".

  • always_apply (bool) – if True, always rotate (overrides p to 1). Defaults to False.

  • p (float) – probability of applying the rotation when not always_apply. Defaults to 0.75.

Example

>>> import numpy as np
>>> from pimm.datasets.transform import RandomRotateTargetAngle
>>> data = {"coord": np.array([[1., 0., 0.], [0., 1., 0.]], dtype="f4")}
>>> # single-element angle set -> deterministic 1*pi (180 deg) about z
>>> out = RandomRotateTargetAngle(angle=(1.0,), axis="z", center=[0, 0, 0],
...                               always_apply=True)(data)
>>> np.round(out["coord"], 3)  # 180 deg flips x and y signs
array([[-1.,  0.,  0.],
       [-0., -1.,  0.]])