Exemplo n.º 1
0
Plot::Plot()
{
    setTitle("A Simple QwtPlot Demonstration");
    insertLegend(new QwtLegend(), QwtPlot::RightLegend);

    // Set axis titles
    setAxisTitle(xBottom, "x -->");
    setAxisTitle(yLeft, "y -->");
    
    // Insert new curves
    QwtPlotCurve *cSin = new QwtPlotCurve("y = sin(x)");
#if QT_VERSION >= 0x040000
    cSin->setRenderHint(QwtPlotItem::RenderAntialiased);
#endif
    cSin->setPen(QPen(Qt::red));
    cSin->attach(this);

    QwtPlotCurve *cCos = new QwtPlotCurve("y = cos(x)");
#if QT_VERSION >= 0x040000
    cCos->setRenderHint(QwtPlotItem::RenderAntialiased);
#endif
    cCos->setPen(QPen(Qt::blue));
    cCos->attach(this);

    // Create sin and cos data
    const int nPoints = 100;
    cSin->setData(SimpleData(::sin, nPoints));
    cCos->setData(SimpleData(::cos, nPoints));

    // Insert markers
    
    //  ...a horizontal line at y = 0...
    QwtPlotMarker *mY = new QwtPlotMarker();
    mY->setLabel(QString::fromLatin1("y = 0"));
    mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
    mY->setLineStyle(QwtPlotMarker::HLine);
    mY->setYValue(0.0);
    mY->attach(this);

    //  ...a vertical line at x = 2 * pi
    QwtPlotMarker *mX = new QwtPlotMarker();
    mX->setLabel(QString::fromLatin1("x = 2 pi"));
    mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);
    mX->setLabelOrientation(Qt::Vertical);
    mX->setLineStyle(QwtPlotMarker::VLine);
    mX->setLinePen(QPen(Qt::black, 0, Qt::DashDotLine));
    mX->setXValue(2.0 * M_PI);
    mX->attach(this);
}
Exemplo n.º 2
0
void VectorPlot::addDotPlot(const MarkupQwtAdapter&adapter,
		QColor color,
		const QString &name,
		bool addToLegend) {
	QwtPlotCurve *curve = new QwtPlotCurve(name);

    QwtSymbol sym;
    sym.setPen(QColor(color));
    sym.setBrush(QColor(color));
    sym.setStyle(QwtSymbol::Rect);
    sym.setSize(
			QSize(1, 20)
			);
	curve->setSymbol(sym);
	curve->setStyle(QwtPlotCurve::NoCurve);

	if(adapter.size() > 0) {
		setupPlot(adapter.boundingRect());
		curve->setData(adapter);
		curve->attach(plot);
	}

	if(!legend) {
		return;
	}

    // Добавляем кривую в легенду
	QwtLegendItem *item = new QwtLegendItem(0);
	item->setText(curve->title());
	item->setSymbol(sym);
	item->setIdentifierMode(QwtLegendItem::ShowLine | QwtLegendItem::ShowSymbol | QwtLegendItem::ShowText);
	legend->insert(curve, item);
}
Exemplo n.º 3
0
void PlotWidget::AddPlotData(QString title, float* plotData, int size, bool showMarkers)
{	
	if(_curves.contains(title))
		return;
	QwtPointSeriesData *points = CreatePointSeriesFromArray(plotData, size);
	QwtPlotCurve *curve = new QwtPlotCurve(title);	
	curve->setData(points);
	//Устанавливается цвет
	curve->setPen(QColor(255,0,0), 2.0);
	if(size < 1000)
		curve->setRenderHint(QwtPlotItem::RenderAntialiased);
	//Marker
	if(_showMarkers || showMarkers)
	{
		/*QwtSymbol *symbol1 = new QwtSymbol();
		symbol1->setStyle(QwtSymbol::Ellipse);
		symbol1->setPen(QColor(Qt::black));	
		symbol1->setSize(4);*/
		curve->setSymbol(GetDefaultMarker());
	}
	//Кривая добавляется на график
	curve->attach(_plot);
	//Добавляется в список кривых
	_curves.insert(title, curve);
	//Область рисования перерисовывается, если включен автоматический режим
	CheckNReplot();
}
Exemplo n.º 4
0
void CDataPlot::rebuild(void)
{
	for(int ci = 0; ci < m_portalCurveMap.count(); ++ci)
	{
		if(m_portalCurveMap.values().at(ci))
		{
			m_portalCurveMap.values().at(ci)->detach();
			delete m_portalCurveMap.values().at(ci);
		}
	}
	m_portalCurveMap.clear();

	if(m_algTreeModel)
	{
		QList<CPortal*> portals = m_algTreeModel->checkedPortalList();
		foreach(CPortal *portal, portals)
		{
			if(!portal) continue;
			QwtPlotCurve *curve = new QwtPlotCurve(portal->caption());
			curve->setData(new CCurveData(portal));
			curve->setPen(portal->dataColor(), 3);
			curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
			curve->attach(this);
			m_portalCurveMap[portal] = curve;
		}
	}

	refresh();
}
Exemplo n.º 5
0
void Plot::drawFunc(QVector params, double (*f)(double, QVector)){
    int j;
    QwtPlotCurve *curve = new QwtPlotCurve(QString("m: %1; a: %2").arg(m).arg(a));
    curve->setData(new FuncData(params, f));
    curve->attach(this);

    this->replot();
}
Exemplo n.º 6
0
void LinePlot::scaleCurves(QwtPlotCurve *curve)
{

  /// multiple curves based on units
  const QwtPlotItemList &listPlotItem = m_qwtPlot->itemList();
  QwtPlotCurve *plotCurve;
  QwtPlotItemIterator itPlotItem;
  int curveCount = numberOfCurves();

  switch (curveCount)
  {
    case 0:
    {
      curve->setYAxis(QwtPlot::yLeft);
      m_qwtPlot->enableAxis(QwtPlot::yRight, false);
      break;
    }
    case 1:
    {
      curve->setYAxis(QwtPlot::yRight);
      m_qwtPlot->enableAxis(QwtPlot::yRight, true);
      break;
    }
    default: //scale
      m_qwtPlot->enableAxis(QwtPlot::yRight, false);
      // find min, max of all curves
      // scale
      int i;
      for ( itPlotItem = listPlotItem.begin();itPlotItem!=listPlotItem.end();++itPlotItem)
      {
        if ( (*itPlotItem)->rtti() == QwtPlotItem::Rtti_PlotCurve)
        {
          plotCurve = (QwtPlotCurve*) (*itPlotItem);

          if ((plotCurve->minYValue() != 0) || (plotCurve->maxYValue() != 1))
          {

            QwtArray<double> xData(plotCurve->dataSize());
            QwtArray<double> yData(plotCurve->dataSize());
            for (i = 0; i < plotCurve->dataSize(); i++)
            {
              xData[i] = plotCurve->x(i);
              yData[i] = (plotCurve->y(i) - plotCurve->minYValue())/ (plotCurve->maxYValue() - plotCurve->minYValue());
            }
            // reset data
            plotCurve->setTitle(plotCurve->title().text() + "[" + QString::number(plotCurve->minYValue()) + ", "  + QString::number(plotCurve->maxYValue()) + "]");
            plotCurve->setData(xData,yData);
          }
        }
      }
      break;
  }

}
Exemplo n.º 7
0
void Plot::initCurves()
{
    QwtPointSeriesData* data = new QwtPointSeriesData();
    
    m_manager.GetPointSeriesData(data, ResourceManager::MF_0);
    
    QwtPlotCurve* curve = new QwtPlotCurve(tr("measured data"));
    curve->setRenderHint(QwtPlotItem::RenderAntialiased);
    curve->setLegendAttribute(QwtPlotCurve::LegendNoAttribute);
    curve->setPen(QPen(Qt::red));
    curve->attach(this);
    curve->setData(data);
}
Exemplo n.º 8
0
void Plot::populate()
{
    // Insert new curves
    QwtPlotCurve *cSin = new QwtPlotCurve("y = sin(x)");
    cSin->setRenderHint(QwtPlotItem::RenderAntialiased);
    cSin->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
    cSin->setPen(QPen(Qt::red));
    cSin->attach(this);

    QwtPlotCurve *cCos = new QwtPlotCurve("y = cos(x)");
    cCos->setRenderHint(QwtPlotItem::RenderAntialiased);
    cCos->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
    cCos->setPen(QPen(Qt::blue));
    cCos->attach(this);

    // Create sin and cos data
    cSin->setData(new FunctionData(::sin));
    cCos->setData(new FunctionData(::cos));

    // Insert markers
    
    //  ...a horizontal line at y = 0...
    QwtPlotMarker *mY = new QwtPlotMarker();
    mY->setLabel(QString::fromLatin1("y = 0"));
    mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
    mY->setLineStyle(QwtPlotMarker::HLine);
    mY->setYValue(0.0);
    mY->attach(this);

    //  ...a vertical line at x = 2 * pi
    QwtPlotMarker *mX = new QwtPlotMarker();
    mX->setLabel(QString::fromLatin1("x = 2 pi"));
    mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);
    mX->setLabelOrientation(Qt::Vertical);
    mX->setLineStyle(QwtPlotMarker::VLine);
    mX->setLinePen(QPen(Qt::black, 0, Qt::DashDotLine));
    mX->setXValue(2.0 * M_PI);
    mX->attach(this);
}
Exemplo n.º 9
0
void VectorPlot::addLinePlot(const VectorQwtAdapter &adapter) {
	setupPlot(adapter.boundingRect());
	QwtPlotCurve *curve = new QwtPlotCurve();

    QwtSymbol sym;
    sym.setStyle(QwtSymbol::Cross);
    sym.setPen(QColor(Qt::black));
    sym.setSize(2);
	curve->setSymbol(sym);
	curve->setPen(QColor(Qt::darkGreen));

	curve->setData(adapter);
	curve->attach(plot);
}
QwtPlotCurve* PowerBarHistoryPlot::createCurve(const QwtText& title, const QPen& pen, ArraySeriesData* data)
{
	QwtPlotCurve* curve = new QwtPlotCurve(title);
	curve->setStyle(QwtPlotCurve::Lines);
	curve->setPen(pen);

	curve->setRenderHint(QwtPlotItem::RenderAntialiased, false);
	curve->setPaintAttribute(QwtPlotCurve::ClipPolygons, true);

	curve->setData(data);
	curve->attach(m_plot);

	return curve;
}
Exemplo n.º 11
0
void Plot::drawGauss(double m, double a, int type, int i)
{
    // Insert new curves
    int j;
    QwtPlotCurve *curve = new QwtPlotCurve(QString("m: %1; a: %2").arg(m).arg(a));
    if (type == 0){
        curve->setData(new GaussData(m, a));
    }else if (type == 1){
        curve->setData(new ExpData(m, a));
    }else{
        curve->setData(new ExpData(m, -a));
    }


    switch (i % 5) {
    case 0:
        curve->setPen(Qt::red);
        break;
    case 1:
        curve->setPen(Qt::green);
        break;
    case 2:
        curve->setPen(Qt::blue);
        break;
    case 3:
        curve->setPen(Qt::magenta);
        break;
    case 4:
        curve->setPen(Qt::cyan);
        break;
    default:
        break;
    }
    curve->attach(this);

    this->replot();
}
Exemplo n.º 12
0
	EventLogger(const char* target, int eventId, int eventVariablesCount, const char* filename) :
		QwtPlot(QwtText(QString(tr("Plot for event %0")).arg(eventId))),
		eventId(eventId),
		values(eventVariablesCount)
	{
		stream = Hub::connect(target);
		cout << "Connected to " << stream->getTargetName() << endl;

		startingTime = QTime::currentTime();

		setCanvasBackground(Qt::white);
		setAxisTitle(xBottom, tr("Time (seconds)"));
		setAxisTitle(yLeft, tr("Values"));

		QwtLegend *legend = new QwtLegend;
		//legend->setItemMode(QwtLegend::CheckableItem);
		insertLegend(legend, QwtPlot::BottomLegend);

		for (size_t i = 0; i < values.size(); i++)
		{
			QwtPlotCurve *curve = new QwtPlotCurve(QString("%0").arg(i));
			#if QWT_VERSION >= 0x060000
			curve->setData(new EventDataWrapper(timeStamps, values[i]));
			#else
			curve->setData(EventDataWrapper(timeStamps, values[i]));
			#endif
			curve->attach(this);
			curve->setPen(QColor::fromHsv((i * 360) / values.size(), 255, 100));
		}

		resize(1000, 600);

		if (filename)
			outputFile.open(filename);

		startTimer(10);
	}
Exemplo n.º 13
0
            void AmplitudePlot::addSampleSource(PointSampler* src) {
                
                // Insert new curves
                QwtPlotCurve* curve = new QwtPlotCurve(src->objectName());
                _sources.insert(src, curve);
                curve->setPen(QPen(src->getColor()));
                curve->setRenderHint(QwtPlotItem::RenderAntialiased);
                
                SampleHistoryPlotDataAdapter adapter(src);
                curve->setData(adapter);
                
                curve->attach(_ui->plot);
                
                _ui->plot->setAxisScale(QwtPlot::xBottom, 0, src->getHistory().size());

                connect(src, SIGNAL(sampleHistoryChanged(const PointSampler*)), SLOT(updatePlot()));
                connect(src, SIGNAL(enabledChanged(bool)), SLOT(updateSeriesVisibility(bool)));
            }
Exemplo n.º 14
0
void VectorPlot::addPrelabelingPlot(const std::vector<double> &preLabeling)
{
	QwtDoubleRect boundingRect(0, 1, preLabeling.size() - 1, 2);

	setupPlot(boundingRect);

	QwtPlotCurve* curve = new QwtPlotCurve;

	QwtArray<double> xData, yData;
	for(unsigned i = 0; i < preLabeling.size(); ++i) {
		xData.push_back(i);
		yData.push_back(preLabeling[i] >= 0 ? preLabeling[i] : 1);
	}

	curve->setData(xData, yData);

	curve->attach(plot);
}
Exemplo n.º 15
0
void
MainWindow::sampleSeriesAdded(int index)
{
  SampleSeries series = adapter->getSampleSeries(index);

  QwtPlotCurve *curve = new QwtPlotCurve();

  curve->setData(new SampleSeries(series));
  curve->setTitle(SampleSeries::toString(series.unit()));

  QPen pen(getColor(series.unit()));
  pen.setWidth(3);

  curve->setPen(pen);

  ui->plot->enableAxis(curve->yAxis());
  curve->attach(ui->plot);
}
Exemplo n.º 16
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void StatsGenPlotWidget::createPowerCurve(int tableRow, float& xMax, float& yMax)
{
  QwtPlotCurve* curve = m_PlotCurves[tableRow];
  int err = 0;
  float alpha = m_TableModel->getDataValue(SGPowerLawTableModel::Alpha, tableRow);
  float k = m_TableModel->getDataValue(SGPowerLawTableModel::K, tableRow);
  float beta = m_TableModel->getDataValue(SGPowerLawTableModel::Beta, tableRow);
  int size = 256;
  QwtArray<float> x;
  QwtArray<float> y;

  err = StatsGen::GenPowerLawPlotData<QwtArray<float > > (alpha, k, beta, x, y, size);
  if (err == 1)
  {
    //TODO: Present Error Message
    return;
  }

  QwtArray<double> xD(size);
  QwtArray<double> yD(size);
  for (int i = 0; i < size; ++i)
  {
    //   qDebug() << x[i] << "  " << y[i] << "\n";
    if (x[i] > xMax)
    {
      xMax = x[i];
    }
    if (y[i] > yMax)
    {
      yMax = y[i];
    }
    xD[i] = static_cast<double>(x[i]);
    yD[i] = static_cast<double>(y[i]);
  }
#if QWT_VERSION >= 0x060000
  curve->setSamples(xD, yD);
#else
  curve->setData(xD, yD);
#endif

  m_PlotView->setAxisScale(QwtPlot::yLeft, 0.0, yMax);
  m_PlotView->setAxisScale(QwtPlot::xBottom, 0.0, xMax);
}
Exemplo n.º 17
0
void CBioPlot::AddCurve( int pen_width )
{
	boost::mutex::scoped_lock lock(data_lock);

	// sanity check
	if ( thePlot == NULL )
	{
		cerr << "Woops, no plot!" << endl;
		throw;
	}

	// don't add more crves if we are at the max
	if ( NumCurves() >= BIOPLOT_MAX_CURVES ) return;

	size_t curve_num = NumCurves();

	// create a new curve for this data set
	QwtPlotCurve * curve = new QwtPlotCurve();
	theCurves.push_back( curve );

	// add the curve to the plot
	curve->attach(thePlot);

	// set the color of the curve
	QPen * pen = new QPen;
	thePens.push_back( pen );

	pen->setColor( QColor( curve_colors[curve_num] ) );
	pen->setWidth( pen_width );

	/* set pen to curve */
	curve->setPen( *pen );

	// add a data set for this curve and bind it to the curve
	theDataX.push_back( data_t() );
	theDataY.push_back( data_t() );
	curve->setData( theDataX[curve_num], theDataY[curve_num] );

	// change style or quality of the curve
	//curve->setStyle( QwtPlotCurve::Dots );
	//curve->setRenderHint(QwtPlotItem::RenderAntialiased);

}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void StatsGenRDFWidget::updateRDFPlot(QVector<float>& freqs)
{
  // These are the output vectors
  QwtArray<double> xD(static_cast<int>(freqs.size()));
  QwtArray<double> yD(static_cast<int>(freqs.size()));

  QLocale loc = QLocale::system();

  bool ok = false;
  float minDist = loc.toFloat(minDistLE->text(), &ok);
  float maxDist = loc.toFloat(maxDistLE->text(), &ok);

  const int numValues = freqs.size();
  float increment = (maxDist - minDist) / numValues;

  double pos = minDist;

  for (qint32 i = 0; i < numValues; ++i)
  {
    xD[i] = pos;
    yD[i] = static_cast<double>(freqs.at(i));
    pos = pos + increment;
  }

  // This will actually plot the XY data in the Qwt plot widget
  QwtPlotCurve* curve = m_PlotCurve;
#if QWT_VERSION >= 0x060000
  curve->setSamples(xD, yD);
#else
  curve->setData(xD, yD);
#endif
  curve->setStyle(QwtPlotCurve::Lines);
  //Use Antialiasing to improve plot render quality
  curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  QPen pen;
  pen.setColor(Qt::white);
  pen.setWidth(2);
  curve->setPen(pen);//Set colour and thickness for drawing the curve
  curve->attach(m_RDFPlot);
  m_RDFPlot->replot();
}
Exemplo n.º 19
0
void Plot::populate()
{
    // Insert new curves
    QwtPlotCurve *cSin = new QwtPlotCurve( "y = sin(x)" );
    cSin->setRenderHint( QwtPlotItem::RenderAntialiased );
    cSin->setLegendAttribute( QwtPlotCurve::LegendShowLine, true );
    cSin->setPen( Qt::red );
    cSin->attach( this );

    cSin->setData( new Data() );



    CurveTracker* tracker = new CurveTracker( canvas() );

    // for the demo we want the tracker to be active without
    // having to click on the canvas
    tracker->setStateMachine( new QwtPickerTrackerMachine() );
    tracker->setRubberBandPen( QPen( "MediumOrchid" ) );

}
Exemplo n.º 20
0
void SetWPDlg::on_pb_test2_clicked() {

	QwtDial *p = ui->dial;
	p->setValue(10.0);
	QwtKnob *k = ui->knob;
	k->setValue(10.0);

	QwtPlot *pp = ui->qwtPlot;
    pp->setAxisScale(QwtPlot::xBottom, 0.0, 10.0);
    pp->setAxisScale(QwtPlot::yLeft, -1.0, 1.0);

    pp->setTitle("fsdafdafdafdaadsf");

	QwtPlotCurve *c = new QwtPlotCurve("curve1");
    c->setRenderHint(QwtPlotItem::RenderAntialiased);
    c->setPen(QPen(Qt::red));
    c->setData(new SinusDataT());
    c->attach(pp);
    pp->show();

}
Exemplo n.º 21
0
void LinePlot::linePlotData(LinePlotData::Ptr data,  const std::string& name, QColor color, double offset )
{
  if (!data) return;


  // set based on data - record overall min and max
  if ( (data->minX() < m_xAxisMin) || (data->maxX() > m_xAxisMax) )
  {
    if  (data->minX() < m_xAxisMin) m_xAxisMin = data->minX();
    if  (data->maxX() > m_xAxisMax) m_xAxisMax = data->maxX();
  }
  if (numberOfCurves() == 0)
  {
    m_lineThickness = 10;
  }


  /// todo - curve collection - shared pointers
  QwtPlotCurve * curve = new QwtPlotCurve(toQString(name));
  if (color == Qt::color0) 
  { // generate new color from color map
    color = curveColor(m_lastColor);
    m_lastColor = color;
  }
  curve->setPen(curvePen(color));
  curve->attach(m_qwtPlot);
  curve->setData(*data);

  // check for number of different units (std::string  based)
  QString curveUnits = toQString(data->units());
  if (m_leftAxisUnits == "NONE SPECIFIED")
  {
    m_leftAxisUnits = curveUnits;
    this->leftAxisTitleFromUnits(toString(m_leftAxisUnits));
    curve->setYAxis(QwtPlot::yLeft);
    m_qwtPlot->enableAxis(QwtPlot::yRight, false);
  }
  else if (m_leftAxisUnits.toUpper() == curveUnits.toUpper())
  {
    curve->setYAxis(QwtPlot::yLeft);
    m_qwtPlot->enableAxis(QwtPlot::yRight, false);
  }
  else if (m_rightAxisUnits == "NONE SPECIFIED")
  {
    m_rightAxisUnits = curveUnits;
    this->rightAxisTitleFromUnits(toString(m_rightAxisUnits));
    curve->setYAxis(QwtPlot::yRight);
    m_qwtPlot->enableAxis(QwtPlot::yRight, true);
  }
  else if (m_rightAxisUnits.toUpper() == curveUnits.toUpper())
  {
    curve->setYAxis(QwtPlot::yRight);
    m_qwtPlot->enableAxis(QwtPlot::yRight, true);
  }
  else // more than 2 units - scale all curves
  {
    scaleCurves(curve);
    m_qwtPlot->enableAxis(QwtPlot::yRight, false);
    this->leftAxisTitle("Scaled");
  }



/// update legend and replot
  showCurve(curve, true);

//  initZoomer();

}
Exemplo n.º 22
0
void
CpintPlot::plot_allCurve(CpintPlot *thisPlot,
                         int n_values,
                         const double *power_values)
{
    clear_CP_Curves();

    QVector<double> energyBests(n_values);
    QVector<double> time_values(n_values);
    // generate an array of time values
    for (int t = 0; t < n_values; t++) {
        time_values[t] = (t + 1) / 60.0;
        energyBests[t] = power_values[t] * time_values[t] * 60.0 / 1000.0;
    }

    // generate zones from derived CP value
    if (cp > 0) {
        QList <int> power_zone;
        int n_zones = zones->lowsFromCP(&power_zone, (int) int(cp));
        int high = n_values - 1;
        int zone = 0;
        while (zone < n_zones && high > 0) {
            int low = high - 1;
            int nextZone = zone + 1;
            if (nextZone >= power_zone.size())
                low = 0;
            else {
                while ((low > 0) && (power_values[low] < power_zone[nextZone]))
                    --low;
            }

            QColor color = zoneColor(zone, n_zones);
            QString name = zones->getDefaultZoneName(zone);
            QwtPlotCurve *curve = new QwtPlotCurve(name);
            if (appsettings->value(this, GC_ANTIALIAS, false).toBool() == true)
                curve->setRenderHint(QwtPlotItem::RenderAntialiased);
            QPen pen(color.darker(200));
            pen.setWidth(appsettings->value(this, GC_LINEWIDTH, 2.0).toDouble());
            curve->setPen(pen);
            curve->attach(thisPlot);

            // use a linear gradient
            color.setAlpha(180);
            QColor color1 = color;
            color1.setAlpha(64);
            QLinearGradient linearGradient(0, 0, 0, height());
            linearGradient.setColorAt(0.0, color);
            linearGradient.setColorAt(1.0, color1);
            linearGradient.setSpread(QGradient::PadSpread);
            curve->setBrush(linearGradient);   // fill below the line

            if (series == RideFile::none) { // this is Energy mode 
                curve->setData(time_values.data() + low,
                               energyBests.data() + low, high - low + 1);
            } else {
                curve->setData(time_values.data() + low,
                               power_values + low, high - low + 1);
            }
            allCurves.append(curve);

            if (series != RideFile::none || energyBests[high] > 100.0) {
                QwtText text(name);
                text.setFont(QFont("Helvetica", 20, QFont::Bold));
                color.setAlpha(255);
                text.setColor(color);
                QwtPlotMarker *label_mark = new QwtPlotMarker();
                // place the text in the geometric mean in time, at a decent power
                double x, y;
                if (series == RideFile::none) {
                    x = (time_values[low] + time_values[high]) / 2;
                    y = (energyBests[low] + energyBests[high]) / 5;
                }
                else {
                    x = sqrt(time_values[low] * time_values[high]);
                    y = (power_values[low] + power_values[high]) / 5;
                }
                label_mark->setValue(x, y);
                label_mark->setLabel(text);
                label_mark->attach(thisPlot);
                allZoneLabels.append(label_mark);
            }

            high = low;
            ++zone;
        }
    }
    // no zones available: just plot the curve without zones
    else {
        QwtPlotCurve *curve = new QwtPlotCurve(tr("maximal power"));
        if (appsettings->value(this, GC_ANTIALIAS, false).toBool() == true)
            curve->setRenderHint(QwtPlotItem::RenderAntialiased);
        QPen pen(GColor(CCP));
        pen.setWidth(appsettings->value(this, GC_LINEWIDTH, 2.0).toDouble());
        curve->setPen(pen);
        QColor brush_color = GColor(CCP);
        brush_color.setAlpha(200);
        curve->setBrush(brush_color);   // brush fills below the line
        if (series == RideFile::none)
            curve->setData(time_values.data(), energyBests.data(), n_values);
        else
            curve->setData(time_values.data(), power_values, n_values);
        curve->attach(thisPlot);
        allCurves.append(curve);
    }

    // Energy mode is really only interesting in the range where energy is
    // linear in interval duration--up to about 1 hour.
    double xmax = (series == RideFile::none)  ? 60.0 : time_values[n_values - 1];

    if (series == RideFile::vam)
        thisPlot->setAxisScale(thisPlot->xBottom, (double) 4.993, (double)xmax);
    else
        thisPlot->setAxisScale(thisPlot->xBottom, (double) 0.017, (double)xmax);

    double ymax;
    if (series == RideFile::none) {
        int i = std::lower_bound(time_values.begin(), time_values.end(), 60.0) - time_values.begin();
        ymax = 10 * ceil(energyBests[i] / 10);
    }
    else {
        ymax = 100 * ceil(power_values[0] / 100);
        if (ymax == 100)
            ymax = 5 * ceil(power_values[0] / 5);
    }
    thisPlot->setAxisScale(thisPlot->yLeft, 0, ymax);
}
Exemplo n.º 23
0
void
PfPvPlot::refreshZoneItems()
{
    // clear out any zone curves which are presently defined
    if (zoneCurves.size()) {

        QListIterator<QwtPlotCurve *> i(zoneCurves);
        while (i.hasNext()) {
            QwtPlotCurve *curve = i.next();
            curve->detach();
            delete curve;
        }
    }
    zoneCurves.clear();

    // delete any existing power zone labels
    if (zoneLabels.size()) {

        QListIterator<PfPvPlotZoneLabel *> i(zoneLabels);
        while (i.hasNext()) {
            PfPvPlotZoneLabel *label = i.next();
            label->detach();
            delete label;
        }
    }
    zoneLabels.clear();

    // give up for a null ride
    if (! rideItem) return;

    const Zones *zones = rideItem->zones;
    int zone_range = rideItem->zoneRange();

    if (zone_range >= 0) {
        setCP(zones->getCP(zone_range));

        // populate the zone curves
        QList <int> zone_power = zones->getZoneLows(zone_range);
        QList <QString> zone_name = zones->getZoneNames(zone_range);
        int num_zones = zone_power.size();
        assert(zone_name.size() == num_zones);

        if (num_zones > 0) {
            QPen *pen = new QPen();
            pen->setStyle(Qt::NoPen);

            QwtArray<double> yvalues;

            // generate x values
            for (int z = 0; z < num_zones; z ++) {

                QwtPlotCurve *curve = new QwtPlotCurve(zone_name[z]);

                curve->setPen(*pen);
                QColor brush_color = zoneColor(z, num_zones);
                brush_color.setHsv(brush_color.hue(), brush_color.saturation() / 4, brush_color.value());
                curve->setBrush(brush_color);   // fill below the line
                curve->setZ(1 - 1e-6 * zone_power[z]);

                // generate data for curve
                if (z < num_zones - 1) {
                    QwtArray <double> contour_yvalues;
                    int watts = zone_power[z + 1];
                    int dwatts = (double) watts;
                    for (int i = 0; i < contour_xvalues.size(); i ++) {
                        contour_yvalues.append( (1e6 * contour_xvalues[i] < watts) ?  1e6 : dwatts / contour_xvalues[i]);
                    }
                    curve->setData(contour_xvalues, contour_yvalues);

                } else {

                    // top zone has a curve at "infinite" power
                    QwtArray <double> contour_x;
                    QwtArray <double> contour_y;
                    contour_x.append(contour_xvalues[0]);
                    contour_x.append(contour_xvalues[contour_xvalues.size() - 1]);
                    contour_y.append(1e6);
                    contour_y.append(1e6);
                    curve->setData(contour_x, contour_y);
                }

                curve->setVisible(shade_zones);
                curve->attach(this);
                zoneCurves.append(curve);
            }

            delete pen;

            // generate labels for existing zones
            for (int z = 0; z < num_zones; z ++) {
                PfPvPlotZoneLabel *label = new PfPvPlotZoneLabel(this, z);
                label->setVisible(shade_zones);
                label->attach(this);
                zoneLabels.append(label);
            }
        }
    }
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void StatsGenMDFWidget::updateMDFPlot(QVector<float>& odf)
{
  int err = 0;
  int size = 100000;

  // These are the input vectors
  QVector<float> angles;
  QVector<float> axes;
  QVector<float> weights;

  angles = m_MDFTableModel->getData(SGMDFTableModel::Angle);
  weights = m_MDFTableModel->getData(SGMDFTableModel::Weight);
  axes = m_MDFTableModel->getData(SGMDFTableModel::Axis);

  // These are the output vectors
  QVector<float> x;
  QVector<float> y;
  if ( Ebsd::CrystalStructure::Cubic_High == m_CrystalStructure )
  {
    // Allocate a new vector to hold the mdf data
    QVector<float> mdf(CubicOps::k_MdfSize);
    // Calculate the MDF Data using the ODF data and the rows from the MDF Table model
    Texture::CalculateMDFData<float, CubicOps>(angles.data(), axes.data(), weights.data(), odf.data(), mdf.data(), static_cast<size_t>(angles.size()));
    // Now generate the actual XY point data that gets plotted.
    int npoints = 13;
    x.resize(npoints);
    y.resize(npoints);
    err = StatsGen::GenCubicMDFPlotData(mdf.data(), x.data(), y.data(), npoints, size);
    if (err < 0)
    {
      return;
    }
  }
  else if ( Ebsd::CrystalStructure::Hexagonal_High == m_CrystalStructure )
  {
    // Allocate a new vector to hold the mdf data
    QVector<float> mdf(HexagonalOps::k_MdfSize);
    // Calculate the MDF Data using the ODF data and the rows from the MDF Table model
    Texture::CalculateMDFData<float, HexagonalOps>(angles.data(), axes.data(), weights.data(), odf.data(), mdf.data(), static_cast<size_t>(angles.size()));
    // Now generate the actual XY point data that gets plotted.
    int npoints = 20;
    x.resize(npoints);
    y.resize(npoints);
    err = StatsGen::GenHexMDFPlotData(mdf.data(), x.data(), y.data(), npoints, size);
    if (err < 0) { return; }
  }

  QwtArray<double> xD(static_cast<int>(x.size()));
  QwtArray<double> yD(static_cast<int>(x.size()));
  for (qint32 i = 0; i < x.size(); ++i)
  {
    xD[i] = static_cast<double>(x.at(i));
    yD[i] = static_cast<double>(y.at(i));
  }


  // This will actually plot the XY data in the Qwt plot widget
  QwtPlotCurve* curve = m_PlotCurve;
#if QWT_VERSION >= 0x060000
  curve->setSamples(xD, yD);
#else
  curve->setData(xD, yD);
#endif
  QColor color = QColor("DodgerBlue");
  curve->setPen(color, 2);
  curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
  curve->setStyle(QwtPlotCurve::Lines);
  QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
      QBrush( Qt::white ), QPen( color, 2 ), QSize( 8, 8 ) );
  curve->setSymbol( symbol );
  curve->attach(m_MDFPlot);
  m_MDFPlot->replot();
}
Exemplo n.º 25
0
	EventViewer::EventViewer(unsigned eventId, const QString& eventName, unsigned eventVariablesCount, MainWindow::EventViewers* eventsViewers) :
		eventId(eventId),
		eventsViewers(eventsViewers),
		values(eventVariablesCount),
		startingTime(QTime::currentTime())
	{
		QSettings settings;
		
		// create plot
		plot = new QwtPlot;
		plot->setCanvasBackground(Qt::white);
		plot->setAxisTitle(plot->xBottom, tr("Time (seconds)"));
		plot->setAxisTitle(plot->yLeft, tr("Values"));
		
		QwtLegend *legend = new QwtLegend;
		//legend->setItemMode(QwtLegend::CheckableItem);
		plot->insertLegend(legend, QwtPlot::BottomLegend);
		
		for (size_t i = 0; i < values.size(); i++)
		{
			QwtPlotCurve *curve = new QwtPlotCurve(QString("%0").arg(i));
			#if QWT_VERSION >= 0x060000
			curve->setData(new EventDataWrapper(timeStamps, values[i]));
			#else
			curve->setData(EventDataWrapper(timeStamps, values[i]));
			#endif
			curve->attach(plot);
			curve->setPen(QPen(QColor::fromHsv((i * 360) / values.size(), 255, 100), 2));
		}
		
		QVBoxLayout *layout = new QVBoxLayout(this);
		layout->addWidget(plot);
		
		// add control
		QHBoxLayout *controlLayout = new QHBoxLayout;
		
		status = new QLabel(tr("Recording..."));
		controlLayout->addWidget(status);
		
		pauseRunButton = new QPushButton(QPixmap(QString(":/images/pause.png")), tr("&Pause"));
		connect(pauseRunButton, SIGNAL(clicked()), SLOT(pauseRunCapture()));
		controlLayout->addWidget(pauseRunButton);
		
		QPushButton *clearButton = new QPushButton(QPixmap(QString(":/images/reset.png")), tr("&Clear"));
		connect(clearButton, SIGNAL(clicked()), SLOT(clearPlot()));
		controlLayout->addWidget(clearButton);
		
		const bool timeWindowEnabled(settings.value("EventViewer/timeWindowEnabled", false).toBool());
		timeWindowCheckBox = new QCheckBox(tr("time &window:"));
		controlLayout->addWidget(timeWindowCheckBox);
		timeWindowCheckBox->setChecked(timeWindowEnabled);
		
		timeWindowLength = new QDoubleSpinBox;
		timeWindowLength->setSuffix("s");
		connect(timeWindowCheckBox, SIGNAL(toggled(bool)), timeWindowLength, SLOT(setEnabled(bool))); 
		timeWindowLength->setValue(settings.value("EventViewer/timeWindowLength", 10.).toDouble());
		timeWindowLength->setEnabled(timeWindowEnabled);
		controlLayout->addWidget(timeWindowLength);
		controlLayout->addStretch();
		
		QPushButton *saveToFileButton = new QPushButton(QPixmap(QString(":/images/filesaveas.png")), tr("Save &As..."));
		connect(saveToFileButton, SIGNAL(clicked()), SLOT(saveToFile()));
		controlLayout->addWidget(saveToFileButton);
		
		layout->addLayout(controlLayout);
		
		// receive events
		eventsViewers->insert(eventId, this);
		isCapturing = true;
	}
Exemplo n.º 26
0
 void setData(QVector<double> &xData, QVector<double> &yData)
 {
     workoutCurve->setData(xData, yData);
 }
Exemplo n.º 27
0
void ScatterPlot::setData (ScatterSettings *settings)
{
    // get application settings
    cranklength = appsettings->value(this, GC_CRANKLENGTH, 0.0).toDouble() / 1000.0;

    // if there are no settings or incomplete settings
    // create a null data plot
    if (settings == NULL || settings->ride == NULL || settings->ride->ride() == NULL ||
        settings->x == 0 || settings->y == 0 ) {
        return;
    }


    // if its not setup or no settings exist default to 175mm cranks
    if (cranklength == 0.0) cranklength = 0.175;

    //
    // Create Main Plot dataset - used to frame intervals
    //
    int points=0;

    x.clear();
    y.clear();
    x.resize(settings->ride->ride()->dataPoints().count());
    y.resize(settings->ride->ride()->dataPoints().count());

    double maxY = maxX = -65535;
    double minY = minX = 65535;

    foreach(const RideFilePoint *point, settings->ride->ride()->dataPoints()) {

        double xv = x[points] = pointType(point, settings->x, context->athlete->useMetricUnits, cranklength);
        double yv = y[points] = pointType(point, settings->y, context->athlete->useMetricUnits, cranklength);

        // skip zeroes?
        if (!(settings->ignore && (x[points] == 0 || y[points] == 0))) {
            points++;
            if (yv > maxY) maxY = yv;
            if (yv < minY) minY = yv;
            if (xv > maxX) maxX = xv;
            if (xv < minX) minX = xv;
        }
    }

    QwtSymbol sym;
    sym.setStyle(QwtSymbol::Ellipse);
    sym.setSize(6);
    sym.setPen(GCColor::invert(GColor(CPLOTBACKGROUND)));
    sym.setBrush(QBrush(Qt::NoBrush));
    QPen p;
    p.setColor(GColor(CPLOTSYMBOL));
    sym.setPen(p);

    // wipe away existing
	if (all) {
        all->detach();
	    delete all;
    }

    // setup the framing curve
    if (settings->frame) {
        all = new QwtPlotCurve();
        all->setSymbol(new QwtSymbol(sym));
        all->setStyle(QwtPlotCurve::Dots);
        all->setRenderHint(QwtPlotItem::RenderAntialiased);
	    all->setData(x.constData(), y.constData(), points);
        all->attach(this);
    } else {
        all = NULL;
    }

    QPen gridPen(GColor(CPLOTGRID));
    gridPen.setStyle(Qt::DotLine);

    if (grid) {
        grid->detach();
        delete grid;
    }

    if (settings->gridlines) {
        grid = new QwtPlotGrid();
        grid->setPen(gridPen);
        grid->enableX(true);
        grid->enableY(true);
        grid->attach(this);
    } else {
        grid = NULL;
    }

    setAxisTitle(yLeft, describeType(settings->y, true, useMetricUnits));
    setAxisTitle(xBottom, describeType(settings->x, true, useMetricUnits));

    // truncate PfPv values to make easier to read
    if (settings->y == MODEL_AEPF) setAxisScale(yLeft, 0, 600);
    else setAxisScale(yLeft, minY, maxY);
    if (settings->x == MODEL_CPV) setAxisScale(xBottom, 0, 3);
    else setAxisScale(xBottom, minX, maxX);

    //
    // Create Interval Plot dataset - used to frame intervals
    //

    // clear out any interval curves which are presently defined
    if (intervalCurves.size()) {
       QListIterator<QwtPlotCurve *> i(intervalCurves);
       while (i.hasNext()) {
           QwtPlotCurve *curve = i.next();
           curve->detach();
           delete curve;
       }
    }
    intervalCurves.clear();

    // which ones are highlighted then?
    QVector<int> intervals;
    QMap<int,int> displaySequence;

    for (int child=0; child<context->athlete->allIntervalItems()->childCount(); child++) {
        IntervalItem *current = dynamic_cast<IntervalItem *>(context->athlete->allIntervalItems()->child(child));
        if ((current != NULL) && current->isSelected()) {
            intervals.append(child);
            displaySequence.insert(current->displaySequence, intervals.count()-1);
        }
    }

    if (intervals.count() > 0) {

        // interval data in here
        QVector<QVector<double> > xvals(intervals.count()); // array of curve x arrays
        QVector<QVector<double> > yvals(intervals.count()); // array of curve x arrays
        QVector<int> points(intervals.count());             // points in eac curve

        // extract interval data
        foreach(const RideFilePoint *point, settings->ride->ride()->dataPoints()) {

            double x = pointType(point, settings->x, useMetricUnits, cranklength);
            double y = pointType(point, settings->y, useMetricUnits, cranklength);

            if (!(settings->ignore && (x == 0 && y ==0))) {

                // which interval is it in?
                for (int idx=0; idx<intervals.count(); idx++) {

                    IntervalItem *current = dynamic_cast<IntervalItem *>(context->athlete->allIntervalItems()->child(intervals[idx]));

                    if (point->secs+settings->ride->ride()->recIntSecs() > current->start && point->secs< current->stop) {
                        xvals[idx].append(x);
                        yvals[idx].append(y);
                        points[idx]++;
                    }
                }
            }
        }

        // now we have the interval data lets create the curves
        QMapIterator<int, int> order(displaySequence);
        while (order.hasNext()) {
            order.next();
            int idx = order.value();

            QPen pen;
            QColor intervalColor;
            intervalColor.setHsv((255/context->athlete->allIntervalItems()->childCount()) * (intervals[idx]), 255,255);
            pen.setColor(intervalColor);
            sym.setPen(pen);

            QwtPlotCurve *curve = new QwtPlotCurve();

            curve->setSymbol(new QwtSymbol(sym));
            curve->setStyle(QwtPlotCurve::Dots);
            curve->setRenderHint(QwtPlotItem::RenderAntialiased);
            curve->setData(xvals[idx].constData(), yvals[idx].constData(), points[idx]);
            curve->attach(this);

            intervalCurves.append(curve);
        }
    }