Pose3SLAMExample_initializePose3Gradient.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 
21 #include <gtsam/slam/dataset.h>
23 #include <fstream>
24 
25 using namespace std;
26 using namespace gtsam;
27 
28 int main(const int argc, const char* argv[]) {
29  // Read graph from file
30  string g2oFile;
31  if (argc < 2)
32  g2oFile = findExampleDataFile("pose3example.txt");
33  else
34  g2oFile = argv[1];
35 
37  Values::shared_ptr initial;
38  bool is3D = true;
39  boost::tie(graph, initial) = readG2o(g2oFile, is3D);
40 
41  // Add prior on the first key
42  auto priorModel = noiseModel::Diagonal::Variances(
43  (Vector(6) << 1e-6, 1e-6, 1e-6, 1e-4, 1e-4, 1e-4).finished());
44  Key firstKey = 0;
45  for (const auto key_value : *initial) {
46  std::cout << "Adding prior to g2o file " << std::endl;
47  firstKey = key_value.key;
48  graph->addPrior(firstKey, Pose3(), priorModel);
49  break;
50  }
51 
52  std::cout << "Initializing Pose3 - Riemannian gradient" << std::endl;
53  bool useGradient = true;
55  InitializePose3::initialize(*graph, *initial, useGradient);
56  std::cout << "done!" << std::endl;
57 
58  std::cout << "initial error=" << graph->error(*initial) << std::endl;
59  std::cout << "initialization error=" << graph->error(initialization)
60  << std::endl;
61 
62  if (argc < 3) {
63  initialization.print("initialization");
64  } else {
65  const string outputFile = argv[2];
66  std::cout << "Writing results to file: " << outputFile << std::endl;
68  Values::shared_ptr initial2;
69  boost::tie(graphNoKernel, initial2) = readG2o(g2oFile);
70  writeG2o(*graphNoKernel, initialization, outputFile);
71  std::cout << "done! " << std::endl;
72  }
73  return 0;
74 }
Initialize Pose3 in a factor graph.
void writeG2o(const NonlinearFactorGraph &graph, const Values &estimate, const string &filename)
This function writes a g2o file from NonlinearFactorGraph and a Values structure. ...
Definition: dataset.cpp:630
Values initial
Definition: Half.h:150
NonlinearFactorGraph graph
string findExampleDataFile(const string &name)
Definition: dataset.cpp:65
boost::shared_ptr< This > shared_ptr
Array< double, 1, 3 > e(1./3., 0.5, 2.)
int main(const int argc, const char *argv[])
string outputFile
traits
Definition: chartTesting.h:28
void print(const std::string &str="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Definition: Values.cpp:77
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
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Values initialize(const NonlinearFactorGraph &graph, bool useOdometricPath)
Definition: lago.cpp:338
utility functions for loading datasets
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:43:27