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