30 #include <QFileDialog> 31 #include <QStandardItemModel> 32 #include <QDoubleValidator> 42 QMainWindow(parent, flags),
43 _lastSolver(-1), _currentSolver(0), _viewerPropertiesWidget(0), _optimizerPropertiesWidget(0)
46 leKernelWidth->setValidator(
new QDoubleValidator(-numeric_limits<double>::max(), numeric_limits<double>::max(), 7,
this));
47 plainTextEdit->setMaximumBlockCount(1000);
49 QObject::connect(cbDrawAxis, SIGNAL(toggled(
bool)), viewer, SLOT(setAxisIsDrawn(
bool)));
58 QString filename = QFileDialog::getOpenFileName(
this,
"Load g2o file",
"",
"g2o files (*.g2o);;All Files (*)");
59 if (! filename.isNull()) {
66 QString filename = QFileDialog::getSaveFileName(
this,
"Save g2o file",
"",
"g2o files (*.g2o)");
67 if (! filename.isNull()) {
68 ofstream fout(filename.toStdString().c_str());
69 viewer->graph->save(fout);
71 cerr <<
"Saved " << filename.toStdString() << endl;
73 cerr <<
"Error while saving file" << endl;
79 if (viewer->graph->vertices().size() == 0 || viewer->graph->edges().size() == 0) {
80 cerr <<
"Graph has no vertices / egdes" << endl;
84 bool allocatedNewSolver;
86 if (! allocateStatus) {
87 cerr <<
"Error while allocating solver" << endl;
90 if (allocatedNewSolver)
100 int maxIterations = spIterations->value();
101 int iter = viewer->graph->optimize(maxIterations);
102 if (maxIterations > 0 && !iter){
103 cerr <<
"Optimization failed, result might be invalid" << endl;
107 btnForceStop->hide();
109 viewer->setUpdateDisplay(
true);
116 if (viewer->graph->activeEdges().size() == 0)
117 viewer->graph->initializeOptimization();
119 switch (cbxIniitialGuessMethod->currentIndex()) {
122 viewer->graph->computeInitialGuess();
128 viewer->graph->computeInitialGuess(costFunction);
136 viewer->setUpdateDisplay(
true);
142 if (viewer->graph->activeEdges().size() == 0)
143 viewer->graph->initializeOptimization();
145 viewer->graph->setToOrigin();
146 viewer->setUpdateDisplay(
true);
152 if (viewer->graph->vertices().size() == 0 || viewer->graph->edges().size() == 0) {
157 bool gaugeFreedom = viewer->graph->gaugeFreedom();
161 cerr <<
"cannot find a vertex to fix in this thing" << endl;
164 cerr <<
"graph is fixed by node " << gauge->
id() << endl;
168 cerr <<
"graph is fixed by priors or nodes are already fixed" << endl;
171 viewer->graph->setVerbose(
true);
182 coOptimizer->clear();
186 bool varFound =
false;
188 for (OptimizationAlgorithmFactory::CreatorList::const_iterator it = knownSolvers.begin(); it != knownSolvers.end(); ++it) {
190 if (sp.
name ==
"gn_var" || sp.
name ==
"gn_var_cholmod") {
198 for (OptimizationAlgorithmFactory::CreatorList::const_iterator it = knownSolvers.begin(); it != knownSolvers.end(); ++it) {
200 if (sp.
type == varType) {
201 coOptimizer->addItem(QString::fromStdString(sp.
name));
207 map<string, vector<OptimizationAlgorithmProperty> > solverLookUp;
209 for (OptimizationAlgorithmFactory::CreatorList::const_iterator it = knownSolvers.begin(); it != knownSolvers.end(); ++it) {
211 if (varFound && varType == sp.
type)
213 solverLookUp[sp.
type].push_back(sp);
216 for (map<
string, vector<OptimizationAlgorithmProperty> >::iterator it = solverLookUp.begin(); it != solverLookUp.end(); ++it) {
218 coOptimizer->insertSeparator(coOptimizer->count());
221 const vector<OptimizationAlgorithmProperty>& vsp = it->second;
222 for (
size_t j = 0; j < vsp.size(); ++j) {
223 coOptimizer->addItem(QString::fromStdString(vsp[j].name));
231 ifstream ifs(filename.toStdString().c_str());
234 viewer->graph->clear();
235 bool loadStatus = viewer->graph->load(ifs);
239 viewer->setUpdateDisplay(
true);
250 qobject_cast<QStandardItemModel *>(coOptimizer->model())->item(i)->setEnabled(suitableSolver);
257 if (coOptimizer->count() == 0) {
258 cerr <<
"No solvers available" << endl;
261 int currentIndex = coOptimizer->currentIndex();
262 bool enabled = qobject_cast<QStandardItemModel *>(coOptimizer->model())->item(currentIndex)->isEnabled();
265 cerr <<
"selected solver is not enabled" << endl;
272 allocatedNewSolver =
true;
273 QString strSolver = coOptimizer->currentText();
277 viewer->graph->setAlgorithm(0);
278 delete algorithmPointer;
293 cerr <<
"Marginalizing Landmarks" << endl;
294 for (SparseOptimizer::VertexIDMap::const_iterator it = optimizer->
vertices().begin(); it != optimizer->
vertices().end(); ++it) {
301 cerr <<
"Preparing (no marginalization of Landmarks)" << endl;
302 for (SparseOptimizer::VertexIDMap::const_iterator it = optimizer->
vertices().begin(); it != optimizer->
vertices().end(); ++it) {
307 viewer->graph->initializeOptimization();
314 bool robustKernel = cbRobustKernel->isChecked();
315 double huberWidth = leKernelWidth->text().toDouble();
318 bool onlyLoop = cbOnlyLoop->isChecked();
321 QString strRobustKernel = coRobustKernel->currentText();
324 cerr << strRobustKernel.toStdString() <<
" is not a valid robust kernel" << endl;
327 for (SparseOptimizer::EdgeSet::const_iterator it = optimizer->
edges().begin(); it != optimizer->
edges().end(); ++it) {
340 for (SparseOptimizer::EdgeSet::const_iterator it = optimizer->
edges().begin(); it != optimizer->
edges().end(); ++it) {
354 viewer->graph->clear();
355 bool loadStatus =
load(filename);
356 cerr <<
"loaded " << filename.toStdString() <<
" with " << viewer->graph->vertices().size()
357 <<
" vertices and " << viewer->graph->edges().size() <<
" measurements" << endl;
365 viewer->setBackgroundColor(QColor::fromRgb(255, 255, 255));
371 viewer->setBackgroundColor(QColor::fromRgb(51, 51, 51));
391 bool allocatedNewSolver;
393 if (! allocateStatus) {
394 cerr <<
"Error while allocating solver" << endl;
397 if (allocatedNewSolver)
409 QString selectedFilter;
410 QString filename = QFileDialog::getSaveFileName(
this,
"Save screen to a file",
"viewer.png",
411 "PNG files (*.png);;JPG files (*.jpg);;EPS files (*.eps)", &selectedFilter);
413 if (! filename.isNull()) {
415 int spacePos = selectedFilter.indexOf(
' ');
416 assert(spacePos > 0 &&
"extracting the image format failed");
417 QString format = selectedFilter.left(spacePos);
419 if (format ==
"JPG") {
420 viewer->setSnapshotQuality(90);
422 viewer->setSnapshotQuality(-1);
424 viewer->setSnapshotFormat(format);
425 viewer->saveSnapshot(filename);
426 cerr <<
"saved snapshot " << filename.toStdString() <<
"(" << format.toStdString() <<
")" << endl;
432 QString filename = QFileDialog::getOpenFileName(
this,
"Load State",
"camera.xml",
"Camera/State file (*.xml)");
433 if (!filename.isEmpty()) {
434 viewer->setStateFileName(filename);
435 viewer->restoreStateFromFile();
436 viewer->setStateFileName(QString::null);
438 cerr <<
"Loaded state from " << filename.toStdString() << endl;
444 QString filename = QFileDialog::getSaveFileName(
this,
"Save State",
"camera.xml",
"Camera/State file (*.xml)");
445 if (!filename.isEmpty()) {
446 viewer->setStateFileName(filename);
447 viewer->saveStateToFile();
448 viewer->setStateFileName(QString::null);
449 cerr <<
"Saved state to " << filename.toStdString() << endl;
455 coRobustKernel->clear();
456 std::vector<std::string> kernels;
457 RobustKernelFactory::instance()->fillKnownKernels(kernels);
458 for (
size_t i = 0; i < kernels.size(); ++i) {
459 coRobustKernel->addItem(QString::fromStdString(kernels[i]));
int id() const
returns the id
void updateRobustKernels()
const Vertex * vertex(size_t i) const
#define __PRETTY_FUNCTION__
const OptimizableGraph * graph() const
const PropertyMap & properties() const
return the properties of the solver
Abstract interface for allocating a robust kernel.
std::string name
name of the solver, e.g., var
describe the properties of a solver
bool loadFromFile(const QString &filename)
void on_btnOptimize_clicked()
void on_actionProperties_triggered(bool)
void updateDisplayedSolvers()
void on_actionLoad_Viewer_State_triggered(bool)
int landmarkDim
dimension of the landmar vertices (-1 if variable)
void on_actionWhite_Background_triggered(bool)
void on_btnSetZero_clicked()
void on_actionSave_Screenshot_triggered(bool)
void setRobustKernel(RobustKernel *ptr)
create solvers based on their short name
const VertexIDMap & vertices() const
void on_btnOptimizerParamaters_clicked()
g2o::OptimizationAlgorithmProperty _currentOptimizationAlgorithmProperty
bool allocateSolver(bool &allocatedNewSolver)
int dimension() const
dimension of the estimated state belonging to this node
const VertexContainer & vertices() const
bool isSolverSuitable(const OptimizationAlgorithmProperty &solverProperty, const std::set< int > &vertDims=std::set< int >()) const
RobustKernel * robustKernel() const
if NOT NULL, error of this edge will be robustifed with the kernel
const EdgeSet & edges() const
void on_actionSave_Viewer_State_triggered(bool)
PropertiesWidget * _optimizerPropertiesWidget
std::vector< g2o::OptimizationAlgorithmProperty > _knownSolvers
A general case Vertex for optimization.
void setMarginalized(bool marginalized)
true => this node should be marginalized out during the optimization
void on_btnInitialGuess_clicked()
void on_actionDefault_Background_triggered(bool)
void on_actionLoad_triggered(bool)
g2o::OptimizationAlgorithm * _currentSolver
virtual void setDelta(double delta)
bool requiresMarginalize
whether the solver requires marginalization of landmarks
virtual RobustKernel * construct()=0
void setFixed(bool fixed)
true => this node should be considered fixed during the optimization
std::list< AbstractOptimizationAlgorithmCreator * > CreatorList
cost for traversing only odometry edges.
bool load(const QString &filename)
std::string desc
short description of the solver
Generic interface for a non-linear solver operating on a graph.
void on_btnForceStop_clicked()
void on_actionSave_triggered(bool)
MainWindow(QWidget *parent=0, Qt::WindowFlags flags=0)
std::set< int > dimensions() const
ViewerPropertiesWidget * _viewerPropertiesWidget
OptimizationAlgorithm * construct(const std::string &tag, OptimizationAlgorithmProperty &solverProperty) const
std::string type
type of solver, e.g., "CSparse Cholesky", "PCG"
void on_actionQuit_triggered(bool)