1
1
# AUTOGENERATED! DO NOT EDIT! File to edit: ../notebooks/api/06_pose.ipynb.
2
2
3
3
# %% auto 0
4
- __all__ = ['RigidTransform' , 'make_matrix' , ' convert' , 'rotation_10d_to_quaternion' , 'quaternion_to_rotation_10d' ,
4
+ __all__ = ['RigidTransform' , 'convert' , 'rotation_10d_to_quaternion' , 'quaternion_to_rotation_10d' ,
5
5
'quaternion_adjugate_to_quaternion' , 'quaternion_to_quaternion_adjugate' ]
6
6
7
7
# %% ../notebooks/api/06_pose.ipynb 4
@@ -44,10 +44,37 @@ def compose(self, T):
44
44
matrix = torch .einsum ("bij, bjk -> bik" , T .matrix , self .matrix )
45
45
return RigidTransform (matrix )
46
46
47
- def get_se3_log (self ):
48
- return se3_log_map (self .matrix .mT )
47
+ def convert (self , parameterization , convention = None ):
48
+ translation = T .matrix [..., :3 , 3 ]
49
+ if parameterization == "axis_angle" :
50
+ rotation = matrix_to_axis_angle (T .matrix [..., :3 , :3 ])
51
+ elif parameterization == "euler_angles" :
52
+ rotation = matrix_to_euler_angles (T .matrix [..., :3 , :3 ], convention )
53
+ elif parameterization == "matrix" :
54
+ rotation = T .matrix [..., :3 , :3 ]
55
+ elif parameterization == "quaternion" :
56
+ rotation = matrix_to_quaternion (T .matrix [..., :3 , :3 ])
57
+ elif parameterization == "quaternion_adjugate" :
58
+ quaternion = matrix_to_quaternion (T .matrix [..., :3 , :3 ])
59
+ rotation = quaternion_to_quaternion_adjugate (quaternion )
60
+ elif parameterization == "rotation_6d" :
61
+ rotation = matrix_to_rotation_6d (T .matrix [..., :3 , :3 ])
62
+ elif parameterization == "rotation_10d" :
63
+ quaternion = matrix_to_quaternion (T .matrix [..., :3 , :3 ])
64
+ rotation = quaternion_to_rotation_10d (quaternion )
65
+ elif parameterization == "se3_log_map" :
66
+ rotation , translation = self .get_se3_log ()
67
+ else :
68
+ raise ValueError (f"Must be in { PARAMETERIZATIONS } , not { parameterization } " )
69
+ return rotation , translation
49
70
71
+ def get_se3_log (self ):
72
+ params = se3_log_map (self .matrix .mT )
73
+ rotation = params [..., 3 :]
74
+ translation = params [..., :3 ]
75
+ return rotation , translation
50
76
77
+ # %% ../notebooks/api/06_pose.ipynb 5
51
78
def make_matrix (R , t ):
52
79
assert (batch_size := len (R )) == len (t )
53
80
matrix = torch .zeros (batch_size , 4 , 4 ).to (R )
@@ -56,17 +83,17 @@ def make_matrix(R, t):
56
83
matrix [..., - 1 , - 1 ] = 1.0
57
84
return matrix
58
85
59
- # %% ../notebooks/api/06_pose.ipynb 5
86
+ # %% ../notebooks/api/06_pose.ipynb 6
60
87
from scipy .spatial .transform import Rotation
61
88
62
89
63
- def random_rigid_transform (batch_size ):
90
+ def random_rigid_transform (batch_size = 1 ):
64
91
"""Helper function for testing implementations."""
65
92
R = torch .from_numpy (Rotation .random (batch_size ).as_matrix ()).to (torch .float32 )
66
93
t = 100 * torch .randn ((batch_size , 3 ))
67
94
return RigidTransform (make_matrix (R , t ))
68
95
69
- # %% ../notebooks/api/06_pose.ipynb 7
96
+ # %% ../notebooks/api/06_pose.ipynb 8
70
97
PARAMETERIZATIONS = [
71
98
"axis_angle" ,
72
99
"euler_angles" ,
@@ -78,7 +105,7 @@ def random_rigid_transform(batch_size):
78
105
"se3_log_map" ,
79
106
]
80
107
81
- # %% ../notebooks/api/06_pose.ipynb 8
108
+ # %% ../notebooks/api/06_pose.ipynb 9
82
109
def convert (* args , parameterization , convention = None ) -> RigidTransform :
83
110
if parameterization == "euler_angles" and convention is None :
84
111
raise ValueError (
@@ -119,7 +146,7 @@ def convert(*args, parameterization, convention=None) -> RigidTransform:
119
146
120
147
return convert (matrix , parameterization = "matrix" )
121
148
122
- # %% ../notebooks/api/06_pose.ipynb 10
149
+ # %% ../notebooks/api/06_pose.ipynb 11
123
150
def _10vec_to_4x4symmetric (vec ):
124
151
"""Convert a 10-vector to a symmetric 4x4 matrix."""
125
152
b = len (vec )
@@ -129,7 +156,7 @@ def _10vec_to_4x4symmetric(vec):
129
156
A [..., jdx , idx ] = vec
130
157
return A
131
158
132
- # %% ../notebooks/api/06_pose.ipynb 11
159
+ # %% ../notebooks/api/06_pose.ipynb 12
133
160
def rotation_10d_to_quaternion (rotation : torch .Tensor ) -> torch .Tensor :
134
161
"""
135
162
Convert a 10-vector into a symmetric matrix, whose eigenvector corresponding
@@ -146,7 +173,7 @@ def quaternion_to_rotation_10d(q: torch.Tensor) -> torch.Tensor:
146
173
idx , jdx = torch .triu_indices (4 , 4 )
147
174
return A [..., idx , jdx ]
148
175
149
- # %% ../notebooks/api/06_pose.ipynb 12
176
+ # %% ../notebooks/api/06_pose.ipynb 13
150
177
def quaternion_adjugate_to_quaternion (rotation : torch .Tensor ) -> torch .Tensor :
151
178
"""
152
179
Convert a 10-vector in the quaternion adjugate, a symmetric matrix whose
@@ -167,7 +194,7 @@ def quaternion_to_quaternion_adjugate(q: torch.Tensor) -> torch.Tensor:
167
194
idx , jdx = torch .triu_indices (4 , 4 )
168
195
return A [..., idx , jdx ]
169
196
170
- # %% ../notebooks/api/06_pose.ipynb 15
197
+ # %% ../notebooks/api/06_pose.ipynb 16
171
198
# pytorch3d/transforms/rotation_conversions.py
172
199
173
200
from typing import Optional , Union
@@ -700,7 +727,7 @@ def matrix_to_rotation_6d(matrix: torch.Tensor) -> torch.Tensor:
700
727
batch_dim = matrix .size ()[:- 2 ]
701
728
return matrix [..., :2 , :].clone ().reshape (batch_dim + (6 ,))
702
729
703
- # %% ../notebooks/api/06_pose.ipynb 16
730
+ # %% ../notebooks/api/06_pose.ipynb 17
704
731
# pytorch3d/transforms/math.py
705
732
from typing import Tuple
706
733
@@ -778,7 +805,7 @@ def _dacos_dx(x: float) -> float:
778
805
"""
779
806
return (- 1.0 ) / math .sqrt (1.0 - x * x )
780
807
781
- # %% ../notebooks/api/06_pose.ipynb 17
808
+ # %% ../notebooks/api/06_pose.ipynb 18
782
809
# pytorch3d/transforms/so3.py
783
810
784
811
import warnings
@@ -1038,7 +1065,7 @@ def hat(v: torch.Tensor) -> torch.Tensor:
1038
1065
1039
1066
return h
1040
1067
1041
- # %% ../notebooks/api/06_pose.ipynb 18
1068
+ # %% ../notebooks/api/06_pose.ipynb 19
1042
1069
# pytorch3d/transforms/se3.py
1043
1070
1044
1071
0 commit comments