Esempio n. 1
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;
	}
Esempio n. 2
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. 3
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. 4
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);
            }
        }
    }
}
//
//  Initialize main window
//
DataPlot::DataPlot(QWidget *parent):
    QwtPlot(parent),
    d_interval(0),
    d_timerId(-1)
{
    // Disable polygon clipping
    QwtPainter::setDeviceClipping(false);

    // We don't need the cache here
    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
    canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);

#if QT_VERSION >= 0x040000
#ifdef Q_WS_X11
    /*
       Qt::WA_PaintOnScreen is only supported for X11, but leads
       to substantial bugs with Qt 4.2.x/Windows
     */
    canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
#endif
#endif

    alignScales();
    
    //  Initialize data
    for (int i = 0; i< PLOT_SIZE; i++)
    {
        d_x[i] = 0.5 * i;     // time axis
        d_y[i] = 0;
        d_z[i] = 0;
    }

    // Assign a title
    setTitle("A Test for High Refresh Rates");
    insertLegend(new QwtLegend(), QwtPlot::BottomLegend);

    // Insert new curves
    QwtPlotCurve *cRight = new QwtPlotCurve("Data Moving Right");
    cRight->attach(this);

    QwtPlotCurve *cLeft = new QwtPlotCurve("Data Moving Left");
    cLeft->attach(this);

    // Set curve styles
    cRight->setPen(QPen(Qt::red));
    cLeft->setPen(QPen(Qt::blue));

    // Attach (don't copy) data. Both curves use the same x array.
    cRight->setRawData(d_x, d_y, PLOT_SIZE);
    cLeft->setRawData(d_x, d_z, PLOT_SIZE);

#if 0
    //  Insert zero line at y = 0
    QwtPlotMarker *mY = new QwtPlotMarker();
    mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
    mY->setLineStyle(QwtPlotMarker::HLine);
    mY->setYValue(0.0);
    mY->attach(this);
#endif

    // Axis 
    setAxisTitle(QwtPlot::xBottom, "Time/seconds");
    setAxisScale(QwtPlot::xBottom, 0, 100);

    setAxisTitle(QwtPlot::yLeft, "Values");
    setAxisScale(QwtPlot::yLeft, -1.5, 1.5);
    
    setTimerInterval(0.0); 
}
Esempio n. 6
0
void Curves::insertNewCurve(int i)
{
    QwtPlotCurve* curve = createCurve(i);
    curves[i] = curve;
    curve->attach(ownerOuts);
}
Esempio n. 7
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);
            color.setAlpha(64);
            curve->setBrush(color);  // brush fills 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);
}
Esempio n. 8
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;

}
Esempio n. 9
0
//---------------------------------------------------------------------------
Plot::Plot( size_t streamPos, size_t Type, size_t Group, QWidget *parent ) :
    QwtPlot( parent ),
    m_streamPos( streamPos ),
    m_type( Type ),
    m_group( Group )
{
    setAutoReplot( false );

    QwtPlotCanvas* canvas = dynamic_cast<QwtPlotCanvas*>( this->canvas() );
    if ( canvas )
    {
        canvas->setFrameStyle( QFrame::Plain | QFrame::Panel );
        canvas->setLineWidth( 1 );
#if 1
        canvas->setPalette( QColor("Cornsilk") );
#endif
    }

    setAxisMaxMajor( QwtPlot::yLeft, 0 );
    setAxisMaxMinor( QwtPlot::yLeft, 0 );
    setAxisScaleDraw( QwtPlot::yLeft, new PlotScaleDrawY() );

    enableAxis( QwtPlot::xBottom, false );

    // something invalid
    setAxisScale( QwtPlot::xBottom, -1, 0 );
    setAxisScale( QwtPlot::yLeft, -1, 0 );

    // Plot grid
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->enableXMin( true );
    grid->enableYMin( true );
    grid->setMajorPen( Qt::darkGray, 0, Qt::DotLine );
    grid->setMinorPen( Qt::gray, 0 , Qt::DotLine );
    grid->attach( this );

    m_cursor = new PlotCursor( canvas );
    m_cursor->setPosition( 0 );

    // curves

    for( unsigned j = 0; j < PerStreamType[m_type].PerGroup[m_group].Count; ++j )
    {
        QwtPlotCurve* curve = new QwtPlotCurve( PerStreamType[m_type].PerItem[PerStreamType[m_type].PerGroup[m_group].Start + j].Name );
        switch (m_group)
        {
            case Group_IDET_S :
            case Group_IDET_M :
            case Group_IDET_R :
                curve->setPen( curveColor( j ), 2 );
                break;
            default :
                curve->setPen( curveColor( j ) );
        }
        curve->setRenderHint( QwtPlotItem::RenderAntialiased );
        curve->setZ( curve->z() - j ); //Invert data order (e.g. MAX before MIN)
        curve->attach( this );

        m_curves += curve;
    }

    // visual helpers
    if ( m_type == Type_Video )
    switch (m_group)
    {
        case Group_Y :
                        Plot_AddHLine( this,  16,  61,  89, 171);
                        Plot_AddHLine( this, 235, 220,  20,  60);
                        break;
        case Group_U :
        case Group_V :
                        Plot_AddHLine( this,  16,  61,  89, 171);
                        Plot_AddHLine( this, 240, 220,  20,  60);
                        break;
        case Group_Sat :
                        Plot_AddHLine( this,  88, 255,   0, 255);
                        Plot_AddHLine( this, 118, 220,  20,  60);
                        break;
        default      :  ;  
    }

    PlotPicker* picker = new PlotPicker( canvas, &PerStreamType[m_type], m_group, &m_curves );
    connect( picker, SIGNAL( moved( const QPointF& ) ), SLOT( onPickerMoved( const QPointF& ) ) );
    connect( picker, SIGNAL( selected( const QPointF& ) ), SLOT( onPickerMoved( const QPointF& ) ) );

    connect( axisWidget( QwtPlot::xBottom ), SIGNAL( scaleDivChanged() ), SLOT( onXScaleChanged() ) );

    // legend
    m_legend = new PlotLegend();
    
    connect( this, SIGNAL( legendDataChanged( const QVariant &, const QList<QwtLegendData> & ) ),
         m_legend, SLOT( updateLegend( const QVariant &, const QList<QwtLegendData> & ) ) );

    updateLegend();
}
Esempio n. 10
0
/**
 * @brief Scatterplot2dScopeConfig::loadConfiguration loads the plot configuration into the scope gadget widget
 * @param scopeGadgetWidget
 */
void Scatterplot2dScopeConfig::loadConfiguration(ScopeGadgetWidget *scopeGadgetWidget)
{
    preparePlot(scopeGadgetWidget);
    scopeGadgetWidget->setScope(this);
    scopeGadgetWidget->startTimer(m_refreshInterval);


    // Configure each data source
    foreach (Plot2dCurveConfiguration* plotCurveConfig,  m_scatterplotSourceConfigs)
    {
        QString uavObjectName = plotCurveConfig->uavObjectName;
        QString uavFieldName = plotCurveConfig->uavFieldName;
        QRgb color = plotCurveConfig->color;

        ScatterplotData* scatterplotData;

        switch(scatterplot2dType){
        case SERIES2D:
            scatterplotData = new SeriesPlotData(uavObjectName, uavFieldName);
            break;
        case TIMESERIES2D:
            scatterplotData = new TimeSeriesPlotData(uavObjectName, uavFieldName);
            break;
        }

        scatterplotData->setXWindowSize(timeHorizon);
        scatterplotData->setScalePower(plotCurveConfig->yScalePower);
        scatterplotData->setMeanSamples(plotCurveConfig->yMeanSamples);
        scatterplotData->setMathFunction(plotCurveConfig->mathFunction);

        //Generate the curve name
        QString curveName = (scatterplotData->getUavoName()) + "." + (scatterplotData->getUavoFieldName());
        if(scatterplotData->getHaveSubFieldFlag())
            curveName = curveName.append("." + scatterplotData->getUavoSubFieldName());

        //Get the uav object
        ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
        UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
        UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject((scatterplotData->getUavoName())));
        if(!obj) {
            qDebug() << "Object " << scatterplotData->getUavoName() << " is missing";
            return;
        }

        //Get the units
        QString units = getUavObjectFieldUnits(scatterplotData->getUavoName(), scatterplotData->getUavoFieldName());

        //Generate name with scaling factor appeneded
        QString curveNameScaled;
        if(plotCurveConfig->yScalePower == 0)
            curveNameScaled = curveName + "(" + units + ")";
        else
            curveNameScaled = curveName + "(x10^" + QString::number(plotCurveConfig->yScalePower) + " " + units + ")";

        QString curveNameScaledMath;
        if (plotCurveConfig->mathFunction == "None")
            curveNameScaledMath = curveNameScaled;
        else if (plotCurveConfig->mathFunction == "Boxcar average"){
            curveNameScaledMath = curveNameScaled + " (avg)";
        }
        else if (plotCurveConfig->mathFunction == "Standard deviation"){
            curveNameScaledMath = curveNameScaled + " (std)";
        }
        else
        {
            //Shouldn't be able to get here. Perhaps a new math function was added without
            // updating this list?
            Q_ASSERT(0);
        }

        while(scopeGadgetWidget->getDataSources().keys().contains(curveNameScaledMath))
            curveNameScaledMath=curveNameScaledMath+"*";

        //Create the curve plot
        QwtPlotCurve* plotCurve = new QwtPlotCurve(curveNameScaledMath);
        plotCurve->setPen(QPen(QBrush(QColor(color), Qt::SolidPattern), (qreal)1, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin));
        plotCurve->setSamples(*(scatterplotData->getXData()), *(scatterplotData->getYData()));
        plotCurve->attach(scopeGadgetWidget);
        scatterplotData->setCurve(plotCurve);

        //Keep the curve details for later
        scopeGadgetWidget->insertDataSources(curveNameScaledMath, scatterplotData);

        // Connect the UAVO
        scopeGadgetWidget->connectUAVO(obj);
    }
Esempio n. 11
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RiuPvtPlotWidget::plotCurves(RiaEclipseUnitTools::UnitSystem unitSystem, const std::vector<RigFlowDiagSolverInterface::PvtCurve>& curveArr, double pressure, double pointMarkerYValue, QString pointMarkerLabel, QString plotTitle, QString yAxisTitle)
{
    m_qwtPlot->detachItems(QwtPlotItem::Rtti_PlotCurve);
    m_qwtPlot->detachItems(QwtPlotItem::Rtti_PlotMarker);
    m_qwtCurveArr.clear();
    m_pvtCurveArr.clear();
    m_trackerPlotMarker = nullptr;


    // Construct an auxiliary curve that connects the first point in all the input curves as a visual aid
    // This should only be shown when the phase being plotted is oil
    // Will not be added to our array of qwt curves since we do not expect the user to interact with it
    {
        std::vector<double> xVals;
        std::vector<double> yVals;
        for (size_t i = 0; i < curveArr.size(); i++)
        {
            const RigFlowDiagSolverInterface::PvtCurve& curve = curveArr[i];
            if (curve.phase == RigFlowDiagSolverInterface::PvtCurve::OIL && curve.pressureVals.size() > 0 && curve.yVals.size() > 0)
            {
                xVals.push_back(curve.pressureVals[0]);
                yVals.push_back(curve.yVals[0]);
            }
        }

        if (xVals.size() > 1)
        {
            QwtPlotCurve* qwtCurve = new QwtPlotCurve();
            qwtCurve->setSamples(xVals.data(), yVals.data(), static_cast<int>(xVals.size()));

            qwtCurve->setStyle(QwtPlotCurve::Lines);
            qwtCurve->setRenderHint(QwtPlotItem::RenderAntialiased, true);

            QColor curveClr = Qt::darkGreen;
            const QPen curvePen(curveClr);
            qwtCurve->setPen(curvePen);

            qwtCurve->attach(m_qwtPlot);
        }
    }


    // Add the primary curves
    for (size_t i = 0; i < curveArr.size(); i++)
    {
        const RigFlowDiagSolverInterface::PvtCurve& curve = curveArr[i];
        QwtPlotCurve* qwtCurve = new QwtPlotCurve();

        CVF_ASSERT(curve.pressureVals.size() == curve.yVals.size());
        qwtCurve->setSamples(curve.pressureVals.data(), curve.yVals.data(), static_cast<int>(curve.pressureVals.size()));

        qwtCurve->setStyle(QwtPlotCurve::Lines);

        QColor curveClr = Qt::magenta;
        if      (curve.phase == RigFlowDiagSolverInterface::PvtCurve::GAS)   curveClr = QColor(Qt::red);
        else if (curve.phase == RigFlowDiagSolverInterface::PvtCurve::OIL)   curveClr = QColor(Qt::green);
        const QPen curvePen(curveClr);
        qwtCurve->setPen(curvePen);

        qwtCurve->setRenderHint(QwtPlotItem::RenderAntialiased, true);

        QwtSymbol* curveSymbol = new QwtSymbol(QwtSymbol::Ellipse);
        curveSymbol->setSize(6, 6);
        curveSymbol->setPen(curvePen);
        curveSymbol->setBrush(Qt::NoBrush);
        qwtCurve->setSymbol(curveSymbol);

        qwtCurve->attach(m_qwtPlot);

        m_qwtCurveArr.push_back(qwtCurve);
    }

    m_pvtCurveArr = curveArr;
    CVF_ASSERT(m_pvtCurveArr.size() == m_qwtCurveArr.size());


    // Add vertical marker line to indicate cell pressure
    if (pressure != HUGE_VAL)
    {
        QwtPlotMarker* lineMarker = new QwtPlotMarker;
        lineMarker->setXValue(pressure);
        lineMarker->setLineStyle(QwtPlotMarker::VLine);
        lineMarker->setLinePen(QPen(QColor(128, 128, 255), 1, Qt::DashLine));
        lineMarker->setLabel(QString("PRESSURE"));
        lineMarker->setLabelAlignment(Qt::AlignTop | Qt::AlignRight);
        lineMarker->setLabelOrientation(Qt::Vertical);
        lineMarker->attach(m_qwtPlot);
    }

    // Then point marker
    if (pressure != HUGE_VAL && pointMarkerYValue != HUGE_VAL)
    {
        QwtPlotMarker* pointMarker = new QwtPlotMarker;
        pointMarker->setValue(pressure, pointMarkerYValue);

        QColor markerClr(128, 0, 255);
        QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Ellipse);
        symbol->setSize(13, 13);
        symbol->setPen(QPen(markerClr, 2));
        symbol->setBrush(Qt::NoBrush);
        pointMarker->setSymbol(symbol);

        if (!pointMarkerLabel.isEmpty())
        {
            QwtText text(pointMarkerLabel);
            text.setRenderFlags(Qt::AlignLeft);
            text.setColor(markerClr);
            pointMarker->setLabel(text);
            pointMarker->setLabelAlignment(Qt::AlignTop | Qt::AlignRight);
        }

        pointMarker->attach(m_qwtPlot);
    }

    m_qwtPlot->setTitle(plotTitle);

    m_qwtPlot->setAxisTitle(QwtPlot::xBottom, QString("Pressure [%1]").arg(RiaEclipseUnitTools::unitStringPressure(unitSystem)));
    m_qwtPlot->setAxisTitle(QwtPlot::yLeft, yAxisTitle);

    updateTrackerPlotMarkerAndLabelFromPicker();

    m_qwtPlot->replot();
}
Esempio n. 12
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);
        }
    }
Esempio n. 13
0
QwtGrapher::QwtGrapher(QWidget* parent):
    QwtPlot(parent) {
    m_values = new TwoDArray<double>(3,100);
    plotLayout()->setAlignCanvasToScales(true);
    QwtLegend *legend = new QwtLegend;
    legend->setItemMode(QwtLegend::CheckableItem);
    insertLegend(legend, QwtPlot::RightLegend);

    setAxisTitle(QwtPlot::xBottom, " FitnessCases");
    /*setAxisScaleDraw(QwtPlot::xBottom,
     new TimeScaleDraw(cpuStat.upTime()));
     setAxisScale(QwtPlot::xBottom, 0, HISTORY);
     setAxisLabelRotation(QwtPlot::xBottom, -50.0);
     setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
     */
    /*
     In situations, when there is a label at the most right position of the
     scale, additional space is needed to display the overlapping part
     of the label would be taken by reducing the width of scale and canvas.
     To avoid this "jumping canvas" effect, we add a permanent margin.
     We don't need to do the same for the left border, because there
     is enough space for the overlapping label below the left scale.
     */

    QwtScaleWidget *scaleWidget = axisWidget(QwtPlot::xBottom);
    const int fmh = QFontMetrics(scaleWidget->font()).height();
    scaleWidget->setMinBorderDist(0, fmh / 2);

    setAxisTitle(QwtPlot::yLeft, "Ouput") ;
    //setAxisScale(QwtPlot::yLeft, 0, 100);

    // Background *bg = new Background();
    //bg->attach(this);

    /*CpuPieMarker *pie = new CpuPieMarker();
     pie->attach(this);
     */
    QwtPlotCurve *curve;

    curve = new QwtPlotCurve("Best");
    curve->setPen(QColor(Qt::green));
    curve->attach(this);
    m_curves[0] = curve;

    curve = new QwtPlotCurve("Average");
    curve->setPen(QColor(Qt::blue));
    curve->setZ(curve->z() - 1);
    curve->attach(this);
    m_curves[1] = curve;

    curve = new QwtPlotCurve("Worst");
    curve->setPen(QColor(Qt::black));
    curve->setZ(curve->z() - 2);
    curve->attach(this);
    m_curves[2] = curve;

    showCurve(m_curves[0], true);
    showCurve(m_curves[1], true);
    showCurve(m_curves[2], true);

    connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
            SLOT(showCurve(QwtPlotItem *, bool)));
}
void StochasticProcessWidget::setScalingEnabled(
		bool isEnabled) {
	if (infCurves.size() <= 0) {
		return;
	}

	imatrix distributionMatrix =
			process->getDistributions();
	int ubDistMatrix = Ub(distributionMatrix, 1);
	int lbDistMatrix = Lb(distributionMatrix, 1);
	unsigned int distCount = ubDistMatrix -lbDistMatrix
			+ 1;

	for (unsigned int i = 0; i < distCount; i++) {
		if (i >= infCurves.size()) {
			return;
		}

		if (infCurves[i]) {
			infCurves[i]->detach();
			delete infCurves[i];
		}

		if (supCurves[i]) {
			supCurves[i]->detach();
			delete supCurves[i];
		}
	}

	infCurves.clear();
	supCurves.clear();

	rvector statProbabilities =
			process->getStationaryProbabilities();

	for (int i = lbDistMatrix; i <= ubDistMatrix; i++) {
		ivector values = distributionMatrix[i];

		if (isEnabled) {
			values *= statProbabilities[i];
		}

		rvector inf = Inf(values);
		rvector sup = Sup(values);

		////////////////////////////////////////////
		// Update distribution graph
		////////////////////////////////////////////
		QwtPlotCurve
				*infCurve =
						PlotUtil::constructCurveFromRVector(inf);
		QwtPlotCurve
				*supCurve =
						PlotUtil::constructCurveFromRVector(sup);

		infCurve->attach(distGraph);
		supCurve->attach(distGraph);

		infCurves.push_back(infCurve);
		supCurves.push_back(supCurve);
	}

	updateColors();
}
bool StochasticProcessWidget::addIntervalDistributionToGraph(
		QString title, ivector values) {
	rvector inf = Inf(values);
	rvector sup = Sup(values);

	intervalDists.push_back(values);

	////////////////////////////////////////////
	// Update distribution graph
	////////////////////////////////////////////
	QwtPlotCurve *infCurve =
			PlotUtil::constructCurveFromRVector(inf);
	QwtPlotCurve *supCurve =
			PlotUtil::constructCurveFromRVector(sup);

	infCurve->attach(distGraph);
	supCurve->attach(distGraph);

	infCurves.push_back(infCurve);
	supCurves.push_back(supCurve);

	int columnIndex = distGraphTable->columnCount() - 1;
	distGraphTable->setColumnCount(columnIndex + 2);

	for (int i = 0; i <= 5; i++) {
		distGraphTable->setItem(
				i,
				columnIndex + 1,
				distGraphTable->takeItem(i, columnIndex));
	}

	QTableWidgetItem *valueItem = new QTableWidgetItem(QString("%1").arg(columnIndex+1));
	valueItem->setFlags(Qt::ItemIsUserCheckable
			| Qt::ItemIsEnabled);
	valueItem->setCheckState(Qt::Checked);
	valueItem->setTextAlignment(Qt::AlignCenter);
	distGraphTable->setItem(0, columnIndex, valueItem);

	double
			average =
					_double(CompUtil::getExpectationValue(values));

	QwtPlotMarker *avgMarker = new QwtPlotMarker();
	avgMarker->setLineStyle(QwtPlotMarker::VLine);
	avgMarker->setXValue(average);
	avgMarker->attach(distGraph);
	avgMarkers.push_back(avgMarker);

	QTableWidgetItem *avgItem = new QTableWidgetItem(QString("%1").arg(average));
	avgItem->setFlags(Qt::ItemIsUserCheckable
			| Qt::ItemIsEnabled);
	avgItem->setCheckState(Qt::Checked);
	avgItem->setTextAlignment(Qt::AlignCenter);
	distGraphTable->setItem(1, columnIndex, avgItem);

	distGraphTable->resizeRowsToContents();

	double
			stdDev =
					_double(CompUtil::getDistributionStandardDeviation(values));

	QwtPlotMarker *lowerStdDevMarker =
			new QwtPlotMarker();
	lowerStdDevMarker->setLineStyle(QwtPlotMarker::VLine);
	lowerStdDevMarker->setXValue(average - stdDev);
	lowerStdDevMarker->attach(distGraph);

	QwtPlotMarker *upperStdDevMarker =
			new QwtPlotMarker();
	upperStdDevMarker->setLineStyle(QwtPlotMarker::VLine);
	upperStdDevMarker->setXValue(average + stdDev);
	upperStdDevMarker->attach(distGraph);

	stdDevMarkers.push_back(PlotMarkerPair(
			lowerStdDevMarker, upperStdDevMarker));

	QTableWidgetItem *stdDevItem =
			new QTableWidgetItem(QString("%1").arg(stdDev));
	stdDevItem->setFlags(Qt::ItemIsUserCheckable
			| Qt::ItemIsEnabled);
	stdDevItem->setCheckState(Qt::Checked);
	stdDevItem->setTextAlignment(Qt::AlignCenter);
	distGraphTable->setItem(2, columnIndex, stdDevItem);

	QTableWidgetItem
			*statProbItem =
					new QTableWidgetItem(QString("%1").arg(_double(statProbs[columnIndex + Lb(statProbs)])));
	statProbItem->setTextAlignment(Qt::AlignCenter);
	distGraphTable->setItem(3, columnIndex,
			statProbItem);

	QTableWidgetItem *rangeItem = new QTableWidgetItem(QString("%1 - %2").arg(Lb(values)).arg(Ub(values)));
	rangeItem->setTextAlignment(Qt::AlignCenter);
	distGraphTable->setItem(4, columnIndex, rangeItem);

	QTableWidgetItem *selectAllItem =
			new QTableWidgetItem(tr("Show All"));
	selectAllItem->setFlags(Qt::ItemIsUserCheckable
			| Qt::ItemIsEnabled);
	selectAllItem->setCheckState(Qt::Checked);
	selectAllItem->setTextAlignment(Qt::AlignCenter);
	distGraphTable->setItem(5, columnIndex,
			selectAllItem);

	////////////////////////////////////////////
	// Update distribution table
	////////////////////////////////////////////
	int lb = Lb(values);
	int ub = Ub(values);
	int vectorSize = ub - lb + 1;
	int newDistRowCount = (int)_double(max(
			distTable->rowCount(), vectorSize + lb));
	distTable->setRowCount(newDistRowCount);
	for (int i = 0; i < newDistRowCount; i++) {
		distTable->setVerticalHeaderItem(i,
				new QTableWidgetItem(QString("%1").arg(i)));
	}

	columnIndex = distTable->columnCount();
	distTable->setColumnCount(columnIndex + 1);

	for (int i = lb; i <= ub; i++) {
		QTableWidgetItem
				*newItem =
						new QTableWidgetItem(QString("%1\n%2").arg(_double(sup[i - lb])).arg(_double(inf[i - lb])));
		distTable->setItem(i, columnIndex, newItem);
	}

	return true;
}