mirror of
https://github.com/introlab/rtabmap.git
synced 2026-10-05 17:47:49 +08:00
GraphViewer: deprecating updatePosterior(), replaced by more general function updateNodeColorByValue()
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user