示例#1
3
void WindPlot::updatePlot()
{
    clearPlottables();
    clearItems();

    // Return now if plot empty
    if (mMainWindow->dataSize() == 0) return;

    double lower = mMainWindow->rangeLower();
    double upper = mMainWindow->rangeUpper();

    QVector< double > t, x, y;

    double xMin, xMax;
    double yMin, yMax;

    int start = mMainWindow->findIndexBelowT(lower) + 1;
    int end   = mMainWindow->findIndexAboveT(upper);

    bool first = true;
    for (int i = start; i < end; ++i)
    {
        const DataPoint &dp = mMainWindow->dataPoint(i);

        t.append(dp.t);

        if (mMainWindow->units() == PlotValue::Metric)
        {
            x.append(dp.velE * MPS_TO_KMH);
            y.append(dp.velN * MPS_TO_KMH);
        }
        else
        {
            x.append(dp.velE * MPS_TO_MPH);
            y.append(dp.velN * MPS_TO_MPH);
        }

        if (first)
        {
            xMin = xMax = x.back();
            yMin = yMax = y.back();

            first = false;
        }
        else
        {
            if (x.back() < xMin) xMin = x.back();
            if (x.back() > xMax) xMax = x.back();

            if (y.back() < yMin) yMin = y.back();
            if (y.back() > yMax) yMax = y.back();
        }
    }

    QCPCurve *curve = new QCPCurve(xAxis, yAxis);
    curve->setData(t, x, y);
    curve->setPen(QPen(Qt::lightGray, mMainWindow->lineThickness()));

    setViewRange(xMin, xMax, yMin, yMax);

    if (mMainWindow->markActive())
    {
        const DataPoint &dpEnd = mMainWindow->interpolateDataT(mMainWindow->markEnd());

        t.clear();
        x.clear();
        y.clear();

        QVector< double > xMark, yMark;

        if (mMainWindow->units() == PlotValue::Metric)
        {
            xMark.append(dpEnd.velE * MPS_TO_KMH);
            yMark.append(dpEnd.velN * MPS_TO_KMH);
        }
        else
        {
            xMark.append(dpEnd.velE * MPS_TO_MPH);
            yMark.append(dpEnd.velN * MPS_TO_MPH);
        }

        QCPGraph *graph = addGraph();
        graph->setData(xMark, yMark);
        graph->setPen(QPen(Qt::black, mMainWindow->lineThickness()));
        graph->setLineStyle(QCPGraph::lsNone);
        graph->setScatterStyle(QCPScatterStyle::ssDisc);
    }

    updateWind(start, end);

    QVector< double > xMark, yMark;

    if (mMainWindow->units() == PlotValue::Metric)
    {
        xMark.append(mWindE * MPS_TO_KMH);
        yMark.append(mWindN * MPS_TO_KMH);
    }
    else
    {
        xMark.append(mWindE * MPS_TO_MPH);
        yMark.append(mWindN * MPS_TO_MPH);
    }

    QCPGraph *graph = addGraph();
    graph->setData(xMark, yMark);
    graph->setPen(QPen(Qt::red, mMainWindow->lineThickness()));
    graph->setLineStyle(QCPGraph::lsNone);
    graph->setScatterStyle(QCPScatterStyle::ssDisc);

    const double x0 = mWindE;
    const double y0 = mWindN;
    const double r = mVelAircraft;

    QVector< double > tCircle, xCircle, yCircle;

    for (int i = 0; i <= 100; ++i)
    {
        tCircle.append(i);

        const double x = x0 + r * cos((double) i / 100 * 2 * M_PI);
        const double y = y0 + r * sin((double) i / 100 * 2 * M_PI);

        if (mMainWindow->units() == PlotValue::Metric)
        {
            xCircle.append(x * MPS_TO_KMH);
            yCircle.append(y * MPS_TO_KMH);
        }
        else
        {
            xCircle.append(x * MPS_TO_MPH);
            yCircle.append(y * MPS_TO_MPH);
        }
    }

    curve = new QCPCurve(xAxis, yAxis);
    curve->setData(tCircle, xCircle, yCircle);
    curve->setPen(QPen(Qt::red, mMainWindow->lineThickness()));

    // Add label to show best fit
    QCPItemText *textLabel = new QCPItemText(this);

    const double factor = (mMainWindow->units() == PlotValue::Metric) ? MPS_TO_KMH : MPS_TO_MPH;
    const QString units = (mMainWindow->units() == PlotValue::Metric) ? "km/h" : "mph";

    double direction = atan2(-mWindE, -mWindN) / M_PI * 180.0;
    if (direction < 0) direction += 360.0;

    QPainter painter(this);
    double mmPerPix = (double) painter.device()->widthMM() / painter.device()->width();

    double xRatioPerPix = 1.0 / axisRect()->width();
    double xRatioPerMM = xRatioPerPix / mmPerPix;

    double yRatioPerPix = 1.0 / axisRect()->height();
    double yRatioPerMM = yRatioPerPix / mmPerPix;

    textLabel->setPositionAlignment(Qt::AlignBottom|Qt::AlignRight);
    textLabel->setTextAlignment(Qt::AlignRight);
    textLabel->position->setType(QCPItemPosition::ptAxisRectRatio);
    textLabel->position->setCoords(1 - 5 * xRatioPerMM,
                                   1 - 5 * yRatioPerMM);
    textLabel->setText(
                QString("Wind speed = %1 %2\nWind direction = %3 deg\nAircraft speed = %4 %5")
                    .arg(sqrt(mWindE * mWindE + mWindN * mWindN) * factor)
                    .arg(units)
                    .arg(direction)
                    .arg(mVelAircraft * factor)
                    .arg(units));

    replot();
}
示例#2
0
void MainWindow::genLineEnding()
{
  resetPlot();
  QMetaEnum endingStyleEnum = QCPLineEnding::staticMetaObject.enumerator(QCPLineEnding::staticMetaObject.indexOfEnumerator("EndingStyle"));
  double offset = -0.2;
  double step = 1.4/((double)endingStyleEnum.keyCount()-1);
  for (int i=0; i<endingStyleEnum.keyCount(); ++i)
  {
    QCPLineEnding ending(static_cast<QCPLineEnding::EndingStyle>(endingStyleEnum.value(i)));
    QString endingName(endingStyleEnum.key(i));
    
    if (ending.style() == QCPLineEnding::esSkewedBar)
      ending.setInverted(true);
    
    QCPItemLine *line = new QCPItemLine(customPlot);
    line->setPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::FlatCap));
    customPlot->addItem(line);
    line->start->setCoords(offset+i*step-0.1, -0.2);
    line->end->setCoords(offset+i*step, 0.5);
    line->setHead(ending);
    QCPItemText *text = new QCPItemText(customPlot);
    customPlot->addItem(text);
    text->position->setParentAnchor(line->end);
    text->position->setCoords(8, -15-(i%2)*15);
    text->setFont(QFont(font().family(), 8));
    text->setText(endingName);
  }

  customPlot->savePng(dir.filePath("QCPLineEnding.png"), 500, 100);
}
示例#3
0
void ScatterWidget::addText(const string &text, const PointD &origin, int q_color)
{
    QCPItemText *textElem = new QCPItemText(ui->scatter);
    textElem->setText(QString::fromStdString(text));
    textElem->position->setCoords(origin.x, origin.y);
    textElem->setColor(QColor((Qt::GlobalColor)q_color));
}
示例#4
0
void MainWindow::genMarginGroup()
{
  resetPlot();
  
  customPlot->plotLayout()->clear();
  customPlot->plotLayout()->addElement(0, 0, new QCPAxisRect(customPlot));
  customPlot->plotLayout()->addElement(0, 1, new QCPAxisRect(customPlot));
  customPlot->plotLayout()->addElement(1, 0, new QCPAxisRect(customPlot));
  customPlot->plotLayout()->addElement(1, 1, new QCPAxisRect(customPlot));
  
  foreach (QCPAxisRect *r, customPlot->axisRects())
    r->axis(QCPAxis::atBottom)->setTickLabels(false);
  
  QCPMarginGroup *marginGroup = new QCPMarginGroup(customPlot);
  customPlot->axisRect(0)->setMarginGroup(QCP::msLeft, marginGroup);
  customPlot->axisRect(2)->setMarginGroup(QCP::msLeft, marginGroup);
  
  customPlot->axisRect(0)->axis(QCPAxis::atLeft)->setRange(0, 1300);
  customPlot->axisRect(1)->axis(QCPAxis::atLeft)->setRange(0, 1300);
  customPlot->axisRect(0)->axis(QCPAxis::atLeft)->setLabel("y");
  customPlot->axisRect(1)->axis(QCPAxis::atLeft)->setLabel("y");
  
  customPlot->plotLayout()->setAutoMargins(QCP::msLeft|QCP::msRight|QCP::msBottom);
  customPlot->plotLayout()->setMargins(QMargins(0, 25, 0, 0));
  
  QFont textFont;
  textFont.setBold(true);
  QCPItemText *leftCaption = new QCPItemText(customPlot);
  customPlot->addItem(leftCaption);
  leftCaption->position->setType(QCPItemPosition::ptViewportRatio);
  leftCaption->setClipToAxisRect(false);
  leftCaption->position->setCoords(0.25, 0);
  leftCaption->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter);
  leftCaption->setText("left sides in margin group");
  leftCaption->setFont(textFont);
  QCPItemText *rightCaption = new QCPItemText(customPlot);
  customPlot->addItem(rightCaption);
  rightCaption->position->setType(QCPItemPosition::ptViewportRatio);
  rightCaption->position->setCoords(0.75, 0);
  rightCaption->setClipToAxisRect(false);
  rightCaption->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter);
  rightCaption->setText("no margin group");
  rightCaption->setFont(textFont);
  
  QCPItemLine *splitter = new QCPItemLine(customPlot);
  splitter->start->setType(QCPItemPosition::ptViewportRatio);
  splitter->start->setCoords(0.5, 0);
  splitter->end->setType(QCPItemPosition::ptViewportRatio);
  splitter->end->setCoords(0.5, 1);
  splitter->setClipToAxisRect(false);
  splitter->setPen(QPen(Qt::gray, 0, Qt::DashLine));
  
  customPlot->savePng(dir.filePath("QCPMarginGroup.png"), 400, 400);
}
示例#5
0
void MainWindow::genItemText()
{
  resetPlot();
  QCPItemText *text = new QCPItemText(customPlot);
  customPlot->addItem(text);
  text->position->setCoords(0.5, 0.5);
  text->setText("QCustomPlot\nWidget");
  text->setFont(QFont(font().family(), 24));
  text->setRotation(12);
  text->setBrush(defaultBrush);
  labelItemAnchors(text);
  customPlot->savePng(dir.filePath("QCPItemText.png"), 300, 170);
}
void MainWindow::labelItemAnchors(QCPAbstractItem *item, double fontSize, bool circle, bool labelBelow)
{
	QList<QCPItemAnchor*> anchors = item->anchors();
	for (int i=0; i<anchors.size(); ++i)
	{
		if (circle)
		{
			QCPItemEllipse *circ = new QCPItemEllipse(item->parentPlot());
			item->parentPlot()->addItem(circ);
			circ->topLeft->setParentAnchor(anchors.at(i));
			circ->bottomRight->setParentAnchor(anchors.at(i));
			circ->topLeft->setCoords(-4, -4);
			circ->bottomRight->setCoords(4, 4);
			QPen p(Qt::blue, 0, Qt::CustomDashLine);
#if (QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)) // Qt 4.8 changed the meaning of this completely...
			p.setDashPattern(QVector<qreal>()<<2<<1);
#else
			p.setDashPattern(QVector<qreal>()<<1<<3);
#endif
			circ->setPen(p);
			if (dynamic_cast<QCPItemPosition*>(anchors.at(i)))
			{
				QCPItemEllipse *circ2 = new QCPItemEllipse(item->parentPlot());
				item->parentPlot()->addItem(circ2);
				circ2->topLeft->setParentAnchor(anchors.at(i));
				circ2->bottomRight->setParentAnchor(anchors.at(i));
				circ2->topLeft->setCoords(-2.5, -2.5);
				circ2->bottomRight->setCoords(2.5, 2.5);
				circ2->setPen(Qt::NoPen);
				circ2->setBrush(Qt::blue);
			}
		}
		if (fontSize > 0)
		{
			QCPItemText *label = new QCPItemText(item->parentPlot());
			item->parentPlot()->addItem(label);
			label->setFont(QFont(font().family(), fontSize));
			label->setColor(Qt::blue);
			label->setText(QString("%2 (%1)").arg(i).arg(anchors.at(i)->name()));
			label->position->setParentAnchor(anchors.at(i));
			if (circle)
				label->position->setCoords(0, fontSize*2*(labelBelow?1:-1));
			else
				label->position->setCoords(0, 0);
			label->setTextAlignment(Qt::AlignCenter);
		}
	}
}
示例#7
0
void MainWindow::genAxisRectSpacingOverview()
{
  resetPlot();
 
  customPlot->xAxis->setRange(-0.4, 1.4);
  customPlot->yAxis->setRange(100, 900);
  customPlot->xAxis->setVisible(true);
  customPlot->yAxis->setVisible(true);
  customPlot->axisRect()->setupFullAxesBox();
  customPlot->xAxis->setTickLabels(false);
  customPlot->axisRect()->setAutoMargins(QCP::msNone);
  customPlot->axisRect()->setMargins(QMargins(200, 50, 20, 165));
  customPlot->axisRect()->setBackground(QColor(245, 245, 245));
  
  customPlot->yAxis->setLabel("Axis Label");
  customPlot->yAxis->setOffset(30);
  customPlot->yAxis->setTickLabelPadding(30);
  customPlot->yAxis->setLabelPadding(30);
  customPlot->yAxis->setTickLengthOut(5);
  customPlot->yAxis->setSubTickLengthOut(2);
  
  addBracket(QPointF(200-95-27-17, 30), QPointF(1, 30), "Padding (if auto margins enabled)", QPointF(-25, -5), false, Qt::AlignLeft|Qt::AlignBottom);
  addBracket(QPointF(1, 370), QPointF(200, 370), "Margin", QPointF(0, 5), false, Qt::AlignHCenter|Qt::AlignTop);
  addBracket(QPointF(200-30, 240), QPointF(200, 240), "Axis offset", QPointF(-1, 5), true, Qt::AlignRight|Qt::AlignVCenter);
  addBracket(QPointF(200-35, 250), QPointF(200-30, 250), "Tick length out", QPointF(-1, 5), true, Qt::AlignRight|Qt::AlignVCenter);
  addBracket(QPointF(200-65, 240), QPointF(200-35, 240), "Tick label padding", QPointF(-1, 5), true, Qt::AlignRight|Qt::AlignVCenter);
  addBracket(QPointF(200-95-25, 240), QPointF(200-65-25, 240), "Label padding", QPointF(-1, 5), true, Qt::AlignRight|Qt::AlignVCenter);
  
  QCPItemLine *leftBorder = new QCPItemLine(customPlot);
  customPlot->addItem(leftBorder);
  leftBorder->setClipToAxisRect(false);
  leftBorder->start->setType(QCPItemPosition::ptViewportRatio);
  leftBorder->end->setType(QCPItemPosition::ptViewportRatio);
  leftBorder->start->setCoords(0, 0);
  leftBorder->end->setCoords(0, 1);
  leftBorder->setPen(QPen(Qt::gray, 0, Qt::DashLine));
  
  QCPItemText *axisRectLabel = new QCPItemText(customPlot);
  customPlot->addItem(axisRectLabel);
  axisRectLabel->position->setType(QCPItemPosition::ptAxisRectRatio);
  axisRectLabel->position->setCoords(0.5, 0.5);
  axisRectLabel->setFont(QFont(QFont().family(), 16));
  axisRectLabel->setText("QCPAxisRect");
  axisRectLabel->setColor(QColor(0, 0, 0, 60));
  
  customPlot->savePng(dir.filePath("AxisRectSpacingOverview.png"), 400, 400);
}
示例#8
0
/*! \brief Constructor of the class.
 *
 *  \param title the title of the plotter
 *  \param gridx the x pos in the grid
 *  \param gridy the y pos in the grid
 *  \param hspan the horizonatl span
 *  \param vspan the vertical span
 *  \param minval the minimum scale value
 *  \param maxval the maximium scale value
 *  \param size number of sample of datas in plotter
 *  \param bgcolor the background color of the plotter
 *  \param autorescale not used
 */
Plotter::Plotter(const QString &title, int gridx, int gridy, int hspan, int vspan, float minval, float maxval, int size, const QString &bgcolor, bool autorescale,  QObject *parent) :
    QObject(parent)
{
    Q_UNUSED(autorescale);
    this->title = title;
    this->gridx = gridx;
    this->gridy = gridy;
    this->hspan = hspan;
    this->vspan = vspan;
    this->minval = minval;
    this->maxval = maxval;
    this->size = size;
    initialSize = size;
    start = 0;
    this->bgcolor = bgcolor;
    interact = false;

    connect(customPlot.axisRect(),SIGNAL(zoomRequest()),this,SLOT(onInteract()));
    connect(customPlot.axisRect(),SIGNAL(dragStarted()),this,SLOT(onInteract()));

    customPlot.axisRect()->setBackground(QBrush(QColor(bgcolor)));
    customPlot.axisRect()->setupFullAxesBox(true);
    customPlot.axisRect()->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltNumber);
    customPlot.axisRect()->axis(QCPAxis::atBottom)->setAutoTickStep(false);
    customPlot.axisRect()->axis(QCPAxis::atBottom)->setTickStep(25);
    customPlot.axisRect()->axis(QCPAxis::atBottom)->setRange(0,size);
    customPlot.axisRect()->axis(QCPAxis::atLeft)->setRange(minval, maxval);
    customPlot.setInteractions( QCP::iRangeDrag | QCP::iRangeZoom  );
    QCPItemText *textLabel = new QCPItemText(&customPlot);
    customPlot.addItem(textLabel);
    textLabel->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter);
    textLabel->position->setType(QCPItemPosition::ptAxisRectRatio);
    textLabel->position->setCoords(0.5, 0); // place position at center/top of axis rect
    textLabel->setText(title);

    connect(customPlot.xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot.xAxis2, SLOT(setRange(QCPRange)));
    connect(customPlot.yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot.yAxis2, SLOT(setRange(QCPRange)));

}
示例#9
0
void MainWindow::genItemBracket()
{
  resetPlot();
  QCPItemBracket *bracket = new QCPItemBracket(customPlot);
  customPlot->addItem(bracket);
  bracket->left->setCoords(-0.2, 0.35);
  bracket->right->setCoords(1.2, 0.65);
  bracket->setLength(12);
  labelItemAnchors(bracket, 8, true, false);
  customPlot->savePng(dir.filePath("QCPItemBracket.png"), 230, 160);
  customPlot->clearItems();
  
  // generate image of multiple bracket lengths/styles:
  for (int i=0; i<4; ++i)
  {
    QCPItemBracket *bracket = new QCPItemBracket(customPlot);
    customPlot->addItem(bracket);
    bracket->setStyle(QCPItemBracket::bsCalligraphic);
    bracket->left->setCoords(-0.35+i*0.18, 0.95);
    bracket->right->setCoords(-0.15+i*0.18, 0.05);
    bracket->setLength(10+i*5);
    labelItemAnchors(bracket, 0, true, false);
    QCPItemText *label = new QCPItemText(customPlot);
    customPlot->addItem(label);
    label->setText(QString::number(bracket->length()));
    label->position->setParentAnchor(bracket->right);
    label->position->setCoords(-5, 20);
    label->setFont(QFont(font().family(), 9));
  }
  for (int i=0; i<4; ++i)
  {
    QCPItemBracket *bracket = new QCPItemBracket(customPlot);
    customPlot->addItem(bracket);
    bracket->setStyle(QCPItemBracket::bsSquare);
    bracket->left->setCoords(0.55+i*0.18, 0.95);
    bracket->right->setCoords(0.75+i*0.18, 0.05);
    bracket->setLength(10+i*5);
    labelItemAnchors(bracket, 0, true, false);
    QCPItemText *label = new QCPItemText(customPlot);
    customPlot->addItem(label);
    label->setText(QString::number(bracket->length()));
    label->position->setParentAnchor(bracket->right);
    label->position->setCoords(-5, 20);
    label->setFont(QFont(font().family(), 9));
  }
  QCPItemText *topLabel1 = new QCPItemText(customPlot);
  customPlot->addItem(topLabel1);
  topLabel1->setText("bsCalligraphic");
  topLabel1->position->setCoords(-0.05, 1.1);
  topLabel1->setFont(QFont(font().family(), 10));
  QCPItemText *topLabel2 = new QCPItemText(customPlot);
  customPlot->addItem(topLabel2);
  topLabel2->setText("bsSquare");
  topLabel2->position->setCoords(0.85, 1.1);
  topLabel2->setFont(QFont(font().family(), 10));
  customPlot->savePng(dir.filePath("QCPItemBracket-length.png"), 450, 200);
}
示例#10
0
void MainWindow::setupItemTracerTest(QCustomPlot *customPlot)
{
	QCPItemTracer *tracer1 = new QCPItemTracer(customPlot);
	customPlot->addItem(tracer1);
	tracer1->position->setCoords(1, 3);
	tracer1->setStyle(QCPItemTracer::tsCircle);
	tracer1->setSize(20);

	QCPItemTracer *tracer2 = new QCPItemTracer(customPlot);
	customPlot->addItem(tracer2);
	tracer2->position->setCoords(2, 2.5);
	tracer2->setStyle(QCPItemTracer::tsCrosshair);

	QCPItemTracer *tracer3 = new QCPItemTracer(customPlot);
	customPlot->addItem(tracer3);
	tracer3->position->setCoords(3, 2);
	tracer3->setStyle(QCPItemTracer::tsPlus);
	tracer3->setSize(20);

	QCPItemTracer *tracer4 = new QCPItemTracer(customPlot);
	customPlot->addItem(tracer4);
	tracer4->position->setCoords(4, 1.5);
	tracer4->setStyle(QCPItemTracer::tsSquare);
	tracer4->setSize(20);

	QCPGraph *graph = customPlot->addGraph();
	int n = 20;
	QVector<double> x(n), y(n);
	for (int i=0; i<n; ++i)
	{
		x[i] = 0.5+i/(double)n*4;
		y[i] = qSin(x[i])+1.5;
	}
	graph->setData(x, y);

	QCPItemTracer *graphTracer = new QCPItemTracer(customPlot);
	customPlot->addItem(graphTracer);
	graphTracer->setGraph(graph);
	graphTracer->setGraphKey(2.3);
	graphTracer->setStyle(QCPItemTracer::tsNone);
	graphTracer->setInterpolating(true);
	tracerTestTracer = graphTracer;
	connect(customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(tracerTestMouseMove(QMouseEvent*)));
	graphTracer->setStyle(QCPItemTracer::tsSquare);

	QCPItemText *text = new QCPItemText(customPlot);
	customPlot->addItem(text);
	text->setText("Tracer");
	text->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter);
	text->position->setType(QCPItemPosition::ptAxisRectRatio);
	text->position->setCoords(0.5, 0.05);
	text->setPen(QPen());

	QCPItemCurve *curve = new QCPItemCurve(customPlot);
	customPlot->addItem(curve);
	curve->start->setParentAnchor(text->bottom);
	curve->startDir->setParentAnchor(curve->start);
	curve->startDir->setCoords(0, 100);
	curve->end->setParentAnchor(tracerTestTracer->position);
	curve->end->setCoords(0, -5);
	curve->endDir->setParentAnchor(curve->end);
	curve->endDir->setCoords(0, -100);
	curve->setHead(QCPLineEnding::esSpikeArrow);
}
示例#11
0
void MainWindow::fillMyocardialPlot(int** ANN, QCustomPlot *plot, EcgAnnotation& ann, QVector<double> &x, QVector<double> &y, double sr)
{
    QPen pen;
    pen.setColor(QColor(255,0,0));
    float lastTTime = -1;

    static std::vector<QCPAbstractItem*> items;

    for(int i=0; i<items.size(); i++)
    {
        delete items[i];
    }
    items.clear();

    plot->clearGraphs();
    plot->addGraph();

    plot->graph(0)->setData(x, y);

    plot->xAxis->setLabel("time (s)");
    plot->yAxis->setLabel("y");

    plot->xAxis->setRange(0, 2);
    plot->yAxis->setRange(-4, 4);

    float lastN, lastQ, lastR;
    bool foundN=false, foundQ=false;

    int currXPos = 0;
    float lastQTime, lastNTime, lastRTime;

    int annNum = ann.GetEcgAnnotationSize();
    for (int i = 0; i < annNum; i++)
    {
        int smpl = ANN[i][0];
        int type = ANN[i][1];

        float msec = float(((double)smpl / sr));

        /*
        QCPItemText *text = new QCPItemText(plot);
        plot->addItem(text);
        text->setText(QString::fromWCharArray(anncodes[type]));
        text->position->setCoords(msec, 7.3);*/

        if(anncodes[type][0] == L'(' && anncodes[type][1] == L't')
        {
            lastTTime = msec;

            while(currXPos < x.size()-1 && x[currXPos] < msec)
                currXPos++;
        }
        if(anncodes[type][0] == L't' && anncodes[type][1] == L')')
        {
            if(lastTTime > 0)
            {

                int firstXPos = currXPos;
                while(currXPos < x.size()-1 && x[currXPos] < msec)
                    currXPos++;

                float first = y[firstXPos];
                float second = y[currXPos];

                float mid = y[(firstXPos + currXPos)/2];

                mid -= (first+second)/2;

                float f = -mid/0.2f;
                if(f < 0) f = 0;
                if(f > 1) f = 1;

                float qr_perc = (lastN - lastQ) / (lastR - lastQ);

                float alpha = 0;

                if(mAnn != 0)
                {
                    fann_type *calc_out;
                    fann_type input[3];

                    input[0] = mid;
                    input[1] = lastRTime - lastQTime;
                    input[2] = qr_perc;
                    calc_out = fann_run(mAnn, input);
                    alpha = (calc_out[0] + 1)/2.0f;

                    if(alpha > 1) alpha = 1;
                    if(alpha < 0) alpha = 0;
                }

                QColor color = QColor(255, 0, 0, 128*alpha);

                QBrush brush;
                brush.setStyle(Qt::SolidPattern);
                brush.setColor(color);
                QPen pen;
                pen.setColor(color);

                QCPItemRect* rect = new QCPItemRect(plot);
                rect->topLeft->setCoords(lastNTime, 4);
                rect->bottomRight->setCoords(msec, -4);
                rect->setBrush(brush);
                QPen nonePen;
                nonePen.setColor(QColor(255,255,255,0));
                rect->setPen(nonePen);
                plot->addItem(rect);

                items.push_back(rect);


                brush.setColor(QColor(255,255,255,0));
                rect = new QCPItemRect(plot);
                rect->topLeft->setCoords(lastTTime, 4);
                rect->bottomRight->setCoords(msec, -4);
                rect->setBrush(brush);
                plot->addItem(rect);

                items.push_back(rect);

                QCPItemText *text = new QCPItemText(plot);
                plot->addItem(text);
                text->setText(QString::number(mid, 'f', 2));
                text->position->setCoords((lastTTime+msec)/2, 4.3);

                items.push_back(text);

                text = new QCPItemText(plot);
                plot->addItem(text);
                text->setText("T");
                text->position->setCoords((lastTTime+msec)/2, 5);

                items.push_back(text);
            }

            lastTTime = -1;
        }
        if(anncodes[type][0] == L'N')
        {
            while(currXPos < x.size()-1 && x[currXPos] < msec)
                currXPos++;

            lastN = y[currXPos];
            lastNTime = msec;
        }
        if(anncodes[type][0] == L'Q')
        {
            while(currXPos < x.size()-1 && x[currXPos] < msec)
                currXPos++;

            lastQ = y[currXPos];
            lastQTime = msec;

            std::cout << "LAST Q: "<<lastQ<<"\n";
        }
        if(anncodes[type][0] == L'R')
        {
            while(currXPos < x.size()-1 && x[currXPos] < msec)
                currXPos++;

            lastR = y[currXPos];
            lastRTime = msec;

            if(lastNTime < lastQTime && lastQTime < lastRTime && lastRTime - lastNTime < 1.0f)
            {


            float qr_perc = (lastN - lastQ) / (lastR - lastQ);

            //std::cout <<lastN<<" "<<lastQ<<" "<<lastR<<" "<<  qr_perc<<"\n";

            QBrush brush;
            brush.setStyle(Qt::SolidPattern);
            brush.setColor(QColor(255,255,255,20));


            QCPItemRect* rect = new QCPItemRect(plot);
            rect->topLeft->setCoords(lastNTime, 4);
            rect->bottomRight->setCoords(msec, -4);
            rect->setBrush(brush);
            plot->addItem(rect);

            items.push_back(rect);

            QCPItemText *text = new QCPItemText(plot);
            plot->addItem(text);
            text->setText(QString::number(msec - lastQTime, 'f', 2)+"s");
            text->position->setCoords((lastNTime+msec)/2, -4.3);

            items.push_back(text);

            text = new QCPItemText(plot);
            plot->addItem(text);
            text->setText(QString::number(qr_perc*100, 'f', 2)+"%");
            text->position->setCoords((lastNTime+msec)/2, 4.3);

            items.push_back(text);

            text = new QCPItemText(plot);
            plot->addItem(text);
            text->setText("Q");
            text->position->setCoords((lastNTime+msec)/2, 5);

            items.push_back(text);
            }
        }
    }

    plot->replot();
}
示例#12
0
FlowViewWindow::FlowViewWindow(const QVector<CANFrame> *frames, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::FlowViewWindow)
{
    ui->setupUi(this);    

    readSettings();

    modelFrames = frames;

    playbackTimer = new QTimer();

    currentPosition = 0;
    playbackActive = false;
    playbackForward = true;

    memset(refBytes, 0, 8);
    memset(currBytes, 0, 8);
    memset(triggerValues, -1, sizeof(int) * 8);

    //ui->graphView->setInteractions();

    ui->graphView->xAxis->setRange(0, 8);
    ui->graphView->yAxis->setRange(-10, 265); //run range a bit outside possible number so they aren't plotted in a hard to see place
    ui->graphView->axisRect()->setupFullAxesBox();

    QCPItemText *textLabel = new QCPItemText(ui->graphView);
    ui->graphView->addItem(textLabel);
    textLabel->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter);
    textLabel->position->setType(QCPItemPosition::ptAxisRectRatio);
    textLabel->position->setCoords(0.5, .5);
    textLabel->setText("+");
    textLabel->setFont(QFont(font().family(), 16)); // make font a bit larger
    textLabel->setPen(QPen(Qt::black)); // show black border around text

    ui->graphView->xAxis->setLabel("Time Axis");
    ui->graphView->yAxis->setLabel("Value Axis");
    QFont legendFont = font();
    legendFont.setPointSize(10);
    QFont legendSelectedFont = font();
    legendSelectedFont.setPointSize(12);
    legendSelectedFont.setBold(true);
    ui->graphView->legend->setFont(legendFont);
    ui->graphView->legend->setSelectedFont(legendSelectedFont);
    ui->graphView->legend->setSelectableParts(QCPLegend::spItems); // legend box shall not be selectable, only legend items
    //ui->graphView->xAxis->setAutoSubTicks(false);
    //ui->graphView->xAxis->setAutoTicks(false);
    ui->graphView->xAxis->setAutoTickStep(false);
    ui->graphView->xAxis->setAutoSubTicks(false);
    ui->graphView->xAxis->setNumberFormat("gb");
    ui->graphView->xAxis->setTickStep(5.0);
    ui->graphView->xAxis->setSubTickCount(0);

    connect(ui->btnBackOne, SIGNAL(clicked(bool)), this, SLOT(btnBackOneClick()));
    connect(ui->btnPause, SIGNAL(clicked(bool)), this, SLOT(btnPauseClick()));
    connect(ui->btnReverse, SIGNAL(clicked(bool)), this, SLOT(btnReverseClick()));
    connect(ui->btnStop, SIGNAL(clicked(bool)), this, SLOT(btnStopClick()));
    connect(ui->btnPlay, SIGNAL(clicked(bool)), this, SLOT(btnPlayClick()));
    connect(ui->btnForwardOne, SIGNAL(clicked(bool)), this, SLOT(btnFwdOneClick()));
    connect(ui->spinPlayback, SIGNAL(valueChanged(int)), this, SLOT(changePlaybackSpeed(int)));
    connect(ui->cbLoopPlayback, SIGNAL(clicked(bool)), this, SLOT(changeLooping(bool)));
    connect(ui->listFrameID, SIGNAL(currentTextChanged(QString)), this, SLOT(changeID(QString)));
    connect(playbackTimer, SIGNAL(timeout()), this, SLOT(timerTriggered()));    
    connect(ui->graphView, SIGNAL(plottableDoubleClick(QCPAbstractPlottable*,QMouseEvent*)), this, SLOT(plottableDoubleClick(QCPAbstractPlottable*,QMouseEvent*)));
    connect(ui->txtTrigger0, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
    connect(ui->txtTrigger1, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
    connect(ui->txtTrigger2, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
    connect(ui->txtTrigger3, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
    connect(ui->txtTrigger4, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
    connect(ui->txtTrigger5, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
    connect(ui->txtTrigger6, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
    connect(ui->txtTrigger7, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));

    connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)));

    ui->graphView->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(ui->graphView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequestGraph(QPoint)));
    ui->flowView->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(ui->flowView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequestFlow(QPoint)));

    playbackTimer->setInterval(ui->spinPlayback->value()); //set the timer to the default value of the control
}
示例#13
0
GraphVisualizer::GraphVisualizer(QWidget *parent) :
    QCustomPlot(parent),
    labelCoord(NULL)
{
    // Layer pour la position des octaves
    this->addGraph();
    QPen graphPen;
    graphPen.setColor(QColor(0, 0, 0, 40));
    graphPen.setWidth(1);
    this->graph(0)->setPen(graphPen);
    this->graph(0)->setLineStyle(QCPGraph::lsLine);
    for (int i = 0; i < 10; i++)
    {
        int note = 12 * (i + 1);
        QCPItemText *textLabel = new QCPItemText(this);
        listTextOctave << textLabel;
        this->addItem(textLabel);
        textLabel->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter);
        textLabel->position->setType(QCPItemPosition::ptPlotCoords);
        textLabel->position->setCoords(note, 0);
        textLabel->setText(Config::getInstance()->getKeyName(note));
        textLabel->setFont(QFont(font().family(), 8));
        textLabel->setColor(QColor(40, 40, 40));
    }

    // Layer des moyennes
    this->addGraph();
    graphPen.setColor(QColor(30, 250, 80));
    graphPen.setWidth(2);
    this->graph(1)->setPen(graphPen);
    this->graph(1)->setLineStyle(QCPGraph::lsNone);
    this->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 7));
    this->graph(1)->setAntialiasedScatters(true);

    // Layer des valeurs
    this->addGraph();
    graphPen.setColor(QColor(100, 130, 250));
    graphPen.setWidth(2);
    this->graph(2)->setPen(graphPen);
    this->graph(2)->setLineStyle(QCPGraph::lsNone);
    this->graph(2)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, 5));
    this->graph(2)->setAntialiasedScatters(false);

    // Layer des valeurs par défaut
    this->addGraph();
    graphPen.setColor(QColor(100, 130, 250));
    graphPen.setWidth(1);
    this->graph(3)->setPen(graphPen);
    this->graph(3)->setLineStyle(QCPGraph::lsNone);
    this->graph(3)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, 5));
    this->graph(3)->setAntialiasedScatters(false);

    // Layer aperçu valeurs
    this->addGraph();
    graphPen.setColor(QColor(0, 0, 0));
    graphPen.setWidth(1);
    this->graph(4)->setPen(graphPen);
    this->graph(4)->setScatterStyle(QCPScatterStyle::ssPlus);
    labelCoord = new QCPItemText(this);
    this->addItem(labelCoord);
    labelCoord->position->setType(QCPItemPosition::ptPlotCoords);
    labelCoord->setText("");
    QFont fontLabel = QFont(font().family(), 9);
    fontLabel.setBold(true);
    labelCoord->setFont(fontLabel);
    labelCoord->setColor(QColor(0, 0, 0));

    // Message warning
    textWarning = new QCPItemText(this);
    this->addItem(textWarning);
    textWarning->setPositionAlignment(Qt::AlignTop | Qt::AlignLeft);
    textWarning->position->setType(QCPItemPosition::ptPlotCoords);
    textWarning->position->setCoords(0, 0);
    textWarning->setFont(QFont(font().family(), 10, 100));
    textWarning->setColor(QColor(255, 0, 0));

    // Axes
    this->xAxis->setVisible(false);
    this->xAxis->setTicks(false);
    this->yAxis->setVisible(false);
    this->yAxis->setTicks(false);

    // Marges
    this->axisRect()->setAutoMargins(QCP::msNone);
    this->axisRect()->setMargins(QMargins(0, 0, 0, 0));

    // Filtre sur les événements
    this->installEventFilter(this);
}
示例#14
0
void MainWindow::setupItemAnchorTest(QCustomPlot *customPlot)
{
	customPlot->xAxis->setRange(-3, 3);
	customPlot->yAxis->setRange(-3, 3);
	customPlot->xAxis->setAutoTickCount(5);
	customPlot->yAxis->setAutoTickCount(5);

	QCPItemPixmap *pixmapItem = new QCPItemPixmap(customPlot);
	customPlot->addItem(pixmapItem);
	pixmapItem->setPixmap(QPixmap("./gnu.png"));
	pixmapItem->setScaled(true);
	pixmapItem->topLeft->setCoords(-2, 2);
	pixmapItem->bottomRight->setCoords(-1, 1);
	labelItemAnchors(pixmapItem);

	QCPItemPixmap *pixmapItem2 = new QCPItemPixmap(customPlot);
	customPlot->addItem(pixmapItem2);
	pixmapItem2->setPixmap(QPixmap("./gnu.png"));
	pixmapItem2->setScaled(true);
	pixmapItem2->topLeft->setCoords(1, 0.5);
	pixmapItem2->bottomRight->setCoords(0, 2);
	labelItemAnchors(pixmapItem2);

	QCPItemRect *rect = new QCPItemRect(customPlot);
	customPlot->addItem(rect);
	rect->topLeft->setCoords(-2, 0);
	rect->bottomRight->setCoords(-1, -0.5);
	labelItemAnchors(rect);

	QCPItemRect *rect2 = new QCPItemRect(customPlot);
	customPlot->addItem(rect2);
	rect2->topLeft->setCoords(0, -1);
	rect2->bottomRight->setCoords(-0.5, 0);
	labelItemAnchors(rect2);

	QCPItemEllipse *ellipse = new QCPItemEllipse(customPlot);
	customPlot->addItem(ellipse);
	ellipse->topLeft->setCoords(0.5, 0);
	ellipse->bottomRight->setCoords(1, -1);
	labelItemAnchors(ellipse);

	QCPItemEllipse *ellipse2 = new QCPItemEllipse(customPlot);
	customPlot->addItem(ellipse2);
	ellipse2->topLeft->setCoords(2, -1);
	ellipse2->bottomRight->setCoords(1.1, 0.2);
	labelItemAnchors(ellipse2);

	QCPItemLine *line = new QCPItemLine(customPlot);
	customPlot->addItem(line);
	line->start->setCoords(-2, -1.5);
	line->end->setCoords(-1, -1.2);
	labelItemAnchors(line);

	QCPItemCurve *curve = new QCPItemCurve(customPlot);
	customPlot->addItem(curve);
	curve->start->setCoords(0, -1.5);
	curve->startDir->setCoords(1, -1.5);
	curve->endDir->setCoords(1, -1.2);
	curve->end->setCoords(2, -1.2);
	labelItemAnchors(curve);

	QCPItemBracket *bracket = new QCPItemBracket(customPlot);
	customPlot->addItem(bracket);
	bracket->left->setCoords(-2, -2);
	bracket->right->setCoords(2, -2);
	bracket->setLength(12);
	labelItemAnchors(bracket);

	QCPItemText *text = new QCPItemText(customPlot);
	customPlot->addItem(text);
	text->position->setCoords(0, -2.6);
	text->setText("QCustomPlot");
	text->setFont(QFont(font().family(), 26));
	text->setRotation(12);
	text->setPadding(QMargins(5, 5, 40, 5));
	text->setBrush(QBrush(QColor(0, 0, 0, 30)));
	labelItemAnchors(text);
}
void AP2DataPlot2D::navModeChanged(int uasid, int mode, const QString& text)
{
    Q_UNUSED(mode);
    if (m_uas->getUASID() != uasid)
    {
        return;
    }
    if (m_logLoaded)
    {
        //If a log is currently loaded, we don't care about incoming data.
        return;
    }
    qint64 msec_current = QDateTime::currentMSecsSinceEpoch();
    m_currentIndex = msec_current;
    qint64 newmsec = (msec_current - m_startIndex) + m_timeDiff;
    if (m_graphCount > 0 && ui.autoScrollCheckBox->isChecked())
    {
        double diff = (newmsec / 1000.0) - m_wideAxisRect->axis(QCPAxis::atBottom,0)->range().upper;
        m_wideAxisRect->axis(QCPAxis::atBottom,0)->setRangeLower(m_wideAxisRect->axis(QCPAxis::atBottom,0)->range().lower + diff);
        m_wideAxisRect->axis(QCPAxis::atBottom,0)->setRangeUpper((newmsec / 1000.0));
    }
    if (!m_graphClassMap.contains("MODE"))
    {
        QCPAxis *axis = m_wideAxisRect->addAxis(QCPAxis::atLeft);
        axis->setLabel("MODE");

        if (m_graphCount > 0)
        {
            connect(m_wideAxisRect->axis(QCPAxis::atLeft,0),SIGNAL(rangeChanged(QCPRange)),axis,SLOT(setRange(QCPRange)));
        }
        QColor color = QColor::fromRgb(rand()%255,rand()%255,rand()%255);
        axis->setLabelColor(color);
        axis->setTickLabelColor(color);
        axis->setTickLabelColor(color); // add an extra axis on the left and color its numbers
        QCPGraph *mainGraph1 = m_plot->addGraph(m_wideAxisRect->axis(QCPAxis::atBottom), m_wideAxisRect->axis(QCPAxis::atLeft,m_graphCount++));
        m_graphNameList.append("MODE");

        mainGraph1->setPen(QPen(color, 2));
        Graph graph;
        graph.axis = axis;
        graph.groupName = "";
        graph.graph=  mainGraph1;
        graph.isInGroup = false;
        graph.isManualRange = false;
        m_graphClassMap["MODE"] = graph;

        mainGraph1->rescaleValueAxis();
        if (m_graphCount == 1)
        {
            mainGraph1->rescaleKeyAxis();
        }
    }
    QCPAxis *xAxis = m_wideAxisRect->axis(QCPAxis::atBottom);
    QCPItemText *itemtext = new QCPItemText(m_plot);
    itemtext->setText(text);
    itemtext->position->setAxes(xAxis,m_graphClassMap["MODE"].axis);
    itemtext->position->setCoords((newmsec / 1000.0),2.0);
    m_plot->addItem(itemtext);
    m_graphClassMap["MODE"].itemList.append(itemtext);
    m_graphClassMap["MODE"].modeMap[newmsec / 1000.0] = text;


    QCPItemLine *itemline = new QCPItemLine(m_plot);
    m_graphClassMap["MODE"].itemList.append(itemline);
    itemline->start->setParentAnchor(itemtext->bottom);
    itemline->start->setAxes(xAxis, m_graphClassMap["MODE"].axis);
    itemline->start->setCoords(0.0, 0.0);
    itemline->end->setAxes(xAxis, m_graphClassMap["MODE"].axis);
    itemline->end->setCoords((newmsec / 1000.0), 0.0);
    itemline->setTail(QCPLineEnding::esDisc);
    itemline->setHead(QCPLineEnding::esSpikeArrow);
    m_plot->addItem(itemline);
}
示例#16
0
void LiftDragPlot::updatePlot()
{
    clearPlottables();
    clearItems();

    xAxis->setLabel(tr("Drag Coefficient"));
    yAxis->setLabel(tr("Lift Coefficient"));

    double lower = mMainWindow->rangeLower();
    double upper = mMainWindow->rangeUpper();

    QVector< double > t, x, y;

    double xMin, xMax;
    double yMin, yMax;

    int start = mMainWindow->findIndexBelowT(lower) + 1;
    int end   = mMainWindow->findIndexAboveT(upper);

    double s10 = 0, s01 = 0, s20 = 0, s11 = 0;
    double s21 = 0, s30 = 0, s40 = 0;

    bool first = true;
    for (int i = start; i < end; ++i)
    {
        const DataPoint &dp = mMainWindow->dataPoint(i);

        t.append(dp.t);
        x.append(dp.drag);
        y.append(dp.lift);

        if (first)
        {
            xMax = x.back();
            yMax = y.back();

            first = false;
        }
        else
        {
            if (x.back() > xMax) xMax = x.back();
            if (y.back() > yMax) yMax = y.back();
        }

        s10 += dp.lift;
        s01 += dp.drag;
        s20 += dp.lift * dp.lift;
        s11 += dp.lift * dp.drag;
        s21 += dp.lift * dp.lift * dp.drag;
        s30 += dp.lift * dp.lift * dp.lift;
        s40 += dp.lift * dp.lift * dp.lift * dp.lift;
    }

    QCPCurve *curve = new QCPCurve(xAxis, yAxis);
    curve->setData(t, x, y);
    curve->setPen(QPen(Qt::lightGray, mMainWindow->lineThickness()));
    curve->setLineStyle(QCPCurve::lsNone);
    curve->setScatterStyle(QCPScatterStyle::ssDisc);
    addPlottable(curve);

    setViewRange(xMax, yMax);

    // Update plot limits
    xMin = xAxis->range().lower;
    xMax = xAxis->range().upper;

    yMin = yAxis->range().lower;
    yMax = yAxis->range().upper;

    if (mMainWindow->markActive())
    {
        int i1 = mMainWindow->findIndexBelowT(mMainWindow->markEnd()) + 1;
        int i2 = mMainWindow->findIndexAboveT(mMainWindow->markEnd()) - 1;

        const DataPoint &dp1 = mMainWindow->dataPoint(i1);
        const DataPoint &dp2 = mMainWindow->dataPoint(i2);

        QVector< double > xMark, yMark;

        if (mMainWindow->markEnd() - dp1.t < dp2.t - mMainWindow->markEnd())
        {
            xMark.append(dp1.drag);
            yMark.append(dp1.lift);
        }
        else
        {
            xMark.append(dp2.drag);
            yMark.append(dp2.lift);
        }

        QCPGraph *graph = addGraph();
        graph->setData(xMark, yMark);
        graph->setPen(QPen(Qt::black, mMainWindow->lineThickness()));
        graph->setLineStyle(QCPGraph::lsNone);
        graph->setScatterStyle(QCPScatterStyle::ssDisc);
    }

    // x = ay^2 + c
    const double m = 1 / mMainWindow->maxLD();
    const double c = mMainWindow->minDrag();
    const double a = m * m / (4 * c);

    // Draw tangent line
    const double yt = sqrt(c / a);

    if (a != 0)
    {
        x.clear();
        y.clear();

        x << m * yMin << m * yMax;
        y << yMin << yMax;

        QCPGraph *graph = addGraph();
        graph->setData(x, y);
        graph->setPen(QPen(Qt::blue, mMainWindow->lineThickness(), Qt::DashLine));
    }

    // Draw minimum drag
    x.clear();
    y.clear();

    x << mMainWindow->minDrag() << mMainWindow->minDrag();
    y << yMin << yMax;

    QCPGraph *graph = addGraph();
    graph->setData(x, y);
    graph->setPen(QPen(Qt::blue, mMainWindow->lineThickness(), Qt::DashLine));

    // Draw maximum lift
    x.clear();
    y.clear();

    x << xMin << xMax;
    y << mMainWindow->maxLift() << mMainWindow->maxLift();

    graph = addGraph();
    graph->setData(x, y);
    graph->setPen(QPen(Qt::blue, mMainWindow->lineThickness(), Qt::DashLine));

    // Draw saved curve
    t.clear();
    x.clear();
    y.clear();

    for (int i = 0; i <= 100; ++i)
    {
        const double yy = yMin + (yMax - yMin) / 100 * i;

        t.append(yy);
        x.append(a * yy * yy + c);
        y.append(yy);
    }

    curve = new QCPCurve(xAxis, yAxis);
    curve->setData(t, x, y);
    curve->setPen(QPen(Qt::red, mMainWindow->lineThickness()));
    addPlottable(curve);

    // Draw dot at maximum L/D
    x.clear();
    y.clear();

    x << a * yt * yt + c;
    y << yt;

    graph = addGraph();
    graph->setData(x, y);
    graph->setPen(QPen(Qt::red, mMainWindow->lineThickness()));
    graph->setLineStyle(QCPGraph::lsNone);
    graph->setScatterStyle(QCPScatterStyle::ssDisc);

    // Add label to show equation for saved curve
    QCPItemText *textLabel = new QCPItemText(this);
    addItem(textLabel);

    QPainter painter(this);
    double mmPerPix = (double) painter.device()->widthMM() / painter.device()->width();

    double xRatioPerPix = 1.0 / axisRect()->width();
    double xRatioPerMM = xRatioPerPix / mmPerPix;

    double yRatioPerPix = 1.0 / axisRect()->height();
    double yRatioPerMM = yRatioPerPix / mmPerPix;

    textLabel->setPositionAlignment(Qt::AlignBottom|Qt::AlignRight);
    textLabel->setTextAlignment(Qt::AlignRight);
    textLabel->position->setType(QCPItemPosition::ptAxisRectRatio);
    textLabel->position->setCoords(1 - 5 * xRatioPerMM,
                                   1 - 5 * yRatioPerMM);
    textLabel->setText(
                QString("Minimum drag = %1\nMaximum lift = %2\nMaximum L/D = %3")
                    .arg(fabs(c))
                    .arg(mMainWindow->maxLift())
                    .arg(1/ m));

    replot();
}
示例#17
0
void MainWindow::fillArrhytmiaPlot(int** ANN, QCustomPlot *plot, EcgAnnotation& ann, QVector<double> &x, QVector<double> &y, double sr)
{
    QPen pen;
    pen.setColor(QColor(255,0,0));
    float lastRTime = -1;

    static std::vector<QCPAbstractItem*> items;

    for(int i=0; i<items.size(); i++)
    {
        delete items[i];
    }
    items.clear();

    plot->clearGraphs();
    plot->addGraph();

    plot->graph(0)->setData(x, y);

    plot->xAxis->setLabel("time (s)");
    plot->yAxis->setLabel("y");

    plot->xAxis->setRange(0, 2);
    plot->yAxis->setRange(-4, 4);

    int annNum = ann.GetEcgAnnotationSize();
    for (int i = 0; i < annNum; i++)
    {
        int smpl = ANN[i][0];
        int type = ANN[i][1];

        float msec = float(((double)smpl / sr));

        if(anncodes[type][0] == L'R')
        {
            if(lastRTime > 0)
            {
                float time = 60.0f/(msec - lastRTime);
                bool blue = false;

                time -= 75;
                time /= 20.0f;
                if(time < 0) { time = -time; blue = true; }
                if(time > 1) time = 1;

                QColor color = QColor(!blue ? 255 : 255*(1-time), 255*(1-time), blue ? 255 : 255*(1-time), 128);

                QBrush brush;
                brush.setStyle(Qt::SolidPattern);
                brush.setColor(color);

                QCPItemRect* rect = new QCPItemRect(plot);
                plot->addItem(rect);
                rect->topLeft->setCoords(lastRTime, 4);
                rect->bottomRight->setCoords(msec, -4);
                rect->setBrush(brush);

                items.push_back(rect);

                QCPItemText *text = new QCPItemText(plot);
                plot->addItem(text);
                text->setText(QString::number(msec - lastRTime, 'f', 2)+"s");
                text->position->setCoords((lastRTime+msec)/2, 6.3);

                items.push_back(text);
            }

            lastRTime = msec;
        }
    }

    plot->replot();
}
示例#18
0
void smart_plot::mousePress(QMouseEvent *event)
{
    static double prevKey, prevValue;

    if(event->button() == Qt::MiddleButton)
    {
        QCPAbstractPlottable *plottable = activePlot()->plottableAt(event->localPos());

        if(plottable)
        {
            QCPGraph *graph = qobject_cast<QCPGraph*>(plottable);
            plot_analytics analytics;
            plotStats stats;

            if(graph)
            {
                //Do diff by % range vs
                double mouseKey = graph->keyAxis()->pixelToCoord(event->localPos().x());
                double mouseValue = graph->valueAxis()->pixelToCoord(event->localPos().y());
                double keyRange = graph->keyAxis()->range().size();
                double keyDistance_no_abs = 0;
                double value = 0;
                double key = 0;

                bool ok = false;
                double m = std::numeric_limits<double>::max();
                //QCPGraphDataContainer
                analytics.plotAnalyze( graph, &stats, graph->keyAxis()->range());

                //Iterate through on screen data and see which point is closest
                QCPGraphDataContainer::const_iterator QCPGraphDataBegin = graph->data().data()->findBegin(graph->keyAxis()->range().lower,true);
                QCPGraphDataContainer::const_iterator QCPGraphDataEnd = graph->data().data()->findEnd(graph->keyAxis()->range().upper,true);
                for (QCPGraphDataContainer::const_iterator QCPGraphDataIt=QCPGraphDataBegin; QCPGraphDataIt!=QCPGraphDataEnd; ++QCPGraphDataIt)
                {
                    double valueRange = graph->valueAxis()->range().size();
                    double keyDistance = qAbs(mouseKey - QCPGraphDataIt->key)/keyRange;
                    double valueDistance = qAbs(mouseValue - QCPGraphDataIt->value)/valueRange;

                    if( (valueDistance + keyDistance) < m )
                    {
                        value = QCPGraphDataIt->value;
                        key = QCPGraphDataIt->key;
                        keyDistance_no_abs = mouseKey - QCPGraphDataIt->key;
                        ok = true;
                        m = (valueDistance + keyDistance);
                    }
                }
//                qDebug () << QDateTime::fromTime_t((int)mouseKey) << value;

                if(ok)
                {
                    QToolTip::hideText();

                    if(!qSharedPointerDynamicCast<QCPAxisTickerDateTime>(graph->keyAxis()->ticker()).isNull())
                    {
                        if(QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
                        {
                            quint32 timeDelta = qAbs(mouseKey-prevKey);

                            // add the bracket at the top:
                            QCPItemBracket *bracket = new QCPItemBracket(activePlot());
                            bracket->left->setAxes(graph->keyAxis(), graph->valueAxis());
                            bracket->left->setCoords(prevKey, value);
                            bracket->right->setAxes(graph->keyAxis(), graph->valueAxis());
                            bracket->right->setCoords(mouseKey, value);

                            // add the text label at the top:
                            QCPItemText *wavePacketText = new QCPItemText(activePlot());
                            wavePacketText->position->setParentAnchor(bracket->center);
                            wavePacketText->position->setCoords(0, -10); // move 10 pixels to the top from bracket center anchor
                            wavePacketText->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter);
                            wavePacketText->setText(
                                QString("%L1: ΔX->%L2 ΔY->%L3").
                                   arg(graph->name().isEmpty() ? "..." : graph->name()).
                                   arg(seconds_to_DHMS(timeDelta)).
                                   arg(value-prevValue));
                            wavePacketText->setFont(QFont(font().family(), 12));
                            activePlot()->replot();
                        }
                        else if(QApplication::keyboardModifiers().testFlag(Qt::AltModifier))
                        {
                            if(QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier))
                                graph->addData(graph->keyAxis()->pixelToCoord(event->localPos().x()),
                                               graph->valueAxis()->pixelToCoord(event->localPos().y()));
                            else if(keyDistance_no_abs < 0)
                                graph->addData(key - 1, std::numeric_limits<double>::quiet_NaN());
                            else
                                graph->addData(key + 1, std::numeric_limits<double>::quiet_NaN());

                            activePlot()->replot();
                        }
                        else if(QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier))
                        {
                            //Delete point
                            graph->data().data()->remove(key);
                            activePlot()->replot();
                        }
                        //Hold Alt to insert NAN(Break link?)
                        else
                        {
                            QDateTime dateTime;
                            dateTime.setTime_t(mouseKey);

                            //activePlot()->xAxis->tick
                            QToolTip::showText(event->globalPos(),
                            QString("<table>"
                                    "<tr>" "<th colspan=\"2\">%L1</th>"  "</tr>"
                                    "<tr>" "<td>X:</td>"   "<td>%L2</td>" "</tr>"
                                    "<tr>" "<td>Y:</td>"   "<td>%L3</td>" "</tr>"
                                    "<tr>" "<td>Min:</td>" "<td>%L4</td>" "</tr>"
                                    "<tr>" "<td>Avg:</td>" "<td>%L5</td>" "</tr>"
                                    "<tr>" "<td>Max:</td>" "<td>%L6</td>" "</tr>"
                                   "</table>").
                               arg(graph->name().isEmpty() ? "..." : graph->name()).
                               arg(dateTime.toString(qSharedPointerDynamicCast<QCPAxisTickerDateTime>(graph->keyAxis()->ticker())->dateTimeFormat())).
                               arg(value).
                               arg(stats.minValue).
                               arg(stats.avgValue).
                               arg(stats.maxValue),
                               activePlot(), activePlot()->rect());
                        }
                    }
                    else
                    {
                        QToolTip::showText(event->globalPos(),
                        QString("<table>"
                                "<tr>" "<th colspan=\"2\">%L1</th>"  "</tr>"
                                "<tr>" "<td>X:</td>"   "<td>%L2</td>" "</tr>"
                                "<tr>" "<td>Y:</td>"   "<td>%L3</td>" "</tr>"
                                "<tr>" "<td>Min:</td>" "<td>%L4</td>" "</tr>"
                                "<tr>" "<td>Avg:</td>" "<td>%L5</td>" "</tr>"
                                "<tr>" "<td>Max:</td>" "<td>%L6</td>" "</tr>"
                               "</table>").
                           arg(graph->name().isEmpty() ? "..." : graph->name()).
                           arg(mouseKey).
                           arg(value).
                           arg(stats.minValue).
                           arg(stats.avgValue).
                           arg(stats.maxValue),
                           activePlot(), activePlot()->rect());
                    }
                }

                prevKey = mouseKey;
                prevValue = value;
            }
        }
    }
}
示例#19
0
void MainWindow::fillPericarditisPlot(int** ANN, QCustomPlot *plot, EcgAnnotation& ann, QVector<double> &x, QVector<double> &y, double sr)
{
    QPen pen;
    pen.setColor(QColor(255,0,0));

    static std::vector<QCPAbstractItem*> items;

    for(int i=0; i<items.size(); i++)
    {
        delete items[i];
    }
    items.clear();

    plot->clearGraphs();
    plot->addGraph();

    plot->graph(0)->setData(x, y);

    plot->xAxis->setLabel("time (s)");
    plot->yAxis->setLabel("y");

    plot->xAxis->setRange(0, 2);
    plot->yAxis->setRange(-4, 4);

    int lastP = 0, lastQ = 0;
    int lastS = 0;

    int currXPos = 0;

    int annNum = ann.GetEcgAnnotationSize();
    for (int i = 0; i < annNum; i++)
    {
        int smpl = ANN[i][0];
        int type = ANN[i][1];

        float msec = float(((double)smpl / sr));

        if(anncodes[type][0] == L'p' && anncodes[type][1] == L')')
        {
            while(currXPos < x.size()-1 && x[currXPos] < msec)
                currXPos++;

            lastP = currXPos;
        }
        if(anncodes[type][0] == L'N')
        {
            while(currXPos < x.size()-1 && x[currXPos] < msec)
                currXPos++;

            lastQ = currXPos;
        }
        if(anncodes[type][0] == L')')
        {
            while(currXPos < x.size()-1 && x[currXPos] < msec)
                currXPos++;

            lastS = currXPos;
        }
        if(anncodes[type][0] == L'(' && anncodes[type][1] == L't')
        {
            while(currXPos < x.size()-1 && x[currXPos] < msec)
                currXPos++;

            int lastT = currXPos;

            if(lastP < lastQ && lastQ < lastS && lastS < lastT && x[lastT] - x[lastP] < 0.5f)
            {
                float midPQ = 0;
                for(int i=lastP; i<=lastQ; i++)
                {
                    midPQ += y[i];
                }
                midPQ /= (lastQ - lastP)+1;

                float midST = 0;
                for(int i=lastS; i<=lastT; i++)
                {
                    midST += y[i];
                }
                midST /= (lastT - lastS)+1;

                float alpha = 0;

                if(pAnn != 0)
                {
                    fann_type *calc_out;
                    fann_type input[1];

                    input[0] = midST - midPQ;
                    calc_out = fann_run(pAnn, input);
                    alpha = (calc_out[0] + 1)/2.0f;

                    if(alpha > 1) alpha = 1;
                    if(alpha < 0) alpha = 0;

                    std::cout <<input[0] << " -- A:"<< alpha <<"\n";
                }

                QBrush brush;
                brush.setStyle(Qt::SolidPattern);
                brush.setColor(QColor(255,0,0, 200*alpha));

                QPen pen;
                pen.setColor(brush.color());

                QCPItemRect* rect = new QCPItemRect(plot);
                rect->topLeft->setCoords(x[lastP], 4);
                rect->bottomRight->setCoords(x[lastT], -4);
                rect->setBrush(brush);
                plot->addItem(rect);

                items.push_back(rect);

                rect->setPen(pen);

                brush.setColor(QColor(255,255,255,20));

                rect = new QCPItemRect(plot);
                rect->topLeft->setCoords(x[lastP], 3.5);
                rect->bottomRight->setCoords(x[lastQ], -3.5);
                rect->setBrush(brush);
                plot->addItem(rect);

                items.push_back(rect);

                rect = new QCPItemRect(plot);
                rect->topLeft->setCoords(x[lastS], 3.5);
                rect->bottomRight->setCoords(x[lastT], -3.5);
                rect->setBrush(brush);
                plot->addItem(rect);

                items.push_back(rect);

                QCPItemText *text = new QCPItemText(plot);
                plot->addItem(text);
                text->setText("PQ");
                text->position->setCoords((x[lastP]+x[lastQ])/2, -4.3);

                items.push_back(text);

                text = new QCPItemText(plot);
                plot->addItem(text);
                text->setText("ST");
                text->position->setCoords((x[lastS]+x[lastT])/2, -4.3);

                items.push_back(text);

                text = new QCPItemText(plot);
                plot->addItem(text);
                text->setText(QString::number(midPQ, 'f', 2));
                text->position->setCoords((x[lastP]+x[lastQ])/2, 4.3);

                items.push_back(text);

                text = new QCPItemText(plot);
                plot->addItem(text);
                text->setText(QString::number(midST, 'f', 2));
                text->position->setCoords((x[lastS]+x[lastT])/2, 4.3);

                items.push_back(text);

                text = new QCPItemText(plot);
                plot->addItem(text);
                text->setText(QString("ST - PQ = ")+QString::number(midST - midPQ, 'f', 2));
                text->position->setCoords((x[lastP]+x[lastT])/2, 5);

                items.push_back(text);
            }
        }
    }

    plot->replot();
}
示例#20
0
GraphParamGlobal::GraphParamGlobal(QWidget * parent) : QCustomPlot(parent),
    forme(FORME_MANUELLE),
    flagEdit(false),
    limitEdit(0),
    nbPoints(140),
    raideurExp(50.0),
    yMin(0.), yMax(1.),
    xMin(0), xMax(140),
    labelCoord(NULL),
    previousX(-1)
{
    // Layer pour la position des octaves
    this->addGraph();
    QPen graphPen;
    graphPen.setColor(QColor(0, 0, 0, 40));
    graphPen.setWidth(1);
    this->graph(0)->setPen(graphPen);
    this->graph(0)->setLineStyle(QCPGraph::lsLine);
    QVector<double> x, y;
    x.resize(20);
    y.resize(20);
    y[0] = y[3] = y[4] = y[7] = y[8] = y[11] = y[12] = y[15] = y[16] = y[19] =  2;
    y[1] = y[2] = y[5] = y[6] = y[9] = y[10] = y[13] = y[14] = y[17] = y[18] = -1;
    for (int i = 0; i < 10; i++)
    {
        int note = 12 * (i + 1);
        double pos = (double)(note * this->nbPoints) / 127.;
        x[2*i] = x[2*i+1] = pos;
        QCPItemText *textLabel = new QCPItemText(this);
        this->addItem(textLabel);
        textLabel->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter);
        textLabel->position->setType(QCPItemPosition::ptPlotCoords);
        textLabel->position->setCoords(pos, 0);
        textLabel->setText(Config::getInstance()->getKeyName(note));
        textLabel->setFont(QFont(font().family(), 8));
        textLabel->setColor(QColor(40, 40, 40));
    }
    this->graph(0)->setData(x, y);

    // Layers coloration zone sur laquelle s'étend le clavier
    this->addGraph();
    x.resize(2);
    y.resize(2);
    x[0] = -1;
    x[1] = this->nbPoints + 1;
    y[0] = y[1] = -2;
    graphPen.setWidth(0);
    this->graph(1)->setPen(graphPen);
    this->graph(1)->setData(x, y);
    this->graph(1)->setBrush(QBrush(QColor(255, 255, 0, 30)));
    this->addGraph();
    this->graph(2)->setPen(graphPen);
    this->graph(1)->setChannelFillGraph(this->graph(2));

    // Layer des valeurs
    this->addGraph();
    graphPen.setColor(QColor(100, 130, 250));
    graphPen.setWidth(2);
    this->graph(3)->setPen(graphPen);
    this->graph(3)->setLineStyle(QCPGraph::lsNone);
    this->graph(3)->setScatterStyle(QCPScatterStyle::ssDot);
    this->graph(3)->setAntialiased(true);
    this->graph(3)->setAntialiasedScatters(true);

    // Layer aperçu valeurs
    this->addGraph();
    graphPen.setColor(QColor(0, 0, 0));
    graphPen.setWidth(1);
    this->graph(4)->setPen(graphPen);
    this->graph(4)->setScatterStyle(QCPScatterStyle::ssPlus);
    labelCoord = new QCPItemText(this);
    this->addItem(labelCoord);
    labelCoord->position->setType(QCPItemPosition::ptPlotCoords);
    labelCoord->setText("");
    QFont fontLabel = QFont(font().family(), 9);
    fontLabel.setBold(true);
    labelCoord->setFont(fontLabel);
    labelCoord->setColor(QColor(0, 0, 0));

    // Axes
    this->xAxis->setRange(0, this->nbPoints);
    this->yAxis->setRange(0, 1);
    this->xAxis->setVisible(false);
    this->xAxis->setTicks(false);
    this->yAxis->setVisible(false);
    this->yAxis->setTicks(false);

    // Marges
    this->axisRect()->setAutoMargins(QCP::msNone);
    this->axisRect()->setMargins(QMargins(0, 0, 0, 0));
    // Préparation des données
    this->dValues.resize(this->nbPoints);
    this->dValues.fill(0.5);
    // Filtre sur les événements
    this->installEventFilter(this);
    // Affichage
    this->replot();
}