Esempio n. 1
0
void Plot::populate()
{
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setMinorPen( Qt::black, 0, Qt::DashLine );
    grid->enableXMin( true );
    grid->attach( this );

    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setTitle("Some Points");
    curve->setPen( Qt::blue, 4 ),
          curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );

    QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
                                       QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
    curve->setSymbol( symbol );

    QPolygonF points;
    points << QPointF( 10.0, 4.4 )
           << QPointF( 100.0, 3.0 ) << QPointF( 200.0, 4.5 )
           << QPointF( 300.0, 6.8 ) << QPointF( 400.0, 7.9 )
           << QPointF( 500.0, 7.1 ) << QPointF( 600.0, 7.9 )
           << QPointF( 700.0, 7.1 ) << QPointF( 800.0, 5.4 )
           << QPointF( 900.0, 2.8 ) << QPointF( 1000.0, 3.6 );
    curve->setSamples( points );
    curve->attach( this );
}
Esempio n. 2
0
void CentralWidget::initTmpPlotAndGL()
{
    QwtPlot *plot = new QwtPlot(this);
    plot->setTitle( "Plot Demo" );
    plot->setCanvasBackground( Qt::white );
    plot->setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );

    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->attach( plot );

    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setTitle( "Some Points" );
    curve->setPen( Qt::blue, 4 ),
    curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );

    QPolygonF points;
    points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
        << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
        << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
    curve->setSamples( points );
    curve->attach( plot );
    this->addTab(plot, tr("Tmp Plot"));

    MyGLWidget *widget = new MyGLWidget(this);
    this->addTab(widget, tr("Tmp OpenGL"));
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
	/*const int L = 10; 
	fftw_complex *in; 
	fftw_complex *out;
	gsl_sf_bessel_k0_scaled(0.684684);
	fftw_plan p;

	in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*L);
	out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*L);
	p = fftw_plan_dft_1d(L, in, out,FFTW_FORWARD,FFTW_MEASURE); 

	fftw_execute(p);
	fftw_destroy_plan(p);
	fftw_free(in);
	fftw_free(out);
	 
	QApplication a(argc, argv);
	Ekg w;
	w.show();
	qDebug() << "sdfsdfsd";
	std::cout << "ALKO PROJEKT CPP CHLOSTA!";			
	
	return a.exec();*/

	    QApplication a( argc, argv );
 
    QwtPlot plot;
    plot.setTitle( "Plot Demo" );
    plot.setCanvasBackground( Qt::white );
    plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
    plot.insertLegend( new QwtLegend() );
 
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->attach( &plot );
 
    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setTitle( "Some Points" );
    curve->setPen( Qt::blue, 4 ),
    curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
 
    QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
        QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
    curve->setSymbol( symbol );
 
    QPolygonF points;
    points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
        << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
        << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
    curve->setSamples( points );
 
    curve->attach( &plot );
  
    plot.resize( 600, 400 );
    plot.show(); 
  
    return a.exec();
}
Esempio n. 4
0
void MainWindow::sampleFormatChanged()
{
    for (int i = 0; i < curves.size(); i++) {
        curves[i].curve->detach();
        delete curves[i].curve;
        curves[i].data->clear();
        delete curves[i].data;
    }
    curves.clear();
    timeAxis.clear();

    QList<sampleValue> sampleList = kwp.getSample();
    int numSamples = settingsDialog->rate * settingsDialog->historySecs + 1;

    timeAxis.clear();
    for (int i = 0; i < numSamples; i++) {
        timeAxis.prepend(-i / static_cast<double>(settingsDialog->rate));
    }

    int numColors = sizeof(colorList) / sizeof(QString);

    for (int i = 0; i < sampleList.length(); i++) {
        QwtPlotCurve* curve = new QwtPlotCurve;
        QVector<double>* data = new QVector<double>();
        data->reserve(numSamples+1);
        data->fill(0, numSamples);

        QColor curveColor;
        curveColor.setNamedColor(colorList[i % numColors]);

        int blockNum = sampleList.at(i).refs.at(0).blockNum;
        int pos = sampleList.at(i).refs.at(0).pos;
        blockLabels_t label = kwp.getBlockLabel(blockNum);
        QString desc = label.desc[pos] + " " + label.subDesc[pos];

        curve->setRenderHint(QwtPlotItem::RenderAntialiased);
        curve->setPen(curveColor);
        curve->setTitle(desc);

        curve->setRawSamples(timeAxis.constData(), data->constData(), numSamples);
        curve->attach(ui->plot);

        // set legend checked
        QwtLegendItem *legendItem = qobject_cast<QwtLegendItem*>(ui->plot->legend()->find(curve));
        if (legendItem) {
            legendItem->setChecked(true);
        }

        curveAndData tmp;
        tmp.curve = curve;
        tmp.data = data;
        curves.append(tmp);
    }
}
Esempio n. 5
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;
  }

}
Esempio n. 6
0
void Plot::insertCurve( const QString &title,
                        const QColor &color, const QPolygonF &points )
{
    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setTitle( title );
    curve->setPen( color, 2 ),
          curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );

    QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
                                       QBrush( Qt::white ), QPen( color, 2 ), QSize( 8, 8 ) );
    curve->setSymbol( symbol );

    curve->setSamples( points );

    curve->attach( this );
}
Esempio n. 7
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);
}
Esempio n. 8
0
void PlotWidget::ChangeSeriesTitle(QString oldTitle, QString newTitle)
{
	QwtPlotCurve *c = _curves.value(oldTitle);
	c->setTitle(newTitle);
	//Replot();
}
void QwtPlotPropertySetDialog::onPropertyValueChanged(QtProperty * property, const QVariant & value)
{
    if(!m_enableSet)
        return;
    int id = m_property_id.getPropertyID(property);

    if (id < ID_CurveIDBase)
    {
        switch(id)
        {
            case ID_PlotTitle:
                m_plot->setTitle(value.toString());
                return;
            case ID_PlotFooter:
                m_plot->setFooter(value.toString());
                return;
            case ID_PlotCanvasBackground:
                m_plot->setCanvasBackground(QBrush(value.value<QColor>()));
                return;
            case ID_PlotEnableZoomerScroll:
                m_plot->enableZoomerScroll(value.toBool());
                return;
            case ID_PlotAxisSet:
                setAxisEnable(value.toInt());
                return;
            case ID_XBottomScale:
                setAxisScaleDrawStyle(QwtPlot::xBottom,value);
                return;
            case ID_XTopScale:
                setAxisScaleDrawStyle(QwtPlot::xTop,value);
                return;
            case ID_YLeftScale:
                setAxisScaleDrawStyle(QwtPlot::yLeft,value);
                return;
            case ID_YRightScale:
                setAxisScaleDrawStyle(QwtPlot::yRight,value);
                return;
            case ID_XBottomDateScaleType:
                m_plot->setAxisDateFormat(QwtPlot::xBottom,ChartWave_qwt::AxisDateScaleType(value.toInt()));
                return;
            case ID_XTopDateScaleType:
                m_plot->setAxisDateFormat(QwtPlot::xTop,ChartWave_qwt::AxisDateScaleType(value.toInt()));
                return;
            case ID_YLeftDateScaleType:
                m_plot->setAxisDateFormat(QwtPlot::yLeft,ChartWave_qwt::AxisDateScaleType(value.toInt()));
                return;
            case ID_YRightDateScaleType:
                m_plot->setAxisDateFormat(QwtPlot::yRight,ChartWave_qwt::AxisDateScaleType(value.toInt()));
                return;
            case ID_XBottomInterval:
            case ID_XTopInterval:
            case ID_YLeftInterval:
            case ID_YRightInterval:
                setAxisScale(id,value.toPointF());
                return;
            case ID_XBottomTitle:
            case ID_XTopTitle:
            case ID_YLeftTitle:
            case ID_YRightTitle:
                setAxisTitle(id,value.toString());
                return;
            case ID_XBottomLabelRotation:
            case ID_XTopLabelRotation:
            case ID_YLeftLabelRotation:
            case ID_YRightLabelRotation:
                setAxislabelRotation(id,value.toDouble());
                return;

        }
    }
    else
    {
        QwtPlotCurve* cur = getCurvePtr(id);
        if(!cur)
            return;
        const int propertyID = getCurvePropertyID(id);

        if (ID_CurveTitle == propertyID)
        {
            cur->setTitle(value.toString());
            return;
        }

        QPen newPen(cur->pen());
        switch (propertyID) {
            case ID_CurveColore:
                newPen.setColor(value.value<QColor>());
                break;
            case ID_CurveWidth:
                newPen.setWidth(value.toInt());
                break;
            case ID_CurvePenStyle:
                newPen.setStyle(order2penStyle(value.toInt()));
                break;
        }
        cur->setPen(newPen);
    }
}
Esempio n. 10
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    string videoName = "static";
//
//*** Pixel variation error

//  original video pixel variation (RMSE) reading
    tic();
    vector<double> RMSEO,framesO;
    double avrRMSEO;
    if(readPixelRMSE("/home/maelle/Desktop/Samples/Static/"+videoName+"/"+videoName+".avi",RMSEO,framesO,avrRMSEO)>0) return -1;
    toc();

//  fusion stabilized video pixel variation (RMSE) reading
    tic();
    vector<double> RMSEF,framesF;
    double avrRMSEF;
    if(readPixelRMSE("/home/maelle/Desktop/Samples/Static/"+videoName+"/"+videoName+"_stable_F.avi",RMSEF,framesF,avrRMSEF)>0) return -1;
    toc();

//  video processing stabilized video pixel variation (RMSE) reading
    tic();
    vector<double> RMSEV,framesV;
    double avrRMSEV;
    if(readPixelRMSE("/home/maelle/Desktop/Samples/Static/"+videoName+"/"+videoName+"_stable_VP.avi",RMSEV,framesV,avrRMSEV)>0) return -1;
    toc();
//  second round fusion stabilized video pixel variation (RMSE) reading
    tic();
    vector<double> RMSEF2,framesF2;
    double avrRMSEF2;
    if(readPixelRMSE("/home/maelle/Desktop/Samples/Static/"+videoName+"/"+videoName+"_stable2_F.avi",RMSEF2,framesF2,avrRMSEF2)>0) return -1;
    toc();

//  second round video processing stabilized video pixel variation (RMSE) reading
    tic();
    vector<double> RMSEV2,framesV2;
    double avrRMSEV2;
    if(readPixelRMSE("/home/maelle/Desktop/Samples/Static/"+videoName+"/"+videoName+"_stable2_VP.avi",RMSEV2,framesV2,avrRMSEV2)>0) return -1;
    toc();

//  plot first round
    QwtPlot plotRMSE;
    plotRMSE.setTitle("Root Mean Squared pixel variation per frame");
    plotRMSE.setCanvasBackground(Qt::white);
    plotRMSE.insertLegend(new QwtLegend());
    plotRMSE.setAxisTitle(QwtPlot::yLeft,"RMSE (px)");
    plotRMSE.setAxisTitle(QwtPlot::xBottom,"Frame");
    QwtPlotMarker *mAO=new QwtPlotMarker();
    mAO->setLinePen(QPen(Qt::darkBlue));
    mAO->setLineStyle(QwtPlotMarker::HLine);
    mAO->setValue(0,avrRMSEO);
    mAO->attach(&plotRMSE);
    QwtPlotMarker *mAF=new QwtPlotMarker();
    mAF->setLinePen(QPen(Qt::darkRed));
    mAF->setLineStyle(QwtPlotMarker::HLine);
    mAF->setValue(0,avrRMSEF);
    mAF->attach(&plotRMSE);
    QwtPlotMarker *mAV=new QwtPlotMarker();
    mAV->setLinePen(QPen(Qt::darkGreen));
    mAV->setLineStyle(QwtPlotMarker::HLine);
    mAV->setValue(0,avrRMSEV);
    mAV->attach(&plotRMSE);
    QwtPlotCurve *curveRMSEO = new QwtPlotCurve();
    curveRMSEO->setTitle("Original");
    curveRMSEO->setPen(Qt::blue,2);
    curveRMSEO->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curveRMSEO->setRawSamples(framesO.data(),RMSEO.data(),framesO.size());
    curveRMSEO->attach(&plotRMSE);
    QwtPlotCurve *curveRMSEF = new QwtPlotCurve();
    curveRMSEF->setTitle("Fusion stabilized");
    curveRMSEF->setPen(Qt::red,2);
    curveRMSEF->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curveRMSEF->setRawSamples(framesF.data(),RMSEF.data(),framesF.size());
    curveRMSEF->attach(&plotRMSE);
    QwtPlotCurve *curveRMSEV = new QwtPlotCurve();
    curveRMSEV->setTitle("Video Processing stabilized");
    curveRMSEV->setPen(Qt::green,2);
    curveRMSEV->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curveRMSEV->setRawSamples(framesV.data(),RMSEV.data(),framesV.size());
    curveRMSEV->attach(&plotRMSE);
    plotRMSE.resize(600,400);
    plotRMSE.show();

//  plot second round
    QwtPlot plotRMSE2;
    plotRMSE2.setTitle("Root Mean Squared pixel variation per frame (second round)");
    plotRMSE2.setCanvasBackground(Qt::white);
    plotRMSE2.insertLegend(new QwtLegend());
    plotRMSE2.setAxisTitle(QwtPlot::yLeft,"RMSE (px)");
    plotRMSE2.setAxisTitle(QwtPlot::xBottom,"Frame");
    QwtPlotMarker *mAO2=new QwtPlotMarker();
    mAO2->setLinePen(QPen(Qt::darkBlue));
    mAO2->setLineStyle(QwtPlotMarker::HLine);
    mAO2->setValue(0,avrRMSEO);
    mAO2->attach(&plotRMSE2);
    QwtPlotMarker *mAOF=new QwtPlotMarker();
    mAOF->setLinePen(QPen(Qt::darkCyan));
    mAOF->setLineStyle(QwtPlotMarker::HLine);
    mAOF->setValue(0,avrRMSEF);
    mAOF->attach(&plotRMSE2);
    QwtPlotMarker *mAF2=new QwtPlotMarker();
    mAF2->setLinePen(QPen(Qt::darkRed));
    mAF2->setLineStyle(QwtPlotMarker::HLine);
    mAF2->setValue(0,avrRMSEF2);
    mAF2->attach(&plotRMSE2);
    QwtPlotMarker *mAV2=new QwtPlotMarker();
    mAV2->setLinePen(QPen(Qt::darkGreen));
    mAV2->setLineStyle(QwtPlotMarker::HLine);
    mAV2->setValue(0,avrRMSEV2);
    mAV2->attach(&plotRMSE2);
    QwtPlotCurve *curveRMSEO2 = new QwtPlotCurve();
    curveRMSEO2->setTitle("Original");
    curveRMSEO2->setPen(Qt::blue,2);
    curveRMSEO2->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curveRMSEO2->setRawSamples(framesO.data(),RMSEO.data(),framesO.size());
    curveRMSEO2->attach(&plotRMSE2);
    QwtPlotCurve *curveRMSEOF = new QwtPlotCurve();
    curveRMSEOF->setTitle("First round fusion stabilized");
    curveRMSEOF->setPen(Qt::cyan,2);
    curveRMSEOF->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curveRMSEOF->setRawSamples(framesF.data(),RMSEF.data(),framesF.size());
    curveRMSEOF->attach(&plotRMSE2);
    QwtPlotCurve *curveRMSEF2 = new QwtPlotCurve();
    curveRMSEF2->setTitle("Fusion stabilized");
    curveRMSEF2->setPen(Qt::red,2);
    curveRMSEF2->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curveRMSEF2->setRawSamples(framesF2.data(),RMSEF2.data(),framesF2.size());
    curveRMSEF2->attach(&plotRMSE2);
    QwtPlotCurve *curveRMSEV2 = new QwtPlotCurve();
    curveRMSEV2->setTitle("Video Processing stabilized");
    curveRMSEV2->setPen(Qt::green,2);
    curveRMSEV2->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curveRMSEV2->setRawSamples(framesV2.data(),RMSEV2.data(),framesV2.size());
    curveRMSEV2->attach(&plotRMSE2);
    plotRMSE2.resize(600,400);
    plotRMSE2.show();

//
//*** Flow

//  original video motion flows reading
    tic();
    vector<double> xflowsO,yflowsO,framesFlowO;
    double avrxO=0,avryO=0;
    if(readFlows("/home/maelle/Desktop/Samples/Static/"+videoName+"/"+videoName+".avi",xflowsO,yflowsO,framesFlowO,avrxO,avryO,true)>0) return -1;
    toc();

//  fusion stabilized video motion flows reading
    tic();
    vector<double> xflowsF,yflowsF,framesFlowF;
    double avrxF=0,avryF=0;
    if(readFlows("/home/maelle/Desktop/Samples/Static/"+videoName+"/"+videoName+"_stable_F.avi",xflowsF,yflowsF,framesFlowF,avrxF,avryF,true)>0) return -1;
    toc();

//  video processing stabilized video motion flows reading
    tic();
    vector<double> xflowsV,yflowsV,framesFlowV;
    double avrxV=0,avryV=0;
    if(readFlows("/home/maelle/Desktop/Samples/Static/"+videoName+"/"+videoName+"_stable_VP.avi",xflowsV,yflowsV,framesFlowV,avrxV,avryV,true)>0) return -1;
    toc();

//  second round fusion stabilized video motion flows reading
    tic();
    vector<double> xflowsF2,yflowsF2,framesFlowF2;
    double avrxF2=0,avryF2=0;
    if(readFlows("/home/maelle/Desktop/Samples/Static/"+videoName+"/"+videoName+"_stable2_F.avi",xflowsF2,yflowsF2,framesFlowF2,avrxF2,avryF2,true)>0) return -1;
    toc();

//  second round video processing stabilized video motion flows reading
    tic();
    vector<double> xflowsV2,yflowsV2,framesFlowV2;
    double avrxV2=0,avryV2=0;
    if(readFlows("/home/maelle/Desktop/Samples/Static/"+videoName+"/"+videoName+"_stable2_VP.avi",xflowsV2,yflowsV2,framesFlowV2,avrxV2,avryV2,true)>0) return -1;
    toc();

//  plots
    QwtPlot plotxFlow;
    plotxFlow.setTitle("Average horizontal flow per frame");
    plotxFlow.setCanvasBackground(Qt::white);
    plotxFlow.insertLegend(new QwtLegend());
    plotxFlow.setAxisTitle(QwtPlot::yLeft,"Flow (px)");
    plotxFlow.setAxisTitle(QwtPlot::xBottom,"Frame");
    QwtPlotMarker *mxAO=new QwtPlotMarker();
    mxAO->setLinePen(QPen(Qt::darkBlue));
    mxAO->setLineStyle(QwtPlotMarker::HLine);
    mxAO->setValue(0,avrxO);
    mxAO->attach(&plotxFlow);
    QwtPlotMarker *mxAF=new QwtPlotMarker();
    mxAF->setLinePen(QPen(Qt::darkRed));
    mxAF->setLineStyle(QwtPlotMarker::HLine);
    mxAF->setValue(0,avrxF);
    mxAF->attach(&plotxFlow);
    QwtPlotMarker *mxAV=new QwtPlotMarker();
    mxAV->setLinePen(QPen(Qt::darkGreen));
    mxAV->setLineStyle(QwtPlotMarker::HLine);
    mxAV->setValue(0,avrxV);
    mxAV->attach(&plotxFlow);
    QwtPlotCurve *curvexFlowO = new QwtPlotCurve();
    curvexFlowO->setTitle("Original");
    curvexFlowO->setPen(Qt::blue,2);
    curvexFlowO->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curvexFlowO->setRawSamples(framesFlowO.data(),xflowsO.data(),framesFlowO.size());
    curvexFlowO->attach(&plotxFlow);
    QwtPlotCurve *curvexFlowF = new QwtPlotCurve();
    curvexFlowF->setTitle("Fusion stabilized");
    curvexFlowF->setPen(Qt::red,2);
    curvexFlowF->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curvexFlowF->setRawSamples(framesFlowF.data(),xflowsF.data(),framesFlowF.size());
    curvexFlowF->attach(&plotxFlow);
    QwtPlotCurve *curvexFlowV = new QwtPlotCurve();
    curvexFlowV->setTitle("Video Processing stabilized");
    curvexFlowV->setPen(Qt::green,2);
    curvexFlowV->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curvexFlowV->setRawSamples(framesFlowV.data(),xflowsV.data(),framesFlowV.size());
    curvexFlowV->attach(&plotxFlow);
    plotxFlow.resize(600,400);
    plotxFlow.show();

    QwtPlot plotxFlow2;
    plotxFlow2.setTitle("Average horizontal flow per frame (second round)");
    plotxFlow2.setCanvasBackground(Qt::white);
    plotxFlow2.insertLegend(new QwtLegend());
    plotxFlow2.setAxisTitle(QwtPlot::yLeft,"Flow (px)");
    plotxFlow2.setAxisTitle(QwtPlot::xBottom,"Frame");
    QwtPlotMarker *mxAO2=new QwtPlotMarker();
    mxAO2->setLinePen(QPen(Qt::darkBlue));
    mxAO2->setLineStyle(QwtPlotMarker::HLine);
    mxAO2->setValue(0,avrxO);
    mxAO2->attach(&plotxFlow2);
    QwtPlotMarker *mxAF0=new QwtPlotMarker();
    mxAF0->setLinePen(QPen(Qt::darkCyan));
    mxAF0->setLineStyle(QwtPlotMarker::HLine);
    mxAF0->setValue(0,avrxF);
    mxAF0->attach(&plotxFlow2);
    QwtPlotMarker *mxAF2=new QwtPlotMarker();
    mxAF2->setLinePen(QPen(Qt::darkRed));
    mxAF2->setLineStyle(QwtPlotMarker::HLine);
    mxAF2->setValue(0,avrxF2);
    mxAF2->attach(&plotxFlow2);
    QwtPlotMarker *mxAV2=new QwtPlotMarker();
    mxAV2->setLinePen(QPen(Qt::darkGreen));
    mxAV2->setLineStyle(QwtPlotMarker::HLine);
    mxAV2->setValue(0,avrxV2);
    mxAV2->attach(&plotxFlow2);
    QwtPlotCurve *curvexFlowO2 = new QwtPlotCurve();
    curvexFlowO2->setTitle("Original");
    curvexFlowO2->setPen(Qt::blue,2);
    curvexFlowO2->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curvexFlowO2->setRawSamples(framesFlowO.data(),xflowsO.data(),framesFlowO.size());
    curvexFlowO2->attach(&plotxFlow2);
    QwtPlotCurve *curvexFlowFO = new QwtPlotCurve();
    curvexFlowFO->setTitle("First round fusion stabilized");
    curvexFlowFO->setPen(Qt::cyan,2);
    curvexFlowFO->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curvexFlowFO->setRawSamples(framesFlowF.data(),xflowsF.data(),framesFlowF.size());
    curvexFlowFO->attach(&plotxFlow2);
    QwtPlotCurve *curvexFlowF2 = new QwtPlotCurve();
    curvexFlowF2->setTitle("Fusion stabilized");
    curvexFlowF2->setPen(Qt::red,2);
    curvexFlowF2->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curvexFlowF2->setRawSamples(framesFlowF2.data(),xflowsF2.data(),framesFlowF2.size());
    curvexFlowF2->attach(&plotxFlow2);
    QwtPlotCurve *curvexFlowV2 = new QwtPlotCurve();
    curvexFlowV2->setTitle("Video Processing stabilized");
    curvexFlowV2->setPen(Qt::green,2);
    curvexFlowV2->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curvexFlowV2->setRawSamples(framesFlowV2.data(),xflowsV2.data(),framesFlowV2.size());
    curvexFlowV2->attach(&plotxFlow2);
    plotxFlow2.resize(600,400);
    plotxFlow2.show();

    QwtPlot plotyFlow;
    plotyFlow.setTitle("Average vertical flow per frame");
    plotyFlow.setCanvasBackground(Qt::white);
    plotyFlow.insertLegend(new QwtLegend());
    plotyFlow.setAxisTitle(QwtPlot::yLeft,"Flow (px)");
    plotyFlow.setAxisTitle(QwtPlot::xBottom,"Frame");
    QwtPlotMarker *myAO=new QwtPlotMarker();
    myAO->setLinePen(QPen(Qt::darkBlue));
    myAO->setLineStyle(QwtPlotMarker::HLine);
    myAO->setValue(0,avryO);
    myAO->attach(&plotyFlow);
    QwtPlotMarker *myAF=new QwtPlotMarker();
    myAF->setLinePen(QPen(Qt::darkRed));
    myAF->setLineStyle(QwtPlotMarker::HLine);
    myAF->setValue(0,avryF);
    myAF->attach(&plotyFlow);
    QwtPlotMarker *myAV=new QwtPlotMarker();
    myAV->setLinePen(QPen(Qt::darkGreen));
    myAV->setLineStyle(QwtPlotMarker::HLine);
    myAV->setValue(0,avryV);
    myAV->attach(&plotyFlow);
    QwtPlotCurve *curveyFlowO = new QwtPlotCurve();
    curveyFlowO->setTitle("Original");
    curveyFlowO->setPen(Qt::blue,2);
    curveyFlowO->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curveyFlowO->setRawSamples(framesFlowO.data(),yflowsO.data(),framesFlowO.size());
    curveyFlowO->attach(&plotyFlow);
    QwtPlotCurve *curveyFlowF = new QwtPlotCurve();
    curveyFlowF->setTitle("Fusion stabilized");
    curveyFlowF->setPen(Qt::red,2);
    curveyFlowF->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curveyFlowF->setRawSamples(framesFlowF.data(),yflowsF.data(),framesFlowF.size());
    curveyFlowF->attach(&plotyFlow);
    QwtPlotCurve *curveyFlowV = new QwtPlotCurve();
    curveyFlowV->setTitle("Video Processing stabilized");
    curveyFlowV->setPen(Qt::green,2);
    curveyFlowV->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curveyFlowV->setRawSamples(framesFlowV.data(),yflowsV.data(),framesFlowV.size());
    curveyFlowV->attach(&plotyFlow);
    plotyFlow.resize(600,400);
    plotyFlow.show();

    QwtPlot plotyFlow2;
    plotyFlow2.setTitle("Average vertical flow per frame (second round)");
    plotyFlow2.setCanvasBackground(Qt::white);
    plotyFlow2.insertLegend(new QwtLegend());
    plotyFlow2.setAxisTitle(QwtPlot::yLeft,"Flow (px)");
    plotyFlow2.setAxisTitle(QwtPlot::xBottom,"Frame");
    QwtPlotMarker *myAO2=new QwtPlotMarker();
    myAO2->setLinePen(QPen(Qt::darkBlue));
    myAO2->setLineStyle(QwtPlotMarker::HLine);
    myAO2->setValue(0,avryO);
    myAO2->attach(&plotyFlow2);
    QwtPlotMarker *myAF0=new QwtPlotMarker();
    myAF0->setLinePen(QPen(Qt::darkCyan));
    myAF0->setLineStyle(QwtPlotMarker::HLine);
    myAF0->setValue(0,avryF);
    myAF0->attach(&plotyFlow2);
    QwtPlotMarker *myAF2=new QwtPlotMarker();
    myAF2->setLinePen(QPen(Qt::darkRed));
    myAF2->setLineStyle(QwtPlotMarker::HLine);
    myAF2->setValue(0,avryF2);
    myAF2->attach(&plotyFlow2);
    QwtPlotMarker *myAV2=new QwtPlotMarker();
    myAV2->setLinePen(QPen(Qt::darkGreen));
    myAV2->setLineStyle(QwtPlotMarker::HLine);
    myAV2->setValue(0,avryV2);
    myAV2->attach(&plotyFlow2);
    QwtPlotCurve *curveyFlowO2 = new QwtPlotCurve();
    curveyFlowO2->setTitle("Original");
    curveyFlowO2->setPen(Qt::blue,2);
    curveyFlowO2->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curveyFlowO2->setRawSamples(framesFlowO.data(),yflowsO.data(),framesFlowO.size());
    curveyFlowO2->attach(&plotyFlow2);
    QwtPlotCurve *curveyFlowFO = new QwtPlotCurve();
    curveyFlowFO->setTitle("First round fusion stabilized");
    curveyFlowFO->setPen(Qt::cyan,2);
    curveyFlowFO->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curveyFlowFO->setRawSamples(framesFlowF.data(),yflowsF.data(),framesFlowF.size());
    curveyFlowFO->attach(&plotyFlow2);
    QwtPlotCurve *curveyFlowF2 = new QwtPlotCurve();
    curveyFlowF2->setTitle("Fusion stabilized");
    curveyFlowF2->setPen(Qt::red,2);
    curveyFlowF2->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curveyFlowF2->setRawSamples(framesFlowF2.data(),yflowsF2.data(),framesFlowF2.size());
    curveyFlowF2->attach(&plotyFlow2);
    QwtPlotCurve *curveyFlowV2 = new QwtPlotCurve();
    curveyFlowV2->setTitle("Video Processing stabilized");
    curveyFlowV2->setPen(Qt::green,2);
    curveyFlowV2->setRenderHint(QwtPlotItem::RenderAntialiased,true);
    curveyFlowV2->setRawSamples(framesFlowV2.data(),yflowsV2.data(),framesFlowV2.size());
    curveyFlowV2->attach(&plotyFlow2);
    plotyFlow2.resize(600,400);
    plotyFlow2.show();
//
    return a.exec();
}
Esempio n. 11
0
int main( int argc, char **argv )
{
    QApplication a( argc, argv );

    QwtPlot plot;
    plot.setTitle( "Plot Demo" );
    plot.setCanvasBackground( Qt::white );

    plot.setAxisScale( QwtPlot::xBottom, -1.0, 6.0 );

    QwtLegend *legend = new QwtLegend();
    legend->setDefaultItemMode( QwtLegendData::Checkable );
    plot.insertLegend( legend );

    for ( int i = 0; i < 4; i++ )
    {
        QwtPlotCurve *curve = new QwtPlotCurve();
        curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
        curve->setPen( Qt::blue );

        QBrush brush;
        QwtSymbol::Style style = QwtSymbol::NoSymbol;
        QString title;
        if ( i == 0 )
        {
            brush = Qt::magenta;
            style = QwtSymbol::Path;
            title = "Path";
        }
        else if ( i == 2 )
        {
            brush = Qt::red;
            style = QwtSymbol::Graphic;
            title = "Graphic";
        }
        else if ( i == 1 )
        {
            brush = Qt::yellow;
            style = QwtSymbol::SvgDocument;
            title = "Svg";
        }
        else if ( i == 3 )
        {
            brush = Qt::cyan;
            style = QwtSymbol::Pixmap;
            title = "Pixmap";
        }

        MySymbol *symbol = new MySymbol( style, brush );

        curve->setSymbol( symbol );
        curve->setTitle( title );
        curve->setLegendAttribute( QwtPlotCurve::LegendShowSymbol, true );
        curve->setLegendIconSize( QSize( 15, 18 ) );

        QPolygonF points;
        points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
            << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
            << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );

        points.translate( 0.0, i * 2.0 );

        curve->setSamples( points );
        curve->attach( &plot );
    }

    plot.resize( 600, 400 );
    plot.show();

    return a.exec();
}
Esempio n. 12
0
//  Generate new values 
void DataPlot::timerEvent(QTimerEvent *)
{
    for (int k = 0; k < numberOfInputPorts; k++)
        {
            int timeout = 0;
            int maxTimeout = 2;
            Bottle *b = NULL;
            
            while(b==NULL && timeout < maxTimeout) 
                {
                    b = inputPorts[k].read(false);
                    Time::delay(0.005);
                    timeout++;
                }
            if (timeout==maxTimeout)
                {
                    if(VERBOSE) fprintf(stderr, "MESSAGE: Couldn't receive data. Going to put a zero! \n");
                    for(int i = 0; i < numberOfPlots[k]; i++)
                        {
                            d_y[k][i][PLOT_SIZE - 1] = 0;
                            for ( int j = 0; j < PLOT_SIZE - 1; j++ )
                                {
                                    d_y[k][i][j] = d_y[k][i][j+1];
                                }
                        }
                }
            else
                {
                    for(int i = 0; i < numberOfPlots[k]; i++)
                        {

                            Stamp stmp;
                            inputPorts[k].getEnvelope(stmp);
#ifdef ENABLE_REALTIME
                            if (stmp.isValid()) 
                                d_x_real_time[PLOT_SIZE - 1] = (stmp.getTime() - initialTime);                            
                            
                            for ( int j = 0; j < PLOT_SIZE - 1; j++ )
                                {
                                    if(realTime)
                                        d_x_real_time[j] =  d_x_real_time[j+1];
                                }
#endif
                            if (b==NULL)
                                d_y[k][i][PLOT_SIZE - 1] = 0;
                            else
                                if (b->size()-1 >= index[k][i])
                                    {
                                        d_y[k][i][PLOT_SIZE - 1] = b->get(index[k][i]).asDouble();
                                        //if(VERBOSE) fprintf(stderr, "MESSAGE: Getting from port %d the index %d\n", k, index[k][i]);
                                    }
                            // y moves from left to right:
                            // Shift y array right and assign new value to y[0].
                            
                            for ( int j = 0; j < PLOT_SIZE - 1; j++ )
                                {
                                    d_y[k][i][j] = d_y[k][i][j+1];
                                }
                            
                            // update the display
                            //setAxisScale(QwtPlot::yLeft, min, max);
#ifdef ENABLE_REALTIME                            
                            if(numberAcquiredData==PLOT_SIZE && realTime)
                                {
                                    if(VERBOSE) fprintf(stderr, "MESSAGE: switching to real time\n");
                                    
                                    QwtPlotCurve *timeBasedCurve = new QwtPlotCurve("Data");
                                    timeBasedCurve->attach(this);
                                    timeBasedCurve->setRawData(d_x_real_time, d_y[k][i], PLOT_SIZE);
                                    timeBasedCurve->setPen(coloredPens[k%NUMBER_OF_LIN][i%NUMBER_OF_COL]);
                                    nonTimeBasedCurve[k][i].attach(NULL);
                                    
                                    //Set title
                                    char cTitle[256];
                                    sprintf(cTitle, "Data(%d)", index[k][i]);
                                    QwtText curveTitle(cTitle, QwtText::PlainText);
                                    curveTitle.setFont(plotFont);
                                    timeBasedCurve->setTitle(curveTitle); 
                                }
#endif
                        }
                }
        }
    if (acquire)
        replot();

    numberAcquiredData++;
    //if(VERBOSE) fprintf(stderr, "Number of acquired data is %d\n", numberAcquiredData);
    //QSize plotSize= this->sizeHint();
    //if(VERBOSE) fprintf(stderr, "Hint is: hInt=%d, vInt=%d\n", plotSize.height(), plotSize.width()); 

	static double before = Time::now();	
	double now = Time::now();
	static double meanEffectiveTime = 0;

	double currentEffectiveTime = (now - before)*1000.0;
	if (numberAcquiredData >= 2)
		meanEffectiveTime = (meanEffectiveTime*(numberAcquiredData-2) + currentEffectiveTime)/(numberAcquiredData-1);
	//if(VERBOSE) fprintf(stderr, "Iteration %d: Current time is %f and mean is %f\n", numberAcquiredData, currentEffectiveTime, meanEffectiveTime);	
	if (currentEffectiveTime*0.5 > d_interval)
	{
		if(VERBOSE) fprintf(stderr, "Real Timer is %f but I was supposed to run at %d ms. Mean is: %f \n", currentEffectiveTime, d_interval, meanEffectiveTime);	
	    if(VERBOSE) fprintf(stderr, "You should slow down to %d ms \n", (int) (meanEffectiveTime * 2));	
        //setTimerInterval((int) (meanEffectiveTime * 2));
	}

	before = now;

}