2011-10-25 15:48:19 +00:00
|
|
|
/*
|
2014-08-06 13:43:29 +00:00
|
|
|
Copyright (c) 2011-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
|
2014-08-11 15:49:53 +00:00
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
2014-08-06 13:43:29 +00:00
|
|
|
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.
|
|
|
|
|
*/
|
2011-10-25 15:48:19 +00:00
|
|
|
|
2014-07-31 20:11:46 +00:00
|
|
|
#include "find_object/Settings.h"
|
|
|
|
|
|
2011-10-25 15:48:19 +00:00
|
|
|
#include "ParametersToolBox.h"
|
|
|
|
|
#include <QtGui/QComboBox>
|
|
|
|
|
#include <QtGui/QDoubleSpinBox>
|
|
|
|
|
#include <QtGui/QLineEdit>
|
|
|
|
|
#include <QtGui/QLabel>
|
|
|
|
|
#include <QtGui/QGroupBox>
|
|
|
|
|
#include <QtGui/QCheckBox>
|
|
|
|
|
#include <QtGui/QVBoxLayout>
|
2012-08-28 13:44:57 +00:00
|
|
|
#include <QtGui/QMessageBox>
|
2011-10-25 15:48:19 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2014-08-06 13:43:29 +00:00
|
|
|
namespace find_object {
|
|
|
|
|
|
2011-10-25 15:48:19 +00:00
|
|
|
ParametersToolBox::ParametersToolBox(QWidget *parent) :
|
|
|
|
|
QToolBox(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParametersToolBox::~ParametersToolBox()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-23 16:44:14 +00:00
|
|
|
QWidget * ParametersToolBox::getParameterWidget(const QString & key)
|
|
|
|
|
{
|
|
|
|
|
return this->findChild<QWidget*>(key);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 19:04:14 +00:00
|
|
|
QStringList ParametersToolBox::resetPage(int index)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-08-29 19:04:14 +00:00
|
|
|
QStringList paramChanged;
|
2012-02-04 22:15:32 +00:00
|
|
|
const QObjectList & children = this->widget(index)->children();
|
2011-10-25 15:48:19 +00:00
|
|
|
for(int j=0; j<children.size();++j)
|
|
|
|
|
{
|
|
|
|
|
QString key = children.at(j)->objectName();
|
2012-02-04 22:15:32 +00:00
|
|
|
// ignore only the nextObjID setting, to avoid problem with saved objects
|
|
|
|
|
if(key.compare(Settings::kGeneral_nextObjID()) != 0)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-02-04 22:15:32 +00:00
|
|
|
QVariant value = Settings::getDefaultParameters().value(key, QVariant());
|
|
|
|
|
if(value.isValid())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-08-29 19:04:14 +00:00
|
|
|
Settings::setParameter(key, value);
|
|
|
|
|
|
2012-02-04 22:15:32 +00:00
|
|
|
if(qobject_cast<QComboBox*>(children.at(j)))
|
|
|
|
|
{
|
2012-08-29 19:04:14 +00:00
|
|
|
if(((QComboBox*)children.at(j))->currentIndex() != value.toString().split(':').first().toInt())
|
|
|
|
|
{
|
|
|
|
|
((QComboBox*)children.at(j))->setCurrentIndex(value.toString().split(':').first().toInt());
|
|
|
|
|
paramChanged.append(key);
|
|
|
|
|
}
|
2012-02-04 22:15:32 +00:00
|
|
|
}
|
|
|
|
|
else if(qobject_cast<QSpinBox*>(children.at(j)))
|
|
|
|
|
{
|
2012-08-29 19:04:14 +00:00
|
|
|
if(((QSpinBox*)children.at(j))->value() != value.toInt())
|
|
|
|
|
{
|
|
|
|
|
((QSpinBox*)children.at(j))->setValue(value.toInt());
|
|
|
|
|
paramChanged.append(key);
|
|
|
|
|
}
|
2012-02-04 22:15:32 +00:00
|
|
|
}
|
|
|
|
|
else if(qobject_cast<QDoubleSpinBox*>(children.at(j)))
|
|
|
|
|
{
|
2012-08-29 19:04:14 +00:00
|
|
|
if(((QDoubleSpinBox*)children.at(j))->value() != value.toDouble())
|
|
|
|
|
{
|
|
|
|
|
((QDoubleSpinBox*)children.at(j))->setValue(value.toDouble());
|
|
|
|
|
paramChanged.append(key);
|
|
|
|
|
}
|
2012-02-04 22:15:32 +00:00
|
|
|
}
|
|
|
|
|
else if(qobject_cast<QCheckBox*>(children.at(j)))
|
|
|
|
|
{
|
2012-08-29 19:04:14 +00:00
|
|
|
if(((QCheckBox*)children.at(j))->isChecked() != value.toBool())
|
|
|
|
|
{
|
|
|
|
|
((QCheckBox*)children.at(j))->setChecked(value.toBool());
|
|
|
|
|
paramChanged.append(key);
|
|
|
|
|
}
|
2012-02-04 22:15:32 +00:00
|
|
|
}
|
|
|
|
|
else if(qobject_cast<QLineEdit*>(children.at(j)))
|
|
|
|
|
{
|
2012-08-29 19:04:14 +00:00
|
|
|
if(((QLineEdit*)children.at(j))->text().compare(value.toString()) != 0)
|
|
|
|
|
{
|
|
|
|
|
((QLineEdit*)children.at(j))->setText(value.toString());
|
|
|
|
|
paramChanged.append(key);
|
|
|
|
|
}
|
2012-02-04 22:15:32 +00:00
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-08-29 19:04:14 +00:00
|
|
|
return paramChanged;
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-04 22:15:32 +00:00
|
|
|
void ParametersToolBox::resetCurrentPage()
|
|
|
|
|
{
|
|
|
|
|
this->blockSignals(true);
|
2012-08-29 19:04:14 +00:00
|
|
|
QStringList paramChanged = this->resetPage(this->currentIndex());
|
2012-02-04 22:15:32 +00:00
|
|
|
this->blockSignals(false);
|
2014-07-08 19:55:03 +00:00
|
|
|
Q_EMIT parametersChanged(paramChanged);
|
2012-02-04 22:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-12 22:21:56 +00:00
|
|
|
void ParametersToolBox::resetAllPages()
|
|
|
|
|
{
|
2012-08-29 19:04:14 +00:00
|
|
|
QStringList paramChanged;
|
2012-02-04 22:15:32 +00:00
|
|
|
this->blockSignals(true);
|
2012-01-12 22:21:56 +00:00
|
|
|
for(int i=0; i< this->count(); ++i)
|
|
|
|
|
{
|
2012-08-29 19:04:14 +00:00
|
|
|
paramChanged.append(this->resetPage(i));
|
2012-01-12 22:21:56 +00:00
|
|
|
}
|
2012-02-04 22:15:32 +00:00
|
|
|
this->blockSignals(false);
|
2014-07-08 19:55:03 +00:00
|
|
|
Q_EMIT parametersChanged(paramChanged);
|
2012-01-12 22:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-24 22:32:54 +00:00
|
|
|
void ParametersToolBox::updateParametersVisibility()
|
|
|
|
|
{
|
|
|
|
|
//show/hide not used parameters
|
|
|
|
|
QComboBox * descriptorBox = this->findChild<QComboBox*>(Settings::kFeature2D_2Descriptor());
|
|
|
|
|
QComboBox * detectorBox = this->findChild<QComboBox*>(Settings::kFeature2D_1Detector());
|
|
|
|
|
if(descriptorBox && detectorBox)
|
|
|
|
|
{
|
|
|
|
|
QString group = Settings::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)
|
|
|
|
|
{
|
2014-04-11 22:30:38 +00:00
|
|
|
if(!objects[i]->objectName().isEmpty())
|
2014-03-24 22:32:54 +00:00
|
|
|
{
|
2014-04-11 22:30:38 +00:00
|
|
|
if(objects[i]->objectName().contains(descriptorName) || objects[i]->objectName().contains(detectorName))
|
|
|
|
|
{
|
|
|
|
|
((QWidget*)objects[i])->setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
else if(!objects[i]->objectName().split('/').at(1).at(0).isDigit())
|
|
|
|
|
{
|
|
|
|
|
((QWidget*)objects[i])->setVisible(false);
|
|
|
|
|
}
|
2014-03-24 22:32:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QComboBox * nnBox = this->findChild<QComboBox*>(Settings::kNearestNeighbor_1Strategy());
|
|
|
|
|
if(nnBox)
|
|
|
|
|
{
|
|
|
|
|
QString group = Settings::kNearestNeighbor_1Strategy().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 nnName = nnBox->currentText();
|
|
|
|
|
|
|
|
|
|
for(int i=0; i<objects.size(); ++i)
|
|
|
|
|
{
|
2014-04-11 22:30:38 +00:00
|
|
|
if(!objects[i]->objectName().isEmpty())
|
2014-03-24 22:32:54 +00:00
|
|
|
{
|
2014-04-11 22:30:38 +00:00
|
|
|
if(objects[i]->objectName().contains(nnName))
|
|
|
|
|
{
|
|
|
|
|
((QWidget*)objects[i])->setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
else if(!objects[i]->objectName().split('/').at(1).at(0).isDigit())
|
|
|
|
|
{
|
|
|
|
|
((QWidget*)objects[i])->setVisible(false);
|
|
|
|
|
}
|
2014-03-24 22:32:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 15:48:19 +00:00
|
|
|
void ParametersToolBox::setupUi()
|
|
|
|
|
{
|
2012-08-28 13:44:57 +00:00
|
|
|
this->removeItem(0); // remove dummy page used in .ui
|
2011-10-25 15:48:19 +00:00
|
|
|
QWidget * currentItem = 0;
|
|
|
|
|
const ParametersMap & parameters = Settings::getParameters();
|
|
|
|
|
for(ParametersMap::const_iterator iter=parameters.constBegin();
|
|
|
|
|
iter!=parameters.constEnd();
|
|
|
|
|
++iter)
|
|
|
|
|
{
|
|
|
|
|
QStringList splitted = iter.key().split('/');
|
|
|
|
|
QString group = splitted.first();
|
|
|
|
|
QString name = splitted.last();
|
|
|
|
|
if(currentItem == 0 || currentItem->objectName().compare(group) != 0)
|
|
|
|
|
{
|
|
|
|
|
currentItem = new QWidget(this);
|
2011-11-23 18:08:33 +00:00
|
|
|
this->addItem(currentItem, group);
|
2011-10-25 15:48:19 +00:00
|
|
|
currentItem->setObjectName(group);
|
|
|
|
|
QVBoxLayout * layout = new QVBoxLayout(currentItem);
|
|
|
|
|
currentItem->setLayout(layout);
|
2012-08-28 20:06:43 +00:00
|
|
|
layout->setContentsMargins(0,0,0,0);
|
|
|
|
|
layout->setSpacing(0);
|
2011-10-25 15:48:19 +00:00
|
|
|
layout->addSpacerItem(new QSpacerItem(0,0, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
|
|
|
|
|
|
|
|
|
addParameter(layout, iter.key(), iter.value());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
addParameter((QVBoxLayout*)currentItem->layout(), iter.key(), iter.value());
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-24 22:32:54 +00:00
|
|
|
|
|
|
|
|
updateParametersVisibility();
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-30 03:16:30 +00:00
|
|
|
void ParametersToolBox::updateParameter(const QString & key)
|
|
|
|
|
{
|
|
|
|
|
QWidget * widget = this->findChild<QWidget*>(key);
|
|
|
|
|
QString type = Settings::getParametersType().value(key);
|
|
|
|
|
if(type.compare("QString") == 0)
|
|
|
|
|
{
|
2012-08-28 13:44:57 +00:00
|
|
|
QString value = Settings::getParameter(key).toString();
|
|
|
|
|
if(value.contains(';'))
|
|
|
|
|
{
|
|
|
|
|
// It's a list, just change the index
|
|
|
|
|
QStringList splitted = value.split(':');
|
|
|
|
|
((QComboBox*)widget)->setCurrentIndex(splitted.first().toInt());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
((QLineEdit*)widget)->setText(value);
|
|
|
|
|
}
|
2012-01-30 03:16:30 +00:00
|
|
|
}
|
|
|
|
|
else if(type.compare("int") == 0)
|
|
|
|
|
{
|
|
|
|
|
((QSpinBox*)widget)->setValue(Settings::getParameter(key).toInt());
|
|
|
|
|
}
|
|
|
|
|
else if(type.compare("uint") == 0)
|
|
|
|
|
{
|
|
|
|
|
((QSpinBox*)widget)->setValue(Settings::getParameter(key).toInt());
|
|
|
|
|
}
|
|
|
|
|
else if(type.compare("double") == 0)
|
|
|
|
|
{
|
|
|
|
|
((QDoubleSpinBox*)widget)->setValue(Settings::getParameter(key).toDouble());
|
|
|
|
|
}
|
|
|
|
|
else if(type.compare("float") == 0)
|
|
|
|
|
{
|
|
|
|
|
((QDoubleSpinBox*)widget)->setValue(Settings::getParameter(key).toDouble());
|
|
|
|
|
}
|
|
|
|
|
else if(type.compare("bool") == 0)
|
|
|
|
|
{
|
|
|
|
|
((QCheckBox*)widget)->setChecked(Settings::getParameter(key).toBool());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 15:48:19 +00:00
|
|
|
void ParametersToolBox::addParameter(QVBoxLayout * layout,
|
|
|
|
|
const QString & key,
|
|
|
|
|
const QVariant & value)
|
|
|
|
|
{
|
|
|
|
|
QString type = Settings::getParametersType().value(key);
|
|
|
|
|
if(type.compare("QString") == 0)
|
|
|
|
|
{
|
|
|
|
|
addParameter(layout, key, value.toString());
|
|
|
|
|
}
|
|
|
|
|
else if(type.compare("int") == 0)
|
|
|
|
|
{
|
|
|
|
|
addParameter(layout, key, value.toInt());
|
|
|
|
|
}
|
2012-01-04 20:44:58 +00:00
|
|
|
else if(type.compare("uint") == 0)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
addParameter(layout, key, value.toInt());
|
|
|
|
|
}
|
|
|
|
|
else if(type.compare("double") == 0)
|
|
|
|
|
{
|
|
|
|
|
addParameter(layout, key, value.toDouble());
|
|
|
|
|
}
|
|
|
|
|
else if(type.compare("float") == 0)
|
|
|
|
|
{
|
|
|
|
|
addParameter(layout, key, value.toDouble());
|
|
|
|
|
}
|
|
|
|
|
else if(type.compare("bool") == 0)
|
|
|
|
|
{
|
|
|
|
|
addParameter(layout, key, value.toBool());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)));
|
2014-03-24 20:04:56 +00:00
|
|
|
addParameter(layout, key, widget);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QLineEdit * widget = new QLineEdit(value, this);
|
|
|
|
|
widget->setObjectName(key);
|
2012-02-04 22:15:32 +00:00
|
|
|
connect(widget, SIGNAL(editingFinished()), this, SLOT(changeParameter()));
|
2014-03-24 20:04:56 +00:00
|
|
|
addParameter(layout, key, widget);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParametersToolBox::addParameter(QVBoxLayout * layout,
|
|
|
|
|
const QString & key,
|
|
|
|
|
const double & value)
|
|
|
|
|
{
|
|
|
|
|
QDoubleSpinBox * widget = new QDoubleSpinBox(this);
|
|
|
|
|
double def = Settings::getDefaultParameters().value(key).toDouble();
|
|
|
|
|
if(def<0.001)
|
|
|
|
|
{
|
|
|
|
|
widget->setDecimals(4);
|
|
|
|
|
}
|
|
|
|
|
else if(def<0.01)
|
|
|
|
|
{
|
|
|
|
|
widget->setDecimals(3);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-04 22:38:28 +00:00
|
|
|
if(def>=0.0)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-01-04 17:30:36 +00:00
|
|
|
widget->setMaximum(def*1000000.0);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2012-02-04 22:38:28 +00:00
|
|
|
else if(def==0.0)
|
|
|
|
|
{
|
|
|
|
|
widget->setMaximum(1000000.0);
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
else if(def<0.0)
|
|
|
|
|
{
|
2012-01-04 17:30:36 +00:00
|
|
|
widget->setMinimum(def*1000000.0);
|
2011-10-25 15:48:19 +00:00
|
|
|
widget->setMaximum(0.0);
|
|
|
|
|
}
|
|
|
|
|
widget->setValue(value);
|
|
|
|
|
widget->setObjectName(key);
|
|
|
|
|
connect(widget, SIGNAL(editingFinished()), this, SLOT(changeParameter()));
|
2014-03-24 20:04:56 +00:00
|
|
|
addParameter(layout, key, widget);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParametersToolBox::addParameter(QVBoxLayout * layout,
|
|
|
|
|
const QString & key,
|
|
|
|
|
const int & value)
|
|
|
|
|
{
|
|
|
|
|
QSpinBox * widget = new QSpinBox(this);
|
|
|
|
|
int def = Settings::getDefaultParameters().value(key).toInt();
|
|
|
|
|
|
|
|
|
|
if(def>0)
|
|
|
|
|
{
|
2012-01-30 03:16:30 +00:00
|
|
|
widget->setMaximum(def*1000000);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2012-02-04 22:38:28 +00:00
|
|
|
else if(def == 0)
|
|
|
|
|
{
|
|
|
|
|
widget->setMaximum(1000000);
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
else if(def<0)
|
|
|
|
|
{
|
2012-01-30 03:16:30 +00:00
|
|
|
widget->setMinimum(def*1000000);
|
2011-10-25 15:48:19 +00:00
|
|
|
widget->setMaximum(0);
|
|
|
|
|
}
|
|
|
|
|
widget->setValue(value);
|
|
|
|
|
widget->setObjectName(key);
|
|
|
|
|
connect(widget, SIGNAL(editingFinished()), this, SLOT(changeParameter()));
|
2014-03-24 20:04:56 +00:00
|
|
|
addParameter(layout, key, widget);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)));
|
2014-03-24 20:04:56 +00:00
|
|
|
addParameter(layout, key, widget);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-24 20:04:56 +00:00
|
|
|
void ParametersToolBox::addParameter(QVBoxLayout * layout, const QString & key, QWidget * widget)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
QHBoxLayout * hLayout = new QHBoxLayout();
|
|
|
|
|
layout->insertLayout(layout->count()-1, hLayout);
|
2014-03-24 20:04:56 +00:00
|
|
|
QString tmp = key.split('/').last();
|
2012-08-28 13:44:57 +00:00
|
|
|
if(tmp.at(0).isDigit())
|
|
|
|
|
{
|
|
|
|
|
tmp.remove(0,1);
|
|
|
|
|
}
|
2014-03-24 20:04:56 +00:00
|
|
|
QLabel * label = new QLabel(tmp, this);
|
2014-03-24 22:32:54 +00:00
|
|
|
label->setObjectName(key+"/label");
|
2014-03-24 20:04:56 +00:00
|
|
|
label->setToolTip(QString("<FONT>%1</FONT>").arg(Settings::getDescriptions().value(key, "")));
|
2014-08-04 13:20:24 +00:00
|
|
|
label->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
2014-03-24 20:04:56 +00:00
|
|
|
hLayout->addWidget(label);
|
2011-10-25 15:48:19 +00:00
|
|
|
hLayout->addWidget(widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParametersToolBox::changeParameter(const QString & value)
|
|
|
|
|
{
|
|
|
|
|
if(sender())
|
|
|
|
|
{
|
|
|
|
|
Settings::setParameter(sender()->objectName(), value);
|
2012-08-29 19:04:14 +00:00
|
|
|
QStringList paramChanged;
|
|
|
|
|
paramChanged.append(sender()->objectName());
|
2014-07-08 19:55:03 +00:00
|
|
|
Q_EMIT parametersChanged(paramChanged);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void ParametersToolBox::changeParameter()
|
|
|
|
|
{
|
|
|
|
|
if(sender())
|
|
|
|
|
{
|
|
|
|
|
QDoubleSpinBox * doubleSpinBox = qobject_cast<QDoubleSpinBox*>(sender());
|
|
|
|
|
QSpinBox * spinBox = qobject_cast<QSpinBox*>(sender());
|
2012-02-04 22:15:32 +00:00
|
|
|
QLineEdit * lineEdit = qobject_cast<QLineEdit*>(sender());
|
2011-10-25 15:48:19 +00:00
|
|
|
if(doubleSpinBox)
|
|
|
|
|
{
|
|
|
|
|
Settings::setParameter(sender()->objectName(), doubleSpinBox->value());
|
|
|
|
|
}
|
|
|
|
|
else if(spinBox)
|
|
|
|
|
{
|
2014-05-05 23:08:01 +00:00
|
|
|
if(spinBox->objectName().compare(Settings::kHomography_minimumInliers()) == 0 &&
|
|
|
|
|
spinBox->value() < 4)
|
|
|
|
|
{
|
|
|
|
|
Settings::setHomography_minimumInliers(4);
|
|
|
|
|
spinBox->blockSignals(true);
|
|
|
|
|
this->updateParameter(Settings::kHomography_minimumInliers());
|
|
|
|
|
spinBox->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Settings::setParameter(sender()->objectName(), spinBox->value());
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
2012-02-04 22:15:32 +00:00
|
|
|
else if(lineEdit)
|
|
|
|
|
{
|
|
|
|
|
Settings::setParameter(sender()->objectName(), lineEdit->text());
|
|
|
|
|
}
|
2012-08-29 19:04:14 +00:00
|
|
|
QStringList paramChanged;
|
|
|
|
|
paramChanged.append(sender()->objectName());
|
2014-07-08 19:55:03 +00:00
|
|
|
Q_EMIT parametersChanged(paramChanged);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-03-24 22:32:54 +00:00
|
|
|
|
2011-10-25 15:48:19 +00:00
|
|
|
void ParametersToolBox::changeParameter(const int & value)
|
|
|
|
|
{
|
|
|
|
|
if(sender())
|
|
|
|
|
{
|
2012-08-29 19:04:14 +00:00
|
|
|
QStringList paramChanged;
|
2011-10-25 15:48:19 +00:00
|
|
|
QComboBox * comboBox = qobject_cast<QComboBox*>(sender());
|
|
|
|
|
QCheckBox * checkBox = qobject_cast<QCheckBox*>(sender());
|
|
|
|
|
if(comboBox)
|
|
|
|
|
{
|
2012-08-29 19:04:14 +00:00
|
|
|
bool nnStrategyChanged = false;
|
|
|
|
|
//verify binary issue with nearest neighbor strategy
|
2012-10-29 20:00:44 +00:00
|
|
|
if(comboBox->objectName().compare(Settings::kFeature2D_2Descriptor()) == 0 ||
|
2012-08-28 13:44:57 +00:00
|
|
|
comboBox->objectName().compare(Settings::kNearestNeighbor_1Strategy()) == 0)
|
|
|
|
|
{
|
2012-10-29 20:00:44 +00:00
|
|
|
QComboBox * descriptorBox = (QComboBox*)this->getParameterWidget(Settings::kFeature2D_2Descriptor());
|
2012-08-28 13:44:57 +00:00
|
|
|
QComboBox * nnBox = (QComboBox*)this->getParameterWidget(Settings::kNearestNeighbor_1Strategy());
|
2014-06-19 15:29:00 +00:00
|
|
|
QComboBox * distBox = (QComboBox*)this->getParameterWidget(Settings::kNearestNeighbor_2Distance_type());
|
2012-10-29 20:00:44 +00:00
|
|
|
bool isBinaryDescriptor = descriptorBox->currentText().compare("ORB") == 0 ||
|
|
|
|
|
descriptorBox->currentText().compare("Brief") == 0 ||
|
|
|
|
|
descriptorBox->currentText().compare("BRISK") == 0 ||
|
|
|
|
|
descriptorBox->currentText().compare("FREAK") == 0;
|
2012-08-28 13:44:57 +00:00
|
|
|
if(isBinaryDescriptor && nnBox->currentText().compare("Lsh") != 0)
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this,
|
2013-02-07 18:02:04 +00:00
|
|
|
tr("Warning"),
|
2012-08-28 13:44:57 +00:00
|
|
|
tr("Current selected descriptor type (\"%1\") is binary while nearest neighbor strategy is not (\"%2\").\n"
|
2014-05-12 22:58:57 +00:00
|
|
|
"Falling back to \"Lsh\" nearest neighbor strategy with Hamming distance (by default).")
|
2012-08-28 13:44:57 +00:00
|
|
|
.arg(descriptorBox->currentText())
|
|
|
|
|
.arg(nnBox->currentText()));
|
|
|
|
|
QString tmp = Settings::getNearestNeighbor_1Strategy();
|
2014-05-12 22:58:57 +00:00
|
|
|
*tmp.begin() = '5'; // set LSH
|
2012-08-28 13:44:57 +00:00
|
|
|
Settings::setNearestNeighbor_1Strategy(tmp);
|
2014-05-12 22:58:57 +00:00
|
|
|
tmp = Settings::getNearestNeighbor_2Distance_type();
|
|
|
|
|
*tmp.begin() = '8'; // set HAMMING
|
|
|
|
|
Settings::setNearestNeighbor_2Distance_type(tmp);
|
2012-08-29 19:04:14 +00:00
|
|
|
nnBox->blockSignals(true);
|
2014-06-19 15:29:00 +00:00
|
|
|
distBox->blockSignals(true);
|
2012-08-28 13:44:57 +00:00
|
|
|
this->updateParameter(Settings::kNearestNeighbor_1Strategy());
|
2014-05-12 22:58:57 +00:00
|
|
|
this->updateParameter(Settings::kNearestNeighbor_2Distance_type());
|
2012-08-29 19:04:14 +00:00
|
|
|
nnBox->blockSignals(false);
|
2014-06-19 15:29:00 +00:00
|
|
|
distBox->blockSignals(false);
|
2012-08-28 13:44:57 +00:00
|
|
|
if(sender() == nnBox)
|
|
|
|
|
{
|
2014-03-24 22:32:54 +00:00
|
|
|
this->updateParametersVisibility();
|
2012-08-28 13:44:57 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2012-08-29 19:04:14 +00:00
|
|
|
nnStrategyChanged = true;
|
|
|
|
|
paramChanged.append(Settings::kNearestNeighbor_1Strategy());
|
2014-06-19 15:29:00 +00:00
|
|
|
paramChanged.append(Settings::kNearestNeighbor_2Distance_type());
|
2012-08-28 13:44:57 +00:00
|
|
|
}
|
|
|
|
|
else if(!isBinaryDescriptor && nnBox->currentText().compare("Lsh") == 0)
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this,
|
2013-02-07 18:02:04 +00:00
|
|
|
tr("Warning"),
|
2012-08-28 13:44:57 +00:00
|
|
|
tr("Current selected descriptor type (\"%1\") is not binary while nearest neighbor strategy is (\"%2\").\n"
|
2014-05-12 22:58:57 +00:00
|
|
|
"Falling back to \"KDTree\" nearest neighbor strategy with Euclidean_L2 distance (by default).")
|
2012-08-28 13:44:57 +00:00
|
|
|
.arg(descriptorBox->currentText())
|
|
|
|
|
.arg(nnBox->currentText()));
|
|
|
|
|
QString tmp = Settings::getNearestNeighbor_1Strategy();
|
2014-05-12 22:58:57 +00:00
|
|
|
*tmp.begin() = '1'; // set KDTree
|
2012-08-28 13:44:57 +00:00
|
|
|
Settings::setNearestNeighbor_1Strategy(tmp);
|
2014-05-12 22:58:57 +00:00
|
|
|
tmp = Settings::getNearestNeighbor_2Distance_type();
|
|
|
|
|
*tmp.begin() = '0'; // set EUCLIDEAN_L2
|
|
|
|
|
Settings::setNearestNeighbor_2Distance_type(tmp);
|
2012-08-29 19:04:14 +00:00
|
|
|
nnBox->blockSignals(true);
|
2014-06-19 15:29:00 +00:00
|
|
|
distBox->blockSignals(true);
|
2012-08-28 13:44:57 +00:00
|
|
|
this->updateParameter(Settings::kNearestNeighbor_1Strategy());
|
2014-05-12 22:58:57 +00:00
|
|
|
this->updateParameter(Settings::kNearestNeighbor_2Distance_type());
|
2012-08-29 19:04:14 +00:00
|
|
|
nnBox->blockSignals(false);
|
2014-06-19 15:29:00 +00:00
|
|
|
distBox->blockSignals(false);
|
2012-08-28 13:44:57 +00:00
|
|
|
if(sender() == nnBox)
|
|
|
|
|
{
|
2014-03-24 22:32:54 +00:00
|
|
|
this->updateParametersVisibility();
|
2012-08-28 13:44:57 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2012-08-29 19:04:14 +00:00
|
|
|
nnStrategyChanged = true;
|
|
|
|
|
paramChanged.append(Settings::kNearestNeighbor_1Strategy());
|
2014-06-19 15:29:00 +00:00
|
|
|
paramChanged.append(Settings::kNearestNeighbor_2Distance_type());
|
2012-08-29 19:04:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Distance issue when using nearest neighbor strategy using CV_32F type, though Lsh support all type (doesn't crash at least)
|
|
|
|
|
if(nnStrategyChanged ||
|
|
|
|
|
comboBox->objectName().compare(Settings::kNearestNeighbor_1Strategy()) == 0 ||
|
|
|
|
|
comboBox->objectName().compare(Settings::kNearestNeighbor_2Distance_type()) == 0)
|
|
|
|
|
{
|
|
|
|
|
QComboBox * nnBox = (QComboBox*)this->getParameterWidget(Settings::kNearestNeighbor_1Strategy());
|
|
|
|
|
QComboBox * distBox = (QComboBox*)this->getParameterWidget(Settings::kNearestNeighbor_2Distance_type());
|
|
|
|
|
if(nnBox->currentText().compare("Lsh") != 0 && distBox->currentIndex() > 1)
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this,
|
2013-02-07 18:02:04 +00:00
|
|
|
tr("Warning"),
|
2012-08-29 19:04:14 +00:00
|
|
|
tr("Current selected nearest neighbor strategy type (\"%1\") cannot handle distance strategy (\"%2\").\n"
|
|
|
|
|
"Falling back to \"EUCLIDEAN_L2\" distance strategy (by default).")
|
|
|
|
|
.arg(nnBox->currentText())
|
|
|
|
|
.arg(distBox->currentText()));
|
|
|
|
|
QString tmp = Settings::getNearestNeighbor_2Distance_type();
|
|
|
|
|
*tmp.begin() = '0'; // set index
|
|
|
|
|
Settings::setNearestNeighbor_2Distance_type(tmp);
|
|
|
|
|
distBox->blockSignals(true);
|
|
|
|
|
this->updateParameter(Settings::kNearestNeighbor_2Distance_type());
|
|
|
|
|
distBox->blockSignals(false);
|
|
|
|
|
if(sender() == distBox)
|
|
|
|
|
{
|
2014-03-24 22:32:54 +00:00
|
|
|
this->updateParametersVisibility();
|
2012-08-29 19:04:14 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
paramChanged.append(Settings::kNearestNeighbor_2Distance_type());
|
2012-08-28 13:44:57 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 15:48:19 +00:00
|
|
|
QStringList items;
|
|
|
|
|
for(int i=0; i<comboBox->count(); ++i)
|
|
|
|
|
{
|
|
|
|
|
items.append(comboBox->itemText(i));
|
|
|
|
|
}
|
|
|
|
|
QString merged = QString::number(value) + QString(":") + items.join(";");
|
|
|
|
|
Settings::setParameter(sender()->objectName(), merged);
|
2014-03-24 22:32:54 +00:00
|
|
|
|
|
|
|
|
this->updateParametersVisibility();
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
else if(checkBox)
|
|
|
|
|
{
|
|
|
|
|
Settings::setParameter(sender()->objectName(), value==Qt::Checked?true:false);
|
|
|
|
|
}
|
2014-05-05 23:08:01 +00:00
|
|
|
|
2012-08-29 19:04:14 +00:00
|
|
|
paramChanged.append(sender()->objectName());
|
2014-07-08 19:55:03 +00:00
|
|
|
Q_EMIT parametersChanged(paramChanged);
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-08-06 13:43:29 +00:00
|
|
|
|
|
|
|
|
} // namespace find_object
|