26 using namespace gtsam;
28 int main(
const int argc,
const char* argv[]) {
39 boost::tie(graph, initial) =
readG2o(g2oFile, is3D);
42 auto priorModel = noiseModel::Diagonal::Variances(
43 (
Vector(6) << 1
e-6, 1
e-6, 1
e-6, 1
e-4, 1
e-4, 1
e-4).finished());
45 for (
const auto key_value : *initial) {
46 std::cout <<
"Adding prior to g2o file " << std::endl;
47 firstKey = key_value.key;
52 std::cout <<
"Optimizing the factor graph" << std::endl;
57 std::cout <<
"Optimization complete" << std::endl;
59 std::cout <<
"initial error=" << graph->error(*initial) << std::endl;
60 std::cout <<
"final error=" << graph->error(result) << std::endl;
63 result.
print(
"result");
66 std::cout <<
"Writing results to file: " << outputFile << std::endl;
69 boost::tie(graphNoKernel, initial2) =
readG2o(g2oFile);
70 writeG2o(*graphNoKernel, result, outputFile);
71 std::cout <<
"done! " << std::endl;
void writeG2o(const NonlinearFactorGraph &graph, const Values &estimate, const string &filename)
This function writes a g2o file from NonlinearFactorGraph and a Values structure. ...
virtual const Values & optimize()
NonlinearFactorGraph graph
int main(const int argc, const char *argv[])
string findExampleDataFile(const string &name)
boost::shared_ptr< This > shared_ptr
void setVerbosity(const std::string &src)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static SmartStereoProjectionParams params
void print(const std::string &str="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
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...
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
utility functions for loading datasets
std::uint64_t Key
Integer nonlinear key type.