Skip to content

Commit b68a9d5

Browse files
authored
Add option to return Euler angles in degrees (#365)
* Add option to return euler angles in degrees * Bump version
1 parent 8182b85 commit b68a9d5

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

diffdrr/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.4.8"
1+
__version__ = "0.4.9"

diffdrr/pose.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ def compose(self, T):
5454
matrix = torch.einsum("bij, bjk -> bik", T.matrix, self.matrix)
5555
return RigidTransform(matrix)
5656

57-
def convert(self, parameterization, convention=None):
57+
def convert(self, parameterization, convention=None, degrees=False):
5858
translation = -self.inverse().translation
5959
if parameterization == "axis_angle":
6060
rotation = matrix_to_axis_angle(self.matrix[..., :3, :3])
6161
elif parameterization == "euler_angles":
6262
rotation = matrix_to_euler_angles(self.matrix[..., :3, :3], convention)
63+
if degrees:
64+
rotation = rotation / torch.pi * 180
6365
elif parameterization == "matrix":
6466
rotation = self.matrix[..., :3, :3]
6567
elif parameterization == "quaternion":
@@ -119,7 +121,7 @@ def random_rigid_transform(batch_size=1):
119121
]
120122

121123
# %% ../notebooks/api/06_pose.ipynb 11
122-
def convert(*args, parameterization, convention=None) -> RigidTransform:
124+
def convert(*args, parameterization, convention=None, degrees=False) -> RigidTransform:
123125
if parameterization == "euler_angles" and convention is None:
124126
raise ValueError(
125127
"convention for Euler angles must be specified as a 3 letter combination of [X, Y, Z]"
@@ -132,6 +134,8 @@ def convert(*args, parameterization, convention=None) -> RigidTransform:
132134
matrix = make_matrix(rotmat, camera_center)
133135
elif parameterization == "euler_angles":
134136
rotation, translation = args
137+
if degrees:
138+
rotation = rotation / 180 * torch.pi
135139
rotmat = euler_angles_to_matrix(rotation, convention)
136140
camera_center = torch.einsum("bij, bj -> bi", rotmat, translation)
137141
matrix = make_matrix(rotmat, camera_center)

notebooks/api/06_pose.ipynb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,14 @@
138138
" matrix = torch.einsum(\"bij, bjk -> bik\", T.matrix, self.matrix)\n",
139139
" return RigidTransform(matrix)\n",
140140
"\n",
141-
" def convert(self, parameterization, convention=None):\n",
141+
" def convert(self, parameterization, convention=None, degrees=False):\n",
142142
" translation = -self.inverse().translation\n",
143143
" if parameterization == \"axis_angle\":\n",
144144
" rotation = matrix_to_axis_angle(self.matrix[..., :3, :3])\n",
145145
" elif parameterization == \"euler_angles\":\n",
146146
" rotation = matrix_to_euler_angles(self.matrix[..., :3, :3], convention)\n",
147+
" if degrees:\n",
148+
" rotation = rotation / torch.pi * 180\n",
147149
" elif parameterization == \"matrix\":\n",
148150
" rotation = self.matrix[..., :3, :3]\n",
149151
" elif parameterization == \"quaternion\":\n",
@@ -243,7 +245,7 @@
243245
"outputs": [],
244246
"source": [
245247
"#| export\n",
246-
"def convert(*args, parameterization, convention=None) -> RigidTransform:\n",
248+
"def convert(*args, parameterization, convention=None, degrees=False) -> RigidTransform:\n",
247249
" if parameterization == \"euler_angles\" and convention is None:\n",
248250
" raise ValueError(\n",
249251
" \"convention for Euler angles must be specified as a 3 letter combination of [X, Y, Z]\"\n",
@@ -256,6 +258,8 @@
256258
" matrix = make_matrix(rotmat, camera_center)\n",
257259
" elif parameterization == \"euler_angles\":\n",
258260
" rotation, translation = args\n",
261+
" if degrees:\n",
262+
" rotation = rotation / 180 * torch.pi\n",
259263
" rotmat = euler_angles_to_matrix(rotation, convention)\n",
260264
" camera_center = torch.einsum(\"bij, bj -> bi\", rotmat, translation)\n",
261265
" matrix = make_matrix(rotmat, camera_center)\n",

settings.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[DEFAULT]
22
repo = DiffDRR
33
lib_name = diffdrr
4-
version = 0.4.8
4+
version = 0.4.9
55
min_python = 3.8
66
license = mit
77
black_formatting = True

0 commit comments

Comments
 (0)