Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SE3.transform_from and SE3.transform_to #80

Merged
merged 23 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7fa60c5
add SE3 defintions
fantaosha Feb 1, 2022
67e77b4
add initialization method
fantaosha Feb 1, 2022
e72ab40
modify test_so3.check_SO3_to_quaternion to handle cases near pi
fantaosha Feb 2, 2022
fe05db4
add SE3.hat and SE.vee
fantaosha Feb 2, 2022
1ae2dea
add SE3.adjoint
fantaosha Feb 2, 2022
f8cf872
add SE3.adjoint, vee and hat
fantaosha Feb 2, 2022
e5de005
backup before switching to taoshaf.add_SE3
fantaosha Feb 2, 2022
23292d4
add support for single x_y_z_quaternion
fantaosha Feb 2, 2022
b4c1738
modify SO3
fantaosha Feb 2, 2022
ae9e845
Remove repeated if in SE3 construction
fantaosha Feb 2, 2022
19d787d
SE3.exp added but not tested
fantaosha Feb 2, 2022
8a6f88e
add SE3.log_map()
fantaosha Feb 2, 2022
87c5f82
SE3.exp_map() and SE3.log_map() are tested
fantaosha Feb 2, 2022
2c1b729
add SE3.compose()
fantaosha Feb 2, 2022
107c55e
simplify test_se3.py
fantaosha Feb 2, 2022
2486e54
Merge branch 'taoshaf.add_se3.exp_and_log' into taoshaf.add_se3_compose
fantaosha Feb 2, 2022
3a65b2e
modify test_se3.py
fantaosha Feb 3, 2022
0548508
add SE3.transform_from and SE3.transform_to
fantaosha Feb 3, 2022
19419f8
add SE3.transform_from and SE3.transform_to
fantaosha Feb 3, 2022
e4abe1b
change err_msgs for SO3._rotate_shape_check and SE3._rotate_shape_check
fantaosha Feb 10, 2022
6c71afc
change error message for SO3._rotate_shape_check and SE3._transform_s…
fantaosha Feb 10, 2022
01db55e
update err_msg for shape_check
fantaosha Feb 10, 2022
95c9b41
Merge branch 'main' into taoshaf.add_SE3.transfrom
fantaosha Feb 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add SE3.transform_from and SE3.transform_to
  • Loading branch information
fantaosha committed Feb 3, 2022
commit 19419f89450903b995900d992ac7bf10dfff6d6f
6 changes: 3 additions & 3 deletions theseus/geometry/se3.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@ def transform_to(
p = point.data.view(-1, 3, 1)

ret = Point3(data=(self[:, :, :3] @ p).view(-1, 3))
ret[:, 3:] += self[:, :, 3:]
ret += self[:, :, 3]

if jacobians is not None:
self._check_jacobians_list(jacobians)
# Right jacobians for SE(3) are computed
Jg = torch.zeros(batch_size, 3, 6)
Jg = torch.zeros(batch_size, 3, 6, dtype=self.dtype, device=self.device)
Jg[:, :, :3] = self[:, :, :3]
Jg[:, :, 3:] = -self[:, :, :3] @ SO3.hat(p)
# Jacobians for point
Expand Down Expand Up @@ -353,7 +353,7 @@ def transform_from(
if jacobians is not None:
self._check_jacobians_list(jacobians)
# Right jacobians for SE(3) are computed
Jg = torch.zeros(batch_size, 3, 6)
Jg = torch.zeros(batch_size, 3, 6, dtype=self.dtype, device=self.device)
Jg[:, 0, 0] = -1
Jg[:, 1, 1] = -1
Jg[:, 2, 2] = -1
Expand Down
40 changes: 40 additions & 0 deletions theseus/geometry/tests/test_se3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import theseus as th
from theseus.constants import EPS
from theseus.utils import numeric_jacobian

from .common import check_adjoint, check_compose, check_exp_map, check_inverse

Expand Down Expand Up @@ -145,3 +146,42 @@ def test_adjoint():
se3 = _create_random_se3(batch_size, rng)
tangent = torch.randn(batch_size, 6).double()
check_adjoint(se3, tangent)


def test_transform_from_and_to():
rng = torch.Generator()
rng.manual_seed(0)
for _ in range(10): # repeat a few times
for batch_size in [1, 20, 100]:
se3 = _create_random_se3(batch_size, rng)
point_tensor = torch.randn(batch_size, 3).double()
point_tensor_ext = torch.cat(
(point_tensor, torch.ones(batch_size, 1).double()), dim=1
)

jacobians_to = []
point_to = se3.transform_to(point_tensor, jacobians=jacobians_to)
expected_to = (se3.to_matrix() @ point_tensor_ext.unsqueeze(2))[:, :3]
jacobians_from = []
point_from = se3.transform_from(point_to, jacobians_from)

# Check the operation result
assert torch.allclose(expected_to.squeeze(2), point_to.data, atol=EPS)
assert torch.allclose(point_tensor, point_from.data, atol=EPS)

# Check the jacobians
expected_jac = numeric_jacobian(
lambda groups: groups[0].transform_to(groups[1]),
[se3, th.Point3(point_tensor)],
function_dim=3,
)
assert torch.allclose(jacobians_to[0], expected_jac[0])
assert torch.allclose(jacobians_to[1], expected_jac[1])
expected_jac = numeric_jacobian(
lambda groups: groups[0].transform_from(groups[1]),
[se3, point_to],
delta_mag=1e-5,
function_dim=3,
)
assert torch.allclose(jacobians_from[0], expected_jac[0])
assert torch.allclose(jacobians_from[1], expected_jac[1])