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

0001 /*
0002     SPDX-FileCopyrightText: 2023 John Evans <john.e.evans.email@googlemail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "aberrationinspectorutils.h"
0010 #include "qcustomplot.h"
0011 
0012 // AberrationInspectorPlot manages the QCustomPlot graph of focus position vs measure for the 9 mosaic tiles
0013 // Each tile has its own curve. The legend shows which curve refers to which tile. The maximum or minimum of each
0014 // curve is also displayed. The tooltip of each max / min gives more info. Optionally, a label describing the max / min
0015 // can be displayed; and the CFZ can be displayed around the centre tile max / min.
0016 //
0017 namespace Ekos
0018 {
0019 
0020 class CurveFitting;
0021 
0022 class AberrationInspectorPlot : public QCustomPlot
0023 {
0024     public:
0025         /**
0026          * @brief create an AberrationInspectorPlot graph
0027          * @param parent widget
0028          */
0029         AberrationInspectorPlot(QWidget *parent = nullptr);
0030 
0031         /**
0032          * @brief add all data for all datapoints for all curves
0033          * @param position focuser position
0034          * @param measure for the associated position
0035          * @param weight for the associated measure
0036          * @param outlier or not
0037          */
0038         void addData(QVector<int> position, QVector<double> measure, QVector<double> weight, QVector<bool> outlier);
0039 
0040         /**
0041          * @brief Add the max / min solution to the plot
0042          * @param tile number
0043          * @param solution position
0044          * @param solution value
0045          */
0046         void drawMaxMin(int tile, double solutionPosition, double solutionValue);
0047 
0048         /**
0049          * @brief Draw the Critical Focus Zone centred on solution
0050          * @param solution position
0051          * @param solution measure
0052          * @param CFZ size in steps
0053          */
0054         void drawCFZ(double solutionPosition, double solutionMeasure, int cfzSteps);
0055 
0056         /**
0057          * @brief Draw the curve
0058          * @param tile
0059          * @param curveFit pointer to generate data points
0060          * @param maxmin is the curve max or min
0061          * @param measure of the curve, e.g. HFR
0062          * @param fit is whether a curve fit was achieved
0063          * @param R2 of the curve fit
0064          */
0065         void drawCurve(int tile, Ekos::CurveFitting *curveFit, int maxmin, double measure, bool fit, double R2);
0066 
0067         /**
0068          * @brief Refresh the entire graph
0069          * @param useTile array indicating which tiles to show/hide
0070          */
0071         void redrawCurve(bool useTile[NUM_TILES]);
0072 
0073         /**
0074          * @brief Initialize the plot
0075          * @param yAxisLabel is the label to display
0076          * @param starUnits the units multiplier to display the pixel data
0077          * @param useWeights whether or not weights have been used
0078          * @param show labels on the plot
0079          * @param show CFZ on the plot
0080          */
0081         void init(QString yAxisLabel, double starUnits, bool useWeights, bool showLabels, bool showCFZ);
0082 
0083         /**
0084          * @brief show / hide labels on plot
0085          * @return setting
0086          */
0087         void setShowLabels(bool setting);
0088 
0089         /**
0090          * @brief show / hide CFZ on plot
0091          * @return setting
0092          */
0093         void setShowCFZ(bool setting);
0094 
0095     private:
0096         /**
0097          * @brief return font size
0098          * @return font size
0099          */
0100         int basicFontSize() const
0101         {
0102             return m_basicFontSize;
0103         }
0104 
0105         /**
0106          * @brief set font size
0107          * @param font size
0108          */
0109         void setBasicFontSize(int fontSize);
0110 
0111         /**
0112          * @brief Setup the axes based on the data
0113          * @param tile to process
0114          */
0115         void setAxes(const int tile);
0116 
0117         /**
0118          * @brief Convert input measure to output display measure
0119          * @param measure to convert
0120          * @return converted measure
0121          */
0122         double getDisplayMeasure(const double measure);
0123 
0124         QVector<int> m_positions;
0125         QVector<QVector<double>> m_measures;
0126 
0127         // Legend items for the plot
0128         QCPAbstractLegendItem *m_legendItems[NUM_TILES] { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
0129 
0130         // Text items highlighting the max / min of each curve
0131         bool m_showLabels = false;
0132         QCPItemText *m_labelItems[NUM_TILES] { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
0133 
0134         // CFZ
0135         bool m_showCFZ = false;
0136         QCPItemBracket *m_CFZ = nullptr;
0137 
0138         // V curves
0139         QCPGraph *m_graph[NUM_TILES] { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
0140         // Focus points plotted as graphs
0141         QCPGraph *focusPoint[NUM_TILES] { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
0142 
0143         // basic font size from which all others are derived
0144         int m_basicFontSize = 10;
0145         // Units multiplier for star measure value
0146         double m_starUnits = 1.0;
0147 
0148         // Max / Mins used to set the graph axes
0149         int m_minPosition = -1;
0150         int m_maxPosition = -1;
0151         double m_minMeasure = -1.0;
0152         double m_maxMeasure = -1.0;
0153 };
0154 
0155 }