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");
37  Values::shared_ptr posesInFile;
38  bool is3D = false;
39  boost::tie(inputGraph, posesInFile) = readG2o(g2oFile, is3D);
40 
41  auto priorModel = noiseModel::Unit::Create(3);
42  inputGraph->addPrior(0, posesInFile->at<Pose2>(0), priorModel);
43 
44  auto poseGraph = initialize::buildPoseGraph<Pose2>(*inputGraph);
45 
46  auto I = genericValue(Rot3());
47  Values orientations;
48  for (size_t i : {0, 1, 2, 3})
49  orientations.insert(i, posesInFile->at<Pose2>(i).rotation());
50  const Values poses = initialize::computePoses<Pose2>(orientations, &poseGraph);
51 
52  // posesInFile is seriously noisy, so we check error of recovered poses
53  EXPECT_DOUBLES_EQUAL(0.0810283, inputGraph->error(poses), 1e-6);
54 }
55 
56 /* ************************************************************************* */
57 TEST(InitializePose3, computePoses3D) {
58  const string g2oFile = findExampleDataFile("Klaus3");
60  Values::shared_ptr posesInFile;
61  bool is3D = true;
62  boost::tie(inputGraph, posesInFile) = readG2o(g2oFile, is3D);
63 
64  auto priorModel = noiseModel::Unit::Create(6);
65  inputGraph->addPrior(0, posesInFile->at<Pose3>(0), priorModel);
66 
67  auto poseGraph = initialize::buildPoseGraph<Pose3>(*inputGraph);
68 
69  auto I = genericValue(Rot3());
70  Values orientations;
71  for (size_t i : {0, 1, 2})
72  orientations.insert(i, posesInFile->at<Pose3>(i).rotation());
73  Values poses = initialize::computePoses<Pose3>(orientations, &poseGraph);
74  EXPECT(assert_equal(*posesInFile, poses, 0.1)); // TODO(frank): very loose !!
75 }
76 
77 /* ************************************************************************* */
78 int main() {
79  TestResult tr;
80  return TestRegistry::runAllTests(tr);
81 }
82 /* ************************************************************************* */
static int runAllTests(TestResult &result)
void insert(Key j, const Value &val)
Definition: Values.cpp:140
common code between lago.* (2D) and InitializePose3.* (3D)
Definition: Half.h:150
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:162
string findExampleDataFile(const string &name)
Definition: dataset.cpp:65
boost::shared_ptr< This > shared_ptr
TEST(InitializePose3, computePoses2D)
#define EXPECT(condition)
Definition: Test.h:151
const Rot2 & rotation() const
rotation
Definition: Pose2.h:233
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static const Matrix I
Definition: lago.cpp:35
traits
Definition: chartTesting.h:28
GenericValue< T > genericValue(const T &v)
Definition: GenericValue.h:212
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
int main()
2D Pose
GraphAndValues readG2o(const 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:615
3D Pose
utility functions for loading datasets
const Rot3 & rotation(OptionalJacobian< 3, 6 > Hself=boost::none) const
get rotation
Definition: Pose3.cpp:266


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:47:23