(
spatial_dims: int,
radians: Sequence[float] | float,
sin_func: Callable = np.sin,
cos_func: Callable = np.cos,
eye_func: Callable = np.eye,
)
| 898 | |
| 899 | |
| 900 | def _create_rotate( |
| 901 | spatial_dims: int, |
| 902 | radians: Sequence[float] | float, |
| 903 | sin_func: Callable = np.sin, |
| 904 | cos_func: Callable = np.cos, |
| 905 | eye_func: Callable = np.eye, |
| 906 | ) -> NdarrayOrTensor: |
| 907 | radians = ensure_tuple(radians) |
| 908 | if spatial_dims == 2: |
| 909 | if len(radians) >= 1: |
| 910 | sin_, cos_ = sin_func(radians[0]), cos_func(radians[0]) |
| 911 | out = eye_func(3) |
| 912 | out[0, 0], out[0, 1] = cos_, -sin_ |
| 913 | out[1, 0], out[1, 1] = sin_, cos_ |
| 914 | return out # type: ignore |
| 915 | raise ValueError("radians must be non empty.") |
| 916 | |
| 917 | if spatial_dims == 3: |
| 918 | affine = None |
| 919 | if len(radians) >= 1: |
| 920 | sin_, cos_ = sin_func(radians[0]), cos_func(radians[0]) |
| 921 | affine = eye_func(4) |
| 922 | affine[1, 1], affine[1, 2] = cos_, -sin_ |
| 923 | affine[2, 1], affine[2, 2] = sin_, cos_ |
| 924 | if len(radians) >= 2: |
| 925 | sin_, cos_ = sin_func(radians[1]), cos_func(radians[1]) |
| 926 | if affine is None: |
| 927 | raise ValueError("Affine should be a matrix.") |
| 928 | _affine = eye_func(4) |
| 929 | _affine[0, 0], _affine[0, 2] = cos_, sin_ |
| 930 | _affine[2, 0], _affine[2, 2] = -sin_, cos_ |
| 931 | affine = affine @ _affine |
| 932 | if len(radians) >= 3: |
| 933 | sin_, cos_ = sin_func(radians[2]), cos_func(radians[2]) |
| 934 | if affine is None: |
| 935 | raise ValueError("Affine should be a matrix.") |
| 936 | _affine = eye_func(4) |
| 937 | _affine[0, 0], _affine[0, 1] = cos_, -sin_ |
| 938 | _affine[1, 0], _affine[1, 1] = sin_, cos_ |
| 939 | affine = affine @ _affine |
| 940 | if affine is None: |
| 941 | raise ValueError("radians must be non empty.") |
| 942 | return affine # type: ignore |
| 943 | |
| 944 | raise ValueError(f"Unsupported spatial_dims: {spatial_dims}, available options are [2, 3].") |
| 945 | |
| 946 | |
| 947 | def create_shear( |
no test coverage detected
searching dependent graphs…