Guest

How can I make “real-time” plots with wxMathPlot

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 1.50 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. void mpFXYVector::AddData(float x, float y, std::vector<double> &xs, std::vector<double> &ys)
  2.     {
  3.         // Check if the data vectora are of the same size
  4.         if (xs.size() != ys.size()) {
  5.             wxLogError(_("wxMathPlot error: X and Y vector are not of the same length!"));
  6.             return;
  7.         }
  8.  
  9.         //Delete first point if you need a filo buffer (i dont need it)
  10.         //xs.erase(xs.begin());
  11.         //xy.erase(xy.begin());
  12.  
  13.         //Add new Data points at the end
  14.         xs.push_back(x);
  15.         ys.push_back(y);
  16.  
  17.  
  18.         // Copy the data:
  19.         m_xs = xs;
  20.         m_ys = ys;
  21.  
  22.         // Update internal variables for the bounding box.
  23.         if (xs.size()>0)
  24.         {
  25.             m_minX  = xs[0];
  26.             m_maxX  = xs[0];
  27.             m_minY  = ys[0];
  28.             m_maxY  = ys[0];
  29.  
  30.             std::vector<double>::const_iterator  it;
  31.  
  32.             for (it=xs.begin();it!=xs.end();it++)
  33.             {
  34.                 if (*it<m_minX) m_minX=*it;
  35.                 if (*it>m_maxX) m_maxX=*it;
  36.             }
  37.             for (it=ys.begin();it!=ys.end();it++)
  38.             {
  39.                 if (*it<m_minY) m_minY=*it;
  40.                 if (*it>m_maxY) m_maxY=*it;
  41.             }
  42.             m_minX-=0.5f;
  43.             m_minY-=0.5f;
  44.             m_maxX+=0.5f;
  45.             m_maxY+=0.5f;
  46.         }
  47.         else
  48.         {
  49.             m_minX  = -1;
  50.             m_maxX  = 1;
  51.             m_minY  = -1;
  52.             m_maxY  = 1;
  53.         }
  54.     }
  55.        
  56. m_Vector->AddData(xPos,yPos,vectorX, vectorY);
  57. m_plot->Fit();