##// END OF EJS Templates
Creates method that computes thresholds of a SqpColorScale
Alexandre Leroux -
r1018:63f62cbba482
parent child
Show More
@@ -1,24 +1,30
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>
7
8 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpColorScale)
9
6 /**
10 /**
7 * @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
8 * spectrograms).
12 * spectrograms).
9 *
13 *
10 * 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
11 * other useful properties for viewing in SciQlop
15 * other useful properties for viewing in SciQlop
12 */
16 */
13 struct SqpColorScale {
17 struct SqpColorScale {
18 static std::pair<double, double> computeThresholds(const SqpColorScale &scale);
19
14 explicit SqpColorScale(QCustomPlot &plot);
20 explicit SqpColorScale(QCustomPlot &plot);
15
21
16 /// QCustomPlot object representing the color scale.
22 /// QCustomPlot object representing the color scale.
17 /// @remarks The SqpColorScale instance has not the property on this pointer. The pointer must
23 /// @remarks The SqpColorScale instance has not the property on this pointer. The pointer must
18 /// remain valid throughout the existence of the SqpColorScale instance
24 /// remain valid throughout the existence of the SqpColorScale instance
19 QCPColorScale *m_Scale{nullptr};
25 QCPColorScale *m_Scale{nullptr};
20 bool m_AutomaticThreshold{false};
26 bool m_AutomaticThreshold{false};
21 QCPColorGradient::GradientPreset m_GradientPreset{QCPColorGradient::gpJet};
27 QCPColorGradient::GradientPreset m_GradientPreset{QCPColorGradient::gpJet};
22 };
28 };
23
29
24 #endif // SCIQLOP_SQPCOLORSCALE_H
30 #endif // SCIQLOP_SQPCOLORSCALE_H
@@ -1,17 +1,41
1 #include "Visualization/SqpColorScale.h"
1 #include "Visualization/SqpColorScale.h"
2
2
3 #include <Data/DataSeriesUtils.h>
4
5 #include <Visualization/QCPColorMapIterator.h>
6
7 Q_LOGGING_CATEGORY(LOG_SqpColorScale, "SqpColorScale")
8
3 namespace {
9 namespace {
4
10
5 const auto DEFAULT_GRADIENT_PRESET = QCPColorGradient::gpJet;
11 const auto DEFAULT_GRADIENT_PRESET = QCPColorGradient::gpJet;
6 const auto DEFAULT_RANGE = QCPRange{1.0e3, 1.7e7};
12 const auto DEFAULT_RANGE = QCPRange{1.0e3, 1.7e7};
7
13
8 } // namespace
14 } // namespace
9
15
16 std::pair<double, double> SqpColorScale::computeThresholds(const SqpColorScale &scale)
17 {
18 auto qcpScale = scale.m_Scale;
19
20 auto colorMaps = qcpScale->colorMaps();
21 if (colorMaps.size() != 1) {
22 return {std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()};
23 }
24
25 // Computes thresholds
26 auto isLogarithmicScale = qcpScale->dataScaleType() == QCPAxis::stLogarithmic;
27 auto colorMapData = colorMaps.first()->data();
28 QCPColorMapIterator begin{colorMapData, true};
29 QCPColorMapIterator end{colorMapData, false};
30
31 return DataSeriesUtils::thresholds(begin, end, isLogarithmicScale);
32 }
33
10 SqpColorScale::SqpColorScale(QCustomPlot &plot)
34 SqpColorScale::SqpColorScale(QCustomPlot &plot)
11 : m_Scale{new QCPColorScale{&plot}},
35 : m_Scale{new QCPColorScale{&plot}},
12 m_AutomaticThreshold{false},
36 m_AutomaticThreshold{false},
13 m_GradientPreset{DEFAULT_GRADIENT_PRESET}
37 m_GradientPreset{DEFAULT_GRADIENT_PRESET}
14 {
38 {
15 m_Scale->setGradient(m_GradientPreset);
39 m_Scale->setGradient(m_GradientPreset);
16 m_Scale->setDataRange(DEFAULT_RANGE);
40 m_Scale->setDataRange(DEFAULT_RANGE);
17 }
41 }
General Comments 0
You need to be logged in to leave comments. Login now