34using SlamLinearSolver =
39 auto linearSolverGN = std::make_unique<SlamLinearSolver>();
40 linearSolverGN->setBlockOrdering(
false);
42 std::make_unique<SlamBlockSolver>(std::move(linearSolverGN)));
47 auto linearSolverLM = std::make_unique<SlamLinearSolver>();
48 linearSolverLM->setBlockOrdering(
false);
50 std::make_unique<SlamBlockSolver>(std::move(linearSolverLM)));
60 viewer->graph->clear();
61 QString filename = QFileDialog::getOpenFileName(
62 this,
"Load g2o file",
"",
"g2o files (*.g2o);;All Files (*)");
63 if (!filename.isNull()) {
64 ifstream ifs(filename.toStdString().c_str());
65 viewer->graph->load(ifs);
66 cerr <<
"Graph loaded with " << viewer->graph->vertices().size()
67 <<
" vertices and " << viewer->graph->edges().size() <<
" Measurements"
75 QString filename = QFileDialog::getSaveFileName(
this,
"Save g2o file",
"",
77 if (!filename.isNull()) {
78 ofstream fout(filename.toStdString().c_str());
79 viewer->graph->save(fout);
81 cerr <<
"Saved " << filename.toStdString() << endl;
83 cerr <<
"Error while saving file" << endl;
90 if (viewer->graph->vertices().size() == 0 ||
91 viewer->graph->edges().size() == 0) {
92 cerr <<
"Graph has no vertices / edges" << endl;
96 viewer->graph->initializeOptimization();
98 if (rbGauss->isChecked())
99 viewer->graph->setAlgorithm(createGauss());
100 else if (rbLevenberg->isChecked())
101 viewer->graph->setAlgorithm(createLevenberg());
103 viewer->graph->setAlgorithm(createGauss());
105 int maxIterations = spIterations->value();
106 int iter = viewer->graph->optimize(maxIterations);
107 if (maxIterations > 0 && !iter) {
108 cerr <<
"Optimization failed, result might be invalid" << endl;
111 if (cbCovariances->isChecked()) {
112 std::vector<std::pair<int, int> > cov_vertices;
113 for (
const auto& vertex_index : viewer->graph->vertices()) {
116 if (!vertex->fixed())
117 cov_vertices.emplace_back(vertex->hessianIndex(),
118 vertex->hessianIndex());
120 viewer->covariances.clear(
true);
121 std::cerr <<
"Compute covariance matrices" << std::endl;
123 viewer->
graph->computeMarginals(viewer->covariances, cov_vertices);
124 viewer->drawCovariance = cov_result;
125 std::cerr << (cov_result ?
"Done." :
"Failed") << std::endl;
127 viewer->drawCovariance =
false;
133 viewer->graph->computeInitialGuess();
134 viewer->drawCovariance =
false;
139 if (viewer->graph->vertices().size() == 0 ||
140 viewer->graph->edges().size() == 0) {
145 bool gaugeFreedom = viewer->graph->gaugeFreedom();
149 cerr <<
"cannot find a vertex to fix in this thing" << endl;
152 cerr <<
"graph is fixed by node " << gauge->
id() << endl;
156 cerr <<
"graph is fixed by priors" << endl;
159 viewer->graph->setVerbose(
true);
160 viewer->graph->computeActiveErrors();
void on_btnOptimize_clicked()
void on_actionSave_triggered(bool)
void on_btnInitialGuess_clicked()
void on_actionLoad_triggered(bool)
MainWindow(QWidget *parent=0)
void on_actionQuit_triggered(bool)
Implementation of a solver operating on the blocks of the Hessian.
int id() const
returns the id
linear solver which uses the sparse Cholesky solver from Eigen
A general case Vertex for optimization.
const OptimizableGraph * graph() const
void setFixed(bool fixed)
true => this node should be considered fixed during the optimization
Implementation of the Gauss Newton Algorithm.
Implementation of the Levenberg Algorithm.
Generic interface for a non-linear solver operating on a graph.
traits to summarize the properties of the fixed size optimization problem