1515import numpy as np
1616
1717import gtsam
18- from gtsam import Point3 , Pose3 , Rot3
18+ from gtsam import Point3 , Pose3 , Rot3 , Point3Pairs
1919from gtsam .utils .test_case import GtsamTestCase
2020
2121
@@ -30,13 +30,34 @@ def test_between(self):
3030 actual = T2 .between (T3 )
3131 self .gtsamAssertEquals (actual , expected , 1e-6 )
3232
33- def test_transform_to (self ):
33+ def test_transformTo (self ):
3434 """Test transformTo method."""
35- transform = Pose3 (Rot3 .Rodrigues (0 , 0 , - 1.570796 ), Point3 (2 , 4 , 0 ))
36- actual = transform .transformTo (Point3 (3 , 2 , 10 ))
35+ pose = Pose3 (Rot3 .Rodrigues (0 , 0 , - math . pi / 2 ), Point3 (2 , 4 , 0 ))
36+ actual = pose .transformTo (Point3 (3 , 2 , 10 ))
3737 expected = Point3 (2 , 1 , 10 )
3838 self .gtsamAssertEquals (actual , expected , 1e-6 )
3939
40+ # multi-point version
41+ points = np .stack ([Point3 (3 , 2 , 10 ), Point3 (3 , 2 , 10 )]).T
42+ actual_array = pose .transformTo (points )
43+ self .assertEqual (actual_array .shape , (3 , 2 ))
44+ expected_array = np .stack ([expected , expected ]).T
45+ np .testing .assert_allclose (actual_array , expected_array , atol = 1e-6 )
46+
47+ def test_transformFrom (self ):
48+ """Test transformFrom method."""
49+ pose = Pose3 (Rot3 .Rodrigues (0 , 0 , - math .pi / 2 ), Point3 (2 , 4 , 0 ))
50+ actual = pose .transformFrom (Point3 (2 , 1 , 10 ))
51+ expected = Point3 (3 , 2 , 10 )
52+ self .gtsamAssertEquals (actual , expected , 1e-6 )
53+
54+ # multi-point version
55+ points = np .stack ([Point3 (2 , 1 , 10 ), Point3 (2 , 1 , 10 )]).T
56+ actual_array = pose .transformFrom (points )
57+ self .assertEqual (actual_array .shape , (3 , 2 ))
58+ expected_array = np .stack ([expected , expected ]).T
59+ np .testing .assert_allclose (actual_array , expected_array , atol = 1e-6 )
60+
4061 def test_range (self ):
4162 """Test range method."""
4263 l1 = Point3 (1 , 0 , 0 )
@@ -81,6 +102,24 @@ def test_serialization(self):
81102 actual .deserialize (serialized )
82103 self .gtsamAssertEquals (expected , actual , 1e-10 )
83104
105+ def test_align_squares (self ):
106+ """Test if Align method can align 2 squares."""
107+ square = np .array ([[0 ,0 ,0 ],[0 ,1 ,0 ],[1 ,1 ,0 ],[1 ,0 ,0 ]], float ).T
108+ sTt = Pose3 (Rot3 .Rodrigues (0 , 0 , - math .pi ), Point3 (2 , 4 , 0 ))
109+ transformed = sTt .transformTo (square )
110+
111+ st_pairs = Point3Pairs ()
112+ for j in range (4 ):
113+ st_pairs .append ((square [:,j ], transformed [:,j ]))
114+
115+ # Recover the transformation sTt
116+ estimated_sTt = Pose3 .Align (st_pairs )
117+ self .gtsamAssertEquals (estimated_sTt , sTt , 1e-10 )
118+
119+ # Matrix version
120+ estimated_sTt = Pose3 .Align (square , transformed )
121+ self .gtsamAssertEquals (estimated_sTt , sTt , 1e-10 )
122+
84123
85124if __name__ == "__main__" :
86125 unittest .main ()
0 commit comments