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