65 {
66 int maxIterations;
67 bool verbose;
68 string inputFilename;
69 string gnudump;
70 string outputfilename;
71 bool initialGuess;
72
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");
85
86 commandLineArguments.
parseArgs(argc, argv);
87
90
94
97
98
100 cerr << "Error while loading gm2dl file" << endl;
101 }
102
104 dynamic_cast<VertexSE2*
>(optimizer.
vertex(numeric_limits<int>::max()));
105
106 if (laserOffset) {
107 cerr << "Initial laser offset "
109 }
111
113 if (gaugeFreedom) {
114 if (!gauge) {
115 cerr << "# cannot find a vertex to fix in this thing" << endl;
116 return 2;
117 } else {
118 cerr <<
"# graph is fixed by node " << gauge->
id() << endl;
120 }
121 } else {
122 cerr << "# graph is fixed by priors" << endl;
123 }
124
125
128 d.shortestPaths(gauge, &f);
129
130
131 if (d.visited().size() != optimizer.
vertices().size()) {
132 cerr <<
CL_RED(
"Warning: d.visited().size() != optimizer.vertices().size()")
133 << endl;
134 cerr << "visited: " << d.visited().size() << endl;
135 cerr <<
"vertices: " << optimizer.
vertices().size() << endl;
136 if (1)
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;
146 }
147 }
148 }
149
152 cerr <<
"Initial chi2 = " << FIXED(optimizer.
chi2()) << endl;
153
154
155
156
158
159 int i = optimizer.
optimize(maxIterations);
160 if (maxIterations > 0 && !i) {
161 cerr << "optimize failed, result might be invalid" << endl;
162 }
163
164 if (laserOffset) {
165 cerr << "Calibrated laser offset "
167 }
168
169 if (outputfilename.size() > 0) {
171 cerr << "Writing " << outputfilename << " ... ";
173 cerr << (writeStatus ? "done." : "failed") << endl;
174 }
175
176 if (gnudump.size() > 0) {
177 ofstream fout(gnudump.c_str());
178 for (SparseOptimizer::VertexIDMap::const_iterator it =
180 it != optimizer.
vertices().end(); ++it) {
183 }
184 }
185
186 return 0;
187}
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)
void sigquit_handler(int sig)
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