65int main(
int argc,
char** argv) {
70 string outputfilename;
74 commandLineArguments.
param(
"i", maxIterations, 10,
"perform n iterations");
75 commandLineArguments.
param(
"v", verbose,
false,
76 "verbose output of the optimization process");
77 commandLineArguments.
param(
"guess", initialGuess,
false,
78 "initial guess based on spanning tree");
79 commandLineArguments.
param(
"gnudump", gnudump,
"",
80 "dump to gnuplot data file");
81 commandLineArguments.
param(
"o", outputfilename,
"",
82 "output final version of the graph");
83 commandLineArguments.
paramLeftOver(
"gm2dl-input", inputFilename,
"",
84 "gm2dl file which will be processed");
86 commandLineArguments.
parseArgs(argc, argv);
100 cerr <<
"Error while loading gm2dl file" << endl;
104 dynamic_cast<VertexSE2*
>(optimizer.
vertex(numeric_limits<int>::max()));
107 cerr <<
"Initial laser offset "
115 cerr <<
"# cannot find a vertex to fix in this thing" << endl;
118 cerr <<
"# graph is fixed by node " << gauge->
id() << endl;
122 cerr <<
"# graph is fixed by priors" << endl;
132 cerr <<
CL_RED(
"Warning: d.visited().size() != optimizer.vertices().size()")
134 cerr <<
"visited: " << d.
visited().size() << endl;
135 cerr <<
"vertices: " << optimizer.
vertices().size() << endl;
137 for (SparseOptimizer::VertexIDMap::const_iterator it =
139 it != optimizer.
vertices().end(); ++it) {
142 if (d.
visited().count(v) == 0) {
143 cerr <<
"\t unvisited vertex " << it->first <<
" "
144 <<
static_cast<void*
>(v) << endl;
152 cerr <<
"Initial chi2 = " << FIXED(optimizer.
chi2()) << endl;
159 int i = optimizer.
optimize(maxIterations);
160 if (maxIterations > 0 && !i) {
161 cerr <<
"optimize failed, result might be invalid" << endl;
165 cerr <<
"Calibrated laser offset "
169 if (outputfilename.size() > 0) {
171 cerr <<
"Writing " << outputfilename <<
" ... ";
173 cerr << (writeStatus ?
"done." :
"failed") << endl;
176 if (gnudump.size() > 0) {
177 ofstream fout(gnudump.c_str());
178 for (SparseOptimizer::VertexIDMap::const_iterator it =
180 it != optimizer.
vertices().end(); ++it) {
const EstimateType & estimate() const
return the current estimate of the vertex
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 bool readGm2dl(const std::string &filename, SparseOptimizer &optimizer, bool overrideCovariances=false)
static bool updateLaserData(SparseOptimizer &optimizer)
static bool writeGm2dl(const std::string &filename, const SparseOptimizer &optimizer)
int id() const
returns the id
const VertexIDMap & vertices() const
A general case Vertex for optimization.
void setFixed(bool fixed)
true => this node should be considered fixed during the optimization
create solvers based on their short name
OptimizationAlgorithm * construct(const std::string &tag, OptimizationAlgorithmProperty &solverProperty) const
static OptimizationAlgorithmFactory * instance()
return the instance
Vector3 toVector() const
convert to a 3D vector (x, y, theta)
void computeActiveErrors()
int optimize(int iterations, bool online=false)
void setForceStopFlag(bool *flag)
void setVerbose(bool verbose)
virtual bool initializeOptimization(HyperGraph::EdgeSet &eset)
void setAlgorithm(OptimizationAlgorithm *algorithm)
virtual Vertex * findGauge()
finds a gauge in the graph to remove the undefined dof.
2D pose Vertex, (x,y,theta)
#define G2O_USE_TYPE_GROUP(typeGroupName)
#define __PRETTY_FUNCTION__
#define G2O_USE_OPTIMIZATION_LIBRARY(libraryname)
void sigquit_handler(int sig)
HyperGraph::VertexSet & visited()
void shortestPaths(HyperGraph::Vertex *v, HyperDijkstra::CostFunction *cost, double maxDistance=std::numeric_limits< double >::max(), double comparisonConditioner=1e-3, bool directed=false, double maxEdgeCost=std::numeric_limits< double >::max())
double chi2() const
returns the chi2 of the current configuration
Vertex * vertex(int id)
returns the vertex number id appropriately casted
describe the properties of a solver
utility functions for handling time related stuff