Example #1
0
bool Editor::eventFilter( QObject* object, QEvent* event )
{
    QwtPlot *plot = qobject_cast<QwtPlot *>( parent() );
    if ( plot && object == plot->canvas() )
    {
        switch( event->type() )
        {
            case QEvent::MouseButtonPress:
            {
                const QMouseEvent* mouseEvent =
                    dynamic_cast<QMouseEvent* >( event );

                if ( d_overlay == NULL && 
                    mouseEvent->button() == Qt::LeftButton  )
                {
                    const bool accepted = pressed( mouseEvent->pos() );
                    if ( accepted )
                    {
                        d_overlay = new Overlay( plot->canvas(), this );

                        d_overlay->updateOverlay();
                        d_overlay->show();
                    }
                }

                break;
            }
            case QEvent::MouseMove:
            {
                if ( d_overlay )
                {
                    const QMouseEvent* mouseEvent =
                        dynamic_cast< QMouseEvent* >( event );

                    const bool accepted = moved( mouseEvent->pos() );
                    if ( accepted )
                        d_overlay->updateOverlay();
                }

                break;
            }
            case QEvent::MouseButtonRelease:
            {
                const QMouseEvent* mouseEvent =
                    static_cast<QMouseEvent* >( event );

                if ( d_overlay && mouseEvent->button() == Qt::LeftButton )
                {
                    released( mouseEvent->pos() );

                    delete d_overlay;
                    d_overlay = NULL;
                }

                break;
            }
            default:
                break;
        }

        return false;
    }

    return QObject::eventFilter( object, event );
}
Example #2
0
	void PlotItem::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget*)
	{
		const auto& rect = option->rect;
#else
	void PlotItem::paint (QPainter *painter)
	{
		const auto& rect = contentsBoundingRect ().toRect ();
#endif

		QwtPlot plot;
		plot.setFrameShape (QFrame::NoFrame);
		plot.enableAxis (QwtPlot::yLeft, LeftAxisEnabled_);
		plot.enableAxis (QwtPlot::xBottom, BottomAxisEnabled_);
		plot.setAxisTitle (QwtPlot::yLeft, LeftAxisTitle_);
		plot.setAxisTitle (QwtPlot::xBottom, BottomAxisTitle_);
		plot.resize (rect.size ());

		auto setPaletteColor = [&plot] (const QColor& color, QPalette::ColorRole role) -> void
		{
			if (!color.isValid ())
				return;

			auto pal = plot.palette ();
			pal.setColor (role, { color });
			plot.setPalette (pal);
		};

		setPaletteColor (BackgroundColor_, QPalette::Window);
		setPaletteColor (TextColor_, QPalette::WindowText);
		setPaletteColor (TextColor_, QPalette::Text);

		if (!PlotTitle_.isEmpty ())
			plot.setTitle (QwtText { PlotTitle_ });

		if (MinYValue_ < MaxYValue_)
		{
			plot.setAxisAutoScale (QwtPlot::yLeft, false);
			plot.setAxisScale (QwtPlot::yLeft, MinYValue_, MaxYValue_);
		}
		plot.setAutoFillBackground (false);
		plot.setCanvasBackground (Qt::transparent);

		if (YGridEnabled_)
		{
			auto grid = new QwtPlotGrid;
			grid->enableYMin (YMinorGridEnabled_);
			grid->enableX (false);
#if QWT_VERSION >= 0x060100
			grid->setMajorPen (QPen (GridLinesColor_, 1, Qt::SolidLine));
			grid->setMinorPen (QPen (GridLinesColor_, 1, Qt::DashLine));
#else
			grid->setMajPen (QPen (GridLinesColor_, 1, Qt::SolidLine));
			grid->setMinPen (QPen (GridLinesColor_, 1, Qt::DashLine));
#endif
			grid->attach (&plot);
		}

		auto items = Multipoints_;
		if (items.isEmpty ())
			items.push_back ({ Color_, Points_ });

		if (MinXValue_ < MaxXValue_)
			plot.setAxisScale (QwtPlot::xBottom, MinXValue_, MaxXValue_);
		else if (const auto ptsCount = items.first ().Points_.size ())
			plot.setAxisScale (QwtPlot::xBottom, 0, ptsCount - 1);

		std::vector<std::unique_ptr<QwtPlotCurve>> curves;
		for (const auto& item : items)
		{
			curves.emplace_back (new QwtPlotCurve);
			const auto curve = curves.back ().get ();

			curve->setPen (QPen (item.Color_));
			auto transpColor = item.Color_;
			transpColor.setAlphaF (Alpha_);
			curve->setBrush (transpColor);

			curve->setRenderHint (QwtPlotItem::RenderAntialiased);
			curve->attach (&plot);

			curve->setSamples (item.Points_.toVector ());
		}

		plot.replot ();

		QwtPlotRenderer {}.render (&plot, painter, rect);

		const auto xExtent = CalcXExtent (plot);
		const auto yExtent = CalcYExtent (plot);
		if (xExtent != XExtent_ || yExtent != YExtent_)
		{
			XExtent_ = xExtent;
			YExtent_ = yExtent;
			emit extentsChanged ();
		}
	}
Example #3
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();
}
Example #4
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();
}
bool TitlePicker::eventFilter(QObject *object, QEvent *e)
{
	if (object != (QObject *)title)
		return FALSE;
	
    if ( object->inherits("QLabel") && e->type() == QEvent::MouseButtonDblClick)
		{
		emit doubleClicked();
        return TRUE;
		}

	if ( object->inherits("QLabel") &&  e->type() == QEvent::MouseButtonPress )
		{
		emit clicked();

		const QMouseEvent *me = (const QMouseEvent *)e;	
		if (me->button()==QEvent::RightButton)
			emit showTitleMenu();

		QwtPlot *plot = (QwtPlot *)title->parent();
		if (plot->margin() < 2 && plot->lineWidth() < 2)
			{
			QRect r = title->rect();
			r.addCoords(2, 2, -2, -2);
			if (!r.contains(me->pos()))
				emit highlightGraph();
			}

		return TRUE;
		}

	if ( object->inherits("QLabel") &&  e->type() == QEvent::MouseMove)
		{	
		const QMouseEvent *me = (const QMouseEvent *)e;			
		movedGraph=TRUE;
		emit moveGraph(me->pos());

        return TRUE;
		}
	
	if ( object->inherits("QLabel") && e->type() == QEvent::MouseButtonRelease)
		{
		const QMouseEvent *me = (const QMouseEvent *)e;
		if (me->button()== QEvent::LeftButton)
			{
			emit clicked();
			if (movedGraph)
				{
				emit releasedGraph();
				movedGraph=FALSE;
				}
        	return TRUE;
			}
		}

	if ( object->inherits("QLabel") && 
        e->type() == QEvent::KeyPress)
		{
		switch (((const QKeyEvent *)e)->key()) 
			{
			case Qt::Key_Delete: 
			emit removeTitle();	
            return TRUE;
			}
		}

    return QObject::eventFilter(object, e);
}
Example #6
0
dtkPlotViewZoomer::dtkPlotViewZoomer(dtkPlotView *parent) : QObject(parent)
{
    QwtPlot *plot = reinterpret_cast<QwtPlot *>(parent->plotWidget());
    d = new dtkPlotViewZoomerPrivate(reinterpret_cast<QwtPlotCanvas *>(plot->canvas()));
}
Example #7
0
/**
 * Odświeża bieżący wykres.
 */
void ChartsWidget::refresh()
{
    QwtPlot* plot = static_cast<QwtPlot*>(ui->tabCharts->currentWidget());
    plot->replot();
    emit sendMessage(tr("Chart refreshed"));
}
QSize MultiLayer::arrangeLayers(bool userSize) {
  const QRect rect = canvas->geometry();

  gsl_vector *xTopR = gsl_vector_calloc(
      graphs);  // ratio between top axis + title and canvas height
  gsl_vector *xBottomR =
      gsl_vector_calloc(graphs);  // ratio between bottom axis and canvas height
  gsl_vector *yLeftR = gsl_vector_calloc(graphs);
  gsl_vector *yRightR = gsl_vector_calloc(graphs);
  gsl_vector *maxXTopHeight =
      gsl_vector_calloc(rows);  // maximum top axis + title height in a row
  gsl_vector *maxXBottomHeight =
      gsl_vector_calloc(rows);  // maximum bottom axis height in a row
  gsl_vector *maxYLeftWidth =
      gsl_vector_calloc(cols);  // maximum left axis width in a column
  gsl_vector *maxYRightWidth =
      gsl_vector_calloc(cols);  // maximum right axis width in a column
  gsl_vector *Y = gsl_vector_calloc(rows);
  gsl_vector *X = gsl_vector_calloc(cols);

  int i;
  for (i = 0; i < graphs;
       i++) {  // calculate scales/canvas dimensions reports for each layer and
               // stores them in the above vectors
    Graph *gr = (Graph *)graphsList.at(i);
    QwtPlot *plot = gr->plotWidget();
    QwtPlotLayout *plotLayout = plot->plotLayout();
    QRect cRect = plotLayout->canvasRect();
    double ch = (double)cRect.height();
    double cw = (double)cRect.width();

    QRect tRect = plotLayout->titleRect();
    QwtScaleWidget *scale = (QwtScaleWidget *)plot->axisWidget(QwtPlot::xTop);

    int topHeight = 0;
    if (!tRect.isNull()) topHeight += tRect.height() + plotLayout->spacing();
    if (scale) {
      QRect sRect = plotLayout->scaleRect(QwtPlot::xTop);
      topHeight += sRect.height();
    }
    gsl_vector_set(xTopR, i, double(topHeight) / ch);

    scale = (QwtScaleWidget *)plot->axisWidget(QwtPlot::xBottom);
    if (scale) {
      QRect sRect = plotLayout->scaleRect(QwtPlot::xBottom);
      gsl_vector_set(xBottomR, i, double(sRect.height()) / ch);
    }

    scale = (QwtScaleWidget *)plot->axisWidget(QwtPlot::yLeft);
    if (scale) {
      QRect sRect = plotLayout->scaleRect(QwtPlot::yLeft);
      gsl_vector_set(yLeftR, i, double(sRect.width()) / cw);
    }

    scale = (QwtScaleWidget *)plot->axisWidget(QwtPlot::yRight);
    if (scale) {
      QRect sRect = plotLayout->scaleRect(QwtPlot::yRight);
      gsl_vector_set(yRightR, i, double(sRect.width()) / cw);
    }

    // calculate max scales/canvas dimensions ratio for each line and column and
    // stores them to vectors
    int row = i / cols;
    if (row >= rows) row = rows - 1;

    int col = i % cols;

    double aux = gsl_vector_get(xTopR, i);
    double old_max = gsl_vector_get(maxXTopHeight, row);
    if (aux >= old_max) gsl_vector_set(maxXTopHeight, row, aux);

    aux = gsl_vector_get(xBottomR, i);
    if (aux >= gsl_vector_get(maxXBottomHeight, row))
      gsl_vector_set(maxXBottomHeight, row, aux);

    aux = gsl_vector_get(yLeftR, i);
    if (aux >= gsl_vector_get(maxYLeftWidth, col))
      gsl_vector_set(maxYLeftWidth, col, aux);

    aux = gsl_vector_get(yRightR, i);
    if (aux >= gsl_vector_get(maxYRightWidth, col))
      gsl_vector_set(maxYRightWidth, col, aux);
  }

  double c_heights = 0.0;
  for (i = 0; i < rows; i++) {
    gsl_vector_set(Y, i, c_heights);
    c_heights += 1 + gsl_vector_get(maxXTopHeight, i) +
                 gsl_vector_get(maxXBottomHeight, i);
  }

  double c_widths = 0.0;
  for (i = 0; i < cols; i++) {
    gsl_vector_set(X, i, c_widths);
    c_widths += 1 + gsl_vector_get(maxYLeftWidth, i) +
                gsl_vector_get(maxYRightWidth, i);
  }

  if (!userSize) {
    l_canvas_width = int(
        (rect.width() - (cols - 1) * colsSpace - right_margin - left_margin) /
        c_widths);
    l_canvas_height = int(
        (rect.height() - (rows - 1) * rowsSpace - top_margin - bottom_margin) /
        c_heights);
  }

  QSize size = QSize(l_canvas_width, l_canvas_height);

  for (i = 0; i < graphs; i++) {
    int row = i / cols;
    if (row >= rows) row = rows - 1;

    int col = i % cols;

    // calculate sizes and positions for layers
    const int w = int(l_canvas_width * (1 + gsl_vector_get(yLeftR, i) +
                                        gsl_vector_get(yRightR, i)));
    const int h = int(l_canvas_height * (1 + gsl_vector_get(xTopR, i) +
                                         gsl_vector_get(xBottomR, i)));

    int x = left_margin + col * colsSpace;
    if (hor_align == HCenter)
      x += int(l_canvas_width *
               (gsl_vector_get(X, col) + gsl_vector_get(maxYLeftWidth, col) -
                gsl_vector_get(yLeftR, i)));
    else if (hor_align == Left)
      x += int(l_canvas_width * gsl_vector_get(X, col));
    else if (hor_align == Right)
      x +=
          int(l_canvas_width *
              (gsl_vector_get(X, col) + gsl_vector_get(maxYLeftWidth, col) -
               gsl_vector_get(yLeftR, i) + gsl_vector_get(maxYRightWidth, col) -
               gsl_vector_get(yRightR, i)));

    int y = top_margin + row * rowsSpace;
    if (vert_align == VCenter)
      y += int(l_canvas_height *
               (gsl_vector_get(Y, row) + gsl_vector_get(maxXTopHeight, row) -
                gsl_vector_get(xTopR, i)));
    else if (vert_align == Top)
      y += int(l_canvas_height * gsl_vector_get(Y, row));
    else if (vert_align == Bottom)
      y += int(l_canvas_height *
               (gsl_vector_get(Y, row) + gsl_vector_get(maxXTopHeight, row) -
                gsl_vector_get(xTopR, i) +
                +gsl_vector_get(maxXBottomHeight, row) -
                gsl_vector_get(xBottomR, i)));

    // resizes and moves layers
    Graph *gr = (Graph *)graphsList.at(i);
    bool autoscaleFonts = false;
    if (!userSize) {  // When the user specifies the layer canvas size, the
                      // window is resized
      // and the fonts must be scaled accordingly. If the size is calculated
      // automatically we don't rescale the fonts in order to prevent problems
      // with too small fonts when the user adds new layers or when removing
      // layers

      autoscaleFonts = gr->autoscaleFonts();  // save user settings
      gr->setAutoscaleFonts(false);
    }

    gr->setGeometry(QRect(x, y, w, h));
    gr->plotWidget()->resize(QSize(w, h));

    if (!userSize)
      gr->setAutoscaleFonts(autoscaleFonts);  // restore user settings
  }

  // free memory
  gsl_vector_free(maxXTopHeight);
  gsl_vector_free(maxXBottomHeight);
  gsl_vector_free(maxYLeftWidth);
  gsl_vector_free(maxYRightWidth);
  gsl_vector_free(xTopR);
  gsl_vector_free(xBottomR);
  gsl_vector_free(yLeftR);
  gsl_vector_free(yRightR);
  gsl_vector_free(X);
  gsl_vector_free(Y);
  return size;
}
Example #9
0
void PlotExporter::exportPlot(QwtPlot *plot, const QRectF &zoom)
{
  QSizeF guessedDimensions;
  ExportPlotToImageDialog::Parameters p = m_exportDlg->parameters();

  m_exportDlg->setAspectRatio(plot->size().width() / plot->size().height());

  while (m_exportDlg->exec() == QDialog::Accepted) {
    p = m_exportDlg->parameters();

    QString path;

    if (p.path.length() < 0) {
      QMessageBox::warning(nullptr, QObject::tr("Invalid input"), QObject::tr("Invalid path"));
      continue;
    }
    if (!m_supportedFormats.contains(p.format)) {
      QMessageBox::warning(nullptr, QObject::tr("Invalid input"), QObject::tr("Invalid output format"));
      continue;
    }

    if (p.path.endsWith("." + p.format))
      path = p.path;
    else
      path = p.path + "." + p.format;

    /* Create a temporary QwtPlot to use to write the chart to file */
    QwtPlot exPlot;
    QwtPlotZoomer exPlorZoomer(exPlot.canvas());
    exPlorZoomer.zoom(zoom);

    exPlot.setCanvasBackground(QBrush(Qt::white));
    exPlot.setTitle(p.title);
    exPlot.setAxisTitle(QwtPlot::xBottom, plot->axisTitle(QwtPlot::xBottom));
    exPlot.setAxisTitle(QwtPlot::xTop, plot->axisTitle(QwtPlot::xTop));
    exPlot.setAxisTitle(QwtPlot::yLeft, plot->axisTitle(QwtPlot::yLeft));
    exPlot.setAxisTitle(QwtPlot::yRight, plot->axisTitle(QwtPlot::yRight));
    QwtPlotItemList curves = plot->itemList();

    /* Attach all plots from the GUI plot to the temporary plot
     * Note that this will detach the plots from the GUI plot! */
    QList<qreal> curvePenWidths;
    for (QwtPlotItem *i : curves) {
      QwtPlotCurve *c = dynamic_cast<QwtPlotCurve *>(i);

      if (c != nullptr) {
        QPen p = c->pen();
        qreal w = p.widthF();
        qreal nw;

        curvePenWidths.push_back(w);

        nw = w - 1.0;
        if (nw < 0.0)
          nw = 0.0;

        p.setWidthF(nw);
        c->setPen(p);
      }

      i->attach(&exPlot);
    }

    /* Scale up from millimeters to centimeters*/
    QSizeF dimensionsMM(p.dimensions.width() * 10.0, p.dimensions.height() * 10.0);

    /* Store current properties of the plot as we need to change them for rendering */
    QFont xBottomFont = plot->axisWidget(QwtPlot::xBottom)->font();
    QFont xTopFont = plot->axisWidget(QwtPlot::xTop)->font();
    QFont yLeftFont = plot->axisWidget(QwtPlot::yLeft)->font();
    QFont yRightFont = plot->axisWidget(QwtPlot::yRight)->font();
    QFont xBottomTitleFont = plot->axisTitle(QwtPlot::xBottom).font();
    QFont xTopTitleFont = plot->axisTitle(QwtPlot::xTop).font();
    QFont yLeftTitleFont = plot->axisTitle(QwtPlot::yLeft).font();
    QFont yRightTitleFont = plot->axisTitle(QwtPlot::yRight).font();
    QFont titleFont = plot->title().font();
    const qreal xBottomPenWidth = plot->axisWidget(QwtPlot::xBottom)->scaleDraw()->penWidth() > 0 ? plot->axisWidget(QwtPlot::xBottom)->scaleDraw()->penWidth() : 1.0;
    const qreal xTopPenWidth = plot->axisWidget(QwtPlot::xTop)->scaleDraw()->penWidth() > 0 ? plot->axisWidget(QwtPlot::xTop)->scaleDraw()->penWidth() : 1.0;
    const qreal yLeftPenWidth = plot->axisWidget(QwtPlot::yLeft)->scaleDraw()->penWidth() > 0 ? plot->axisWidget(QwtPlot::yLeft)->scaleDraw()->penWidth() : 1.0;
    const qreal yRightPenWidth = plot->axisWidget(QwtPlot::yRight)->scaleDraw()->penWidth() > 0 ? plot->axisWidget(QwtPlot::yRight)->scaleDraw()->penWidth() : 1.0;

    /* Recalculate sizes by the DPI for every element that needs it */
    const qreal outputInPixels = (static_cast<qreal>(p.dimensions.width()) / 2.54) * p.dpi;
    const qreal scalingRatio = (static_cast<qreal>(qApp->desktop()->logicalDpiX()) / p.dpi) * (outputInPixels / plot->geometry().width());

    const qreal _xBottomPenWidth = floor((xBottomPenWidth * scalingRatio) + 0.45);
    const qreal _xTopPenWidth = floor((xTopPenWidth * scalingRatio) + 0.45);
    const qreal _yLeftPenWidth = floor((yLeftPenWidth * scalingRatio) + 0.45);
    const qreal _yRightPenWidth = floor((yRightPenWidth * scalingRatio) + 0.45);
    xBottomFont.setPointSizeF(p.axisNumbersFontSize * scalingRatio);
    xTopFont.setPointSizeF(p.axisNumbersFontSize * scalingRatio);
    yLeftFont.setPointSizeF(p.axisNumbersFontSize * scalingRatio);
    yRightFont.setPointSizeF(p.axisNumbersFontSize * scalingRatio);
    xBottomTitleFont.setPointSizeF(p.axisTitlesFontSize * scalingRatio);
    xTopTitleFont.setPointSizeF(p.axisTitlesFontSize * scalingRatio);
    yLeftTitleFont.setPointSizeF(p.axisTitlesFontSize * scalingRatio);
    yRightTitleFont.setPointSizeF(p.axisTitlesFontSize * scalingRatio);
    titleFont.setPointSizeF(p.chartTitleFontSize * scalingRatio);
    exPlot.axisWidget(QwtPlot::xBottom)->scaleDraw()->setPenWidth(_xBottomPenWidth);
    exPlot.axisWidget(QwtPlot::xTop)->scaleDraw()->setPenWidth(_xTopPenWidth);
    exPlot.axisWidget(QwtPlot::yLeft)->scaleDraw()->setPenWidth(_yLeftPenWidth);
    exPlot.axisWidget(QwtPlot::yRight)->scaleDraw()->setPenWidth(_yRightPenWidth);

    exPlot.setPalette(m_plotPalette);
    exPlot.axisWidget(QwtPlot::xBottom)->setPalette(m_plotPalette);
    exPlot.axisWidget(QwtPlot::xTop)->setPalette(m_plotPalette);
    exPlot.axisWidget(QwtPlot::yLeft)->setPalette(m_plotPalette);
    exPlot.axisWidget(QwtPlot::yRight)->setPalette(m_plotPalette);
    exPlot.axisWidget(QwtPlot::xBottom)->setFont(xBottomFont);
    exPlot.axisWidget(QwtPlot::xTop)->setFont(xTopFont);
    exPlot.axisWidget(QwtPlot::yLeft)->setFont(yLeftFont);
    exPlot.axisWidget(QwtPlot::yRight)->setFont(yRightFont);
    setAxisTitleFont(&exPlot, QwtPlot::xBottom, xBottomTitleFont);
    setAxisTitleFont(&exPlot, QwtPlot::xTop, xTopTitleFont);
    setAxisTitleFont(&exPlot, QwtPlot::yLeft, yLeftTitleFont);
    setAxisTitleFont(&exPlot, QwtPlot::yRight, yRightTitleFont);
    setTitleFont(&exPlot, titleFont);

    exPlot.replot();

    renderPlotToFile(&exPlot, path, p.format, dimensionsMM, p.dpi);

    /* Reattach the plots back to the GUI plot */
    for (QwtPlotItem *i : curves) {
      QwtPlotCurve *c = dynamic_cast<QwtPlotCurve *>(i);

      if (c != nullptr) {
        QPen p = c->pen();

        if (curvePenWidths.isEmpty())
          break;

        p.setWidthF(curvePenWidths.front());
        curvePenWidths.pop_front();

        c->setPen(p);
      }

      i->attach(plot);
    }

    break; /* Exit the while loop */
  }
}
Example #10
0
//--------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------
void MainWindow:: drawDistPlots(bool dummy)
{
    double *x, *prob;
    x = new double[nDistPts];
    prob = new double[nDistPts];
    QString median_qstr, shape_qstr;
    double median, shape;
    double expMean[3];
    double expTbase;
    bool use_lognormal = cbox_USE_LOGNORMAL_DIST->isChecked();

    groupBox_divisiondistributions->setEnabled(use_lognormal);
    for (int j=0; j<ndistplots; j++) {
        QwtPlot *qp = distplot_list[j];
        if (j == 0) {
            qp->setTitle("Type 1 division time (hrs)");
            if (use_lognormal) {
                median_qstr = line_DIVIDE_TIME_1_MEDIAN->text();
                shape_qstr = line_DIVIDE_TIME_1_SHAPE->text();
            } else {
                expTbase = line_T_G1_1->text().toDouble() + line_T_S_1->text().toDouble() + line_T_G2_1->text().toDouble();
                expMean[0] = line_G1_MEAN_DELAY_1->text().toDouble();
                expMean[1] = line_S_MEAN_DELAY_1->text().toDouble();
                expMean[2] = line_G2_MEAN_DELAY_1->text().toDouble();
            }
        } else if (j == 1) {
            qp->setTitle("Type 2 division time (hrs)");
            if (use_lognormal) {
                median_qstr = line_DIVIDE_TIME_2_MEDIAN->text();
                shape_qstr = line_DIVIDE_TIME_2_SHAPE->text();
            } else {
                expTbase = line_T_G1_2->text().toDouble() + line_T_S_2->text().toDouble() + line_T_G2_2->text().toDouble();
                expMean[0] = line_G1_MEAN_DELAY_2->text().toDouble();
                expMean[1] = line_S_MEAN_DELAY_2->text().toDouble();
                expMean[2] = line_G2_MEAN_DELAY_2->text().toDouble();
            }
        }
        if (use_lognormal) {
            median = median_qstr.toDouble();
            shape = shape_qstr.toDouble();
            create_lognorm_dist(median, shape, nDistPts, x, prob);
        } else {
            create_expon_dist(expTbase, expMean, nDistPts, x, prob);
        }

        int n = dist_limit(prob,nDistPts);
        double xmax = x[n];
        qp->setAxisScale(QwtPlot::xBottom, 0.0, xmax, 0.0);

        if (first_plot) {
            curve_list[j] = new QwtPlotCurve("title");
            curve_list[j]->setSamples(x, prob, n);
            curve_list[j]->attach(qp);
        } else {
            curve_list[j]->setSamples(x, prob, n);
        }
        qp->replot();
    }
    delete [] x;
    x = NULL;
    delete [] prob;
    prob = NULL;
    first_plot = false;
}
void PlotMagnifier::rescale( double factor, AxisMode axis )
{
    factor = qAbs( 1.0/factor );

    QwtPlot* plt = plot();
    if ( plt == nullptr || factor == 1.0 ){
        return;
    }

    bool doReplot = false;

    const bool autoReplot = plt->autoReplot();
    plt->setAutoReplot( false );

    const int axis_list[2] = {QwtPlot::xBottom, QwtPlot::yLeft};
    QRectF new_rect;

    for ( int i = 0; i <2; i++ )
    {
        double temp_factor = factor;
        if( i==1 && axis == X_AXIS)
        {
            temp_factor = 1.0;
        }
        if( i==0 && axis == Y_AXIS)
        {
            temp_factor = 1.0;
        }

        int axisId = axis_list[i];

        if ( isAxisEnabled( axisId ) )
        {
            const QwtScaleMap scaleMap = plt->canvasMap( axisId );

            double v1 = scaleMap.s1();
            double v2 = scaleMap.s2();
            double center = _mouse_position.x();

            if( axisId == QwtPlot::yLeft){
                center = _mouse_position.y();
            }

            if ( scaleMap.transformation() )
            {
                // the coordinate system of the paint device is always linear
                v1 = scaleMap.transform( v1 ); // scaleMap.p1()
                v2 = scaleMap.transform( v2 ); // scaleMap.p2()
            }

            const double width = ( v2 - v1 );
            const double ratio = (v2-center)/ (width);

            v1 = center - width*temp_factor*(1-ratio);
            v2 = center + width*temp_factor*(ratio);

            if( v1 > v2 ) std::swap( v1, v2 );

            if ( scaleMap.transformation() )
            {
                v1 = scaleMap.invTransform( v1 );
                v2 = scaleMap.invTransform( v2 );
            }

            if( v1 < _lower_bounds[axisId]) v1 = _lower_bounds[axisId];
            if( v2 > _upper_bounds[axisId]) v2 = _upper_bounds[axisId];

            plt->setAxisScale( axisId, v1, v2 );

            if( axisId == QwtPlot::xBottom)
            {
                new_rect.setLeft(  v1 );
                new_rect.setRight( v2 );
            }
            else{
                new_rect.setBottom( v1 );
                new_rect.setTop( v2 );
            }

            doReplot = true;
        }
    }

    plt->setAutoReplot( autoReplot );

    if ( doReplot ){
        emit rescaled( new_rect );
    }
}
Example #12
0
void PlotMatrix::alignScaleBorder( int rowOrColumn, int axis )
{
    int startDist = 0;
    int endDist = 0;

    if ( axis == QwtPlot::yLeft )
    {
        QwtPlot *p = plotAt( rowOrColumn, 0 );
        if ( p )
            p->axisWidget( axis )->getBorderDistHint( startDist, endDist );

        for ( int col = 1; col < numColumns(); col++ )
        {
            QwtPlot *p = plotAt( rowOrColumn, col );
            if ( p )
                p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
        }
    }
    else if ( axis == QwtPlot::yRight )
    {
        QwtPlot *p = plotAt( rowOrColumn, numColumns() - 1 );
        if ( p )
            p->axisWidget( axis )->getBorderDistHint( startDist, endDist );

        for ( int col = 0; col < numColumns() - 1; col++ )
        {
            QwtPlot *p = plotAt( rowOrColumn, col );
            if ( p )
                p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
        }       
    }
    if ( axis == QwtPlot::xTop )
    {
        QwtPlot *p = plotAt( rowOrColumn, 0 );
        if ( p )
            p->axisWidget( axis )->getBorderDistHint( startDist, endDist );
    
        for ( int row = 1; row < numRows(); row++ )
        {
            QwtPlot *p = plotAt( row, rowOrColumn );
            if ( p )
                p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
        }   
    }   
    else if ( axis == QwtPlot::xBottom )
    {       
        QwtPlot *p = plotAt( numRows() - 1, rowOrColumn );
        if ( p )
            p->axisWidget( axis )->getBorderDistHint( startDist, endDist );
    
        for ( int row = 0; row < numRows() - 1; row++ )
        {
            QwtPlot *p = plotAt( row, rowOrColumn );
            if ( p )
                p->axisWidget( axis )->setMinBorderDist( startDist, endDist );
        }
    }
}
Example #13
0
void PlotMatrix::alignAxes( int rowOrColumn, int axis )
{
    if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight )
    {
        double maxExtent = 0;

        for ( int row = 0; row < numRows(); row++ )
        {
            QwtPlot *p = plotAt( row, rowOrColumn );
            if ( p )
            {
                QwtScaleWidget *scaleWidget = p->axisWidget( axis );

                QwtScaleDraw *sd = scaleWidget->scaleDraw();
                sd->setMinimumExtent( 0.0 );

                const double extent = sd->extent( scaleWidget->font() );
                if ( extent > maxExtent )
                    maxExtent = extent;
            }
        }

        for ( int row = 0; row < numRows(); row++ )
        {
            QwtPlot *p = plotAt( row, rowOrColumn );
            if ( p )
            {
                QwtScaleWidget *scaleWidget = p->axisWidget( axis );
                scaleWidget->scaleDraw()->setMinimumExtent( maxExtent );
            }
        }
    }
    else
    {
        double maxExtent = 0;

        for ( int col = 0; col < numColumns(); col++ )
        {
            QwtPlot *p = plotAt( rowOrColumn, col );
            if ( p )
            {
                QwtScaleWidget *scaleWidget = p->axisWidget( axis );

                QwtScaleDraw *sd = scaleWidget->scaleDraw();
                sd->setMinimumExtent( 0.0 );

                const double extent = sd->extent( scaleWidget->font() );
                if ( extent > maxExtent )
                    maxExtent = extent;
            }
        }

        for ( int col = 0; col < numColumns(); col++ )
        {
            QwtPlot *p = plotAt( rowOrColumn, col );
            if ( p )
            {
                QwtScaleWidget *scaleWidget = p->axisWidget( axis );
                scaleWidget->scaleDraw()->setMinimumExtent( maxExtent );
            }
        }
    }
}
Example #14
0
int main(int argc, char *argv[])
{

    //  QGuiApplication a(argc, argv);
    QApplication a(argc, argv);
    QwtPlot *plot = new QwtPlot();
    QwtPlotCanvas *canvas = new QwtPlotCanvas();
    canvas->setBorderRadius(10);

    plot->setCanvas(canvas);
    plot->setCanvasBackground(QColor("LIGHTGRAY"));

    plot->enableAxis(QwtPlot::yRight);
    plot->enableAxis(QwtPlot::xTop);
    plot->setAxisTitle(QwtPlot::xBottom, "Xline");
    plot->setAxisTitle(QwtPlot::xTop, "Xline");
    plot->setAxisTitle(QwtPlot::yLeft, "Inline");
    plot->setAxisTitle(QwtPlot::yRight, "Inline");
    //    float minx = srv->getStations().first().x();
    //    float maxx = srv->getStations().last().x();
        plot->setAxisScale( QwtPlot::xBottom,3500,300);
    //    plot->setAxisScale( QwtPlot::xTop,minx,maxx );
    //    QwtScaleDraw *sd = axisScaleDraw( QwtPlot::yLeft );
    //    sd->setMinimumExtent( sd->extent( axisWidget( QwtPlot::yLeft )->font() ) );
    plot->plotLayout()->setAlignCanvasToScales( true );
    QFileDialog custDialog;
    QStringList names = custDialog.getOpenFileNames(NULL, ("Open Files..."),QString(), ("UKOOA Files (*.p190 *.p90);;All Files (*)"));

    // handle if the dialog was "Cancelled"
    if(names.isEmpty())
    {
        return 0;
    }
    qSort(names.begin(), names.end());
    QVector <QwtPlotCurve *> curves;
    foreach (QString name, names)
    {


        QwtPlotCurve *vCurve = new QwtPlotCurve;
       if(name.contains(QString( "NS1763")) || name.contains(QString("NS2029")))
        {
           QColor c = Qt::red;
            vCurve->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, Qt::red,c , QSize( 2, 2 ) ) );
        }
        else
        {
           QColor c = Qt::green;
            vCurve->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, Qt::green,c , QSize( 2, 2 ) ) );
        }
        vCurve->setStyle( QwtPlotCurve::NoCurve );
        vCurve->setPen( Qt::gray );

        cout << name.toStdString() << endl;
        QVector<QPointF> curveData;

        //  m_nameLineLable->setText(m_names.at(0));
        QFile *ukFile = new QFile(QString(name));

        bool rt = ukFile->open(QIODevice::ReadOnly);

        cout << "return " << rt << endl;

        qint64 icount = 0;

        qint64 fileSize = ukFile->size();
        char *data = new char[fileSize];
        ukFile->read(data,fileSize);
        QString sData = data;
        QString shot = "SNS";
        while (true)
        {
            ukFile->seek(icount);
            ukFile->read(data,fileSize);
            sData = data;;
            if(icount>=fileSize)
            {
                break;
            }
            auto sPos = sData.indexOf(shot,0,Qt::CaseInsensitive);
            QString cr = sData.mid(sPos,19);
            if(cr.contains("\n"))
            {
                sPos +=2;
            }
            // auto shotNo  = sData.mid(sPos+20,sPos+5);
            QString shotNo = sData.mid(sPos+19,6);
            int shotNos;

            if(shotNo.contains("\n") || shotNo.contains("\r"))
            {
                shotNo = sData.mid(sPos+19,8);
                int shift1 = shotNo.indexOf("\r");
                int shift = shotNo.indexOf("\n");
                //    cout << shift1 << " " << shift << endl;
                QString tmp = shotNo.mid(0,shift1);
                tmp.append(shotNo.mid(shift+1,3));
                shotNos = tmp.toInt();
            }
            else
            {
                shotNos = sData.mid(sPos+19,6).toInt();
            }

            float shotYs;
            sPos = sData.indexOf(shot,0,Qt::CaseInsensitive);
            cr = sData.mid(sPos,55);
            if(cr.contains("\n"))
            {
                //       cout << " cr " << sPos << endl;
                sPos +=2;
            }

            QString shotY = sData.mid(sPos+55,10);
            //   cout << "shotx " << shotX.toStdString() << endl;
            if(shotY.contains("\n") || shotY.contains("\r"))
            {
                shotY = sData.mid(sPos+55,12);
                int shift1 = shotY.indexOf("\r");
                int shift = shotY.indexOf("\n");
                //           cout << shift1 << " " << shift << endl;
                QString tmp = shotY.mid(0,shift1);
                tmp.append(shotY.mid(shift+1,12));
                shotYs = tmp.toFloat();
            }
            else
            {
                shotYs = shotY.toFloat();
            }

            float shotXs;
            sPos = sData.indexOf(shot,0,Qt::CaseInsensitive);
            cr = sData.mid(sPos,46);
            if(cr.contains("\n"))
            {
                //       cout << " cr " << sPos << endl;
                sPos +=2;
            }

            QString shotX = sData.mid(sPos+46,10);
            //   cout << "shotx " << shotX.toStdString() << endl;
            if(shotX.contains("\n") || shotX.contains("\r"))
            {
                shotX = sData.mid(sPos+46,12);
                int shift1 = shotX.indexOf("\r");
                int shift = shotX.indexOf("\n");
                //           cout << shift1 << " " << shift << endl;
                QString tmp = shotX.mid(0,shift1);
                tmp.append(shotX.mid(shift+1,12));
                shotXs = tmp.toFloat();
            }
            else
            {
                shotXs = shotX.toFloat();
            }
            icount +=sPos+1;
            //     cout << shotNos << endl;
            float shotXt = shotXs - 757551.46;


            float shotYt = shotYs - 978769.0;
            float shotYr = shotYt * cosf(13.661f * M_PI/180.0f) + shotXt * sinf(13.661f * M_PI/180.0f);
            int shotYy = 981 + shotYr/25.0;
            float shotXr = shotXt * cosf(13.661f * M_PI/180.0f) - shotYt * sinf(13.661f * M_PI/180.0f);
            int shotXx = 2570 - shotXr/25.0;
//            if(shotXx>0 && shotYy>0)
//            {
                QPointF shotPoint(shotXx,shotYy);
                curveData.append(shotPoint);
            //    cout << " shot " << shotNos << " " << shotXs  << " " << shotYs << " "  << shotXx << " " << shotYy << endl;
 //           }



        }
        vCurve->setSamples(curveData);
        curves.append(vCurve);
        ukFile->close();
    }
/*!
   Update the axes scales

   \param intervals Scale intervals
*/
void QwtPlotRescaler::updateScales(
    QwtInterval intervals[QwtPlot::axisCnt] ) const
{
    if ( d_data->inReplot >= 5 )
    {
        return;
    }

    QwtPlot *plt = const_cast<QwtPlot *>( plot() );

    const bool doReplot = plt->autoReplot();
    plt->setAutoReplot( false );

    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        if ( axis == referenceAxis() || aspectRatio( axis ) > 0.0 )
        {
            double v1 = intervals[axis].minValue();
            double v2 = intervals[axis].maxValue();

            if ( plt->axisScaleDiv( axis )->lowerBound() >
                plt->axisScaleDiv( axis )->upperBound() )
            {
                qSwap( v1, v2 );
            }

            if ( d_data->inReplot >= 1 )
            {
                d_data->axisData[axis].scaleDiv = *plt->axisScaleDiv( axis );
            }

            if ( d_data->inReplot >= 2 )
            {
                QList<double> ticks[QwtScaleDiv::NTickTypes];
                for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ )
                    ticks[i] = d_data->axisData[axis].scaleDiv.ticks( i );

                plt->setAxisScaleDiv( axis, QwtScaleDiv( v1, v2, ticks ) );
            }
            else
            {
                plt->setAxisScale( axis, v1, v2 );
            }
        }
    }

    const bool immediatePaint = 
        plt->canvas()->testPaintAttribute( QwtPlotCanvas::ImmediatePaint );
    plt->canvas()->setPaintAttribute( QwtPlotCanvas::ImmediatePaint, false );

    plt->setAutoReplot( doReplot );

    d_data->inReplot++;
    plt->replot();
    d_data->inReplot--;

    plt->canvas()->setPaintAttribute( 
        QwtPlotCanvas::ImmediatePaint, immediatePaint );
}
void QwtPlotZoomer::rescale()
{
    QwtPlot *plt = plot();
    if ( !plt )
        return;

    const QwtDoubleRect &rect = d_data->zoomStack[d_data->zoomRectIndex];
    if ( rect != scaleRect() )
    {
        const bool doReplot = plt->autoReplot();
        plt->setAutoReplot(false);

        double x1 = rect.left();
        double x2 = rect.right();
        if ( plt->axisScaleDiv(xAxis())->lowerBound() > 
            plt->axisScaleDiv(xAxis())->upperBound() )
        {
            qSwap(x1, x2);
        }

        plt->setAxisScale(xAxis(), x1, x2);

        double y1 = rect.top();
        double y2 = rect.bottom();
        if ( plt->axisScaleDiv(yAxis())->lowerBound() > 
            plt->axisScaleDiv(yAxis())->upperBound() )
        {
            qSwap(y1, y2);
        }
        plt->setAxisScale(yAxis(), y1, y2);

        plt->setAutoReplot(doReplot);

        plt->replot();
    }
}
Example #17
0
void PlotMatrix::scaleDivChanged()
{
    if ( d_data->inScaleSync )
        return;

    d_data->inScaleSync = true;

    QwtPlot *plt = NULL;
    int axisId = -1;
    int rowOrColumn = -1;

    // find the changed axis
    for ( int row = 0; row < numRows(); row++ )
    {
        for ( int col = 0; col < numColumns(); col++ )
        {
            QwtPlot *p = plot( row, col );
            if ( p )
            {
                for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
                {
                    if ( p->axisWidget( axis ) == sender() )
                    {
                        plt = p;
                        axisId = axis;
                        if ( axisId == QwtPlot::xBottom || axisId == QwtPlot::xTop )
                            rowOrColumn = col;
                        else
                            rowOrColumn = row;

                    }
                }
            }
        }
    }

    if ( plt )
    {
#if (QWT_VERSION < 0x060100)
      // nix in 6.02
#else
      const QwtScaleDiv scaleDiv = plt->axisScaleDiv( axisId );
#endif

        // synchronize the axes
        if ( axisId == QwtPlot::xBottom || axisId == QwtPlot::xTop )
        {
            for ( int row = 0; row < numRows(); row++ )
            {
                QwtPlot *p = plot( row, rowOrColumn );
                if ( p != plt )
#if (QWT_VERSION < 0x060100)
		  p->setAxisScaleDiv( axisId, *plt->axisScaleDiv( axisId ) );
#else
		  p->setAxisScaleDiv( axisId, scaleDiv );
#endif
            }
        }
        else
        {
            for ( int col = 0; col < numColumns(); col++ )
            {
                QwtPlot *p = plot( rowOrColumn, col );
                if ( p != plt )
#if (QWT_VERSION < 0x060100)
                    p->setAxisScaleDiv( axisId, *plt->axisScaleDiv( axisId ) );
#else
		    p->setAxisScaleDiv( axisId, scaleDiv );
#endif
            }
        }

        updateLayout();
    }

    d_data->inScaleSync = false;
}
void DataWidget::setValue(double value)
{
    switch (_dataDescription->widget)
    {
    case DATA_WIDGET_PLOT:
	{
            QwtPlot *widget = qobject_cast<QwtPlot*> (_internalWidget);
            if (widget != 0)
            {
                _curveData->xData->append(_mainWindow->effectiveRunningTime());
                _curveData->yData->append(value);
#if QWT_VERSION >= 0x060000
                _curve->setRawSamples(_curveData->xData->data(),
                                      _curveData->yData->data(), _curveData->xData->size());
#else
#  warning Old version of qwt being used, data aggregator will not work.
#endif
                widget->replot();
            }
            else
            {
                qDebug() << "Bad data widget cast (DataWidget::setValue()) !";
            }
            break;
	}

    case DATA_WIDGET_LCD:
	{
            QLCDNumber *widget = qobject_cast<QLCDNumber*> (_internalWidget);
            if (widget != 0)
            {
                widget->display(value);
            }
            else
            {
                qDebug() << "Bad data widget cast (DataWidget::setValue()) !";
            }
            break;
	}

    case DATA_WIDGET_LEVEL:
	{
            QwtThermo *widget = qobject_cast<QwtThermo*> (_internalWidget);
            if (widget != 0)
            {
                widget->setValue(value);
            }
            else
            {
                qDebug() << "Bad data widget cast (DataWidget::setValue()) !";
            }
            break;
	}

    case DATA_WIDGET_DIAL:
	{
            QwtDial *widget = qobject_cast<QwtDial*> (_internalWidget);
            if (widget != 0)
            {
                widget->setValue(value);
            }
            else
            {
                qDebug() << "Bad data widget cast (DataWidget::setValue()) !";
            }
            break;
	}

    default:
        ;
    }

    emit valueChanged(value, _dataDescription->id);
}