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 054850802f2e6889c4160535a71d512fcba22513
72 changes: 67 additions & 5 deletions theseus/geometry/se3.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,26 +284,88 @@ def vee(matrix: torch.Tensor) -> torch.Tensor:
SE3._hat_matrix_check(matrix)
return torch.cat((matrix[:, :3, 3], SO3.vee(matrix[:, :3, :3])), dim=1)

def _transform_shape_check(self, point: Union[Point3, torch.Tensor]):
raise NotImplementedError

def _copy_impl(self, new_name: Optional[str] = None) -> "SE3":
return SE3(data=self.data.clone(), name=new_name)

# only added to avoid casting downstream
def copy(self, new_name: Optional[str] = None) -> "SE3":
return cast(SE3, super().copy(new_name=new_name))

def _transform_shape_check(self, point: Union[Point3, torch.Tensor]):
err_msg = "SE3 can only transform 3-D vectors."
if isinstance(point, torch.Tensor):
if not point.ndim == 2 or point.shape[1] != 3:
raise ValueError(err_msg)
elif point.dof() != 3:
raise ValueError(err_msg)
if (
point.shape[0] != self.shape[0]
and point.shape[0] != 1
and self.shape[0] != 1
):
raise ValueError(
"Input point batch size is not broadcastable with group batch size."
)

def transform_to(
self,
point: Union[Point3, torch.Tensor],
jacobians: Optional[List[torch.Tensor]] = None,
) -> Point3:
raise NotImplementedError
self._transform_shape_check(point)
batch_size = max(self.shape[0], point.shape[0])
if isinstance(point, torch.Tensor):
p = point.view(-1, 3, 1)
else:
p = point.data.view(-1, 3, 1)

ret = Point3(data=(self[:, :, :3] @ p).view(-1, 3))
ret[:, 3:] += 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[:, :, :3] = self[:, :, :3]
Jg[:, :, 3:] = -self[:, :, :3] @ SO3.hat(p)
# Jacobians for point
Jpnt = Jg[:, :, :3]

jacobians.extend([Jg, Jpnt])

return ret

def transform_from(
self,
point: Union[Point3, torch.Tensor],
jacobians: Optional[List[torch.Tensor]] = None,
) -> Point3:
raise NotImplementedError
self._transform_shape_check(point)
batch_size = max(self.shape[0], point.shape[0])
if isinstance(point, torch.Tensor):
p = point.view(-1, 3, 1)
else:
p = point.data.view(-1, 3, 1)

temp = p - self[:, :, 3:]
ret = Point3(data=(self[:, :, :3].transpose(1, 2) @ temp).view(-1, 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[:, 0, 0] = -1
Jg[:, 1, 1] = -1
Jg[:, 2, 2] = -1
Jg[:, 0, 4] = -ret[:, 2]
Jg[:, 1, 3] = ret[:, 2]
Jg[:, 0, 5] = ret[:, 1]
Jg[:, 2, 3] = -ret[:, 1]
Jg[:, 1, 5] = -ret[:, 0]
Jg[:, 2, 4] = ret[:, 0]
# Jacobians for point
Jpnt = self[:, :, :3].transpose(1, 2).expand(batch_size, 3, 3)

jacobians.extend([Jg, Jpnt])

return ret
4 changes: 2 additions & 2 deletions theseus/geometry/so3.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def rotate(
ret = Point3(data=(self.data @ p).view(-1, 3))
if jacobians is not None:
self._check_jacobians_list(jacobians)
# Jacobians for SO3: left-invariant jacobians are computed
# Right jacobians for SO(3) are computed
Jrot = -self.data @ SO3.hat(p)
# Jacobians for point
Jpnt = self.to_matrix().expand(batch_size, 3, 3)
Expand All @@ -323,7 +323,7 @@ def unrotate(
ret = Point3(data=(self.data.transpose(1, 2) @ p).view(-1, 3))
if jacobians is not None:
self._check_jacobians_list(jacobians)
# Jacobians for SO3: left-invariant jacobians are computed
# Left jacobians for SO3 are computed
Jrot = torch.zeros(batch_size, 3, 3, dtype=self.dtype, device=self.device)
Jrot[:, 0, 1] = -ret[:, 2]
Jrot[:, 1, 0] = ret[:, 2]
Expand Down