68 int main(
int argc,
char** argv)
74 string outputfilename;
78 commandLineArguments.
param(
"i", maxIterations, 10,
"perform n iterations");
79 commandLineArguments.
param(
"v", verbose,
false,
"verbose output of the optimization process");
80 commandLineArguments.
param(
"guess", initialGuess,
false,
"initial guess based on spanning tree");
81 commandLineArguments.
param(
"gnudump", gnudump,
"",
"dump to gnuplot data file");
82 commandLineArguments.
param(
"o", outputfilename,
"",
"output final version of the graph");
83 commandLineArguments.
paramLeftOver(
"gm2dl-input", inputFilename,
"",
"gm2dl file which will be processed");
85 commandLineArguments.
parseArgs(argc, argv);
97 if (! Gm2dlIO::readGm2dl(inputFilename, optimizer,
false)) {
98 cerr <<
"Error while loading gm2dl file" << endl;
104 cerr <<
"Initial laser offset " << laserOffset->
estimate().
toVector().transpose() << endl;
111 cerr <<
"# cannot find a vertex to fix in this thing" << endl;
114 cerr <<
"# graph is fixed by node " << gauge->
id() << endl;
118 cerr <<
"# graph is fixed by priors" << endl;
128 cerr <<
CL_RED(
"Warning: d.visited().size() != optimizer.vertices().size()") << endl;
129 cerr <<
"visited: " << d.
visited().size() << endl;
130 cerr <<
"vertices: " << optimizer.
vertices().size() << endl;
132 for (SparseOptimizer::VertexIDMap::const_iterator it = optimizer.
vertices().begin(); it != optimizer.
vertices().end(); ++it) {
134 if (d.
visited().count(v) == 0) {
135 cerr <<
"\t unvisited vertex " << it->first <<
" " << (
void*)v << endl;
143 cerr <<
"Initial chi2 = " << FIXED(optimizer.
chi2()) << endl;
150 int i=optimizer.
optimize(maxIterations);
151 if (maxIterations > 0 && !i){
152 cerr <<
"optimize failed, result might be invalid" << endl;
156 cerr <<
"Calibrated laser offset " << laserOffset->
estimate().
toVector().transpose() << endl;
159 if (outputfilename.size() > 0) {
160 Gm2dlIO::updateLaserData(optimizer);
161 cerr <<
"Writing " << outputfilename <<
" ... ";
162 bool writeStatus = Gm2dlIO::writeGm2dl(outputfilename, optimizer);
163 cerr << (writeStatus ?
"done." :
"failed") << endl;
166 if (gnudump.size() > 0) {
167 ofstream fout(gnudump.c_str());
168 for (SparseOptimizer::VertexIDMap::const_iterator it = optimizer.
vertices().begin(); it != optimizer.
vertices().end(); ++it) {
int id() const
returns the id
#define __PRETTY_FUNCTION__
Command line parsing of argc and argv.
HyperGraph::VertexSet & visited()
G2O_USE_TYPE_GROUP(slam2d)
Vector3D toVector() const
convert to a 3D vector (x, y, theta)
describe the properties of a solver
G2O_USE_OPTIMIZATION_LIBRARY(csparse)
int main(int argc, char **argv)
int optimize(int iterations, bool online=false)
void computeActiveErrors()
2D pose Vertex, (x,y,theta)
create solvers based on their short name
const VertexIDMap & vertices() const
Vertex * vertex(int id)
returns the vertex number id appropriately casted
utility functions for handling time related stuff
virtual Vertex * findGauge()
finds a gauge in the graph to remove the undefined dof.
double chi2() const
returns the chi2 of the current configuration
bool parseArgs(int argc, char **argv, bool exitOnError=true)
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())
void setVerbose(bool verbose)
void setForceStopFlag(bool *flag)
void paramLeftOver(const std::string &name, std::string &p, const std::string &defValue, const std::string &desc, bool optional=false)
void setAlgorithm(OptimizationAlgorithm *algorithm)
void param(const std::string &name, bool &p, bool defValue, const std::string &desc)
A general case Vertex for optimization.
void sigquit_handler(int sig)
const EstimateType & estimate() const
return the current estimate of the vertex
void setFixed(bool fixed)
true => this node should be considered fixed during the optimization
virtual bool initializeOptimization(HyperGraph::EdgeSet &eset)
OptimizationAlgorithm * construct(const std::string &tag, OptimizationAlgorithmProperty &solverProperty) const