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
+6 -3
View File
@@ -74,7 +74,9 @@ public:
const std::map<int, GPS> & gpsValues); const std::map<int, GPS> & gpsValues);
void updateReferentialPosition(const Transform & t); void updateReferentialPosition(const Transform & t);
void updateMap(const cv::Mat & map8U, float resolution, float xMin, float yMin); 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 updateLocalPath(const std::vector<int> & localPath);
void setGlobalPath(const std::vector<std::pair<int, Transform> > & globalPath); void setGlobalPath(const std::vector<std::pair<int, Transform> > & globalPath);
void setCurrentGoalID(int id, const Transform & pose = Transform()); void setCurrentGoalID(int id, const Transform & pose = Transform());
@@ -82,9 +84,10 @@ public:
void highlightNode(int nodeId, int highlightIndex); void highlightNode(int nodeId, int highlightIndex);
void clearGraph(); void clearGraph();
void clearMap(); void clearMap();
void clearPosterior(); // Use clearNodeColorByValue() instead.
RTABMAP_DEPRECATED void clearPosterior();
void clearNodeColorByValue();
void clearAll(); void clearAll();
void saveSettings(QSettings & settings, const QString & group = "") const; void saveSettings(QSettings & settings, const QString & group = "") const;
void loadSettings(QSettings & settings, const QString & group = ""); void loadSettings(QSettings & settings, const QString & group = "");
+30 -7
View File
@@ -92,7 +92,7 @@ public:
} }
virtual ~NodeItem() {} virtual ~NodeItem() {}
void setColor(const QColor & color) void setColor(const QColor & color, const QString & valueName = QString(), float value = 0.0f)
{ {
QPen p = this->pen(); QPen p = this->pen();
p.setColor(color); p.setColor(color);
@@ -104,6 +104,9 @@ public:
QPen pen = _line->pen(); QPen pen = _line->pen();
pen.setColor(QColor(255-color.red(), 255-color.green(), 255-color.blue())); pen.setColor(QColor(255-color.red(), 255-color.green(), 255-color.blue()));
_line->setPen(pen); _line->setPen(pen);
_valueName = valueName;
_value = value;
} }
void setRadius(float radius) void setRadius(float radius)
@@ -144,14 +147,22 @@ public:
protected: protected:
virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event )
{ {
QString msg;
if(_weight>=0) 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 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); this->setScale(2);
QGraphicsEllipseItem::hoverEnterEvent(event); QGraphicsEllipseItem::hoverEnterEvent(event);
} }
@@ -168,6 +179,8 @@ private:
int _weight; int _weight;
Transform _pose; Transform _pose;
QGraphicsLineItem * _line; QGraphicsLineItem * _line;
QString _valueName;
float _value;
}; };
class NodeGPSItem: public NodeItem 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) 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 //find max
if(max <= 0.0f) 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) 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) for(QMap<int, NodeItem*>::iterator iter = _nodeItems.begin(); iter!=_nodeItems.end(); ++iter)
{ {
std::map<int,float>::const_iterator jter = posterior.find(iter.key()); std::map<int,float>::const_iterator jter = values.find(iter.key());
if(jter != posterior.end()) if(jter != values.end())
{ {
float v = jter->second>max?max:jter->second; 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); iter.value()->setZValue(iter.value()->zValue()+zValueOffset);
} }
} }
@@ -1286,6 +1304,11 @@ void GraphViewer::clearMap()
} }
void GraphViewer::clearPosterior() void GraphViewer::clearPosterior()
{
clearNodeColorByValue();
}
void GraphViewer::clearNodeColorByValue()
{ {
for(QMap<int, NodeItem*>::iterator iter = _nodeItems.begin(); iter!=_nodeItems.end(); ++iter) for(QMap<int, NodeItem*>::iterator iter = _nodeItems.begin(); iter!=_nodeItems.end(); ++iter)
{ {
+6 -6
View File
@@ -2620,19 +2620,19 @@ void MainWindow::processStats(const rtabmap::Statistics & stat)
if(_preferencesDialog->isPosteriorGraphView() && if(_preferencesDialog->isPosteriorGraphView() &&
stat.posterior().size()) stat.posterior().size())
{ {
_ui->graphicsView_graphView->updatePosterior(stat.posterior()); _ui->graphicsView_graphView->updateNodeColorByValue("Posterior", stat.posterior());
} }
else if(_preferencesDialog->isRGBDMode()) else if(_preferencesDialog->isRGBDMode())
{ {
if(_preferencesDialog->isWordsCountGraphView() && if(_preferencesDialog->isWordsCountGraphView() &&
_cachedWordsCount.size()) _cachedWordsCount.size())
{ {
_ui->graphicsView_graphView->updatePosterior(_cachedWordsCount, (float)_preferencesDialog->getKpMaxFeatures()); _ui->graphicsView_graphView->updateNodeColorByValue("Visual Words", _cachedWordsCount, (float)_preferencesDialog->getKpMaxFeatures());
} }
else if(_preferencesDialog->isLocalizationsCountGraphView() && else if(_preferencesDialog->isLocalizationsCountGraphView() &&
_cachedLocalizationsCount.size()) _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()) 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 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 // update local path on the graph view
_ui->graphicsView_graphView->updateLocalPath(stat.localPath()); _ui->graphicsView_graphView->updateLocalPath(stat.localPath());
@@ -4771,7 +4771,7 @@ void MainWindow::processRtabmapEvent3DMap(const rtabmap::RtabmapEvent3DMap & eve
_preferencesDialog->isRGBDMode()&& _preferencesDialog->isRGBDMode()&&
_cachedWordsCount.size()) _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."); _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()) if(!_preferencesDialog->isPosteriorGraphView() && _ui->graphicsView_graphView->isVisible())
{ {
_ui->graphicsView_graphView->clearPosterior(); _ui->graphicsView_graphView->clearNodeColorByValue();
} }
} }