test_TranslationRecovery.py
Go to the documentation of this file.
1 from __future__ import print_function
2 
3 import numpy as np
4 import unittest
5 
6 import gtsam
7 
8 """ Returns example pose values of 3 points A, B and C in the world frame """
10  T = []
11  T.append(gtsam.Point3(np.array([3.14, 1.59, 2.65])))
12  T.append(gtsam.Point3(np.array([-1.0590e+00, -3.6017e-02, -1.5720e+00])))
13  T.append(gtsam.Point3(np.array([8.5034e+00, 6.7499e+00, -3.6383e+00])))
14 
15  data = gtsam.Values()
16  for i in range(len(T)):
17  data.insert(i, gtsam.Pose3(gtsam.Rot3(), T[i]))
18  return data
19 
20 """ Returns binary measurements for the points in the given edges."""
21 def SimulateMeasurements(gt_poses, graph_edges):
22  measurements = gtsam.BinaryMeasurementsUnit3()
23  for edge in graph_edges:
24  Ta = gt_poses.atPose3(edge[0]).translation()
25  Tb = gt_poses.atPose3(edge[1]).translation()
26  measurements.append(gtsam.BinaryMeasurementUnit3( \
27  edge[0], edge[1], gtsam.Unit3(Tb - Ta), \
29  return measurements
30 
31 """ Tests for the translation recovery class """
32 class TestTranslationRecovery(unittest.TestCase):
33  """Test selected Translation Recovery methods."""
34 
35  def test_constructor(self):
36  """Construct from binary measurements."""
38  self.assertIsInstance(algorithm, gtsam.TranslationRecovery)
39 
40  def test_run(self):
41  gt_poses = ExampleValues()
42  measurements = SimulateMeasurements(gt_poses, [[0, 1], [0, 2], [1, 2]])
43 
44  # Set verbosity to Silent for tests
46  lmParams.setVerbosityLM("silent")
47 
48  algorithm = gtsam.TranslationRecovery(measurements, lmParams)
49  scale = 2.0
50  result = algorithm.run(scale)
51 
52  w_aTc = gt_poses.atPose3(2).translation() - gt_poses.atPose3(0).translation()
53  w_aTb = gt_poses.atPose3(1).translation() - gt_poses.atPose3(0).translation()
54  w_aTc_expected = w_aTc*scale/np.linalg.norm(w_aTb)
55  w_aTb_expected = w_aTb*scale/np.linalg.norm(w_aTb)
56 
57  np.testing.assert_array_almost_equal(result.atPoint3(0), np.array([0,0,0]), 6, "Origin result is incorrect.")
58  np.testing.assert_array_almost_equal(result.atPoint3(1), w_aTb_expected, 6, "Point B result is incorrect.")
59  np.testing.assert_array_almost_equal(result.atPoint3(2), w_aTc_expected, 6, "Point C result is incorrect.")
60 
61 if __name__ == "__main__":
62  unittest.main()
63 
std::vector< BinaryMeasurement< Unit3 >> BinaryMeasurementsUnit3
Definition: dataset.h:506
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
def SimulateMeasurements(gt_poses, graph_edges)
Vector3 Point3
Definition: Point3.h:35
size_t len(handle h)
Definition: pytypes.h:1514
static shared_ptr Sigma(size_t dim, double sigma, bool smart=true)
Definition: NoiseModel.cpp:567


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:46:04