@@ -3,12 +3,16 | |||||
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 | */ | |
@@ -47,6 +51,40 struct PlottablesSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSerie | |||||
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 | */ | |
@@ -70,6 +108,9 IPlottablesHelperFactory::create(std::shared_ptr<IDataSeries> dataSeries) noexce | |||||
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 | } |
General Comments 0
You need to be logged in to leave comments.
Login now