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 support for single x_y_z_quaternion
  • Loading branch information
fantaosha committed Feb 2, 2022
commit 23292d4709f05a401af7061eb2dc0c0e6f94bf01
40 changes: 21 additions & 19 deletions theseus/geometry/se3.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ def __init__(
super().__init__(data=data, name=name, dtype=dtype)
if x_y_z_quaternion is not None:
if x_y_z_quaternion is not None:
if x_y_z_quaternion.ndim == 1:
x_y_z_quaternion = x_y_z_quaternion.unsqueeze(0)
self.update_from_x_y_z_quaternion(x_y_z_quaternion=x_y_z_quaternion)

@staticmethod
Expand Down Expand Up @@ -64,6 +62,25 @@ def _SE3_matrix_check(matrix: torch.Tensor):
raise ValueError("SE(3) can only be 3x4 matrices.")
SO3._SO3_matrix_check(matrix.data[:, :3, :3])

@staticmethod
def x_y_z_unit_quaternion_to_SE3(x_y_z_quaternion: torch.Tensor) -> "SE3":
if x_y_z_quaternion.ndim == 1:
x_y_z_quaternion = x_y_z_quaternion.unsqueeze(0)

if x_y_z_quaternion.ndim != 2 and x_y_z_quaternion.shape[1] != 7:
raise ValueError("x_y_z_quaternion can only be 7-D vectors.")

ret = SE3()

batch_size = x_y_z_quaternion.shape[0]
ret.data = torch.empty(batch_size, 3, 4).to(
device=x_y_z_quaternion.device, dtype=x_y_z_quaternion.dtype
)
ret[:, :3, :3] = SO3.unit_quaternion_to_SO3(x_y_z_quaternion[:, 3:]).data
ret[:, :3, 3] = x_y_z_quaternion[:, :3]

return ret

@staticmethod
def _hat_matrix_check(matrix: torch.Tensor):
if matrix.ndim != 3 or matrix.shape[1:] != (4, 4):
Expand All @@ -81,15 +98,8 @@ def _hat_matrix_check(matrix: torch.Tensor):

@staticmethod
def exp_map(tangent_vector: torch.Tensor) -> LieGroup:
if tangent_vector.ndim != 2 or tangent_vector.shape[1] != 6:
raise ValueError("The tangent vectors can only be 6-D vectors.")
ret = SE3(dtype=tangent_vector.dtype)

# TODO: Not Implemented yet
raise NotImplementedError

return ret

def _log_map_impl(self) -> torch.Tensor:
raise NotImplementedError

Expand All @@ -109,15 +119,7 @@ def to_matrix(self) -> torch.Tensor:
return ret

def update_from_x_y_z_quaternion(self, x_y_z_quaternion: torch.Tensor):
if x_y_z_quaternion.ndim != 2 and x_y_z_quaternion.shape[1] != 7:
raise ValueError("x_y_z_quaternion can only be 7-D vectors.")

batch_size = x_y_z_quaternion.shape[0]
self.data = torch.empty(batch_size, 3, 4).to(
device=x_y_z_quaternion.device, dtype=x_y_z_quaternion.dtype
)
self[:, :3, :3] = SO3.unit_quaternion_to_matrix(x_y_z_quaternion[:, 3:])
self[:, :3, 3] = x_y_z_quaternion[:, :3]
self.update(SE3.x_y_z_unit_quaternion_to_SE3(x_y_z_quaternion))

def update_from_rot_and_trans(self, rotation: SO3, translation: Point3):
if rotation.shape[0] != translation.shape[0]:
Expand Down Expand Up @@ -166,7 +168,7 @@ def transform_to(
) -> Point3:
raise NotImplementedError

def untransform_to(
def transform_from(
self,
point: Union[Point3, torch.Tensor],
jacobians: Optional[List[torch.Tensor]] = None,
Expand Down
13 changes: 8 additions & 5 deletions theseus/geometry/so3.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ def __init__(
self._SO3_matrix_check(data)
super().__init__(data=data, name=name, dtype=dtype)
if quaternion is not None:
if quaternion.ndim == 1:
quaternion = quaternion.unsqueeze(0)
self.update_from_unit_quaternion(quaternion)

@staticmethod
def _init_data() -> torch.Tensor: # type: ignore
return torch.eye(3, 3).view(1, 3, 3)

def update_from_unit_quaternion(self, quaternion: torch.Tensor):
self.update(self.unit_quaternion_to_matrix(quaternion))
self.update(self.unit_quaternion_to_SO3(quaternion))

def dof(self) -> int:
return 3
Expand Down Expand Up @@ -244,8 +242,11 @@ def _rotate_shape_check(self, point: Union[Point3, torch.Tensor]):
)

@staticmethod
def unit_quaternion_to_matrix(quaternion: torch.torch.Tensor):
def unit_quaternion_to_SO3(quaternion: torch.torch.Tensor):
if quaternion.ndim == 1:
quaternion = quaternion.unsqueeze(0)
SO3._unit_quaternion_check(quaternion)

q0 = quaternion[:, 0]
q1 = quaternion[:, 1]
q2 = quaternion[:, 2]
Expand All @@ -260,7 +261,9 @@ def unit_quaternion_to_matrix(quaternion: torch.torch.Tensor):
q22 = q2 * q2
q23 = q2 * q3
q33 = q3 * q3
ret = torch.zeros(quaternion.shape[0], 3, 3).to(

ret = SO3()
ret.data = torch.zeros(quaternion.shape[0], 3, 3).to(
dtype=quaternion.dtype, device=quaternion.device
)
ret[:, 0, 0] = 2 * (q00 + q11) - 1
Expand Down