2 GTSAM Copyright 2010-2019, Georgia Tech Research Corporation, 3 Atlanta, Georgia 30332-0415 6 See LICENSE for the license information 9 Author: Frank Dellaert, Duy Nguyen Ta 19 from gtsam
import Point3, Pose3, Rot3
23 jacobian = np.zeros((6, 6))
29 pose_plus = pose.retract(xplus).__getattribute__(method)()
30 pose_minus = pose.retract(xminus).__getattribute__(method)()
31 jacobian[:, idx] = pose_minus.localCoordinates(pose_plus) / (2 * delta)
36 jacobian = np.zeros((6, 6))
37 other_jacobian = np.zeros((6, 6))
44 pose_plus = pose.retract(xplus).__getattribute__(method)(*inputs, other_pose)
45 pose_minus = pose.retract(xminus).__getattribute__(method)(*inputs, other_pose)
46 jacobian[:, idx] = pose_minus.localCoordinates(pose_plus) / (2 * delta)
48 other_pose_plus = pose.__getattribute__(method)(*inputs, other_pose.retract(xplus))
49 other_pose_minus = pose.__getattribute__(method)(*inputs, other_pose.retract(xminus))
50 other_jacobian[:, idx] = other_pose_minus.localCoordinates(other_pose_plus) / (2 * delta)
51 return jacobian, other_jacobian
55 jacobian = np.zeros((3, 6))
56 point_jacobian = np.zeros((3, 3))
63 point_plus = pose.retract(xplus).__getattribute__(method)(point)
64 point_minus = pose.retract(xminus).__getattribute__(method)(point)
65 jacobian[:, idx] = (point_plus - point_minus) / (2 * delta)
72 point_plus = pose.__getattribute__(method)(point + xplus)
73 point_minus = pose.__getattribute__(method)(point + xminus)
74 point_jacobian[:, idx] = (point_plus - point_minus) / (2 * delta)
75 return jacobian, point_jacobian
79 """Test selected Pose3 methods.""" 82 """Test between method.""" 83 T2 =
Pose3(Rot3.Rodrigues(0.3, 0.2, 0.1),
Point3(3.5, -8.2, 4.2))
84 T3 =
Pose3(Rot3.Rodrigues(-90, 0, 0),
Point3(1, 2, 3))
85 expected = T2.inverse().
compose(T3)
86 actual = T2.between(T3)
90 jacobian = np.zeros((6, 6), order=
'F')
91 jacobian_other = np.zeros((6, 6), order=
'F')
92 T2.between(T3, jacobian, jacobian_other)
98 """Test between method.""" 99 pose =
Pose3(Rot3.Rodrigues(0, 0, -math.pi/2),
Point3(2, 4, 0))
100 expected =
Pose3(Rot3.Rodrigues(0, 0, math.pi/2),
Point3(4, -2, 0))
101 actual = pose.inverse()
105 jacobian = np.zeros((6, 6), order=
'F')
106 pose.inverse(jacobian)
111 """Test slerp method.""" 113 pose1 =
Pose3(Rot3.Rodrigues(0, 0, -math.pi/2),
Point3(2, 4, 0))
114 actual_alpha_0 = pose0.slerp(0, pose1)
116 actual_alpha_1 = pose0.slerp(1, pose1)
118 actual_alpha_half = pose0.slerp(0.5, pose1)
119 expected_alpha_half =
Pose3(Rot3.Rodrigues(0, 0, -math.pi/4),
Point3(0.17157288, 2.41421356, 0))
123 jacobian = np.zeros((6, 6), order=
'F')
124 jacobian_other = np.zeros((6, 6), order=
'F')
125 pose0.slerp(0.5, pose1, jacobian, jacobian_other)
131 """Test transformTo method.""" 132 pose =
Pose3(Rot3.Rodrigues(0, 0, -math.pi/2),
Point3(2, 4, 0))
133 actual = pose.transformTo(
Point3(3, 2, 10))
134 expected =
Point3(2, 1, 10)
139 jacobian_pose = np.zeros((3, 6), order=
'F')
140 jacobian_point = np.zeros((3, 3), order=
'F')
141 pose.transformTo(point, jacobian_pose, jacobian_point)
147 points = np.stack([
Point3(3, 2, 10),
Point3(3, 2, 10)]).T
148 actual_array = pose.transformTo(points)
149 self.assertEqual(actual_array.shape, (3, 2))
150 expected_array = np.stack([expected, expected]).T
151 np.testing.assert_allclose(actual_array, expected_array, atol=1e-6)
154 """Test transformFrom method.""" 155 pose =
Pose3(Rot3.Rodrigues(0, 0, -math.pi/2),
Point3(2, 4, 0))
156 actual = pose.transformFrom(
Point3(2, 1, 10))
157 expected =
Point3(3, 2, 10)
162 jacobian_pose = np.zeros((3, 6), order=
'F')
163 jacobian_point = np.zeros((3, 3), order=
'F')
164 pose.transformFrom(point, jacobian_pose, jacobian_point)
170 points = np.stack([
Point3(2, 1, 10),
Point3(2, 1, 10)]).T
171 actual_array = pose.transformFrom(points)
172 self.assertEqual(actual_array.shape, (3, 2))
173 expected_array = np.stack([expected, expected]).T
174 np.testing.assert_allclose(actual_array, expected_array, atol=1e-6)
177 """Test range method.""" 182 xl1 =
Pose3(Rot3.Ypr(0.0, 0.0, 0.0),
Point3(1, 0, 0))
183 xl2 =
Pose3(Rot3.Ypr(0.0, 1.0, 0.0),
Point3(1, 1, 0))
186 self.assertEqual(1, x1.range(point=l1))
189 self.assertEqual(math.sqrt(2.0), x1.range(point=l2))
192 self.assertEqual(1, x1.range(pose=xl1))
195 self.assertEqual(math.sqrt(2.0), x1.range(pose=xl2))
198 """Test adjoint methods.""" 200 xi = np.array([1, 2, 3, 4, 5, 6])
204 T.AdjointTranspose(xi)
206 Pose3.adjoint(xi, xi)
208 expected = np.dot(Pose3.adjointMap_(xi), xi)
209 actual = Pose3.adjoint_(xi, xi)
210 np.testing.assert_array_equal(actual, expected)
213 """Test if serialization is working normally""" 214 expected =
Pose3(Rot3.Ypr(0.0, 1.0, 0.0),
Point3(1, 1, 0))
216 serialized = expected.serialize()
217 actual.deserialize(serialized)
221 """Test if Align method can align 2 squares.""" 222 square = np.array([[0,0,0],[0,1,0],[1,1,0],[1,0,0]], float).T
223 sTt =
Pose3(Rot3.Rodrigues(0, 0, -math.pi),
Point3(2, 4, 0))
224 transformed = sTt.transformTo(square)
228 st_pairs.append((square[:,j], transformed[:,j]))
231 estimated_sTt = Pose3.Align(st_pairs)
235 estimated_sTt = Pose3.Align(square, transformed)
239 if __name__ ==
"__main__":
def test_transformTo(self)
def gtsamAssertEquals(self, actual, expected, tol=1e-9)
def test_serialization(self)
def numerical_derivative_pose(pose, method, delta=1e-5)
T compose(const T &t1, const T &t2)
def numerical_derivative_2_poses(pose, other_pose, method, delta=1e-5, inputs=())
def test_transformFrom(self)
def numerical_derivative_pose_point(pose, point, method, delta=1e-5)
def test_align_squares(self)
Double_ range(const Point2_ &p, const Point2_ &q)