【发布时间】:2017-12-02 17:59:07
【问题描述】:
我有一个std::map< QString, QPolygonF>,其中包含三个QStrings (sensorId),每个传感器的一些数据为QVector< QPointF>,这些数据连续生成并写入cv::Mat。
在下面的代码块中,我从cv::Mat 获取每个传感器的数据并将其保存在std::map< QString, double> m_Value; 中,并将值推送到std::map< QString, QPolygonF> m_Points 中。我只为每个传感器收集数据 5 次。之后,我将我的积分发送给其他班级,以便使用QwtPlot 将它们可视化。
std::map<QString, QPolygonF> m_Points
std::map<QString, double> m_Value;
std::map<QString, int> m_Index;
for(int i= 0; i< 5 ++i)
{
m_Value[sensorId]= dataMat.at<double>(i);
m_Points[sensorId].push_back(QPointF((double)m_Index[sensorId],
m_Value[sensorId]));
m_Index[sensorId]++;
}
qDebug()<<" POINTS: " << toolId << m_Points[toolId];
emit updateDataSignal(m_Points);
使用std::map< QString, int> m_Index; 我继续/增加发送点数。
for 循环仅针对一个循环的输出如下所示:
POINTS:
sensor1 QPolygonF(0, pointValue) QPolygonF(1, pointValue) QPolygonF(2, pointValue) QPolygonF(3, pointValue) QPolygonF(4, pointValue)
sensor2 QPolygonF(0, pointValue) QPolygonF(1, pointValue) QPolygonF(2, pointValue) QPolygonF(3, pointValue) QPolygonF(4, pointValue)
sensor3 QPolygonF(0, pointValue) QPolygonF(1, pointValue) QPolygonF(2, pointValue) QPolygonF(3, pointValue) QPolygonF(4, pointValue)
对于第二个循环:
sensor1 QPolygonF(0, pointValue) QPolygonF(1, pointValue) QPolygonF(2, pointValue) QPolygonF(3, pointValue) QPolygonF(4, pointValue) QPolygonF(5, newPointValue) QPolygonF(6, newPointValue) QPolygonF(7, newPointValue) QPolygonF(8, newPointValue) QPolygonF(9, newPointValue)
sensor2 ...
sensor3 ...
一段时间后,我获得了数千个积分,而我的 Qwtplot 通过实时绘制/更新而变慢。因此我只想发送例如我地图上的最后 5 个点。
输出例如传感器 1 应如下所示:
第一个循环:
sensor1 QPolygonF(0, pointValue) QPolygonF(1, pointValue) QPolygonF(2, pointValue) QPolygonF(3, pointValue) QPolygonF(4, pointValue)
第二个循环:
sensor1 QPolygonF(5, newPointValue) QPolygonF(6, newPointValue) QPolygonF(7, newPointValue) QPolygonF(8, newPointValue) QPolygonF(9, newPointValue)
第三个循环:
sensor1 QPolygonF(10, newPointValue) QPolygonF(11, newPointValue) QPolygonF(12, newPointValue) QPolygonF(13, newPointValue) QPolygonF(14, newPointValue)
...
谢谢
【问题讨论】:
-
您的标题具有误导性。似乎您只想显示矢量
QPolygonF的最后一个n元素,其中m_Points不包含std::map的最后一个n元素