Kstars

focusprofileplot.cpp
1/*
2 SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
3 SPDX-FileCopyrightText: 2021 Wolfgang Reissenberger <sterne-jaeger@openfuture.de>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#include "focusprofileplot.h"
9
10FocusProfilePlot::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);
43 pen.setStyle(Qt::DashLine);
44 pen.setWidth(2);
45 lastGaus->setPen(pen);
46
47}
48
49void FocusProfilePlot::drawProfilePlot(double currentHFR)
50{
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
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
80 }
81 else if (firstGaus)
82 {
83 removeGraph(firstGaus);
84 firstGaus = nullptr;
85 }
86
88 replot();
89
90 lastGausIndexes = currentIndexes;
91 lastGausFrequencies = currentFrequencies;
92}
93
94void FocusProfilePlot::clear()
95{
96 if (firstGaus)
97 {
98 removeGraph(firstGaus);
99 firstGaus = nullptr;
100 }
101
102}
void setPen(const QPen &pen)
void setData(QSharedPointer< QCPGraphDataContainer > data)
@ lsLine
data points are connected by a straight line
The central class of the library. This is the QWidget which displays the plot and interacts with the ...
QCPGraph * addGraph(QCPAxis *keyAxis=nullptr, QCPAxis *valueAxis=nullptr)
bool removeGraph(QCPGraph *graph)
Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint)
Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false)
const QList< QKeySequence > & end()
void setColor(const QColor &color)
void setStyle(Qt::PenStyle style)
void setWidth(int width)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:48:26 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.