GraphViewer: deprecating updatePosterior(), replaced by more general function updateNodeColorByValue()

This commit is contained in:
matlabbe
2025-04-16 13:41:17 -07:00
parent ccb6ce67d5
commit 3d968da30f
3 changed files with 42 additions and 16 deletions

View File

@@ -74,7 +74,9 @@ public:
const std::map<int, GPS> & gpsValues);
void updateReferentialPosition(const Transform & t);
void updateMap(const cv::Mat & map8U, float resolution, float xMin, float yMin);
void updatePosterior(const std::map<int, float> & posterior, float fixedMax = 0.0f, int zValueOffset = 0);
// Use updateNodeColorByValue() instead with valueName="Posterior".
RTABMAP_DEPRECATED void updatePosterior(const std::map<int, float> & posterior, float fixedMax = 0.0f, int zValueOffset = 0);
void updateNodeColorByValue(const std::string & valueName, const std::map<int, float> & values, float fixedMax = 0.0f, bool invertedColorScale = false, int zValueOffset = 0);
void updateLocalPath(const std::vector<int> & localPath);
void setGlobalPath(const std::vector<std::pair<int, Transform> > & globalPath);
void setCurrentGoalID(int id, const Transform & pose = Transform());
@@ -82,9 +84,10 @@ public:
void highlightNode(int nodeId, int highlightIndex);
void clearGraph();
void clearMap();
void clearPosterior();
// Use clearNodeColorByValue() instead.
RTABMAP_DEPRECATED void clearPosterior();
void clearNodeColorByValue();
void clearAll();
void saveSettings(QSettings & settings, const QString & group = "") const;
void loadSettings(QSettings & settings, const QString & group = "");

View File

@@ -92,7 +92,7 @@ public:
}
virtual ~NodeItem() {}
void setColor(const QColor & color)
void setColor(const QColor & color, const QString & valueName = QString(), float value = 0.0f)
{
QPen p = this->pen();
p.setColor(color);
@@ -104,6 +104,9 @@ public:
QPen pen = _line->pen();
pen.setColor(QColor(255-color.red(), 255-color.green(), 255-color.blue()));
_line->setPen(pen);
_valueName = valueName;
_value = value;
}
void setRadius(float radius)
@@ -144,14 +147,22 @@ public:
protected:
virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event )
{
QString msg;
if(_weight>=0)
{
this->setToolTip(QString("%1 [map=%2, w=%3] %4").arg(_id).arg(_mapId).arg(_weight).arg(_pose.prettyPrint().c_str()));
msg = QString("%1 [map=%2, w=%3]\n%4").arg(_id).arg(_mapId).arg(_weight).arg(_pose.prettyPrint().c_str());
}
else
{
this->setToolTip(QString("%1 [map=%2] %3").arg(_id).arg(_mapId).arg(_pose.prettyPrint().c_str()));
msg = QString("%1 [map=%2]\n%3").arg(_id).arg(_mapId).arg(_pose.prettyPrint().c_str());
}
if(!_valueName.isEmpty())
{
msg += QString("\n%1=%2").arg(_valueName).arg(_value);
}
this->setToolTip(msg);
this->setScale(2);
QGraphicsEllipseItem::hoverEnterEvent(event);
}
@@ -168,6 +179,8 @@ private:
int _weight;
Transform _pose;
QGraphicsLineItem * _line;
QString _valueName;
float _value;
};
class NodeGPSItem: public NodeItem
@@ -1071,11 +1084,16 @@ void GraphViewer::updateMap(const cv::Mat & map8U, float resolution, float xMin,
}
void GraphViewer::updatePosterior(const std::map<int, float> & posterior, float max, int zValueOffset)
{
updateNodeColorByValue("Posterior Prob", posterior, max, false, zValueOffset);
}
void GraphViewer::updateNodeColorByValue(const std::string & valueName, const std::map<int, float> & values, float max, bool invertedColorScale, int zValueOffset)
{
//find max
if(max <= 0.0f)
{
for(std::map<int, float>::const_iterator iter = posterior.begin(); iter!=posterior.end(); ++iter)
for(std::map<int, float>::const_iterator iter = values.begin(); iter!=values.end(); ++iter)
{
if(iter->first > 0 && iter->second>max)
{
@@ -1087,11 +1105,11 @@ void GraphViewer::updatePosterior(const std::map<int, float> & posterior, float
{
for(QMap<int, NodeItem*>::iterator iter = _nodeItems.begin(); iter!=_nodeItems.end(); ++iter)
{
std::map<int,float>::const_iterator jter = posterior.find(iter.key());
if(jter != posterior.end())
std::map<int,float>::const_iterator jter = values.find(iter.key());
if(jter != values.end())
{
float v = jter->second>max?max:jter->second;
iter.value()->setColor(QColor::fromHsvF((1-v/max)*240.0f/360.0f, 1, 1, 1)); //0=red 240=blue
iter.value()->setColor(QColor::fromHsvF(( invertedColorScale ? v/max : 1-v/max )*240.0f/360.0f, 1, 1, 1), valueName.c_str(), jter->second); //0=red 240=blue
iter.value()->setZValue(iter.value()->zValue()+zValueOffset);
}
}
@@ -1286,6 +1304,11 @@ void GraphViewer::clearMap()
}
void GraphViewer::clearPosterior()
{
clearNodeColorByValue();
}
void GraphViewer::clearNodeColorByValue()
{
for(QMap<int, NodeItem*>::iterator iter = _nodeItems.begin(); iter!=_nodeItems.end(); ++iter)
{

View File

@@ -2620,19 +2620,19 @@ void MainWindow::processStats(const rtabmap::Statistics & stat)
if(_preferencesDialog->isPosteriorGraphView() &&
stat.posterior().size())
{
_ui->graphicsView_graphView->updatePosterior(stat.posterior());
_ui->graphicsView_graphView->updateNodeColorByValue("Posterior", stat.posterior());
}
else if(_preferencesDialog->isRGBDMode())
{
if(_preferencesDialog->isWordsCountGraphView() &&
_cachedWordsCount.size())
{
_ui->graphicsView_graphView->updatePosterior(_cachedWordsCount, (float)_preferencesDialog->getKpMaxFeatures());
_ui->graphicsView_graphView->updateNodeColorByValue("Visual Words", _cachedWordsCount, (float)_preferencesDialog->getKpMaxFeatures());
}
else if(_preferencesDialog->isLocalizationsCountGraphView() &&
_cachedLocalizationsCount.size())
{
_ui->graphicsView_graphView->updatePosterior(_cachedLocalizationsCount, 1.0f);
_ui->graphicsView_graphView->updateNodeColorByValue("Re-Localization Count", _cachedLocalizationsCount, 1.0f);
}
}
if(_preferencesDialog->isRelocalizationColorOdomCacheGraphView() && !stat.odomCachePoses().empty())
@@ -2653,7 +2653,7 @@ void MainWindow::processStats(const rtabmap::Statistics & stat)
colors.insert(std::make_pair(iter->first, 240)); //red
}
}
_ui->graphicsView_graphView->updatePosterior(colors, 240);
_ui->graphicsView_graphView->updateNodeColorByValue("Re-Localized", colors, 240);
}
// update local path on the graph view
_ui->graphicsView_graphView->updateLocalPath(stat.localPath());
@@ -4771,7 +4771,7 @@ void MainWindow::processRtabmapEvent3DMap(const rtabmap::RtabmapEvent3DMap & eve
_preferencesDialog->isRGBDMode()&&
_cachedWordsCount.size())
{
_ui->graphicsView_graphView->updatePosterior(_cachedWordsCount, (float)_preferencesDialog->getKpMaxFeatures());
_ui->graphicsView_graphView->updateNodeColorByValue("Visual Words", _cachedWordsCount, (float)_preferencesDialog->getKpMaxFeatures());
}
_progressDialog->appendText("Updating the 3D map cloud... done.");
@@ -4922,7 +4922,7 @@ void MainWindow::applyPrefSettings(PreferencesDialog::PANEL_FLAGS flags)
}
if(!_preferencesDialog->isPosteriorGraphView() && _ui->graphicsView_graphView->isVisible())
{
_ui->graphicsView_graphView->clearPosterior();
_ui->graphicsView_graphView->clearNodeColorByValue();
}
}