testTranslationFactor.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010-2020, 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/geometry/Point3.h>
22 
24 
25 using namespace std::placeholders;
26 using namespace std;
27 using namespace gtsam;
28 
29 // Create a noise model for the chordal error
30 static SharedNoiseModel model(noiseModel::Isotropic::Sigma(3, 0.05));
31 
32 // Keys are deliberately *not* in sorted order to test that case.
33 static const Key kKey1(2), kKey2(1);
34 static const Unit3 kMeasured(1, 0, 0);
35 
36 /* ************************************************************************* */
37 TEST(TranslationFactor, Constructor) {
39 }
40 
41 /* ************************************************************************* */
42 TEST(TranslationFactor, ZeroError) {
43  // Create a factor
45 
46  // Set the linearization
47  Point3 T1(1, 0, 0), T2(2, 0, 0);
48 
49  // Use the factor to calculate the error
50  Vector actualError(factor.evaluateError(T1, T2));
51 
52  // Verify we get the expected error
53  Vector expected = (Vector3() << 0, 0, 0).finished();
54  EXPECT(assert_equal(expected, actualError, 1e-9));
55 }
56 
57 /* ************************************************************************* */
58 TEST(TranslationFactor, NonZeroError) {
59  // create a factor
61 
62  // set the linearization
63  Point3 T1(0, 1, 1), T2(0, 2, 2);
64 
65  // use the factor to calculate the error
66  Vector actualError(factor.evaluateError(T1, T2));
67 
68  // verify we get the expected error
69  Vector expected = (Vector3() << -1, 1 / sqrt(2), 1 / sqrt(2)).finished();
70  EXPECT(assert_equal(expected, actualError, 1e-9));
71 }
72 
73 /* ************************************************************************* */
75  const TranslationFactor &factor) {
76  return factor.evaluateError(T1, T2);
77 }
78 
79 TEST(TranslationFactor, Jacobian) {
80  // Create a factor
82 
83  // Set the linearization
84  Point3 T1(1, 0, 0), T2(2, 0, 0);
85 
86  // Use the factor to calculate the Jacobians
87  Matrix H1Actual, H2Actual;
88  factor.evaluateError(T1, T2, H1Actual, H2Actual);
89 
90  // Use numerical derivatives to calculate the Jacobians
91  Matrix H1Expected, H2Expected;
92  H1Expected = numericalDerivative11<Vector, Point3>(
93  std::bind(&factorError, std::placeholders::_1, T2, factor), T1);
94  H2Expected = numericalDerivative11<Vector, Point3>(
95  std::bind(&factorError, T1, std::placeholders::_1, factor), T2);
96 
97  // Verify the Jacobians are correct
98  EXPECT(assert_equal(H1Expected, H1Actual, 1e-9));
99  EXPECT(assert_equal(H2Expected, H2Actual, 1e-9));
100 }
101 
102 /* ************************************************************************* */
103 int main() {
104  TestResult tr;
105  return TestRegistry::runAllTests(tr);
106 }
107 /* ************************************************************************* */
static int runAllTests(TestResult &result)
Eigen::Vector3d Vector3
Definition: Vector.h:43
Matrix expected
Definition: testMatrix.cpp:971
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
TEST(TranslationFactor, Constructor)
Definition: BFloat16.h:88
Some functions to compute numerical derivatives.
static const Pose3 T2(Rot3::Rodrigues(0.3, 0.2, 0.1), P2)
static const Key kKey2(1)
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
Eigen::VectorXd Vector
Definition: Vector.h:38
#define EXPECT(condition)
Definition: Test.h:150
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Binary factor for a relative translation direction measurement.
traits
Definition: chartTesting.h:28
static const Similarity3 T1(R, Point3(3.5, -8.2, 4.2), 1)
3D Point
static const Key kKey1(2)
Jet< T, N > sqrt(const Jet< T, N > &f)
Definition: jet.h:418
Vector3 Point3
Definition: Point3.h:38
Vector evaluateError(const Point3 &Ta, const Point3 &Tb, OptionalMatrixType H1, OptionalMatrixType H2) const override
Caclulate error: (norm(Tb - Ta) - measurement) where Tb and Ta are Point3 translations and measuremen...
Vector factorError(const Point3 &T1, const Point3 &T2, const TranslationFactor &factor)
static const Unit3 kMeasured(1, 0, 0)
int main()
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741
static SharedNoiseModel model(noiseModel::Isotropic::Sigma(3, 0.05))


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:39:48