mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-02 17:40:23 +08:00
Refactoring of the cameraStereoImages and cameraRGBDImages classes (now inheriting from CameraImages) for easy setting of laser scan path, timestamps path and ground truth path.
Added graph::importPoses(). Can now have a ground truth published with SensorData (filled optionally by CameraImages classes). Increased database closing time performance when the database is not saved. Added ParametersToolBox widget in DatabaseViewer for core parameters (refactoring done to make easy access to all rtabmap parameters in DatabaseViewer). Added Parameters::getType(key). Added Transform::interpolate() to interpolate between two transforms (SLERP) Updated pf_filter.m and added test_pf_filter.m MATLAB scripts (making easier to compare with a ground truth) UPlot: can now save all curve data of a figure in one action (see right-click on legend area->"Copy all curve data to clipboard")
This commit is contained in:
516
guilib/src/ParametersToolBox.cpp
Normal file
516
guilib/src/ParametersToolBox.cpp
Normal file
@@ -0,0 +1,516 @@
|
||||
/*
|
||||
Copyright (c) 2010-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Universite de Sherbrooke nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
//
|
||||
// Original version from Find-Object: https://github.com/introlab/find-object
|
||||
//
|
||||
|
||||
#include <rtabmap/core/Parameters.h>
|
||||
#include <rtabmap/core/Optimizer.h>
|
||||
|
||||
#include "ParametersToolBox.h"
|
||||
#include <QComboBox>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QLineEdit>
|
||||
#include <QLabel>
|
||||
#include <QGroupBox>
|
||||
#include <QCheckBox>
|
||||
#include <QVBoxLayout>
|
||||
#include <QMessageBox>
|
||||
#include <stdio.h>
|
||||
#include <rtabmap/utilite/ULogger.h>
|
||||
#include <rtabmap/utilite/UConversion.h>
|
||||
#include <opencv2/opencv_modules.hpp>
|
||||
|
||||
namespace rtabmap {
|
||||
|
||||
ParametersToolBox::ParametersToolBox(QWidget *parent) :
|
||||
QToolBox(parent),
|
||||
parameters_(Parameters::getDefaultParameters())
|
||||
{
|
||||
}
|
||||
|
||||
ParametersToolBox::~ParametersToolBox()
|
||||
{
|
||||
}
|
||||
|
||||
QWidget * ParametersToolBox::getParameterWidget(const QString & key)
|
||||
{
|
||||
return this->findChild<QWidget*>(key);
|
||||
}
|
||||
|
||||
QStringList ParametersToolBox::resetPage(int index)
|
||||
{
|
||||
QStringList paramChanged;
|
||||
const QObjectList & children = this->widget(index)->children();
|
||||
for(int j=0; j<children.size();++j)
|
||||
{
|
||||
QString key = children.at(j)->objectName();
|
||||
// ignore working memory
|
||||
QString group = key.split("/").first();
|
||||
if(!ignoredGroups_.contains(group))
|
||||
{
|
||||
std::string value = Parameters::getDefaultParameters().at(key.toStdString());
|
||||
parameters_.at(key.toStdString()) = value;
|
||||
|
||||
if(qobject_cast<QComboBox*>(children.at(j)))
|
||||
{
|
||||
if(((QComboBox*)children.at(j))->currentIndex() != QString::fromStdString(value).split(':').first().toInt())
|
||||
{
|
||||
((QComboBox*)children.at(j))->setCurrentIndex(QString::fromStdString(value).split(':').first().toInt());
|
||||
paramChanged.append(key);
|
||||
}
|
||||
}
|
||||
else if(qobject_cast<QSpinBox*>(children.at(j)))
|
||||
{
|
||||
if(((QSpinBox*)children.at(j))->value() != uStr2Int(value))
|
||||
{
|
||||
((QSpinBox*)children.at(j))->setValue(uStr2Int(value));
|
||||
paramChanged.append(key);
|
||||
}
|
||||
}
|
||||
else if(qobject_cast<QDoubleSpinBox*>(children.at(j)))
|
||||
{
|
||||
if(((QDoubleSpinBox*)children.at(j))->value() != uStr2Double(value))
|
||||
{
|
||||
((QDoubleSpinBox*)children.at(j))->setValue(uStr2Double(value));
|
||||
paramChanged.append(key);
|
||||
}
|
||||
}
|
||||
else if(qobject_cast<QCheckBox*>(children.at(j)))
|
||||
{
|
||||
if(((QCheckBox*)children.at(j))->isChecked() != uStr2Bool(value))
|
||||
{
|
||||
((QCheckBox*)children.at(j))->setChecked(uStr2Bool(value));
|
||||
paramChanged.append(key);
|
||||
}
|
||||
}
|
||||
else if(qobject_cast<QLineEdit*>(children.at(j)))
|
||||
{
|
||||
if(((QLineEdit*)children.at(j))->text().compare(QString::fromStdString(value)) != 0)
|
||||
{
|
||||
((QLineEdit*)children.at(j))->setText(QString::fromStdString(value));
|
||||
paramChanged.append(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return paramChanged;
|
||||
}
|
||||
|
||||
void ParametersToolBox::resetCurrentPage()
|
||||
{
|
||||
this->blockSignals(true);
|
||||
QStringList paramChanged = this->resetPage(this->currentIndex());
|
||||
this->blockSignals(false);
|
||||
Q_EMIT parametersChanged(paramChanged);
|
||||
}
|
||||
|
||||
void ParametersToolBox::resetAllPages()
|
||||
{
|
||||
QStringList paramChanged;
|
||||
this->blockSignals(true);
|
||||
for(int i=0; i< this->count(); ++i)
|
||||
{
|
||||
paramChanged.append(this->resetPage(i));
|
||||
}
|
||||
this->blockSignals(false);
|
||||
Q_EMIT parametersChanged(paramChanged);
|
||||
}
|
||||
|
||||
void ParametersToolBox::updateParametersVisibility()
|
||||
{
|
||||
//show/hide not used parameters
|
||||
/*QComboBox * descriptorBox = this->findChild<QComboBox*>(Parameters::kFeature2D_2Descriptor());
|
||||
QComboBox * detectorBox = this->findChild<QComboBox*>(Parameters::kFeature2D_1Detector());
|
||||
if(descriptorBox && detectorBox)
|
||||
{
|
||||
QString group = Parameters::kFeature2D_2Descriptor().split('/').first();
|
||||
QWidget * panel = 0;
|
||||
for(int i=0; i<this->count(); ++i)
|
||||
{
|
||||
if(this->widget(i)->objectName().compare(group) == 0)
|
||||
{
|
||||
panel = this->widget(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(panel)
|
||||
{
|
||||
const QObjectList & objects = panel->children();
|
||||
QString descriptorName = descriptorBox->currentText();
|
||||
QString detectorName = detectorBox->currentText();
|
||||
|
||||
for(int i=0; i<objects.size(); ++i)
|
||||
{
|
||||
if(!objects[i]->objectName().isEmpty())
|
||||
{
|
||||
if(objects[i]->objectName().contains(descriptorName) || objects[i]->objectName().contains(detectorName))
|
||||
{
|
||||
((QWidget*)objects[i])->setVisible(true);
|
||||
}
|
||||
else if(objects[i]->objectName().contains("Fast") && detectorName == QString("ORB"))
|
||||
{
|
||||
((QWidget*)objects[i])->setVisible(true); // ORB uses some FAST parameters
|
||||
}
|
||||
else if(!objects[i]->objectName().split('/').at(1).at(0).isDigit())
|
||||
{
|
||||
((QWidget*)objects[i])->setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void ParametersToolBox::setupUi(const QSet<QString> & ignoredGroups)
|
||||
{
|
||||
ignoredGroups_ = ignoredGroups;
|
||||
this->removeItem(0); // remove dummy page used in .ui
|
||||
QWidget * currentItem = 0;
|
||||
const ParametersMap & parameters = Parameters::getDefaultParameters();
|
||||
for(ParametersMap::const_iterator iter=parameters.begin();
|
||||
iter!=parameters.end();
|
||||
++iter)
|
||||
{
|
||||
QStringList splitted = QString::fromStdString(iter->first).split('/');
|
||||
QString group = splitted.first();
|
||||
if(!ignoredGroups_.contains(group))
|
||||
{
|
||||
QString name = splitted.last();
|
||||
if(currentItem == 0 || currentItem->objectName().compare(group) != 0)
|
||||
{
|
||||
currentItem = new QWidget(this);
|
||||
this->addItem(currentItem, group);
|
||||
currentItem->setObjectName(group);
|
||||
QVBoxLayout * layout = new QVBoxLayout(currentItem);
|
||||
currentItem->setLayout(layout);
|
||||
layout->setContentsMargins(0,0,0,0);
|
||||
layout->setSpacing(0);
|
||||
layout->addSpacerItem(new QSpacerItem(0,0, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
||||
|
||||
addParameter(layout, iter->first, iter->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
addParameter((QVBoxLayout*)currentItem->layout(), iter->first, iter->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateParametersVisibility();
|
||||
}
|
||||
|
||||
void ParametersToolBox::updateParameter(const std::string & key, const std::string & value)
|
||||
{
|
||||
QString group = QString::fromStdString(key).split("/").first();
|
||||
if(!ignoredGroups_.contains(group))
|
||||
{
|
||||
QWidget * widget = this->findChild<QWidget*>(key.c_str());
|
||||
QString type = QString::fromStdString(Parameters::getType(key));
|
||||
if(type.compare("string") == 0)
|
||||
{
|
||||
QString valueQt = QString::fromStdString(value);
|
||||
if(valueQt.contains(';'))
|
||||
{
|
||||
// It's a list, just change the index
|
||||
QStringList splitted = valueQt.split(':');
|
||||
((QComboBox*)widget)->setCurrentIndex(splitted.first().toInt());
|
||||
}
|
||||
else
|
||||
{
|
||||
((QLineEdit*)widget)->setText(valueQt);
|
||||
}
|
||||
}
|
||||
else if(type.compare("int") == 0)
|
||||
{
|
||||
((QSpinBox*)widget)->setValue(uStr2Int(value));
|
||||
}
|
||||
else if(type.compare("uint") == 0)
|
||||
{
|
||||
((QSpinBox*)widget)->setValue(uStr2Int(value));
|
||||
}
|
||||
else if(type.compare("double") == 0)
|
||||
{
|
||||
((QDoubleSpinBox*)widget)->setValue(uStr2Double(value));
|
||||
}
|
||||
else if(type.compare("float") == 0)
|
||||
{
|
||||
((QDoubleSpinBox*)widget)->setValue(uStr2Float(value));
|
||||
}
|
||||
else if(type.compare("bool") == 0)
|
||||
{
|
||||
((QCheckBox*)widget)->setChecked(uStr2Bool(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ParametersToolBox::addParameter(
|
||||
QVBoxLayout * layout,
|
||||
const std::string & key,
|
||||
const std::string & value)
|
||||
{
|
||||
std::string type = Parameters::getType(key);
|
||||
if(type.compare("string") == 0)
|
||||
{
|
||||
addParameter(layout, key.c_str(), QString::fromStdString(value));
|
||||
}
|
||||
else if(type.compare("int") == 0)
|
||||
{
|
||||
addParameter(layout, key.c_str(), uStr2Int(value));
|
||||
}
|
||||
else if(type.compare("uint") == 0)
|
||||
{
|
||||
addParameter(layout, key.c_str(), uStr2Int(value));
|
||||
}
|
||||
else if(type.compare("double") == 0)
|
||||
{
|
||||
addParameter(layout, key.c_str(), uStr2Double(value));
|
||||
}
|
||||
else if(type.compare("float") == 0)
|
||||
{
|
||||
addParameter(layout, key.c_str(), uStr2Double(value));
|
||||
}
|
||||
else if(type.compare("bool") == 0)
|
||||
{
|
||||
addParameter(layout, key.c_str(), uStr2Bool(value));
|
||||
}
|
||||
}
|
||||
|
||||
void ParametersToolBox::addParameter(QVBoxLayout * layout,
|
||||
const QString & key,
|
||||
const QString & value)
|
||||
{
|
||||
if(value.contains(';'))
|
||||
{
|
||||
QComboBox * widget = new QComboBox(this);
|
||||
widget->setObjectName(key);
|
||||
QStringList splitted = value.split(':');
|
||||
widget->addItems(splitted.last().split(';'));
|
||||
|
||||
widget->setCurrentIndex(splitted.first().toInt());
|
||||
connect(widget, SIGNAL(currentIndexChanged(int)), this, SLOT(changeParameter(int)));
|
||||
addParameter(layout, key, widget);
|
||||
}
|
||||
else
|
||||
{
|
||||
QLineEdit * widget = new QLineEdit(value, this);
|
||||
widget->setObjectName(key);
|
||||
connect(widget, SIGNAL(editingFinished()), this, SLOT(changeParameter()));
|
||||
addParameter(layout, key, widget);
|
||||
}
|
||||
}
|
||||
|
||||
void ParametersToolBox::addParameter(QVBoxLayout * layout,
|
||||
const QString & key,
|
||||
const double & value)
|
||||
{
|
||||
QDoubleSpinBox * widget = new QDoubleSpinBox(this);
|
||||
double def = uStr2Double(Parameters::getDefaultParameters().at(key.toStdString()));
|
||||
if(def<0.01)
|
||||
{
|
||||
widget->setDecimals(4);
|
||||
}
|
||||
else if(def<0.1)
|
||||
{
|
||||
widget->setDecimals(3);
|
||||
}
|
||||
|
||||
if(def>=0.0)
|
||||
{
|
||||
widget->setMaximum(def*1000000.0);
|
||||
}
|
||||
else if(def==0.0)
|
||||
{
|
||||
widget->setMaximum(1000000.0);
|
||||
}
|
||||
else if(def<0.0)
|
||||
{
|
||||
widget->setMinimum(def*1000000.0);
|
||||
widget->setMaximum(0.0);
|
||||
}
|
||||
widget->setValue(value);
|
||||
widget->setObjectName(key);
|
||||
connect(widget, SIGNAL(editingFinished()), this, SLOT(changeParameter()));
|
||||
addParameter(layout, key, widget);
|
||||
}
|
||||
|
||||
void ParametersToolBox::addParameter(QVBoxLayout * layout,
|
||||
const QString & key,
|
||||
const int & value)
|
||||
{
|
||||
QSpinBox * widget = new QSpinBox(this);
|
||||
int def = uStr2Int(Parameters::getDefaultParameters().at(key.toStdString()));
|
||||
|
||||
if(def>0)
|
||||
{
|
||||
widget->setMaximum(def*1000000);
|
||||
}
|
||||
else if(def == 0)
|
||||
{
|
||||
widget->setMaximum(1000000);
|
||||
}
|
||||
else if(def<0)
|
||||
{
|
||||
widget->setMinimum(def*1000000);
|
||||
widget->setMaximum(0);
|
||||
}
|
||||
widget->setValue(value);
|
||||
widget->setObjectName(key);
|
||||
|
||||
if(key.compare(Parameters::kVisFeatureType().c_str()) == 0)
|
||||
{
|
||||
if(RTABMAP_NONFREE == 0)
|
||||
{
|
||||
if(value <= 1)
|
||||
{
|
||||
UWARN("SURF/SIFT not available, setting feature default to FAST/BRIEF.");
|
||||
widget->setValue(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(key.compare(Parameters::kOptimizerStrategy().c_str()) == 0)
|
||||
{
|
||||
if(!Optimizer::isAvailable(Optimizer::kTypeG2O))
|
||||
{
|
||||
if(value == 1)
|
||||
{
|
||||
UWARN("g2o is not available, setting optimization default to TORO.");
|
||||
widget->setValue(0);
|
||||
}
|
||||
}
|
||||
if(!Optimizer::isAvailable(Optimizer::kTypeGTSAM))
|
||||
{
|
||||
if(value == 2)
|
||||
{
|
||||
UWARN("GTSAM is not available, setting optimization default to TORO.");
|
||||
widget->setValue(0);
|
||||
}
|
||||
}
|
||||
if(!Optimizer::isAvailable(Optimizer::kTypeG2O) && !Optimizer::isAvailable(Optimizer::kTypeGTSAM))
|
||||
{
|
||||
widget->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
connect(widget, SIGNAL(editingFinished()), this, SLOT(changeParameter()));
|
||||
addParameter(layout, key, widget);
|
||||
}
|
||||
|
||||
void ParametersToolBox::addParameter(QVBoxLayout * layout,
|
||||
const QString & key,
|
||||
const bool & value)
|
||||
{
|
||||
QCheckBox * widget = new QCheckBox(this);
|
||||
widget->setChecked(value);
|
||||
widget->setObjectName(key);
|
||||
connect(widget, SIGNAL(stateChanged(int)), this, SLOT(changeParameter(int)));
|
||||
addParameter(layout, key, widget);
|
||||
}
|
||||
|
||||
void ParametersToolBox::addParameter(QVBoxLayout * layout, const QString & key, QWidget * widget)
|
||||
{
|
||||
QHBoxLayout * hLayout = new QHBoxLayout();
|
||||
layout->insertLayout(layout->count()-1, hLayout);
|
||||
QString tmp = key.split('/').last();
|
||||
if(tmp.at(0).isDigit())
|
||||
{
|
||||
tmp.remove(0,1);
|
||||
}
|
||||
QLabel * label = new QLabel(tmp, this);
|
||||
label->setObjectName(key+"/label");
|
||||
label->setToolTip(QString("<FONT>%1</FONT>").arg(Parameters::getDescription(key.toStdString()).c_str()));
|
||||
label->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
||||
hLayout->addWidget(label);
|
||||
hLayout->addWidget(widget);
|
||||
}
|
||||
|
||||
void ParametersToolBox::changeParameter(const QString & value)
|
||||
{
|
||||
if(sender())
|
||||
{
|
||||
parameters_.at(sender()->objectName().toStdString()) = value.toStdString();
|
||||
QStringList paramChanged;
|
||||
paramChanged.append(sender()->objectName());
|
||||
Q_EMIT parametersChanged(paramChanged);
|
||||
}
|
||||
}
|
||||
void ParametersToolBox::changeParameter()
|
||||
{
|
||||
if(sender())
|
||||
{
|
||||
QDoubleSpinBox * doubleSpinBox = qobject_cast<QDoubleSpinBox*>(sender());
|
||||
QSpinBox * spinBox = qobject_cast<QSpinBox*>(sender());
|
||||
QLineEdit * lineEdit = qobject_cast<QLineEdit*>(sender());
|
||||
if(doubleSpinBox)
|
||||
{
|
||||
parameters_.at(sender()->objectName().toStdString()) = uNumber2Str(doubleSpinBox->value());
|
||||
}
|
||||
else if(spinBox)
|
||||
{
|
||||
parameters_.at(sender()->objectName().toStdString()) = uNumber2Str(spinBox->value());
|
||||
}
|
||||
else if(lineEdit)
|
||||
{
|
||||
parameters_.at(sender()->objectName().toStdString()) = lineEdit->text().toStdString();
|
||||
}
|
||||
QStringList paramChanged;
|
||||
paramChanged.append(sender()->objectName());
|
||||
Q_EMIT parametersChanged(paramChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void ParametersToolBox::changeParameter(const int & value)
|
||||
{
|
||||
if(sender())
|
||||
{
|
||||
QStringList paramChanged;
|
||||
QComboBox * comboBox = qobject_cast<QComboBox*>(sender());
|
||||
QCheckBox * checkBox = qobject_cast<QCheckBox*>(sender());
|
||||
if(comboBox)
|
||||
{
|
||||
QStringList items;
|
||||
for(int i=0; i<comboBox->count(); ++i)
|
||||
{
|
||||
items.append(comboBox->itemText(i));
|
||||
}
|
||||
QString merged = QString::number(value) + QString(":") + items.join(";");
|
||||
parameters_.at(sender()->objectName().toStdString()) = merged.toStdString();
|
||||
|
||||
this->updateParametersVisibility();
|
||||
}
|
||||
else if(checkBox)
|
||||
{
|
||||
parameters_.at(sender()->objectName().toStdString()) = uBool2Str(value==Qt::Checked?true:false);
|
||||
}
|
||||
|
||||
paramChanged.append(sender()->objectName());
|
||||
Q_EMIT parametersChanged(paramChanged);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace find_object
|
||||
Reference in New Issue
Block a user