File indexing completed on 2024-05-05 15:55:12

0001 /*
0002     SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003     SPDX-FileCopyrightText: 2021 Wolfgang Reissenberger <sterne-jaeger@openfuture.de>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "focusprofileplot.h"
0009 
0010 FocusProfilePlot::FocusProfilePlot(QWidget *parent) : QCustomPlot (parent)
0011 {
0012     Q_UNUSED(parent);
0013 
0014     setBackground(QBrush(Qt::black));
0015     xAxis->setBasePen(QPen(Qt::white, 1));
0016     yAxis->setBasePen(QPen(Qt::white, 1));
0017     xAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));
0018     yAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));
0019     xAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine));
0020     yAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine));
0021     xAxis->grid()->setZeroLinePen(Qt::NoPen);
0022     yAxis->grid()->setZeroLinePen(Qt::NoPen);
0023     xAxis->setBasePen(QPen(Qt::white, 1));
0024     yAxis->setBasePen(QPen(Qt::white, 1));
0025     xAxis->setTickPen(QPen(Qt::white, 1));
0026     xAxis->setTickLabelFont(QFont(font().family(), 9));
0027     yAxis->setTickPen(QPen(Qt::white, 1));
0028     yAxis->setTickLabelFont(QFont(font().family(), 9));
0029     xAxis->setSubTickPen(QPen(Qt::white, 1));
0030     yAxis->setSubTickPen(QPen(Qt::white, 1));
0031     xAxis->setTickLabelColor(Qt::white);
0032     yAxis->setTickLabelColor(Qt::white);
0033     xAxis->setLabelColor(Qt::white);
0034     yAxis->setLabelColor(Qt::white);
0035 
0036     currentGaus = addGraph();
0037     currentGaus->setLineStyle(QCPGraph::lsLine);
0038     currentGaus->setPen(QPen(Qt::red, 2));
0039 
0040     lastGaus = addGraph();
0041     lastGaus->setLineStyle(QCPGraph::lsLine);
0042     QPen pen(Qt::darkGreen);
0043     pen.setStyle(Qt::DashLine);
0044     pen.setWidth(2);
0045     lastGaus->setPen(pen);
0046 
0047 }
0048 
0049 void FocusProfilePlot::drawProfilePlot(double currentHFR)
0050 {
0051     QVector<double> currentIndexes;
0052     QVector<double> currentFrequencies;
0053 
0054     // HFR = 50% * 1.36 = 68% aka one standard deviation
0055     double stdDev = currentHFR * 1.36;
0056     float start   = -stdDev * 4;
0057     float end     = stdDev * 4;
0058     float step    = stdDev * 4 / 20.0;
0059     for (double x = start; x < end; x += step)
0060     {
0061         currentIndexes.append(x);
0062         currentFrequencies.append((1 / (stdDev * sqrt(2 * M_PI))) * exp(-1 * (x * x) / (2 * (stdDev * stdDev))));
0063     }
0064 
0065     currentGaus->setData(currentIndexes, currentFrequencies);
0066 
0067     if (lastGausIndexes.count() > 0)
0068         lastGaus->setData(lastGausIndexes, lastGausFrequencies);
0069 
0070     if (focusAuto && firstGaus == nullptr)
0071     {
0072         firstGaus = addGraph();
0073         QPen pen;
0074         pen.setStyle(Qt::DashDotLine);
0075         pen.setWidth(2);
0076         pen.setColor(Qt::darkMagenta);
0077         firstGaus->setPen(pen);
0078 
0079         firstGaus->setData(currentIndexes, currentFrequencies);
0080     }
0081     else if (firstGaus)
0082     {
0083         removeGraph(firstGaus);
0084         firstGaus = nullptr;
0085     }
0086 
0087     rescaleAxes();
0088     replot();
0089 
0090     lastGausIndexes     = currentIndexes;
0091     lastGausFrequencies = currentFrequencies;
0092 }
0093 
0094 void FocusProfilePlot::clear()
0095 {
0096     if (firstGaus)
0097     {
0098         removeGraph(firstGaus);
0099         firstGaus = nullptr;
0100     }
0101 
0102 }