testSimilarity3.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 #include <gtsam/base/Testable.h>
22 #include <gtsam/base/testLie.h>
23 #include <gtsam/geometry/Pose3.h>
25 #include <gtsam/inference/Symbol.h>
29 #include <gtsam/nonlinear/Values.h>
31 
32 #include <functional>
33 
34 using namespace std::placeholders;
35 using namespace gtsam;
36 using namespace std;
38 
40 
41 static const Point3 P(0.2, 0.7, -2);
42 static const Rot3 R = Rot3::Rodrigues(0.3, 0, 0);
43 static const double s = 4;
44 static const Similarity3 id;
45 static const Similarity3 T1(R, Point3(3.5, -8.2, 4.2), 1);
46 static const Similarity3 T2(Rot3::Rodrigues(0.3, 0.2, 0.1),
47  Point3(3.5, -8.2, 4.2), 1);
48 static const Similarity3 T3(Rot3::Rodrigues(-90, 0, 0), Point3(1, 2, 3), 1);
49 static const Similarity3 T4(R, P, s);
50 static const Similarity3 T5(R, P, 10);
51 static const Similarity3 T6(Rot3(), Point3(1, 1, 0), 2); // Simpler transform
52 
53 const double degree = M_PI / 180;
54 
55 //******************************************************************************
56 TEST(Similarity3, Concepts) {
58  GTSAM_CONCEPT_ASSERT(IsManifold<Similarity3 >);
60 }
61 
62 //******************************************************************************
63 TEST(Similarity3, Constructors) {
64  Similarity3 sim3_Construct1;
65  Similarity3 sim3_Construct2(s);
66  Similarity3 sim3_Construct3(R, P, s);
67  Similarity3 sim4_Construct4(R.matrix(), P, s);
68 }
69 
70 //******************************************************************************
71 TEST(Similarity3, Getters) {
72  Similarity3 sim3_default;
73  EXPECT(assert_equal(Rot3(), sim3_default.rotation()));
74  EXPECT(assert_equal(Point3(0,0,0), sim3_default.translation()));
75  EXPECT_DOUBLES_EQUAL(1.0, sim3_default.scale(), 1e-9);
76 
77  Similarity3 sim3(Rot3::Ypr(1, 2, 3), Point3(4, 5, 6), 7);
78  EXPECT(assert_equal(Rot3::Ypr(1, 2, 3), sim3.rotation()));
79  EXPECT(assert_equal(Point3(4, 5, 6), sim3.translation()));
80  EXPECT_DOUBLES_EQUAL(7.0, sim3.scale(), 1e-9);
81 }
82 
83 /* ************************************************************************* */
84 TEST(Similarity3, HatAndVee) {
85  // Create a few test vectors
86  Vector7 v1(1, 2, 3, 4, 5, 6, 7);
87  Vector7 v2(0.1, -0.5, 1.0, -1.0, 0.5, 2.0, -0.3);
88  Vector7 v3(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
89 
90  // Test that Vee(Hat(v)) == v for various inputs
91  EXPECT(assert_equal(v1, Similarity3::Vee(Similarity3::Hat(v1))));
92  EXPECT(assert_equal(v2, Similarity3::Vee(Similarity3::Hat(v2))));
93  EXPECT(assert_equal(v3, Similarity3::Vee(Similarity3::Hat(v3))));
94 
95  // Check the structure of the Lie Algebra element
96  Matrix4 expected;
97  expected << 0, -3, 2, 4,
98  3, 0, -1, 5,
99  -2, 1, 0, 6,
100  0, 0, 0, -7;
101 
102  EXPECT(assert_equal(expected, Similarity3::Hat(v1)));
103 }
104 
105 /* ************************************************************************* */
106 // Checks correct exponential map (Expmap) with brute force matrix exponential
107 TEST(Similarity3, BruteForceExpmap) {
108  const Vector7 xi(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7);
109  EXPECT(assert_equal(Similarity3::Expmap(xi), expm<Similarity3>(xi), 1e-4));
110 }
111 
112 //******************************************************************************
113 TEST(Similarity3, AdjointMap) {
114  const Matrix4 T = T2.matrix();
115  // Check Ad with actual definition
116  Vector7 delta;
117  delta << 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7;
118  Matrix4 W = Similarity3::Hat(delta);
119  Matrix4 TW = Similarity3::Hat(T2.AdjointMap() * delta);
120  EXPECT(assert_equal(TW, Matrix4(T * W * T.inverse()), 1e-9));
121 }
122 
123 //******************************************************************************
125  Similarity3 sim3(Rot3::Ypr(1, 2, 3).inverse(), Point3(4, 5, 6), 7);
126  Matrix3 Re; // some values from matlab
127  Re << -0.2248, 0.9024, -0.3676, -0.3502, -0.4269, -0.8337, -0.9093, -0.0587, 0.4120;
128  Vector3 te(-9.8472, 59.7640, 10.2125);
129  Similarity3 expected(Re, te, 1.0 / 7.0);
130  EXPECT(assert_equal(expected, sim3.inverse(), 1e-4));
131  EXPECT(assert_equal(sim3, sim3.inverse().inverse(), 1e-8));
132 
133  // test lie group inverse
134  Matrix H1, H2;
135  EXPECT(assert_equal(expected, sim3.inverse(H1), 1e-4));
136  EXPECT(assert_equal(sim3, sim3.inverse().inverse(H2), 1e-8));
137 }
138 
139 //******************************************************************************
140 TEST(Similarity3, Multiplication) {
141  Similarity3 test1(Rot3::Ypr(1, 2, 3).inverse(), Point3(4, 5, 6), 7);
142  Similarity3 test2(Rot3::Ypr(1, 2, 3).inverse(), Point3(8, 9, 10), 11);
143  Matrix3 re;
144  re << 0.0688, 0.9863, -0.1496, -0.5665, -0.0848, -0.8197, -0.8211, 0.1412, 0.5530;
145  Vector3 te(-13.6797, 3.2441, -5.7794);
146  Similarity3 expected(re, te, 77);
147  EXPECT(assert_equal(expected, test1 * test2, 1e-2));
148 }
149 
150 //******************************************************************************
151 TEST(Similarity3, Manifold) {
152  EXPECT_LONGS_EQUAL(7, Similarity3::Dim());
153  Vector z = Vector7::Zero();
154  Similarity3 sim;
155  EXPECT(sim.retract(z) == sim);
156 
157  Vector7 v = Vector7::Zero();
158  v(6) = 2;
159  Similarity3 sim2;
160  EXPECT(sim2.retract(z) == sim2);
161 
162  EXPECT(assert_equal(z, sim2.localCoordinates(sim)));
163 
164  Similarity3 sim3 = Similarity3(Rot3(), Point3(1, 2, 3), 1);
165  Vector v3(7);
166  v3 << 0, 0, 0, 1, 2, 3, 0;
167  EXPECT(assert_equal(v3, sim2.localCoordinates(sim3)));
168 
169  Similarity3 other = Similarity3(Rot3::Ypr(0.1, 0.2, 0.3), Point3(4, 5, 6), 1);
170 
171  Vector vlocal = sim.localCoordinates(other);
172 
173  EXPECT(assert_equal(sim.retract(vlocal), other, 1e-2));
174 
175  Similarity3 other2 = Similarity3(Rot3::Ypr(0.3, 0, 0), Point3(4, 5, 6), 1);
176  Rot3 R = Rot3::Rodrigues(0.3, 0, 0);
177 
178  Vector vlocal2 = sim.localCoordinates(other2);
179 
180  EXPECT(assert_equal(sim.retract(vlocal2), other2, 1e-2));
181 
182  // TODO add unit tests for retract and localCoordinates
183 }
184 
185 //******************************************************************************
186 TEST( Similarity3, retract_first_order) {
187  Similarity3 id;
188  Vector v = Z_7x1;
189  v(0) = 0.3;
190  EXPECT(assert_equal(Similarity3(R, Point3(0,0,0), 1), id.retract(v), 1e-2));
191 // v(3) = 0.2;
192 // v(4) = 0.7;
193 // v(5) = -2;
194 // EXPECT(assert_equal(Similarity3(R, P, 1), id.retract(v), 1e-2));
195 }
196 
197 //******************************************************************************
198 TEST(Similarity3, localCoordinates_first_order) {
199  Vector7 d12 = Vector7::Constant(0.1);
200  d12(6) = 1.0;
201  Similarity3 t1 = T1, t2 = t1.retract(d12);
202  EXPECT(assert_equal(d12, t1.localCoordinates(t2)));
203 }
204 
205 //******************************************************************************
206 TEST(Similarity3, manifold_first_order) {
207  Similarity3 t1 = T1;
208  Similarity3 t2 = T3;
210  Vector d12 = t1.localCoordinates(t2);
211  EXPECT(assert_equal(t2, t1.retract(d12)));
212  Vector d21 = t2.localCoordinates(t1);
213  EXPECT(assert_equal(t1, t2.retract(d21)));
214 }
215 
216 //******************************************************************************
217 // Return as a 4*4 Matrix
219  Matrix4 expected;
220  expected << 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0.5;
221  Matrix4 actual = T6.matrix();
222  EXPECT(assert_equal(expected, actual));
223 }
224 
225 //*****************************************************************************
226 // Exponential and log maps
227 TEST(Similarity3, ExpLogMap) {
228  Vector7 delta;
229  delta << 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7;
230  Vector7 actual = Similarity3::Logmap(Similarity3::Expmap(delta));
231  EXPECT(assert_equal(delta, actual));
232 
233  Vector7 zeros;
234  zeros << 0, 0, 0, 0, 0, 0, 0;
235  Vector7 logIdentity = Similarity3::Logmap(Similarity3::Identity());
236  EXPECT(assert_equal(zeros, logIdentity));
237 
238  Similarity3 expZero = Similarity3::Expmap(zeros);
239  Similarity3 ident = Similarity3::Identity();
240  EXPECT(assert_equal(expZero, ident));
241 }
242 
243 //******************************************************************************
244 // Group action on Point3 (with simpler transform)
245 TEST(Similarity3, GroupAction) {
246  EXPECT(assert_equal(Point3(2, 2, 0), T6 * Point3(0, 0, 0)));
247  EXPECT(assert_equal(Point3(4, 2, 0), T6 * Point3(1, 0, 0)));
248 
249  // Test group action on R^4 via matrix representation
250  Vector4 qh;
251  qh << 1, 0, 0, 1;
252  Vector4 ph;
253  ph << 2, 1, 0, 0.5; // equivalent to Point3(4, 2, 0)
254  EXPECT(assert_equal((Vector )ph, T6.matrix() * qh));
255 
256  // Test some more...
257  Point3 pa = Point3(1, 0, 0);
258  Similarity3 Ta(Rot3(), Point3(1, 2, 3), 1.0);
259  Similarity3 Tb(Rot3(), Point3(1, 2, 3), 2.0);
260  EXPECT(assert_equal(Point3(2, 2, 3), Ta.transformFrom(pa)));
261  EXPECT(assert_equal(Point3(4, 4, 6), Tb.transformFrom(pa)));
262 
263  Similarity3 Tc(Rot3::Rz(M_PI / 2.0), Point3(1, 2, 3), 1.0);
264  Similarity3 Td(Rot3::Rz(M_PI / 2.0), Point3(1, 2, 3), 2.0);
265  EXPECT(assert_equal(Point3(1, 3, 3), Tc.transformFrom(pa)));
266  EXPECT(assert_equal(Point3(2, 6, 6), Td.transformFrom(pa)));
267 
268  // Test derivative
269  // Use lambda to resolve overloaded method
270  std::function<Point3(const Similarity3&, const Point3&)>
271  f = [](const Similarity3& S, const Point3& p){ return S.transformFrom(p); };
272 
273  Point3 q(1, 2, 3);
274  for (const auto& T : { T1, T2, T3, T4, T5, T6 }) {
275  Point3 q(1, 0, 0);
276  Matrix H1 = numericalDerivative21<Point3, Similarity3, Point3>(f, T, q);
277  Matrix H2 = numericalDerivative22<Point3, Similarity3, Point3>(f, T, q);
278  Matrix actualH1, actualH2;
279  T.transformFrom(q, actualH1, actualH2);
280  EXPECT(assert_equal(H1, actualH1));
281  EXPECT(assert_equal(H2, actualH2));
282  }
283 }
284 
285 //******************************************************************************
286 // Group action on Pose3
287 // Estimate Sim(3) object "aSb" from pose pairs {(aTi, bTi)}
288 // In the example below, let the "a" frame be the "world" frame below,
289 // and let the "b" frame be the "egovehicle" frame.
290 // Suppose within the egovehicle frame, we know the poses of two objects "o1" and "o2"
291 TEST(Similarity3, GroupActionPose3) {
292  // Suppose we know the pose of the egovehicle in the world frame
293  Similarity3 wSe(Rot3::Ry(180 * degree), Point3(2, 3, 5), 2.0);
294 
295  // Create source poses (two objects o1 and o2 living in the egovehicle "e" frame)
296  // Suppose they are 3d cuboids detected by onboard sensor, in the egovehicle frame
297  Pose3 eTo1(Rot3(), Point3(0, 0, 0));
298  Pose3 eTo2(Rot3(-1, 0, 0, 0, -1, 0, 0, 0, 1), Point3(4, 0, 0));
299 
300  // Create destination poses (two objects now living in the world/city "w" frame)
301  // Desired to place the objects into the world frame for tracking
302  Pose3 expected_wTo1(Rot3(-1, 0, 0, 0, 1, 0, 0, 0, -1), Point3(4, 6, 10));
303  Pose3 expected_wTo2(Rot3(1, 0, 0, 0, -1, 0, 0, 0, -1), Point3(-4, 6, 10));
304 
305  // objects now live in the world frame, instead of in the egovehicle frame
306  EXPECT(assert_equal(expected_wTo1, wSe.transformFrom(eTo1)));
307  EXPECT(assert_equal(expected_wTo2, wSe.transformFrom(eTo2)));
308 }
309 
310 // Test left group action compatibility.
311 // cSa*Ta = cSb*bSa*Ta
312 TEST(Similarity3, GroupActionPose3_Compatibility) {
313  Similarity3 bSa(Rot3::Ry(180 * degree), Point3(2, 3, 5), 2.0);
314  Similarity3 cSb(Rot3::Ry(90 * degree), Point3(-10, -4, 0), 3.0);
315  Similarity3 cSa(Rot3::Ry(270 * degree), Point3(0, 1, -2), 6.0);
316 
317  // Create poses
318  Pose3 Ta1(Rot3(), Point3(0, 0, 0));
319  Pose3 Ta2(Rot3(-1, 0, 0, 0, -1, 0, 0, 0, 1), Point3(4, 0, 0));
320  Pose3 Tb1(Rot3(-1, 0, 0, 0, 1, 0, 0, 0, -1), Point3(4, 6, 10));
321  Pose3 Tb2(Rot3(1, 0, 0, 0, -1, 0, 0, 0, -1), Point3(-4, 6, 10));
322  Pose3 Tc1(Rot3(0, 0, -1, 0, 1, 0, 1, 0, 0), Point3(0, 6, -12));
323  Pose3 Tc2(Rot3(0, 0, -1, 0, -1, 0, -1, 0, 0), Point3(0, 6, 12));
324 
325  EXPECT(assert_equal(Tc1, cSb.transformFrom(Tb1)));
326  EXPECT(assert_equal(Tc2, cSb.transformFrom(Tb2)));
327 
328  EXPECT(assert_equal(cSa.transformFrom(Ta1), cSb.transformFrom(Tb1)));
329  EXPECT(assert_equal(cSa.transformFrom(Ta2), cSb.transformFrom(Tb2)));
330 }
331 
332 //******************************************************************************
333 // Align with Point3 Pairs
334 TEST(Similarity3, AlignPoint3_1) {
335  Similarity3 expected_aSb(Rot3::Rz(-90 * degree), Point3(3, 4, 5), 2.0);
336 
337  Point3 b1(0, 0, 0), b2(3, 0, 0), b3(3, 0, 4);
338 
339  Point3Pair ab1(make_pair(expected_aSb.transformFrom(b1), b1));
340  Point3Pair ab2(make_pair(expected_aSb.transformFrom(b2), b2));
341  Point3Pair ab3(make_pair(expected_aSb.transformFrom(b3), b3));
342 
343  vector<Point3Pair> correspondences{ab1, ab2, ab3};
344 
345  Similarity3 actual_aSb = Similarity3::Align(correspondences);
346  EXPECT(assert_equal(expected_aSb, actual_aSb));
347 }
348 
349 TEST(Similarity3, AlignPoint3_2) {
350  Similarity3 expected_aSb(Rot3(), Point3(10, 10, 0), 1.0);
351 
352  Point3 b1(0, 0, 0), b2(20, 10, 0), b3(10, 20, 0);
353 
354  Point3Pair ab1(make_pair(expected_aSb.transformFrom(b1), b1));
355  Point3Pair ab2(make_pair(expected_aSb.transformFrom(b2), b2));
356  Point3Pair ab3(make_pair(expected_aSb.transformFrom(b3), b3));
357 
358  vector<Point3Pair> correspondences{ab1, ab2, ab3};
359 
360  Similarity3 actual_aSb = Similarity3::Align(correspondences);
361  EXPECT(assert_equal(expected_aSb, actual_aSb));
362 }
363 
364 TEST(Similarity3, AlignPoint3_3) {
365  Similarity3 expected_aSb(Rot3::RzRyRx(0.3, 0.2, 0.1), Point3(20, 10, 5), 1.0);
366 
367  Point3 b1(0, 0, 1), b2(10, 0, 2), b3(20, -10, 30);
368 
369  Point3Pair ab1(make_pair(expected_aSb.transformFrom(b1), b1));
370  Point3Pair ab2(make_pair(expected_aSb.transformFrom(b2), b2));
371  Point3Pair ab3(make_pair(expected_aSb.transformFrom(b3), b3));
372 
373  vector<Point3Pair> correspondences{ab1, ab2, ab3};
374 
375  Similarity3 actual_aSb = Similarity3::Align(correspondences);
376  EXPECT(assert_equal(expected_aSb, actual_aSb));
377 }
378 
379 //******************************************************************************
380 // Align with Pose3 Pairs
381 TEST(Similarity3, AlignPose3) {
382  Similarity3 expected_wSe(Rot3::Ry(180 * degree), Point3(2, 3, 5), 2.0);
383 
384  // Create source poses (two objects o1 and o2 living in the egovehicle "e" frame)
385  // Suppose they are 3d cuboids detected by an onboard sensor in the egovehicle frame
386  Pose3 eTo1(Rot3(), Point3(0, 0, 0));
387  Pose3 eTo2(Rot3(-1, 0, 0, 0, -1, 0, 0, 0, 1), Point3(4, 0, 0));
388 
389  // Create destination poses (same two objects, but instead living in the world/city "w" frame)
390  Pose3 wTo1(Rot3(-1, 0, 0, 0, 1, 0, 0, 0, -1), Point3(4, 6, 10));
391  Pose3 wTo2(Rot3(1, 0, 0, 0, -1, 0, 0, 0, -1), Point3(-4, 6, 10));
392 
393  Pose3Pair wTe1(make_pair(wTo1, eTo1));
394  Pose3Pair wTe2(make_pair(wTo2, eTo2));
395 
396  vector<Pose3Pair> correspondences{wTe1, wTe2};
397 
398  // Cayley transform cannot accommodate 180 degree rotations,
399  // hence we only test for Expmap
400 #ifdef GTSAM_ROT3_EXPMAP
401  // Recover the transformation wSe (i.e. world_S_egovehicle)
402  Similarity3 actual_wSe = Similarity3::Align(correspondences);
403  EXPECT(assert_equal(expected_wSe, actual_wSe));
404 #endif
405 }
406 
407 //******************************************************************************
408 // Test very simple prior optimization example
409 TEST(Similarity3, Optimization) {
410  // Create a PriorFactor with a Sim3 prior
411  Similarity3 prior = Similarity3(Rot3::Ypr(0.1, 0.2, 0.3), Point3(1, 2, 3), 4);
412  noiseModel::Isotropic::shared_ptr model = noiseModel::Isotropic::Sigma(7, 1);
413  Symbol key('x', 1);
414 
415  // Create graph
418 
419  // Create initial estimate with Identity transform
420  Values initial;
421  initial.insert<Similarity3>(key, Similarity3());
422 
423  // Optimize
424  Values result;
426  params.setVerbosityLM("TRYCONFIG");
428 
429  // After optimization, result should be prior
431 }
432 
433 //******************************************************************************
434 // Test optimization with both Prior and BetweenFactors
435 TEST(Similarity3, Optimization2) {
437  Similarity3 m1 = Similarity3(Rot3::Ypr(M_PI / 4.0, 0, 0), Point3(2.0, 0, 0),
438  1.0);
439  Similarity3 m2 = Similarity3(Rot3::Ypr(M_PI / 2.0, 0, 0),
440  Point3(sqrt(8) * 0.9, 0, 0), 1.0);
441  Similarity3 m3 = Similarity3(Rot3::Ypr(3 * M_PI / 4.0, 0, 0),
442  Point3(sqrt(32) * 0.8, 0, 0), 1.0);
443  Similarity3 m4 = Similarity3(Rot3::Ypr(M_PI / 2.0, 0, 0),
444  Point3(6 * 0.7, 0, 0), 1.0);
445  Similarity3 loop = Similarity3(1.42);
446 
447  //prior.print("Goal Transform");
448  noiseModel::Isotropic::shared_ptr model = noiseModel::Isotropic::Sigma(7,
449  0.01);
450  SharedDiagonal betweenNoise = noiseModel::Diagonal::Sigmas(
451  (Vector(7) << 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 10).finished());
452  SharedDiagonal betweenNoise2 = noiseModel::Diagonal::Sigmas(
453  (Vector(7) << 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 1.0).finished());
454  BetweenFactor<Similarity3> b1(X(1), X(2), m1, betweenNoise);
455  BetweenFactor<Similarity3> b2(X(2), X(3), m2, betweenNoise);
456  BetweenFactor<Similarity3> b3(X(3), X(4), m3, betweenNoise);
457  BetweenFactor<Similarity3> b4(X(4), X(5), m4, betweenNoise);
458  BetweenFactor<Similarity3> lc(X(5), X(1), loop, betweenNoise2);
459 
460  // Create graph
462  graph.addPrior(X(1), prior, model); // Prior !
463  graph.push_back(b1);
464  graph.push_back(b2);
465  graph.push_back(b3);
466  graph.push_back(b4);
467  graph.push_back(lc);
468 
469  //graph.print("Full Graph\n");
470  Values initial;
471  initial.insert<Similarity3>(X(1), Similarity3());
472  initial.insert<Similarity3>(X(2),
473  Similarity3(Rot3::Ypr(M_PI / 2.0, 0, 0), Point3(1, 0, 0), 1.1));
474  initial.insert<Similarity3>(X(3),
475  Similarity3(Rot3::Ypr(2.0 * M_PI / 2.0, 0, 0), Point3(0.9, 1.1, 0), 1.2));
476  initial.insert<Similarity3>(X(4),
477  Similarity3(Rot3::Ypr(3.0 * M_PI / 2.0, 0, 0), Point3(0, 1, 0), 1.3));
478  initial.insert<Similarity3>(X(5),
479  Similarity3(Rot3::Ypr(4.0 * M_PI / 2.0, 0, 0), Point3(0, 0, 0), 1.0));
480 
481  //initial.print("Initial Estimate\n");
482 
483  Values result;
485  //result.print("Optimized Estimate\n");
486  Similarity3 p1, p2, p3, p4, p5;
487  p1 = result.at<Similarity3>(X(1));
488  p2 = result.at<Similarity3>(X(2));
489  p3 = result.at<Similarity3>(X(3));
490  p4 = result.at<Similarity3>(X(4));
491  p5 = result.at<Similarity3>(X(5));
492 
493  //p1.print("Similarity1");
494  //p2.print("Similarity2");
495  //p3.print("Similarity3");
496  //p4.print("Similarity4");
497  //p5.print("Similarity5");
498 
499  Similarity3 expected(0.7);
501 }
502 
503 //******************************************************************************
504 // Align points (p,q) assuming that p = T*q + noise
505 TEST(Similarity3, AlignScaledPointClouds) {
506 // Create ground truth
507  Point3 q1(0, 0, 0), q2(1, 0, 0), q3(0, 1, 0);
508 
509  // Create transformed cloud (noiseless)
510 // Point3 p1 = T4 * q1, p2 = T4 * q2, p3 = T4 * q3;
511 
512  // Create an unknown expression
513  Expression<Similarity3> unknownT(0); // use key 0
514 
515  // Create constant expressions for the ground truth points
516  Expression<Point3> q1_(q1), q2_(q2), q3_(q3);
517 
518  // Create prediction expressions
519  Expression<Point3> predict1(unknownT, &Similarity3::transformFrom, q1_);
520  Expression<Point3> predict2(unknownT, &Similarity3::transformFrom, q2_);
521  Expression<Point3> predict3(unknownT, &Similarity3::transformFrom, q3_);
522 
524 // ExpressionFactorGraph graph;
525 // graph.addExpressionFactor(predict1, p1, R); // |T*q1 - p1|
526 // graph.addExpressionFactor(predict2, p2, R); // |T*q2 - p2|
527 // graph.addExpressionFactor(predict3, p3, R); // |T*q3 - p3|
528 }
529 
530 //******************************************************************************
531 TEST(Similarity3 , Invariants) {
532  Similarity3 id;
533 
534  EXPECT(check_group_invariants(id, id));
535  EXPECT(check_group_invariants(id, T3));
536  EXPECT(check_group_invariants(T2, id));
537  EXPECT(check_group_invariants(T2, T3));
538 
539  EXPECT(check_manifold_invariants(id, id));
540  EXPECT(check_manifold_invariants(id, T3));
541  EXPECT(check_manifold_invariants(T2, id));
542  EXPECT(check_manifold_invariants(T2, T3));
543 }
544 
545 //******************************************************************************
546 TEST(Similarity3 , LieGroupDerivatives) {
547  Similarity3 id;
548 
553 }
554 
555 //******************************************************************************
556 int main() {
557  TestResult tr;
558  return TestRegistry::runAllTests(tr);
559 }
560 //******************************************************************************
561 
gtsam::Similarity3::scale
double scale() const
Return the scale.
Definition: Similarity3.h:196
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
gtsam::Pose3Pair
std::pair< Pose3, Pose3 > Pose3Pair
Definition: Pose3.h:445
gtsam::Point3Pair
std::pair< Point3, Point3 > Point3Pair
Definition: Point3.h:42
gtsam::NonlinearOptimizer::optimize
virtual const Values & optimize()
Definition: NonlinearOptimizer.h:98
Similarity3.h
Implementation of Similarity3 transform.
simple_graph::b1
Vector2 b1(2, -1)
P
static const Point3 P(0.2, 0.7, -2)
inverse
const EIGEN_DEVICE_FUNC InverseReturnType inverse() const
Definition: ArrayCwiseUnaryOps.h:411
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
GTSAM_CONCEPT_TESTABLE_INST
#define GTSAM_CONCEPT_TESTABLE_INST(T)
Definition: Testable.h:176
EXPECT_LONGS_EQUAL
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:154
gtsam::IsMatrixLieGroup
Definition: Lie.h:311
screwPose2::xi
Vector xi
Definition: testPose2.cpp:169
Testable.h
Concept check for values that can be used in unit tests.
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
p5
KeyInt p5(x5, 5)
TestHarness.h
LevenbergMarquardtOptimizer.h
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
initial
Values initial
Definition: OdometryOptimize.cpp:2
simple_graph::b2
Vector2 b2(4, -5)
gtsam::Similarity3::AdjointMap
Matrix7 AdjointMap() const
Project from one tangent space to another.
Definition: Similarity3.cpp:213
m1
Matrix3d m1
Definition: IOFormat.cpp:2
gtsam::utils.numerical_derivative.retract
def retract(a, np.ndarray xi)
Definition: numerical_derivative.py:44
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
X
#define X
Definition: icosphere.cpp:20
gtsam::Vector3
Eigen::Vector3d Vector3
Definition: Vector.h:44
testLie.h
vanilla::params
static const SmartProjectionParams params
Definition: smartFactorScenarios.h:69
gtsam::IsGroup
Definition: Group.h:42
gtsam::Similarity3::inverse
Similarity3 inverse() const
Return the inverse.
Definition: Similarity3.cpp:130
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:39
result
Values result
Definition: OdometryOptimize.cpp:8
s
static const double s
Definition: testSimilarity3.cpp:43
gtsam::Expression
Definition: Expression.h:49
simple::p2
static Point3 p2
Definition: testInitializePose3.cpp:51
m2
MatrixType m2(n_dims)
Expmap
Pose2_ Expmap(const Vector3_ &xi)
Definition: InverseKinematicsExampleExpressions.cpp:47
gtsam::Values::at
const ValueType at(Key j) const
Definition: Values-inl.h:261
id
static const Similarity3 id
Definition: testSimilarity3.cpp:44
gtsam::transformFrom
Point3_ transformFrom(const Pose3_ &x, const Point3_ &p)
Definition: slam/expressions.h:47
numericalDerivative.h
Some functions to compute numerical derivatives.
T4
static const Similarity3 T4(R, P, s)
gtsam.examples.PlanarManipulatorExample.delta
def delta(g0, g1)
Definition: PlanarManipulatorExample.py:45
gtsam::Similarity3::translation
Point3 translation() const
Return a GTSAM translation.
Definition: Similarity3.h:193
Eigen::numext::q
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:1984
BetweenFactor.h
TEST
TEST(Similarity3, Concepts)
Definition: testSimilarity3.cpp:56
gtsam::Rot3
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition: Rot3.h:58
T6
static const Similarity3 T6(Rot3(), Point3(1, 1, 0), 2)
gtsam::Pose3
Definition: Pose3.h:37
gtsam::NonlinearFactorGraph
Definition: NonlinearFactorGraph.h:55
gtsam::SharedDiagonal
noiseModel::Diagonal::shared_ptr SharedDiagonal
Definition: NoiseModel.h:764
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:916
gtsam::NonlinearFactorGraph::addPrior
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
Definition: NonlinearFactorGraph.h:199
ExpressionFactorGraph.h
Factor graph that supports adding ExpressionFactors directly.
gtsam::LevenbergMarquardtOptimizer
Definition: LevenbergMarquardtOptimizer.h:35
CHECK_LIE_GROUP_DERIVATIVES
#define CHECK_LIE_GROUP_DERIVATIVES(t1, t2)
Definition: testLie.h:82
T5
static const Similarity3 T5(R, P, 10)
Symbol.h
simple::p3
static Point3 p3
Definition: testInitializePose3.cpp:53
pybind_wrapper_test_script.z
z
Definition: pybind_wrapper_test_script.py:61
gtsam::Similarity3::transformFrom
Point3 transformFrom(const Point3 &p, OptionalJacobian< 3, 7 > H1={}, OptionalJacobian< 3, 3 > H2={}) const
Action on a point p is s*(R*p+t)
Definition: Similarity3.cpp:136
Eigen::Triplet< double >
gtsam::LieGroup::localCoordinates
TangentVector localCoordinates(const Class &g) const
localCoordinates as required by manifold concept: finds tangent vector between *this and g
Definition: Lie.h:136
simple_graph::b3
Vector2 b3(3, -6)
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
EXPECT_DOUBLES_EQUAL
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:161
p1
Vector3f p1
Definition: MatrixBase_all.cpp:2
p4
KeyInt p4(x4, 4)
main
int main()
Definition: testSimilarity3.cpp:556
TestResult
Definition: TestResult.h:26
key
const gtsam::Symbol key('X', 0)
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
m3
static const DiscreteKey m3(M(3), 2)
gtsam
traits
Definition: SFMdata.h:40
NonlinearFactorGraph.h
Factor Graph consisting of non-linear factors.
gtsam::FactorGraph::push_back
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:147
gtsam::Values
Definition: Values.h:65
gtsam::symbol_shorthand::W
Key W(std::uint64_t j)
Definition: inference/Symbol.h:170
gtsam::Similarity3::rotation
Rot3 rotation() const
Return a GTSAM rotation.
Definition: Similarity3.h:190
std
Definition: BFloat16.h:88
T2
static const Similarity3 T2(Rot3::Rodrigues(0.3, 0.2, 0.1), Point3(3.5, -8.2, 4.2), 1)
origin
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set origin
Definition: gnuplot_common_settings.hh:45
p
float * p
Definition: Tutorial_Map_using.cpp:9
v2
Vector v2
Definition: testSerializationBase.cpp:39
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
gtsam::Similarity3::matrix
Matrix4 matrix() const
Calculate 4*4 matrix group equivalent.
Definition: Similarity3.cpp:291
gtsam::Rot3::matrix
Matrix3 matrix() const
Definition: Rot3M.cpp:218
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:41
gtsam::LevenbergMarquardtParams
Definition: LevenbergMarquardtParams.h:35
gtsam::Point3
Vector3 Point3
Definition: Point3.h:38
initial
Definition: testScenarioRunner.cpp:148
gtsam::LieGroup::retract
Class retract(const TangentVector &v) const
retract as required by manifold concept: applies v at *this
Definition: Lie.h:131
different_sigmas::prior
const auto prior
Definition: testHybridBayesNet.cpp:240
gtsam::noiseModel::Isotropic::shared_ptr
std::shared_ptr< Isotropic > shared_ptr
Definition: NoiseModel.h:559
test2
void test2(OptionalJacobian<-1,-1 > H={})
Definition: testOptionalJacobian.cpp:123
v3
Vector v3
Definition: testSerializationBase.cpp:40
gtsam::internal::Align
static Similarity2 Align(const Point2Pairs &d_abPointPairs, const Rot2 &aRb, const Point2Pair &centroids)
This method estimates the similarity transform from differences point pairs, given a known or estimat...
Definition: Similarity2.cpp:74
M_PI
#define M_PI
Definition: mconf.h:117
T1
static const Similarity3 T1(R, Point3(3.5, -8.2, 4.2), 1)
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2
ceres::Vector
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Definition: gtsam/3rdparty/ceres/eigen.h:38
GTSAM_CONCEPT_ASSERT
#define GTSAM_CONCEPT_ASSERT(concept)
Definition: base/concepts.h:25
degree
const double degree
Definition: testSimilarity3.cpp:53
R
static const Rot3 R
Definition: testSimilarity3.cpp:42
ceres::sqrt
Jet< T, N > sqrt(const Jet< T, N > &f)
Definition: jet.h:418
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
T3
static const Similarity3 T3(Rot3::Rodrigues(-90, 0, 0), Point3(1, 2, 3), 1)
gtsam::Similarity3
Definition: Similarity3.h:36
Values.h
A non-templated config holding any types of Manifold-group elements.
Pose3.h
3D Pose manifold SO(3) x R^3 and group SE(3)
S
DiscreteKey S(1, 2)
v1
Vector v1
Definition: testSerializationBase.cpp:38
gtsam::Symbol
Definition: inference/Symbol.h:37
gtsam::BetweenFactor
Definition: BetweenFactor.h:40


gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:07:52