testBinaryMeasurement.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 
21 #include <gtsam/geometry/Rot3.h>
22 #include <gtsam/geometry/Unit3.h>
23 #include <gtsam/geometry/Pose3.h>
24 
26 
27 using namespace std;
28 using namespace gtsam;
29 
30 static const Key kKey1(2), kKey2(1);
31 
32 // Create noise models for unit3 and rot3
33 static SharedNoiseModel unit3_model(noiseModel::Isotropic::Sigma(2, 0.05));
34 static SharedNoiseModel rot3_model(noiseModel::Isotropic::Sigma(3, 0.05));
35 
36 const Unit3 unit3Measured(Vector3(1, 1, 1));
38 
39 /* ************************************************************************* */
42  unit3_model);
43  EXPECT_LONGS_EQUAL(unit3Measurement.key1(), kKey1);
44  EXPECT_LONGS_EQUAL(unit3Measurement.key2(), kKey2);
45  EXPECT(unit3Measurement.measured().equals(unit3Measured));
46 
47  BinaryMeasurement<Unit3> unit3MeasurementCopy(kKey1, kKey2, unit3Measured,
48  unit3_model);
49  EXPECT(unit3Measurement.equals(unit3MeasurementCopy));
50 }
51 
52 /* ************************************************************************* */
54  // testing the accessors
56  rot3_model);
57  EXPECT_LONGS_EQUAL(rot3Measurement.key1(), kKey1);
58  EXPECT_LONGS_EQUAL(rot3Measurement.key2(), kKey2);
59  EXPECT(rot3Measurement.measured().equals(rot3Measured));
60 
61  // testing the equals function
62  BinaryMeasurement<Rot3> rot3MeasurementCopy(kKey1, kKey2, rot3Measured,
63  rot3_model);
64  EXPECT(rot3Measurement.equals(rot3MeasurementCopy));
65 }
66 
67 /* ************************************************************************* */
68 TEST(BinaryMeasurement, Rot3MakeRobust) {
69  auto huber_model = noiseModel::Robust::Create(
70  noiseModel::mEstimator::Huber::Create(1.345), rot3_model);
72  huber_model);
73 
74  EXPECT_LONGS_EQUAL(rot3Measurement.key1(), kKey1);
75  EXPECT_LONGS_EQUAL(rot3Measurement.key2(), kKey2);
76  EXPECT(rot3Measurement.measured().equals(rot3Measured));
77  const auto &robust = std::dynamic_pointer_cast<noiseModel::Robust>(
78  rot3Measurement.noiseModel());
79  EXPECT(robust);
80 }
81 
82 /* ************************************************************************* */
83 int main() {
84  TestResult tr;
85  return TestRegistry::runAllTests(tr);
86 }
87 /* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
EXPECT_LONGS_EQUAL
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:154
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
gtsam::BinaryMeasurement::equals
bool equals(const BinaryMeasurement &expected, double tol=1e-9) const
Definition: BinaryMeasurement.h:75
main
int main()
Definition: testBinaryMeasurement.cpp:83
rot3_model
static SharedNoiseModel rot3_model(noiseModel::Isotropic::Sigma(3, 0.05))
gtsam::Vector3
Eigen::Vector3d Vector3
Definition: Vector.h:43
rot3Measured
const Rot3 rot3Measured
Definition: testBinaryMeasurement.cpp:37
Unit3.h
Rot3.h
3D rotation represented as a rotation matrix or quaternion
gtsam::BinaryMeasurement::noiseModel
const SharedNoiseModel & noiseModel() const
Definition: BinaryMeasurement.h:61
gtsam::Rot3
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition: Rot3.h:58
kKey2
static const Key kKey2(1)
TEST
TEST(BinaryMeasurement, Unit3)
Definition: testBinaryMeasurement.cpp:40
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:762
gtsam::BinaryMeasurement::key1
Key key1() const
Definition: BinaryMeasurement.h:58
TestResult
Definition: TestResult.h:26
unit3_model
static SharedNoiseModel unit3_model(noiseModel::Isotropic::Sigma(2, 0.05))
gtsam::BinaryMeasurement
Definition: BinaryMeasurement.h:36
gtsam::BinaryMeasurement::key2
Key key2() const
Definition: BinaryMeasurement.h:59
gtsam
traits
Definition: SFMdata.h:40
BinaryMeasurement.h
Binary measurement represents a measurement between two keys in a graph. A binary measurement is simi...
std
Definition: BFloat16.h:88
unit3Measured
const Unit3 unit3Measured(Vector3(1, 1, 1))
kKey1
static const Key kKey1(2)
gtsam::Unit3::equals
bool equals(const Unit3 &s, double tol=1e-9) const
The equals function with tolerance.
Definition: Unit3.h:115
gtsam::Unit3
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
gtsam::BinaryMeasurement::measured
const T & measured() const
Definition: BinaryMeasurement.h:60
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::Rot3::equals
bool equals(const Rot3 &p, double tol=1e-9) const
Definition: Rot3.cpp:99
Pose3.h
3D Pose


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:18