0.11.11: changed Statistics table name to Info and added new Statistics table containing detection statistics. StatisticsToolBox can cache statistics (true by default). DatabaseViewer: new Statistics panel to see all statistics contained in the database.

This commit is contained in:
matlabbe
2016-09-20 11:19:34 -04:00
parent a0972158dc
commit 3530da935b
20 changed files with 609 additions and 219 deletions

View File

@@ -44,24 +44,30 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace rtabmap {
StatItem::StatItem(const QString & name, const std::vector<float> & x, const std::vector<float> & y, const QString & unit, const QMenu * menu, QGridLayout * grid, QWidget * parent) :
StatItem::StatItem(const QString & name, bool cacheOn, const std::vector<float> & x, const std::vector<float> & y, const QString & unit, const QMenu * menu, QGridLayout * grid, QWidget * parent) :
QWidget(parent),
_button(0),
_name(0),
_value(0),
_unit(0),
_menu(0)
_menu(0),
_cacheOn(cacheOn)
{
this->setupUi(grid);
_name->setText(name);
if(y.size() == 1)
if(y.size() == 1 || (y.size() > 1 && _cacheOn))
{
_value->setNum(y[0]);
_value->setNum(y[y.size()-1]);
}
else if(y.size() > 1)
{
_value->setText("*");
}
if(cacheOn)
{
_x = x;
_y = y;
}
_unit->setText(unit);
this->updateMenu(menu);
}
@@ -73,19 +79,53 @@ StatItem::~StatItem()
void StatItem::addValue(float y)
{
if(_cacheOn)
{
if(_y.size() % 100)
{
_y.reserve(_y.size()+100);
}
_y.push_back(y);
}
_value->setText(QString::number(y, 'g', 3));
emit valueAdded(y);
}
void StatItem::addValue(float x, float y)
{
if(_cacheOn)
{
if(_y.size() % 100)
{
_y.reserve(_y.size()+100);
}
_y.push_back(y);
if(_x.size() % 100)
{
_x.reserve(_x.size()+100);
}
_x.push_back(x);
}
_value->setText(QString::number(y, 'g', 3));
emit valueAdded(x,y);
}
void StatItem::setValues(const std::vector<float> & x, const std::vector<float> & y)
{
_value->setText("*");
if(_cacheOn)
{
_x = x;
_y = y;
if(y.size())
{
_value->setNum(y[y.size()-1]);
}
}
else
{
_value->setText("*");
}
emit valuesChanged(x,y);
}
@@ -132,6 +172,16 @@ void StatItem::setupUi(QGridLayout * grid)
}
}
void StatItem::setCacheOn(bool on)
{
_cacheOn = on;
if(!on)
{
_x.clear();
_y.clear();
}
}
void StatItem::updateMenu(const QMenu * menu)
{
_menu->clear();
@@ -190,22 +240,37 @@ void StatsToolBox::closeFigures()
}
}
void StatsToolBox::updateStat(const QString & statFullName, float y)
void StatsToolBox::setCacheOn(bool on)
{
QList<StatItem *> items = _statBox->findChildren<StatItem *>();
for(int i=0; i<items.size(); ++i)
{
items[i]->setCacheOn(on);
}
}
void StatsToolBox::updateStat(const QString & statFullName, bool cacheOn)
{
std::vector<float> vx,vy;
updateStat(statFullName, vx, vy, cacheOn);
}
void StatsToolBox::updateStat(const QString & statFullName, float y, bool cacheOn)
{
std::vector<float> vx,vy(1);
vy[0] = y;
updateStat(statFullName, vx, vy);
updateStat(statFullName, vx, vy, cacheOn);
}
void StatsToolBox::updateStat(const QString & statFullName, float x, float y)
void StatsToolBox::updateStat(const QString & statFullName, float x, float y, bool cacheOn)
{
std::vector<float> vx(1),vy(1);
vx[0] = x;
vy[0] = y;
updateStat(statFullName, vx, vy);
updateStat(statFullName, vx, vy, cacheOn);
}
void StatsToolBox::updateStat(const QString & statFullName, const std::vector<float> & x, const std::vector<float> & y)
void StatsToolBox::updateStat(const QString & statFullName, const std::vector<float> & x, const std::vector<float> & y, bool cacheOn)
{
// round float to max 2 numbers after the dot
//x = (float(int(100*x)))/100;
@@ -214,6 +279,7 @@ void StatsToolBox::updateStat(const QString & statFullName, const std::vector<fl
StatItem * item = _statBox->findChild<StatItem *>(statFullName);
if(item)
{
item->setCacheOn(cacheOn);
if(y.size() == 1 && x.size() == 1)
{
item->addValue(x[0], y[0]);
@@ -296,7 +362,7 @@ void StatsToolBox::updateStat(const QString & statFullName, const std::vector<fl
return;
}
item = new StatItem(name, x, y, unit, _plotMenu, grid, _statBox->widget(index));
item = new StatItem(name, cacheOn, x, y, unit, _plotMenu, grid, _statBox->widget(index));
item->setObjectName(statFullName);
//layout->insertWidget(layout->count()-1, item);
@@ -327,6 +393,17 @@ void StatsToolBox::plot(const StatItem * stat, const QString & plotName)
{
plot->setMaxVisibleItems(0);
}
if(!stat->yValues().empty())
{
if(stat->xValues().size() == stat->yValues().size())
{
curve->setData(stat->xValues(),stat->yValues());
}
else
{
curve->setData(stat->yValues());
}
}
if(!plot->addCurve(curve))
{
ULOGGER_WARN("Already added to the figure");
@@ -376,6 +453,19 @@ void StatsToolBox::plot(const StatItem * stat, const QString & plotName)
{
newPlot->setMaxVisibleItems(0);
}
if(!stat->yValues().empty())
{
if(stat->xValues().size() == stat->yValues().size())
{
curve->setData(stat->xValues(),stat->yValues());
}
else
{
curve->setData(stat->yValues());
}
}
if(!newPlot->addCurve(curve))
{
ULOGGER_ERROR("Not supposed to be here !?!");
@@ -493,12 +583,12 @@ void StatsToolBox::getFiguresSetup(QList<int> & curvesPerFigure, QStringList & c
}
}
}
void StatsToolBox::addCurve(const QString & name, bool newFigure)
void StatsToolBox::addCurve(const QString & name, bool newFigure, bool cacheOn)
{
StatItem * item = _statBox->findChild<StatItem *>(name);
if(!item)
{
this->updateStat(name, 0, 0);
this->updateStat(name, cacheOn);
item = _statBox->findChild<StatItem *>(name);
}