g2o
Loading...
Searching...
No Matches
Functions
simple_optimize.cpp File Reference
#include <iostream>
#include "g2o/core/factory.h"
#include "g2o/core/optimization_algorithm_factory.h"
#include "g2o/core/sparse_optimizer.h"
#include "g2o/stuff/command_args.h"
Include dependency graph for simple_optimize.cpp:

Go to the source code of this file.

Functions

 G2O_USE_TYPE_GROUP (slam2d)
 
 G2O_USE_TYPE_GROUP (slam3d)
 
 G2O_USE_OPTIMIZATION_LIBRARY (eigen)
 
int main (int argc, char **argv)
 

Function Documentation

◆ G2O_USE_OPTIMIZATION_LIBRARY()

G2O_USE_OPTIMIZATION_LIBRARY ( eigen  )

◆ G2O_USE_TYPE_GROUP() [1/2]

G2O_USE_TYPE_GROUP ( slam2d  )

◆ G2O_USE_TYPE_GROUP() [2/2]

G2O_USE_TYPE_GROUP ( slam3d  )

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 42 of file simple_optimize.cpp.

42 {
43 // Command line parsing
44 int maxIterations;
45 string outputFilename;
46 string inputFilename;
47 CommandArgs arg;
48 arg.param("i", maxIterations, 10,
49 "perform n iterations, if negative consider the gain");
50 arg.param("o", outputFilename, "", "output final version of the graph");
51 arg.paramLeftOver("graph-input", inputFilename, "",
52 "graph file which will be processed");
53 arg.parseArgs(argc, argv);
54
55 // NOTE: We skip to fix a vertex here, either this is stored in the file
56 // itself or Levenberg will handle it.
57
58 // create the optimizer to load the data and carry out the optimization
59 SparseOptimizer optimizer;
60 optimizer.setVerbose(true);
61
62 // allocate the solver
64 optimizer.setAlgorithm(
66 solverProperty));
67
68 ifstream ifs(inputFilename.c_str());
69 if (!ifs) {
70 cerr << "unable to open " << inputFilename << endl;
71 return 1;
72 }
73 optimizer.load(ifs);
74 optimizer.initializeOptimization();
75 optimizer.optimize(maxIterations);
76
77 if (outputFilename.size() > 0) {
78 if (outputFilename == "-") {
79 cerr << "saving to stdout";
80 optimizer.save(cout);
81 } else {
82 cerr << "saving " << outputFilename << " ... ";
83 optimizer.save(outputFilename.c_str());
84 }
85 cerr << "done." << endl;
86 }
87 return 0;
88}
Command line parsing of argc and argv.
bool parseArgs(int argc, char **argv, bool exitOnError=true)
void paramLeftOver(const std::string &name, std::string &p, const std::string &defValue, const std::string &desc, bool optional=false)
void param(const std::string &name, bool &p, bool defValue, const std::string &desc)
static OptimizationAlgorithmFactory * instance()
return the instance
int optimize(int iterations, bool online=false)
void setVerbose(bool verbose)
virtual bool initializeOptimization(HyperGraph::EdgeSet &eset)
void setAlgorithm(OptimizationAlgorithm *algorithm)
virtual bool save(std::ostream &os, int level=0) const
save the graph to a stream. Again uses the Factory system.
virtual bool load(std::istream &is)

References g2o::SparseOptimizer::initializeOptimization(), g2o::OptimizationAlgorithmFactory::instance(), g2o::OptimizableGraph::load(), g2o::SparseOptimizer::optimize(), g2o::CommandArgs::param(), g2o::CommandArgs::paramLeftOver(), g2o::CommandArgs::parseArgs(), g2o::OptimizableGraph::save(), g2o::SparseOptimizer::setAlgorithm(), and g2o::SparseOptimizer::setVerbose().