@@ -1,50 +1,50 | |||
|
1 | 1 | #ifndef SCIQLOP_DATASERIES_H |
|
2 | 2 | #define SCIQLOP_DATASERIES_H |
|
3 | 3 | |
|
4 | 4 | #include <Data/ArrayData.h> |
|
5 | 5 | #include <Data/IDataSeries.h> |
|
6 | 6 | |
|
7 | 7 | #include <memory> |
|
8 | 8 | |
|
9 | 9 | /** |
|
10 | 10 | * @brief The DataSeries class is the base (abstract) implementation of IDataSeries. |
|
11 | 11 | * |
|
12 | 12 | * It proposes to set a dimension for the values data |
|
13 | 13 | * |
|
14 | 14 | * @tparam Dim The dimension of the values data |
|
15 | 15 | * |
|
16 | 16 | */ |
|
17 | 17 | template <int Dim> |
|
18 | 18 | class DataSeries : public IDataSeries { |
|
19 | 19 | public: |
|
20 | 20 | /// @sa IDataSeries::xAxisData() |
|
21 | 21 | std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; } |
|
22 | 22 | |
|
23 | 23 | /// @sa IDataSeries::xAxisUnit() |
|
24 |
|
|
|
24 | Unit xAxisUnit() const override { return m_XAxisUnit; } | |
|
25 | 25 | |
|
26 | 26 | /// @return the values dataset |
|
27 | 27 | std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; } |
|
28 | 28 | |
|
29 | 29 | /// @sa IDataSeries::valuesUnit() |
|
30 |
|
|
|
30 | Unit valuesUnit() const override { return m_ValuesUnit; } | |
|
31 | 31 | |
|
32 | 32 | protected: |
|
33 | 33 | /// Protected ctor (DataSeries is abstract) |
|
34 |
explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, |
|
|
35 |
std::shared_ptr<ArrayData<Dim> > valuesData, |
|
|
34 | explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, Unit xAxisUnit, | |
|
35 | std::shared_ptr<ArrayData<Dim> > valuesData, Unit valuesUnit) | |
|
36 | 36 | : m_XAxisData{xAxisData}, |
|
37 | m_XAxisUnit{xAxisUnit}, | |
|
37 | m_XAxisUnit{std::move(xAxisUnit)}, | |
|
38 | 38 | m_ValuesData{valuesData}, |
|
39 | m_ValuesUnit{valuesUnit} | |
|
39 | m_ValuesUnit{std::move(valuesUnit)} | |
|
40 | 40 | { |
|
41 | 41 | } |
|
42 | 42 | |
|
43 | 43 | private: |
|
44 | 44 | std::shared_ptr<ArrayData<1> > m_XAxisData; |
|
45 |
|
|
|
45 | Unit m_XAxisUnit; | |
|
46 | 46 | std::shared_ptr<ArrayData<Dim> > m_ValuesData; |
|
47 |
|
|
|
47 | Unit m_ValuesUnit; | |
|
48 | 48 | }; |
|
49 | 49 | |
|
50 | 50 | #endif // SCIQLOP_DATASERIES_H |
@@ -1,37 +1,47 | |||
|
1 | 1 | #ifndef SCIQLOP_IDATASERIES_H |
|
2 | 2 | #define SCIQLOP_IDATASERIES_H |
|
3 | 3 | |
|
4 | 4 | #include <QString> |
|
5 | 5 | |
|
6 | 6 | #include <memory> |
|
7 | 7 | |
|
8 | 8 | template <int Dim> |
|
9 | 9 | class ArrayData; |
|
10 | 10 | |
|
11 | struct Unit { | |
|
12 | explicit Unit(const QString &name = {}, bool timeUnit = false) | |
|
13 | : m_Name{name}, m_TimeUnit{timeUnit} | |
|
14 | { | |
|
15 | } | |
|
16 | ||
|
17 | QString m_Name; ///< Unit name | |
|
18 | bool m_TimeUnit; ///< The unit is a unit of time | |
|
19 | }; | |
|
20 | ||
|
11 | 21 | /** |
|
12 | 22 | * @brief The IDataSeries aims to declare a data series. |
|
13 | 23 | * |
|
14 | 24 | * A data series is an entity that contains at least : |
|
15 | 25 | * - one dataset representing the x-axis |
|
16 | 26 | * - one dataset representing the values |
|
17 | 27 | * |
|
18 | 28 | * Each dataset is represented by an ArrayData, and is associated with a unit. |
|
19 | 29 | * |
|
20 | 30 | * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the |
|
21 | 31 | * IDataSeries. The x-axis dataset is always unidimensional. |
|
22 | 32 | * |
|
23 | 33 | * @sa ArrayData |
|
24 | 34 | */ |
|
25 | 35 | class IDataSeries { |
|
26 | 36 | public: |
|
27 | 37 | virtual ~IDataSeries() noexcept = default; |
|
28 | 38 | |
|
29 | 39 | /// Returns the x-axis dataset |
|
30 | 40 | virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0; |
|
31 | 41 | |
|
32 |
virtual |
|
|
42 | virtual Unit xAxisUnit() const = 0; | |
|
33 | 43 | |
|
34 |
virtual |
|
|
44 | virtual Unit valuesUnit() const = 0; | |
|
35 | 45 | }; |
|
36 | 46 | |
|
37 | 47 | #endif // SCIQLOP_IDATASERIES_H |
@@ -1,28 +1,28 | |||
|
1 | 1 | #ifndef SCIQLOP_SCALARSERIES_H |
|
2 | 2 | #define SCIQLOP_SCALARSERIES_H |
|
3 | 3 | |
|
4 | 4 | #include <Data/DataSeries.h> |
|
5 | 5 | |
|
6 | 6 | /** |
|
7 | 7 | * @brief The ScalarSeries class is the implementation for a data series representing a scalar. |
|
8 | 8 | */ |
|
9 | 9 | class ScalarSeries : public DataSeries<1> { |
|
10 | 10 | public: |
|
11 | 11 | /** |
|
12 | 12 | * Ctor |
|
13 | 13 | * @param size the number of data the series will hold |
|
14 | 14 | * @param xAxisUnit x-axis unit |
|
15 | 15 | * @param valuesUnit values unit |
|
16 | 16 | */ |
|
17 |
explicit ScalarSeries(int size, |
|
|
17 | explicit ScalarSeries(int size, Unit xAxisUnit, Unit valuesUnit); | |
|
18 | 18 | |
|
19 | 19 | /** |
|
20 | 20 | * Sets data for a specific index. The index has to be valid to be effective |
|
21 | 21 | * @param index the index to which the data will be set |
|
22 | 22 | * @param x the x-axis data |
|
23 | 23 | * @param value the value data |
|
24 | 24 | */ |
|
25 | 25 | void setData(int index, double x, double value) noexcept; |
|
26 | 26 | }; |
|
27 | 27 | |
|
28 | 28 | #endif // SCIQLOP_SCALARSERIES_H |
@@ -1,13 +1,13 | |||
|
1 | 1 | #include <Data/ScalarSeries.h> |
|
2 | 2 | |
|
3 |
ScalarSeries::ScalarSeries(int size, |
|
|
4 | : DataSeries{std::make_shared<ArrayData<1> >(size), xAxisUnit, | |
|
5 | std::make_shared<ArrayData<1> >(size), valuesUnit} | |
|
3 | ScalarSeries::ScalarSeries(int size, Unit xAxisUnit, Unit valuesUnit) | |
|
4 | : DataSeries{std::make_shared<ArrayData<1> >(size), std::move(xAxisUnit), | |
|
5 | std::make_shared<ArrayData<1> >(size), std::move(valuesUnit)} | |
|
6 | 6 | { |
|
7 | 7 | } |
|
8 | 8 | |
|
9 | 9 | void ScalarSeries::setData(int index, double x, double value) noexcept |
|
10 | 10 | { |
|
11 | 11 | xAxisData()->setData(index, x); |
|
12 | 12 | valuesData()->setData(index, value); |
|
13 | 13 | } |
@@ -1,30 +1,30 | |||
|
1 | 1 | #include "CosinusProvider.h" |
|
2 | 2 | |
|
3 | 3 | #include <Data/DataProviderParameters.h> |
|
4 | 4 | #include <Data/ScalarSeries.h> |
|
5 | 5 | |
|
6 | 6 | #include <cmath> |
|
7 | 7 | |
|
8 | 8 | std::unique_ptr<IDataSeries> |
|
9 | 9 | CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const |
|
10 | 10 | { |
|
11 | 11 | // Gets the timerange from the parameters |
|
12 | 12 | auto start = parameters.m_TStart; |
|
13 | 13 | auto end = parameters.m_TEnd; |
|
14 | 14 | |
|
15 | 15 | // We assure that timerange is valid |
|
16 | 16 | if (end < start) { |
|
17 | 17 | std::swap(start, end); |
|
18 | 18 | } |
|
19 | 19 | |
|
20 | 20 | // Generates scalar series containing cosinus values (one value per second) |
|
21 | 21 | auto scalarSeries |
|
22 |
= std::make_unique<ScalarSeries>(end - start, QStringLiteral("t"), |
|
|
22 | = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); | |
|
23 | 23 | |
|
24 | 24 | auto dataIndex = 0; |
|
25 | 25 | for (auto time = start; time < end; ++time, ++dataIndex) { |
|
26 | 26 | scalarSeries->setData(dataIndex, time, std::cos(time)); |
|
27 | 27 | } |
|
28 | 28 | |
|
29 | 29 | return scalarSeries; |
|
30 | 30 | } |
General Comments 0
You need to be logged in to leave comments.
Login now