@@ -1,88 +1,85 | |||||
1 | #include "Data/VectorSeries.h" |
|
1 | #include "Data/VectorSeries.h" | |
2 |
|
2 | |||
3 | namespace { |
|
3 | namespace { | |
4 |
|
4 | |||
5 | /** |
|
5 | /** | |
6 | * Flatten the three components of a vector to a single QVector that can be passed to an ArrayData |
|
6 | * Flatten the three components of a vector to a single QVector that can be passed to an ArrayData | |
7 | * |
|
7 | * | |
8 | * Example: |
|
8 | * Example: | |
9 | * xValues = {1, 2, 3} |
|
9 | * xValues = {1, 2, 3} | |
10 | * yValues = {4, 5, 6} |
|
10 | * yValues = {4, 5, 6} | |
11 | * zValues = {7, 8, 9} |
|
11 | * zValues = {7, 8, 9} | |
12 | * |
|
12 | * | |
13 | * result = {1, 4, 7, 2, 5, 8, 3, 6, 9} |
|
13 | * result = {1, 4, 7, 2, 5, 8, 3, 6, 9} | |
14 | * |
|
14 | * | |
15 | * @param xValues the x-component values of the vector |
|
15 | * @param xValues the x-component values of the vector | |
16 | * @param yValues the y-component values of the vector |
|
16 | * @param yValues the y-component values of the vector | |
17 | * @param zValues the z-component values of the vector |
|
17 | * @param zValues the z-component values of the vector | |
18 | * @return the single QVector |
|
18 | * @return the single QVector | |
19 | * @remarks the three components are consumed |
|
19 | * @remarks the three components are consumed | |
20 | * @sa ArrayData |
|
20 | * @sa ArrayData | |
21 | */ |
|
21 | */ | |
22 | std::vector<double> flatten(std::vector<double> xValues, std::vector<double> yValues, |
|
22 | std::vector<double> flatten(std::vector<double> xValues, std::vector<double> yValues, | |
23 | std::vector<double> zValues) |
|
23 | std::vector<double> zValues) | |
24 | { |
|
24 | { | |
25 | if (xValues.size() != yValues.size() || xValues.size() != zValues.size()) { |
|
25 | if (xValues.size() != yValues.size() || xValues.size() != zValues.size()) { | |
26 | /// @todo ALX : log |
|
26 | /// @todo ALX : log | |
27 | return {}; |
|
27 | return {}; | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | auto result = std::vector<double>(); |
|
30 | auto result = std::vector<double>(); | |
31 | result.reserve(xValues.size() * 3); |
|
31 | result.reserve(xValues.size() * 3); | |
32 |
|
32 | |||
33 | while (!xValues.empty()) { |
|
33 | while (!xValues.empty()) { | |
34 | result.insert(result.cend(), {xValues.front(), yValues.front(), zValues.front()}); |
|
34 | result.insert(result.cend(), {xValues.front(), yValues.front(), zValues.front()}); | |
35 | xValues.erase(xValues.begin()); |
|
35 | xValues.erase(xValues.begin()); | |
36 | yValues.erase(yValues.begin()); |
|
36 | yValues.erase(yValues.begin()); | |
37 | zValues.erase(zValues.begin()); |
|
37 | zValues.erase(zValues.begin()); | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | return result; |
|
40 | return result; | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | } // namespace |
|
43 | } // namespace | |
44 |
|
44 | |||
45 | VectorSeries::VectorSeries(std::vector<double> xAxisData, std::vector<double> xValuesData, |
|
45 | VectorSeries::VectorSeries(std::vector<double> xAxisData, std::vector<double> xValuesData, | |
46 | std::vector<double> yValuesData, std::vector<double> zValuesData, |
|
46 | std::vector<double> yValuesData, std::vector<double> zValuesData, | |
47 | const Unit &xAxisUnit, const Unit &valuesUnit) |
|
47 | const Unit &xAxisUnit, const Unit &valuesUnit) | |
48 | : VectorSeries{std::move(xAxisData), flatten(std::move(xValuesData), std::move(yValuesData), |
|
48 | : VectorSeries{std::move(xAxisData), flatten(std::move(xValuesData), std::move(yValuesData), | |
49 | std::move(zValuesData)), |
|
49 | std::move(zValuesData)), | |
50 | xAxisUnit, valuesUnit} |
|
50 | xAxisUnit, valuesUnit} | |
51 | { |
|
51 | { | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | VectorSeries::VectorSeries(std::vector<double> xAxisData, std::vector<double> valuesData, |
|
54 | VectorSeries::VectorSeries(std::vector<double> xAxisData, std::vector<double> valuesData, | |
55 | const Unit &xAxisUnit, const Unit &valuesUnit) |
|
55 | const Unit &xAxisUnit, const Unit &valuesUnit) | |
56 | : DataSeries{std::make_shared<ArrayData<1> >(std::move(xAxisData)), xAxisUnit, |
|
56 | : DataSeries{std::make_shared<ArrayData<1> >(std::move(xAxisData)), xAxisUnit, | |
57 | std::make_shared<ArrayData<2> >(std::move(valuesData), 3), valuesUnit} |
|
57 | std::make_shared<ArrayData<2> >(std::move(valuesData), 3), valuesUnit} | |
58 | { |
|
58 | { | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | std::unique_ptr<IDataSeries> VectorSeries::clone() const |
|
61 | std::unique_ptr<IDataSeries> VectorSeries::clone() const | |
62 | { |
|
62 | { | |
63 | return std::make_unique<VectorSeries>(*this); |
|
63 | return std::make_unique<VectorSeries>(*this); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | std::shared_ptr<IDataSeries> VectorSeries::subDataSeries(const SqpRange &range) |
|
66 | std::shared_ptr<IDataSeries> VectorSeries::subDataSeries(const SqpRange &range) | |
67 | { |
|
67 | { | |
68 | auto subXAxisData = std::vector<double>(); |
|
68 | auto subXAxisData = std::vector<double>(); | |
69 |
auto sub |
|
69 | auto subValuesData = std::vector<double>(); | |
70 | auto subYValuesData = std::vector<double>(); |
|
|||
71 | auto subZValuesData = std::vector<double>(); |
|
|||
72 |
|
70 | |||
73 | this->lockRead(); |
|
71 | this->lockRead(); | |
74 | { |
|
72 | { | |
75 | auto bounds = xAxisRange(range.m_TStart, range.m_TEnd); |
|
73 | auto bounds = xAxisRange(range.m_TStart, range.m_TEnd); | |
76 | for (auto it = bounds.first; it != bounds.second; ++it) { |
|
74 | for (auto it = bounds.first; it != bounds.second; ++it) { | |
77 | subXAxisData.push_back(it->x()); |
|
75 | subXAxisData.push_back(it->x()); | |
78 |
sub |
|
76 | subValuesData.push_back(it->value(0)); | |
79 |
sub |
|
77 | subValuesData.push_back(it->value(1)); | |
80 |
sub |
|
78 | subValuesData.push_back(it->value(2)); | |
81 | } |
|
79 | } | |
82 | } |
|
80 | } | |
83 | this->unlock(); |
|
81 | this->unlock(); | |
84 |
|
82 | |||
85 |
return std::make_shared<VectorSeries>(std::move(subXAxisData), std::move(sub |
|
83 | return std::make_shared<VectorSeries>(std::move(subXAxisData), std::move(subValuesData), | |
86 | std::move(subYValuesData), std::move(subZValuesData), |
|
|||
87 | this->xAxisUnit(), this->valuesUnit()); |
|
84 | this->xAxisUnit(), this->valuesUnit()); | |
88 | } |
|
85 | } |
General Comments 0
You need to be logged in to leave comments.
Login now