##// END OF EJS Templates
Handles rendering properties for spectrograms...
Alexandre Leroux -
r922:76b9deb45018
parent child
Show More
@@ -1,79 +1,120
1 #include "Visualization/PlottablesRenderingUtils.h"
1 #include "Visualization/PlottablesRenderingUtils.h"
2
2
3 #include <Common/ColorUtils.h>
3 #include <Common/ColorUtils.h>
4
4
5 #include <Data/ScalarSeries.h>
5 #include <Data/ScalarSeries.h>
6 #include <Data/SpectrogramSeries.h>
6 #include <Data/VectorSeries.h>
7 #include <Data/VectorSeries.h>
7
8
8 #include <Visualization/qcustomplot.h>
9 #include <Visualization/qcustomplot.h>
9
10
10 namespace {
11 namespace {
11
12
13 /// Default gradient used for colormap
14 const auto DEFAULT_COLORMAP_GRADIENT = QCPColorGradient::gpJet;
15
12 /**
16 /**
13 * Delegate used to set plottables properties
17 * Delegate used to set plottables properties
14 */
18 */
15 template <typename T, typename Enabled = void>
19 template <typename T, typename Enabled = void>
16 struct PlottablesSetter {
20 struct PlottablesSetter {
17 static void setProperties(T &, PlottablesMap &)
21 static void setProperties(T &, PlottablesMap &)
18 {
22 {
19 // Default implementation does nothing
23 // Default implementation does nothing
20 }
24 }
21 };
25 };
22
26
23 /**
27 /**
24 * Specialization of PlottablesSetter for scalars and vectors
28 * Specialization of PlottablesSetter for scalars and vectors
25 * @sa ScalarSeries
29 * @sa ScalarSeries
26 * @sa VectorSeries
30 * @sa VectorSeries
27 */
31 */
28 template <typename T>
32 template <typename T>
29 struct PlottablesSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value
33 struct PlottablesSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value
30 or std::is_base_of<VectorSeries, T>::value> > {
34 or std::is_base_of<VectorSeries, T>::value> > {
31 static void setProperties(T &dataSeries, PlottablesMap &plottables)
35 static void setProperties(T &dataSeries, PlottablesMap &plottables)
32 {
36 {
33 // Gets the number of components of the data series
37 // Gets the number of components of the data series
34 dataSeries.lockRead();
38 dataSeries.lockRead();
35 auto componentCount = dataSeries.valuesData()->componentCount();
39 auto componentCount = dataSeries.valuesData()->componentCount();
36 dataSeries.unlock();
40 dataSeries.unlock();
37
41
38 // Generates colors for each component
42 // Generates colors for each component
39 auto colors = ColorUtils::colors(Qt::blue, Qt::red, componentCount);
43 auto colors = ColorUtils::colors(Qt::blue, Qt::red, componentCount);
40
44
41 // For each component of the data series, creates a QCPGraph to add to the plot
45 // For each component of the data series, creates a QCPGraph to add to the plot
42 for (auto i = 0; i < componentCount; ++i) {
46 for (auto i = 0; i < componentCount; ++i) {
43 auto graph = plottables.at(i);
47 auto graph = plottables.at(i);
44 graph->setPen(QPen{colors.at(i)});
48 graph->setPen(QPen{colors.at(i)});
45 }
49 }
46 }
50 }
47 };
51 };
48
52
49 /**
53 /**
54 * Specialization of PlottablesSetter for spectrograms
55 * @sa SpectrogramSeries
56 */
57 template <typename T>
58 struct PlottablesSetter<T,
59 typename std::enable_if_t<std::is_base_of<SpectrogramSeries, T>::value> > {
60 static void setProperties(T &, PlottablesMap &plottables)
61 {
62 // Checks that for a spectrogram there is only one plottable, that is a colormap
63 if (plottables.size() != 1) {
64 return;
65 }
66
67 if (auto colormap = dynamic_cast<QCPColorMap *>(plottables.begin()->second)) {
68 colormap->setInterpolate(false); // No value interpolation
69 colormap->setTightBoundary(true);
70
71 // Finds color scale in the colormap's plot to associate with it
72 auto plot = colormap->parentPlot();
73 auto plotElements = plot->plotLayout()->elements(false);
74 for (auto plotElement : plotElements) {
75 if (auto colorScale = dynamic_cast<QCPColorScale *>(plotElement)) {
76 colormap->setColorScale(colorScale);
77 }
78 }
79
80 // Sets gradient used for color scale
81 colormap->setGradient(DEFAULT_COLORMAP_GRADIENT);
82 colormap->rescaleDataRange();
83 }
84 }
85 };
86
87 /**
50 * Default implementation of IPlottablesHelper, which takes data series to set plottables properties
88 * Default implementation of IPlottablesHelper, which takes data series to set plottables properties
51 * @tparam T the data series' type
89 * @tparam T the data series' type
52 */
90 */
53 template <typename T>
91 template <typename T>
54 struct PlottablesHelper : public IPlottablesHelper {
92 struct PlottablesHelper : public IPlottablesHelper {
55 explicit PlottablesHelper(T &dataSeries) : m_DataSeries{dataSeries} {}
93 explicit PlottablesHelper(T &dataSeries) : m_DataSeries{dataSeries} {}
56
94
57 void setProperties(PlottablesMap &plottables) override
95 void setProperties(PlottablesMap &plottables) override
58 {
96 {
59 PlottablesSetter<T>::setProperties(m_DataSeries, plottables);
97 PlottablesSetter<T>::setProperties(m_DataSeries, plottables);
60 }
98 }
61
99
62 T &m_DataSeries;
100 T &m_DataSeries;
63 };
101 };
64
102
65 } // namespace
103 } // namespace
66
104
67 std::unique_ptr<IPlottablesHelper>
105 std::unique_ptr<IPlottablesHelper>
68 IPlottablesHelperFactory::create(std::shared_ptr<IDataSeries> dataSeries) noexcept
106 IPlottablesHelperFactory::create(std::shared_ptr<IDataSeries> dataSeries) noexcept
69 {
107 {
70 if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(dataSeries)) {
108 if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(dataSeries)) {
71 return std::make_unique<PlottablesHelper<ScalarSeries> >(*scalarSeries);
109 return std::make_unique<PlottablesHelper<ScalarSeries> >(*scalarSeries);
72 }
110 }
111 else if (auto spectrogramSeries = std::dynamic_pointer_cast<SpectrogramSeries>(dataSeries)) {
112 return std::make_unique<PlottablesHelper<SpectrogramSeries> >(*spectrogramSeries);
113 }
73 else if (auto vectorSeries = std::dynamic_pointer_cast<VectorSeries>(dataSeries)) {
114 else if (auto vectorSeries = std::dynamic_pointer_cast<VectorSeries>(dataSeries)) {
74 return std::make_unique<PlottablesHelper<VectorSeries> >(*vectorSeries);
115 return std::make_unique<PlottablesHelper<VectorSeries> >(*vectorSeries);
75 }
116 }
76 else {
117 else {
77 return std::make_unique<PlottablesHelper<IDataSeries> >(*dataSeries);
118 return std::make_unique<PlottablesHelper<IDataSeries> >(*dataSeries);
78 }
119 }
79 }
120 }
General Comments 0
You need to be logged in to leave comments. Login now