我怎么可以做出"实时"地块与wxMathPlot?
-
13-09-2019 - |
题
我想用 wxMathPlot 为策划/制图的某些数据达不断。我想提请"实时"的情节/图使用它。这可能吗?
E.I.我不想只是一个静态图的一个时间阅读一个文件-我想流数据绘制和继续出正确的图的(而我的左侧倒闭/滚出查看)
编辑
我仍然没有得到一个答案。还有一个有趣的类wxmathPlot库称为mpFXYVector但这似乎只是为了画出一个图从一矢量的数据。我想要什么东西能够喂养一个流和涡旋曲线水平(并且还调整规模如果需要的)
解决方案
我觉得mpFXYVector是要走的路。
要对付这可能是写mpFXYVector一个包装类持有最近的数据点的FIFO缓冲器的最简单方法。每当一个新的数据点到达时,将其添加到FIFO缓冲区,将删除最早的点,然后用更新的缓冲加载mpFXYVector。该wxMathPlot类mpWindow会看你需要什么休息后。
一个更好的方法将是mpFXYVector的特它实现了FIFO缓冲器,使用mpFXYVector简单向量。这样做的好处是,你只持有一个显示数据的副本。除非你显示许多千点,我怀疑其优点是值得mpFXYVector继承,而不是简单地使用mpFXYVector公开的接口的额外的麻烦。
看细节之后,唯一棘手位是一种新的方法来取代mpFXYVector :: SetData的()加入(),他们到达添加的数据点。这种新方法需要管理mpFXYVector向量作为FIFO缓冲器,并重新实现的代码来更新边界框(不幸的是不与记继承写入)。
其结果是,专业化给出具有较小存储器要求和更大的灵活性比使用包装器中的溶液。
其他提示
感谢ravenspoint ...!我没有你所说的话。它的工作完美无瑕! 这是我的AddData()函数:
void mpFXYVector::AddData(float x, float y, std::vector<double> &xs, std::vector<double> &ys)
{
// Check if the data vectora are of the same size
if (xs.size() != ys.size()) {
wxLogError(_("wxMathPlot error: X and Y vector are not of the same length!"));
return;
}
//Delete first point if you need a filo buffer (i dont need it)
//xs.erase(xs.begin());
//xy.erase(xy.begin());
//Add new Data points at the end
xs.push_back(x);
ys.push_back(y);
// Copy the data:
m_xs = xs;
m_ys = ys;
// Update internal variables for the bounding box.
if (xs.size()>0)
{
m_minX = xs[0];
m_maxX = xs[0];
m_minY = ys[0];
m_maxY = ys[0];
std::vector<double>::const_iterator it;
for (it=xs.begin();it!=xs.end();it++)
{
if (*it<m_minX) m_minX=*it;
if (*it>m_maxX) m_maxX=*it;
}
for (it=ys.begin();it!=ys.end();it++)
{
if (*it<m_minY) m_minY=*it;
if (*it>m_maxY) m_maxY=*it;
}
m_minX-=0.5f;
m_minY-=0.5f;
m_maxX+=0.5f;
m_maxY+=0.5f;
}
else
{
m_minX = -1;
m_maxX = 1;
m_minY = -1;
m_maxY = 1;
}
}
在主()你只需要:
m_Vector->AddData(xPos,yPos,vectorX, vectorY);
m_plot->Fit();
我知道这是一个古老的线程,但我需要绘制与wxMathPlot滚动X轴。
我已经做了简单的修改来jayjo的代码,以使X轴的滚动工作。
我锄这有助于。
void mpFXYVector::AddData(float x, float y, std::vector<double> &xs, std::vector<double> &ys)
{
// Check if the data vectora are of the same size
if (xs.size() != ys.size()) {
wxLogError(_("wxMathPlot error: X and Y vector are not of the same length!"));
return;
}
//After a certain number of points implement a FIFO buffer
//As plotting too many points can cause missing data
if (x > 300)
{
xs.erase(xs.begin());
ys.erase(ys.begin());
}
//Add new Data points at the end
xs.push_back(x);
ys.push_back(y);
// Copy the data:
m_xs = xs;
m_ys = ys;
// Update internal variables for the bounding box.
if (xs.size()>0)
{
m_minX = xs[0];
m_maxX = xs[0];
m_minY = ys[0];
m_maxY = ys[0];
std::vector<double>::const_iterator it;
for (it=xs.begin();it!=xs.end();it++)
{
if (*it<m_minX) m_minX=*it;
if (*it>m_maxX) m_maxX=*it;
}
for (it=ys.begin();it!=ys.end();it++)
{
if (*it<m_minY) m_minY=*it;
if (*it>m_maxY) m_maxY=*it;
}
m_minX-=0.5f;
m_minY-=0.5f;
m_maxX+=0.5f;
m_maxY+=0.5f;
}
else
{
m_minX = -1;
m_maxX = 1;
m_minY = -1;
m_maxY = 1;
}
}
我没有任何个人经验与wxMathPlot,但我已经工作与个函数库和二进制文年,并强烈建议它的跨平台gui c++编程,用于所述的根据 wxWiki页的图形 的 Numerix库的图形 可用于实时数据,因此,也许这可以帮助你。好运气。
也许有人会具有同样的问题,将需要它。我需要非常快的绘图显示来自示波器的数据。
我是在数据包获取数据。我做了做了一个代码的快很多一些变化。
第一件事是改变如果从SetData
功能if (xs.size()>0)
状态if (!xs.empty)
。
然后,你应该首先所有的数据包都添加到矢量
Vector1_X.push_back(x);
Vector1_Y.push_back(y);
在这之后,你应该适应并设定数据。
Vector1 ->SetData(Vector1_X,Vector1_Y); // add vectors to main vector
MathPlot1-> Fit(); //fit plot to the data
Vector1_X.clear(); //if you want to clear plot after every packet
Vector1_Y.clear(); //you should use it
您在主函数的代码会更长,但因为添加的所有数据“毕其功于一役”的功能会更快。
我们结束了使用 ChartDirector中代替。它有很多能力和快速。