25 #include <QFileDialog> 32 QMainWindow(parent, flags)
43 viewer->graph->clear();
44 QString filename = QFileDialog::getOpenFileName(
this,
"Load g2o file",
"",
"g2o files (*.g2o);;All Files (*)");
45 if (! filename.isNull()) {
46 ifstream ifs(filename.toStdString().c_str());
47 viewer->graph->load(ifs);
48 cerr <<
"Graph loaded with " << viewer->graph->vertices().size() <<
" vertices and " 49 << viewer->graph->edges().size() <<
" measurments" << endl;
57 QString filename = QFileDialog::getSaveFileName(
this,
"Save g2o file",
"",
"g2o files (*.g2o)");
58 if (! filename.isNull()) {
59 ofstream fout(filename.toStdString().c_str());
60 viewer->graph->save(fout);
62 cerr <<
"Saved " << filename.toStdString() << endl;
64 cerr <<
"Error while saving file" << endl;
75 if (viewer->graph->vertices().size() == 0 || viewer->graph->edges().size() == 0) {
76 cerr <<
"Graph has no vertices / egdes" << endl;
80 viewer->graph->initializeOptimization();
82 if (rbGauss->isChecked())
84 else if (rbLevenberg->isChecked())
89 int maxIterations = spIterations->value();
90 int iter = viewer->graph->optimize(maxIterations);
91 if (maxIterations > 0 && !iter){
92 cerr <<
"Optimization failed, result might be invalid" << endl;
95 if (cbCovariances->isChecked()) {
99 viewer->drawCovariance = cbCovariances->isChecked();
106 viewer->graph->computeInitialGuess();
107 viewer->drawCovariance =
false;
113 if (viewer->graph->vertices().size() == 0 || viewer->graph->edges().size() == 0) {
118 bool gaugeFreedom = viewer->graph->gaugeFreedom();
122 cerr <<
"cannot find a vertex to fix in this thing" << endl;
125 cerr <<
"graph is fixed by node " << gauge->
id() << endl;
129 cerr <<
"graph is fixed by priors" << endl;
132 viewer->graph->setVerbose(
true);
133 viewer->graph->computeActiveErrors();
g2o::OptimizationAlgorithm * solverGaussNewton
int id() const
returns the id
const OptimizableGraph * graph() const
void on_btnOptimize_clicked()
A general case Vertex for optimization.
g2o::OptimizationAlgorithm * solverLevenberg
void on_btnInitialGuess_clicked()
void on_actionLoad_triggered(bool)
void setFixed(bool fixed)
true => this node should be considered fixed during the optimization
void on_actionSave_triggered(bool)
MainWindow(QWidget *parent=0, Qt::WindowFlags flags=0)
void on_actionQuit_triggered(bool)