testInitializePose.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 
22 
24 #include <gtsam/geometry/Pose2.h>
25 #include <gtsam/geometry/Pose3.h>
26 #include <gtsam/slam/dataset.h>
27 
28 #include <cmath>
29 
30 using namespace std;
31 using namespace gtsam;
32 
33 /* ************************************************************************* */
34 TEST(InitializePose3, computePoses2D) {
35  const string g2oFile = findExampleDataFile("noisyToyGraph.txt");
36  bool is3D = false;
37  const auto [inputGraph, posesInFile] = readG2o(g2oFile, is3D);
38 
39  auto priorModel = noiseModel::Unit::Create(3);
40  inputGraph->addPrior(0, posesInFile->at<Pose2>(0), priorModel);
41 
42  auto poseGraph = initialize::buildPoseGraph<Pose2>(*inputGraph);
43 
44  auto I = genericValue(Rot3());
45  Values orientations;
46  for (size_t i : {0, 1, 2, 3})
47  orientations.insert(i, posesInFile->at<Pose2>(i).rotation());
48  const Values poses = initialize::computePoses<Pose2>(orientations, &poseGraph);
49 
50  // posesInFile is seriously noisy, so we check error of recovered poses
51  EXPECT_DOUBLES_EQUAL(0.0810283, inputGraph->error(poses), 1e-6);
52 }
53 
54 /* ************************************************************************* */
55 TEST(InitializePose3, computePoses3D) {
56  const string g2oFile = findExampleDataFile("Klaus3");
57  bool is3D = true;
58  const auto [inputGraph, posesInFile] = readG2o(g2oFile, is3D);
59 
60  auto priorModel = noiseModel::Unit::Create(6);
61  inputGraph->addPrior(0, posesInFile->at<Pose3>(0), priorModel);
62 
63  auto poseGraph = initialize::buildPoseGraph<Pose3>(*inputGraph);
64 
65  auto I = genericValue(Rot3());
66  Values orientations;
67  for (size_t i : {0, 1, 2})
68  orientations.insert(i, posesInFile->at<Pose3>(i).rotation());
69  Values poses = initialize::computePoses<Pose3>(orientations, &poseGraph);
70  EXPECT(assert_equal(*posesInFile, poses, 0.1)); // TODO(frank): very loose !!
71 }
72 
73 /* ************************************************************************* */
74 int main() {
75  TestResult tr;
76  return TestRegistry::runAllTests(tr);
77 }
78 /* ************************************************************************* */
InitializePose.h
common code between lago.* (2D) and InitializePose3.* (3D)
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
Pose2.h
2D Pose
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
gtsam::Pose2::rotation
const Rot2 & rotation(OptionalJacobian< 1, 3 > Hself={}) const
rotation
Definition: Pose2.h:270
gtsam::readG2o
GraphAndValues readG2o(const std::string &g2oFile, const bool is3D, KernelFunctionType kernelFunctionType)
This function parses a g2o file and stores the measurements into a NonlinearFactorGraph and the initi...
Definition: dataset.cpp:621
gtsam::genericValue
GenericValue< T > genericValue(const T &v)
Definition: GenericValue.h:211
dataset.h
utility functions for loading datasets
I
#define I
Definition: main.h:112
gtsam::Rot3
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition: Rot3.h:58
gtsam::Pose3
Definition: Pose3.h:37
EXPECT_DOUBLES_EQUAL
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:161
TestResult
Definition: TestResult.h:26
gtsam::Pose3::rotation
const Rot3 & rotation(OptionalJacobian< 3, 6 > Hself={}) const
get rotation
Definition: Pose3.cpp:315
gtsam
traits
Definition: chartTesting.h:28
gtsam::Values
Definition: Values.h:65
gtsam::InitializePose3
Definition: InitializePose3.h:36
std
Definition: BFloat16.h:88
gtsam::Values::insert
void insert(Key j, const Value &val)
Definition: Values.cpp:155
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
main
int main()
Definition: testInitializePose.cpp:74
gtsam::findExampleDataFile
GTSAM_EXPORT std::string findExampleDataFile(const std::string &name)
Definition: dataset.cpp:70
TEST
TEST(InitializePose3, computePoses2D)
Definition: testInitializePose.cpp:34
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Pose3.h
3D Pose
gtsam::Pose2
Definition: Pose2.h:39


gtsam
Author(s):
autogenerated on Tue Jun 25 2024 03:06:00