File indexing completed on 2024-04-21 03:43:51
0001 /* 0002 SPDX-FileCopyrightText: 2015 Jasem Mutlaq <mutlaqja@ikarustech.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "fitscommon.h" 0010 #include "fitsdata.h" 0011 #include "ui_fitshistogramui.h" 0012 0013 #include <QDialog> 0014 #include <QUndoCommand> 0015 0016 class QMouseEvent; 0017 0018 class FITSTab; 0019 0020 class histogramUI : public QDialog, public Ui::FITSHistogramUI 0021 { 0022 Q_OBJECT 0023 0024 public: 0025 explicit histogramUI(QDialog * parent = nullptr); 0026 }; 0027 0028 class FITSHistogram : public QDialog 0029 { 0030 Q_OBJECT 0031 0032 friend class histDrawArea; 0033 0034 public: 0035 explicit FITSHistogram(QWidget * parent); 0036 0037 enum { RED_CHANNEL, GREEN_CHANNEL, BLUE_CHANNEL }; 0038 0039 void constructHistogram(); 0040 void syncGUI(); 0041 void reset() 0042 { 0043 m_Constructed = false; 0044 } 0045 0046 void applyFilter(FITSScale ftype); 0047 0048 double getBinWidth(int channel = 0) 0049 { 0050 return binWidth[channel]; 0051 } 0052 0053 QVector<uint32_t> getCumulativeFrequency(int channel = 0) const; 0054 0055 double getJMIndex() const; 0056 0057 bool isConstructed() 0058 { 0059 return m_Constructed; 0060 } 0061 0062 0063 protected: 0064 void showEvent(QShowEvent * event) override; 0065 void driftMouseOverLine(QMouseEvent * event); 0066 0067 public slots: 0068 void applyScale(); 0069 void resizePlot(); 0070 0071 private: 0072 template <typename T> 0073 void constructHistogram(); 0074 double cutMin; 0075 double cutMax; 0076 0077 histogramUI * ui { nullptr }; 0078 FITSTab * tab { nullptr }; 0079 0080 QVector<QVector<uint32_t>> cumulativeFrequency; 0081 QVector<QVector<double>> intensity; 0082 QVector<QVector<double>> frequency; 0083 QVector<QVector<QWidget *>> rgbWidgets; 0084 QVector<ctkRangeSlider *> sliders; 0085 QVector<QDoubleSpinBox *> minBoxes, maxBoxes; 0086 0087 QVector<double> FITSMin; 0088 QVector<double> FITSMax; 0089 QVector<double> sliderScale, sliderTick; 0090 QVector<int> numDecimals; 0091 0092 QVector<QCPGraph *> graphs; 0093 QVector<double> binWidth; 0094 uint16_t binCount { 0 }; 0095 double JMIndex { 0 }; 0096 0097 int maxFrequency {0}; 0098 FITSScale type { FITS_AUTO }; 0099 bool isGUISynced { false}; 0100 bool m_Constructed { false }; 0101 QCustomPlot * customPlot { nullptr }; 0102 }; 0103 0104 class FITSHistogramCommand : public QUndoCommand 0105 { 0106 public: 0107 FITSHistogramCommand(QWidget * parent, FITSHistogram * inHisto, FITSScale newType, const QVector<double> &lmin, const QVector<double> &lmax); 0108 virtual ~FITSHistogramCommand(); 0109 0110 virtual void redo() override; 0111 virtual void undo() override; 0112 virtual QString text() const; 0113 0114 private: 0115 bool calculateDelta(const uint8_t * buffer); 0116 bool reverseDelta(); 0117 0118 FITSImage::Statistic stats; 0119 FITSHistogram * histogram { nullptr }; 0120 FITSScale type; 0121 QVector<double> min, max; 0122 0123 unsigned char * delta { nullptr }; 0124 unsigned long compressedBytes { 0 }; 0125 FITSTab * tab { nullptr }; 0126 };