##// END OF EJS Templates
Updates PlottablesRenderingUtils to use variable's type instead of dataseries
Alexandre Leroux -
r1253:a119058eb032
parent child
Show More
@@ -1,6 +1,8
1 #ifndef SCIQLOP_PLOTTABLESRENDERINGUTILS_H
1 #ifndef SCIQLOP_PLOTTABLESRENDERINGUTILS_H
2 #define SCIQLOP_PLOTTABLESRENDERINGUTILS_H
2 #define SCIQLOP_PLOTTABLESRENDERINGUTILS_H
3
3
4 #include <Data/DataSeriesType.h>
5
4 #include <Visualization/VisualizationDefs.h>
6 #include <Visualization/VisualizationDefs.h>
5
7
6 #include <memory>
8 #include <memory>
@@ -9,9 +11,9
9
11
10 Q_DECLARE_LOGGING_CATEGORY(LOG_PlottablesRenderingUtils)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_PlottablesRenderingUtils)
11
13
12 class IDataSeries;
13 class QCPColorScale;
14 class QCPColorScale;
14 class QCustomPlot;
15 class QCustomPlot;
16 class Variable;
15
17
16 /**
18 /**
17 * Helper used to handle plottables rendering
19 * Helper used to handle plottables rendering
@@ -25,9 +27,8 struct IPlottablesHelper {
25 };
27 };
26
28
27 struct IPlottablesHelperFactory {
29 struct IPlottablesHelperFactory {
28 /// Creates IPlottablesHelper according to a data series
30 /// Creates IPlottablesHelper according to the type of data series a variable holds
29 static std::unique_ptr<IPlottablesHelper>
31 static std::unique_ptr<IPlottablesHelper> create(const Variable &variable) noexcept;
30 create(std::shared_ptr<IDataSeries> dataSeries) noexcept;
31 };
32 };
32
33
33 #endif // SCIQLOP_PLOTTABLESRENDERINGUTILS_H
34 #endif // SCIQLOP_PLOTTABLESRENDERINGUTILS_H
@@ -6,6 +6,8
6 #include <Data/SpectrogramSeries.h>
6 #include <Data/SpectrogramSeries.h>
7 #include <Data/VectorSeries.h>
7 #include <Data/VectorSeries.h>
8
8
9 #include <Variable/Variable.h>
10
9 #include <Visualization/qcustomplot.h>
11 #include <Visualization/qcustomplot.h>
10
12
11 Q_LOGGING_CATEGORY(LOG_PlottablesRenderingUtils, "PlottablesRenderingUtils")
13 Q_LOGGING_CATEGORY(LOG_PlottablesRenderingUtils, "PlottablesRenderingUtils")
@@ -17,7 +19,7 namespace {
17 */
19 */
18 template <typename T, typename Enabled = void>
20 template <typename T, typename Enabled = void>
19 struct PlottablesSetter {
21 struct PlottablesSetter {
20 static void setProperties(T &, PlottablesMap &)
22 static void setProperties(PlottablesMap &)
21 {
23 {
22 // Default implementation does nothing
24 // Default implementation does nothing
23 qCCritical(LOG_PlottablesRenderingUtils())
25 qCCritical(LOG_PlottablesRenderingUtils())
@@ -33,20 +35,25 struct PlottablesSetter {
33 template <typename T>
35 template <typename T>
34 struct PlottablesSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value
36 struct PlottablesSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value
35 or std::is_base_of<VectorSeries, T>::value> > {
37 or std::is_base_of<VectorSeries, T>::value> > {
36 static void setProperties(T &dataSeries, PlottablesMap &plottables)
38 static void setProperties(PlottablesMap &plottables)
37 {
39 {
38 // Gets the number of components of the data series
40 // Finds the plottable with the highest index to determine the number of colors to generate
39 dataSeries.lockRead();
41 auto end = plottables.cend();
40 auto componentCount = dataSeries.valuesData()->componentCount();
42 auto maxPlottableIndexIt
41 dataSeries.unlock();
43 = std::max_element(plottables.cbegin(), end, [](const auto &it1, const auto &it2) {
44 return it1.first < it2.first;
45 });
46 auto componentCount = maxPlottableIndexIt != end ? maxPlottableIndexIt->first + 1 : 0;
42
47
43 // Generates colors for each component
48 // Generates colors for each component
44 auto colors = ColorUtils::colors(Qt::blue, Qt::red, componentCount);
49 auto colors = ColorUtils::colors(Qt::blue, Qt::red, componentCount);
45
50
46 // For each component of the data series, creates a QCPGraph to add to the plot
51 // For each component of the data series, creates a QCPGraph to add to the plot
47 for (auto i = 0; i < componentCount; ++i) {
52 for (auto i = 0; i < componentCount; ++i) {
48 auto graph = plottables.at(i);
53 auto graphIt = plottables.find(i);
49 graph->setPen(QPen{colors.at(i)});
54 if (graphIt != end) {
55 graphIt->second->setPen(QPen{colors.at(i)});
56 }
50 }
57 }
51 }
58 }
52 };
59 };
@@ -58,7 +65,7 struct PlottablesSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSerie
58 template <typename T>
65 template <typename T>
59 struct PlottablesSetter<T,
66 struct PlottablesSetter<T,
60 typename std::enable_if_t<std::is_base_of<SpectrogramSeries, T>::value> > {
67 typename std::enable_if_t<std::is_base_of<SpectrogramSeries, T>::value> > {
61 static void setProperties(T &, PlottablesMap &plottables)
68 static void setProperties(PlottablesMap &plottables)
62 {
69 {
63 // Checks that for a spectrogram there is only one plottable, that is a colormap
70 // Checks that for a spectrogram there is only one plottable, that is a colormap
64 if (plottables.size() != 1) {
71 if (plottables.size() != 1) {
@@ -92,31 +99,28 struct PlottablesSetter<T,
92 */
99 */
93 template <typename T>
100 template <typename T>
94 struct PlottablesHelper : public IPlottablesHelper {
101 struct PlottablesHelper : public IPlottablesHelper {
95 explicit PlottablesHelper(T &dataSeries) : m_DataSeries{dataSeries} {}
96
97 void setProperties(PlottablesMap &plottables) override
102 void setProperties(PlottablesMap &plottables) override
98 {
103 {
99 PlottablesSetter<T>::setProperties(m_DataSeries, plottables);
104 PlottablesSetter<T>::setProperties(plottables);
100 }
105 }
101
102 T &m_DataSeries;
103 };
106 };
104
107
105 } // namespace
108 } // namespace
106
109
107 std::unique_ptr<IPlottablesHelper>
110 std::unique_ptr<IPlottablesHelper>
108 IPlottablesHelperFactory::create(std::shared_ptr<IDataSeries> dataSeries) noexcept
111 IPlottablesHelperFactory::create(const Variable &variable) noexcept
109 {
112 {
110 if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(dataSeries)) {
113 switch (variable.type()) {
111 return std::make_unique<PlottablesHelper<ScalarSeries> >(*scalarSeries);
114 case DataSeriesType::SCALAR:
112 }
115 return std::make_unique<PlottablesHelper<ScalarSeries> >();
113 else if (auto spectrogramSeries = std::dynamic_pointer_cast<SpectrogramSeries>(dataSeries)) {
116 case DataSeriesType::SPECTROGRAM:
114 return std::make_unique<PlottablesHelper<SpectrogramSeries> >(*spectrogramSeries);
117 return std::make_unique<PlottablesHelper<SpectrogramSeries> >();
115 }
118 case DataSeriesType::VECTOR:
116 else if (auto vectorSeries = std::dynamic_pointer_cast<VectorSeries>(dataSeries)) {
119 return std::make_unique<PlottablesHelper<VectorSeries> >();
117 return std::make_unique<PlottablesHelper<VectorSeries> >(*vectorSeries);
120 default:
118 }
121 // Returns default helper
119 else {
122 break;
120 return std::make_unique<PlottablesHelper<IDataSeries> >(*dataSeries);
121 }
123 }
124
125 return std::make_unique<PlottablesHelper<IDataSeries> >();
122 }
126 }
General Comments 0
You need to be logged in to leave comments. Login now