Ejemplo n.º 1
0
void FlareScoring::prepareDataPlot(
        DataPlot *plot)
{
    // Return now if plot empty
    if (mMainWindow->dataSize() == 0) return;

    DataPoint dpBottom, dpTop;
    bool success;

    switch (mMainWindow->windowMode())
    {
    case MainWindow::Actual:
        success = getWindowBounds(mMainWindow->data(), dpBottom, dpTop);
        break;
    case MainWindow::Optimal:
        success = getWindowBounds(mMainWindow->optimal(), dpBottom, dpTop);
        break;
    }

    // Add shading for scoring window
    if (success && plot->yValue(DataPlot::Elevation)->visible())
    {
        DataPoint dpLower = mMainWindow->interpolateDataT(mMainWindow->rangeLower());
        DataPoint dpUpper = mMainWindow->interpolateDataT(mMainWindow->rangeUpper());

        const double xMin = plot->xValue()->value(dpLower, mMainWindow->units());
        const double xMax = plot->xValue()->value(dpUpper, mMainWindow->units());

        QVector< double > xElev, yElev;

        xElev << xMin << xMax;
        yElev << plot->yValue(DataPlot::Elevation)->value(dpBottom, mMainWindow->units())
              << plot->yValue(DataPlot::Elevation)->value(dpBottom, mMainWindow->units());

        QCPGraph *graph = plot->addGraph(
                    plot->axisRect()->axis(QCPAxis::atBottom),
                    plot->yValue(DataPlot::Elevation)->axis());
        graph->setData(xElev, yElev);
        graph->setPen(QPen(QBrush(Qt::lightGray), mMainWindow->lineThickness(), Qt::DashLine));

        yElev.clear();
        yElev << plot->yValue(DataPlot::Elevation)->value(dpTop, mMainWindow->units())
              << plot->yValue(DataPlot::Elevation)->value(dpTop, mMainWindow->units());

        graph = plot->addGraph(
                    plot->axisRect()->axis(QCPAxis::atBottom),
                    plot->yValue(DataPlot::Elevation)->axis());
        graph->setData(xElev, yElev);
        graph->setPen(QPen(QBrush(Qt::lightGray), mMainWindow->lineThickness(), Qt::DashLine));

        QCPItemRect *rect = new QCPItemRect(plot);
        plot->addItem(rect);

        rect->setPen(QPen(QBrush(Qt::lightGray), mMainWindow->lineThickness(), Qt::DashLine));
        rect->setBrush(QColor(0, 0, 0, 8));

        rect->topLeft->setType(QCPItemPosition::ptAxisRectRatio);
        rect->topLeft->setAxes(plot->xAxis, plot->yValue(DataPlot::Elevation)->axis());
        rect->topLeft->setCoords(-0.1, -0.1);

        rect->bottomRight->setType(QCPItemPosition::ptAxisRectRatio);
        rect->bottomRight->setAxes(plot->xAxis, plot->yValue(DataPlot::Elevation)->axis());
        rect->bottomRight->setCoords(
                    (plot->xValue()->value(dpBottom, mMainWindow->units()) - xMin) / (xMax - xMin),
                    1.1);

        rect = new QCPItemRect(plot);
        plot->addItem(rect);

        rect->setPen(QPen(QBrush(Qt::lightGray), mMainWindow->lineThickness(), Qt::DashLine));
        rect->setBrush(QColor(0, 0, 0, 8));

        rect->topLeft->setType(QCPItemPosition::ptAxisRectRatio);
        rect->topLeft->setAxes(plot->xAxis, plot->yValue(DataPlot::Elevation)->axis());
        rect->topLeft->setCoords(
                    (plot->xValue()->value(dpTop, mMainWindow->units()) - xMin) / (xMax - xMin),
                    -0.1);

        rect->bottomRight->setType(QCPItemPosition::ptAxisRectRatio);
        rect->bottomRight->setAxes(plot->xAxis, plot->yValue(DataPlot::Elevation)->axis());
        rect->bottomRight->setCoords(1.1, 1.1);
    }
}
Ejemplo n.º 2
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();
}
Ejemplo n.º 3
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();
}
void PerformanceScoring::prepareDataPlot(
        DataPlot *plot)
{
    // Return now if plot empty
    if (mMainWindow->dataSize() == 0) return;

    DataPoint dpStart = mMainWindow->interpolateDataT(mStartTime);
    DataPoint dpEnd = mMainWindow->interpolateDataT(mEndTime);

    // Add shading for scoring window
    if (plot->yValue(DataPlot::Elevation)->visible())
    {
        DataPoint dpLower = mMainWindow->interpolateDataT(mMainWindow->rangeLower());
        DataPoint dpUpper = mMainWindow->interpolateDataT(mMainWindow->rangeUpper());

        const double xMin = plot->xValue()->value(dpLower, mMainWindow->units());
        const double xMax = plot->xValue()->value(dpUpper, mMainWindow->units());

        QVector< double > xElev, yElev;

        xElev << xMin << xMax;
        yElev << plot->yValue(DataPlot::Elevation)->value(dpStart, mMainWindow->units())
              << plot->yValue(DataPlot::Elevation)->value(dpStart, mMainWindow->units());

        QCPGraph *graph = plot->addGraph(
                    plot->axisRect()->axis(QCPAxis::atBottom),
                    plot->yValue(DataPlot::Elevation)->axis());
        graph->setData(xElev, yElev);
        graph->setPen(QPen(QBrush(Qt::lightGray), mMainWindow->lineThickness(), Qt::DashLine));

        yElev.clear();
        yElev << plot->yValue(DataPlot::Elevation)->value(dpEnd, mMainWindow->units())
              << plot->yValue(DataPlot::Elevation)->value(dpEnd, mMainWindow->units());

        graph = plot->addGraph(
                    plot->axisRect()->axis(QCPAxis::atBottom),
                    plot->yValue(DataPlot::Elevation)->axis());
        graph->setData(xElev, yElev);
        graph->setPen(QPen(QBrush(Qt::lightGray), mMainWindow->lineThickness(), Qt::DashLine));

        QCPItemRect *rect = new QCPItemRect(plot);

        rect->setPen(QPen(QBrush(Qt::lightGray), mMainWindow->lineThickness(), Qt::DashLine));
        rect->setBrush(QColor(0, 0, 0, 8));

        rect->topLeft->setType(QCPItemPosition::ptAxisRectRatio);
        rect->topLeft->setAxes(plot->xAxis, plot->yValue(DataPlot::Elevation)->axis());
        rect->topLeft->setCoords(-0.1, -0.1);

        rect->bottomRight->setType(QCPItemPosition::ptAxisRectRatio);
        rect->bottomRight->setAxes(plot->xAxis, plot->yValue(DataPlot::Elevation)->axis());
        rect->bottomRight->setCoords(
                    (plot->xValue()->value(dpStart, mMainWindow->units()) - xMin) / (xMax - xMin),
                    1.1);

        rect = new QCPItemRect(plot);

        rect->setPen(QPen(QBrush(Qt::lightGray), mMainWindow->lineThickness(), Qt::DashLine));
        rect->setBrush(QColor(0, 0, 0, 8));

        rect->topLeft->setType(QCPItemPosition::ptAxisRectRatio);
        rect->topLeft->setAxes(plot->xAxis, plot->yValue(DataPlot::Elevation)->axis());
        rect->topLeft->setCoords(
                    (plot->xValue()->value(dpEnd, mMainWindow->units()) - xMin) / (xMax - xMin),
                    -0.1);

        rect->bottomRight->setType(QCPItemPosition::ptAxisRectRatio);
        rect->bottomRight->setAxes(plot->xAxis, plot->yValue(DataPlot::Elevation)->axis());
        rect->bottomRight->setCoords(1.1, 1.1);
    }
}