RandomRotateTargetAngle#
- class RandomRotateTargetAngle(angle=(0.5, 1, 1.5), center=None, axis='z', always_apply=False, p=0.75)[source]#
Bases:
objectRotate the cloud by a random angle drawn from a discrete set.
Like
RandomRotate, but the angle is chosen uniformly from the discreteangleset (in units of pi radians) rather than a continuous range – useful for snapping to canonical orientations (e.g. quarter/half turns). With probabilityp(forced to 1 whenalways_apply), rotatescoordaboutaxisaroundcenterin place, and applies the same rotation to v3vertexmetadata,aux_position_keys,normal, and (linear part, re-normalized)aux_direction_keys. WhencenterisNonethe bounding-box center is used. Requirescoord. Registered asRandomRotateTargetAngle– use this string as thetypein atransform=[...]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.
Noneuses the per-sample bounding-box center. Defaults toNone.axis (str) – rotation axis, one of
"x","y","z". Defaults to"z".always_apply (bool) – if
True, always rotate (overridespto 1). Defaults toFalse.p (float) – probability of applying the rotation when not
always_apply. Defaults to0.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.]])