@@ -1,30 +1,32 | |||||
1 | #ifndef SCIQLOP_SQPCOLORSCALE_H |
|
1 | #ifndef SCIQLOP_SQPCOLORSCALE_H | |
2 | #define SCIQLOP_SQPCOLORSCALE_H |
|
2 | #define SCIQLOP_SQPCOLORSCALE_H | |
3 |
|
3 | |||
4 | #include <Visualization/qcustomplot.h> |
|
4 | #include <Visualization/qcustomplot.h> | |
5 |
|
5 | |||
6 | #include <QLoggingCategory> |
|
6 | #include <QLoggingCategory> | |
7 |
|
7 | |||
8 | Q_DECLARE_LOGGING_CATEGORY(LOG_SqpColorScale) |
|
8 | Q_DECLARE_LOGGING_CATEGORY(LOG_SqpColorScale) | |
9 |
|
9 | |||
10 | /** |
|
10 | /** | |
11 | * @brief The SqpColorScale struct represents the color scale for some graphs (such as |
|
11 | * @brief The SqpColorScale struct represents the color scale for some graphs (such as | |
12 | * spectrograms). |
|
12 | * spectrograms). | |
13 | * |
|
13 | * | |
14 | * Its implementation is based on the QCustomPlot color scale (@sa QCPColorScale) to which are added |
|
14 | * Its implementation is based on the QCustomPlot color scale (@sa QCPColorScale) to which are added | |
15 | * other useful properties for viewing in SciQlop |
|
15 | * other useful properties for viewing in SciQlop | |
16 | */ |
|
16 | */ | |
17 | struct SqpColorScale { |
|
17 | struct SqpColorScale { | |
18 | static std::pair<double, double> computeThresholds(const SqpColorScale &scale); |
|
18 | static std::pair<double, double> computeThresholds(const SqpColorScale &scale); | |
19 |
|
19 | |||
20 | explicit SqpColorScale(QCustomPlot &plot); |
|
20 | explicit SqpColorScale(QCustomPlot &plot); | |
21 |
|
21 | |||
|
22 | void updateDataRange() noexcept; | |||
|
23 | ||||
22 | /// QCustomPlot object representing the color scale. |
|
24 | /// QCustomPlot object representing the color scale. | |
23 | /// @remarks The SqpColorScale instance has not the property on this pointer. The pointer must |
|
25 | /// @remarks The SqpColorScale instance has not the property on this pointer. The pointer must | |
24 | /// remain valid throughout the existence of the SqpColorScale instance |
|
26 | /// remain valid throughout the existence of the SqpColorScale instance | |
25 | QCPColorScale *m_Scale{nullptr}; |
|
27 | QCPColorScale *m_Scale{nullptr}; | |
26 | bool m_AutomaticThreshold{false}; |
|
28 | bool m_AutomaticThreshold{false}; | |
27 | QCPColorGradient::GradientPreset m_GradientPreset{QCPColorGradient::gpJet}; |
|
29 | QCPColorGradient::GradientPreset m_GradientPreset{QCPColorGradient::gpJet}; | |
28 | }; |
|
30 | }; | |
29 |
|
31 | |||
30 | #endif // SCIQLOP_SQPCOLORSCALE_H |
|
32 | #endif // SCIQLOP_SQPCOLORSCALE_H |
@@ -1,41 +1,60 | |||||
1 | #include "Visualization/SqpColorScale.h" |
|
1 | #include "Visualization/SqpColorScale.h" | |
2 |
|
2 | |||
3 | #include <Data/DataSeriesUtils.h> |
|
3 | #include <Data/DataSeriesUtils.h> | |
4 |
|
4 | |||
5 | #include <Visualization/QCPColorMapIterator.h> |
|
5 | #include <Visualization/QCPColorMapIterator.h> | |
6 |
|
6 | |||
7 | Q_LOGGING_CATEGORY(LOG_SqpColorScale, "SqpColorScale") |
|
7 | Q_LOGGING_CATEGORY(LOG_SqpColorScale, "SqpColorScale") | |
8 |
|
8 | |||
9 | namespace { |
|
9 | namespace { | |
10 |
|
10 | |||
11 | const auto DEFAULT_GRADIENT_PRESET = QCPColorGradient::gpJet; |
|
11 | const auto DEFAULT_GRADIENT_PRESET = QCPColorGradient::gpJet; | |
12 | const auto DEFAULT_RANGE = QCPRange{1.0e3, 1.7e7}; |
|
12 | const auto DEFAULT_RANGE = QCPRange{1.0e3, 1.7e7}; | |
13 |
|
13 | |||
14 | } // namespace |
|
14 | } // namespace | |
15 |
|
15 | |||
16 | std::pair<double, double> SqpColorScale::computeThresholds(const SqpColorScale &scale) |
|
16 | std::pair<double, double> SqpColorScale::computeThresholds(const SqpColorScale &scale) | |
17 | { |
|
17 | { | |
18 | auto qcpScale = scale.m_Scale; |
|
18 | auto qcpScale = scale.m_Scale; | |
19 |
|
19 | |||
20 | auto colorMaps = qcpScale->colorMaps(); |
|
20 | auto colorMaps = qcpScale->colorMaps(); | |
21 | if (colorMaps.size() != 1) { |
|
21 | if (colorMaps.size() != 1) { | |
22 | return {std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()}; |
|
22 | return {std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()}; | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
25 | // Computes thresholds |
|
25 | // Computes thresholds | |
26 | auto isLogarithmicScale = qcpScale->dataScaleType() == QCPAxis::stLogarithmic; |
|
26 | auto isLogarithmicScale = qcpScale->dataScaleType() == QCPAxis::stLogarithmic; | |
27 | auto colorMapData = colorMaps.first()->data(); |
|
27 | auto colorMapData = colorMaps.first()->data(); | |
28 | QCPColorMapIterator begin{colorMapData, true}; |
|
28 | QCPColorMapIterator begin{colorMapData, true}; | |
29 | QCPColorMapIterator end{colorMapData, false}; |
|
29 | QCPColorMapIterator end{colorMapData, false}; | |
30 |
|
30 | |||
31 | return DataSeriesUtils::thresholds(begin, end, isLogarithmicScale); |
|
31 | return DataSeriesUtils::thresholds(begin, end, isLogarithmicScale); | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | SqpColorScale::SqpColorScale(QCustomPlot &plot) |
|
34 | SqpColorScale::SqpColorScale(QCustomPlot &plot) | |
35 | : m_Scale{new QCPColorScale{&plot}}, |
|
35 | : m_Scale{new QCPColorScale{&plot}}, | |
36 |
m_AutomaticThreshold{ |
|
36 | m_AutomaticThreshold{true}, | |
37 | m_GradientPreset{DEFAULT_GRADIENT_PRESET} |
|
37 | m_GradientPreset{DEFAULT_GRADIENT_PRESET} | |
38 | { |
|
38 | { | |
39 | m_Scale->setGradient(m_GradientPreset); |
|
39 | m_Scale->setGradient(m_GradientPreset); | |
40 | m_Scale->setDataRange(DEFAULT_RANGE); |
|
40 | m_Scale->setDataRange(DEFAULT_RANGE); | |
41 | } |
|
41 | } | |
|
42 | ||||
|
43 | void SqpColorScale::updateDataRange() noexcept | |||
|
44 | { | |||
|
45 | // Updates data range only if mode is automatic | |||
|
46 | if (!m_AutomaticThreshold) { | |||
|
47 | return; | |||
|
48 | } | |||
|
49 | ||||
|
50 | double minThreshold, maxThreshold; | |||
|
51 | std::tie(minThreshold, maxThreshold) = computeThresholds(*this); | |||
|
52 | if (std::isnan(minThreshold) || std::isnan(maxThreshold)) { | |||
|
53 | qCCritical(LOG_SqpColorScale()) | |||
|
54 | << "Can't update data range of color scale: thresholds computed are invalid"; | |||
|
55 | return; | |||
|
56 | } | |||
|
57 | ||||
|
58 | // Updates thresholds | |||
|
59 | m_Scale->setDataRange({minThreshold, maxThreshold}); | |||
|
60 | } |
General Comments 0
You need to be logged in to leave comments.
Login now