##// END OF EJS Templates
Updates sqp color scale thresholds (1)...
Alexandre Leroux -
r1060:1474b0522998
parent child
Show More
@@ -1,30 +1,32
1 1 #ifndef SCIQLOP_SQPCOLORSCALE_H
2 2 #define SCIQLOP_SQPCOLORSCALE_H
3 3
4 4 #include <Visualization/qcustomplot.h>
5 5
6 6 #include <QLoggingCategory>
7 7
8 8 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpColorScale)
9 9
10 10 /**
11 11 * @brief The SqpColorScale struct represents the color scale for some graphs (such as
12 12 * spectrograms).
13 13 *
14 14 * Its implementation is based on the QCustomPlot color scale (@sa QCPColorScale) to which are added
15 15 * other useful properties for viewing in SciQlop
16 16 */
17 17 struct SqpColorScale {
18 18 static std::pair<double, double> computeThresholds(const SqpColorScale &scale);
19 19
20 20 explicit SqpColorScale(QCustomPlot &plot);
21 21
22 void updateDataRange() noexcept;
23
22 24 /// QCustomPlot object representing the color scale.
23 25 /// @remarks The SqpColorScale instance has not the property on this pointer. The pointer must
24 26 /// remain valid throughout the existence of the SqpColorScale instance
25 27 QCPColorScale *m_Scale{nullptr};
26 28 bool m_AutomaticThreshold{false};
27 29 QCPColorGradient::GradientPreset m_GradientPreset{QCPColorGradient::gpJet};
28 30 };
29 31
30 32 #endif // SCIQLOP_SQPCOLORSCALE_H
@@ -1,41 +1,60
1 1 #include "Visualization/SqpColorScale.h"
2 2
3 3 #include <Data/DataSeriesUtils.h>
4 4
5 5 #include <Visualization/QCPColorMapIterator.h>
6 6
7 7 Q_LOGGING_CATEGORY(LOG_SqpColorScale, "SqpColorScale")
8 8
9 9 namespace {
10 10
11 11 const auto DEFAULT_GRADIENT_PRESET = QCPColorGradient::gpJet;
12 12 const auto DEFAULT_RANGE = QCPRange{1.0e3, 1.7e7};
13 13
14 14 } // namespace
15 15
16 16 std::pair<double, double> SqpColorScale::computeThresholds(const SqpColorScale &scale)
17 17 {
18 18 auto qcpScale = scale.m_Scale;
19 19
20 20 auto colorMaps = qcpScale->colorMaps();
21 21 if (colorMaps.size() != 1) {
22 22 return {std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()};
23 23 }
24 24
25 25 // Computes thresholds
26 26 auto isLogarithmicScale = qcpScale->dataScaleType() == QCPAxis::stLogarithmic;
27 27 auto colorMapData = colorMaps.first()->data();
28 28 QCPColorMapIterator begin{colorMapData, true};
29 29 QCPColorMapIterator end{colorMapData, false};
30 30
31 31 return DataSeriesUtils::thresholds(begin, end, isLogarithmicScale);
32 32 }
33 33
34 34 SqpColorScale::SqpColorScale(QCustomPlot &plot)
35 35 : m_Scale{new QCPColorScale{&plot}},
36 m_AutomaticThreshold{false},
36 m_AutomaticThreshold{true},
37 37 m_GradientPreset{DEFAULT_GRADIENT_PRESET}
38 38 {
39 39 m_Scale->setGradient(m_GradientPreset);
40 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