@@ -3,6 +3,7 | |||
|
3 | 3 | |
|
4 | 4 | #include <Data/DataProviderParameters.h> |
|
5 | 5 | #include <Data/ScalarSeries.h> |
|
6 | #include <Data/SpectrogramSeries.h> | |
|
6 | 7 | #include <Data/VectorSeries.h> |
|
7 | 8 | |
|
8 | 9 | #include <cmath> |
@@ -15,6 +16,9 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") | |||
|
15 | 16 | |
|
16 | 17 | namespace { |
|
17 | 18 | |
|
19 | /// Number of bands generated for a spectrogram | |
|
20 | const auto SPECTROGRAM_NUMBER_BANDS = 30; | |
|
21 | ||
|
18 | 22 | /// Abstract cosinus type |
|
19 | 23 | struct ICosinusType { |
|
20 | 24 | virtual ~ICosinusType() = default; |
@@ -25,6 +29,12 struct ICosinusType { | |||
|
25 | 29 | std::vector<double> valuesData, |
|
26 | 30 | Unit xAxisUnit, |
|
27 | 31 | Unit valuesUnit) const = 0; |
|
32 | /// Generates values (one value per component) | |
|
33 | /// @param x the x-axis data used to generate values | |
|
34 | /// @param values the vector in which to insert the generated values | |
|
35 | /// @param dataIndex the index of insertion of the generated values | |
|
36 | /// | |
|
37 | virtual void generateValues(double x, std::vector<double> &values, int dataIndex) const = 0; | |
|
28 | 38 | }; |
|
29 | 39 | |
|
30 | 40 | struct ScalarCosinus : public ICosinusType { |
@@ -37,7 +47,47 struct ScalarCosinus : public ICosinusType { | |||
|
37 | 47 | return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), |
|
38 | 48 | xAxisUnit, valuesUnit); |
|
39 | 49 | } |
|
50 | ||
|
51 | void generateValues(double x, std::vector<double> &values, int dataIndex) const override | |
|
52 | { | |
|
53 | values[dataIndex] = std::cos(x); | |
|
54 | } | |
|
40 | 55 | }; |
|
56 | ||
|
57 | struct SpectrogramCosinus : public ICosinusType { | |
|
58 | /// Ctor with y-axis | |
|
59 | explicit SpectrogramCosinus(std::vector<double> yAxisData, Unit yAxisUnit) | |
|
60 | : m_YAxisData{std::move(yAxisData)}, m_YAxisUnit{std::move(yAxisUnit)} | |
|
61 | { | |
|
62 | } | |
|
63 | ||
|
64 | int componentCount() const override { return m_YAxisData.size(); } | |
|
65 | ||
|
66 | std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData, | |
|
67 | std::vector<double> valuesData, Unit xAxisUnit, | |
|
68 | Unit valuesUnit) const override | |
|
69 | { | |
|
70 | return std::make_shared<SpectrogramSeries>(std::move(xAxisData), m_YAxisData, | |
|
71 | std::move(valuesData), xAxisUnit, m_YAxisUnit, | |
|
72 | valuesUnit); | |
|
73 | } | |
|
74 | ||
|
75 | void generateValues(double x, std::vector<double> &values, int dataIndex) const override | |
|
76 | { | |
|
77 | auto componentCount = this->componentCount(); | |
|
78 | for (int i = 0; i < componentCount; ++i) { | |
|
79 | auto y = m_YAxisData[i]; | |
|
80 | auto r = 3 * std::sqrt(x * x + y * y) + 1e-2; | |
|
81 | auto value = 2 * x * (std::cos(r + 2) / r - std::sin(r + 2) / r); | |
|
82 | ||
|
83 | values[componentCount * dataIndex + i] = value; | |
|
84 | } | |
|
85 | } | |
|
86 | ||
|
87 | std::vector<double> m_YAxisData; | |
|
88 | Unit m_YAxisUnit; | |
|
89 | }; | |
|
90 | ||
|
41 | 91 | struct VectorCosinus : public ICosinusType { |
|
42 | 92 | int componentCount() const override { return 3; } |
|
43 | 93 | |
@@ -48,6 +98,16 struct VectorCosinus : public ICosinusType { | |||
|
48 | 98 | return std::make_shared<VectorSeries>(std::move(xAxisData), std::move(valuesData), |
|
49 | 99 | xAxisUnit, valuesUnit); |
|
50 | 100 | } |
|
101 | ||
|
102 | void generateValues(double x, std::vector<double> &values, int dataIndex) const override | |
|
103 | { | |
|
104 | // Generates value for each component: cos(x), cos(x)/2, cos(x)/3 | |
|
105 | auto xValue = std::cos(x); | |
|
106 | auto componentCount = this->componentCount(); | |
|
107 | for (auto i = 0; i < componentCount; ++i) { | |
|
108 | values[componentCount * dataIndex + i] = xValue / (i + 1); | |
|
109 | } | |
|
110 | } | |
|
51 | 111 | }; |
|
52 | 112 | |
|
53 | 113 | /// Converts string to cosinus type |
@@ -57,6 +117,13 std::unique_ptr<ICosinusType> cosinusType(const QString &type) noexcept | |||
|
57 | 117 | if (type.compare(QStringLiteral("scalar"), Qt::CaseInsensitive) == 0) { |
|
58 | 118 | return std::make_unique<ScalarCosinus>(); |
|
59 | 119 | } |
|
120 | else if (type.compare(QStringLiteral("spectrogram"), Qt::CaseInsensitive) == 0) { | |
|
121 | // Generates default y-axis data for spectrogram [0., 1., 2., ...] | |
|
122 | std::vector<double> yAxisData(SPECTROGRAM_NUMBER_BANDS); | |
|
123 | std::iota(yAxisData.begin(), yAxisData.end(), 0.); | |
|
124 | ||
|
125 | return std::make_unique<SpectrogramCosinus>(std::move(yAxisData), Unit{"eV"}); | |
|
126 | } | |
|
60 | 127 | else if (type.compare(QStringLiteral("vector"), Qt::CaseInsensitive) == 0) { |
|
61 | 128 | return std::make_unique<VectorCosinus>(); |
|
62 | 129 | } |
@@ -128,16 +195,12 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier, | |||
|
128 | 195 | for (auto time = start; time <= end; ++time, ++dataIndex) { |
|
129 | 196 | auto it = m_VariableToEnableProvider.find(acqIdentifier); |
|
130 | 197 | if (it != m_VariableToEnableProvider.end() && it.value()) { |
|
131 |
const auto |
|
|
198 | const auto x = time / freq; | |
|
132 | 199 | |
|
133 |
xAxisData[dataIndex] = |
|
|
200 | xAxisData[dataIndex] = x; | |
|
134 | 201 | |
|
135 |
// Generates |
|
|
136 | // Example: for a vector, values will be : cos(x), cos(x)/2, cos(x)/3 | |
|
137 | auto value = std::cos(timeOnFreq); | |
|
138 | for (auto i = 0; i < componentCount; ++i) { | |
|
139 | valuesData[componentCount * dataIndex + i] = value / (i + 1); | |
|
140 | } | |
|
202 | // Generates values (depending on the type) | |
|
203 | type->generateValues(x, valuesData, dataIndex); | |
|
141 | 204 | |
|
142 | 205 | // progression |
|
143 | 206 | int currentProgress = (time - start) * 100.0 / progressEnd; |
@@ -75,6 +75,11 std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) | |||
|
75 | 75 | {COSINUS_TYPE_KEY, "vector"}, |
|
76 | 76 | {COSINUS_FREQUENCY_KEY, 100.}}, |
|
77 | 77 | dataSourceUid)); |
|
78 | magneticFieldFolder->appendChild( | |
|
79 | createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Spectrogram 1 Hz")}, | |
|
80 | {COSINUS_TYPE_KEY, "spectrogram"}, | |
|
81 | {COSINUS_FREQUENCY_KEY, 1.}}, | |
|
82 | dataSourceUid)); | |
|
78 | 83 | |
|
79 | 84 | // Electric field products |
|
80 | 85 | auto electricFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, |
General Comments 0
You need to be logged in to leave comments.
Login now