Kstars

focusprofileplot.cpp
1 /*
2  SPDX-FileCopyrightText: 2012 Jasem Mutlaq <[email protected]>
3  SPDX-FileCopyrightText: 2021 Wolfgang Reissenberger <[email protected]>
4 
5  SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #include "focusprofileplot.h"
9 
10 FocusProfilePlot::FocusProfilePlot(QWidget *parent) : QCustomPlot (parent)
11 {
12  Q_UNUSED(parent);
13 
14  setBackground(QBrush(Qt::black));
15  xAxis->setBasePen(QPen(Qt::white, 1));
16  yAxis->setBasePen(QPen(Qt::white, 1));
17  xAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));
18  yAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));
19  xAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine));
20  yAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine));
21  xAxis->grid()->setZeroLinePen(Qt::NoPen);
22  yAxis->grid()->setZeroLinePen(Qt::NoPen);
23  xAxis->setBasePen(QPen(Qt::white, 1));
24  yAxis->setBasePen(QPen(Qt::white, 1));
25  xAxis->setTickPen(QPen(Qt::white, 1));
26  xAxis->setTickLabelFont(QFont(font().family(), 9));
27  yAxis->setTickPen(QPen(Qt::white, 1));
28  yAxis->setTickLabelFont(QFont(font().family(), 9));
29  xAxis->setSubTickPen(QPen(Qt::white, 1));
30  yAxis->setSubTickPen(QPen(Qt::white, 1));
31  xAxis->setTickLabelColor(Qt::white);
32  yAxis->setTickLabelColor(Qt::white);
33  xAxis->setLabelColor(Qt::white);
34  yAxis->setLabelColor(Qt::white);
35 
36  currentGaus = addGraph();
37  currentGaus->setLineStyle(QCPGraph::lsLine);
38  currentGaus->setPen(QPen(Qt::red, 2));
39 
40  lastGaus = addGraph();
41  lastGaus->setLineStyle(QCPGraph::lsLine);
42  QPen pen(Qt::darkGreen);
43  pen.setStyle(Qt::DashLine);
44  pen.setWidth(2);
45  lastGaus->setPen(pen);
46 
47 }
48 
49 void FocusProfilePlot::drawProfilePlot(double currentHFR)
50 {
51  QVector<double> currentIndexes;
52  QVector<double> currentFrequencies;
53 
54  // HFR = 50% * 1.36 = 68% aka one standard deviation
55  double stdDev = currentHFR * 1.36;
56  float start = -stdDev * 4;
57  float end = stdDev * 4;
58  float step = stdDev * 4 / 20.0;
59  for (double x = start; x < end; x += step)
60  {
61  currentIndexes.append(x);
62  currentFrequencies.append((1 / (stdDev * sqrt(2 * M_PI))) * exp(-1 * (x * x) / (2 * (stdDev * stdDev))));
63  }
64 
65  currentGaus->setData(currentIndexes, currentFrequencies);
66 
67  if (lastGausIndexes.count() > 0)
68  lastGaus->setData(lastGausIndexes, lastGausFrequencies);
69 
70  if (focusAuto && firstGaus == nullptr)
71  {
72  firstGaus = addGraph();
73  QPen pen;
75  pen.setWidth(2);
77  firstGaus->setPen(pen);
78 
79  firstGaus->setData(currentIndexes, currentFrequencies);
80  }
81  else if (firstGaus)
82  {
83  removeGraph(firstGaus);
84  firstGaus = nullptr;
85  }
86 
87  rescaleAxes();
88  replot();
89 
90  lastGausIndexes = currentIndexes;
91  lastGausFrequencies = currentFrequencies;
92 }
93 
94 void FocusProfilePlot::clear()
95 {
96  if (firstGaus)
97  {
98  removeGraph(firstGaus);
99  firstGaus = nullptr;
100  }
101 
102 }
void append(const T &value)
void setColor(const QColor &color)
void setWidth(int width)
The central class of the library. This is the QWidget which displays the plot and interacts with the ...
Definition: qcustomplot.h:3735
void setStyle(Qt::PenStyle style)
@ lsLine
data points are connected by a straight line
Definition: qcustomplot.h:5458
QObject * parent() const const
const QList< QKeySequence > & end()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:51 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.